Class: TempestTime::Models::Report

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::FormattingHelper

#braced, #with_percent_sign

Constructor Details

#initialize(user:, worklogs:, required_seconds:, internal_projects:, number_of_users: 1) ⇒ Report

Returns a new instance of Report.



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

def initialize(user:, worklogs:, required_seconds:, internal_projects:, number_of_users: 1)
  @user = user
  @worklogs = worklogs
  @number_of_users = number_of_users
  @required_seconds = required_seconds * number_of_users
  @internal_projects = internal_projects
end

Instance Attribute Details

#internal_projectsObject (readonly)

Returns the value of attribute internal_projects.



7
8
9
# File 'lib/tempest_time/models/report.rb', line 7

def internal_projects
  @internal_projects
end

#number_of_usersObject (readonly)

Returns the value of attribute number_of_users.



7
8
9
# File 'lib/tempest_time/models/report.rb', line 7

def number_of_users
  @number_of_users
end

#required_secondsObject (readonly)

Returns the value of attribute required_seconds.



7
8
9
# File 'lib/tempest_time/models/report.rb', line 7

def required_seconds
  @required_seconds
end

#userObject (readonly)

Returns the value of attribute user.



7
8
9
# File 'lib/tempest_time/models/report.rb', line 7

def user
  @user
end

#worklogsObject (readonly)

Returns the value of attribute worklogs.



7
8
9
# File 'lib/tempest_time/models/report.rb', line 7

def worklogs
  @worklogs
end

Instance Method Details

#compliance_percentage(time) ⇒ Object



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

def compliance_percentage(time)
  time.to_f / required_seconds
end

#project_compliance_percentagesObject



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

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



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

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

#project_worklogsObject



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

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

#projectsObject



57
58
59
# File 'lib/tempest_time/models/report.rb', line 57

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

#time_logged_seconds(logs) ⇒ Object



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

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

#total_compliance_percentageObject



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

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

#total_seconds_loggedObject



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

def total_seconds_logged
  @total_seconds_logged ||= time_logged_seconds(worklogs)
end

#utilization_percentageObject



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

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