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

Run the report with the given filters and store the result.

Parameters:

  • queue_params (Object, nil) (defaults to: nil)

Returns:

  • (Object)


27
28
29
30
31
# File 'app/services/report/phone_queue_report_command.rb', line 27

def execute(queue_params = nil)
  return unless valid?

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

#operator_optionsObject

Operator options.

Returns:

  • (Object)


20
21
22
# File 'app/services/report/phone_queue_report_command.rb', line 20

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

#period1_humanizedObject

Period1 humanized.

Returns:

  • (Object)


60
61
62
# File 'app/services/report/phone_queue_report_command.rb', line 60

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

#period1_rangeObject

Period1 range.

Returns:

  • (Object)


54
55
56
# File 'app/services/report/phone_queue_report_command.rb', line 54

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

#to_csv(queue_params = nil) ⇒ String

Render the report rows as CSV.

Parameters:

  • queue_params (Object, nil) (defaults to: nil)

Returns:

  • (String)


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/services/report/phone_queue_report_command.rb', line 36

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