From ddf679dd3671af9367eee4d31abe170a3b685241 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 10 Jul 2019 11:31:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9F=A5=E9=87=8D=E8=AF=A6=E6=83=85=E9=A1=B5?= =?UTF-8?q?=E7=9A=84=E6=8E=A5=E5=8F=A3=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../homework_commons_controller.rb | 22 +++---------------- app/helpers/homework_commons_helper.rb | 16 -------------- app/models/student_work.rb | 15 +++++++++++++ .../code_review_detail.json.jbuilder | 7 ++++++ .../shixun_work_report.json.jbuilder | 6 ++--- 5 files changed, 28 insertions(+), 38 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 232250e4c..b7291b647 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -1354,7 +1354,7 @@ class HomeworkCommonsController < ApplicationController if results.status == 0 code_info = results.code_info homework_challenge_settings = @homework.homework_challenge_settings - @challenges = @shixun.challenges.where(id: homework_challenge_settings.pluck(:challenge_id), st: 0).includes(:games) + @challenges = @shixun.challenges.where(id: homework_challenge_settings.pluck(:challenge_id), st: 0) @challenges = @challenges.map do |challenge| code_rate = 0 @@ -1368,24 +1368,8 @@ class HomeworkCommonsController < ApplicationController game = challenge.games.find_by(user_id: @user.id) end_time = game.end_time # 用户关卡的得分 - all_score = homework_challenge_settings.find_by(challenge_id: challenge.id).try(:score) - final_score = - if @student_work.challenge_work_scores.where(challenge_id: challenge.id).last.present? - @student_work.challenge_work_scores.where(:challenge_id => game.challenge_id).last.score - else - if game.status == 2 && ((game.end_time && game.end_time < @homework.end_time) || - (@homework.allow_late && (@course.end_date.nil? || - (game.end_time && game.end_time < @course.end_date.end_of_day)))) - answer_open_evaluation = @homework.homework_detail_manual.answer_open_evaluation - # 设置了查看答案也获得满分的话就取总分。否则取关卡的百分比分支 - if answer_open_evaluation.present? - all_score - else - # 关卡的百分比 * 作业设置的分数 = 总得分 - ((game.final_score) / challenge.score) * all_score - end - end - end + all_score = homework_challenge_settings.find_by(challenge_id: challenge.id).try(:score).to_f + final_score = @student_work.work_challenge_score game, all_score # 抄袭用户 copy_user = User.find_by_id(game_codes[0].target_user_id) copy_end_time = copy_user.games.find_by(challenge_id: challenge.id).try(:end_time) if copy_user.present? diff --git a/app/helpers/homework_commons_helper.rb b/app/helpers/homework_commons_helper.rb index 10e20ec0c..c77ae5937 100644 --- a/app/helpers/homework_commons_helper.rb +++ b/app/helpers/homework_commons_helper.rb @@ -1,21 +1,5 @@ module HomeworkCommonsHelper - # 实训作品的单个关卡得分 - def work_challenge_score student_work, game, score, homework - result = 0 - adjust_score = student_work.challenge_work_scores.where(challenge_id: game.challenge_id).last - if adjust_score.present? - result = adjust_score.score - else - setting = homework.homework_group_setting student_work.user_id - if game.status == 2 && ((game.end_time && game.end_time < setting.end_time) || (homework.allow_late && game.end_time && game.end_time < homework.late_time)) - answer_open_evaluation = homework.homework_detail_manual.answer_open_evaluation - result = answer_open_evaluation ? score : (game.final_score > 0 ? game.real_score(score) : 0) - end - end - result - end - # 未发布时非老师角色不能访问,发布后非课堂成员不能访问未公开的作业,学生需要考虑分班设置的作业是否已发布 def homework_publish if (@user_course_identity >= Course::STUDENT && (@homework.publish_time.nil? || @homework.publish_time > Time.now)) || diff --git a/app/models/student_work.rb b/app/models/student_work.rb index d5b746ebd..0e41ce1ae 100644 --- a/app/models/student_work.rb +++ b/app/models/student_work.rb @@ -193,4 +193,19 @@ class StudentWork < ApplicationRecord def scored? student_works_scores.where.not(reviewer_role: 3).exists? end + + def work_challenge_score game, score + game_score = 0 + adjust_score = challenge_work_scores.where(challenge_id: game.challenge_id).last + if adjust_score.present? + game_score = adjust_score.score + else + setting = homework.homework_group_setting user_id + if game.status == 2 && ((game.end_time && game.end_time < setting.end_time) || (homework.allow_late && game.end_time && game.end_time < homework.late_time)) + answer_open_evaluation = homework.homework_detail_manual.answer_open_evaluation + game_score = answer_open_evaluation ? score : (game.final_score > 0 ? game.real_score(score) : 0) + end + end + game_score + end end diff --git a/app/views/homework_commons/code_review_detail.json.jbuilder b/app/views/homework_commons/code_review_detail.json.jbuilder index 4ebabf20a..f2cad7f3e 100644 --- a/app/views/homework_commons/code_review_detail.json.jbuilder +++ b/app/views/homework_commons/code_review_detail.json.jbuilder @@ -8,12 +8,19 @@ json.user_id @user.id json.user_login @user.login json.work_score @student_work.work_score + if @student_work.ultimate_score json.adjust_score @student_work.work_score < 0 ? 0 : number_with_precision(@student_work.work_score, precision: 1) else json.final_score @student_work.final_score json.late_penalty @student_work.late_penalty json.score @student_work.work_score < 0 ? 0 : number_with_precision(@student_work.work_score, precision: 1) + if @homework.work_efficiency + json.eff_score_full number_with_precision @homework.eff_score, precision: 1 + json.eff_score number_with_precision @work.eff_score, precision: 1 + json.challenge_score_full number_with_precision (100 - @homework.eff_score), precision: 1 + json.challenge_score number_with_precision @work.final_score, precision: 1 + end end json.challenge_list do diff --git a/app/views/student_works/shixun_work_report.json.jbuilder b/app/views/student_works/shixun_work_report.json.jbuilder index 103ead73f..05387125d 100644 --- a/app/views/student_works/shixun_work_report.json.jbuilder +++ b/app/views/student_works/shixun_work_report.json.jbuilder @@ -13,9 +13,9 @@ if @shixun json.evaluate_count @user_evaluate_count.to_i if @homework.work_efficiency json.eff_score_full number_with_precision @homework.eff_score, precision: 1 - json.eff_score @work.eff_score + json.eff_score number_with_precision @work.eff_score, precision: 1 json.challenge_score_full number_with_precision (100 - @homework.eff_score), precision: 1 - json.challenge_score @work.final_score + json.challenge_score number_with_precision @work.final_score, precision: 1 end # 阶段成绩 @@ -33,7 +33,7 @@ if @shixun json.challenge_id game.challenge_id challenge_score = @homework.challenge_score game.challenge_id json.game_score_full challenge_score - json.game_score work_challenge_score @work, game, challenge_score, @homework + json.game_score @work.work_challenge_score game, challenge_score end end