Fix statistics for empty collections and exercises without submissions

This commit is contained in:
Maximilian Grundke
2018-03-21 15:35:59 +01:00
parent 4f9cbf91a1
commit 28a3fa3a86

View File

@ -13,7 +13,12 @@ class ExerciseCollection < ActiveRecord::Base
end
def average_working_time
exercise_working_times.values.reduce(:+) / exercises.size
if exercises.empty?
0
else
values = exercise_working_times.values.reject { |v| v.nil?}
values.reduce(:+) / exercises.size
end
end
def to_s