57 lines
2.5 KiB
Ruby
57 lines
2.5 KiB
Ruby
#encoding: utf-8
|
|
module ContestantWorksHelper
|
|
|
|
def get_status status
|
|
str = ""
|
|
case status
|
|
when 0
|
|
str = "未提交"
|
|
when 1
|
|
str = "已提交"
|
|
when 2
|
|
str = "迟交"
|
|
end
|
|
str
|
|
end
|
|
|
|
#成绩计算
|
|
def set_final_score contestwork, contestant_work
|
|
if contestwork.online_evaluation
|
|
if contestwork.score_valid
|
|
if ContestantWorkScore.find_by_sql("SELECT * FROM (SELECT * FROM contestant_work_scores WHERE contestant_work_id = #{contestant_work.id} AND reviewer_role = 2 ORDER BY created_at DESC) AS t GROUP BY user_id").count < 2
|
|
judge_score = ContestantWorkScore.find_by_sql("SELECT AVG(score) AS score FROM (SELECT * FROM (SELECT * FROM contestant_work_scores WHERE contestant_work_id = #{contestant_work.id} AND reviewer_role = 2 ORDER BY created_at DESC) AS t GROUP BY user_id) AS a")
|
|
else
|
|
judge_score = ContestantWorkScore.find_by_sql("SELECT (SUM(score)-MIN(score)-MAX(score))/(COUNT(score)-2) AS score FROM (SELECT * FROM (SELECT * FROM contestant_work_scores WHERE contestant_work_id = #{contestant_work.id} AND reviewer_role = 2 ORDER BY created_at DESC) AS t GROUP BY user_id) AS a")
|
|
end
|
|
@work.work_score = judge_score.first.score.try(:round, 2).to_f
|
|
else
|
|
judge_score = ContestantWorkScore.find_by_sql("SELECT AVG(score) AS score FROM (SELECT * FROM (SELECT * FROM contestant_work_scores WHERE contestant_work_id = #{contestant_work.id} AND reviewer_role = 2 ORDER BY created_at DESC) AS t GROUP BY user_id) AS a")
|
|
@work.work_score = judge_score.first.score.try(:round, 2).to_f
|
|
end
|
|
else
|
|
contestant_work.work_score = nil
|
|
end
|
|
end
|
|
|
|
#获取学生作品的评分记录:同一个评委只显示最后一次评分
|
|
def contestant_work_score_record work
|
|
sql = "SELECT MAX(id) id FROM contestant_work_scores WHERE reviewer_role = 2 AND score IS NOT NULL AND contestant_work_id = #{work.id} GROUP BY user_id"
|
|
tea_ts_ids = ContestantWorkScore.find_by_sql sql
|
|
tea_ts_ids = tea_ts_ids.empty? ? "(-1)" : "(" + tea_ts_ids.map{|tea| tea.id}.join(",") + ")"
|
|
scores = work.contestant_work_scores.where("score IS NULL or reviewer_role = 3 or id in #{tea_ts_ids}").order("updated_at desc")
|
|
return scores
|
|
end
|
|
|
|
#获取指定评分的角色
|
|
def student_work_score_role score
|
|
case score.reviewer_role
|
|
when 1
|
|
role = "管理员"
|
|
when 2
|
|
role = "评委"
|
|
when 3
|
|
role = "参赛者"
|
|
end
|
|
end
|
|
end
|