dev_daiao
daiao 5 years ago
parent bbf6c47ccf
commit 9ad2a0ffe6

@ -30,6 +30,8 @@ class Shixun < ApplicationRecord
has_one :first_tag_repertoire, through: :first_shixun_tag_repertoire, source: :tag_repertoire
has_many :homework_commons_shixuns, class_name: 'HomeworkCommonsShixun'
has_many :homework_commons, through: :homework_commons_shixuns
has_many :fork_shixuns, foreign_key: "fork_from", class_name: 'Shixun'
#实训的关卡

@ -13,27 +13,27 @@ class Subjects::CourseUsedInfoService < ApplicationService
.where(homework_commons_shixuns: {shixun_id: @shixun_ids})
course_ids = homework_commons.pluck(:course_id)
homework_common_ids = homework_commons.pluck("homework_commons.id")
schools = School.joins(:courses).where(courses: {id: course_ids}).select("schools.*, count(courses.id) course_count")
schools = School.joins(:courses).where(courses: {id: course_ids}).group("schools.id").select("schools.*, count(courses.id) course_count")
# name将该课程使用到课堂的单位
# course_count: 将该课程使用到课堂的数量
# student_count: 课堂的学生总数(去掉重复)
# choice_shixun_num: 选用该课程实训的个数(去重)
# choice_shixun_frequency: 选用该课程实训的次数
course_info =
course_info = []
schools.map do |school|
name = school.name
course_count = school.course_count
student_count = school.courses.joins(:course_members).where(course_members: {role: 4, course_id: course_ids})
homework_commons = school.courses.joins(:homework_commons).where(homework_commons: {id: homework_common_ids})
.pluck("homework_commons.id")
choice_shixun_num = homework_commons.uniq.size
choice_shixun_frequency = homework_commons.size
{school_id: school.id, school_name: name, course_count: course_count, student_count: student_count,
student_count = school.courses.joins(:course_members).where(course_members: {role: 4, course_id: course_ids}).size
shixun_ids = school.courses.joins(homework_commons: :homework_commons_shixun)
.where(homework_commons: {id: homework_common_ids})
.pluck("homework_commons_shixuns.shixun_id")
choice_shixun_frequency = shixun_ids.size
choice_shixun_num = shixun_ids.uniq.size
course_info << {school_id: school.id, school_name: name, course_count: course_count, student_count: student_count,
choice_shixun_num: choice_shixun_num, choice_shixun_frequency: choice_shixun_frequency}
end
# 默认按照选用实训的次数作为排序
course_info.sort{|x,y| y['choice_shixun_frequency'] <=> x['choice_shixun_frequency']}
course_info
end
end

@ -18,7 +18,7 @@ class Subjects::DataStatisticService < ApplicationService
# 开发备注只要通过课堂进入并点击了实训生成了tpi则算一个可以学习人数去重一个人数计算1次
def course_study_count
# 实训作业
sw_user_ids = StudentWork.where.not(myshixun_id: nil).joins(homework_common: :homework_commons_shixun)
sw_user_ids = StudentWork.where.not(myshixun_id: 0).joins(homework_common: :homework_commons_shixun)
.where(homework_commons_shixuns: {shixun_id: @shixun_ids}).pluck("student_works.user_id")
# 试卷的实训题
esa_user_ids = ExerciseShixunAnswer.joins(exercise_shixun_challenge: :shixun)

@ -13,26 +13,18 @@ class Subjects::ShixunUsedInfoService < ApplicationService
stage = "#{position}-#{index+1}"
name = shixun.name
challenge_count = shixun.challenges_count
course_count = shixun.homework_commons_shixuns.select{|hcs| hcs.homework_common.course_id}.uniq.size
school_count = shixun.homework_commons_shixuns.select{|hcs| hcs.homework_common.course.school_id}.uniq.size
course_count = shixun.homework_commons.map{|hc| hc.course_id}.uniq.size
school_count = shixun.homework_commons.map{|hc| hc.course&.school_id}.uniq.size
used_count = shixun.myshixuns_count
passed_count = shixun.myshixuns.select{|m| m.status == 1}.size
evaluate_count = shixun.myshixuns.map{|m| m.output_times }.sum
passed_ave_time = passed_count > 0 ? shixun.myshixuns.map{|m| m.total_cost_time}.sum : 0
#evaluate_count = shixun.myshixuns.joins(:games).select("SUM(games.evaluate_count) evaluate_count").first.evaluate_count
# passed_ave_time = (passed_count > 0) ?
# (shixun.myshixuns.joins(:games)
# .where(myshixuns: {status: 1})
# .select("SUM(games.cost_time) cost_time").first.cost_time / passed_count) : 0
shixun_infos << {stage: stage, name: name, challenge_count: challenge_count, course_count: course_count,
school_count: school_count, used_count: used_count, passed_count: passed_count,
evaluate_count: evaluate_count, passed_ave_time: passed_ave_time, shixun_id: shixun.id}
end
shixun_infos
end
shixun_infos
end
end

@ -0,0 +1,5 @@
class ModifyMyshixunIdForStudentWorks < ActiveRecord::Migration[5.2]
def change
StudentWork.where(myshixun_id: nil).update_all(myshixun_id: 0)
end
end

@ -10,13 +10,19 @@ namespace :subjects do
Rails.logger.info("---------------------data_statistic: #{subject.id}")
sr = SubjectRecord.find_or_create_by!(subject_id: subject.id)
data = Subjects::DataStatisticService.new(subject)
study_count = data.study_count
# 总人数没有变化的话,不同课堂之类的变化了
course_study_count = (study_count == sr.study_count ? sr.course_study_count : data.course_study_count)
passed_count = (study_count == sr.study_count ? sr.passed_count : data.passed_count)
course_used_count = (study_count == sr.study_count ? sr.course_used_count : data.course_used_count)
school_used_count = (study_count == sr.study_count ? sr.school_used_count : data.school_used_count)
update_params = {
study_count: data.study_count,
course_study_count: data.course_study_count,
initiative_study: data.initiative_study,
passed_count: data.passed_count,
course_used_count: data.course_used_count,
school_used_count: data.school_used_count
study_count: study_count,
course_study_count: course_study_count,
initiative_study: (study_count - course_study_count),
passed_count: passed_count,
course_used_count: course_used_count,
school_used_count: school_used_count
}
sr.update_attributes!(update_params)
end
@ -31,7 +37,7 @@ namespace :subjects do
subjects.find_each do |subject|
puts("---------------------course_info_statistic: #{subject.id}")
Rails.logger.info("---------------------course_info_statistic: #{subject.id}")
data = Subjects::DataStatisticService.call(subject)
data = Subjects::CourseUsedInfoService.call(subject)
data.each do |key|
scr = SubjectCourseRecord.find_or_create_by!(school_id: key[:school_id], subject_id: subject.id)
update_params = {
@ -53,6 +59,8 @@ namespace :subjects do
Rails.logger.info("---------------------shixun_info_statistic_begin")
subjects = Subject.where(status: 2)
subjects.find_each(batch_size: 100) do |subject|
puts("---------------------shixun_info_statistic: #{subject.id}")
Rails.logger.info("---------------------shixun_info_statistic: #{subject.id}")
data = Subjects::ShixunUsedInfoService.call(subject)
data.each do |key|
ssi = SubjectShixunInfo.find_or_create_by!(shixun_id: key[:shixun_id], subject_id: subject.id)

Loading…
Cancel
Save