diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 99356946f..77c9fe0a6 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1407,11 +1407,16 @@ class ExercisesController < ApplicationController min_score = exercise_scores.min.present? ? exercise_scores.min : 0.0 max_score = exercise_scores.max.present? ? exercise_scores.max : 0.0 total_score = exercise_scores.sum.present? ? exercise_scores.sum : 0.0 - average_score = @exercise_commit_user_counts > 0 ? (total_score / @exercise_commit_user_counts).round(1) : 0.0 - fail_counts = exercise_scores.count{|a| a < 60.0} - pass_counts = exercise_scores.count{|a| a < 70.0 && a >= 60.0} - good_counts = exercise_scores.count{|a| a < 90.0 && a >= 70.0} - best_counts = exercise_scores.count{|a| a >= 90.0 && a <= 100.0} + average_score = @exercise_commit_user_counts > 0 ? (total_score.round(1) / @exercise_commit_user_counts).round(1) : 0.0 + question_scores = @exercise.question_scores + fail_score = question_scores * 0.6.round(2) + pass_score = question_scores * 0.7.round(2) + good_score = question_scores * 0.9.round(2) + + fail_counts = exercise_scores.count{|a| a < fail_score} + pass_counts = exercise_scores.count{|a| a < pass_score && a >= fail_score} + good_counts = exercise_scores.count{|a| a < good_score && a >= pass_score} + best_counts = exercise_scores.count{|a| a >= good_score && a <= question_scores} end @counts_array = { :commit_percent => commit_percent, diff --git a/app/helpers/export_helper.rb b/app/helpers/export_helper.rb index 36120266b..86cac2f98 100644 --- a/app/helpers/export_helper.rb +++ b/app/helpers/export_helper.rb @@ -112,7 +112,7 @@ module ExportHelper @work_cells_column.push(row_cells_column) end else #实训题 - shixun = homework.shixuns.first + shixun = homework.shixuns.take shixun_head_cells = %w(完成情况 通关时间 学员在EduCoder做实训花费的时间 总评测次数 获得经验值 关卡得分) eff_boolean = homework.work_efficiency if eff_boolean @@ -123,9 +123,12 @@ module ExportHelper if allow_late_boolean #允许迟交 eff_score_cell.push("迟交扣分") end - shixun_time_cells = %w(最终成绩 更新时间 作业发布到学员完成作业所耗的时间 评语) + shixun_time_cells = %w(最终成绩 更新时间 作业发布到学员完成作业所耗的时间 总评语) + for i in 1 .. shixun.challenges.size + shixun_time_cells << "第#{i}关评语" + end @work_head_cells = (head_cells_format + shixun_head_cells + eff_score_cell + shixun_time_cells).reject(&:blank?) - works.includes(:student_works_scores, user: :user_extension, myshixun: :games).each_with_index do |w, index| + works.includes(:shixun_work_comments, :student_works_scores, user: :user_extension, myshixun: :games).each_with_index do |w, index| myshixun = w.try(:myshixun) w_user = w.user w_1 = (index + 1) @@ -165,21 +168,20 @@ module ExportHelper w_16 = w.update_time ? format_time(w.update_time) : "--" "更新时间" myshixun_complete = myshixun && myshixun.status == 1 w_17 = myshixun_complete && w.cost_time ? (game_spend_time w.cost_time) : "未完成" - teacher_comments = w.student_works_scores - if teacher_comments.present? - w_18 = "" - teacher_comments.each do |t| - user_name = t.user&.real_name - user_time = format_time(t.updated_at) - user_score = t&.score - user_comment = t.comment.present? ? t.comment : "--" - comment_title = "#{user_name}: #{user_time.to_s} #{user_score.to_s}分\n#{user_comment}\n\n" - w_18 = w_18 + comment_title - end + teacher_comment = w.shixun_work_comments.select{|comment| comment.challenge_id == 0}.first + if teacher_comment.present? + w_18 = "学生可见:\n #{teacher_comment.comment.to_s} \n\n 老师可见:\n#{teacher_comment.hidden_comment.to_s}" else w_18 = "--" end row_cells_column = [w_1,w_2,w_3,w_3_1,w_4,w_5,w_6,w_7,w_8,w_9,w_10,w_11,w_12,w_13,w_14,w_15,w_16,w_17,w_18] + + # 关卡评语 + shixun.challenges.pluck(:id).each do |challenge_id| + challenge_comment = w.shixun_work_comments.select{|comment| comment.challenge_id == challenge_id}.first + row_cells_column << (challenge_comment.present? ? "学生可见:\n #{challenge_comment.comment.to_s} \n\n 老师可见:\n#{challenge_comment.hidden_comment.to_s}" : "--") + end + row_cells_column = row_cells_column.reject(&:blank?) @work_cells_column.push(row_cells_column) end diff --git a/app/models/course.rb b/app/models/course.rb index 01eed30db..16700428b 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -196,7 +196,7 @@ class Course < ApplicationRecord end def all_course_module_types - %w[activity announcement online_learning shixun_homework common_homework group_homework exercise attachment course_group graduation poll board] + %w[activity announcement online_learning shixun_homework common_homework group_homework exercise attachment course_group graduation poll board statistics] end def get_course_module_by_type(type) @@ -386,6 +386,7 @@ class Course < ApplicationRecord when 'attachment' then '资源' when 'board' then '讨论' when 'course_group' then '分班' + when 'statistics' then '统计' else '' end end @@ -404,6 +405,7 @@ class Course < ApplicationRecord when 'attachment' then 10 when 'board' then 11 when 'course_group' then 12 + when 'statistics' then 13 else 100 end end diff --git a/app/models/exercise.rb b/app/models/exercise.rb index 8469d25b6..0b9963eee 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -37,6 +37,9 @@ class Exercise < ApplicationRecord DEADLINE = 3 #已截止 ENDED = 4 #课堂已结束 + def question_scores + exercise_questions.pluck(:question_score).sum + end def create_exercise_list str = "" diff --git a/app/services/admins/competition_stage_create_service.rb b/app/services/admins/competition_stage_create_service.rb index cc7b338e4..dc0e65991 100644 --- a/app/services/admins/competition_stage_create_service.rb +++ b/app/services/admins/competition_stage_create_service.rb @@ -10,13 +10,15 @@ class Admins::CompetitionStageCreateService < ApplicationService ActiveRecord::Base.transaction do stage = CompetitionStage.create!(competition_id: competition.id, name: params[:stage_name], score_rate: (params[:score_rate].to_i / 100).round(2)) - params[:stage].each do |section| - stage_section = CompetitionStageSection.create!(competition_id: competition.id, competition_stage_id: stage.id, - start_time: section["start_time"], end_time: section["end_time"], - entry: section["entry"], score_source: section["score_source"]) - section["identifiers"].each do |identifier| - CompetitionEntry.create!(competition_stage_section_id: stage_section.id, competition_stage_id: stage.id, - shixun_identifier: identifier) + unless params[:stage].blank? + params[:stage].each do |section| + stage_section = CompetitionStageSection.create!(competition_id: competition.id, competition_stage_id: stage.id, + start_time: section["start_time"], end_time: section["end_time"], + entry: section["entry"], score_source: section["score_source"]) + section["identifiers"].each do |identifier| + CompetitionEntry.create!(competition_stage_section_id: stage_section.id, competition_stage_id: stage.id, + shixun_identifier: identifier) + end end end diff --git a/app/services/admins/competition_stage_update_service.rb b/app/services/admins/competition_stage_update_service.rb index 1e5501260..a3988d417 100644 --- a/app/services/admins/competition_stage_update_service.rb +++ b/app/services/admins/competition_stage_update_service.rb @@ -13,13 +13,15 @@ class Admins::CompetitionStageUpdateService < ApplicationService stage.competition_stage_sections.destroy_all - params[:stage].each do |section| - stage_section = CompetitionStageSection.create!(competition_id: competition.id, competition_stage_id: stage.id, - start_time: section["start_time"], end_time: section["end_time"], - entry: section["entry"], score_source: section["score_source"]) - section["identifiers"].each do |identifier| - CompetitionEntry.create!(competition_stage_section_id: stage_section.id, competition_stage_id: stage.id, - shixun_identifier: identifier) + unless params[:stage].blank? + params[:stage].each do |section| + stage_section = CompetitionStageSection.create!(competition_id: competition.id, competition_stage_id: stage.id, + start_time: section["start_time"], end_time: section["end_time"], + entry: section["entry"], score_source: section["score_source"]) + section["identifiers"].each do |identifier| + CompetitionEntry.create!(competition_stage_section_id: stage_section.id, competition_stage_id: stage.id, + shixun_identifier: identifier) + end end end diff --git a/app/views/admins/competition_settings/index.html.erb b/app/views/admins/competition_settings/index.html.erb index 73bc343d6..a03e1e351 100644 --- a/app/views/admins/competition_settings/index.html.erb +++ b/app/views/admins/competition_settings/index.html.erb @@ -360,7 +360,7 @@ %
新增子阶段 - <% if stage.max_end_time > Time.now %> + <% if stage.max_end_time && stage.max_end_time > Time.now %> <%= agree_link '发送短信提醒', send_message_admins_competition_competition_stage_path(@competition, stage, element: ".send-message-#{stage.id}"), class: 'btn btn-outline-primary ml20', 'data-confirm': '确认执行发送短信操作?' %> <% end %> @@ -492,6 +492,7 @@
<% end %> <% end %> +
diff --git a/db/migrate/20191029011040_add_statistics_to_course_module.rb b/db/migrate/20191029011040_add_statistics_to_course_module.rb new file mode 100644 index 000000000..3babbcdbf --- /dev/null +++ b/db/migrate/20191029011040_add_statistics_to_course_module.rb @@ -0,0 +1,7 @@ +class AddStatisticsToCourseModule < ActiveRecord::Migration[5.2] + def change + Course.includes(:course_modules).all.each do |course| + CourseModule.create!(course_id: course.id, module_type: "statistics", hidden:0, module_name: "统计", position: course.course_modules.pluck(:position).max + 1) + end + end +end