From 3f0e5b95ec0df2e52434c25d67624cbb3e86f3ff Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 8 Jan 2020 09:58:07 +0800 Subject: [PATCH] 1 --- app/models/shixun.rb | 3 +++ .../subjects/data_statistic_service.rb | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 app/services/subjects/data_statistic_service.rb diff --git a/app/models/shixun.rb b/app/models/shixun.rb index d8a41ba6a..b77038a78 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -59,6 +59,9 @@ class Shixun < ApplicationRecord # Jupyter数据集,附件 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 ? ", "%#{keyword}%", "%#{keyword}%") } diff --git a/app/services/subjects/data_statistic_service.rb b/app/services/subjects/data_statistic_service.rb new file mode 100644 index 000000000..9311953ca --- /dev/null +++ b/app/services/subjects/data_statistic_service.rb @@ -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