实践课程统计

dev_daiao
daiao 5 years ago
parent 11155590fa
commit ab02572d06

@ -456,6 +456,25 @@ class SubjectsController < ApplicationController
end end
end end
def statistics_new
# data = Subjects::DataStatisticService.new(@subject)
# Rails.logger.info("study_count: #{data.study_count}")
# Rails.logger.info("course_study_count: #{ data.course_study_count}")
# Rails.logger.info("passed_count: #{data.passed_count}")
# Rails.logger.info("course_used_count: #{data.course_used_count}")
# Rails.logger.info("school_used_count: #{data.school_used_count}")
# data_1 = Subjects::CourseUsedInfoService.call(@subject)
# Rails.logger.info("study_count: #{data_1}")
# data_2 = Subjects::ShixunUsedInfoService.call(@subject)
# Rails.logger.info("study_count: #{data_2}")
data_3 = Subjects::UserUsedInfoService.call(@subject)
Rails.logger.info("study_count: #{data_3}")
render_ok()
end
def shixun_report def shixun_report
end end

@ -5,7 +5,7 @@ class Myshixun < ApplicationRecord
has_one :shixun_modify, :dependent => :destroy has_one :shixun_modify, :dependent => :destroy
belongs_to :user belongs_to :user
belongs_to :user_extension belongs_to :user_extension, foreign_key: :user_id
belongs_to :shixun, counter_cache: true belongs_to :shixun, counter_cache: true
has_one :last_executable_task, -> { where(status: [0, 1]).reorder(created_at: :asc) }, class_name: 'Game' has_one :last_executable_task, -> { where(status: [0, 1]).reorder(created_at: :asc) }, class_name: 'Game'
@ -22,7 +22,7 @@ class Myshixun < ApplicationRecord
end end
def output_times def output_times
games.pluck(:evaluate_count).sum.to_i games.map(&:evaluate_count).sum.to_i
end end
def repo_path def repo_path

@ -13,7 +13,7 @@ class Subjects::CourseUsedInfoService < ApplicationService
.where(homework_commons_shixuns: {shixun_id: @shixun_ids}) .where(homework_commons_shixuns: {shixun_id: @shixun_ids})
course_ids = homework_commons.pluck(:course_id) course_ids = homework_commons.pluck(:course_id)
homework_common_ids = homework_commons.pluck("homework_commons.id") homework_common_ids = homework_commons.pluck("homework_commons.id")
schools = School.joins(courses: [:course_members, :homework_commons]) schools = School.joins(:courses).where(courses: {id: course_ids}).select("schools.*, count(courses.id) course_count")
# name将该课程使用到课堂的单位 # name将该课程使用到课堂的单位
# course_count: 将该课程使用到课堂的数量 # course_count: 将该课程使用到课堂的数量
@ -23,11 +23,11 @@ class Subjects::CourseUsedInfoService < ApplicationService
course_info = course_info =
schools.map do |school| schools.map do |school|
name = school.name name = school.name
course_count = school.where(courses: {id: course_ids}).count course_count = school.course_count
student_count = school.where(course_members: {role: 4}).select("course_members.user_id").distinct.size student_count = school.courses.joins(:course_members).where(course_members: {role: 4, course_id: course_ids})
homework_commons = school.where(homework_commons: {id: homework_common_ids}) homework_commons = school.courses.joins(:homework_commons).where(homework_commons: {id: homework_common_ids})
.select("homework_commons.id") .pluck("homework_commons.id")
choice_shixun_num = homework_commons.distinct.size choice_shixun_num = homework_commons.uniq.size
choice_shixun_frequency = homework_commons.size choice_shixun_frequency = homework_commons.size
{name: name, course_count: course_count, student_count: student_count, choice_shixun_num: choice_shixun_num, {name: name, course_count: course_count, student_count: student_count, choice_shixun_num: choice_shixun_num,
choice_shixun_frequency: choice_shixun_frequency} choice_shixun_frequency: choice_shixun_frequency}

@ -10,7 +10,7 @@ class Subjects::DataStatisticService < ApplicationService
# 文案解释:学习该课程的全部人数(学习总人数=课堂学习人数+自主学习人数) # 文案解释:学习该课程的全部人数(学习总人数=课堂学习人数+自主学习人数)
# 开发备注只要点击该课程的任何一个实训生成了tpi都算一个学习人数去重一个人数计算1次 # 开发备注只要点击该课程的任何一个实训生成了tpi都算一个学习人数去重一个人数计算1次
def study_count def study_count
@shixuns.joins(:myshixuns).select("myshixuns.user_id").distinct.size @shixuns.joins(:myshixuns).pluck("myshixuns.user_id").uniq.size
end end
# 课堂学习人数: # 课堂学习人数:
@ -18,7 +18,7 @@ class Subjects::DataStatisticService < ApplicationService
# 开发备注只要通过课堂进入并点击了实训生成了tpi则算一个可以学习人数去重一个人数计算1次 # 开发备注只要通过课堂进入并点击了实训生成了tpi则算一个可以学习人数去重一个人数计算1次
def course_study_count def course_study_count
# 实训作业 # 实训作业
sw_user_ids = StudentWork.where.not(myshixun_id: nil).joins(homework_common: :homework_commons_shixuns) sw_user_ids = StudentWork.where.not(myshixun_id: nil).joins(homework_common: :homework_commons_shixun)
.where(homework_commons_shixuns: {shixun_id: @shixun_ids}).pluck("student_works.user_id") .where(homework_commons_shixuns: {shixun_id: @shixun_ids}).pluck("student_works.user_id")
# 试卷的实训题 # 试卷的实训题
esa_user_ids = ExerciseShixunAnswer.joins(exercise_shixun_challenge: :shixun) esa_user_ids = ExerciseShixunAnswer.joins(exercise_shixun_challenge: :shixun)
@ -37,7 +37,7 @@ class Subjects::DataStatisticService < ApplicationService
# 文案解释: # 文案解释:
# 通关该课程所有实训的人数去重。一个人数计算1次 # 通关该课程所有实训的人数去重。一个人数计算1次
def passed_count def passed_count
@shixuns.includes(:myshixuns).where(myshixuns: {status: 1}).select("myshixuns.user_id").distinct.size @shixuns.includes(:myshixuns).where(myshixuns: {status: 1}).pluck("myshixuns.user_id").uniq.size
end end
# 使用课堂数: # 使用课堂数:
@ -65,7 +65,7 @@ class Subjects::DataStatisticService < ApplicationService
private private
def school_ids def school_ids
@shixuns.joins(myshixuns: :user_extension).select("user_extensions.school_id").distinct @shixuns.joins(myshixuns: :user_extension).pluck("user_extensions.school_id").uniq
end end

@ -17,15 +17,22 @@ class Subjects::ShixunUsedInfoService < ApplicationService
school_count = shixun.homework_commons_shixuns.select{|hcs| hcs.homework_common.course.school_id}.uniq.size school_count = shixun.homework_commons_shixuns.select{|hcs| hcs.homework_common.course.school_id}.uniq.size
used_count = shixun.myshixuns_count used_count = shixun.myshixuns_count
passed_count = shixun.myshixuns.select{|m| m.status == 1}.size passed_count = shixun.myshixuns.select{|m| m.status == 1}.size
evaluate_count = shixun.myshixuns.map{|m| m.games.sum(:evaluate_count).to_i}.sum evaluate_count = shixun.myshixuns.map{|m| m.output_times }.sum
passed_ave_time = (passed_count > 0) ? passed_ave_time = passed_count > 0 ? shixun.myshixuns.map{|m| m.total_cost_time}.sum : 0
(shixun.myshixuns.map{|m| m.status == 1 && m.games.sum(:cost_time).to_i}.sum / passed_count) : 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, 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, school_count: school_count, used_count: used_count, passed_count: passed_count,
evaluate_count: evaluate_count, passed_ave_time: passed_ave_time} evaluate_count: evaluate_count, passed_ave_time: passed_ave_time}
end end
shixun_infos shixun_infos
end end
end end
end end

@ -1,4 +1,4 @@
class Subject::UserUsedInfoService < ApplicationService class Subjects::UserUsedInfoService < ApplicationService
attr_reader :subject, :shixun_ids attr_reader :subject, :shixun_ids
def initialize(subject) def initialize(subject)
@ -8,21 +8,19 @@ class Subject::UserUsedInfoService < ApplicationService
end end
def call def call
users = User.joins(:myshixuns).where(myshixuns: {shixun_id: shixun_ids}).group(:user_id)
users_info = [] users_info = []
users.includes(:myshixuns, :games).each do |user| users = User.includes(myshixuns: :games).where(myshixuns: {shixun_id: shixun_ids}, games: {status: 2})
games = user.games users.each do |user|
name = "#{user.lastname}#{user.firstname}" myshixuns = user.myshixuns.select{|m| shixun_ids.include?(m.shixun_id)}
passed_myshixun_count = user.myshixuns.select{|m| m.status == 1}.size name = "#{user.lastname}#{user.firstname}"
passed_games_count = games.select{|g| g.status == 2}.size passed_myshixun_count = myshixuns.select{|m| m.status == 1}.size
passed_games_count = myshixuns.map{|m| m.games.select{|g| g.status == 2}.size }.size
code_line_count = "未完成" code_line_count = "未完成"
evaluate_count = games.sum(evaluate_count) evaluate_count = myshixuns.map{|m| m.output_times }.sum
cost_time = games.sum(:cost_time) cost_time = myshixuns.map{|m|m.total_cost_time }.sum
user_login = user.login users_info << {login: user.login, name: name, passed_myshixun_count: passed_myshixun_count,
users_info << {login: user_login, name: name, passed_myshixun_count: passed_myshixun_count,
passed_games_count: passed_games_count, code_line_count: code_line_count, passed_games_count: passed_games_count, code_line_count: code_line_count,
evaluate_count: evaluate_count, cost_time: cost_time} evaluate_count: evaluate_count, cost_time: cost_time}
end end
users_info users_info
end end

@ -394,6 +394,7 @@ Rails.application.routes.draw do
get 'cancel_publish' get 'cancel_publish'
get 'cancel_has_publish' get 'cancel_has_publish'
get 'statistics' get 'statistics'
get 'statistics_new'
get 'shixun_report' get 'shixun_report'
get 'school_report' get 'school_report'
post 'update_attr' post 'update_attr'

Loading…
Cancel
Save