|
|
|
@ -17,12 +17,12 @@ class Ecs::QueryCourseEvaluationService < ApplicationService
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def graduation_subitem_evaluations
|
|
|
|
|
student_scores = ec_course.ec_course_student_scores.joins(:ec_course_target).group(:ec_course_target_id)
|
|
|
|
|
student_scores = ec_course.ec_course_student_scores.joins(ec_student_score_targets: :ec_course_target).group(:ec_course_target_id)
|
|
|
|
|
student_scores = student_scores.select('AVG(score) as average_score, ec_course_target_id')
|
|
|
|
|
student_score_map = student_scores.group_by { |item| item.ec_course_target_id }
|
|
|
|
|
|
|
|
|
|
subitem_targets = ec_course.ec_graduation_subitem_course_targets
|
|
|
|
|
.includes(ec_graduation_subitem: :ec_graduation_requirement)
|
|
|
|
|
.includes(:ec_course_target, ec_graduation_subitem: :ec_graduation_requirement)
|
|
|
|
|
|
|
|
|
|
subitem_targets.group_by(&:ec_graduation_subitem_id).map do |_id, arr|
|
|
|
|
|
subitem = arr.first.ec_graduation_subitem
|
|
|
|
@ -37,7 +37,7 @@ class Ecs::QueryCourseEvaluationService < ApplicationService
|
|
|
|
|
|
|
|
|
|
arr.map(&:ec_course_target).uniq.each do |target|
|
|
|
|
|
target_total_rates += target.weight.to_f
|
|
|
|
|
student_score = student_score_map[target.id]
|
|
|
|
|
student_score = student_score_map[target.id]&.first
|
|
|
|
|
|
|
|
|
|
reach_real_target += student_score.average_score.to_f * target.weight.to_f if student_score
|
|
|
|
|
end
|
|
|
|
@ -60,8 +60,19 @@ class Ecs::QueryCourseEvaluationService < ApplicationService
|
|
|
|
|
|
|
|
|
|
def score_levels_map
|
|
|
|
|
@_score_levels_map ||= begin
|
|
|
|
|
index = 0
|
|
|
|
|
ec_course.ec_score_levels.each_with_object({}) do |level, obj|
|
|
|
|
|
obj[level.id.to_s] = level.as_json(only: %i[id position score level])
|
|
|
|
|
hash = level.as_json(only: %i[id position score level])
|
|
|
|
|
|
|
|
|
|
hash[:description] =
|
|
|
|
|
case index
|
|
|
|
|
when 0 then "#{level.score}分以上"
|
|
|
|
|
when ec_course.ec_score_levels.to_a.size - 1 then "低于#{level.score}分"
|
|
|
|
|
else "#{level.score}~#{ec_course.ec_score_levels[index - 1].score - 1}分"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
index += 1
|
|
|
|
|
obj[level.id.to_s] = hash
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
@ -87,23 +98,29 @@ class Ecs::QueryCourseEvaluationService < ApplicationService
|
|
|
|
|
@_course_achievement += data[:average_score].to_f * course_target.weight.to_f
|
|
|
|
|
|
|
|
|
|
# 计算学生成绩分布区间
|
|
|
|
|
student_count = 0
|
|
|
|
|
data[:score_levels] = score_levels.map do |score_level|
|
|
|
|
|
level_condition_proc =
|
|
|
|
|
if (score_level.position - 1).zero? # 第一区间
|
|
|
|
|
-> (score_target){ score_target.score >= score_level.score ? 1 : 0 }
|
|
|
|
|
elsif score_levels.position == score_levels.size # 末尾区间
|
|
|
|
|
elsif score_level.position == score_levels.size # 末尾区间
|
|
|
|
|
-> (score_target){ score_target.score < score_level.score ? 1 : 0 }
|
|
|
|
|
else
|
|
|
|
|
# 中间区间
|
|
|
|
|
-> (score_target){ score_target.score >= score_level.score && score_target.score < score_targets[score_level.position - 1] ? 1 : 0 }
|
|
|
|
|
-> (score_target){ score_target.score >= score_level.score && score_target.score < score_levels[score_level.position - 1].score ? 1 : 0 }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 计算该成绩区间人数
|
|
|
|
|
count = score_targets.sum(&level_condition_proc)
|
|
|
|
|
student_count += count
|
|
|
|
|
|
|
|
|
|
{ id: score_level.id, count: count }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
data[:score_levels].each do |score_level|
|
|
|
|
|
score_level[:rate] = score_level[:count].fdiv(student_count).round(2)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
data
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|