From cade029fc14df0157e91ffc20c53f84d8fec29e6 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 10 Jul 2019 11:06:28 +0800 Subject: [PATCH 01/12] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E6=8A=A5=E5=91=8A?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E7=9A=84=E8=B0=83=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/homework_commons_helper.rb | 16 ++++++++++++++++ app/models/homework_common.rb | 4 ++++ .../shixun_work_report.json.jbuilder | 11 ++++++++++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/app/helpers/homework_commons_helper.rb b/app/helpers/homework_commons_helper.rb index c77ae5937..10e20ec0c 100644 --- a/app/helpers/homework_commons_helper.rb +++ b/app/helpers/homework_commons_helper.rb @@ -1,5 +1,21 @@ 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/homework_common.rb b/app/models/homework_common.rb index 335b898fb..ac64b92c1 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -260,4 +260,8 @@ class HomeworkCommon < ApplicationRecord self.homework_group_settings.where("end_time is not null").pluck(:end_time).max end + + def challenge_score challenge_id + homework_challenge_settings.find_by(challenge_id: challenge_id)&.score.to_f + end end diff --git a/app/views/student_works/shixun_work_report.json.jbuilder b/app/views/student_works/shixun_work_report.json.jbuilder index f0aa8119e..103ead73f 100644 --- a/app/views/student_works/shixun_work_report.json.jbuilder +++ b/app/views/student_works/shixun_work_report.json.jbuilder @@ -8,9 +8,15 @@ if @shixun json.myself_experience @work.myshixun.try(:total_score) json.total_experience @shixun.all_score json.work_score number_with_precision @work.work_score, precision: 1 - json.all_work_score 100 + json.all_work_score number_with_precision 100, precision: 1 json.time_consuming @work.myshixun_consume 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.challenge_score_full number_with_precision (100 - @homework.eff_score), precision: 1 + json.challenge_score @work.final_score + end # 阶段成绩 json.stage_list do @@ -25,6 +31,9 @@ if @shixun json.experience game.challenge.all_score json.complete_status game_status(game, @homework) 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 end end 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 02/12] =?UTF-8?q?=E6=9F=A5=E9=87=8D=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E9=A1=B5=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 From e9db5afd54fcd8e765c933a4aef454d9b32a0ea8 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 10 Jul 2019 11:33:21 +0800 Subject: [PATCH 03/12] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/student_work.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/student_work.rb b/app/models/student_work.rb index 0e41ce1ae..9151ca501 100644 --- a/app/models/student_work.rb +++ b/app/models/student_work.rb @@ -200,9 +200,9 @@ class StudentWork < ApplicationRecord 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 + setting = homework_common.homework_group_setting user_id + if game.status == 2 && ((game.end_time && game.end_time < setting.end_time) || (homework_common.allow_late && game.end_time && game.end_time < homework_common.late_time)) + answer_open_evaluation = homework_common.homework_detail_manual.answer_open_evaluation game_score = answer_open_evaluation ? score : (game.final_score > 0 ? game.real_score(score) : 0) end end From a1d11910fe2932f11cf4d17ae4b9886396495527 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 10 Jul 2019 13:52:11 +0800 Subject: [PATCH 04/12] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/homework_commons/code_review_detail.json.jbuilder | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/homework_commons/code_review_detail.json.jbuilder b/app/views/homework_commons/code_review_detail.json.jbuilder index f2cad7f3e..90d2c4a54 100644 --- a/app/views/homework_commons/code_review_detail.json.jbuilder +++ b/app/views/homework_commons/code_review_detail.json.jbuilder @@ -17,9 +17,9 @@ else 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.eff_score number_with_precision @student_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 + json.challenge_score number_with_precision @student_work.final_score, precision: 1 end end From bd099f2e1b4cce1edc309d107cc72b974e267c3e Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 10 Jul 2019 14:18:42 +0800 Subject: [PATCH 05/12] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E6=8A=A5=E5=91=8A?= =?UTF-8?q?=E5=92=8C=E4=BB=A3=E7=A0=81=E6=9F=A5=E9=87=8D=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E9=A1=B5=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 --- app/controllers/student_works_controller.rb | 2 +- app/views/homework_commons/code_review_detail.json.jbuilder | 2 ++ app/views/student_works/adjust_review_score.json.jbuilder | 3 ++- app/views/student_works/shixun_work_report.json.jbuilder | 1 + 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb index 62d96c424..1c98db56c 100644 --- a/app/controllers/student_works_controller.rb +++ b/app/controllers/student_works_controller.rb @@ -631,7 +631,7 @@ class StudentWorksController < ApplicationController # 查重作品调分 def adjust_review_score - tip_exception("缺少type参数") if params[:type].blank? || ["review", "report"].include?(params[:type]) + tip_exception("缺少type参数") if params[:type].blank? || !["review", "report"].include?(params[:type]) if params[:type] == "review" && (params[:score].nil? || params[:challenge_id].nil? || params[:code_rate].nil? || params[:copy_user_id].nil?) tip_exception("参数错误,score和challenge_id和code_rate和copy_user_id不能为空") elsif params[:type] == "report" && (params[:score].nil? || params[:challenge_id].nil?) diff --git a/app/views/homework_commons/code_review_detail.json.jbuilder b/app/views/homework_commons/code_review_detail.json.jbuilder index 90d2c4a54..c33a906ec 100644 --- a/app/views/homework_commons/code_review_detail.json.jbuilder +++ b/app/views/homework_commons/code_review_detail.json.jbuilder @@ -2,6 +2,7 @@ json.course_id @course.id json.course_name @course.name json.homework_common_id @homework.id json.homework_common_name @homework.name +json.work_id @student_work.id json.work_name @student_work.name json.username @user.full_name json.user_id @user.id @@ -32,6 +33,7 @@ json.challenge_list do json.final_score challenge[:final_score] json.username challenge[:username] json.all_score challenge[:all_score] + json.copy_user_id challenge[:copy_user_id] json.copy_username challenge[:copy_username] json.copy_end_time challenge[:copy_end_time] json.code_rate challenge[:code_rate] diff --git a/app/views/student_works/adjust_review_score.json.jbuilder b/app/views/student_works/adjust_review_score.json.jbuilder index 399b52c13..928806bd6 100644 --- a/app/views/student_works/adjust_review_score.json.jbuilder +++ b/app/views/student_works/adjust_review_score.json.jbuilder @@ -1,3 +1,4 @@ json.status 0 json.message "调分成功" -json.work_score @work.work_score \ No newline at end of file +json.work_score number_with_precision @work.work_score, 1 +json.challenge_score number_with_precision @work.final_score, 1 \ No newline at end of file diff --git a/app/views/student_works/shixun_work_report.json.jbuilder b/app/views/student_works/shixun_work_report.json.jbuilder index 05387125d..e24092f05 100644 --- a/app/views/student_works/shixun_work_report.json.jbuilder +++ b/app/views/student_works/shixun_work_report.json.jbuilder @@ -1,6 +1,7 @@ json.homework_common_id @homework.id json.category @homework.category_info json.course_name @course.name +json.work_id @work.id if @shixun json.shixun_name @shixun.name # 总体评价 From a299eabdaf347fb6d71be65864864a0dd3912f9f Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 10 Jul 2019 14:55:57 +0800 Subject: [PATCH 06/12] =?UTF-8?q?=E5=AD=A6=E7=94=9F=E6=9F=A5=E7=9C=8B?= =?UTF-8?q?=E4=BD=9C=E5=93=81=E5=88=97=E8=A1=A8=E6=97=B6=E6=B3=A8=E6=84=8F?= =?UTF-8?q?=E5=8C=BF=E8=AF=84=E6=88=AA=E6=AD=A2=E4=B8=8E=E8=A1=A5=E4=BA=A4?= =?UTF-8?q?=E6=88=AA=E6=AD=A2=E7=9A=84=E6=97=B6=E9=97=B4=E5=B7=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_commons_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index b7291b647..767884d68 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -118,7 +118,7 @@ class HomeworkCommonsController < ApplicationController # 学生已提交作品且补交(提交)已截止、作品公开、非匿评阶段 if @work&.work_status.to_i > 0 && (@homework.work_public || @homework.score_open) && - ((!@homework.anonymous_comment && @homework.end_or_late) || @homework_detail_manual.comment_status > 4) + ((!@homework.anonymous_comment && @homework.end_or_late) || (@homework_detail_manual.comment_status > 4 && @homework.end_or_late)) @student_works = student_works.where("user_id != #{@work.user_id}") # 匿评、申诉阶段只能看到分配给自己的匿评作品 From 24799503e415a0c9c64bb4d9675fc087a46d775a Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 10 Jul 2019 14:57:40 +0800 Subject: [PATCH 07/12] =?UTF-8?q?=E8=AF=84=E9=98=85=E9=98=B6=E6=AE=B5?= =?UTF-8?q?=E4=B8=8D=E8=83=BD=E7=9C=8B=E5=8C=BF=E8=AF=84=E4=BD=9C=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_commons_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 767884d68..09d225496 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -122,7 +122,7 @@ class HomeworkCommonsController < ApplicationController @student_works = student_works.where("user_id != #{@work.user_id}") # 匿评、申诉阶段只能看到分配给自己的匿评作品 - elsif @work&.work_status.to_i > 0 && @homework.anonymous_comment && @homework_detail_manual.comment_status > 2 + elsif @work&.work_status.to_i > 0 && @homework.anonymous_comment && @homework_detail_manual.comment_status > 2 && @homework_detail_manual.comment_status <= 4 @is_evaluation = true @student_works = student_works.joins(:student_works_evaluation_distributions).where( "student_works_evaluation_distributions.user_id = #{@current_user.id}") From 1bfc279905387e0caf29cefe66472761d0ce8fc8 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 10 Jul 2019 15:36:52 +0800 Subject: [PATCH 08/12] =?UTF-8?q?=E8=AE=A1=E7=AE=97=E6=88=90=E7=BB=A9?= =?UTF-8?q?=E7=9A=84=E5=88=A4=E6=96=AD=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_commons_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 09d225496..6f0f10f4d 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -240,7 +240,7 @@ class HomeworkCommonsController < ApplicationController end def update_score - tip_exception("作业还未发布,暂不能计算成绩") if @homework.end_or_late_none_group + tip_exception("作业还未发布,暂不能计算成绩") if @homework.publish_time.nil? || @homework.publish_time > Time.now begin if @homework.unified_setting student_works = @homework.student_works From e7cec7b8a34125769e8ada3ad35a7c6b2cc289f3 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 10 Jul 2019 15:51:30 +0800 Subject: [PATCH 09/12] =?UTF-8?q?=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 --- app/controllers/exercises_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 9a7838a96..0b8e12094 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1188,7 +1188,7 @@ class ExercisesController < ApplicationController elsif @user_course_identity > Course::ASSISTANT_PROFESSOR #当前为学生或者有过答题的(提交/未提交) @ex_user_end_time = @exercise.get_exercise_end_time(current_user.id) #当前用户所看到的剩余时间 @exercise_all_users = @exercise.get_stu_exercise_users - get_exercise_answers(@exercise_users_list, @exercise_status) # 未答和已答的 + get_exercise_answers(@exercise_all_users, @exercise_status) # 未答和已答的 exercise_current_user = @exercise_all_users.exercise_commit_users(current_user.id) #当前用户是否开始做试卷(提交/未提交/没做) if exercise_current_user.present? @exercise_current_user_status = 1 #当前用户的状态,为学生 @@ -1202,7 +1202,7 @@ class ExercisesController < ApplicationController end else @exercise_all_users = @exercise.get_stu_exercise_users - get_exercise_answers(@exercise_users_list, @exercise_status) # 未答和已答的 + get_exercise_answers(@exercise_all_users, @exercise_status) # 未答和已答的 @exercise_current_user_status = 2 #当前用户非课堂成员 @exercise_users_list = [] end From ef0953f86752a635e216eeef62ad5f2e80f163e7 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 10 Jul 2019 17:08:43 +0800 Subject: [PATCH 10/12] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E8=AF=84=E9=98=85?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E7=9A=84=E5=88=86=E6=95=B0=E8=AF=84=E5=88=A4?= =?UTF-8?q?=E6=A0=87=E5=87=86=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercises_controller.rb | 1 + app/helpers/exercises_helper.rb | 28 ++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 9a7838a96..68be45660 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1040,6 +1040,7 @@ class ExercisesController < ApplicationController @exercise_questions = @exercise_questions.order("question_number ASC") end # 判断问题是否已回答还是未回答 + @exercise_questions = @exercise_questions.includes(:exercise_stand_answers,:exercise_answers,:exercise_shixun_answers) if @t_user_exercise_status == 3 get_each_student_exercise(@exercise.id,@exercise_questions,@exercise_current_user_id) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 0b64cb916..25255de85 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -9,11 +9,32 @@ module ExercisesHelper @ex_obj_array = [] exercise_obj_status.each do |q| if q.question_type == 5 - ques_score = q.exercise_shixun_answers.search_shixun_answers("user_id",user_id).pluck(:score).sum + answers_content = q.exercise_shixun_answers.search_shixun_answers("user_id",user_id) else - ques_score = q.exercise_answers.search_answer_users("user_id",user_id).score_reviewed.pluck(:score).sum + answers_content = q.exercise_answers.includes(:exercise_choices).search_answer_users("user_id",user_id) end + if q.question_type <= 2 + if answers_content.present? #学生有回答时 + answer_choice_array = [] + answers_content.each do |a| + answer_choice_array.push(a.exercise_choice.choice_position) #学生答案的位置 + end + user_answer_content = answer_choice_array.sort + standard_answer = q.exercise_standard_answers.pluck(:exercise_choice_id).sort #该问题的标准答案,可能有多个 + if user_answer_content == standard_answer #答案一致,多选或单选才给分,答案不对不给分 + ques_score = q.question_score + else + ques_score = 0.0 + end + else + ques_score = 0.0 + end + else + ques_score = answers_content.select(:score).pluck(:score).sum + end + + if ques_score >= q.question_score #满分作答为正确 ques_score = q.question_score stand_answer = 1 @@ -370,7 +391,8 @@ module ExercisesHelper standard_answer = q.exercise_standard_answers.pluck(:exercise_choice_id).sort #该问题的标准答案,可能有多个 if user_answer_content == standard_answer #答案一致,多选或单选才给分,答案不对不给分 if standard_answer.count > 0 - q_score_1 = (q.question_score.to_f / standard_answer.count) #当多选答案正确时,每个answer的分数均摊。 + q_score_1 = q.question_score + # q_score_1 = (q.question_score.to_f / standard_answer.count) #当多选答案正确时,每个answer的分数均摊。 else q_score_1 = 0.0 end From 88a85bff7db9c71a0ace287606a1f9515102e25d Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 10 Jul 2019 17:12:17 +0800 Subject: [PATCH 11/12] fixbug --- app/helpers/exercises_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 25255de85..018bc2c39 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -11,7 +11,7 @@ module ExercisesHelper if q.question_type == 5 answers_content = q.exercise_shixun_answers.search_shixun_answers("user_id",user_id) else - answers_content = q.exercise_answers.includes(:exercise_choices).search_answer_users("user_id",user_id) + answers_content = q.exercise_answers.search_answer_users("user_id",user_id) end if q.question_type <= 2 From e7da0d9be83609256420292bd2822a03e8ad20dd Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 10 Jul 2019 17:39:59 +0800 Subject: [PATCH 12/12] fixbug --- app/controllers/exercises_controller.rb | 2 +- app/helpers/exercises_helper.rb | 30 +++++++++++++++++++------ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 4be76fc59..6af48dbd1 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1130,7 +1130,7 @@ class ExercisesController < ApplicationController @is_teacher_or = @user_course_identity < Course::STUDENT ? 1 : 0 @student_status = 2 # @exercise_answerer = User.find_by(id:@exercise_current_user_id) #试卷回答者 - @exercise_questions = @exercise.exercise_questions.order("question_number ASC") + @exercise_questions = @exercise.exercise_questions.includes(:exercise_shixun_challenges,:exercise_standard_answers,:exercise_answers,:exercise_shixun_answers).order("question_number ASC") @question_status = [] get_exercise_status = @exercise.get_exercise_status(current_user) if @ex_user.present? && @is_teacher_or == 0 diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 018bc2c39..314a90403 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -34,7 +34,6 @@ module ExercisesHelper ques_score = answers_content.select(:score).pluck(:score).sum end - if ques_score >= q.question_score #满分作答为正确 ques_score = q.question_score stand_answer = 1 @@ -663,6 +662,7 @@ module ExercisesHelper user_score = nil shixun_type = 0 question_comment = [] + # user_score_pre = nil if ques_type == 5 exercise_answers = q.exercise_shixun_answers.search_shixun_answers("user_id",ex_answerer_id) else @@ -670,10 +670,26 @@ module ExercisesHelper end if student_status == 2 #当前为老师,或为学生且已提交 user_score_pre = exercise_answers.score_reviewed - if ques_type == 4 && user_score_pre.blank? #主观题时,且没有大于0的分数时,为空 - user_score = nil - else + if ques_type == 4 #主观题时,且没有大于0的分数时,为空 + user_score = user_score_pre.present? ? user_score_pre.pluck(:score).sum : nil + elsif ques_type == 5 || ques_type == 3 user_score = user_score_pre.present? ? user_score_pre.pluck(:score).sum : 0.0 + else + if exercise_answers.present? #判断题和选择题时, + answer_choice_array = [] + exercise_answers.each do |a| + answer_choice_array.push(a.exercise_choice.choice_position) #学生答案的位置 + end + user_answer_content = answer_choice_array.sort + standard_answer = q.exercise_standard_answers.pluck(:exercise_choice_id).sort #该问题的标准答案,可能有多个 + if user_answer_content == standard_answer #答案一致,多选或单选才给分,答案不对不给分 + user_score = q.question_score + else + user_score = 0.0 + end + else + user_score = 0.0 + end end end @@ -681,9 +697,9 @@ module ExercisesHelper user_score = q.question_score end if ques_type <= 2 - answered_content = exercise_answers.pluck(:exercise_choice_id) + answered_content = exercise_answers&.pluck(:exercise_choice_id) elsif ques_type == 3 - exercise_answers.each do |a| + exercise_answers&.each do |a| u_answer = { "choice_id":a.exercise_choice_id, "answer_text": a.answer_text @@ -691,7 +707,7 @@ module ExercisesHelper answered_content.push(u_answer) end elsif ques_type == 4 - answered_content = exercise_answers.pluck(:answer_text) + answered_content = exercise_answers&.pluck(:answer_text) end if ques_type == 5 #存在实训题,及已经做了实训题的 if ex_status == 3 || is_teacher_or == 1 #如果试卷已截止,则可以看到分数,否则不能查看分数