From 6035f984bad86eab0483aad19f02a17005627c17 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 22 Aug 2019 17:39:20 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=9A=84=E5=88=86?= =?UTF-8?q?=E6=95=B0=E8=BF=81=E7=A7=BB=E6=96=87=E4=BB=B6=E7=9A=84=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...20190822022306_add_exercise_user_update.rb | 38 ++++++++++++++----- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/db/migrate/20190822022306_add_exercise_user_update.rb b/db/migrate/20190822022306_add_exercise_user_update.rb index f45e6a8ee..8bf668934 100644 --- a/db/migrate/20190822022306_add_exercise_user_update.rb +++ b/db/migrate/20190822022306_add_exercise_user_update.rb @@ -2,19 +2,37 @@ class AddExerciseUserUpdate < ActiveRecord::Migration[5.2] include ExercisesHelper def change #2019,8,22添加 - exs = Exercise.all.is_exercise_published.where("publish_time > ?",(Time.now - 2.months)).includes(:exercise_questions,:exercise_users) + two_months = Time.now - 2.months + exs = Exercise.all.is_exercise_published.where("publish_time > ?",two_months).includes(:exercise_questions,:exercise_users) exs.each do |ex| - ex_users = ex.exercise_users.exercise_user_committed.where("end_at is not null and end_at > ?",(Time.now - 2.months)) - if ex_users.present? - ex_users.each do |ex_user| - calculate_score = calculate_student_score(ex,ex_user.user)[:total_score] - subjective_score = ex_user.subjective_score - total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score - total_score = calculate_score + total_score_subjective_score - ex_user.update_attributes(score:total_score,objective_score:calculate_score) - puts ex_user.id + if ex.exercise_questions.where("created_at < ?",Time.now - 1.month).pluck(:question_type).include?(1) #含有多选题,且是1个月前创建的才更新 + ex_users = ex.exercise_users.exercise_user_committed.where("end_at is not null and end_at > ?",two_months) + if ex_users.exists? + ex_users.each do |ex_user| + calculate_score = calculate_student_score(ex,ex_user.user)[:total_score] + subjective_score = ex_user.subjective_score + total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score + total_score = calculate_score + total_score_subjective_score + ex_user.update_attributes(score:total_score,objective_score:calculate_score) + puts ex_user.id + end end end end + + #1936的试卷成绩有问题。 + # #https://www.educoder.net/courses/2935/exercises/1936/users/pizfnr5ts + ex_special = Exercise.find_by_id(1936) + ex_special_users = ex_special.exercise_users.exercise_user_committed.where("end_at is not null and end_at > ?",two_months) + if ex_special.present? && ex_special_users.exists? + ex_special_users.each do |ex_user| + calculate_score = calculate_student_score(ex_special,ex_user.user)[:total_score] + subjective_score = ex_user.subjective_score + total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score + total_score = calculate_score + total_score_subjective_score + ex_user.update_attributes(score:total_score,objective_score:calculate_score) + puts ex_user.id + end + end end end From 646bf9e0b5f3a9b12561dfce6ca3507ba8344f9e Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 23 Aug 2019 09:39:09 +0800 Subject: [PATCH 2/3] qiayi --- ...20190822022306_add_exercise_user_update.rb | 72 +++++++++---------- ...13551_re_calculate_exercise_users_socre.rb | 38 ++++++++++ 2 files changed, 74 insertions(+), 36 deletions(-) create mode 100644 db/migrate/20190823013551_re_calculate_exercise_users_socre.rb diff --git a/db/migrate/20190822022306_add_exercise_user_update.rb b/db/migrate/20190822022306_add_exercise_user_update.rb index 8bf668934..05881c78b 100644 --- a/db/migrate/20190822022306_add_exercise_user_update.rb +++ b/db/migrate/20190822022306_add_exercise_user_update.rb @@ -1,38 +1,38 @@ class AddExerciseUserUpdate < ActiveRecord::Migration[5.2] - include ExercisesHelper - def change - #2019,8,22添加 - two_months = Time.now - 2.months - exs = Exercise.all.is_exercise_published.where("publish_time > ?",two_months).includes(:exercise_questions,:exercise_users) - exs.each do |ex| - if ex.exercise_questions.where("created_at < ?",Time.now - 1.month).pluck(:question_type).include?(1) #含有多选题,且是1个月前创建的才更新 - ex_users = ex.exercise_users.exercise_user_committed.where("end_at is not null and end_at > ?",two_months) - if ex_users.exists? - ex_users.each do |ex_user| - calculate_score = calculate_student_score(ex,ex_user.user)[:total_score] - subjective_score = ex_user.subjective_score - total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score - total_score = calculate_score + total_score_subjective_score - ex_user.update_attributes(score:total_score,objective_score:calculate_score) - puts ex_user.id - end - end - end - end - - #1936的试卷成绩有问题。 - # #https://www.educoder.net/courses/2935/exercises/1936/users/pizfnr5ts - ex_special = Exercise.find_by_id(1936) - ex_special_users = ex_special.exercise_users.exercise_user_committed.where("end_at is not null and end_at > ?",two_months) - if ex_special.present? && ex_special_users.exists? - ex_special_users.each do |ex_user| - calculate_score = calculate_student_score(ex_special,ex_user.user)[:total_score] - subjective_score = ex_user.subjective_score - total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score - total_score = calculate_score + total_score_subjective_score - ex_user.update_attributes(score:total_score,objective_score:calculate_score) - puts ex_user.id - end - end - end + # include ExercisesHelper + # def change + # #2019,8,22添加 + # two_months = Time.now - 2.months + # exs = Exercise.all.is_exercise_published.where("publish_time > ?",two_months).includes(:exercise_questions,:exercise_users) + # exs.each do |ex| + # if ex.exercise_questions.where("created_at < ?",Time.now - 1.month).pluck(:question_type).include?(1) #含有多选题,且是1个月前创建的才更新 + # ex_users = ex.exercise_users.exercise_user_committed.where("end_at is not null and end_at > ?",two_months) + # if ex_users.exists? + # ex_users.each do |ex_user| + # calculate_score = calculate_student_score(ex,ex_user.user)[:total_score] + # subjective_score = ex_user.subjective_score + # total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score + # total_score = calculate_score + total_score_subjective_score + # ex_user.update_attributes(score:total_score,objective_score:calculate_score) + # puts ex_user.id + # end + # end + # end + # end + # + # #1936的试卷成绩有问题。 + # # #https://www.educoder.net/courses/2935/exercises/1936/users/pizfnr5ts + # ex_special = Exercise.find_by_id(1936) + # ex_special_users = ex_special.exercise_users.exercise_user_committed.where("end_at is not null and end_at > ?",two_months) + # if ex_special.present? && ex_special_users.exists? + # ex_special_users.each do |ex_user| + # calculate_score = calculate_student_score(ex_special,ex_user.user)[:total_score] + # subjective_score = ex_user.subjective_score + # total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score + # total_score = calculate_score + total_score_subjective_score + # ex_user.update_attributes(score:total_score,objective_score:calculate_score) + # puts ex_user.id + # end + # end + # end end diff --git a/db/migrate/20190823013551_re_calculate_exercise_users_socre.rb b/db/migrate/20190823013551_re_calculate_exercise_users_socre.rb new file mode 100644 index 000000000..cd6c67c76 --- /dev/null +++ b/db/migrate/20190823013551_re_calculate_exercise_users_socre.rb @@ -0,0 +1,38 @@ +class ReCalculateExerciseUsersSocre < ActiveRecord::Migration[5.2] + include ExercisesHelper + def change + #2019,8,22添加 + two_months = Time.now - 2.months + exs = Exercise.all.is_exercise_published.where("publish_time > ?",two_months).includes(:exercise_questions,:exercise_users) + exs.each do |ex| + if ex.exercise_questions.where("created_at < ?",Time.now - 1.month).pluck(:question_type).include?(1) #含有多选题,且是1个月前创建的才更新 + ex_users = ex.exercise_users.exercise_user_committed.where("end_at is not null and end_at > ?",two_months) + if ex_users.exists? + ex_users.each do |ex_user| + calculate_score = calculate_student_score(ex,ex_user.user)[:total_score] + subjective_score = ex_user.subjective_score + total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score + total_score = calculate_score + total_score_subjective_score + ex_user.update_attributes(score:total_score,objective_score:calculate_score) + puts ex_user.id + end + end + end + end + + #1936的试卷成绩有问题。 + # #https://www.educoder.net/courses/2935/exercises/1936/users/pizfnr5ts + ex_special = Exercise.find_by_id(1936) + ex_special_users = ex_special.exercise_users.exercise_user_committed.where("end_at is not null and end_at > ?",two_months) + if ex_special.present? && ex_special_users.exists? + ex_special_users.each do |ex_user| + calculate_score = calculate_student_score(ex_special,ex_user.user)[:total_score] + subjective_score = ex_user.subjective_score + total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score + total_score = calculate_score + total_score_subjective_score + ex_user.update_attributes(score:total_score,objective_score:calculate_score) + puts ex_user.id + end + end + end +end From 77496f28581c6d823e7c91dba6621c24c004e85a Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 23 Aug 2019 13:56:55 +0800 Subject: [PATCH 3/3] fixubg --- app/helpers/exercises_helper.rb | 75 ++++++++++--------- ...13551_re_calculate_exercise_users_socre.rb | 38 ---------- 2 files changed, 40 insertions(+), 73 deletions(-) delete mode 100644 db/migrate/20190823013551_re_calculate_exercise_users_socre.rb diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 7caed7fae..0b18ff6f8 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -461,45 +461,50 @@ module ExercisesHelper 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 - if game.final_score > 0 - exercise_cha_score = game.real_score(exercise_cha.question_score) - # 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) - code = nil - if exercise_cha.challenge&.path.present? - 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) + user_shixun_score = exercise_cha&.exercise_shixun_answers&.where(user_id:user.id,exercise_question_id:q.id) + if user_shixun_score.present? + score5 += user_shixun_score&.first.score + else + 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 + if game.final_score > 0 + exercise_cha_score = game.real_score(exercise_cha.question_score) + # 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) + code = nil + if exercise_cha.challenge&.path.present? + 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(game.myshixun.repo_path,cha_path) + end + end + if ex_shixun_answer_content.blank? #把关卡的答案存入试卷的实训里 + ### Todo 实训题的_shixun_details里的代码是不是直接从这里取出就可以了?涉及到code的多个版本库的修改 + sx_option = { + :exercise_question_id => q.id, + :exercise_shixun_challenge_id => exercise_cha.id, + :user_id => user.id, + :score => exercise_cha_score.round(1), + :answer_text => code, + :status => answer_status + } + ExerciseShixunAnswer.create(sx_option) else - code = git_fle_content(game.myshixun.repo_path,cha_path) + ex_shixun_answer_content.first.update_attributes(score:exercise_cha_score.round(1),answer_text:code) end - end - if ex_shixun_answer_content.blank? #把关卡的答案存入试卷的实训里 - ### Todo 实训题的_shixun_details里的代码是不是直接从这里取出就可以了?涉及到code的多个版本库的修改 - sx_option = { - :exercise_question_id => q.id, - :exercise_shixun_challenge_id => exercise_cha.id, - :user_id => user.id, - :score => exercise_cha_score.round(1), - :answer_text => code, - :status => answer_status - } - ExerciseShixunAnswer.create(sx_option) + score5 += exercise_cha_score else - ex_shixun_answer_content.first.update_attributes(score:exercise_cha_score.round(1),answer_text:code) + score5 += 0.0 end - score5 += exercise_cha_score - else - score5 += 0.0 end end end diff --git a/db/migrate/20190823013551_re_calculate_exercise_users_socre.rb b/db/migrate/20190823013551_re_calculate_exercise_users_socre.rb deleted file mode 100644 index c36a3df3f..000000000 --- a/db/migrate/20190823013551_re_calculate_exercise_users_socre.rb +++ /dev/null @@ -1,38 +0,0 @@ -class ReCalculateExerciseUsersSocre < ActiveRecord::Migration[5.2] - include ExercisesHelper - def change - #2019,8,22添加 - two_months = Time.now - 2.months - exs = Exercise.all.is_exercise_published.where("publish_time > ?",two_months).includes(:exercise_questions,:exercise_users) - exs.each do |ex| - if ex.exercise_questions.where("created_at < ?",Time.now - 1.month).pluck(:question_type).include?(1) #含有多选题,且是1个月前创建的才更新 - ex_users = ex.exercise_users.exercise_user_committed.where("end_at is not null and end_at > ?",two_months) - if ex_users.exists? - ex_users.each do |ex_user| - calculate_score = calculate_student_score(ex,ex_user.user)[:total_score] - subjective_score = ex_user.subjective_score - total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score - total_score = calculate_score + total_score_subjective_score - ex_user.update_attributes(score:total_score,objective_score:calculate_score) - puts ex_user.id - end - end - end - end - - # #1936的试卷成绩有问题。 - # # #https://www.educoder.net/courses/2935/exercises/1936/users/pizfnr5ts - # ex_special = Exercise.find_by_id(1936) - # ex_special_users = ex_special.exercise_users.exercise_user_committed.where("end_at is not null and end_at > ?",two_months) - # if ex_special.present? && ex_special_users.exists? - # ex_special_users.each do |ex_user| - # calculate_score = calculate_student_score(ex_special,ex_user.user)[:total_score] - # subjective_score = ex_user.subjective_score - # total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score - # total_score = calculate_score + total_score_subjective_score - # ex_user.update_attributes(score:total_score,objective_score:calculate_score) - # puts ex_user.id - # end - # end - end -end