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

Get last status by employee.

Parameters:

  • employee_id (Integer)
  • start_time (Object) (defaults to: Date.current.beginning_of_day)
  • end_time (Object) (defaults to: Date.current.end_of_day)

Returns:

  • (Object)


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

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

Get statuses from range.

Parameters:

  • start_time (Object) (defaults to: Date.current.beginning_of_day)
  • end_time (Object) (defaults to: Date.current.end_of_day)

Returns:

  • (Object)


11
12
13
14
15
16
17
18
19
# File 'app/services/report/status_timeline_report.rb', line 11

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