Visualize exercise working times in exercise collection statstics

This commit is contained in:
Maximilian Grundke
2018-03-19 18:17:34 +01:00
parent 36d0c2839d
commit d55b39eb48
4 changed files with 134 additions and 2 deletions

View File

@ -4,12 +4,16 @@ class ExerciseCollection < ActiveRecord::Base
has_and_belongs_to_many :exercises
belongs_to :user, polymorphic: true
def average_working_time
def exercise_working_times
working_times = {}
exercises.each do |exercise|
working_times[exercise.id] = time_to_f exercise.average_working_time
end
working_times.values.reduce(:+) / working_times.size
working_times
end
def average_working_time
exercise_working_times.values.reduce(:+) / exercises.size
end
def to_s