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

View File

@ -147,9 +147,11 @@ namespace :detect_exercise_anomalies do
def performers_by_time(exercise, n)
working_times = get_user_working_times(exercise).values.map do |item|
{user_id: item['user_id'], user_type: item['user_type'], value: time_to_f(item['working_time']), reason: 'time'}
{user_id: item['user_id'], user_type: item['user_type'], score: item['score'].to_f,
value: time_to_f(item['working_time']), reason: 'time'}
end
working_times.reject! {|item| item[:value].nil? or item[:value] <= MIN_USER_WORKING_TIME}
avg_score = exercise.average_score
working_times.reject! {|item| item[:value].nil? or item[:value] <= MIN_USER_WORKING_TIME or item[:score] < avg_score}
working_times.sort_by! {|item| item[:value]}
return {:best => working_times.first(n), :worst => working_times.last(n)}
end