diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 8855228e..b506afdf 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -3,6 +3,7 @@ class ExercisesController < ApplicationController include Lti include SubmissionParameters include SubmissionScoring + include TimeHelper before_action :handle_file_uploads, only: [:create, :update] before_action :set_execution_environments, only: [:create, :edit, :new, :update] @@ -347,14 +348,15 @@ class ExercisesController < ApplicationController def statistics if(@external_user) @submissions = Submission.where("user_id = ? AND exercise_id = ?", @external_user.id, @exercise.id).order("created_at") - @submissions_and_interventions = (@submissions + UserExerciseIntervention.where("user_id = ? AND exercise_id = ?", @external_user.id, @exercise.id)).sort_by { |a| a.created_at } - deltas = @submissions.map.with_index do |item, index| - delta = item.created_at - @submissions[index - 1].created_at if index > 0 + interventions = UserExerciseIntervention.where("user_id = ? AND exercise_id = ?", @external_user.id, @exercise.id) + @all_events = (@submissions + interventions).sort_by { |a| a.created_at } + @deltas = @all_events.map.with_index do |item, index| + delta = item.created_at - @all_events[index - 1].created_at if index > 0 if delta == nil or delta > 10 * 60 then 0 else delta end end @working_times_until = [] - @submissions_and_interventions.each_with_index do |submission, index| - @working_times_until.push((Time.at(deltas[1..index].inject(:+)).utc.strftime("%H:%M:%S") if index > 0)) + @all_events.each_with_index do |_, index| + @working_times_until.push((format_time_difference(@deltas[0..index].inject(:+)) if index > 0)) end render 'exercises/external_users/statistics' else diff --git a/app/helpers/time_helper.rb b/app/helpers/time_helper.rb index ed05ede5..ca93c0d8 100644 --- a/app/helpers/time_helper.rb +++ b/app/helpers/time_helper.rb @@ -9,4 +9,9 @@ module TimeHelper nil end + # given a delta in seconds, return a "Hours:Minutes:Seconds" representation + def format_time_difference(delta) + Time.at(delta).utc.strftime("%H:%M:%S") + end + end diff --git a/app/views/exercises/external_users/statistics.html.slim b/app/views/exercises/external_users/statistics.html.slim index 7d00f3b1..5d91716a 100644 --- a/app/views/exercises/external_users/statistics.html.slim +++ b/app/views/exercises/external_users/statistics.html.slim @@ -39,8 +39,8 @@ h1 = "#{@exercise} (external user #{@external_user})" - ['.time', '.cause', '.score', '.tests', '.time_difference'].each do |title| th.header = t(title) tbody - - @submissions_and_interventions.each_with_index do |this, index| - - highlight = (index > 0 and @working_times_until[index] == @working_times_until[index - 1] and this.created_at > @submissions_and_interventions[index - 1].created_at) + - @all_events.each_with_index do |this, index| + - highlight = (index > 0 and @deltas[index] == 0 and this.created_at.to_s != @all_events[index - 1].created_at.to_s) tr data-id=this.id class=('highlight' if highlight) td.clickable = this.created_at.strftime("%F %T") - if this.is_a?(Submission) @@ -49,7 +49,7 @@ h1 = "#{@exercise} (external user #{@external_user})" td -this.testruns.each do |run| - if run.passed - .unit-test-result.positive-result title=run.output + .unit-test-result.positive-result title=run.output - else .unit-test-result.unknown-result title=run.output td = @working_times_until[index] if index > 0 @@ -57,7 +57,7 @@ h1 = "#{@exercise} (external user #{@external_user})" td = this.intervention.name td = td = - td = + td = @working_times_until[index] if index > 0 p = t('.addendum') .hidden#wtimes data-working_times=ActiveSupport::JSON.encode(@working_times_until); div#progress_chart.col-lg-12