Class: TempestTime::Models::Report

Inherits:
Object
  • Object
show all
Includes:
Helpers::FormattingHelper
Defined in:
lib/tempest_time/models/report.rb

Constant Summary collapse

EXPECTED_SECONDS =
(37.5 * 60 * 60).to_i.freeze
INTERNAL_PROJECT =
'BCIT'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::FormattingHelper

#braced, #with_percent_sign

Constructor Details

#initialize(user, worklogs, number_of_users = 1) ⇒ Report

Returns a new instance of Report.



12
13
14
15
16
# File 'lib/tempest_time/models/report.rb', line 12

def initialize(user, worklogs, number_of_users = 1)
  @user = user
  @worklogs = worklogs
  @number_of_users = number_of_users
end

Instance Attribute Details

#number_of_usersObject (readonly)

Returns the value of attribute number_of_users.



10
11
12
# File 'lib/tempest_time/models/report.rb', line 10

def number_of_users
  @number_of_users
end

#userObject (readonly)

Returns the value of attribute user.



10
11
12
# File 'lib/tempest_time/models/report.rb', line 10

def user
  @user
end

#worklogsObject (readonly)

Returns the value of attribute worklogs.



10
11
12
# File 'lib/tempest_time/models/report.rb', line 10

def worklogs
  @worklogs
end

Instance Method Details

#compliance_percentage(time) ⇒ Object



24
25
26
# File 'lib/tempest_time/models/report.rb', line 24

def compliance_percentage(time)
  (time.to_f / (EXPECTED_SECONDS * number_of_users)).round(2)
end

#project_compliance_percentagesObject



28
29
30
31
32
# File 'lib/tempest_time/models/report.rb', line 28

def project_compliance_percentages
  @project_compliance_percentages ||= project_total_times.map do |project, time|
    [project, compliance_percentage(time)]
  end.to_h.sort
end

#project_total_timesObject



18
19
20
21
22
# File 'lib/tempest_time/models/report.rb', line 18

def project_total_times
  @project_total_times ||= project_worklogs.map do |project, worklogs|
    [project, time_logged_seconds(worklogs)]
  end.to_h
end

#project_worklogsObject



49
50
51
# File 'lib/tempest_time/models/report.rb', line 49

def project_worklogs
  @project_worklogs ||= worklogs.group_by(&:project)
end

#projectsObject



53
54
55
# File 'lib/tempest_time/models/report.rb', line 53

def projects
  @projects ||= project_worklogs.keys.sort
end

#time_logged_seconds(logs) ⇒ Object



45
46
47
# File 'lib/tempest_time/models/report.rb', line 45

def time_logged_seconds(logs)
  logs.flat_map(&:seconds).reduce(:+)
end

#total_compliance_percentageObject



34
35
36
# File 'lib/tempest_time/models/report.rb', line 34

def total_compliance_percentage
  @total_compliance_percentage ||= compliance_percentage(time_logged_seconds(worklogs))
end

#utilization_percentageObject



38
39
40
41
42
43
# File 'lib/tempest_time/models/report.rb', line 38

def utilization_percentage
  @utilization_percentage ||= project_compliance_percentages.inject(0) do |memo, (project, percentage)|
    memo += percentage unless project == INTERNAL_PROJECT
    memo
  end
end