Extract WORKING_TIME_DELTA to be used globally and set it to 5 min.

This commit is contained in:
Sebastian Serth
2019-03-05 18:23:33 +01:00
parent 26c2069e02
commit 114f77e799
8 changed files with 12 additions and 9 deletions

View File

@ -40,7 +40,7 @@ class ExecutionEnvironmentsController < ApplicationController
FROM FROM
(SELECT user_id, (SELECT user_id,
exercise_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 FROM
(SELECT user_id, (SELECT user_id,
exercise_id, exercise_id,

View File

@ -343,7 +343,7 @@ class ExercisesController < ApplicationController
@all_events = (@submissions + interventions).sort_by { |a| a.created_at } @all_events = (@submissions + interventions).sort_by { |a| a.created_at }
@deltas = @all_events.map.with_index do |item, index| @deltas = @all_events.map.with_index do |item, index|
delta = item.created_at - @all_events[index - 1].created_at if index > 0 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 end
@working_times_until = [] @working_times_until = []
@all_events.each_with_index do |_, index| @all_events.each_with_index do |_, index|

View File

@ -27,7 +27,7 @@ class ExternalUsersController < ApplicationController
score, score,
id, id,
CASE CASE
WHEN working_time >= '0:05:00' THEN '0' WHEN working_time >= #{StatisticsHelper::WORKING_TIME_DELTA_IN_SQL_INTERVAL} THEN '0'
ELSE working_time ELSE working_time
END AS working_time_new END AS working_time_new
FROM FROM

View File

@ -1,5 +1,8 @@
module StatisticsHelper 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 def statistics_data
[ [
{ {

View File

@ -76,7 +76,7 @@ class Exercise < ApplicationRecord
(SELECT user_id, (SELECT user_id,
user_type, user_type,
score, 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 FROM
(SELECT user_id, (SELECT user_id,
user_type, user_type,
@ -180,7 +180,7 @@ class Exercise < ApplicationRecord
exercise_id, exercise_id,
max_score, max_score,
CASE CASE
WHEN working_time >= '0:05:00' THEN '0' WHEN working_time >= #{StatisticsHelper::WORKING_TIME_DELTA_IN_SQL_INTERVAL} THEN '0'
ELSE working_time ELSE working_time
END AS working_time_new END AS working_time_new
FROM all_working_times_until_max ), result AS FROM all_working_times_until_max ), result AS
@ -274,7 +274,7 @@ class Exercise < ApplicationRecord
FILTERED_TIMES_UNTIL_MAX AS 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 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 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

View File

@ -58,7 +58,7 @@ h1 = "#{@exercise} (external user #{@external_user})"
td = td =
td = td =
td = @working_times_until[index] if index > 0 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); .d-none#wtimes data-working_times=ActiveSupport::JSON.encode(@working_times_until);
div#progress_chart.col-lg-12 div#progress_chart.col-lg-12
.graph-functions-2 .graph-functions-2

View File

@ -378,7 +378,7 @@ de:
score: Punktzahl score: Punktzahl
tests: Unit Tests tests: Unit Tests
time_difference: 'Arbeitszeit bis hier*' 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: proxy_exercises:
index: index:
clone: Duplizieren clone: Duplizieren

View File

@ -378,7 +378,7 @@ en:
score: Score score: Score
tests: Unit Test Results tests: Unit Test Results
time_difference: 'Working Time until here*' time_difference: 'Working Time until here*'
addendum: '* Deltas longer than 10 minutes are ignored.' addendum: "* Deltas longer than %{delta} minutes are ignored."
proxy_exercises: proxy_exercises:
index: index:
clone: Duplicate clone: Duplicate