socialforge/app/helpers/contestant_works_helper.rb

55 lines
1.9 KiB
Ruby

#encoding: utf-8
module ContestantWorksHelper
def get_contest_new_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
contestant_work.work_score = contestant_work.judge_score
else
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
contestant_work.work_score = contestant_work.judge_score
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")
contestant_work.work_score = judge_score.first.score.try(:round, 2).to_f
end
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
scores = work.contestant_work_scores.where(:id => tea_ts_ids.map{|tea| tea.id}).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