Class: Report::KpiCall::KpiCallCommand
- Inherits:
-
BaseCommand
- Object
- BaseCommand
- Report::KpiCall::KpiCallCommand
- Defined in:
- app/services/report/kpi_call/kpi_call_command.rb
Overview
Command pattern to encapsulate parameters necessary to run a presence report
Constant Summary collapse
- KPI_LIST =
Kpi list.
[ ['TIME ON AVAILABLE', 1], ['INBOUNDS', 2], ['OUTBOUNDS', 3], ['ACTIVITIES', 4], ['SMS', 5], ['LOOM/ZOOM Clip', 6], ['CALL BLOCKS', 7], ['EMAILS', 8], ['MISSED CALLS %', 9] ].freeze
Class Method Summary collapse
-
.select_weeks ⇒ Object
Select weeks.
Instance Method Summary collapse
-
#execute ⇒ Object
Run the report with the given filters and store the result.
-
#success? ⇒ Boolean
Whether the command validated and ran successfully.
-
#to_csv ⇒ String
Render the report rows as CSV.
Class Method Details
.select_weeks ⇒ Object
Select weeks.
102 103 104 105 106 107 108 109 110 |
# File 'app/services/report/kpi_call/kpi_call_command.rb', line 102 def self.select_weeks week_and_dates = [] (Date.current.beginning_of_year.years_ago(1)..Date.current.to_date).each do |d| week_number = Date.new(d.year, d.month, d.day).cweek block = week_number.even? == true ? 'A' : 'B' week_and_dates << ["Week #{week_number} ---> From #{d.beginning_of_week} to #{d.end_of_week.days_ago(2)} (Block #{block})", "#{d.beginning_of_week}/#{d.end_of_week.days_ago(2)}/#{block}"] end week_and_dates.uniq.compact end |
Instance Method Details
#execute ⇒ Object
Run the report with the given filters and store the result.
26 27 28 29 30 |
# File 'app/services/report/kpi_call/kpi_call_command.rb', line 26 def execute return unless valid? @result = Report::KpiCall::KpiCall.result_report(attributes) end |
#success? ⇒ Boolean
Whether the command validated and ran successfully.
51 52 53 |
# File 'app/services/report/kpi_call/kpi_call_command.rb', line 51 def success? valid? && @result.success? end |
#to_csv ⇒ String
Render the report rows as CSV.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/services/report/kpi_call/kpi_call_command.rb', line 34 def to_csv return unless valid? @result = Report::KpiCall::KpiCall.result_report(attributes) return if @result.data_csv.blank? attributes = @result.data_csv.first.keys CSV.generate(headers: true) do |csv| csv << attributes @result.data_csv.each do |r| csv << r end end end |