Class: Report::PhoneQueueReportCommand
- Inherits:
-
BaseCommand
- Object
- BaseCommand
- Report::PhoneQueueReportCommand
- 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
-
#execute(queue_params = nil) ⇒ Object
Run the report with the given filters and store the result.
-
#operator_options ⇒ Object
Operator options.
-
#period1_humanized ⇒ Object
Period1 humanized.
-
#period1_range ⇒ Object
Period1 range.
-
#to_csv(queue_params = nil) ⇒ String
Render the report rows as CSV.
Instance Method Details
#execute(queue_params = nil) ⇒ Object
Run the report with the given filters and store the result.
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_options ⇒ Object
Operator options.
20 21 22 |
# File 'app/services/report/phone_queue_report_command.rb', line 20 def QueueCallLog.where.not(member_name: nil).pluck('distinct member_name'.sql_safe).sort end |
#period1_humanized ⇒ Object
Period1 humanized.
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_range ⇒ Object
Period1 range.
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.
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 |