Class: Report::StatusTimelineReport

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

Overview

Aggregates EmployeePhoneStatusChange rows into per-employee presence
timelines: the full timeline for the Switchboard chart, or just the
bucketed time-on-status durations for the inline DND-duration display
shown on each employee's presence dropdown.

Class Method Summary collapse

Class Method Details

.get_last_status_by_employee(employee_id, start_time = Date.current.beginning_of_day, end_time = Date.current.end_of_day) ⇒ Object



16
17
18
19
20
21
22
# File 'app/services/report/status_timeline_report.rb', line 16

def self.get_last_status_by_employee(employee_id, start_time = Date.current.beginning_of_day, end_time = Date.current.end_of_day)
  effective_end = effective_end_for(end_time)

  grouped_changes(start_time, effective_end, employee_id: employee_id)
    .each_value
    .flat_map { |eps_changes| durations_for(eps_changes, effective_end) }
end

.get_statuses_from_range(start_time = Date.current.beginning_of_day, end_time = Date.current.end_of_day) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'app/services/report/status_timeline_report.rb', line 6

def self.get_statuses_from_range(start_time = Date.current.beginning_of_day, end_time = Date.current.end_of_day)
  effective_end = effective_end_for(end_time)

  data = grouped_changes(start_time, effective_end).map do |eps, eps_changes|
    { label: eps.employee.full_name, times: time_ranges_for(eps_changes, effective_end) }
  end

  { data: data, start_time: start_time, end_time: effective_end }
end