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/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 diff --git a/app/models/edu_setting.rb b/app/models/edu_setting.rb index 4b39dea81..835aaec76 100644 --- a/app/models/edu_setting.rb +++ b/app/models/edu_setting.rb @@ -20,6 +20,6 @@ class EduSetting < ApplicationRecord private def expire_value_cache - Rails.cache.clear(value_cache_key) + Rails.cache.write(value_cache_key, value) end end 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]