Only ask for feedback from fast users if they achieved an above-average score

This commit is contained in:
Maximilian Grundke
2018-02-26 19:54:11 +01:00
parent 0ba94574b5
commit 73929512c6
2 changed files with 8 additions and 3 deletions

View File

@ -69,14 +69,17 @@ class Exercise < ActiveRecord::Base
"
SELECT user_id,
user_type,
sum(working_time_new) AS working_time
SUM(working_time_new) AS working_time,
MAX(score) AS score
FROM
(SELECT user_id,
user_type,
score,
CASE WHEN working_time >= '0:05:00' THEN '0' ELSE working_time END AS working_time_new
FROM
(SELECT user_id,
user_type,
score,
id,
(created_at - lag(created_at) over (PARTITION BY user_id, exercise_id
ORDER BY created_at)) AS working_time