From 560332ab0951dc7d7e48642bb4e95880173303fe Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 15 Jul 2019 16:46:40 +0800 Subject: [PATCH] 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