dev_daiao
daiao 5 years ago
parent b640198fdc
commit 3f0e5b95ec

@ -59,6 +59,9 @@ class Shixun < ApplicationRecord
# Jupyter数据集,附件 # Jupyter数据集,附件
has_many :data_sets, ->{where(attachtype: 2)}, class_name: 'Attachment', as: :container, dependent: :destroy has_many :data_sets, ->{where(attachtype: 2)}, class_name: 'Attachment', as: :container, dependent: :destroy
# 试卷的实训题
has_many :exercise_questions
scope :search_by_name, ->(keyword) { where("name like ? or description like ? ", scope :search_by_name, ->(keyword) { where("name like ? or description like ? ",
"%#{keyword}%", "%#{keyword}%") } "%#{keyword}%", "%#{keyword}%") }

@ -0,0 +1,22 @@
class Subjects::DataStatisticService < ApplicationService
attr_reader :subject, :user
def initialize(subject, user)
@subject = subject
@user = user
@shixuns = subject.shixuns
end
# 学习总人数
def study_count
@shixuns.includes(:myshixuns).map{|shixun| shixun.myshixuns.pluck(:user_id)}.uniq
end
# 课堂学习人数
def course_study_count
# 实训作业
sw_user_ids = StudentWork.where.not(myshixun_id: nil).pluck(:user_id)
# 试卷的实训题
esa_user_ids = ExerciseShixunAnswer.where()
end
end
Loading…
Cancel
Save