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

@ -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