From 9ddd5f6f75c47178c18740d601386da3af0fbc57 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 15 Jan 2020 15:35:38 +0800 Subject: [PATCH 01/91] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E5=8A=A0=E7=B4=A2?= =?UTF-8?q?=E5=BC=95=E3=80=81=E6=9B=B4=E6=94=B9=E7=AE=97=E5=88=86=E8=A7=84?= =?UTF-8?q?=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exercise_answers_controller.rb | 7 ++- app/helpers/exercise_questions_helper.rb | 10 ++-- app/helpers/exercises_helper.rb | 56 +++++++++++-------- ...30_add_choice_index_to_exercise_answers.rb | 17 ++++++ ...ce_index_uniq_index_to_exercise_answers.rb | 13 +++++ 5 files changed, 75 insertions(+), 28 deletions(-) create mode 100644 db/migrate/20200115020230_add_choice_index_to_exercise_answers.rb create mode 100644 db/migrate/20200115030135_add_choice_index_uniq_index_to_exercise_answers.rb diff --git a/app/controllers/exercise_answers_controller.rb b/app/controllers/exercise_answers_controller.rb index 158628475..31df2291e 100644 --- a/app/controllers/exercise_answers_controller.rb +++ b/app/controllers/exercise_answers_controller.rb @@ -26,6 +26,7 @@ class ExerciseAnswersController < ApplicationController end elsif q_type == Exercise::MULTIPLE #多选题的 choice_ids = params[:exercise_choice_id].present? ? params[:exercise_choice_id] : [] + question_choice_ids = @exercise_question.exercise_choices.pluck(:id) ea_ids = ea.pluck(:exercise_choice_id) common_answer_ids = choice_ids & ea_ids #已经存在的试卷选项id @@ -37,7 +38,8 @@ class ExerciseAnswersController < ApplicationController :user_id => current_user.id, :exercise_question_id => @exercise_question.id, :exercise_choice_id => e, - :answer_text => "" + :answer_text => "", + :choice_index => question_choice_ids.index(e).to_i + 1 # choice的序号 } ex_a = ExerciseAnswer.new(answer_option) ex_a.save! @@ -52,7 +54,8 @@ class ExerciseAnswersController < ApplicationController :user_id => current_user.id, :exercise_question_id => @exercise_question.id, :exercise_choice_id => choice_id, - :answer_text => answer_text + :answer_text => answer_text, + :choice_index => choice_id } ea_answer = ea.search_answer_users("exercise_choice_id",choice_id) if ea.present? && ea_answer.present? diff --git a/app/helpers/exercise_questions_helper.rb b/app/helpers/exercise_questions_helper.rb index 69dee034f..1cc613bc6 100644 --- a/app/helpers/exercise_questions_helper.rb +++ b/app/helpers/exercise_questions_helper.rb @@ -2,9 +2,11 @@ module ExerciseQuestionsHelper def get_exercise_question_info(question,exercise,ex_user,ex_answerer_id) answered_content = [] exercise_answers = question.exercise_answers.search_exercise_answer("user_id",ex_answerer_id) #试卷用户的回答 - if question.question_type <= 2 + if question.question_type == Exercise::SINGLE || question.question_type == Exercise::JUDGMENT + answered_content << exercise_answers.last&.exercise_choice_id if exercise_answers.present? + elsif question.question_type == Exercise::MULTIPLE answered_content = exercise_answers.pluck(:exercise_choice_id) - elsif question.question_type == 3 + elsif question.question_type == Exercise::COMPLETION exercise_answers.each do |a| u_answer = { "choice_id": a.exercise_choice_id, @@ -12,10 +14,10 @@ module ExerciseQuestionsHelper } answered_content.push(u_answer) end - elsif question.question_type == 4 + elsif question.question_type == Exercise::SUBJECTIVE answered_content = exercise_answers.pluck(:answer_text) end - if question.question_type == 5 && ex_user.present? && ex_user.commit_status == 1 #存在实训题,且用户已提交了的,如果实训题只做了一半就关闭,则相当于不要了 + if question.question_type == Exercise::PRACTICAL && ex_user.present? && ex_user.commit_status == 1 #存在实训题,且用户已提交了的,如果实训题只做了一半就关闭,则相当于不要了 if exercise.exercise_status == 3 #如果试卷已截止,则可以看到分数,否则不能查看分数 shixun_type = 2 else diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 513f980d8..0ec1f6cb3 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -16,8 +16,8 @@ module ExercisesHelper end if q_type <= Exercise::JUDGMENT - if answers_content.present? #学生有回答时,分数已经全部存到exercise_answer 表,所以可以直接取第一个值 - ques_score = answers_content.first.score + if answers_content.present? #学生有回答时,分数已经全部存到exercise_answer 表,多选题直接取第一个值,单选题和判断题选最后一个值(考虑并发) + ques_score = q_type == Exercise::MULTIPLE ? answers_content.first.score : answers_content.last.score ques_score = ques_score < 0 ? 0.0 : ques_score # answer_choice_array = [] # answers_content.each do |a| @@ -441,30 +441,42 @@ module ExercisesHelper 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 #该问题的标准答案,可能有多个 - - #TODO: 旧版多选题的标准答案是放在一个里面的,新版又做成了一个题有多个标准答案(exercise_choice_id存放的是标准答案的位置..) - if q.question_type == 1 && standard_answer.size == 1 - standard_answer = standard_answer.first.to_s.split("").map(&:to_i).sort - end - - if user_answer_content == standard_answer #答案一致,多选或单选才给分,答案不对不给分 - if standard_answer.size > 0 + if q.question_type == 0 || q.question_type == 2 ## 单选、判断题的算分与多选题分开计算 + user_answer = answers_content.last.exercise_choice.choice_position + standard_answer = q.exercise_standard_answers.first&.exercise_choice_id + if standard_answer.present? && user_answer == standard_answer q_score_1 = q.question_score - # q_score_1 = (q.question_score.to_f / standard_answer.count) #当多选答案正确时,每个answer的分数均摊。 + score1 = score1 + q.question_score else - q_score_1 = 0.0 + q_score_1 = -1.0 end - answers_content.update_all(:score => q_score_1) - score1 = score1 + q.question_score + answers_content.last.update!(score: q_score_1) else - answers_content.update_all(:score => -1.0) - score1 += 0.0 + 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 #该问题的标准答案,可能有多个 + + #TODO: 旧版多选题的标准答案是放在一个里面的,新版又做成了一个题有多个标准答案(exercise_choice_id存放的是标准答案的位置..) + if q.question_type == 1 && standard_answer.size == 1 + standard_answer = standard_answer.first.to_s.split("").map(&:to_i).sort + end + + if user_answer_content == standard_answer #答案一致,多选或单选才给分,答案不对不给分 + if standard_answer.size > 0 + 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 + answers_content.update_all(:score => q_score_1) + score1 = score1 + q.question_score + else + answers_content.update_all(:score => -1.0) + score1 += 0.0 + end end else score1 += 0.0 diff --git a/db/migrate/20200115020230_add_choice_index_to_exercise_answers.rb b/db/migrate/20200115020230_add_choice_index_to_exercise_answers.rb new file mode 100644 index 000000000..cb518bb42 --- /dev/null +++ b/db/migrate/20200115020230_add_choice_index_to_exercise_answers.rb @@ -0,0 +1,17 @@ +class AddChoiceIndexToExerciseAnswers < ActiveRecord::Migration[5.2] + def change + add_column :exercise_answers, :choice_index, :integer, default: 1 + + multi_questions = ExerciseQuestion.where(question_type: 1) + multi_questions.includes(:exercise_choices, :exercise_answers).find_each do |question| + exercise_answers = question.exercise_answers + exercise_answers.find_each do |answer| + choice_index = question.exercise_choices.pluck(:id).index(answer.exercise_choice_id).to_i + 1 + answer.update_column('choice_index', choice_index) + end + puts "multi_questions: #{question.id}" + end + + ExerciseAnswer.joins(:exercise_question).where(exercise_questions: {question_type: 3}).update_all("choice_index = exercise_choice_id") + end +end diff --git a/db/migrate/20200115030135_add_choice_index_uniq_index_to_exercise_answers.rb b/db/migrate/20200115030135_add_choice_index_uniq_index_to_exercise_answers.rb new file mode 100644 index 000000000..d870fba7f --- /dev/null +++ b/db/migrate/20200115030135_add_choice_index_uniq_index_to_exercise_answers.rb @@ -0,0 +1,13 @@ +class AddChoiceIndexUniqIndexToExerciseAnswers < ActiveRecord::Migration[5.2] + def change + sql = %Q(delete from exercise_answers where (exercise_question_id, user_id, choice_index) in + (select * from (select exercise_question_id, user_id, choice_index from exercise_answers group by exercise_question_id, user_id, choice_index having count(*) > 1) a) + and id not in (select * from (select max(id) from exercise_answers group by exercise_question_id, user_id, choice_index having count(*) > 1 order by id) b)) + ActiveRecord::Base.connection.execute sql + + add_index :exercise_answers, [:exercise_question_id, :user_id, :choice_index], name: 'exercise_user_choice_index', unique: true + + remove_index :exercise_answers, name: :exercise_choice_index + + end +end From 373bd4e712027a5e74b83b56ef4d3697cd1c7f3d Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 15 Jan 2020 15:41:47 +0800 Subject: [PATCH 02/91] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E7=9A=84=E5=88=A0?= =?UTF-8?q?=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/shixuns_helper.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/helpers/shixuns_helper.rb b/app/helpers/shixuns_helper.rb index 655a7ed04..85da9858b 100644 --- a/app/helpers/shixuns_helper.rb +++ b/app/helpers/shixuns_helper.rb @@ -24,6 +24,8 @@ module ShixunsHelper "已发布" when 3 "已关闭" + when -1 + "已删除" end end From e571a009ed93ff7e71c12bfd800ec3d0979af12a Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 15 Jan 2020 16:06:01 +0800 Subject: [PATCH 03/91] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E5=8A=A0=E5=85=A5?= =?UTF-8?q?=E9=A2=98=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercises_controller.rb | 3 ++- app/controllers/question_banks_controller.rb | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 44bfcf03f..193ef857b 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -316,7 +316,8 @@ class ExercisesController < ApplicationController :question_number => q.question_number, :question_score => q.question_score, :shixun_id => q.shixun_id, - :shixun_name => q.shixun_name + :shixun_name => q.shixun_name, + :is_ordered => q.is_ordered } exercise_bank_question = current_ex_bank.exercise_bank_questions.new option exercise_bank_question.save! diff --git a/app/controllers/question_banks_controller.rb b/app/controllers/question_banks_controller.rb index 5183c7a96..bcb88ad85 100644 --- a/app/controllers/question_banks_controller.rb +++ b/app/controllers/question_banks_controller.rb @@ -259,7 +259,8 @@ class QuestionBanksController < ApplicationController :question_number => q.question_number, :question_score => q.question_score, :shixun_name => q.shixun_name, - :shixun_id => q.shixun_id + :shixun_id => q.shixun_id, + :is_ordered => q.is_ordered } exercise_question = new_exercise.exercise_questions.new option # question_type:5实训题;其他是非实训题 From 64e00ccf33eaae2cfaa9fe44b74d3c793e8e2c6b Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 15 Jan 2020 16:14:45 +0800 Subject: [PATCH 04/91] =?UTF-8?q?=E8=AF=BE=E5=A0=82=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E8=A7=92=E8=89=B2=E7=9A=84=E6=8F=90=E7=A4=BA=E8=AF=AD=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/weapps/courses_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/weapps/courses_controller.rb b/app/controllers/weapps/courses_controller.rb index d732416ba..07e35b531 100644 --- a/app/controllers/weapps/courses_controller.rb +++ b/app/controllers/weapps/courses_controller.rb @@ -108,7 +108,7 @@ class Weapps::CoursesController < Weapps::BaseController def change_member_roles @course = current_course tip_exception("请至少选择一个角色") if params[:roles].reject(&:blank?).blank? - tip_exception("不能具有老师、助教两种角色") if params[:roles].include?("PROFESSOR") && params[:roles].include?("ASSISTANT_PROFESSOR") + tip_exception("老师、助教角色只能二选一") if params[:roles].include?("PROFESSOR") && params[:roles].include?("ASSISTANT_PROFESSOR") params[:user_ids].each do |user_id| course_members = @course.course_members.where(user_id: user_id) From 99375fa7bbca577add5e56fa90fb43c59d73c4ab Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 15 Jan 2020 16:16:50 +0800 Subject: [PATCH 05/91] =?UTF-8?q?=E8=AF=BE=E5=A0=82=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E8=A7=92=E8=89=B2=E7=9A=84=E6=8F=90=E7=A4=BA=E8=AF=AD=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/weapps/courses_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/weapps/courses_controller.rb b/app/controllers/weapps/courses_controller.rb index 07e35b531..35a122e2c 100644 --- a/app/controllers/weapps/courses_controller.rb +++ b/app/controllers/weapps/courses_controller.rb @@ -108,7 +108,7 @@ class Weapps::CoursesController < Weapps::BaseController def change_member_roles @course = current_course tip_exception("请至少选择一个角色") if params[:roles].reject(&:blank?).blank? - tip_exception("老师、助教角色只能二选一") if params[:roles].include?("PROFESSOR") && params[:roles].include?("ASSISTANT_PROFESSOR") + tip_exception("教师、助教角色只能二选一") if params[:roles].include?("PROFESSOR") && params[:roles].include?("ASSISTANT_PROFESSOR") params[:user_ids].each do |user_id| course_members = @course.course_members.where(user_id: user_id) From b5e5432873c787e39a98fe6a31f90b7957aa0ee2 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 15 Jan 2020 16:42:29 +0800 Subject: [PATCH 06/91] =?UTF-8?q?=E5=86=85=E5=AD=98=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/subjects/user_used_info_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/subjects/user_used_info_service.rb b/app/services/subjects/user_used_info_service.rb index 12c7f6ab7..9b76e3473 100644 --- a/app/services/subjects/user_used_info_service.rb +++ b/app/services/subjects/user_used_info_service.rb @@ -13,7 +13,7 @@ class Subjects::UserUsedInfoService < ApplicationService users_info = [] users = User.includes(myshixuns: :games).where(myshixuns: {shixun_id: shixun_ids}, games: {status: 2}, users: {is_test: false}) users.find_in_batches(batch_size: 500) do |u| - Parallel.each(u, in_processes: 5) do |user| + Parallel.each(u, in_processes: 3) do |user| myshixuns = user.myshixuns.select{|m| shixun_ids.include?(m.shixun_id)} name = "#{user.lastname}#{user.firstname}" passed_myshixun_count = myshixuns.select{|m| m.status == 1}.size From 5223734c4a40ebde1e39f2329c937254433dc00d Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 15 Jan 2020 17:01:23 +0800 Subject: [PATCH 07/91] 1 --- app/controllers/application_controller.rb | 2 +- app/services/shixun_search_service.rb | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index fdb41c114..3c481e8b6 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -23,7 +23,7 @@ class ApplicationController < ActionController::Base # 所有请求必须合法签名 def check_sign - if !Rails.env.development? + if !Rails.env.development? || Rails.logger.info("66666 #{params}") # suffix = request.url.split(".").last.split("?").first # suffix_arr = ["xls", "xlsx", "pdf", "zip"] # excel文件先注释 diff --git a/app/services/shixun_search_service.rb b/app/services/shixun_search_service.rb index 071b9f478..323804e95 100644 --- a/app/services/shixun_search_service.rb +++ b/app/services/shixun_search_service.rb @@ -43,7 +43,6 @@ class ShixunSearchService < ApplicationService @shixuns = @shixuns.where(trainee: params[:diff]) end - Rails.logger.info("search_shixun_ids: #{@shixuns.pluck(:id)}") Shixun.search(keyword, search_options) end @@ -53,7 +52,7 @@ class ShixunSearchService < ApplicationService order = if sort_str == "wechat_myshixuns_count" - {"is_wechat_support" => "desc", sort_str => order_str} + {"is_wechat_support" => "desc", "myshixuns_count" => order_str} else {sort_str => order_str} end From b29c2d8198273de06b52dd56bdd49be8c43cddd2 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 15 Jan 2020 17:04:22 +0800 Subject: [PATCH 08/91] dead parallel --- app/services/subjects/user_used_info_service.rb | 2 +- lib/tasks/statistic_subject_info.rake | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/services/subjects/user_used_info_service.rb b/app/services/subjects/user_used_info_service.rb index 9b76e3473..78dbfe8e9 100644 --- a/app/services/subjects/user_used_info_service.rb +++ b/app/services/subjects/user_used_info_service.rb @@ -13,7 +13,7 @@ class Subjects::UserUsedInfoService < ApplicationService users_info = [] users = User.includes(myshixuns: :games).where(myshixuns: {shixun_id: shixun_ids}, games: {status: 2}, users: {is_test: false}) users.find_in_batches(batch_size: 500) do |u| - Parallel.each(u, in_processes: 3) do |user| + Parallel.each(u, in_processes: 2) do |user| myshixuns = user.myshixuns.select{|m| shixun_ids.include?(m.shixun_id)} name = "#{user.lastname}#{user.firstname}" passed_myshixun_count = myshixuns.select{|m| m.status == 1}.size diff --git a/lib/tasks/statistic_subject_info.rake b/lib/tasks/statistic_subject_info.rake index c9f0361fc..f982cfc12 100644 --- a/lib/tasks/statistic_subject_info.rake +++ b/lib/tasks/statistic_subject_info.rake @@ -124,7 +124,7 @@ namespace :subjects do "code_line_count, evaluate_count, cost_time, created_at, updated_at" subjects.find_in_batches(batch_size: 50) do |s| - Parallel.each(s, in_processes: 5) do |subject| + Parallel.each(s, in_processes: 4) do |subject| puts("---------------------user_info_statistic: #{subject.id}") data = Subjects::UserUsedInfoService.call(subject) data.each do |key| From 25ae96a83ae5ce8176547089f472f6f349dede59 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 15 Jan 2020 17:07:03 +0800 Subject: [PATCH 09/91] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E7=9A=84=E7=AD=89?= =?UTF-8?q?=E7=BA=A7=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/shixun.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/shixun.rb b/app/models/shixun.rb index c16c4df4e..30c27ba94 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -276,8 +276,8 @@ class Shixun < ApplicationRecord case trainee when 1 then '初级学员' when 2 then '中级学员' - when 3 then '高级学员' - when 4 then '顶级学员' + when 3 then '中高级学员' + when 4 then '高级学员' else '' end end @@ -286,8 +286,8 @@ class Shixun < ApplicationRecord case trainee when 1 then '初级' when 2 then '中级' - when 3 then '高级' - when 4 then '顶级' + when 3 then '中高级' + when 4 then '高级' else '' end end From c64cf2928efe5b48c2b703eb206793f124b0055c Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 15 Jan 2020 17:12:51 +0800 Subject: [PATCH 10/91] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E7=9A=84=E7=AD=89?= =?UTF-8?q?=E7=BA=A7=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/shixuns_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/helpers/shixuns_helper.rb b/app/helpers/shixuns_helper.rb index 85da9858b..451d4a9a4 100644 --- a/app/helpers/shixuns_helper.rb +++ b/app/helpers/shixuns_helper.rb @@ -1,12 +1,12 @@ module ShixunsHelper def level_to_s(level) - %W(初级 中级 高级 顶级)[level-1] + %W(初级 中级 中高级 高级)[level-1] end #难度 def diff_to_s(trainee) - %W(初级学员 中级学员 高级学员 顶级学员)[trainee-1] + %W(初级学员 中级学员 中高级学员 高级学员)[trainee-1] end #1. 未发布 From f4f62f59dcc1a9b9a177afeb91204eade43ccc05 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 15 Jan 2020 17:39:09 +0800 Subject: [PATCH 11/91] =?UTF-8?q?=E9=A2=98=E5=BA=93=E7=9A=84=E5=88=A0?= =?UTF-8?q?=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/item_banks_controller.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/controllers/item_banks_controller.rb b/app/controllers/item_banks_controller.rb index a0abffe6c..f108c1fad 100644 --- a/app/controllers/item_banks_controller.rb +++ b/app/controllers/item_banks_controller.rb @@ -41,7 +41,11 @@ class ItemBanksController < ApplicationController def destroy ActiveRecord::Base.transaction do ApplyAction.where(container_type: "ItemBank", container_id: @item.id).destroy_all - @item.destroy! + if @item.item_type == "PROGRAM" + @item.container&.destroy! + else + @item.destroy! + end render_ok end end From ed258312ae4ed378e74fc0ac1ff8e4c2e706a43e Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 15 Jan 2020 17:49:08 +0800 Subject: [PATCH 12/91] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../subjects/shixun_used_info_service.rb | 31 ++--- lib/tasks/statistic_subject_info.rake | 115 ++++++++++-------- 2 files changed, 78 insertions(+), 68 deletions(-) diff --git a/app/services/subjects/shixun_used_info_service.rb b/app/services/subjects/shixun_used_info_service.rb index dfd8485e0..5fa99a120 100644 --- a/app/services/subjects/shixun_used_info_service.rb +++ b/app/services/subjects/shixun_used_info_service.rb @@ -10,20 +10,23 @@ class Subjects::ShixunUsedInfoService < ApplicationService stages.each do |stage| position = stage.position shixuns = stage.shixuns.includes(myshixuns: :games, homework_commons: :course) - shixuns.each_with_index do |shixun, index| - stage = "#{position}-#{index+1}" - name = shixun.name - myshixuns = shixun.myshixuns - challenge_count = shixun.challenges_count - course_count = shixun.homework_commons.map{|hc| hc.course_id}.uniq.size - school_count = shixun.homework_commons.map{|hc| hc.course&.school_id}.uniq.size - used_count = shixun.myshixuns_count - passed_count = myshixuns.select{|m| m.status == 1}.size - evaluate_count = myshixuns.map{|m| m.output_times }.sum - passed_ave_time = passed_count > 0 ? myshixuns.map{|m| m.total_cost_time}.sum : 0 - shixun_infos << {stage: stage, name: name, challenge_count: challenge_count, course_count: course_count, - school_count: school_count, used_count: used_count, passed_count: passed_count, - evaluate_count: evaluate_count, passed_ave_time: passed_ave_time, shixun_id: shixun.id} + shixuns.find_in_batches(batch_size: 1000) do |s| + Parallel.each_with_index(s, in_processes: 2) do |shixun, index| + stage = "#{position}-#{index+1}" + name = shixun.name + myshixuns = shixun.myshixuns + challenge_count = shixun.challenges_count + course_count = shixun.homework_commons.map{|hc| hc.course_id}.uniq.size + school_count = shixun.homework_commons.map{|hc| hc.course&.school_id}.uniq.size + used_count = shixun.myshixuns_count + passed_count = myshixuns.select{|m| m.status == 1}.size + evaluate_count = myshixuns.map{|m| m.output_times }.sum + passed_ave_time = passed_count > 0 ? myshixuns.map{|m| m.total_cost_time}.sum : 0 + shixun_infos << {stage: stage, name: name, challenge_count: challenge_count, course_count: course_count, + school_count: school_count, used_count: used_count, passed_count: passed_count, + evaluate_count: evaluate_count, passed_ave_time: passed_ave_time, shixun_id: shixun.id} + + end end end shixun_infos diff --git a/lib/tasks/statistic_subject_info.rake b/lib/tasks/statistic_subject_info.rake index f982cfc12..d42cb1b1c 100644 --- a/lib/tasks/statistic_subject_info.rake +++ b/lib/tasks/statistic_subject_info.rake @@ -9,25 +9,27 @@ namespace :subjects do buffer_size = 0 column_value = "subject_id, study_count, course_study_count, initiative_study, passed_count, course_used_count, " + "school_used_count, created_at, updated_at" - subjects.find_each do |subject| - puts("---------------------data_statistic: #{subject.id}") - Rails.logger.info("---------------------data_statistic: #{subject.id}") - data = Subjects::DataStatisticService.new(subject) - study_count = data.study_count - next if study_count == 0 - course_study_count = data.course_study_count - initiative_study = study_count - course_study_count - str += ", " unless str.empty? - str += ("(#{subject.id}, #{study_count}, #{course_study_count}, #{initiative_study}, " + - "#{data.passed_count}, #{data.course_used_count}, #{data.school_used_count}, " + - "'#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')") - buffer_size += 1 - if buffer_size == 1000 - sql = "REPLACE INTO subject_records(#{column_value}) VALUES #{str}" - puts sql - ActiveRecord::Base.connection.execute sql - str = "" - buffer_size = 0 + subjects.find_in_batches(batch_size: 50) do |s| + Parallel.each(s, in_processes: 4) do |subject| + puts("---------------------data_statistic: #{subject.id}") + Rails.logger.info("---------------------data_statistic: #{subject.id}") + data = Subjects::DataStatisticService.new(subject) + study_count = data.study_count + next if study_count == 0 + course_study_count = data.course_study_count + initiative_study = study_count - course_study_count + str += ", " unless str.empty? + str += ("(#{subject.id}, #{study_count}, #{course_study_count}, #{initiative_study}, " + + "#{data.passed_count}, #{data.course_used_count}, #{data.school_used_count}, " + + "'#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')") + buffer_size += 1 + if buffer_size == 1000 + sql = "REPLACE INTO subject_records(#{column_value}) VALUES #{str}" + puts sql + ActiveRecord::Base.connection.execute sql + str = "" + buffer_size = 0 + end end end if buffer_size > 0 @@ -47,23 +49,26 @@ namespace :subjects do buffer_size = 0 column_value = "subject_id, school_id, school_name, course_count, student_count, choice_shixun_num, " + "choice_shixun_frequency, created_at, updated_at" - subjects.find_each do |subject| - puts("---------------------course_info_statistic: #{subject.id}") - Rails.logger.info("---------------------course_info_statistic: #{subject.id}") - data = Subjects::CourseUsedInfoService.call(subject) - Parallel.map(data) do |key| - next if key[:school_id].nil? - str += ", " unless str.empty? - str += ("(#{subject.id}, #{key[:school_id]}, '#{key[:school_name]}', #{key[:course_count]}, " + - "#{key[:student_count]}, #{key[:choice_shixun_num]}, #{key[:choice_shixun_frequency]}, " + - "'#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')") - buffer_size += 1 - if buffer_size == 1000 - sql = "REPLACE INTO subject_course_records(#{column_value}) VALUES #{str}" - puts sql - ActiveRecord::Base.connection.execute sql - str = "" - buffer_size = 0 + + subjects.find_in_batches(batch_size: 50) do |s| + Parallel.each(s, in_processes: 4) do |subject| + puts("---------------------course_info_statistic: #{subject.id}") + Rails.logger.info("---------------------course_info_statistic: #{subject.id}") + data = Subjects::CourseUsedInfoService.call(subject) + Parallel.map(data) do |key| + next if key[:school_id].nil? + str += ", " unless str.empty? + str += ("(#{subject.id}, #{key[:school_id]}, '#{key[:school_name]}', #{key[:course_count]}, " + + "#{key[:student_count]}, #{key[:choice_shixun_num]}, #{key[:choice_shixun_frequency]}, " + + "'#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')") + buffer_size += 1 + if buffer_size == 1000 + sql = "REPLACE INTO subject_course_records(#{column_value}) VALUES #{str}" + puts sql + ActiveRecord::Base.connection.execute sql + str = "" + buffer_size = 0 + end end end end @@ -84,24 +89,26 @@ namespace :subjects do buffer_size = 0 column_value = "subject_id, shixun_id, stage, shixun_name, challenge_count, course_count, " + "school_count, used_count, passed_count, evaluate_count, passed_ave_time, created_at, updated_at" - subjects.find_each(batch_size: 100) do |subject| - puts("---------------------shixun_info_statistic: #{subject.id}") - Rails.logger.info("---------------------shixun_info_statistic: #{subject.id}") - data = Subjects::ShixunUsedInfoService.call(subject) - data.each do |key| - next if key[:shixun_id].nil? - str += ", " unless str.empty? - str += ("(#{subject.id}, #{key[:shixun_id]}, '#{key[:stage]}', '#{key[:name]}', #{key[:challenge_count]}, " + - "#{key[:course_count]}, #{key[:school_count]}, #{key[:used_count]}, #{key[:passed_count]}, " + - "#{key[:evaluate_count]}, #{key[:passed_ave_time]}, " + - "'#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')") - buffer_size += 1 - if buffer_size == 1000 - sql = "REPLACE INTO subject_shixun_infos(#{column_value}) VALUES #{str}" - puts sql - ActiveRecord::Base.connection.execute sql - str = "" - buffer_size = 0 + subjects.find_each(batch_size: 50) do |s| + Parallel.each(s, in_processes: 4) do |subject| + puts("---------------------shixun_info_statistic: #{subject.id}") + Rails.logger.info("---------------------shixun_info_statistic: #{subject.id}") + data = Subjects::ShixunUsedInfoService.call(subject) + data.each do |key| + next if key[:shixun_id].nil? + str += ", " unless str.empty? + str += ("(#{subject.id}, #{key[:shixun_id]}, '#{key[:stage]}', '#{key[:name]}', #{key[:challenge_count]}, " + + "#{key[:course_count]}, #{key[:school_count]}, #{key[:used_count]}, #{key[:passed_count]}, " + + "#{key[:evaluate_count]}, #{key[:passed_ave_time]}, " + + "'#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')") + buffer_size += 1 + if buffer_size == 1000 + sql = "REPLACE INTO subject_shixun_infos(#{column_value}) VALUES #{str}" + puts sql + ActiveRecord::Base.connection.execute sql + str = "" + buffer_size = 0 + end end end end From 96bc31e9d6f5d0e947ab7e854545af95ab1a52dc Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 15 Jan 2020 17:54:23 +0800 Subject: [PATCH 13/91] =?UTF-8?q?=E5=B9=B6=E8=A1=8C=E5=A4=84=E7=90=86?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/statistic_subject_info.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/statistic_subject_info.rake b/lib/tasks/statistic_subject_info.rake index d42cb1b1c..259824174 100644 --- a/lib/tasks/statistic_subject_info.rake +++ b/lib/tasks/statistic_subject_info.rake @@ -89,7 +89,7 @@ namespace :subjects do buffer_size = 0 column_value = "subject_id, shixun_id, stage, shixun_name, challenge_count, course_count, " + "school_count, used_count, passed_count, evaluate_count, passed_ave_time, created_at, updated_at" - subjects.find_each(batch_size: 50) do |s| + subjects.find_in_batches(batch_size: 50) do |s| Parallel.each(s, in_processes: 4) do |subject| puts("---------------------shixun_info_statistic: #{subject.id}") Rails.logger.info("---------------------shixun_info_statistic: #{subject.id}") From 0a49a9a919ada940dd13671219a582af48c6790d Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 15 Jan 2020 20:05:24 +0800 Subject: [PATCH 14/91] 1 --- app/controllers/item_banks_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/item_banks_controller.rb b/app/controllers/item_banks_controller.rb index 86b1523c3..f108c1fad 100644 --- a/app/controllers/item_banks_controller.rb +++ b/app/controllers/item_banks_controller.rb @@ -43,8 +43,9 @@ class ItemBanksController < ApplicationController ApplyAction.where(container_type: "ItemBank", container_id: @item.id).destroy_all if @item.item_type == "PROGRAM" @item.container&.destroy! + else + @item.destroy! end - @item.destroy! render_ok end end From 29161608b1a8218ebd1901ce93b63970f088750e Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 15 Jan 2020 20:51:12 +0800 Subject: [PATCH 15/91] qianyi --- .../20200115020230_add_choice_index_to_exercise_answers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20200115020230_add_choice_index_to_exercise_answers.rb b/db/migrate/20200115020230_add_choice_index_to_exercise_answers.rb index cb518bb42..da68e6ac8 100644 --- a/db/migrate/20200115020230_add_choice_index_to_exercise_answers.rb +++ b/db/migrate/20200115020230_add_choice_index_to_exercise_answers.rb @@ -1,6 +1,6 @@ class AddChoiceIndexToExerciseAnswers < ActiveRecord::Migration[5.2] def change - add_column :exercise_answers, :choice_index, :integer, default: 1 + # add_column :exercise_answers, :choice_index, :integer, default: 1 multi_questions = ExerciseQuestion.where(question_type: 1) multi_questions.includes(:exercise_choices, :exercise_answers).find_each do |question| From 75f892f1bdb700fb1629380c62a77f5439f0d640 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 15 Jan 2020 20:56:53 +0800 Subject: [PATCH 16/91] qianyi --- .../20200115020230_add_choice_index_to_exercise_answers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20200115020230_add_choice_index_to_exercise_answers.rb b/db/migrate/20200115020230_add_choice_index_to_exercise_answers.rb index da68e6ac8..cb518bb42 100644 --- a/db/migrate/20200115020230_add_choice_index_to_exercise_answers.rb +++ b/db/migrate/20200115020230_add_choice_index_to_exercise_answers.rb @@ -1,6 +1,6 @@ class AddChoiceIndexToExerciseAnswers < ActiveRecord::Migration[5.2] def change - # add_column :exercise_answers, :choice_index, :integer, default: 1 + add_column :exercise_answers, :choice_index, :integer, default: 1 multi_questions = ExerciseQuestion.where(question_type: 1) multi_questions.includes(:exercise_choices, :exercise_answers).find_each do |question| From e1cfd7700ac60fa3d1958a8cefe746820884acf8 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 16 Jan 2020 09:35:55 +0800 Subject: [PATCH 17/91] =?UTF-8?q?=E9=80=89=E7=94=A8=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E6=98=AF=E6=89=80=E6=9C=89=E5=B7=B2=E5=85=AC=E5=BC=80=E7=9A=84?= =?UTF-8?q?=E5=AE=9E=E8=AE=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/shixun_search_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/shixun_search_service.rb b/app/services/shixun_search_service.rb index 323804e95..2dcf265dc 100644 --- a/app/services/shixun_search_service.rb +++ b/app/services/shixun_search_service.rb @@ -26,7 +26,7 @@ class ShixunSearchService < ApplicationService shixun_ids = ShixunSchool.where(school_id: User.current.school_id).pluck(:shixun_id) shixun_ids = shixun_ids.reject(&:blank?).length == 0 ? -1 : shixun_ids.join(",") - @shixuns = @shixuns.where("use_scope = 0 or id in (#{shixun_ids})").unhidden.published.or(@shixuns.where(id: User.current.shixuns)) + @shixuns = @shixuns.where("use_scope = 0 or id in (#{shixun_ids})").unhidden.publiced.or(@shixuns.where(id: User.current.shixuns)) end end From 230959148167b529472f81349bbf13c03420e835 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 16 Jan 2020 09:40:56 +0800 Subject: [PATCH 18/91] =?UTF-8?q?=E9=A2=98=E5=BA=93=E7=9A=84=E5=88=A0?= =?UTF-8?q?=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/hack.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/models/hack.rb b/app/models/hack.rb index 0c5970af4..9c8ca44fb 100644 --- a/app/models/hack.rb +++ b/app/models/hack.rb @@ -23,7 +23,6 @@ class Hack < ApplicationRecord belongs_to :sub_discipline has_one :item_bank, as: :container, dependent: :destroy - has_one :examination_bank, as: :container, dependent: :destroy scope :published, -> { where(status: 1) } scope :unpublish, -> { where(status: 0) } From 443ff8d0b143e7302961d060b28403297b82961f Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 16 Jan 2020 10:48:57 +0800 Subject: [PATCH 19/91] =?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/controllers/application_controller.rb | 2 +- app/controllers/subjects_controller.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 3c481e8b6..fdb41c114 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -23,7 +23,7 @@ class ApplicationController < ActionController::Base # 所有请求必须合法签名 def check_sign - if !Rails.env.development? || + if !Rails.env.development? Rails.logger.info("66666 #{params}") # suffix = request.url.split(".").last.split("?").first # suffix_arr = ["xls", "xlsx", "pdf", "zip"] # excel文件先注释 diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index ce7fc575c..d8a0f4014 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -200,7 +200,7 @@ class SubjectsController < ApplicationController end def append_to_stage - @shixuns = Shixun.where(id: params[:shixun_id]).order("id desc") + @shixuns = Shixun.where(id: params[:shixun_id]).order("field(id, #{params[:shixun_id]})") end # 添加实训项目 From 63012e1ac70354502123ca399cc6de3ed3413c34 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 16 Jan 2020 11:33:36 +0800 Subject: [PATCH 20/91] =?UTF-8?q?=E9=80=89=E7=94=A8=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E7=9A=84=E9=A1=BA=E5=BA=8F?= 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 db8c688ad..432b83414 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -787,7 +787,7 @@ class HomeworkCommonsController < ApplicationController def create_shixun_homework tip_exception("请至少选择一个实训") if params[:shixun_ids].blank? - shixuns = Shixun.where(id: params[:shixun_ids]).reorder("id desc") + shixuns = Shixun.where(id: params[:shixun_ids]).order("field(id, #{params[:shixun_ids].reverse})") @homework_ids = [] unless params[:category_id].blank? @category = @course.course_second_categories.find_by(id: params[:category_id], category_type: "shixun_homework") From c751f2a96be277c7bdb1ca8acc69281b4e449859 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 16 Jan 2020 11:36:17 +0800 Subject: [PATCH 21/91] =?UTF-8?q?=E9=80=89=E7=94=A8=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E7=9A=84=E9=A1=BA=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_commons_controller.rb | 3 ++- app/controllers/subjects_controller.rb | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 432b83414..d68304bfe 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -787,7 +787,8 @@ class HomeworkCommonsController < ApplicationController def create_shixun_homework tip_exception("请至少选择一个实训") if params[:shixun_ids].blank? - shixuns = Shixun.where(id: params[:shixun_ids]).order("field(id, #{params[:shixun_ids].reverse})") + order_ids = params[:shixun_ids].size > 0 ? params[:shixun_ids].reverse.join(',') : -1 + shixuns = Shixun.where(id: params[:shixun_ids]).order("field(id, #{order_ids})") @homework_ids = [] unless params[:category_id].blank? @category = @course.course_second_categories.find_by(id: params[:category_id], category_type: "shixun_homework") diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index d8a0f4014..e820c383d 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -200,7 +200,8 @@ class SubjectsController < ApplicationController end def append_to_stage - @shixuns = Shixun.where(id: params[:shixun_id]).order("field(id, #{params[:shixun_id]})") + order_ids = params[:shixun_id].size > 0 ? params[:shixun_id].join(',') : -1 + @shixuns = Shixun.where(id: params[:shixun_id]).order("field(id, #{order_ids})") end # 添加实训项目 From 97dab335f3f6c83d159c434e4ae5a948de2dc483 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 16 Jan 2020 14:39:05 +0800 Subject: [PATCH 22/91] =?UTF-8?q?=E9=95=9C=E5=83=8F=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/edu_datas/game.json.jbuilder | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/edu_datas/game.json.jbuilder b/app/views/edu_datas/game.json.jbuilder index 3f4a0335e..963583d2f 100644 --- a/app/views/edu_datas/game.json.jbuilder +++ b/app/views/edu_datas/game.json.jbuilder @@ -3,4 +3,5 @@ json.game @game json.shixun @shixun json.shixun_env @env +json.shixun_image @shixun.main_mirror_name json.shixun_tags @shixun_tags \ No newline at end of file From 08012fb515a43e5c9e821e6a9992b013aca506c9 Mon Sep 17 00:00:00 2001 From: tangjiang <465264938@qq.com> Date: Thu, 16 Jan 2020 15:34:41 +0800 Subject: [PATCH 23/91] add wxcode --- public/react/src/App.js | 10 + public/react/src/modules/wxcode/index.js | 271 +++++++++++++++++ public/react/src/modules/wxcode/index.scss | 275 ++++++++++++++++++ public/react/src/redux/actions/actionTypes.js | 9 +- public/react/src/redux/actions/index.js | 22 +- public/react/src/redux/actions/wxCode.js | 196 +++++++++++++ public/react/src/redux/reducers/index.js | 4 +- .../react/src/redux/reducers/wxcodeReducer.js | 68 +++++ public/react/src/services/wxcodeService.js | 44 +++ 9 files changed, 896 insertions(+), 3 deletions(-) create mode 100644 public/react/src/modules/wxcode/index.js create mode 100644 public/react/src/modules/wxcode/index.scss create mode 100644 public/react/src/redux/actions/wxCode.js create mode 100644 public/react/src/redux/reducers/wxcodeReducer.js create mode 100644 public/react/src/services/wxcodeService.js diff --git a/public/react/src/App.js b/public/react/src/App.js index 247e7939b..96a4f91b0 100644 --- a/public/react/src/App.js +++ b/public/react/src/App.js @@ -366,6 +366,11 @@ const JupyterTPI = Loadable({ loader: () => import('./modules/tpm/jupyter'), loading: Loading }); +// 微信代码编辑器 +const WXCode = Loadable({ + loader: () => import('./modules/wxcode'), + loading: Loading +}); // //个人竞赛报名 // const PersonalCompetit = Loadable({ // loader: () => import('./modules/competition/personal/PersonalCompetit.js'), @@ -823,6 +828,11 @@ class App extends Component { render={ (props) => () }/> + () + } + /> { + + const { + isShow, + wxCode, + path, + showLoading, + // userCode, + testCase = [], + getWXCode, + last_compile_output, + test_sets_count, + sets_error_count, + getWXCodeTestCase, + restoreWXCode, + updateWXCodeForEditor, + updateWXCodeForInterval, + evaluateWxCode, + showWXCodeTextCase, + changeWXCodeEvaluateLoading + } = props; + + const {identifier} = props.match.params; + const [isActive, setIsActive] = useState(-1); + // const [isVisible, setIsVisible] = useState(false); + const editorRef = useRef(null); + let timer = null; + useEffect(() => { + // 加载代码块内容 + getWXCode(identifier); + // 加载测试集 + const params = { + path, + status: 0, + retry: 1 + }; + getWXCodeTestCase(identifier, params); + }, []); + // 关闭 + const handleCloseTestCase = () => { + // setIsVisible(false); + showWXCodeTextCase(false) + } + // 测试集 + const handleClickTestCase = () => { + // setIsVisible(true); + showWXCodeTextCase(true) + } + // 编辑器代码 + const handleEditorChange = (origin, monaco) => { + editorRef.current = monaco; // 获取当前monaco实例 + // setEditCode(origin); // 保存编辑器初始值 + editorRef.current.onDidChangeModelContent(e => { // 监听编辑器内容的变化 + // TODO 需要优化 节流 + const val = editorRef.current.getValue(); + // console.log('编辑器代码====>>>>', val); + // updateWXCodeForEditor(val); + codeChange(val); + }); + }; + + const codeChange = (code) => { + // console.log(code); + updateWXCodeForEditor(code); + if (!timer) { + timer = setInterval(function () { + clearInterval(timer); + timer = null; + // 调用更新代码 + updateWXCodeForInterval(identifier, path); + }, 10000); + } + } + + // 关闭单个测试集 + const handleCloseItem = (i, flag) => { + if (!flag) return; + setIsActive(isActive === i ? -1 : i); + } + // 初始化 + const handleResetCode = () => { + const result = window.confirm('你在本文件中修改的内容将丢失, 是否确定重新加载初始代码?'); + if (result) { + identifier && restoreWXCode(identifier, { path }); + } + } + // 评测 + const handleEvalateCode = () => { + changeWXCodeEvaluateLoading(true); + evaluateWxCode(identifier, path); + } + + const tcclasses = isShow ? `wx-code-test-case active` : 'wx-code-test-case'; + const loading = showLoading ? 'code-evaluate-loading active' : 'code-evaluate-loading'; + const _val = sets_error_count === 0; + let resultTxt = (_val) ? '全部通过' : `${sets_error_count}组测试结果不匹配`; + const iclasses = _val ? 'iconfont icon-tishi1 icon success' : 'iconfont icon-tishi1 icon fail'; + const tclasses = _val ? 'result-txt success' : 'result-txt fail'; + const ulClasses = last_compile_output ? 'case-list hasResult' : 'case-list'; + return ( +
+
+
+ +
+
+
+ + + 初始化 + + + + 测试集 + +
+ {/* */} + +
+
+ {/* 测试集 */} +
+
+
+ 共{testCase.length}个测试用例 + 关闭 +
+
+ + {test_sets_count - sets_error_count}/{test_sets_count} + {resultTxt} +
+
    + { + testCase.map((item, i) => { + const {input, output, actual_output, is_public, result} = item; + const _classes = isActive === i ? 'case-item-desc active' : 'case-item-desc'; + const iconclasses = isActive === i ? 'iconfont icon-sanjiaoxing-down icon active' : 'iconfont icon-triangle icon'; + const headerClasses = is_public ? 'item-header-desc active' : 'item-header-desc'; + // console.log(_classes); + return ( +
  • +
    handleCloseItem(i, is_public)}> +

    + + 测试集{i + 1} +

    + { + is_public + ? (result + ? + : ) + : ( + 隐藏测试集,暂不支持解锁和查看 + {/* {result + ? + : + } */} + ) + } +
    + +
    + 测试输入 + {input || '-'} + 预期输出 + {/* */} + */} + 实际输出 +