Fix working time statistics for internal and external users

This commit is contained in:
Sebastian Serth
2022-01-20 23:41:32 +01:00
parent 11fc31877f
commit ba11adb966
3 changed files with 7 additions and 7 deletions

View File

@ -372,11 +372,11 @@ class Exercise < ApplicationRecord
end
def retrieve_working_time_statistics
@working_time_statistics = {}
@working_time_statistics = {'InternalUser' => {}, 'ExternalUser' => {}}
ActiveRecord::Base.transaction do
self.class.connection.execute("SET LOCAL intervalstyle = 'postgres'")
self.class.connection.execute(user_working_time_query).each do |tuple|
@working_time_statistics[tuple['user_id'].to_i] = tuple
@working_time_statistics[tuple['user_type']][tuple['user_id'].to_i] = tuple
end
end
end
@ -392,9 +392,9 @@ class Exercise < ApplicationRecord
end
end
def average_working_time_for(user_id)
def average_working_time_for(user)
retrieve_working_time_statistics if @working_time_statistics.nil?
@working_time_statistics[user_id]['working_time']
@working_time_statistics[user.class.name][user.id]['working_time']
end
def accumulated_working_time_for_only(user)

View File

@ -32,7 +32,7 @@ h1 = link_to_if(policy(@exercise).show?, @exercise, exercise_path(@exercise))
.card-footer
div.clearfix.feedback-header
span.points.flex-grow-1 = "#{t('exercises.statistics.score')}: #{@submissions[index].score}"
span.working_time.pull-right = "#{t('exercises.statistics.worktime')}: #{@exercise.average_working_time_for(feedback.user.id) or 0}"
span.working_time.pull-right = "#{t('exercises.statistics.worktime')}: #{@exercise.average_working_time_for(feedback.user) or 0}"
= render('shared/pagination', collection: @feedbacks)

View File

@ -48,7 +48,7 @@ h1 = @exercise
- if symbol==:external_users
- working_time_array = []
- @exercise.send(symbol).distinct().each do |user|
- working_time = @exercise.average_working_time_for(user.id) or 0
- working_time = @exercise.average_working_time_for(user) or 0
- working_time_array.push working_time
hr
.d-none#data data-working-time=ActiveSupport::JSON.encode(working_time_array)
@ -88,4 +88,4 @@ h1 = @exercise
- elsif latest_user_submission.after_late_deadline?
.unit-test-result.negative-result.after_late_deadline
td = us['runs'] if policy(@exercise).detailed_statistics?
td = @exercise.average_working_time_for(user.id) or 0 if policy(@exercise).detailed_statistics?
td = @exercise.average_working_time_for(user) or 0 if policy(@exercise).detailed_statistics?