From 6ec1b6006894eda1d8e197c10b3681ed6c48f2fc Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 6 Mar 2020 00:25:51 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E8=BA=AB=E4=BB=BD=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/homework_common.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index 7a19fb82c..2b8a2e118 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 = self.student_works.find_by_user_id(user_id) # || StudentWork.create!(homework_common_id: id, user_id: user_id) end # 是否在补交阶段内 From 65efa585d8c4d521685b5227b35ca42481df9a21 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 6 Mar 2020 00:34:36 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E5=A4=A7=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Procfile | 2 ++ app/models/sta_all.rb | 20 +++++++++++++++ .../shared/_list.html.erb | 2 +- db/migrate/20200305121450_create_sta_alls.rb | 25 +++++++++++++++++++ lib/tasks/static_all.rake | 16 ++++++++++++ spec/models/sta_all_spec.rb | 5 ++++ 6 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 Procfile create mode 100644 app/models/sta_all.rb create mode 100644 db/migrate/20200305121450_create_sta_alls.rb create mode 100644 lib/tasks/static_all.rake create mode 100644 spec/models/sta_all_spec.rb 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/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/views/admins/daily_school_statistics/shared/_list.html.erb b/app/views/admins/daily_school_statistics/shared/_list.html.erb index 6982891ee..2463b45ad 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/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/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/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 From 43e9023904a343c87fcec2cf430fb4dde2f4b433 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 6 Mar 2020 00:35:16 +0800 Subject: [PATCH 3/8] .. --- app/views/admins/daily_school_statistics/shared/_list.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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..bee7505b0 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) %> From 4c12456fc3ce638c53974ec71c7b0cb105130c94 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 6 Mar 2020 00:36:11 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/admins/daily_school_statistics/shared/_list.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 bee7505b0..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) %> From 6a90d611c2d7fc8ccd5b32cba39d18fe3fe8384a Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 6 Mar 2020 09:42:38 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E6=90=9C=E7=B4=A2=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/queries/weapps/subject_query.rb | 5 +++++ 1 file changed, 5 insertions(+) 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}") From 52aad5dcbfac54bf404d0de393cb628b9d9b14ce Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 6 Mar 2020 11:12:31 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E5=88=87=E6=8D=A2=E8=BA=AB=E4=BB=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/homework_common.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index 2b8a2e118..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 # 是否在补交阶段内 From 294aca277104650aacb74216cce4291e4e043184 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 6 Mar 2020 12:00:11 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/tasks/statistic_school_report_task.rb | 32 +++++++++++------------ 1 file changed, 16 insertions(+), 16 deletions(-) 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 From 1a0f966ce84425e132604f68fbe4004de35d43b4 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 6 Mar 2020 12:31:01 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../schools/school_statistic_service.rb | 100 ++++++++++++++++++ app/views/admins/shared/_sidebar.html.erb | 2 +- lib/tasks/school_statistic.rake | 8 ++ ...367fe17b709ff0d344c31b657ed68db6dccda0.css | 14 +-- 4 files changed, 116 insertions(+), 8 deletions(-) create mode 100644 app/services/schools/school_statistic_service.rb create mode 100644 lib/tasks/school_statistic.rake 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;