From 5fa762085f47ae848c02358585edd7cf28aeb835 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 15 Jul 2019 16:18:01 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E8=AF=BE=E5=A0=82=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E7=9A=84=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 1e18b8be6..c27a57c90 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -47,19 +47,19 @@ class CoursesController < ApplicationController @order = params[:order].present? ? params[:order] : "all" order_str = @order != "course_members_count" && @order != "created_at" ? "updated_at" : @order - if @order == "all" + # if @order == "all" # @course = Course.where(is_delete: 0, is_hidden: 0).select("select c.name, c.id, s.name, u.login, ifnull(concat(u.lastname,u.firstname), # u.login), s.name from courses c, users u, user_extensions ue, schools s where c.is_delete=0 and # c.tea_id=u.id and u.id=ue.user_id and ue.school_id=s.id") - @courses = Course.where(is_delete: 0, is_hidden: 0) - .order("courses.id = 1309 desc, courses.created_at desc") + # @courses = Course.where(is_delete: 0, is_hidden: 0) + # .order("courses.id = 1309 desc, courses.created_at desc") # @courses = Course.where(is_delete: 0, is_hidden: 0).select("courses.id, courses.tea_id, courses.name, courses.exercises_count, courses.polls_count, # courses.is_public, courses.is_end, courses.visits, courses.course_members_count,courses.homework_commons_count,(SELECT MAX(created_at) # FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a") # .order("courses.id = 1309 desc, a desc") - elsif @order == "mine" + if @order == "mine" @courses = Course.joins(:course_members) .where("is_delete = 0 AND is_hidden = 0 AND course_members.user_id = ?", @user.id) .order("courses.id = 1309 DESC, courses.#{order_str} DESC") @@ -86,7 +86,7 @@ class CoursesController < ApplicationController (course_members.role in(1,2,3) and CONCAT(users.lastname, users.firstname) like :keyword) or courses.name like :keyword or schools.name like :keyword } - @courses = @courses.joins(:school, course_members: [user: :user_extension]) + @courses = @courses.joins(:school, course_members: :user) .where("#{sql}", keyword: "%#{params[:search]}%").distinct end @courses_count = @courses.size From 560332ab0951dc7d7e48642bb4e95880173303fe Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 15 Jul 2019 16:46:40 +0800 Subject: [PATCH 2/7] fixbug --- app/helpers/exercises_helper.rb | 20 ++++++++++++++----- .../exercises/exercise_result.json.jbuilder | 1 + app/views/exercises/index.json.jbuilder | 2 +- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 92816d68b..7d50d1a66 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -216,10 +216,19 @@ module ExercisesHelper ex.exercise_shixun_challenges.each do |c| cha_score = c&.question_score cha_shixun_answer = effictive_users.search_shixun_keys("exercise_shixun_challenge_id",c.id) - effictive_users_count = cha_shixun_answer.count #实训题的每个关卡的有效填写量 - full_scores = cha_shixun_answer.search_shixun_keys("score",cha_score).count #满分人数 - no_full_scores = cha_shixun_answer.shixun_no_full_scores(cha_score).count #部分分数人数c - all_zero_scores = cha_shixun_answer.search_shixun_keys("score",0.0).count #满分人数 + effictive_users_count = cha_shixun_answer.size #实训题的每个关卡的有效填写量 + full_scores = cha_shixun_answer.search_shixun_keys("score",cha_score).size #满分人数 + no_full_scores = cha_shixun_answer.shixun_no_full_scores(cha_score).size #部分分数人数c + all_zero_scores = cha_shixun_answer.search_shixun_keys("score",0.0).size #零分人数 + shiun_scores = user_ids.count * cha_score + shixun_answered_scores = cha_shixun_answer.score_reviewed.pluck(:score).sum #该问题的全部得分 + + if shixun_answered_scores == 0.0 + game_percent = 0.0 + else + game_percent = (shixun_answered_scores / shiun_scores.to_f).round(3) * 100 #正确率 + end + shixun_score_array = [full_scores,no_full_scores,all_zero_scores] shixun_chas = [] shixun_score_array.each_with_index do |s,index| @@ -242,7 +251,8 @@ module ExercisesHelper :cha_id => c.challenge_id, :cha_name => c.challenge.subject, :cha_position => c.position, - :cha_details => shixun_chas + :cha_details => shixun_chas, + :cha_percent => game_percent } question_answer_infos.push(shixun_new_chas) end diff --git a/app/views/exercises/exercise_result.json.jbuilder b/app/views/exercises/exercise_result.json.jbuilder index 2428e57c7..7f2d871fc 100644 --- a/app/views/exercises/exercise_result.json.jbuilder +++ b/app/views/exercises/exercise_result.json.jbuilder @@ -48,6 +48,7 @@ json.commit_results do json.challenge_id cha[:cha_id] json.challenge_name cha[:cha_name] json.challenge_position cha[:cha_position] + json.challenge_percent cha[:cha_percent] json.challenge_details do json.array! cha[:cha_details] do |ch| json.choice_position ch[:choice_position] diff --git a/app/views/exercises/index.json.jbuilder b/app/views/exercises/index.json.jbuilder index bccce4f2b..e5da76786 100644 --- a/app/views/exercises/index.json.jbuilder +++ b/app/views/exercises/index.json.jbuilder @@ -36,7 +36,7 @@ json.exercises_counts do json.exercises_all_counts @exercises_select_count #选择后的全部试卷数 json.exercises_unpublish_counts @exercises_unpublish_counts #未发布试卷数 json.exercises_published_counts @exercises_published_counts #已发布试卷数 - json.exercises_ended_counts @exercises_ended_counts #已截止试卷数 + # json.exercises_ended_counts @exercises_ended_counts #已截止试卷数 json.left_banner_id @left_banner_id json.left_banner_name @left_banner_name end From e655d36ed128ecf1fecf27dd2c1b9664af3003a1 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 15 Jul 2019 17:02:28 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=A4=B4=E5=83=8F?= =?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/users/avatars_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/users/avatars_controller.rb b/app/controllers/users/avatars_controller.rb index 6d161ba94..3b8c4be84 100644 --- a/app/controllers/users/avatars_controller.rb +++ b/app/controllers/users/avatars_controller.rb @@ -28,6 +28,6 @@ class Users::AvatarsController < Users::BaseAccountController end def avatar_url - ApplicationController.helpers.url_to_avatar(observed_user) + ApplicationController.helpers.url_to_avatar(observed_user).to_s + "?#{Time.now.to_i}" end end From 5a3ac8958c014c53c0c4f0183889884c44fefb93 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 15 Jul 2019 17:22:54 +0800 Subject: [PATCH 4/7] fixbug --- app/controllers/exercises_controller.rb | 2 +- app/helpers/exercises_helper.rb | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 79b22d571..fe04e04f8 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1390,7 +1390,7 @@ class ExercisesController < ApplicationController if @paging_type == "percent" @question_result_hash = ques_result_all.sort_by{|s| s[:percent]} else - @question_result_hash = ques_result_all.sort_by{|s| s["#{@paging_type}"]} + @question_result_hash = ques_result_all.sort_by{|s| s[:"#{@paging_type}"]} end @exercise_questions_count = @exercise_questions.size diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 7d50d1a66..280f571a4 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -220,13 +220,13 @@ module ExercisesHelper full_scores = cha_shixun_answer.search_shixun_keys("score",cha_score).size #满分人数 no_full_scores = cha_shixun_answer.shixun_no_full_scores(cha_score).size #部分分数人数c all_zero_scores = cha_shixun_answer.search_shixun_keys("score",0.0).size #零分人数 - shiun_scores = user_ids.count * cha_score + shixun_scores = user_ids.count * cha_score shixun_answered_scores = cha_shixun_answer.score_reviewed.pluck(:score).sum #该问题的全部得分 if shixun_answered_scores == 0.0 - game_percent = 0.0 + game_percent = "0.0" else - game_percent = (shixun_answered_scores / shiun_scores.to_f).round(3) * 100 #正确率 + game_percent = (shixun_answered_scores / shixun_scores.to_f).round(3) * 100 #正确率 end shixun_score_array = [full_scores,no_full_scores,all_zero_scores] @@ -234,7 +234,7 @@ module ExercisesHelper shixun_score_array.each_with_index do |s,index| right_answer = (index == 0) if effictive_users_count == 0 - score_percent = 0.0 + score_percent = "0.0" else score_percent = (s.to_i / effictive_users_count.to_f ).round(3) end From a75483d8f29e8b8b9c559ce9f33615000b4e16d8 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 15 Jul 2019 17:27:18 +0800 Subject: [PATCH 5/7] fixbug --- app/helpers/exercises_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 280f571a4..be71aedab 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -234,7 +234,7 @@ module ExercisesHelper shixun_score_array.each_with_index do |s,index| right_answer = (index == 0) if effictive_users_count == 0 - score_percent = "0.0" + score_percent = 0.0 else score_percent = (s.to_i / effictive_users_count.to_f ).round(3) end From 8378e4db8ff3f3fe42bc95822c30c317dc486204 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 15 Jul 2019 17:32:30 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E5=A4=B4=E5=83=8Furl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/users/_user.json.jbuilder | 2 +- db/migrate/20190715073825_add_test_for_challenges.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20190715073825_add_test_for_challenges.rb diff --git a/app/views/users/_user.json.jbuilder b/app/views/users/_user.json.jbuilder index afec979a1..66ea1530e 100644 --- a/app/views/users/_user.json.jbuilder +++ b/app/views/users/_user.json.jbuilder @@ -3,5 +3,5 @@ json.login user.login json.name user.full_name json.grade user.grade # json.email user.mail # 邮箱原则上不暴露的,如果实在需要的话只能对某些具体的接口公开 -json.image_url url_to_avatar(user) +json.image_url image_url(url_to_avatar(user)) json.school user.school_name \ No newline at end of file diff --git a/db/migrate/20190715073825_add_test_for_challenges.rb b/db/migrate/20190715073825_add_test_for_challenges.rb new file mode 100644 index 000000000..e7e9bbe80 --- /dev/null +++ b/db/migrate/20190715073825_add_test_for_challenges.rb @@ -0,0 +1,9 @@ +class AddTestForChallenges < ActiveRecord::Migration[5.2] + def change + challenge_answers = ChallengeAnswer.all + byebug + challenge_answers.find_each do |ca| + puts() + end + end +end From e3385daeba4c1532a78d08bb8c7e9b54d089e6a4 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 15 Jul 2019 17:32:54 +0800 Subject: [PATCH 7/7] 1 --- db/migrate/20190715073825_add_test_for_challenges.rb | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 db/migrate/20190715073825_add_test_for_challenges.rb diff --git a/db/migrate/20190715073825_add_test_for_challenges.rb b/db/migrate/20190715073825_add_test_for_challenges.rb deleted file mode 100644 index e7e9bbe80..000000000 --- a/db/migrate/20190715073825_add_test_for_challenges.rb +++ /dev/null @@ -1,9 +0,0 @@ -class AddTestForChallenges < ActiveRecord::Migration[5.2] - def change - challenge_answers = ChallengeAnswer.all - byebug - challenge_answers.find_each do |ca| - puts() - end - end -end