From 5a3ac8958c014c53c0c4f0183889884c44fefb93 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 15 Jul 2019 17:22:54 +0800 Subject: [PATCH 01/22] 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 02/22] 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 03/22] =?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 04/22] 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 From b7b69e2d0e929d1c6f371badbbc0b2e5b034b026 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 15 Jul 2019 17:35:10 +0800 Subject: [PATCH 05/22] =?UTF-8?q?=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/users/_user.json.jbuilder | 2 +- app/views/users/get_user_info.json.jbuilder | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/views/users/_user.json.jbuilder b/app/views/users/_user.json.jbuilder index 66ea1530e..afec979a1 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 image_url(url_to_avatar(user)) +json.image_url url_to_avatar(user) json.school user.school_name \ No newline at end of file diff --git a/app/views/users/get_user_info.json.jbuilder b/app/views/users/get_user_info.json.jbuilder index 779d58e95..fe8400ffd 100644 --- a/app/views/users/get_user_info.json.jbuilder +++ b/app/views/users/get_user_info.json.jbuilder @@ -1,7 +1,9 @@ json.username @user.full_name json.login @user.login json.user_id @user.id -json.image_url url_to_avatar(@user) +json.image_url image_url(url_to_avatar(@user)) +json.image_path image_path(url_to_avatar(@user)) +json.image_tag image_tag(url_to_avatar(@user)) json.admin @user.admin? json.is_teacher @user.user_extension&.teacher? json.tidding_count 0 From 70f3dfdaa3a9bf04f37e448621ad3a0274bfb0f0 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Mon, 15 Jul 2019 17:35:18 +0800 Subject: [PATCH 06/22] =?UTF-8?q?git=E6=96=87=E4=BB=B6=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 019b690b5..0aa23d836 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -653,6 +653,7 @@ class ShixunsController < ApplicationController content = params[:content] author_name = current_user.full_name author_email = current_user.mail + Rails.logger.info("###222333####{content}") @content = update_file_content content, @repo_path, @path, author_email, author_name, "Edit by browser" end From a13a1c328c7aaff62fdec5c5e063d893eae0ed66 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 15 Jul 2019 17:40:14 +0800 Subject: [PATCH 07/22] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/users/get_user_info.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/users/get_user_info.json.jbuilder b/app/views/users/get_user_info.json.jbuilder index fe8400ffd..ba53d0c2a 100644 --- a/app/views/users/get_user_info.json.jbuilder +++ b/app/views/users/get_user_info.json.jbuilder @@ -1,7 +1,7 @@ json.username @user.full_name json.login @user.login json.user_id @user.id -json.image_url image_url(url_to_avatar(@user)) +json.image_url url_to_avatar(@user) json.image_path image_path(url_to_avatar(@user)) json.image_tag image_tag(url_to_avatar(@user)) json.admin @user.admin? From 1857679d41f1a5458eaea223e4233edef3e1e60b Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 15 Jul 2019 17:41:21 +0800 Subject: [PATCH 08/22] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E4=BB=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/users/get_user_info.json.jbuilder | 1 - 1 file changed, 1 deletion(-) diff --git a/app/views/users/get_user_info.json.jbuilder b/app/views/users/get_user_info.json.jbuilder index ba53d0c2a..2e1fad2e6 100644 --- a/app/views/users/get_user_info.json.jbuilder +++ b/app/views/users/get_user_info.json.jbuilder @@ -2,7 +2,6 @@ json.username @user.full_name json.login @user.login json.user_id @user.id json.image_url url_to_avatar(@user) -json.image_path image_path(url_to_avatar(@user)) json.image_tag image_tag(url_to_avatar(@user)) json.admin @user.admin? json.is_teacher @user.user_extension&.teacher? From d11f780bd8ed360b093138aca4cb14ff1c8853a0 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 15 Jul 2019 17:42:07 +0800 Subject: [PATCH 09/22] =?UTF-8?q?500=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/users/get_user_info.json.jbuilder | 1 - 1 file changed, 1 deletion(-) diff --git a/app/views/users/get_user_info.json.jbuilder b/app/views/users/get_user_info.json.jbuilder index 2e1fad2e6..779d58e95 100644 --- a/app/views/users/get_user_info.json.jbuilder +++ b/app/views/users/get_user_info.json.jbuilder @@ -2,7 +2,6 @@ json.username @user.full_name json.login @user.login json.user_id @user.id json.image_url url_to_avatar(@user) -json.image_tag image_tag(url_to_avatar(@user)) json.admin @user.admin? json.is_teacher @user.user_extension&.teacher? json.tidding_count 0 From 1802ac252bc21c5f9ef25b291abf97d780b216c7 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Mon, 15 Jul 2019 17:42:55 +0800 Subject: [PATCH 10/22] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/myshixuns_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 276fbef32..5163824c3 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -260,6 +260,8 @@ class MyshixunsController < ApplicationController # 远程版本库文件内容 last_content = GitService.file_content(repo_path: @repo_path, path: path)["content"] content = params[:content] + Rails.logger.info("###11222333####{content}") + Rails.logger.info("###222333####{last_content}") if content != last_content @content_modified = 1 From 7b476de0ef08cea2509b5c95fc79d364dc830162 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Mon, 15 Jul 2019 17:50:16 +0800 Subject: [PATCH 11/22] test --- app/controllers/myshixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 5163824c3..0df82118d 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -276,7 +276,7 @@ class MyshixunsController < ApplicationController message: message, content: content, author_name: author_name, - author_email: author_email) + author_email: "author_email@email.com") end end From f7db0a73809a340d9f700028a09029840beb15df Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Mon, 15 Jul 2019 18:07:39 +0800 Subject: [PATCH 12/22] =?UTF-8?q?git=20=E6=9B=B4=E6=96=B0=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E7=9A=84=E6=97=B6=E5=80=99=E5=A6=82=E6=9E=9C=E9=82=AE?= =?UTF-8?q?=E7=AE=B1=E4=B8=BA=E7=A9=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/myshixuns_controller.rb | 4 ++-- app/helpers/application_helper.rb | 3 ++- app/models/user.rb | 3 +++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 0df82118d..31395def2 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -267,7 +267,7 @@ class MyshixunsController < ApplicationController @content_modified = 1 author_name = current_user.real_name - author_email = current_user.mail + author_email = current_user.git_mail message = params[:evaluate] == 0 ? "System automatically submitted" : "User submitted" uid_logger("112233#{author_name}") uid_logger("112233#{author_email}") @@ -276,7 +276,7 @@ class MyshixunsController < ApplicationController message: message, content: content, author_name: author_name, - author_email: "author_email@email.com") + author_email: author_email) end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index cdd647ebd..993c132dc 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -30,8 +30,9 @@ module ApplicationHelper end # git用户 + # git用户命名规则:login+"@educoder.net" def git_username(email) - User.find_by_mail(email) + User.find_by_mail(email) || User.find_by_login(mail.split("@").first) end # 不同的类型扩展不同的目录 diff --git a/app/models/user.rb b/app/models/user.rb index 26f0fa544..89918551e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -156,6 +156,9 @@ class User < ApplicationRecord Token.where(:user_id => id, :action => 'session', :value => value).delete_all end + def git_mail + mail || "#{login}@educoder.net" + end # 学号 def student_id From 5522194d5f65c3047341f367afd07c4cb5a5ed1b Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Mon, 15 Jul 2019 18:11:12 +0800 Subject: [PATCH 13/22] .. --- app/helpers/application_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 993c132dc..4c3a449e9 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -32,7 +32,7 @@ module ApplicationHelper # git用户 # git用户命名规则:login+"@educoder.net" def git_username(email) - User.find_by_mail(email) || User.find_by_login(mail.split("@").first) + User.find_by_mail(email) || User.find_by_login(email.split("@").first) end # 不同的类型扩展不同的目录 From c257ad7456e259721efeb1aa7cec4939c83081b8 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Mon, 15 Jul 2019 18:15:22 +0800 Subject: [PATCH 14/22] =?UTF-8?q?=E7=BC=96=E8=BE=91tpi=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 0aa23d836..8f6dd23a4 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -652,8 +652,7 @@ class ShixunsController < ApplicationController def update_file content = params[:content] author_name = current_user.full_name - author_email = current_user.mail - Rails.logger.info("###222333####{content}") + author_email = current_user.git_mail @content = update_file_content content, @repo_path, @path, author_email, author_name, "Edit by browser" end From f1943707060914f781d5875cf903fc9a104225c4 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Mon, 15 Jul 2019 18:20:20 +0800 Subject: [PATCH 15/22] add log --- app/controllers/shixuns_controller.rb | 1 + app/models/user.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 8f6dd23a4..d6a142a22 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -653,6 +653,7 @@ class ShixunsController < ApplicationController content = params[:content] author_name = current_user.full_name author_email = current_user.git_mail + Rails.logger.info("111111#######{author_email}") @content = update_file_content content, @repo_path, @path, author_email, author_name, "Edit by browser" end diff --git a/app/models/user.rb b/app/models/user.rb index 89918551e..a41043ceb 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -157,6 +157,7 @@ class User < ApplicationRecord end def git_mail + Rails.logger.info("111111#######{mail} #222222222####{login}") mail || "#{login}@educoder.net" end From 194d7ee8d6a77d58d61190da77ad3112d4839bce Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Mon, 15 Jul 2019 18:26:24 +0800 Subject: [PATCH 16/22] git update file --- app/controllers/shixuns_controller.rb | 1 - app/models/user.rb | 1 - 2 files changed, 2 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index d6a142a22..8f6dd23a4 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -653,7 +653,6 @@ class ShixunsController < ApplicationController content = params[:content] author_name = current_user.full_name author_email = current_user.git_mail - Rails.logger.info("111111#######{author_email}") @content = update_file_content content, @repo_path, @path, author_email, author_name, "Edit by browser" end diff --git a/app/models/user.rb b/app/models/user.rb index a41043ceb..89918551e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -157,7 +157,6 @@ class User < ApplicationRecord end def git_mail - Rails.logger.info("111111#######{mail} #222222222####{login}") mail || "#{login}@educoder.net" end From 9787d70f9299b79ed18c9bdedd1a785abe7cae2e Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 15 Jul 2019 18:33:05 +0800 Subject: [PATCH 17/22] fixbug --- app/helpers/exercises_helper.rb | 39 +++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index be71aedab..c9c213c47 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -86,10 +86,10 @@ module ExercisesHelper #试卷的统计结果页面计算各题的 def exercise_commit_result(questions,user_ids) question_infos = [] + percent = 0.0 questions.each do |ex| ex_total_score = user_ids.count * ex&.question_score #该试卷的已回答的总分 ex_answers = ex.exercise_answers - if ex.question_type != Exercise::PRACTICAL ques_title = ex.question_title ques_less_title = nil @@ -103,15 +103,23 @@ module ExercisesHelper effictive_users_count = effictive_users.size #有效回答数,可能有重复的用户id,这里仅统计是否回答这个问题的全部人数 ex_answered_scores = effictive_users.score_reviewed.pluck(:score).sum #该问题的全部得分 - if ex_total_score == 0.0 - percent = 0.0 - else - percent = (ex_answered_scores / ex_total_score.to_f).round(3) * 100 #正确率 + if ex.question_type > Exercise::COMPLETION #当为主观题和实训题时, + if ex_total_score != 0.0 + percent = (ex_answered_scores / ex_total_score.to_f).round(3) * 100 #正确率 + end end question_answer_infos = [] - if ex.question_type <= Exercise::JUDGMENT #单选题 - standard_answer = ex.exercise_standard_answers.pluck(:exercise_choice_id) #标准答案的位置 + if ex.question_type <= Exercise::JUDGMENT #选择题和判断题 + standard_answer = ex.exercise_standard_answers.pluck(:exercise_choice_id).sort #标准答案的位置 + right_users_count = 0 #该问题的回答正确的人数 + user_ids.each do |user_id| + user_an_choice = effictive_users.where(user_id:user_id).pluck(:exercise_choice_id).sort + if user_an_choice == standard_answer + right_users_count += 1 + end + end + percent = effictive_users_count > 0 ? (right_users_count / effictive_users_count.to_f).round(3)*100 : 0.0 ex.exercise_choices.each do |c| right_answer = standard_answer.include?(c.choice_position) #选项的标准答案为选项的位置 answer_this_choice = effictive_users.search_exercise_answer("exercise_choice_id",c.id) @@ -125,7 +133,7 @@ module ExercisesHelper :choice_position => c.choice_position, :choice_text => c.choice_text, :choice_users_count => answer_users_count, - :choice_percent => answer_percent.round(1), + :choice_percent => answer_percent.round(1).to_s, :right_answer => right_answer } question_answer_infos.push(answer_option) @@ -161,13 +169,14 @@ module ExercisesHelper :choice_position => index+1, :choice_text => s_choice_text, :choice_users_count => user_count, - :choice_percent => answer_percent.round(1), + :choice_percent => answer_percent.round(1).to_s, :right_answer => true } question_answer_infos.push(answer_option) all_user_count += user_count standard_answer_count += 1 end + percent = effictive_users_count > 0 ? (all_user_count / effictive_users_count.to_f).round(3)*100 : 0.0 user_wrong_count = (effictive_users_count - all_user_count ) if effictive_users_count > 0 && user_wrong_count >= 0 @@ -179,7 +188,7 @@ module ExercisesHelper :choice_position => (standard_answer_count + 1), :choice_text => "wrong", :choice_users_count => user_wrong_count, - :choice_percent => wrong_percent.round(1), + :choice_percent => wrong_percent.round(1).to_s, :right_answer => false } question_answer_infos.push(wrong_answer_position) @@ -188,12 +197,10 @@ module ExercisesHelper full_scores = effictive_users.search_exercise_answer("score",ex_score).count #满分人数 no_full_scores = effictive_users.exercise_no_full_scores(ex_score).count #部分分数人数 zero_scores = effictive_users.search_exercise_answer("score",0.0).count #包含为0分的,及未评阅的 - # review_scores = ex.exercise_answer_comments.count #主观题的评阅数量 un_review_scores = effictive_users_count - full_scores - no_full_scores - zero_scores #未评阅数 if un_review_scores < 0 un_review_scores = 0 end - # zero_scores = all_zero_scores - un_review_scores #已评阅,且答案未0分的人数 main_scores_array = [full_scores,no_full_scores,zero_scores,un_review_scores] main_scores_array.each_with_index do |s,index| right_answer = (index == 0) @@ -207,7 +214,7 @@ module ExercisesHelper :choice_position => index+1, :choice_text => index+1, :choice_users_count => s, - :choice_percent => score_percent.round(1), + :choice_percent => score_percent.round(1).to_s, :right_answer => right_answer } question_answer_infos.push(answer_option) @@ -224,7 +231,7 @@ module ExercisesHelper 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 / shixun_scores.to_f).round(3) * 100 #正确率 end @@ -242,7 +249,7 @@ module ExercisesHelper :choice_position => index+1, :choice_text => index+1, :choice_users_count => s, - :choice_percent => score_percent.round(1), + :choice_percent => score_percent.round(1).to_s, :right_answer => right_answer } shixun_chas.push(answer_option) @@ -252,7 +259,7 @@ module ExercisesHelper :cha_name => c.challenge.subject, :cha_position => c.position, :cha_details => shixun_chas, - :cha_percent => game_percent + :cha_percent => game_percent.round(1).to_s } question_answer_infos.push(shixun_new_chas) end From 1bdffb56cdf8947eb78ce4db9ddb42a0cd3e27d2 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 15 Jul 2019 18:43:12 +0800 Subject: [PATCH 18/22] fixbug --- app/helpers/exercises_helper.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index c9c213c47..a416dfcbe 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -113,9 +113,15 @@ module ExercisesHelper if ex.question_type <= Exercise::JUDGMENT #选择题和判断题 standard_answer = ex.exercise_standard_answers.pluck(:exercise_choice_id).sort #标准答案的位置 right_users_count = 0 #该问题的回答正确的人数 + + #计算每个问题的答案人数 user_ids.each do |user_id| - user_an_choice = effictive_users.where(user_id:user_id).pluck(:exercise_choice_id).sort - if user_an_choice == standard_answer + user_an_choice = ex_answers.where(user_id:user_id) + answer_choice_array = [] + user_an_choice.each do |a| + answer_choice_array.push(a.exercise_choice.choice_position) #学生答案的位置 + end + if answer_choice_array == standard_answer right_users_count += 1 end end From d82a12d84b1bab94ae57096ce7461998f6129ab6 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 16 Jul 2019 09:14:49 +0800 Subject: [PATCH 19/22] =?UTF-8?q?=E6=B3=A8=E5=86=8C=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/accounts_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index e2df181f0..8b6469089 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -31,7 +31,7 @@ class AccountsController < ApplicationController phone = nil verifi_code = VerificationCode.where(email: email, code: code, code_type: 8).last end - uid_logger("start register: verifi_code is #{verifi_code}, code is #{code}, time is #{Time.now.to_i - verifi_code.created_at.to_i}") + uid_logger("start register: verifi_code is #{verifi_code}, code is #{code}, time is #{Time.now.to_i - verifi_code.try(:created_at).to_i}") check_code = (verifi_code.try(:code) == code.strip && (Time.now.to_i - verifi_code.created_at.to_i) <= 10*60) unless check_code tip_exception("验证码无效") From e23e7678e61c89a952fbb07d8fc28859d3f92dd7 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 16 Jul 2019 09:17:25 +0800 Subject: [PATCH 20/22] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=9A=84=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E7=BB=93=E6=9E=9C=E9=A1=B5=E9=9D=A2=EF=BC=8C=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E9=A2=98=E7=9A=84=E6=AD=A3=E7=A1=AE=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/exercises_helper.rb | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index a416dfcbe..6eb798d9a 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -116,12 +116,8 @@ module ExercisesHelper #计算每个问题的答案人数 user_ids.each do |user_id| - user_an_choice = ex_answers.where(user_id:user_id) - answer_choice_array = [] - user_an_choice.each do |a| - answer_choice_array.push(a.exercise_choice.choice_position) #学生答案的位置 - end - if answer_choice_array == standard_answer + answer_choice_array = effictive_users.where(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq + if answer_choice_array.sort == standard_answer right_users_count += 1 end end @@ -129,7 +125,7 @@ module ExercisesHelper ex.exercise_choices.each do |c| right_answer = standard_answer.include?(c.choice_position) #选项的标准答案为选项的位置 answer_this_choice = effictive_users.search_exercise_answer("exercise_choice_id",c.id) - answer_users_count = answer_this_choice.count + answer_users_count = answer_this_choice.size if effictive_users_count == 0 answer_percent = 0.0 else @@ -170,7 +166,6 @@ module ExercisesHelper else answer_percent = (user_count / effictive_users_count.to_f ).round(3) end - answer_option = { :choice_position => index+1, :choice_text => s_choice_text, @@ -200,9 +195,9 @@ module ExercisesHelper question_answer_infos.push(wrong_answer_position) elsif ex.question_type == Exercise::SUBJECTIVE #主观题 ex_score = ex&.question_score - full_scores = effictive_users.search_exercise_answer("score",ex_score).count #满分人数 - no_full_scores = effictive_users.exercise_no_full_scores(ex_score).count #部分分数人数 - zero_scores = effictive_users.search_exercise_answer("score",0.0).count #包含为0分的,及未评阅的 + full_scores = effictive_users.search_exercise_answer("score",ex_score).size #满分人数 + no_full_scores = effictive_users.exercise_no_full_scores(ex_score).size #部分分数人数 + zero_scores = effictive_users.search_exercise_answer("score",0.0).size #包含为0分的,及未评阅的 un_review_scores = effictive_users_count - full_scores - no_full_scores - zero_scores #未评阅数 if un_review_scores < 0 un_review_scores = 0 @@ -415,7 +410,7 @@ module ExercisesHelper 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 + if standard_answer.size > 0 q_score_1 = q.question_score # q_score_1 = (q.question_score.to_f / standard_answer.count) #当多选答案正确时,每个answer的分数均摊。 else From 9a859c567547f5e183d1355fd41c2aea5b01c020 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 16 Jul 2019 09:21:33 +0800 Subject: [PATCH 21/22] fixbug --- app/helpers/exercises_helper.rb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 6eb798d9a..1dd6c7452 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -115,13 +115,14 @@ module ExercisesHelper right_users_count = 0 #该问题的回答正确的人数 #计算每个问题的答案人数 - user_ids.each do |user_id| - answer_choice_array = effictive_users.where(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq - if answer_choice_array.sort == standard_answer - right_users_count += 1 - end - end - percent = effictive_users_count > 0 ? (right_users_count / effictive_users_count.to_f).round(3)*100 : 0.0 + # user_ids.each do |user_id| + # answer_choice_array = effictive_users.where(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq + # if answer_choice_array.sort == standard_answer + # right_users_count += 1 + # end + # end + # percent = effictive_users_count > 0 ? (right_users_count / effictive_users_count.to_f).round(3)*100 : 0.0 + percent = 0.0 ex.exercise_choices.each do |c| right_answer = standard_answer.include?(c.choice_position) #选项的标准答案为选项的位置 answer_this_choice = effictive_users.search_exercise_answer("exercise_choice_id",c.id) From a56da584d1fa4e1c2bb9c028bea67e9e592c9037 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 16 Jul 2019 09:29:17 +0800 Subject: [PATCH 22/22] fixbug --- app/controllers/exercises_controller.rb | 6 +++--- app/helpers/exercises_helper.rb | 15 +++++++-------- app/models/exercise.rb | 5 ++--- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index fe04e04f8..09b237221 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -203,13 +203,13 @@ class ExercisesController < ApplicationController else @is_teacher_or = 1 @user_exercise_answer = 3 #教师页面 - @user_commit_counts = @exercise.exercise_users.where(commit_status:1).count #已提交的用户数 + @user_commit_counts = @exercise.exercise_users.where(commit_status:1).size #已提交的用户数 end @ex_status = @exercise.get_exercise_status(current_user) exercise_id_array = [@exercise.id] - @exercise_publish_count = get_user_permission_course(exercise_id_array,2).count #是否存在已发布的 - @exercise_unpublish_count = get_user_permission_course(exercise_id_array,1).count #是否存在未发布的 + @exercise_publish_count = get_user_permission_course(exercise_id_array,2).size #是否存在已发布的 + @exercise_unpublish_count = get_user_permission_course(exercise_id_array,1).size #是否存在未发布的 if (@exercise_publish_count == 0) && (@exercise_unpublish_count == 0) #即表示没有分班 if @ex_status == 1 diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 1dd6c7452..6eb798d9a 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -115,14 +115,13 @@ module ExercisesHelper right_users_count = 0 #该问题的回答正确的人数 #计算每个问题的答案人数 - # user_ids.each do |user_id| - # answer_choice_array = effictive_users.where(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq - # if answer_choice_array.sort == standard_answer - # right_users_count += 1 - # end - # end - # percent = effictive_users_count > 0 ? (right_users_count / effictive_users_count.to_f).round(3)*100 : 0.0 - percent = 0.0 + user_ids.each do |user_id| + answer_choice_array = effictive_users.where(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq + if answer_choice_array.sort == standard_answer + right_users_count += 1 + end + end + percent = effictive_users_count > 0 ? (right_users_count / effictive_users_count.to_f).round(3)*100 : 0.0 ex.exercise_choices.each do |c| right_answer = standard_answer.include?(c.choice_position) #选项的标准答案为选项的位置 answer_this_choice = effictive_users.search_exercise_answer("exercise_choice_id",c.id) diff --git a/app/models/exercise.rb b/app/models/exercise.rb index e7d141ea9..a46fded25 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -178,13 +178,12 @@ class Exercise < ApplicationRecord ex_answer_user = exercise_users.where(user_id: user.id).select(:start_at,:end_at,:commit_status) user_ex_status = get_exercise_status(user) user_status = 2 - if ex_answer_user.exists? && (ex_answer_user.first&.start_at.present? || ex_answer_user.first&.end_at.present?) #学生有过答题的,或者立即截止,但学生未做试卷的 + if ex_answer_user.present? && (ex_answer_user.first&.start_at.present? || ex_answer_user.first&.end_at.present?) #学生有过答题的,或者立即截止,但学生未做试卷的 user_status = ex_answer_user.first.commit_status end - if ex_answer_user.exists? && ex_answer_user.first&.start_at.blank? && user_ex_status == 3 + if ex_answer_user.present? && ex_answer_user.first&.start_at.blank? && user_ex_status == 3 user_status = 4 end - user_status end