Scaffold exercise collection statistics

This commit is contained in:
Maximilian Grundke
2018-03-14 11:44:18 +01:00
parent be2a4d84fd
commit 119cc9ee71
5 changed files with 27 additions and 3 deletions

View File

@ -1,7 +1,8 @@
class ExerciseCollectionsController < ApplicationController
include CommonBehavior
include TimeHelper
before_action :set_exercise_collection, only: [:show, :edit, :update, :destroy]
before_action :set_exercise_collection, only: [:show, :edit, :update, :destroy, :statistics]
def index
@exercise_collections = ExerciseCollection.all.paginate(:page => params[:page])
@ -34,6 +35,14 @@ class ExerciseCollectionsController < ApplicationController
update_and_respond(object: @exercise_collection, params: exercise_collection_params)
end
def statistics
@working_times = {}
@exercise_collection.exercises.each do |exercise|
@working_times[exercise.id] = time_to_f exercise.average_working_time
end
@average = @working_times.values.reduce(:+) / @working_times.size
end
private
def set_exercise_collection