diff --git a/Procfile b/Procfile new file mode 100644 index 000000000..3fd9f6fd1 --- /dev/null +++ b/Procfile @@ -0,0 +1,2 @@ +web: cd client && npm start +api: bundle exec rails s -p 3001 diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index 7a19fb82c..7da7a177d 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -104,7 +104,7 @@ class HomeworkCommon < ApplicationRecord end def user_work user_id - work = self.student_works.find_by_user_id(user_id) || StudentWork.create!(homework_common_id: id, user_id: user_id) + work = StudentWork.find_by(homework_common_id: id, user_id: user_id) || StudentWork.create!(homework_common_id: id, user_id: user_id) end # 是否在补交阶段内 diff --git a/app/models/sta_all.rb b/app/models/sta_all.rb new file mode 100644 index 000000000..e9d64b368 --- /dev/null +++ b/app/models/sta_all.rb @@ -0,0 +1,20 @@ +class StaAll < ApplicationRecord + # t.integer :school_id 学校ID + # t.integer :tea_count 老师数 + # t.integer :stu_count 学生数 + # t.integer :active_users_count 活跃用户数(3个月内有登录) + # t.integer :courses_count 总课堂数 + # t.integer :curr_courses_count 正在进行的课堂数 + # t.integer :homw_shixuns_count 实训作业数 + # t.integer :homw_other_count 其它类型作业数 + # t.integer :sources_count 资源数 + # t.integer :videos_count 视频总个数 + # t.integer :shixuns_count 制作实训总数 + # t.integer :myshixuns_count 挑战实训总数 + # t.integer :mys_passed_count 通关的实训总数 + # t.integer :games_count 挑战的总关卡数 + # t.integer :games_passed_count 通关的总关卡数 + # t.integer :build_count 评测总数 + + belongs_to :school +end diff --git a/app/queries/weapps/subject_query.rb b/app/queries/weapps/subject_query.rb index b50c2a104..0a3c9beb2 100644 --- a/app/queries/weapps/subject_query.rb +++ b/app/queries/weapps/subject_query.rb @@ -19,6 +19,11 @@ class Weapps::SubjectQuery < ApplicationQuery subjects = subjects.joins(:sub_discipline_containers).where(sub_discipline_containers: {container_type: "Subject"}) end + # 搜索 + if params[:keyword].present? + subjects = subjects.where("subjects.name like '%#{params[:keyword]}%'") + end + subjects = subjects.left_joins(:shixuns, :repertoire).select('subjects.id, subjects.name, subjects.excellent, subjects.stages_count, subjects.status, subjects.homepage_show, subjects.shixuns_count, subjects.repertoire_id, subjects.updated_at, IFNULL(sum(shixuns.myshixuns_count), 0) myshixuns_count') .group('subjects.id').order("subjects.homepage_show #{sort_type}, #{order_type} #{sort_type}") 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/tasks/statistic_school_report_task.rb b/app/tasks/statistic_school_report_task.rb index a72c57830..3371ce527 100644 --- a/app/tasks/statistic_school_report_task.rb +++ b/app/tasks/statistic_school_report_task.rb @@ -1,20 +1,20 @@ class StatisticSchoolReportTask def call - School.find_each do |school| - evaluate_count = Game.joins(:challenge) - .joins('LEFT JOIN course_members ON course_members.user_id = games.user_id') - .joins('LEFT JOIN homework_commons_shixuns hcs ON hcs.shixun_id = challenges.shixun_id') - .joins('LEFT JOIN homework_commons hc ON hcs.homework_common_id = hc.id AND hc.homework_type = 4') - .joins('LEFT JOIN courses ON hc.course_id = courses.id AND course_members.course_id = courses.id') - .where(courses: { school_id: school.id }) - .sum(:evaluate_count) - - report = SchoolReport.find_or_initialize_by(school_id: school.id) - - report.school_name = school.name - report.shixun_evaluate_count = evaluate_count - - report.save - end + # School.find_each do |school| + # evaluate_count = Game.joins(:challenge) + # .joins('LEFT JOIN course_members ON course_members.user_id = games.user_id') + # .joins('LEFT JOIN homework_commons_shixuns hcs ON hcs.shixun_id = challenges.shixun_id') + # .joins('LEFT JOIN homework_commons hc ON hcs.homework_common_id = hc.id AND hc.homework_type = 4') + # .joins('LEFT JOIN courses ON hc.course_id = courses.id AND course_members.course_id = courses.id') + # .where(courses: { school_id: school.id }) + # .sum(:evaluate_count) + # + # report = SchoolReport.find_or_initialize_by(school_id: school.id) + # + # report.school_name = school.name + # report.shixun_evaluate_count = evaluate_count + # + # report.save + # end end end diff --git a/app/views/admins/daily_school_statistics/shared/_list.html.erb b/app/views/admins/daily_school_statistics/shared/_list.html.erb index 6982891ee..1ec80de21 100644 --- a/app/views/admins/daily_school_statistics/shared/_list.html.erb +++ b/app/views/admins/daily_school_statistics/shared/_list.html.erb @@ -11,7 +11,7 @@ <%= sort_tag(name: 'shixun_evaluate_count', path: admins_daily_school_statistics_path) do %> 实训评测总数 - + <% end %> <%= sort_tag('实训作业总数', name: 'homework_count', path: admins_daily_school_statistics_path) %> 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/db/migrate/20200305121450_create_sta_alls.rb b/db/migrate/20200305121450_create_sta_alls.rb new file mode 100644 index 000000000..663094400 --- /dev/null +++ b/db/migrate/20200305121450_create_sta_alls.rb @@ -0,0 +1,25 @@ +class CreateStaAlls < ActiveRecord::Migration[5.2] + def change + create_table :sta_alls do |t| + t.integer :school_id, default: 0 + t.integer :tea_count, default: 0 + t.integer :stu_count, default: 0 + t.integer :active_users_count, default: 0 + t.integer :courses_count, default: 0 + t.integer :curr_courses_count, default: 0 + t.integer :homw_shixuns_count, default: 0 + t.integer :homw_other_count, default: 0 + t.integer :sources_count, default: 0 + t.integer :videos_count, default: 0 + t.integer :shixuns_count, default: 0 + t.integer :myshixuns_count, default: 0 + t.integer :mys_passed_count, default: 0 + t.integer :games_count, default: 0 + t.integer :games_passed_count, default: 0 + t.integer :build_count, default: 0 + + + t.timestamps + end + end +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/lib/tasks/static_all.rake b/lib/tasks/static_all.rake new file mode 100644 index 000000000..4c878841e --- /dev/null +++ b/lib/tasks/static_all.rake @@ -0,0 +1,16 @@ +desc "统计每个学校使用数据" + +namespace :static_all do + task :repo => :environment do + School.find_each(batch_size: 100) do |school| + User.joins(:user_extension).where(school_id: school.id) + + + report = StaAll.find_or_initialize_by(school_id: school.id) + + report.shixun_evaluate_count = evaluate_count + + report.save + end + end +end \ No newline at end of file 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; diff --git a/spec/models/sta_all_spec.rb b/spec/models/sta_all_spec.rb new file mode 100644 index 000000000..b02d7e612 --- /dev/null +++ b/spec/models/sta_all_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe StaAll, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end