diff --git a/app/controllers/contestant_works_controller.rb b/app/controllers/contestant_works_controller.rb index fd4e3264b..777d87cd8 100644 --- a/app/controllers/contestant_works_controller.rb +++ b/app/controllers/contestant_works_controller.rb @@ -48,10 +48,13 @@ class ContestantWorksController < ApplicationController @all_homework_commons = @contest.works.order("created_at desc") @is_teacher = User.current.admin_of_contest?(@contest) || User.current.admin? @is_judge = User.current.judge_of_contest?(@contest) + @is_evaluation = @is_judge && @contestwork.work_status == 3 && @contestwork.online_evaluation @show_all = false - if @is_teacher || @is_judge + is_judge_open = @is_judge && (!@contestwork.online_evaluation || (@contestwork.online_evaluation && @contestwork.work_status == 4)) + is_contestant_open = User.current.contestant_of_contest?(@contest) && ((!@contestwork.online_evaluation && @contestwork.work_status == 2 && @contestwork.score_open) || (@contestwork.online_evaluation && @contestwork.work_status == 4 && @contestwork.score_open)) + if @is_teacher || is_judge_open || is_contestant_open # if @order == 'lastname' # @stundet_works = search_homework_member @homework.student_works.no_copy.select("student_works.*,student_works.work_score as score").joins(:user).order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, login #{@b_sort}"),@name # elsif @order == 'student_id' @@ -60,7 +63,15 @@ class ContestantWorksController < ApplicationController @stundet_works = @contestwork.contestant_works.no_copy.select("contestant_works.*,contestant_works.work_score as score").includes(:user => {:user_extensions => []}, :project => {}, :contestant_work_scores => {}).order("#{@order} #{@b_sort}") #end @show_all = true - elsif User.current.member_of_contest?(@contest) + elsif @is_evaluation + if @contestwork.work_detail_manual.evaluation_num == -1 + @stundet_works = @contestwork.contestant_works.no_copy.select("contestant_works.*,contestant_works.work_score as score").includes(:user => {:user_extensions => []}, :project => {}, :contestant_work_scores => {}).order("#{@order} #{@b_sort}") + else + @stundet_works = User.current.contestant_work_evaluation_distributions.map(&:contestant_work).select { |cwork| cwork.work_id == @contestwork.id} + end + elsif User.current.judge_of_contest?(@contest) + @stundet_works = [] + elsif User.current.contestant_of_contest?(@contest) if @contestwork.work_type == 3 pro = @contestwork.contestant_work_projects.where(:user_id => User.current.id).first if pro.nil? @@ -95,9 +106,10 @@ class ContestantWorksController < ApplicationController end def show - #@score = student_work_score @work,User.current + @score = ContestantWorkScore.where(:user_id => User.current.id,:contestant_work_id => @work.id,:reviewer_role => 2).last + @is_evaluation = User.current.judge_of_contest?(@contest) && @contestwork.work_status == 3 && @contestwork.online_evaluation @is_teacher = User.current.admin_of_contest?(@contest) || User.current.judge_of_contest?(@contest) || User.current.admin? - if @contestwork.work_status == 3 && User.current.judge_of_contest?(@contest) && @contestwork.online_evaluation + if @is_evaluation @student_work_scores = @work.contestant_work_scores.where("user_id = #{User.current.id} and reviewer_role = 2").order("updated_at desc") else @student_work_scores = contestant_work_score_record(@work) @@ -368,9 +380,10 @@ class ContestantWorksController < ApplicationController def add_score @is_last = params[:is_last] == "true" - @is_teacher = User.current.admin_of_contest?(@contest) || User.current.judge_of_contest?(@contest) || User.current.admin? + @is_evaluation = User.current.judge_of_contest?(@contest) && @contestwork.work_status == 3 && @contestwork.online_evaluation + #@is_teacher = User.current.admin_of_contest?(@contest) || User.current.judge_of_contest?(@contest) || User.current.admin? #老师、教辅可以随时评分,学生只能在匿评作业的匿评阶段进行评分 - render_403 and return unless User.current.judge_of_contest?(@contest) && @contestwork.work_status == 3 + render_403 and return unless @is_evaluation @is_last_a = @work.contestant_work_scores.empty? @new_score = ContestantWorkScore.new @new_score.score = params[:score].to_i @@ -403,6 +416,8 @@ class ContestantWorksController < ApplicationController @contestwork.update_column('updated_at', Time.now) update_contest_activity(@contestwork.class,@contestwork.id) update_user_activity(@contestwork.class,@contestwork.id) + judge_score = ContestantWorkScore.find_by_sql("SELECT AVG(score) AS score FROM (SELECT * FROM (SELECT * FROM contestant_work_scores WHERE contestant_work_id = #{@work.id} AND reviewer_role = 2 ORDER BY created_at DESC) AS t GROUP BY user_id) AS a") + @work.judge_score = judge_score.first.score.nil? ? nil : judge_score.first.score.try(:round, 2).to_f if @work.save @work = @contestwork.contestant_works.select("contestant_works.*,contestant_works.work_score as score").where(:id => @work.id).first @count = @contestwork.contestant_works.has_committed.count diff --git a/app/controllers/works_controller.rb b/app/controllers/works_controller.rb index 75a30ba57..f56703bc7 100644 --- a/app/controllers/works_controller.rb +++ b/app/controllers/works_controller.rb @@ -257,11 +257,11 @@ class WorksController < ApplicationController score_valid = params[:score_valid].to_i == 1 ? true : false if score_valid != @contestwork.score_valid @contestwork.score_valid = score_valid + @contestwork.save @contestwork.contestant_works.has_committed.each do |c_work| c_work.save end end - @contestwork.save if params[:student_path] && params[:student_path] == "true" redirect_to contestant_works_path(:work => @contestwork.id) else diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 415913e93..e7fed44fb 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -3964,6 +3964,10 @@ def get_cw_status contest_work end elsif contest_work.work_status == 2 str += '提交已截止' + elsif contest_work.work_status == 3 + str += '在线评审中' + elsif contest_work.work_status == 4 + str += '评审已截止' end str end diff --git a/app/helpers/contestant_works_helper.rb b/app/helpers/contestant_works_helper.rb index aa60c304b..bbe9394b3 100644 --- a/app/helpers/contestant_works_helper.rb +++ b/app/helpers/contestant_works_helper.rb @@ -18,15 +18,14 @@ module ContestantWorksHelper 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") + 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 - @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 diff --git a/app/models/contestant_work_score.rb b/app/models/contestant_work_score.rb index 8aa29024f..6113a84b5 100644 --- a/app/models/contestant_work_score.rb +++ b/app/models/contestant_work_score.rb @@ -2,6 +2,7 @@ class ContestantWorkScore < ActiveRecord::Base belongs_to :contestant_work belongs_to :user attr_accessible :comment, :reviewer_role, :score, :contestant_work_id, :user_id + acts_as_attachable has_many :journals_for_messages end diff --git a/app/models/user.rb b/app/models/user.rb index ff7caff9d..135ffb0f2 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -114,6 +114,13 @@ class User < Principal has_many :apply_homeworks, :dependent => :destroy has_many :apply_resources, :dependent => :destroy #end + #竞赛 + has_many :contests, :dependent => :destroy + has_many :works, :dependent => :destroy + has_many :contestant_works, :dependent => :destroy + has_many :contestant_work_evaluation_distributions, :dependent => :destroy + has_many :contestant_work_scores + has_many :contestant_work_projects has_and_belongs_to_many :groups, :after_add => Proc.new {|user, group| group.user_added(user)}, :after_remove => Proc.new {|user, group| group.user_removed(user)} diff --git a/app/views/contestant_works/_add_score.html.erb b/app/views/contestant_works/_add_score.html.erb index 09eea4808..22f3bb008 100644 --- a/app/views/contestant_works/_add_score.html.erb +++ b/app/views/contestant_works/_add_score.html.erb @@ -1,4 +1,4 @@ -<%= form_for('new_form', :remote => true, :method => :post,:url => add_score_contestant_works_path(work.id),:id=>'add_score_'+work.id.to_s) do |f|%> +<%= form_for('new_form', :remote => true, :method => :post,:url => add_score_contestant_work_path(work.id),:id=>'add_score_'+work.id.to_s) do |f|%>
<%= project.name %><%= project.status == 9 ? "(已删除)" : ""%>
+ ++ 创建者:<%= project.creater %>成员数量:<%= project.members.count %>
+ <% project_score = project.project_score %> +项目综合得分:<%= project.status == 9 ? 0 : static_project_score(project_score).to_i %>
+ + <% if project.status != 9 %> += 代码提交得分 + issue得分 + 资源得分 + 帖子得分
+ += <%= (project_score.changeset_num||0) * 4 %> + + <%= project_score.issue_num * 4 + project_score.issue_journal_num %> + <%= project_score.attach_num * 5 %> + + <%= project_score.board_num * 2 + project_score.board_message_num + project_score.news_num %>
+ <% end %> +在线评审启动之前,无法查看具体作品
+