From eb2b18a22fa0050ac0805d3cf9f67f345b1d16df Mon Sep 17 00:00:00 2001 From: Maximilian Grundke Date: Tue, 10 Apr 2018 14:15:35 +0200 Subject: [PATCH 1/2] Highlight gaps in exercise working time --- app/assets/stylesheets/statistics.css.scss | 4 ++ app/controllers/exercises_controller.rb | 10 +++++ .../external_users/statistics.html.slim | 38 ++++++++----------- config/locales/de.yml | 2 +- config/locales/en.yml | 2 +- 5 files changed, 32 insertions(+), 24 deletions(-) diff --git a/app/assets/stylesheets/statistics.css.scss b/app/assets/stylesheets/statistics.css.scss index 9ce3d61f..13828f4e 100644 --- a/app/assets/stylesheets/statistics.css.scss +++ b/app/assets/stylesheets/statistics.css.scss @@ -58,6 +58,10 @@ div.negative-result { box-shadow: 0px 0px 11px 1px rgba(222,0,0,1); } +tr.highlight { + border-top: 2px solid rgba(222,0,0,1); +} + ///////////////////////////////////////////////////////////////////////////////////////////// // StatisticsController: diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 7d4d2c43..a41a5794 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -326,6 +326,16 @@ 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 + 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)) + end render 'exercises/external_users/statistics' else user_statistics = {} diff --git a/app/views/exercises/external_users/statistics.html.slim b/app/views/exercises/external_users/statistics.html.slim index 06132754..4a1e7b77 100644 --- a/app/views/exercises/external_users/statistics.html.slim +++ b/app/views/exercises/external_users/statistics.html.slim @@ -1,19 +1,16 @@ h1 = "#{@exercise} (external user #{@external_user})" -- submissions = Submission.where("user_id = ? AND exercise_id = ?", @external_user.id, @exercise.id).order("created_at") -- current_submission = submissions.first -- submissions_and_interventions = (submissions + UserExerciseIntervention.where("user_id = ? AND exercise_id = ?", @external_user.id, @exercise.id)).sort_by { |a| a.created_at } - +- current_submission = @submissions.first - if current_submission - initial_files = current_submission.files.to_a - all_files = [] - file_types = Set.new() - - submissions.each do |submission| + - @submissions.each do |submission| - submission.files.each do |file| - file_types.add(ActiveSupport::JSON.encode(file.file_type)) - all_files.push(submission.files) - .hidden#data data-submissions=ActiveSupport::JSON.encode(submissions) data-files=ActiveSupport::JSON.encode(all_files) data-file-types=ActiveSupport::JSON.encode(file_types) + .hidden#data data-submissions=ActiveSupport::JSON.encode(@submissions) data-files=ActiveSupport::JSON.encode(all_files) data-file-types=ActiveSupport::JSON.encode(file_types) #stats-editor.row - index = 0 @@ -27,14 +24,13 @@ h1 = "#{@exercise} (external user #{@external_user})" button.btn.btn-default id='play-button' span.fa.fa-play #submissions-slider.flex-item - input type='range' orient='horizontal' list='datapoints' min=0 max=submissions.length-1 value=0 + input type='range' orient='horizontal' list='datapoints' min=0 max=@submissions.length-1 value=0 datalist#datapoints - index=0 - - submissions.each do |submission| + - @submissions.each do |submission| option data-submission=submission =index - index += 1 - - working_times_until = Array.new #timeline .table-responsive table.table @@ -43,28 +39,26 @@ h1 = "#{@exercise} (external user #{@external_user})" - ['.time', '.cause', '.score', '.tests', '.time_difference'].each do |title| th.header = t(title) tbody - - deltas = submissions.map.with_index {|item, index| delta = item.created_at - submissions[index - 1].created_at if index > 0; if delta == nil or delta > 10*60 then 0 else delta end} - - submissions_and_interventions.each_with_index do |submission_or_intervention, index| - tr data-id=submission_or_intervention.id - td.clickable = submission_or_intervention.created_at.strftime("%F %T") - - if submission_or_intervention.is_a?(Submission) - td = submission_or_intervention.cause - td = submission_or_intervention.score + - @submissions_and_interventions.each_with_index do |this, index| + tr data-id=this.id class=('highlight' if index > 0 and @working_times_until[index] == @working_times_until[index - 1]) + td.clickable = this.created_at.strftime("%F %T") + - if this.is_a?(Submission) + td = this.cause + td = this.score td - -submission_or_intervention.testruns.each do |run| + -this.testruns.each do |run| - if run.passed .unit-test-result.positive-result title=run.output - else .unit-test-result.unknown-result title=run.output - td = Time.at(deltas[1..index].inject(:+)).utc.strftime("%H:%M:%S") if index > 0 - -working_times_until.push((Time.at(deltas[1..index].inject(:+)).utc.strftime("%H:%M:%S") if index > 0)) - - elsif submission_or_intervention.is_a? UserExerciseIntervention - td = submission_or_intervention.intervention.name + td = @working_times_until[index] if index > 0 + - elsif this.is_a? UserExerciseIntervention + td = this.intervention.name td = td = td = p = t('.addendum') - .hidden#wtimes data-working_times=ActiveSupport::JSON.encode(working_times_until); + .hidden#wtimes data-working_times=ActiveSupport::JSON.encode(@working_times_until); div#progress_chart.col-lg-12 .graph-functions-2 diff --git a/config/locales/de.yml b/config/locales/de.yml index 05c7108e..24c50862 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -363,7 +363,7 @@ de: score: Punktzahl tests: Unit Tests time_difference: 'Arbeitszeit bis hier*' - addendum: '* Differenzen von mehr als 30 Minuten werden ignoriert.' + addendum: '* Differenzen von mehr als 10 Minuten werden ignoriert.' proxy_exercises: index: clone: Duplizieren diff --git a/config/locales/en.yml b/config/locales/en.yml index 5d6ada43..f1cc211f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -363,7 +363,7 @@ en: score: Score tests: Unit Test Results time_difference: 'Working Time until here*' - addendum: '* Deltas longer than 30 minutes are ignored.' + addendum: '* Deltas longer than 10 minutes are ignored.' proxy_exercises: index: clone: Duplicate From f2f4419bb8df20f4ab19c3b06da4162511dcc8ad Mon Sep 17 00:00:00 2001 From: Maximilian Grundke Date: Tue, 10 Apr 2018 14:23:23 +0200 Subject: [PATCH 2/2] Don't highlight submissions within the same second --- app/views/exercises/external_users/statistics.html.slim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/exercises/external_users/statistics.html.slim b/app/views/exercises/external_users/statistics.html.slim index 4a1e7b77..7d00f3b1 100644 --- a/app/views/exercises/external_users/statistics.html.slim +++ b/app/views/exercises/external_users/statistics.html.slim @@ -40,7 +40,8 @@ h1 = "#{@exercise} (external user #{@external_user})" th.header = t(title) tbody - @submissions_and_interventions.each_with_index do |this, index| - tr data-id=this.id class=('highlight' if index > 0 and @working_times_until[index] == @working_times_until[index - 1]) + - highlight = (index > 0 and @working_times_until[index] == @working_times_until[index - 1] and this.created_at > @submissions_and_interventions[index - 1].created_at) + tr data-id=this.id class=('highlight' if highlight) td.clickable = this.created_at.strftime("%F %T") - if this.is_a?(Submission) td = this.cause