diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 2175108fc..f10bc81ff 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -12,10 +12,10 @@ class ExercisesController < ApplicationController before_action :get_exercise_question_counts,only: [:show,:edit,:start_answer,:review_exercise,:blank_exercise,:export_exercise] before_action :validate_publish_time,only: [:commit_setting] #提交设置时,需判断时间是否符合 before_action :check_course_public,only: [:set_public] - before_action :check_user_on_answer,only: [:show,:start_answer,:commit_exercise,:exercise_lists] #判断当前用户在试卷的权限/老师是否属于分班的权限 + before_action :check_user_on_answer,only: [:show,:start_answer,:exercise_lists] #判断当前用户在试卷的权限/老师是否属于分班的权限 before_action :only_student_in,only: [:start_answer] before_action :check_user_id_start_answer,only: [:start_answer,:review_exercise] - before_action :commit_user_exercise,only: [:start_answer,:exercise_lists,:review_exercise] #判断试卷时间到用户是否提交 + # before_action :commit_user_exercise,only: [:start_answer,:exercise_lists,:review_exercise] #已有定时的任务 before_action :check_exercise_time,only: [:commit_exercise] #提交试卷时,判断时间是否超过 before_action :check_exercise_status,only: [:redo_modal,:redo_exercise] before_action :check_exercise_is_end, only: [:review_exercise] @@ -1006,6 +1006,7 @@ class ExercisesController < ApplicationController def start_answer ActiveRecord::Base.transaction do begin + @exercise_user_current = @exercise.exercise_users.exercise_commit_users(@exercise_current_user_id)&.first if @exercise_user_current.blank? if @user_course_identity > Course::ASSISTANT_PROFESSOR #当为老师的时候,不创建exercise_user表,理论上老师是不能进入答题的 exercise_user_params = { @@ -1640,38 +1641,38 @@ class ExercisesController < ApplicationController end def check_exercise_time - @answer_committed_user = @exercise.exercise_users.exercise_commit_users(current_user.id).first + @answer_committed_user = @exercise.exercise_users.exercise_commit_users(current_user.id)&.first if @answer_committed_user.blank? normal_status(404,"答题用户不存在") - elsif @exercise.get_exercise_status(current_user.id) != 2 || @answer_committed_user.commit_status == 1 # - normal_status(-1,"提交错误,试卷已截止/用户已提交!") + # elsif @exercise.get_exercise_status(current_user.id) == 2 && @answer_committed_user.commit_status == 1 #当试卷截止时,会自动提交 + # normal_status(-1,"提交错误,试卷用户已提交!") end end - def commit_user_exercise - @exercise_user_current = @exercise.exercise_users.exercise_commit_users(@exercise_current_user_id).first #查找当前用户是否有过答题 - if @user_course_identity == Course::STUDENT - if @exercise_user_current.present? - if @exercise.time > 0 && @exercise_user_current.start_at.present? && (@exercise_user_current.commit_status == 0) && - ((@exercise_user_current.start_at + (@exercise.time.to_i + 1).minutes) < Time.now) - #当前用户存在,且已回答,且试卷时间已过,且未提交,则自动提交。最好是前端控制 - objective_score = calculate_student_score(@exercise,current_user)[:total_score] - subjective_score = @exercise_user_current.subjective_score < 0.0 ? 0.0 : @exercise_user_current.subjective_score - total_score = objective_score + subjective_score - commit_option = { - :status => 1, - :commit_status => 1, - :end_at => Time.now, - :objective_score => objective_score, - :score => total_score, - :subjective_score => subjective_score - } - @exercise_user_current.update_attributes(commit_option) - normal_status(0,"已交卷成功!") - end - end - end - end + # def commit_user_exercise + # @exercise_user_current = @exercise.exercise_users.exercise_commit_users(@exercise_current_user_id)&.first #查找当前用户是否有过答题 + # if @user_course_identity == Course::STUDENT + # if @exercise_user_current.present? + # if @exercise.time > 0 && @exercise_user_current.start_at.present? && (@exercise_user_current.commit_status == 0) && + # ((@exercise_user_current.start_at + (@exercise.time.to_i + 1).minutes) < Time.now) + # #当前用户存在,且已回答,且试卷时间已过,且未提交,则自动提交。最好是前端控制 + # objective_score = calculate_student_score(@exercise,current_user)[:total_score] + # subjective_score = @exercise_user_current.subjective_score < 0.0 ? 0.0 : @exercise_user_current.subjective_score + # total_score = objective_score + subjective_score + # commit_option = { + # :status => 1, + # :commit_status => 1, + # :end_at => Time.now, + # :objective_score => objective_score, + # :score => total_score, + # :subjective_score => subjective_score + # } + # @exercise_user_current.update_attributes(commit_option) + # normal_status(0,"已交卷成功!") + # end + # end + # end + # end #打回重做时的初步判断 def check_exercise_status diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb index f4a072a4b..7e23443d2 100644 --- a/app/controllers/student_works_controller.rb +++ b/app/controllers/student_works_controller.rb @@ -429,10 +429,17 @@ class StudentWorksController < ApplicationController def shixun_work_report @user = @work.user @shixun = @homework.shixuns.take - @games = @work.myshixun.games.includes(:challenge, :game_codes, :outputs) if @work.myshixun + # 提示: 这里如果includes outputs表的话: sum(:evaluate_count)会出现错误 + @games = @work.myshixun.games if @work.myshixun # 用户最大评测次数 - @user_evaluate_count = @games.sum(:evaluate_count) if @games + if @games + @user_evaluate_count = @games.sum(:evaluate_count) + @games = @games.includes(:challenge, :game_codes, :outputs) + else + @user_evaluate_count = 0 + end + # 图形效率图的数据 @echart_data = student_efficiency(@homework, @work) end 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 diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 2a052fffe..9ea7578f2 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -353,121 +353,127 @@ module ExercisesHelper score5 = 0.0 #实训题 ques_stand = [] #问题是否正确 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) #学生的答案 - else - answers_content = q.exercise_shixun_answers.search_shixun_answers("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 #答案一致,多选或单选才给分,答案不对不给分 - if standard_answer.count > 0 - q_score_1 = (q.question_score / standard_answer.count) #当多选答案正确时,每个answer的分数均摊。 - else - q_score_1 = 0.0 - end - answers_content.update_all(:score => q_score_1) - score1 = score1 + q.question_score - end + exercise_questions&.each do |q| + begin + if q.question_type != 5 + answers_content = q.exercise_answers.where(user_id: user.id) #学生的答案 else - score1 += 0.0 + answers_content = q.exercise_shixun_answers.where(user_id: user.id) #学生的答案 end - elsif q.question_type == 3 #填空题 - if answers_content.present? - null_standard_answer = q.exercise_standard_answers - standard_answer_array = null_standard_answer.select(:exercise_choice_id,:answer_text) - standard_answer_ids = standard_answer_array.pluck(:exercise_choice_id).reject(&:blank?).uniq #标准答案的exercise_choice_id数组 - standard_answer_count = standard_answer_ids.count - if standard_answer_count > 0 #存在标准答案时才有分数 - q_score_2 = (q.question_score.to_f / standard_answer_count) #每一空的得分 - else - q_score_2 = 0.0 - end - if q.is_ordered - answers_content.each do |u| - i_standard_answer = standard_answer_array.where(exercise_choice_id:u.exercise_choice_id).pluck(:answer_text).reject(&:blank?).map!(&:downcase) #该选项的全部标准答案 - if i_standard_answer.include?(u.answer_text.downcase) #该空的标准答案包含用户的答案才有分数 - u.update_column('score',q_score_2) - score2 = score2 + q_score_2 + 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 #答案一致,多选或单选才给分,答案不对不给分 + if standard_answer.count > 0 + q_score_1 = (q.question_score.to_f / standard_answer.count) #当多选答案正确时,每个answer的分数均摊。 + else + q_score_1 = 0.0 end + answers_content.update_all(:score => q_score_1) + score1 = score1 + q.question_score end else - st_answer_text = standard_answer_array.pluck(:answer_text).reject(&:blank?).map!(&:downcase) - answers_content.each do |u| - u_answer_text = u.answer_text.downcase - if st_answer_text.include?(u_answer_text) #只要标准答案包含用户的答案,就有分数。同时,下一次循环时,就会删除该标准答案。防止用户的相同答案获分 - u.update_column("score",q_score_2) - score2 = score2 + q_score_2 - st_answer_text.delete(u_answer_text) + score1 += 0.0 + end + elsif q.question_type == 3 #填空题 + if answers_content.present? + null_standard_answer = q.exercise_standard_answers + standard_answer_array = null_standard_answer.select(:exercise_choice_id,:answer_text) + standard_answer_ids = standard_answer_array.pluck(:exercise_choice_id).reject(&:blank?).uniq #标准答案的exercise_choice_id数组 + standard_answer_count = standard_answer_ids.count + if standard_answer_count > 0 #存在标准答案时才有分数 + q_score_2 = (q.question_score.to_f / standard_answer_count) #每一空的得分 + else + q_score_2 = 0.0 + end + if q.is_ordered + answers_content.each do |u| + i_standard_answer = standard_answer_array.where(exercise_choice_id:u.exercise_choice_id).pluck(:answer_text).reject(&:blank?).map!(&:downcase) #该选项的全部标准答案 + if i_standard_answer.include?(u.answer_text.downcase) #该空的标准答案包含用户的答案才有分数 + u.update_column('score',q_score_2) + score2 = score2 + q_score_2 + end + end + else + st_answer_text = standard_answer_array.pluck(:answer_text).reject(&:blank?).map!(&:downcase) + answers_content.each do |u| + u_answer_text = u.answer_text.downcase + if st_answer_text.include?(u_answer_text) #只要标准答案包含用户的答案,就有分数。同时,下一次循环时,就会删除该标准答案。防止用户的相同答案获分 + u.update_column("score",q_score_2) + score2 = score2 + q_score_2 + st_answer_text.delete(u_answer_text) + end end end + else + score2 += 0.0 end - else - score2 += 0.0 - end - elsif q.question_type == 5 #实训题时,主观题这里不评分 - q.exercise_shixun_challenges.each do |exercise_cha| - game = Game.user_games(user.id,exercise_cha.challenge_id)&.first #当前用户的关卡 - if game.present? - exercise_cha_score = 0.0 - answer_status = 0 - if game.status == 2 && game.final_score >= 0 - exercise_cha_score = exercise_cha.question_score #每一关卡的得分 - answer_status = 1 - 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 - game_challenge = game.game_codes.search_challenge_path(cha_path)&.first - if game_challenge.present? - game_code = game_challenge - code = game_code.try(:new_code) + elsif q.question_type == 5 #实训题时,主观题这里不评分 + q.exercise_shixun_challenges&.each do |exercise_cha| + game = Game.user_games(user.id,exercise_cha.challenge_id)&.first #当前用户的关卡 + if game.present? + exercise_cha_score = 0.0 + answer_status = 0 + if game.status == 2 && game.final_score >= 0 + exercise_cha_score = exercise_cha.question_score #每一关卡的得分 + answer_status = 1 + 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) + game_challenge = game.game_codes.search_challenge_path(cha_path)&.first + if game_challenge.present? + game_code = game_challenge + code = game_code.try(:new_code) + else + code = git_fle_content(exercise_cha.shixun&.repo_path,cha_path) + end + sx_option = { + :exercise_question_id => q.id, + :exercise_shixun_challenge_id => exercise_cha.id, + :user_id => user.id, + :score => exercise_cha_score, + :answer_text => code, + :status => answer_status + } + ExerciseShixunAnswer.create(sx_option) else - code = git_fle_content(exercise_cha.shixun&.repo_path,cha_path) + ex_shixun_answer_content.first.update_column('score',exercise_cha_score) end - sx_option = { - :exercise_question_id => q.id, - :exercise_shixun_challenge_id => exercise_cha.id, - :user_id => user.id, - :score => exercise_cha_score, - :answer_text => code, - :status => answer_status - } - ExerciseShixunAnswer.create(sx_option) + score5 += exercise_cha_score else - ex_shixun_answer_content.first.update_column('score',exercise_cha_score) + score5 += 0.0 end - score5 += exercise_cha_score - else - score5 += 0.0 end end + user_scores = answers_content.blank? ? 0.0 : answers_content.score_reviewed.pluck(:score).sum + if user_scores > 0.0 + stand_answer = 1 + else + stand_answer = 0 + end + ques_option = { + "q_id":q.id, #该问题的id + "q_type":q.question_type, + "q_position":q.question_number, #该问题的位置 + "stand_status":stand_answer, #该问题是否正确,1为正确,0为错误 + "user_score":user_scores.round(1) #每个问题的总得分 + } + ques_stand.push(ques_option) + rescue Exception => e + Rails.logger.info("calcuclate_score_have_error____________________________#{e}") + next end - user_scores = answers_content.present? ? answers_content.score_reviewed.pluck(:score).sum : 0.0 - if user_scores > 0.0 - stand_answer = 1 - else - stand_answer = 0 - end - ques_option = { - "q_id":q.id, #该问题的id - "q_type":q.question_type, - "q_position":q.question_number, #该问题的位置 - "stand_status":stand_answer, #该问题是否正确,1为正确,0为错误 - "user_score":user_scores #每个问题的总得分 - } - 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 +693,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 af883131a..b6720c66c 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.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 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.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 end else w_18 = "--" 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/models/game.rb b/app/models/game.rb index c08884afb..ba6664d5c 100644 --- a/app/models/game.rb +++ b/app/models/game.rb @@ -115,9 +115,9 @@ class Game < ApplicationRecord end # 评测次数 - def evaluate_count - self.outputs.pluck(:query_index).first - end + #def evaluate_count + # self.outputs.pluck(:query_index).first + #end # 用户关卡得分 def get_user_final_score 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 diff --git a/app/tasks/exercise_publish_task.rb b/app/tasks/exercise_publish_task.rb index 4c8ee39e8..3df5f84ae 100644 --- a/app/tasks/exercise_publish_task.rb +++ b/app/tasks/exercise_publish_task.rb @@ -6,7 +6,7 @@ class ExercisePublishTask Rails.logger.info("log--------------------------------exercise_publish start") puts "--------------------------------exercise_publish start" exercises = Exercise.includes(:exercise_users).where("publish_time is not null and exercise_status = 1 and publish_time <=?",Time.now) - exercises.each do |exercise| + exercises&.each do |exercise| exercise.update_column('exercise_status', 2) course = exercise.course tid_str = "" @@ -45,7 +45,7 @@ class ExercisePublishTask # 分组设置发布时间的测验 exercise_group_settings = ExerciseGroupSetting.where("publish_time < ? and publish_time > ?", Time.now + 900, Time.now - 900) - exercise_group_settings.each do |exercise_group| + exercise_group_settings&.each do |exercise_group| exercise = exercise_group.exercise if exercise.present? course = exercise.course @@ -71,29 +71,35 @@ class ExercisePublishTask puts "--------------------------------exercise_end start" # 1。统一设置的试卷 exercises = Exercise.includes(:exercise_users,:exercise_questions).where("exercise_status = 2 AND unified_setting = true AND end_time <= ?",Time.now + 900) - exercises.each do |exercise| + exercises&.each do |exercise| ex_type = exercise.exercise_questions.pluck(:question_type).uniq exercise.update_column('exercise_status', 3) - exercise.exercise_users.each do |exercise_user| - if exercise_user&.commit_status == 0 && exercise_user&.start_at.present? - s_score = calculate_student_score(exercise, exercise_user.user)[:total_score] - if ex_type.include?(4) #是否包含主观题 - subjective_score = exercise_user.subjective_score - else - subjective_score = -1.0 + exercise.exercise_users&.each do |exercise_user| + begin + if (exercise_user&.commit_status == 0) && (exercise_user&.start_at.present?) + s_score = calculate_student_score(exercise, exercise_user.user)[:total_score] + if ex_type.include?(4) #是否包含主观题 + subjective_score = exercise_user.subjective_score + else + subjective_score = -1.0 + end + total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score + total_score = s_score + total_score_subjective_score + commit_option = { + :status => 1, + :commit_status => 1, + :end_at => Time.now, + :objective_score => s_score, + :score => total_score, + :subjective_score => subjective_score + } + exercise_user.update_attributes(commit_option) end - total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score - total_score = s_score + total_score_subjective_score - commit_option = { - :status => 1, - :commit_status => 1, - :end_at => Time.now, - :objective_score => s_score, - :score => total_score, - :subjective_score => subjective_score - } - exercise_user.update_attributes(commit_option) + rescue Exception => e + Rails.logger.info("rescue errors ___________________________#{e}") + next end + end end @@ -101,36 +107,41 @@ class ExercisePublishTask all_exercises = Exercise.includes(:exercise_group_settings,:exercise_users,:exercise_questions).where("unified_setting = false AND exercise_status = 2 AND end_time > ?",Time.now + 900) exercise_ids = all_exercises.blank? ? "(-1)" : "(" + all_exercises.map(&:id).join(",") + ")" ex_group_settings = ExerciseGroupSetting.where("end_time <= '#{Time.now}' and exercise_id in #{exercise_ids}") - ex_group_settings.each do |exercise_setting| + ex_group_settings&.each do |exercise_setting| exercise = exercise_setting.exercise - if exercise&.end_time <= Time.now + if exercise.end_time <= Time.now exercise.update_column('exercise_status', 3) end ex_types = exercise.exercise_questions.pluck(:question_type).uniq users = exercise.course.students.where(:course_group_id => exercise_setting.course_group_id) exercise_users = exercise.exercise_users.where(:user_id => users.pluck(:user_id)) - - exercise_users.each do |exercise_user| - if exercise_user.commit_status == 0 && !exercise_user.start_at.nil? - if ex_types.include?(4) #是否包含主观题 - subjective_score = exercise_user.subjective_score - else - subjective_score = -1.0 + exercise_users&.each do |exercise_user| + begin + if exercise_user.commit_status == 0 && !exercise_user.start_at.nil? + if ex_types.include?(4) #是否包含主观题 + subjective_score = exercise_user.subjective_score + else + subjective_score = -1.0 + end + s_score = calculate_student_score(exercise, exercise_user.user)[:total_score] + total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score + total_score = s_score + total_score_subjective_score + commit_option = { + :status => 1, + :commit_status => 1, + :end_at => Time.now, + :objective_score => s_score, + :score => total_score, + :subjective_score => subjective_score + } + exercise_user.update_attributes(commit_option) end - s_score = calculate_student_score(exercise, exercise_user.user)[:total_score] - total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score - total_score = s_score + total_score_subjective_score - commit_option = { - :status => 1, - :commit_status => 1, - :end_at => Time.now, - :objective_score => s_score, - :score => total_score, - :subjective_score => subjective_score - } - exercise_user.update_attributes(commit_option) + rescue Exception => e + Rails.logger.info("unified_setting_false_rescue errors ___________________________#{e}") + next end + end end Rails.logger.info("log--------------------------------exercise_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] diff --git a/app/views/shixuns/index.json.jbuilder b/app/views/shixuns/index.json.jbuilder index 41da7120f..8e5d49a34 100644 --- a/app/views/shixuns/index.json.jbuilder +++ b/app/views/shixuns/index.json.jbuilder @@ -1,7 +1,8 @@ -if @fuzzy_searchs - json.keyword @fuzzy_searchs - json.total_count @fuzzy_searchs.blank? ? nil : @total_count -end +# if @fuzzy_searchs +# json.keyword @fuzzy_searchs +# json.total_count @fuzzy_searchs.blank? ? nil : @total_count +# end +json.total_count @total_count json.pagination @total_count > 16 ? true : false json.search_tags @search_tags json.shixuns do 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