diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index ae7335496..b429f3298 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("验证码无效") diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 79b22d571..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 @@ -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/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 276fbef32..31395def2 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -260,12 +260,14 @@ 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 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}") diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 019b690b5..8f6dd23a4 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -652,7 +652,7 @@ class ShixunsController < ApplicationController def update_file content = params[:content] author_name = current_user.full_name - author_email = current_user.mail + author_email = current_user.git_mail @content = update_file_content content, @repo_path, @path, author_email, author_name, "Edit by browser" end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index cdd647ebd..4c3a449e9 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(email.split("@").first) end # 不同的类型扩展不同的目录 diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 7d50d1a66..6eb798d9a 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,19 +103,29 @@ 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| + 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) - answer_users_count = answer_this_choice.count + answer_users_count = answer_this_choice.size if effictive_users_count == 0 answer_percent = 0.0 else @@ -125,7 +135,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) @@ -156,18 +166,18 @@ 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, :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,21 +189,19 @@ 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) 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分的,及未评阅的 - # review_scores = ex.exercise_answer_comments.count #主观题的评阅数量 + 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 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 +215,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) @@ -220,13 +228,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 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] @@ -242,7 +250,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 +260,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 @@ -402,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 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 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