diff --git a/app/services/schools/school_statistic_service.rb b/app/services/schools/school_statistic_service.rb new file mode 100644 index 000000000..a5082108d --- /dev/null +++ b/app/services/schools/school_statistic_service.rb @@ -0,0 +1,100 @@ +class Schools::SchoolStatisticService < ApplicationService + attr_reader :school + + def initialize(school) + @school = school.includes(:courses, user_extensions: :user) + @user_extensions = school.user_extensions + end + + # 学校老师数量 + def teacher_count + @user_extensions.map{|ue| ue.identity == 0 }.size + end + + # 学校学生数 + def student_count + @user_extensions.map{|ue| ue.identity == 1 }.size + end + + # 活跃用户(近1天有登录) + def acitve_user_1_day_count + @user_extensions.map{|ue| ue.user.last_login_on&.between?(1.days.ago, Time.now)}.size + end + + # 活跃用户(近1个周有登录) + def acitve_user_1_week_count + @user_extensions.map{|ue| ue.user.last_login_on&.between?(1.weeks.ago, Time.now)}.size + end + + # 活跃用户(近3个月有登录) + def acitve_user_1_months_count + @user_extensions.map{|ue| ue.user.last_login_on&.between?(1.months.ago, Time.now)}.size + end + + # 活跃用户(近3个月有登录) + def acitve_user_3_months_count + @user_extensions.map{|ue| ue.user.last_login_on&.between?(3.months.ago, Time.now)}.size + end + + # 活跃用户(进半年有登录记录) + def acitve_user_6_months_count + @user_extensions.map{|ue| ue.user.last_login_on&.between?(6.months.ago, Time.now)}.size + end + + # 课堂总数(上层记得Include) + def courses_count + @school.courses.size + end + + # 正在进行的课堂数 + def curr_courses_count + @school.courses.map{|c| c.is_end == false && c.is_delete != 0}.size + end + + # 实训作业数目 + def hom_shixuns_count + @school.courses.joins(:homework_commons).where(homework_commons: {homework_type: 'practice'}).size + end + + # 资源数 + def sources_count + @school.courses.joins(:attachments).size + end + + # 视频总数 + def videos_count + @school.courses.joins(:course_videos).size + end + + # 制作实训数 + def shixun_count + @user_extensions.joins(user: :shixuns).size + end + + # 挑战实训总数 + def myshixuns_count + @user_extensions.joins("join myshixuns on myshixuns.user_id = user_extensions.user_id").size + end + + # 通过的实训总数 + def pass_myshixun_count + @user_extensions.joins("join myshixuns on myshixuns.user_id = user_extensions.user_id").where(myshixuns: {status: 1}).size + end + + # 挑战的关卡数 + def games_count + @user_extensions.joins("join games on games.user_id = user_extensions.user_id").where(games: {status: 0..2}) + end + + # 通关的关卡数 + def pass_games_count + @user_extensions.joins("join games on games.user_id = user_extensions.user_id").where(games: {status: 2}) + end + + # 评测总数 + def evalute_count + @user_extensions.joins("join games on games.user_id = user_extensions.user_id").sum(:evalute_count) + end + + +end \ No newline at end of file diff --git a/app/views/admins/shared/_sidebar.html.erb b/app/views/admins/shared/_sidebar.html.erb index 0033763bc..c7c487dcf 100644 --- a/app/views/admins/shared/_sidebar.html.erb +++ b/app/views/admins/shared/_sidebar.html.erb @@ -17,7 +17,7 @@
  • <%= sidebar_item_group('#school-submenu', '学校统计', icon: 'area-chart') do %>
  • <%= sidebar_item(admins_daily_school_statistics_path, '统计总表', icon: 'bar-chart', controller: 'admins-daily_school_statistics') %>
  • -
  • <%= sidebar_item(admins_school_statistics_path, '数据变化报表', icon: 'line-chart', controller: 'admins-school_statistics') %>
  • +
  • <%= sidebar_item(admins_school_statistics_path, '数据变化报表', icon: 'line-chart', controller: 'admins-schools') %>
  • <% end %> diff --git a/lib/tasks/school_statistic.rake b/lib/tasks/school_statistic.rake new file mode 100644 index 000000000..3d017ad17 --- /dev/null +++ b/lib/tasks/school_statistic.rake @@ -0,0 +1,8 @@ +#coding=utf-8 + +desc "同步高校数据" +namespace :school_statistic do + task sync_records: :environment do + + end +end diff --git a/public/assets/admin-4ed80c55f7e082a2bd6eda6648367fe17b709ff0d344c31b657ed68db6dccda0.css b/public/assets/admin-4ed80c55f7e082a2bd6eda6648367fe17b709ff0d344c31b657ed68db6dccda0.css index e2a6738de..2b54ed4e9 100644 --- a/public/assets/admin-4ed80c55f7e082a2bd6eda6648367fe17b709ff0d344c31b657ed68db6dccda0.css +++ b/public/assets/admin-4ed80c55f7e082a2bd6eda6648367fe17b709ff0d344c31b657ed68db6dccda0.css @@ -26248,23 +26248,23 @@ input.form-control { color: #6c757d; } -/* line 3, app/assets/stylesheets/admins/school_statistics.scss */ +/* line 3, app/assets/stylesheets/admins/schools.scss */ .admins-school-statistics-index-page .school-statistic-list-form .time-select { -webkit-box-flex: 1; flex: 1; } -/* line 8, app/assets/stylesheets/admins/school_statistics.scss */ +/* line 8, app/assets/stylesheets/admins/schools.scss */ .admins-school-statistics-index-page .school-statistic-list-form .type-box .btn { margin: 0 5px; } -/* line 11, app/assets/stylesheets/admins/school_statistics.scss */ +/* line 11, app/assets/stylesheets/admins/schools.scss */ .admins-school-statistics-index-page .school-statistic-list-form .search-input { width: 220px; } -/* line 15, app/assets/stylesheets/admins/school_statistics.scss */ +/* line 15, app/assets/stylesheets/admins/schools.scss */ .admins-school-statistics-index-page .school-statistic-list-form .contrast-date-container { display: -webkit-box; display: flex; @@ -26272,7 +26272,7 @@ input.form-control { align-items: center; } -/* line 22, app/assets/stylesheets/admins/school_statistics.scss */ +/* line 22, app/assets/stylesheets/admins/schools.scss */ .admins-school-statistics-index-page .school-statistic-list-container .contrast-column-select { position: absolute; right: 30px; @@ -26280,12 +26280,12 @@ input.form-control { width: 130px; } -/* line 29, app/assets/stylesheets/admins/school_statistics.scss */ +/* line 29, app/assets/stylesheets/admins/schools.scss */ .admins-school-statistics-index-page .school-statistic-list-container .relative { position: relative; } -/* line 33, app/assets/stylesheets/admins/school_statistics.scss */ +/* line 33, app/assets/stylesheets/admins/schools.scss */ .admins-school-statistics-index-page .school-statistic-list-container .right-border::after { position: absolute; top: 10px;