From 25ef08118c76f5758cad7162561ddad3f71a5722 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 25 Jun 2019 17:45:57 +0800 Subject: [PATCH 1/6] fixbug --- app/helpers/exercises_helper.rb | 12 ++++++------ app/helpers/export_helper.rb | 19 +++++++++++-------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 2a052fffe..856f808d7 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -355,9 +355,9 @@ module ExercisesHelper exercise_questions = exercise.exercise_questions.includes(:exercise_answers,:exercise_shixun_answers,:exercise_standard_answers,:exercise_shixun_challenges) exercise_questions.each do |q| if q.question_type != 5 - answers_content = q.exercise_answers.search_answer_users("user_id",user.id) #学生的答案 + answers_content = q.exercise_answers.where(user_id: user.id) #学生的答案 else - answers_content = q.exercise_shixun_answers.search_shixun_answers("user_id",user.id) #学生的答案 + answers_content = q.exercise_shixun_answers.where(user_id: user.id) #学生的答案 end if q.question_type <= 2 #为选择题或判断题时 if answers_content.present? #学生有回答时 @@ -369,11 +369,11 @@ 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 / standard_answer.count) #当多选答案正确时,每个answer的分数均摊。 + multi_each_score = (q.question_score / standard_answer.count) #当多选答案正确时,每个answer的分数均摊。 else - q_score_1 = 0.0 + multi_each_score = 0.0 end - answers_content.update_all(:score => q_score_1) + answers_content.update_all(:score => multi_each_score) score1 = score1 + q.question_score end else @@ -424,7 +424,7 @@ module ExercisesHelper end ex_shixun_answer_content = answers_content&.where(exercise_shixun_challenge_id: exercise_cha.id) if ex_shixun_answer_content.blank? #把关卡的答案存入试卷的实训里 - cha_path = challenge_path exercise_cha.challenge&.path + cha_path = challenge_path(exercise_cha.challenge&.path) game_challenge = game.game_codes.search_challenge_path(cha_path)&.first if game_challenge.present? game_code = game_challenge diff --git a/app/helpers/export_helper.rb b/app/helpers/export_helper.rb index af883131a..22c10bdb3 100644 --- a/app/helpers/export_helper.rb +++ b/app/helpers/export_helper.rb @@ -89,11 +89,12 @@ module ExportHelper if teacher_comments.present? w_18 = "" teacher_comments.each do |t| - user_name = t.user.real_name + user_name = t.user&.real_name user_time = format_time(t.updated_at) - user_score = t.score - user_comment = t.comment - w_18 = w_18 + ("教师:" + user_name + "\n" + "时间:" + user_time.to_s + "\n" + "分数:" + user_score.to_s + "分" + "\n" + "评语:" + user_comment + "\n\n") + user_score = t&.score + user_comment = t&.comment + comment_title = "教师:#{user_name}\n时间:#{user_time.to_s}\n分数:#{user_score.to_s}分\n评语:#{user_comment}\n\n" + w_18 = w_18 + comment_title end else w_18 = "--" @@ -160,11 +161,13 @@ module ExportHelper if teacher_comments.present? w_18 = "" teacher_comments.each do |t| - user_name = t.user.real_name + user_name = t.user&.real_name user_time = format_time(t.updated_at) - user_score = t.score - user_comment = t.comment - w_18 = w_18 + ("教师:" + user_name + "\n" + "时间:" + user_time.to_s + "\n" + "分数:" + user_score.to_s + "分" + "\n" + "评语:" + user_comment + "\n\n") + user_score = t&.score + user_comment = t&.comment + comment_title = "教师:#{user_name}\n时间:#{user_time.to_s}\n分数:#{user_score.to_s}分\n评语:#{user_comment}\n\n" + # ("教师:" + user_name + "\n" + "时间:" + user_time.to_s + "\n" + "分数:" + user_score.to_s + "分" + "\n" + "评语:" + user_comment + "\n\n") + w_18 = w_18 + comment_title end else w_18 = "--" From 555b1f8dc0dc08c68a5773a8edcb13bd18f1f541 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 25 Jun 2019 17:46:57 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E7=9A=84=E6=9C=80=E5=A4=A7=E6=95=88=E7=8E=87=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/homeworks_service.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/services/homeworks_service.rb b/app/services/homeworks_service.rb index 2d6f50b5c..1e155dde0 100644 --- a/app/services/homeworks_service.rb +++ b/app/services/homeworks_service.rb @@ -111,7 +111,7 @@ class HomeworksService if homework.work_efficiency if homework.max_efficiency < student_work.efficiency # homework.max_efficiency = student_work.efficiency - homework.update_column("max_efficiency", homework.max_efficiency) + homework.update_column("max_efficiency", student_work.efficiency) end # eff_score = homework.max_efficiency == 0 ? 0 : student_work.efficiency / homework.max_efficiency * homework.eff_score # student_work.eff_score = format("%.2f", eff_score) @@ -200,7 +200,7 @@ class HomeworksService # 如果作业的最大效率值有变更则更新所有作品的效率分 if homework.work_efficiency && homework.max_efficiency < work.efficiency - homework.update_column("max_efficiency", homework.max_efficiency) + homework.update_column("max_efficiency", work.efficiency) end end From cc1d09bee79e53efd7beb55e48a87f1e6b410cd3 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 25 Jun 2019 18:03:19 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E6=9F=A5=E7=9C=8B=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E5=BC=B9=E6=A1=86=E5=A2=9E=E5=8A=A0=E7=94=A8=E6=88=B7=E8=8E=B7?= =?UTF-8?q?=E5=BE=97=E7=9A=84=E6=80=BB=E7=BB=8F=E9=AA=8C=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/student_works/shixun_work.json.jbuilder | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/student_works/shixun_work.json.jbuilder b/app/views/student_works/shixun_work.json.jbuilder index 3b6b598cb..74c33420e 100644 --- a/app/views/student_works/shixun_work.json.jbuilder +++ b/app/views/student_works/shixun_work.json.jbuilder @@ -15,6 +15,7 @@ json.efficiency number_with_precision @work.efficiency, precision: 2 json.max_efficiency number_with_precision @homework.max_efficiency, precision: 2 json.passed_time @myshixun.passed_time json.total_spend_time @myshixun.total_spend_time +json.user_score @myshixun.total_score # 关卡完成情况 index = 1 From 9ca32a6d1a1a8bfb28c929ca13ff061baff4dca2 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 25 Jun 2019 18:10:13 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E5=9B=BE=E7=89=87url=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/application_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index b4e3baf51..32c4438a6 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -128,7 +128,7 @@ module ApplicationHelper if source.class.to_s == 'User' File.join(relative_path, ["#{source.class}", "#{source.id}"]) else - File.join("/images/avatars", ["#{source.class}", "#{source.id}"]) + File.join("images/avatars", ["#{source.class}", "#{source.id}"]) end elsif source.class.to_s == 'User' str = source.user_extension.try(:gender).to_i == 0 ? "b" : "g" @@ -146,7 +146,7 @@ module ApplicationHelper def shixun_url_to_avatar(shixun) if File.exist?(disk_filename(shixun.class, shixun.id)) - File.join("/images/#{relative_path}", "#{shixun.class}", "#{shixun.id}") + File.join("images/#{relative_path}", "#{shixun.class}", "#{shixun.id}") else File.join("educoder", "index", "shixun", "shixun#{rand(23)}.jpg") end From 0be306704cda33b3ab90eb208d6d974fb9451987 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 25 Jun 2019 18:16:03 +0800 Subject: [PATCH 5/6] fix bug --- app/helpers/exercises_helper.rb | 12 ++++++------ app/views/exercises/index.json.jbuilder | 3 ++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 856f808d7..604258c32 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -369,11 +369,11 @@ module ExercisesHelper standard_answer = q.exercise_standard_answers.pluck(:exercise_choice_id).sort #该问题的标准答案,可能有多个 if user_answer_content == standard_answer #答案一致,多选或单选才给分,答案不对不给分 if standard_answer.count > 0 - multi_each_score = (q.question_score / standard_answer.count) #当多选答案正确时,每个answer的分数均摊。 + q_score_1 = (q.question_score.to_f / standard_answer.count) #当多选答案正确时,每个answer的分数均摊。 else - multi_each_score = 0.0 + q_score_1 = 0.0 end - answers_content.update_all(:score => multi_each_score) + answers_content.update_all(:score => q_score_1) score1 = score1 + q.question_score end else @@ -461,13 +461,13 @@ module ExercisesHelper "q_type":q.question_type, "q_position":q.question_number, #该问题的位置 "stand_status":stand_answer, #该问题是否正确,1为正确,0为错误 - "user_score":user_scores #每个问题的总得分 + "user_score":user_scores.round(1) #每个问题的总得分 } ques_stand.push(ques_option) end total_score = score1 + score2 + score5 { - "total_score":total_score, + "total_score":total_score.round(1), "stand_status":ques_stand } end @@ -687,7 +687,7 @@ module ExercisesHelper exercise_user = exercise.exercise_users.find_by(user_id:user.id) time_mill = ex_time * 60 #转为秒 exercise_end_time = exercise.end_time.present? ? exercise.end_time.to_i : 0 - exercise_user_start = exercise_user.present? ? exercise_user.start_at.to_i : 0 + exercise_user_start = exercise_user&.start_at.present? ? exercise_user.start_at.to_i : 0 #用户未开始答题时,即exercise_user_start为0 if exercise_user_start == 0 if (exercise_end_time - time_now_i) > time_mill diff --git a/app/views/exercises/index.json.jbuilder b/app/views/exercises/index.json.jbuilder index d7d51c343..4694ecdf0 100644 --- a/app/views/exercises/index.json.jbuilder +++ b/app/views/exercises/index.json.jbuilder @@ -23,7 +23,8 @@ if @exercises_count > 0 ex_index = exercise_index_show(exercise,@course,@is_teacher_or,@current_user_) json.extract! exercise, :id, :exercise_name,:is_public,:created_at if @is_teacher_or == 2 - json.time get_exercise_left_time(exercise,@current_user_) + second_left = get_exercise_left_time(exercise,@current_user_) + json.time second_left.present? ? (second_left / 60) : nil end json.exercise_status ex_index[:ex_status] From d3e0ecc33afe5bba8f21e085e962cff3256355f3 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 25 Jun 2019 18:17:25 +0800 Subject: [PATCH 6/6] fix bug --- app/helpers/export_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/helpers/export_helper.rb b/app/helpers/export_helper.rb index 22c10bdb3..b6720c66c 100644 --- a/app/helpers/export_helper.rb +++ b/app/helpers/export_helper.rb @@ -92,7 +92,7 @@ module ExportHelper user_name = t.user&.real_name user_time = format_time(t.updated_at) user_score = t&.score - user_comment = t&.comment + user_comment = t.comment.present? ? t.comment : "--" comment_title = "教师:#{user_name}\n时间:#{user_time.to_s}\n分数:#{user_score.to_s}分\n评语:#{user_comment}\n\n" w_18 = w_18 + comment_title end @@ -164,7 +164,7 @@ module ExportHelper user_name = t.user&.real_name user_time = format_time(t.updated_at) user_score = t&.score - user_comment = t&.comment + user_comment = t.comment.present? ? t.comment : "--" comment_title = "教师:#{user_name}\n时间:#{user_time.to_s}\n分数:#{user_score.to_s}分\n评语:#{user_comment}\n\n" # ("教师:" + user_name + "\n" + "时间:" + user_time.to_s + "\n" + "分数:" + user_score.to_s + "分" + "\n" + "评语:" + user_comment + "\n\n") w_18 = w_18 + comment_title