Merge branch 'develop' into educoder

dev_library
daiao 6 years ago
commit d66cdb9f60

@ -34,7 +34,7 @@ module Mobile
version 'v1', using: :path version 'v1', using: :path
format :json format :json
content_type :json, "application/json;charset=UTF-8" content_type :json, "application/json;charset=UTF-8"
use ActionDispatch::Session::CookieStore use ActionDispatch::Session::CookieStore, :expire_after => 8.hours, :key => '_educoder_session', :domain => :all
require 'digest' require 'digest'
use Mobile::Middleware::ErrorHandler use Mobile::Middleware::ErrorHandler
@ -83,6 +83,9 @@ module Mobile
end end
def memo_authenticate! def memo_authenticate!
Rails.logger.info("#######current_user: ###{current_user}")
Rails.logger.info("#######session: ###{session[:user_id]}")
pass = (request.path.match(/memos\/\d+/).present? && !request.path.include?("reply")) || pass = (request.path.match(/memos\/\d+/).present? && !request.path.include?("reply")) ||
request.path.include?("get_memos_list") || request.path.include?("get_memos_list") ||
request.path.include?("memos?page=") || request.path.match(/memos$/).present? request.path.include?("memos?page=") || request.path.match(/memos$/).present?
@ -94,6 +97,8 @@ module Mobile
end end
def discusses_authenticate! def discusses_authenticate!
Rails.logger.info("#######current_user: ###{current_user}")
Rails.logger.info("#######session: ###{session[:user_id]}")
pass = request.path.match(/discusses$/).present? || request.path.include?("discusses?page=") pass = request.path.match(/discusses$/).present? || request.path.include?("discusses?page=")
unless pass unless pass
error!('401 Unauthorized', 401) unless current_user error!('401 Unauthorized', 401) unless current_user
@ -134,7 +139,9 @@ module Mobile
# #
Rails.logger.info("########### host is #{request.host}") Rails.logger.info("########### host is #{request.host}")
if (Rails.env.development? && session[:user_id].blank?) || (session[:user_id].blank? && request.host.include?("testbdweb")) || params[:action] == "privateGit" if (Rails.env.development? && session[:user_id].blank?) ||
(session[:user_id].blank? && request.host.include?("testbdweb")) ||
params[:action] == "privateGit"
session[:user_id] = 12 #116 session[:user_id] = 12 #116
end end

@ -79,6 +79,6 @@ class Managements::SchoolsController < Managements::BaseController
@shixun_homework_total = HomeworkCommon.where(homework_type: 4).count @shixun_homework_total = HomeworkCommon.where(homework_type: 4).count
@other_homework_total = HomeworkCommon.where(homework_type: [1, 3]).count @other_homework_total = HomeworkCommon.where(homework_type: [1, 3]).count
@shixun_total = Shixun.count @shixun_total = Shixun.count
@shixun_evaluate_total = Game.sum(:evaluate_count) @shixun_evaluate_total = SchoolReport.sum(:shixun_evaluate_count)
end end
end end

@ -26,6 +26,7 @@ class School < ActiveRecord::Base
# 报表信息 # 报表信息
has_many :school_daily_reports has_many :school_daily_reports
has_one :school_report
has_many :teacher_extensions, conditions: "identity = #{User::TEACHER}", class_name: 'UserExtensions' has_many :teacher_extensions, conditions: "identity = #{User::TEACHER}", class_name: 'UserExtensions'
has_many :student_extensions, conditions: "identity = #{User::STUDENT}", class_name: 'UserExtensions' has_many :student_extensions, conditions: "identity = #{User::STUDENT}", class_name: 'UserExtensions'

@ -0,0 +1,3 @@
class SchoolReport < ActiveRecord::Base
belongs_to :school
end

@ -533,7 +533,6 @@ class GamesService
# 更新评测次数 # 更新评测次数
game.update_column(:evaluate_count, (game.evaluate_count.to_i + 1)) game.update_column(:evaluate_count, (game.evaluate_count.to_i + 1))
shixun.increment!(:evaluate_count)
# 清空代码评测信息 # 清空代码评测信息
msg = game.run_code_message msg = game.run_code_message
msg.update_attributes(:status => 0, :message => nil) if msg.present? msg.update_attributes(:status => 0, :message => nil) if msg.present?

@ -15,21 +15,24 @@ class Management::SchoolDataGrowService
end end
def call def call
reports = query_reports.group('schools.id') reports = School.where(nil)
count = reports.count.count reports = search_filter(reports)
count = reports.count
reports = reports.joins("LEFT JOIN (#{joins_school_daily_report_sql}) sdr ON sdr.school_id = schools.id")
reports = reports.select( reports = reports.select(
'schools.id school_id, schools.name school_name,'\ 'schools.id school_id, schools.name school_name,'\
'SUM(teacher_increase_count) teacher_increase_count,'\ 'sdr.teacher_increase_count,'\
'SUM(student_increase_count) student_increase_count,'\ 'sdr.student_increase_count,'\
'SUM(course_increase_count) course_increase_count,'\ 'sdr.course_increase_count,'\
'SUM(shixun_increase_count) shixun_increase_count,'\ 'sdr.shixun_increase_count,'\
'SUM(shixun_homework_count) shixun_homework_count,'\ 'sdr.shixun_homework_count,'\
'SUM(shixun_evaluate_count) shixun_evaluate_count,'\ 'sdr.shixun_evaluate_count,'\
'COUNT(distinct(au.user_id)) uniq_active_user_count,'\ 'sdr.uniq_active_user_count,'\
'SUM(active_user_count) active_user_count' 'sdr.active_user_count'
) ).group('schools.id')
reports = custom_sort(reports, params[:sort_by], params[:sort_direction]) reports = custom_sort(reports, params[:sort_by], params[:sort_direction])
reports = reports.order('school_id asc').limit(PAGE_SIZE).offset(offset) reports = reports.order('school_id asc').limit(PAGE_SIZE).offset(offset)
@ -39,37 +42,54 @@ class Management::SchoolDataGrowService
def grow_summary def grow_summary
@_grow_summary ||= begin @_grow_summary ||= begin
query_reports.select( reports = School.joins("LEFT JOIN school_daily_reports sdr ON sdr.school_id = schools.id AND #{date_condition_sql}")
.joins('LEFT JOIN school_daily_active_users au ON au.school_daily_report_id = sdr.id')
reports = search_filter(reports)
reports.select(
'SUM(teacher_increase_count) teacher_increase_count,'\ 'SUM(teacher_increase_count) teacher_increase_count,'\
'SUM(student_increase_count) student_increase_count,'\ 'SUM(student_increase_count) student_increase_count,'\
'SUM(course_increase_count) course_increase_count,'\ 'SUM(course_increase_count) course_increase_count,'\
'SUM(shixun_increase_count) shixun_increase_count,'\ 'SUM(shixun_increase_count) shixun_increase_count,'\
'SUM(shixun_homework_count) shixun_homework_count,'\ 'SUM(shixun_homework_count) shixun_homework_count,'\
'SUM(shixun_evaluate_count) shixun_evaluate_count,'\ 'SUM(shixun_evaluate_count) shixun_evaluate_count,'\
'COUNT(distinct(au.user_id)) uniq_active_user_count,'\ 'COUNT(distinct au.user_id) uniq_active_user_count,'\
'SUM(active_user_count) active_user_count' 'SUM(active_user_count) active_user_count'
).first ).first
end end
end end
private private
def query_reports
date = query_date
date_condition = if date.is_a?(Range)
"sdr.date BETWEEN '#{date.min.strftime('%Y-%m-%d')}' AND '#{date.max.strftime('%Y-%m-%d')}'"
else
"sdr.date = '#{date.strftime('%Y-%m-%d')}'"
end
reports = School.joins("LEFT JOIN school_daily_reports sdr ON sdr.school_id = schools.id AND #{date_condition}")
reports = reports.joins("LEFT JOIN school_daily_active_users au ON au.school_daily_report_id = sdr.id")
def search_filter(relations)
keyword = params[:keyword].try(:to_s).try(:strip) keyword = params[:keyword].try(:to_s).try(:strip)
if keyword.present? if keyword.present?
reports = reports.where("schools.name LIKE :keyword OR schools.id LIKE :keyword", keyword: "%#{keyword}%") relations = relations.where("schools.name LIKE :keyword OR schools.id LIKE :keyword", keyword: "%#{keyword}%")
end end
reports relations
end
def joins_school_daily_report_sql
SchoolDailyReport.joins('LEFT JOIN school_daily_active_users au ON au.school_daily_report_id = school_daily_reports.id')
.select('school_id, '\
'SUM(distinct teacher_increase_count) teacher_increase_count,'\
'SUM(distinct student_increase_count) student_increase_count,'\
'SUM(distinct course_increase_count) course_increase_count,'\
'SUM(distinct shixun_increase_count) shixun_increase_count,'\
'SUM(distinct shixun_homework_count) shixun_homework_count,'\
'SUM(distinct shixun_evaluate_count) shixun_evaluate_count,'\
'COUNT(distinct au.user_id) uniq_active_user_count,'\
'SUM(distinct active_user_count) active_user_count')
.where(date_condition_sql).group(:school_id).to_sql
end
def date_condition_sql
date = query_date
if date.is_a?(Range)
"date BETWEEN '#{date.min.strftime('%Y-%m-%d')}' AND '#{date.max.strftime('%Y-%m-%d')}'"
else
"date = '#{date.strftime('%Y-%m-%d')}'"
end
end end
def query_date def query_date

@ -3,9 +3,8 @@ class Management::SchoolReportService
attr_reader :params attr_reader :params
# 因为实在太慢了,所以不开放 shixun_evaluate_count 排序
sort_columns :student_count, :teacher_count, :homework_count, :other_homework_count, sort_columns :student_count, :teacher_count, :homework_count, :other_homework_count,
:course_count, :active_course_count, :nearly_course_time, :shixun_count, :course_count, :active_course_count, :nearly_course_time, :shixun_count, :shixun_evaluate_count,
default_by: :teacher_count, default_direction: :desc default_by: :teacher_count, default_direction: :desc
def initialize(params) def initialize(params)
@ -49,10 +48,10 @@ class Management::SchoolReportService
active_course_map = courses.where(is_end: false).count active_course_map = courses.where(is_end: false).count
shixun_map = Shixun.joins(creator: :user_extensions).where(user_extensions: { identity: User::TEACHER, school_id: ids }) shixun_map = Shixun.joins(creator: :user_extensions).where(user_extensions: { identity: User::TEACHER, school_id: ids })
.group('school_id').count .where(fork_from: nil).group('school_id').count
evaluate_count_map = Game.joins(challenge: { shixun: { creator: :user_extensions } })
.where(user_extensions: { identity: User::TEACHER, school_id: ids }) reports = SchoolReport.where(school_id: ids)
.group('school_id').sum(:evaluate_count) evaluate_count_map = reports.each_with_object({}) { |report, obj| obj[report.school_id] = report.shixun_evaluate_count }
schools.map do |school| schools.map do |school|
{ {
@ -88,13 +87,10 @@ class Management::SchoolReportService
schools.joins('LEFT JOIN courses cs ON cs.school_id = schools.id AND cs.is_delete = 0') schools.joins('LEFT JOIN courses cs ON cs.school_id = schools.id AND cs.is_delete = 0')
.select("#{base_query_column}, COUNT(*) course_count") .select("#{base_query_column}, COUNT(*) course_count")
when 'shixun_count' then when 'shixun_count' then
schools.joins(teacher_extensions: :user).joins('INNER JOIN shixuns sx ON sx.user_id = users.id') schools.joins(teacher_extensions: :user).joins('INNER JOIN shixuns sx ON sx.user_id = users.id AND sx.fork_from IS NULL')
.select("#{base_query_column}, COUNT(*) shixun_count") .select("#{base_query_column}, COUNT(*) shixun_count")
when 'shixun_evaluate_count' then when 'shixun_evaluate_count' then
schools.joins(teacher_extensions: :user).joins('INNER JOIN shixuns sx ON sx.user_id = users.id') schools.joins(:school_report).select("#{base_query_column}, shixun_evaluate_count")
.joins('LEFT JOIN challenges cs ON cs.shixun_id = sx.id')
.joins('LEFT JOIN games ON games.challenge_id = cs.id')
.select("#{base_query_column}, SUM(games.evaluate_count) shixun_evaluate_count")
when 'nearly_course_time' then when 'nearly_course_time' then
schools.joins('LEFT JOIN courses cs ON cs.school_id = schools.id AND cs.is_delete = 0') schools.joins('LEFT JOIN courses cs ON cs.school_id = schools.id AND cs.is_delete = 0')
.joins('LEFT JOIN course_activities acs ON acs.course_id = cs.id') .joins('LEFT JOIN course_activities acs ON acs.course_id = cs.id')

@ -25,8 +25,12 @@ class StatisticSchoolDailyReportTask
.where(homework_type: 4, created_at: yesterday).count .where(homework_type: 4, created_at: yesterday).count
# 新增实训评测数量 # 新增实训评测数量
shixun_evaluate_count = Output.joins(game: { challenge: { shixun: { creator: :user_extensions } } }) shixun_evaluate_count = Output.joins(game: :challenge)
.where(user_extensions: { identity: User::TEACHER, school_id: school.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 members ON members.user_id = games.user_id')
.joins('LEFT JOIN courses ON members.course_id = courses.id AND hc.course_id = courses.id')
.where(courses: { school_id: school.id })
.where(created_at: yesterday).count .where(created_at: yesterday).count
# 无有效数据时不记录 # 无有效数据时不记录

@ -0,0 +1,20 @@
class StatisticSchoolReportTask
def call
School.find_each do |school|
evaluate_count = Game.joins(:challenge)
.joins('LEFT JOIN members ON 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 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

@ -24,7 +24,8 @@
<%= javascript_include_tag '/editormd/lib/marked.min.js', '/editormd/lib/prettify.min.js', '/editormd/lib/raphael.min.js', '/editormd/lib/underscore.min.js', '/editormd/lib/sequence-diagram.min.js', <%= javascript_include_tag '/editormd/lib/marked.min.js', '/editormd/lib/prettify.min.js', '/editormd/lib/raphael.min.js', '/editormd/lib/underscore.min.js', '/editormd/lib/sequence-diagram.min.js',
'/editormd/lib/flowchart.min.js', '/editormd/lib/jquery.flowchart.min.js', '/editormd/editormd.js' %> '/editormd/lib/flowchart.min.js', '/editormd/lib/jquery.flowchart.min.js', '/editormd/editormd.js' %>
<%= yield :header_tags -%> <%= yield :header_tags -%>
<% Rails.logger.info("########----current_user: #{User.current.id}") %>
<% Rails.logger.info("########----session: #{session[:user_id]}") %>
<script type="text/javascript" <script type="text/javascript"
src="/javascripts/MathJax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"> src="/javascripts/MathJax/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script> </script>

@ -3,15 +3,17 @@
<tr> <tr>
<th width="6%">序号</th> <th width="6%">序号</th>
<th width="6%">ID</th> <th width="6%">ID</th>
<th width="14%" class="edu-txt-left">单位名称</th> <th width="12%" class="edu-txt-left">单位名称</th>
<th width="10%"><%= sort_tag('教师总人数', name: 'teacher_count', path: school_report_managements_path) %></th> <th width="10%"><%= sort_tag('教师总人数', name: 'teacher_count', path: school_report_managements_path) %></th>
<th width="10%"><%= sort_tag('学生总人数', name: 'student_count', path: school_report_managements_path) %></th> <th width="10%"><%= sort_tag('学生总人数', name: 'student_count', path: school_report_managements_path) %></th>
<th width="10%"><%= sort_tag('课堂总数', name: 'course_count', path: school_report_managements_path) %></th> <th width="10%"><%= sort_tag('课堂总数', name: 'course_count', path: school_report_managements_path) %></th>
<th width="10%"><%= sort_tag('正在进行课堂数', name: 'active_course_count', path: school_report_managements_path) %></th> <th width="10%"><%= sort_tag('正在进行课堂数', name: 'active_course_count', path: school_report_managements_path) %></th>
<th width="10%"><%= sort_tag('实训总数', name: 'shixun_count', path: school_report_managements_path) %></th> <th width="10%"><%= sort_tag('实训总数', name: 'shixun_count', path: school_report_managements_path) %></th>
<!-- <th width="10%"><%#= sort_tag('实训评测总数', name: 'shixun_evaluate_count', path: school_report_managements_path) %></th>--> <th width="12%">
<th width="10%">实训评测总数</th> <%= sort_tag('实训评测总数', name: 'shixun_evaluate_count', path: school_report_managements_path) %>
<i class="fa fa-question-circle" data-tip-down="数据更新时间为<br/>当日6点、12点、18点、24点"></i>
</th>
<th width="10%"><%= sort_tag('实训作业总数', name: 'homework_count', path: school_report_managements_path) %></th> <th width="10%"><%= sort_tag('实训作业总数', name: 'homework_count', path: school_report_managements_path) %></th>
<th width="10%"><%= sort_tag('其它作业总数', name: 'other_homework_count', path: school_report_managements_path) %></th> <th width="10%"><%= sort_tag('其它作业总数', name: 'other_homework_count', path: school_report_managements_path) %></th>
<th width="14%"><%= sort_tag('动态时间', name: 'nearly_course_time', path: school_report_managements_path) %></th> <th width="14%"><%= sort_tag('动态时间', name: 'nearly_course_time', path: school_report_managements_path) %></th>

@ -24,7 +24,7 @@
实训总数<span class="color-red"><%= @shixun_total %></span>个, 实训总数<span class="color-red"><%= @shixun_total %></span>个,
实训评测总数<span class="color-red"><%= @shixun_evaluate_total %></span>个, 实训评测总数<span class="color-red"><%= @shixun_evaluate_total %></span>个,
实训作业总数<span class="color-red"><%= @shixun_homework_total %></span>个, 实训作业总数<span class="color-red"><%= @shixun_homework_total %></span>个,
其它作业总数<span class="color-red"><%= @other_homework_total %></span>个 其它作业总数<span class="color-red"><%= @other_homework_total %></span>个
</div> </div>
</div> </div>

@ -1,11 +1,12 @@
wb = xlsx_package.workbook wb = xlsx_package.workbook
wb.add_worksheet(name: '统计总表') do |sheet| wb.add_worksheet(name: '统计总表') do |sheet|
sheet.add_row %w(ID 单位名称 教师总人数 学生总人数 课堂总数 正在进行课堂数 实训作业总数 其它作业总数 动态时间) sheet.add_row %w(ID 单位名称 教师总人数 学生总人数 课堂总数 正在进行课堂数 总实训数 实训评测总数 实训作业总数 其它作业总数 动态时间)
@schools.each do |school| @schools.each do |school|
sheet.add_row([ sheet.add_row([
school[:id].to_s, school[:name].to_s, (school[:teacher_count] || 0).to_s, (school[:student_count] || 0).to_s, school[:id].to_s, school[:name].to_s, (school[:teacher_count] || 0).to_s, (school[:student_count] || 0).to_s,
(school[:course_count] || 0).to_s, (school[:active_course_count] || 0).to_s, (school[:homework_count] || 0).to_s, (school[:course_count] || 0).to_s, (school[:active_course_count] || 0).to_s,
(school[:shixun_count] || 0).to_s,(school[:shixun_evaluate_count] || 0).to_s, (school[:homework_count] || 0).to_s,
(school[:other_homework_count] || 0).to_s, format_time(school[:nearly_course_time]) (school[:other_homework_count] || 0).to_s, format_time(school[:nearly_course_time])
]) ])
end end

@ -21,11 +21,11 @@
<span class="user_filtrate_span1">粉丝</span> <span class="user_filtrate_span1">粉丝</span>
<span class="user_filtrate_span2 ml10"><%= @user_fanlist_count %></span> <span class="user_filtrate_span2 ml10"><%= @user_fanlist_count %></span>
</a> </a>
<a href="<%= growth_record_user_path(@user, :tab => 3) %>" class="user_course_filtrate fl mt20 mr30 font-14" target="_blank"> <a href="<%= user_grade_user_path(@user) %>" class="user_course_filtrate fl mt20 mr30 font-14" target="_blank">
<span class="user_filtrate_span1">金币</span> <span class="user_filtrate_span1">金币</span>
<span class="user_filtrate_span2 ml10"><%= @user.grade %></span> <span class="user_filtrate_span2 ml10"><%= @user.grade %></span>
</a> </a>
<a href="<%= growth_record_user_path(@user, :tab => 2) %>" class="user_course_filtrate fl mt20 mr30 font-14" target="_blank"> <a href="<%= user_experience_user_path(@user) %>" class="user_course_filtrate fl mt20 mr30 font-14" target="_blank">
<span class="user_filtrate_span1">经验值</span> <span class="user_filtrate_span1">经验值</span>
<span class="user_filtrate_span2 ml10"><%= @user.experience %></span> <span class="user_filtrate_span2 ml10"><%= @user.experience %></span>
</a> </a>

@ -0,0 +1,14 @@
class CreateSchoolReports < ActiveRecord::Migration
def change
create_table :school_reports do |t|
t.integer :school_id
t.string :school_name
t.integer :shixun_evaluate_count
t.timestamps
end
add_index :school_reports, :school_id
add_index :school_reports, :shixun_evaluate_count
end
end

@ -0,0 +1,8 @@
#coding=utf-8
namespace :school_report do
desc 'statistic school report task'
task statistic: :environment do
StatisticSchoolReportTask.new.call
end
end

@ -183,11 +183,12 @@ namespace :school_daily_report do
) shixun_homework_count, ( ) shixun_homework_count, (
SELECT COUNT(*) FROM outputs os SELECT COUNT(*) FROM outputs os
LEFT JOIN games gs ON os.game_id = gs.id LEFT JOIN games gs ON os.game_id = gs.id
LEFT JOIN members ON members.user_id = gs.user_id
LEFT JOIN challenges cls ON gs.challenge_id = cls.id LEFT JOIN challenges cls ON gs.challenge_id = cls.id
LEFT JOIN shixuns sx ON cls.shixun_id = sx.id LEFT JOIN homework_commons_shixuns hcs ON hcs.shixun_id = cls.shixun_id
LEFT JOIN users u ON sx.user_id = u.id LEFT JOIN homework_commons hc ON hcs.homework_common_id = hc.id
INNER JOIN user_extensions ue ON ue.user_id = u.id LEFT JOIN courses ON hc.course_id = courses.id AND members.course_id = courses.id
WHERE ue.school_id = schools.id AND ue.identity = #{User::TEACHER} AND os.created_at BETWEEN "#{begin_date}" AND "#{end_date}" WHERE courses.school_id = schools.id AND os.created_at BETWEEN "#{begin_date}" AND "#{end_date}"
) shixun_evaluate_count, ( ) shixun_evaluate_count, (
SELECT COUNT(*) FROM users u SELECT COUNT(*) FROM users u
LEFT JOIN user_extensions ue ON ue.user_id = u.id LEFT JOIN user_extensions ue ON ue.user_id = u.id

Loading…
Cancel
Save