From 114f77e7990715fcc8688ad812db4c0694f27a01 Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Tue, 5 Mar 2019 18:23:33 +0100 Subject: [PATCH] Extract WORKING_TIME_DELTA to be used globally and set it to 5 min. --- app/controllers/execution_environments_controller.rb | 2 +- app/controllers/exercises_controller.rb | 2 +- app/controllers/external_users_controller.rb | 2 +- app/helpers/statistics_helper.rb | 3 +++ app/models/exercise.rb | 6 +++--- app/views/exercises/external_users/statistics.html.slim | 2 +- config/locales/de.yml | 2 +- config/locales/en.yml | 2 +- 8 files changed, 12 insertions(+), 9 deletions(-) diff --git a/app/controllers/execution_environments_controller.rb b/app/controllers/execution_environments_controller.rb index 917c9f5f..cf2160d8 100644 --- a/app/controllers/execution_environments_controller.rb +++ b/app/controllers/execution_environments_controller.rb @@ -40,7 +40,7 @@ class ExecutionEnvironmentsController < ApplicationController FROM (SELECT user_id, exercise_id, - CASE WHEN working_time >= '0:05:00' THEN '0' ELSE working_time END AS working_time_new + CASE WHEN working_time >= #{StatisticsHelper::WORKING_TIME_DELTA_IN_SQL_INTERVAL} THEN '0' ELSE working_time END AS working_time_new FROM (SELECT user_id, exercise_id, diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index c5efa532..20c18f8e 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -343,7 +343,7 @@ class ExercisesController < ApplicationController @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 + if delta == nil or delta > StatisticsHelper::WORKING_TIME_DELTA_IN_SECONDS then 0 else delta end end @working_times_until = [] @all_events.each_with_index do |_, index| diff --git a/app/controllers/external_users_controller.rb b/app/controllers/external_users_controller.rb index 503d323f..091c6716 100644 --- a/app/controllers/external_users_controller.rb +++ b/app/controllers/external_users_controller.rb @@ -27,7 +27,7 @@ class ExternalUsersController < ApplicationController score, id, CASE - WHEN working_time >= '0:05:00' THEN '0' + WHEN working_time >= #{StatisticsHelper::WORKING_TIME_DELTA_IN_SQL_INTERVAL} THEN '0' ELSE working_time END AS working_time_new FROM diff --git a/app/helpers/statistics_helper.rb b/app/helpers/statistics_helper.rb index fdec56fb..4b4ac79c 100644 --- a/app/helpers/statistics_helper.rb +++ b/app/helpers/statistics_helper.rb @@ -1,5 +1,8 @@ module StatisticsHelper + WORKING_TIME_DELTA_IN_SECONDS = 5.minutes + WORKING_TIME_DELTA_IN_SQL_INTERVAL = "'0:05:00'" # yes, a string with quotes + def statistics_data [ { diff --git a/app/models/exercise.rb b/app/models/exercise.rb index 67f2a0a0..7c63f7cf 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -76,7 +76,7 @@ class Exercise < ApplicationRecord (SELECT user_id, user_type, score, - CASE WHEN working_time >= '0:05:00' THEN '0' ELSE working_time END AS working_time_new + CASE WHEN working_time >= #{StatisticsHelper::WORKING_TIME_DELTA_IN_SQL_INTERVAL} THEN '0' ELSE working_time END AS working_time_new FROM (SELECT user_id, user_type, @@ -180,7 +180,7 @@ class Exercise < ApplicationRecord exercise_id, max_score, CASE - WHEN working_time >= '0:05:00' THEN '0' + WHEN working_time >= #{StatisticsHelper::WORKING_TIME_DELTA_IN_SQL_INTERVAL} THEN '0' ELSE working_time END AS working_time_new FROM all_working_times_until_max ), result AS @@ -274,7 +274,7 @@ class Exercise < ApplicationRecord FILTERED_TIMES_UNTIL_MAX AS ( - SELECT user_id,exercise_id, max_score, CASE WHEN working_time >= '0:05:00' THEN '0' ELSE working_time END AS working_time_new + SELECT user_id,exercise_id, max_score, CASE WHEN working_time >= #{StatisticsHelper::WORKING_TIME_DELTA_IN_SQL_INTERVAL} THEN '0' ELSE working_time END AS working_time_new FROM ALL_WORKING_TIMES_UNTIL_MAX ) SELECT e.external_id AS external_user_id, f.user_id, exercise_id, MAX(max_score) AS max_score, sum(working_time_new) AS working_time diff --git a/app/views/exercises/external_users/statistics.html.slim b/app/views/exercises/external_users/statistics.html.slim index e89627ed..9b97ccfe 100644 --- a/app/views/exercises/external_users/statistics.html.slim +++ b/app/views/exercises/external_users/statistics.html.slim @@ -58,7 +58,7 @@ h1 = "#{@exercise} (external user #{@external_user})" td = td = td = @working_times_until[index] if index > 0 - p = t('.addendum') + p = t('.addendum', delta: StatisticsHelper::WORKING_TIME_DELTA_IN_SECONDS / 60) .d-none#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 630e8e80..f4ce9646 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -378,7 +378,7 @@ de: score: Punktzahl tests: Unit Tests time_difference: 'Arbeitszeit bis hier*' - addendum: '* Differenzen von mehr als 10 Minuten werden ignoriert.' + addendum: '* Differenzen von mehr als %{delta} Minuten werden ignoriert.' proxy_exercises: index: clone: Duplizieren diff --git a/config/locales/en.yml b/config/locales/en.yml index c48530e6..cff5899d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -378,7 +378,7 @@ en: score: Score tests: Unit Test Results time_difference: 'Working Time until here*' - addendum: '* Deltas longer than 10 minutes are ignored.' + addendum: "* Deltas longer than %{delta} minutes are ignored." proxy_exercises: index: clone: Duplicate