diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index 9e87d3799..0f6532372 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -74,6 +74,7 @@ class ChallengesController < ApplicationController ChallengeTag.create(:name => tag, :challenge_choose_id => @challenge_choose.id, :challenge_id => @challenge.id) end end + @challenge.update_column(:score, @challenge.challenge_chooses.sum(:score)) end rescue Exception => e raise ActiveRecord::Rollback @@ -95,6 +96,7 @@ class ChallengesController < ApplicationController @challenge.update_column(:modify_time, Time.now) end @challenge_choose.update_attributes(chooce_params) + @challenge.update_column(:score, @challenge.challenge_chooses.sum(:score)) # 单选多选题的更新 category = @challenge_choose.standard_answer.length > 1 ? 2 : 1 @challenge_choose.update_column(:category, category) @@ -208,6 +210,9 @@ class ChallengesController < ApplicationController # 测试集的 @shixun.myshixuns.update_all(:system_tip => 0) end + if params[:challenge][:show_type].to_i == -1 + @challenge.update_attributes(picture_path: nil, web_route: nil, expect_picture_path: nil, original_picture_path: nil) + end # 关卡评测执行文件如果被修改,需要修改脚本内容 script = modify_shixun_script @shixun, @shixun.evaluate_script @shixun.shixun_info.update_column(:evaluate_script, script) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 58e4683e0..4e8c729ce 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -739,7 +739,7 @@ class GamesController < ApplicationController experience = 0 game_status = @game.status had_done = @game.had_done - game_challenge = Challenge.select([:id, :score, :position, :shixun_id, :web_route]).find(@game.challenge_id) + game_challenge = Challenge.select([:id, :score, :position, :shixun_id, :web_route, :show_type]).find(@game.challenge_id) if params[:resubmit].blank? # 非重新评测 if game_status == 2 # 通关 @@ -768,6 +768,7 @@ class GamesController < ApplicationController picture = (@game.picture_path.nil? ? 0 : @game.id) # 针对web类型的实训 web_route = game_challenge.try(:web_route) + mirror_name = @shixun.mirror_name e_record = EvaluateRecord.where(:identifier => sec_key).first diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index a62707536..5b926ee48 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -101,8 +101,9 @@ class SubjectsController < ApplicationController @tags = ChallengeTag.where(challenge_id: challenge_ids).pluck(:name).uniq # 用户获取的实训标签 # @user_tags = @subject.shixuns.map(&:user_tags_name).flatten.uniq - @user_tags = user_shixun_tags challenge_ids, @user.id - @my_subject_progress = @subject.my_subject_progress + + # 用户进展 + user_subject_progress(challenge_ids) end def new @@ -436,4 +437,33 @@ class SubjectsController < ApplicationController tip_exception("403", "") end end + + # 用户进展和获取的标签 + def user_subject_progress challenge_ids + pass_games = Game.select(:id, :cost_time, :challenge_id).where(status: 2, user_id: current_user.id, challenge_id: challenge_ids) if current_user.logged? + @all_score = Challenge.where(id: challenge_ids).sum(:score) + + # 如果没有通关的,没必要再继续统计了 + if pass_games.blank? + @my_score = 0 + @learned = 0 + @time = 0 + @user_tags = [] + else + pass_challenge_ids = pass_games.map(&:challenge_id) + subject_challenge_count = @subject.shixuns.sum(:challenges_count) + # 用户通关获得的标签 + @user_tags = ChallengeTag.where(challenge_id: pass_challenge_ids).pluck(:name) + # 用户学习进度 + @learned = + subject_challenge_count == 0 ? 0 : + ((pass_challenge_ids.size.to_f / subject_challenge_count).round(2) * 100).to_i + # 用户通关分数 + @my_score = Challenge.where(id: pass_challenge_ids).pluck(:score).sum + @time = pass_games.map(&:cost_time).sum + end + + + end + end diff --git a/app/helpers/subjects_helper.rb b/app/helpers/subjects_helper.rb index b03baf825..75ae9f041 100644 --- a/app/helpers/subjects_helper.rb +++ b/app/helpers/subjects_helper.rb @@ -13,13 +13,8 @@ module SubjectsHelper # 实训路径的所有用户获得的标签 def user_shixun_tags challenge_ids, user_id - logger.info("#####################") ChallengeTag.joins("join games on challenge_tags.challenge_id = games.challenge_id"). where(challenge_id: challenge_ids, games: {status: 2, user_id: user_id}).pluck("challenge_tags.name").uniq - logger.info("#####################") - pass_challenge_ids = Game.where(status: 2, user_id: user_id, challenge_id: challenge_ids).pluck(:challenge_id) - ChallengeTag.where(challenge_id: pass_challenge_ids).pluck(:name).uniq - logger.info("#####################") end # 金课的课堂状态 0:未开课,1:进行中,2:已结束 diff --git a/app/models/subject.rb b/app/models/subject.rb index 7aa0bc063..4b7f4dbcd 100644 --- a/app/models/subject.rb +++ b/app/models/subject.rb @@ -82,16 +82,9 @@ class Subject < ApplicationRecord end def my_subject_progress - logger.info("#-----------") my_challenge_count = Game.joins(:challenge).where(user_id: User.current.id, status: 2, challenges: {shixun_id: shixuns.published_closed}). - pluck(:challenge_id).uniq.size - logger.info("#-----------") - new_challenge_count = Challenge.left_joins(:games) - .where(games: {user_id: User.current.id, status: 2}, shixun_id: shixuns.published_closed) - .uniq.count - logger.info("#-----------") - subject_challenge_count = shixuns.sum(:challenges_count) - subject_challenge_count == 0 ? 0 : ((my_challenge_count.to_f / subject_challenge_count).round(2) * 100).to_i + pluck(:challenge_id).uniq.size + count = self.subject_challenge_count == 0 ? 0 : ((my_challenge_count.to_f / self.subject_challenge_count).round(2) * 100).to_i end def my_consume_time diff --git a/app/views/exercise_questions/_exercise_questions.json.jbuilder b/app/views/exercise_questions/_exercise_questions.json.jbuilder index bbdf45440..ca8ea7e6b 100644 --- a/app/views/exercise_questions/_exercise_questions.json.jbuilder +++ b/app/views/exercise_questions/_exercise_questions.json.jbuilder @@ -20,10 +20,20 @@ if question.question_type <= 2 #当为选择题或判断题时,只显示选 #TODO: 旧版本来一个题只有一个标准答案的,新版又做成了一个题有多个标准答案(exercise_choice_id存放的是标准答案的位置..) standard_answer_b = standard_answers_array.join("").include?(a.choice_position.to_s) user_answer_b = user_answer.include?(a.id) + choice_text = a.choice_text + if question.question_type == 2 + if choice_text == "对" + choice_text = "正确" + end + if choice_text == "错" + choice_text = "错误" + end + end json.c_position (index+1) if ex_choice_random_boolean #当选项随机时,选项位置以此为准,否则不出现 json.choice_id a.id # json.choice_text (edit_type.present? || question.question_type == 2) ? a.choice_text : "#{(index+65).chr}.#{a.choice_text}" - json.choice_text a.choice_text + + json.choice_text choice_text json.choice_position a.choice_position if exercise_type == 1 || exercise_type == 4 #1为教师编辑/预览 试卷或问题,2为空白试卷,即标准答案和用户答案都不显示,3为用户开始答题的显示,4为老师评阅试卷或学生在截止后查看试卷 json.standard_boolean standard_answer_b @@ -36,6 +46,14 @@ if question.question_type <= 2 #当为选择题或判断题时,只显示选 if exercise_type == 1 || exercise_type == 4 #1为老师,4为试卷截止且答案公开的情况 json.standard_answer standard_answers_array + if question.question_type == 2 #返回答案的文字 + standard_text = standard_answers_array.first.to_i == 1 ? "正确" : "错误" + else + array_text_answer = [] + standard_answers_array.each{|a| array_text_answer.push((a+64).chr)} + standard_text = array_text_answer.join("") + end + json.standard_answer_show standard_text end if exercise_type == 3 || exercise_type == 4 json.user_answer user_answer diff --git a/app/views/subjects/right_banner.json.jbuilder b/app/views/subjects/right_banner.json.jbuilder index 9ca42c5bc..a289ad0a9 100644 --- a/app/views/subjects/right_banner.json.jbuilder +++ b/app/views/subjects/right_banner.json.jbuilder @@ -14,8 +14,8 @@ end # 我的进展 json.progress do - json.my_score @subject.my_subject_score - json.all_score @subject.all_score - json.learned @subject.my_subject_progress - json.time @subject.my_consume_time + json.my_score @my_score + json.all_score @all_score + json.learned @learned + json.time @time end \ No newline at end of file diff --git a/config/environments/development.rb b/config/environments/development.rb index cdcd45ec5..f0b3f1775 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -50,12 +50,11 @@ Rails.application.configure do # Debug mode disables concatenation and preprocessing of assets. # This option may cause significant delays in view rendering with a large # number of complex assets. - config.assets.debug = false + config.assets.debug = true # Suppress logger output for asset requests. config.assets.quiet = true - config.assets.compile = true # config.assets.prefix = '/dev-assets' # Raises error for missing translations diff --git a/public/images/educoder/path.png b/public/images/educoder/path.png index d3d816012..057838222 100644 Binary files a/public/images/educoder/path.png and b/public/images/educoder/path.png differ diff --git a/public/images/educoder/path1.png b/public/images/educoder/path1.png new file mode 100644 index 000000000..d3d816012 Binary files /dev/null and b/public/images/educoder/path1.png differ diff --git a/public/react/public/css/edu-all.css b/public/react/public/css/edu-all.css index fc910ef37..1daa2d5b1 100644 --- a/public/react/public/css/edu-all.css +++ b/public/react/public/css/edu-all.css @@ -446,7 +446,7 @@ table.text-file{} /*-------------------------------实训路径-------------------------------*/ .path-head{width: 100%;height: 300px;background-image: url("/images/educoder/path.png"); - background-color: #131b39; + background-color: #000a4f; /*background-size: cover;*/ background-position: center; background-repeat: no-repeat; diff --git a/public/react/public/js/js_min_all.js b/public/react/public/js/js_min_all.js index 63c1207af..0d56d86ba 100755 --- a/public/react/public/js/js_min_all.js +++ b/public/react/public/js/js_min_all.js @@ -236,8 +236,7 @@ $(function(){ if(dragging) { clickX = e.pageX || e.originalEvent.touches[0].pageX;; if(clickX > leftOffset+0&&clickX<\\/script>'); document.write('