Class: Report::PhoneQueueReportCommand

Inherits:
BaseCommand
  • Object
show all
Defined in:
app/services/report/phone_queue_report_command.rb

Overview

Command pattern to encapsulate parameters necessary to run a presence report

Constant Summary collapse

GROUPING_OPTIONS =

Available grouping options.

%w[year month day week quarter hour].freeze

Instance Method Summary collapse

Instance Method Details

#execute(queue_params = nil) ⇒ Object



22
23
24
25
26
# File 'app/services/report/phone_queue_report_command.rb', line 22

def execute(queue_params = nil)
  return unless valid?

  @results = Analytic::PhoneRecordFact.get_queue_results(queue_params.presence || default_query_params)
end

#operator_optionsObject



18
19
20
# File 'app/services/report/phone_queue_report_command.rb', line 18

def operator_options
  QueueCallLog.where.not(member_name: nil).pluck('distinct member_name'.sql_safe).sort
end

#period1_humanizedObject



48
49
50
# File 'app/services/report/phone_queue_report_command.rb', line 48

def period1_humanized
  "From #{period1_range.first} until #{period1_range.last}"
end

#period1_rangeObject



44
45
46
# File 'app/services/report/phone_queue_report_command.rb', line 44

def period1_range
  (period1_gteq && period1_lteq && period1_gteq)..period1_lteq
end

#to_csv(queue_params = nil) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/services/report/phone_queue_report_command.rb', line 28

def to_csv(queue_params = nil)
  return unless valid?

  @results ||= Analytic::PhoneRecordFact.get_queue_results(queue_params.presence || default_query_params)
  return if @results.individuals.blank?

  attributes = @results.individuals.first.attributes.keys
  CSV.generate(headers: true) do |csv|
    csv << attributes

    @results.individuals.each do |r|
      csv << attributes.map { |attr| r.send(attr) }
    end
  end
end