diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be79..e2f9d7a 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,19 @@ module ApplicationHelper + def humanise_duration(duration) + raise ArgumentError, "Duration must be a number" unless duration.is_a? ActiveSupport::Duration + + seconds = duration.in_seconds + minutes = seconds / 60 + hours = minutes / 60 + + remaining_minutes = minutes % 60 + + if hours > 0 + "#{hours.floor}h #{remaining_minutes.floor}m" + elsif minutes > 0 + "#{remaining_minutes.floor} minutes" + else + "#{seconds}s" + end + end end diff --git a/app/models/lecture.rb b/app/models/lecture.rb index f761a67..92e6a9a 100644 --- a/app/models/lecture.rb +++ b/app/models/lecture.rb @@ -25,6 +25,10 @@ class Lecture < ApplicationRecord tracked_time_entries.preparation.sum(&:duration).seconds end + def total_overall_time + tracked_time_entries.sum(&:duration).seconds + end + def total_attendance_time tracked_time_entries.where(kind: [:concurrent, :catchup]).sum(&:duration).seconds end diff --git a/app/views/attendance_tracker/index.html.erb b/app/views/attendance_tracker/index.html.erb index d0b9079..c841344 100644 --- a/app/views/attendance_tracker/index.html.erb +++ b/app/views/attendance_tracker/index.html.erb @@ -22,7 +22,19 @@ <% course.lectures.order(:start_time).group_by { |lecture| lecture.week_number }.each do |(week_number, lectures)| %> - Week <%= week_number %> + +
+
+ Week <%= week_number %> +
+ +
+ <%# TODO: Improve this figure, atm it is for lectures in week, not time spent in week (ie + prepping for lecture next week will count in next week not current week) %> + (Total <%= humanise_duration(lectures.sum { |lecture| lecture.total_overall_time }.seconds) %>) +
+
+ <% lectures.reject(&:cancelled).each do |lecture| %> @@ -72,17 +84,19 @@