diff --git a/app/models/exercise.rb b/app/models/exercise.rb index 37e421a7..0f691fde 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -107,7 +107,7 @@ class Exercise < ActiveRecord::Base (created_at - lag(created_at) over (PARTITION BY user_id ORDER BY created_at)) AS working_time FROM submissions - WHERE exercise_id=#{id} and user_id=#{user_id}) AS foo) AS bar + WHERE exercise_id=#{id} and user_id=#{user_id} and user_type='ExternalUser') AS foo) AS bar """).first["working_time"] end @@ -172,8 +172,12 @@ class Exercise < ActiveRecord::Base end private :generate_token - def maximum_score - files.teacher_defined_tests.sum(:weight) + def maximum_score(*user) + if user + submissions.where(user: user, cause: "assess").where("score IS NOT NULL").order("score DESC").first.score || 0 rescue 0 + else + files.teacher_defined_tests.sum(:weight) + end end def set_default_values diff --git a/app/models/proxy_exercise.rb b/app/models/proxy_exercise.rb index 2bf3658b..2efa8962 100644 --- a/app/models/proxy_exercise.rb +++ b/app/models/proxy_exercise.rb @@ -43,8 +43,22 @@ class ProxyExercise < ActiveRecord::Base exercises.shuffle.first end + # [score][quantile] + def scoring_matrix + [ + [0 ,0 ,0 ,0 ,0 ], + [0.2,0.2,0.2,0.2,0.1], + [0.5,0.5,0.4,0.4,0.3], + [0.6,0.6,0.5,0.5,0.4], + [1 ,1 ,0.9,0.8,0.7], + ] + end + def score(user, ex) - 1 + points_ratio = ex.maximum_score(user) / ex.maximum_score.to_f + working_time_user = Time.parse(ex.average_working_time_for_only(user.id) || "00:00:00") + scoring_matrix = scoring_matrix + end def getRelativeKnowledgeLoss(user, execises)