Merge branch 'dev_aliyun' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun

video_transcode
杨树林 5 years ago
commit 48d4364082

@ -95,13 +95,13 @@ class ApplicationController < ActionController::Base
check_account
tip_exception(@course.excellent ? 410 : 409, "您没有权限进入")
end
if @user_course_identity > Course::CREATOR && @user_course_identity <= Course::STUDENT && @course.tea_id != current_user.id
# 实名认证和职业认证的身份判断
tip_exception(411, "你的实名认证和职业认证审核未通过") if @course.authentication &&
@course.professional_certification && (!current_user.authentication && !current_user.professional_certification)
tip_exception(411, "你的实名认证审核未通过") if @course.authentication && !current_user.authentication
tip_exception(411, "你的职业认证审核未通过") if @course.professional_certification && !current_user.professional_certification
end
# if @user_course_identity > Course::CREATOR && @user_course_identity <= Course::STUDENT && @course.tea_id != current_user.id
# # 实名认证和职业认证的身份判断
# tip_exception(411, "你的实名认证和职业认证审核未通过") if @course.authentication &&
# @course.professional_certification && (!current_user.authentication && !current_user.professional_certification)
# tip_exception(411, "你的实名认证审核未通过") if @course.authentication && !current_user.authentication
# tip_exception(411, "你的职业认证审核未通过") if @course.professional_certification && !current_user.professional_certification
# end
uid_logger("###############user_course_identity:#{@user_course_identity}")
end

@ -153,8 +153,8 @@ class CoursesController < ApplicationController
begin
ActiveRecord::Base.transaction do
@course = Course.new(name: params[:name], class_period: params[:class_period], credit: params[:credit],
end_date: params[:end_date], is_public: params[:is_public], school_id: @school.id,
authentication: params[:authentication], professional_certification: params[:professional_certification])
end_date: params[:end_date], is_public: params[:is_public], school_id: @school.id)
# authentication: params[:authentication], professional_certification: params[:professional_certification])
@course.tea_id = current_user.id
if params[:subject_id].blank?
@ -219,8 +219,8 @@ class CoursesController < ApplicationController
extra_params[:is_end] = 1
end
extra_params[:authentication] = params[:authentication]
extra_params[:professional_certification] = params[:professional_certification]
# extra_params[:authentication] = params[:authentication]
# extra_params[:professional_certification] = params[:professional_certification]
if @course.subject
@course.start_date = params[:start_date]
@ -1157,10 +1157,10 @@ class CoursesController < ApplicationController
return normal_status(-1, "课堂已结束,无法加入") if course.is_end
# 实名认证和职业认证的身份判断
return normal_status(-2, "该课堂要求成员完成实名和职业认证") if course.authentication &&
course.professional_certification && (!current_user.authentication && !current_user.professional_certification)
return normal_status(-2, "该课堂要求成员完成实名认证") if course.authentication && !current_user.authentication
return normal_status(-2, "该课堂要求成员完成职业认证") if course.professional_certification && !current_user.professional_certification
# return normal_status(-2, "该课堂要求成员完成实名和职业认证") if course.authentication &&
# course.professional_certification && (!current_user.authentication && !current_user.professional_certification)
# return normal_status(-2, "该课堂要求成员完成实名认证") if course.authentication && !current_user.authentication
# return normal_status(-2, "该课堂要求成员完成职业认证") if course.professional_certification && !current_user.professional_certification
# 身份验证
if params[:professor].blank? && params[:assistant_professor].blank? && params[:student].blank?
@ -1452,6 +1452,7 @@ class CoursesController < ApplicationController
# Never trust parameters from the scary internet, only allow the white list through.
def course_params
params.require(:course).permit(:name, :class_period, :credit, :end_date, :is_public, :authentication, :professional_certification)
# params.require(:course).permit(:name, :class_period, :credit, :end_date, :is_public, :authentication, :professional_certification)
end
def validate_course_name

@ -2,7 +2,7 @@ class Schools::SchoolStatisticService < ApplicationService
attr_reader :school
def initialize(school)
@school = school.includes(:courses, user_extensions: :user)
@school = school
@user_extensions = school.user_extensions
end
@ -26,14 +26,14 @@ class Schools::SchoolStatisticService < ApplicationService
@user_extensions.map{|ue| ue.user.last_login_on&.between?(1.weeks.ago, Time.now)}.size
end
# 活跃用户(近3个月有登录)
# 活跃用户(近1个月有登录)
def acitve_user_1_months_count
@user_extensions.map{|ue| ue.user.last_login_on&.between?(1.months.ago, Time.now)}.size
@user_extensions.joins(:user).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
@user_extensions.map{|ue| ue.user&.last_login_on&.between?(3.months.ago, Time.now)}.size
end
# 活跃用户(进半年有登录记录)
@ -52,10 +52,15 @@ class Schools::SchoolStatisticService < ApplicationService
end
# 实训作业数目
def hom_shixuns_count
def homw_shixuns_count
@school.courses.joins(:homework_commons).where(homework_commons: {homework_type: 'practice'}).size
end
# 其他类型作业
def homw_other_count
@school.courses.joins(:homework_commons).where.not(homework_commons: {homework_type: 'practice'}).size
end
# 资源数
def sources_count
@school.courses.joins(:attachments).size
@ -67,7 +72,7 @@ class Schools::SchoolStatisticService < ApplicationService
end
# 制作实训数
def shixun_count
def shixuns_count
@user_extensions.joins(user: :shixuns).size
end
@ -83,17 +88,17 @@ class Schools::SchoolStatisticService < ApplicationService
# 挑战的关卡数
def games_count
@user_extensions.joins("join games on games.user_id = user_extensions.user_id").where(games: {status: 0..2})
@user_extensions.joins("join games on games.user_id = user_extensions.user_id").where(games: {status: 0..2}).size
end
# 通关的关卡数
def pass_games_count
@user_extensions.joins("join games on games.user_id = user_extensions.user_id").where(games: {status: 2})
@user_extensions.joins("join games on games.user_id = user_extensions.user_id").where(games: {status: 2}).size
end
# 评测总数
def evalute_count
@user_extensions.joins("join games on games.user_id = user_extensions.user_id").sum(:evalute_count)
def evaluate_count
@user_extensions.joins("join games on games.user_id = user_extensions.user_id").sum(:evaluate_count).to_i
end

@ -0,0 +1,5 @@
class AddIndexForStaAll < ActiveRecord::Migration[5.2]
def change
add_index :sta_alls, :school_id, :unique => true
end
end

@ -1,8 +0,0 @@
#coding=utf-8
desc "同步高校数据"
namespace :school_statistic do
task sync_records: :environment do
end
end

@ -2,15 +2,23 @@ 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
school_alls = School.includes(:courses, user_extensions: :user).all
school_alls.find_in_batches(batch_size: 50) do |schools|
Parallel.each(schools, in_processes: 5) do |school|
puts("school_id: #{school.id}")
data = Schools::SchoolStatisticService.new(school)
sta_all = StaAll.find_or_initialize_by(school_id: school.id)
attrs = {tea_count: data.teacher_count, stu_count: data.student_count, courses_count: data.courses_count,
active_users_count: data.acitve_user_3_months_count, curr_courses_count: data.curr_courses_count,
homw_shixuns_count: data.homw_shixuns_count, homw_other_count: data.homw_other_count,
sources_count: data.sources_count, videos_count: data.videos_count, shixuns_count: data.shixuns_count,
myshixuns_count: data.myshixuns_count, mys_passed_count: data.pass_myshixun_count,
games_count: data.games_count, games_passed_count: data.pass_games_count, build_count: data.evaluate_count}
puts "sta_all: #{attrs}"
sta_all.assign_attributes(attrs)
sta_all.save!
end
end
end
end
Loading…
Cancel
Save