Merge branch 'dev_aliyun' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_item_bank
commit
d17578c4d1
@ -1,3 +1,6 @@
|
||||
class ChallengeQuestion < ApplicationRecord
|
||||
belongs_to :challenge_choose
|
||||
|
||||
validates :option_name, length: { maximum: 500 }
|
||||
|
||||
end
|
||||
|
@ -1,4 +1,5 @@
|
||||
class MessageDetail < ApplicationRecord
|
||||
belongs_to :message, :touch => true
|
||||
validates :content, length: { maximum: 5000 }
|
||||
|
||||
end
|
||||
|
@ -0,0 +1,3 @@
|
||||
class SubjectCourseRecord < ApplicationRecord
|
||||
belongs_to :subject
|
||||
end
|
@ -0,0 +1,3 @@
|
||||
class SubjectRecord < ApplicationRecord
|
||||
belongs_to :subject
|
||||
end
|
@ -0,0 +1,3 @@
|
||||
class SubjectShixunInfo < ApplicationRecord
|
||||
belongs_to :subject
|
||||
end
|
@ -0,0 +1,3 @@
|
||||
class SubjectUserInfo < ApplicationRecord
|
||||
belongs_to :subject
|
||||
end
|
@ -0,0 +1,30 @@
|
||||
class Subjects::ShixunUsedInfoService < ApplicationService
|
||||
attr_reader :subject, :stages
|
||||
def initialize(subject)
|
||||
@subject = subject
|
||||
@stages = subject.stages.includes(shixuns: [myshixuns: :games, homework_commons_shixuns: [homework_common: :course]])
|
||||
end
|
||||
|
||||
def call
|
||||
shixun_infos = []
|
||||
stages.each do |stage|
|
||||
position = stage.position
|
||||
stage.shixuns.each_with_index do |shixun, index|
|
||||
stage = "#{position}-#{index+1}"
|
||||
name = shixun.name
|
||||
challenge_count = shixun.challenges_count
|
||||
course_count = shixun.homework_commons.map{|hc| hc.course_id}.uniq.size
|
||||
school_count = shixun.homework_commons.map{|hc| hc.course&.school_id}.uniq.size
|
||||
used_count = shixun.myshixuns_count
|
||||
passed_count = shixun.myshixuns.select{|m| m.status == 1}.size
|
||||
evaluate_count = shixun.myshixuns.map{|m| m.output_times }.sum
|
||||
passed_ave_time = passed_count > 0 ? shixun.myshixuns.map{|m| m.total_cost_time}.sum : 0
|
||||
shixun_infos << {stage: stage, name: name, challenge_count: challenge_count, course_count: course_count,
|
||||
school_count: school_count, used_count: used_count, passed_count: passed_count,
|
||||
evaluate_count: evaluate_count, passed_ave_time: passed_ave_time, shixun_id: shixun.id}
|
||||
end
|
||||
end
|
||||
shixun_infos
|
||||
end
|
||||
|
||||
end
|
@ -0,0 +1,28 @@
|
||||
class Subjects::UserUsedInfoService < ApplicationService
|
||||
attr_reader :subject, :shixun_ids
|
||||
|
||||
def initialize(subject)
|
||||
@subject = subject
|
||||
@shixun_ids = subject.shixuns.pluck(:id)
|
||||
|
||||
end
|
||||
|
||||
def call
|
||||
users_info = []
|
||||
users = User.includes(myshixuns: :games).where(myshixuns: {shixun_id: shixun_ids}, games: {status: 2})
|
||||
users.each do |user|
|
||||
myshixuns = user.myshixuns.select{|m| shixun_ids.include?(m.shixun_id)}
|
||||
name = "#{user.lastname}#{user.firstname}"
|
||||
passed_myshixun_count = myshixuns.select{|m| m.status == 1}.size
|
||||
passed_games_count = myshixuns.map{|m| m.games.select{|g| g.status == 2}.size }.size
|
||||
code_line_count = 0
|
||||
evaluate_count = myshixuns.map{|m| m.output_times }.sum
|
||||
cost_time = myshixuns.map{|m|m.total_cost_time }.sum
|
||||
users_info << {user_id: user.id, name: name, passed_myshixun_count: passed_myshixun_count,
|
||||
passed_games_count: passed_games_count, code_line_count: code_line_count,
|
||||
evaluate_count: evaluate_count, cost_time: cost_time}
|
||||
end
|
||||
users_info
|
||||
end
|
||||
|
||||
end
|
@ -1,6 +1,6 @@
|
||||
json.(@bank, :id, :name, :description, :is_public, :topic_type, :topic_source, :topic_property_first, :topic_property_second,
|
||||
:source_unit, :topic_repeat, :province, :city)
|
||||
json.authorize @bank.user_id == current_user.id || current_user.admin?
|
||||
json.authorize @bank.user_id == current_user.id || current_user.admin_or_business?
|
||||
|
||||
json.attachment_list @bank_attachments do |attachment|
|
||||
json.partial! "attachments/attachment_simple", locals: {attachment: attachment}
|
||||
|
@ -0,0 +1,14 @@
|
||||
class CreateSubjectRecords < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :subject_records do |t|
|
||||
t.references :subject, unique: true
|
||||
t.integer :study_count, default: 0
|
||||
t.integer :course_study_count, default: 0
|
||||
t.integer :initiative_study, default: 0
|
||||
t.integer :passed_count, default: 0
|
||||
t.integer :course_used_count, default: 0
|
||||
t.integer :school_used_count, default: 0
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,16 @@
|
||||
class CreateSubjectCourseRecords < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :subject_course_records do |t|
|
||||
t.references :subject
|
||||
t.references :school
|
||||
t.string :school_name
|
||||
t.integer :course_count, default: 0
|
||||
t.integer :student_count, default: 0
|
||||
t.integer :choice_shixun_num, default: 0
|
||||
t.integer :choice_shixun_frequency, default: 0
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :subject_course_records, [:school_id, :subject_id], unique: true, name: "couse_and_school_index"
|
||||
end
|
||||
end
|
@ -0,0 +1,21 @@
|
||||
class CreateSubjectShixunInfos < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :subject_shixun_infos do |t|
|
||||
t.references :subject
|
||||
t.references :shixun
|
||||
t.string :stage
|
||||
t.string :shixun_name
|
||||
t.integer :challenge_count, default: 0
|
||||
t.integer :course_count, default: 0
|
||||
t.integer :school_count, default: 0
|
||||
t.integer :used_count, default: 0
|
||||
t.integer :passed_count, default: 0
|
||||
t.integer :evaluate_count, default: 0
|
||||
t.integer :passed_ave_time, default: 0
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :subject_shixun_infos, [:shixun_id, :subject_id], unique: true
|
||||
end
|
||||
end
|
@ -0,0 +1,18 @@
|
||||
class CreateSubjectUserInfos < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :subject_user_infos do |t|
|
||||
t.references :user
|
||||
t.references :subject
|
||||
t.string :username
|
||||
t.integer :passed_myshixun_count, default: 0
|
||||
t.integer :passed_games_count, default: 0
|
||||
t.integer :code_line_count, default: 0
|
||||
t.integer :evaluate_count, default: 0
|
||||
t.integer :cost_time, default: 0
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :subject_user_infos, [:user_id, :subject_id], unique: true
|
||||
|
||||
end
|
||||
end
|
@ -0,0 +1,11 @@
|
||||
class AddUniqIndexToEvaluationDistribution < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
sql = %Q(delete from student_works_evaluation_distributions where (user_id, student_work_id) in
|
||||
(select * from (select user_id, student_work_id from student_works_evaluation_distributions group by user_id, student_work_id having count(*) > 1) a)
|
||||
and id not in (select * from (select min(id) from student_works_evaluation_distributions group by user_id, student_work_id having count(*) > 1 order by id) b))
|
||||
ActiveRecord::Base.connection.execute sql
|
||||
|
||||
add_index :student_works_evaluation_distributions, [:student_work_id, :user_id], name: "index_on_student_work_id_and_user_id", unique: true
|
||||
remove_index :student_works_evaluation_distributions, :user_id
|
||||
end
|
||||
end
|
@ -0,0 +1,5 @@
|
||||
class ModifyMyshixunIdForStudentWorks < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
StudentWork.where(myshixun_id: nil).update_all(myshixun_id: 0)
|
||||
end
|
||||
end
|
@ -0,0 +1,111 @@
|
||||
desc "统计实践课程的学习统计数据"
|
||||
|
||||
namespace :subjects do
|
||||
task data_statistic: :environment do
|
||||
puts("---------------------data_statistic_begin")
|
||||
Rails.logger.info("---------------------data_statistic_begin")
|
||||
subjects = Subject.where(status: 2)
|
||||
subjects.find_each do |subject|
|
||||
puts("---------------------data_statistic: #{subject.id}")
|
||||
Rails.logger.info("---------------------data_statistic: #{subject.id}")
|
||||
sr = SubjectRecord.find_or_create_by!(subject_id: subject.id)
|
||||
data = Subjects::DataStatisticService.new(subject)
|
||||
study_count = data.study_count
|
||||
# 总人数没有变化的话,不同课堂之类的变化了
|
||||
course_study_count = (study_count == sr.study_count ? sr.course_study_count : data.course_study_count)
|
||||
passed_count = (study_count == sr.study_count ? sr.passed_count : data.passed_count)
|
||||
course_used_count = (study_count == sr.study_count ? sr.course_used_count : data.course_used_count)
|
||||
school_used_count = (study_count == sr.study_count ? sr.school_used_count : data.school_used_count)
|
||||
update_params = {
|
||||
study_count: study_count,
|
||||
course_study_count: course_study_count,
|
||||
initiative_study: (study_count - course_study_count),
|
||||
passed_count: passed_count,
|
||||
course_used_count: course_used_count,
|
||||
school_used_count: school_used_count
|
||||
}
|
||||
sr.update_attributes!(update_params)
|
||||
end
|
||||
puts("---------------------data_statistic_end")
|
||||
Rails.logger.info("---------------------data_statistic_end")
|
||||
end
|
||||
|
||||
task course_info_statistic: :environment do
|
||||
puts("---------------------course_info_statistic_begin")
|
||||
Rails.logger.info("---------------------course_info_statistic_begin")
|
||||
subjects = Subject.where(status: 2)
|
||||
subjects.find_each do |subject|
|
||||
puts("---------------------course_info_statistic: #{subject.id}")
|
||||
Rails.logger.info("---------------------course_info_statistic: #{subject.id}")
|
||||
data = Subjects::CourseUsedInfoService.call(subject)
|
||||
data.each do |key|
|
||||
scr = SubjectCourseRecord.find_or_create_by!(school_id: key[:school_id], subject_id: subject.id)
|
||||
update_params = {
|
||||
school_name: key[:school_name],
|
||||
course_count: key[:course_count],
|
||||
student_count: key[:student_count],
|
||||
choice_shixun_num: key[:choice_shixun_num],
|
||||
choice_shixun_frequency: key[:choice_shixun_frequency]
|
||||
}
|
||||
scr.update_attributes(update_params)
|
||||
end
|
||||
end
|
||||
puts("---------------------course_info_statistic_end")
|
||||
Rails.logger.info("---------------------course_info_statistic_end")
|
||||
end
|
||||
|
||||
task shixun_info_statistic: :environment do
|
||||
puts("---------------------shixun_info_statistic_begin")
|
||||
Rails.logger.info("---------------------shixun_info_statistic_begin")
|
||||
subjects = Subject.where(status: 2)
|
||||
subjects.find_each(batch_size: 100) do |subject|
|
||||
puts("---------------------shixun_info_statistic: #{subject.id}")
|
||||
Rails.logger.info("---------------------shixun_info_statistic: #{subject.id}")
|
||||
data = Subjects::ShixunUsedInfoService.call(subject)
|
||||
data.each do |key|
|
||||
ssi = SubjectShixunInfo.find_or_create_by!(shixun_id: key[:shixun_id], subject_id: subject.id)
|
||||
update_params = {
|
||||
stage: key[:stage],
|
||||
shixun_name: key[:name],
|
||||
challenge_count: key[:challenge_count],
|
||||
course_count: key[:course_count],
|
||||
school_count: key[:school_count],
|
||||
used_count: key[:used_count],
|
||||
passed_count: key[:passed_count],
|
||||
evaluate_count: key[:evaluate_count],
|
||||
passed_ave_time: key[:passed_ave_time]
|
||||
}
|
||||
ssi.update_attributes(update_params)
|
||||
end
|
||||
end
|
||||
puts("---------------------shixun_info_statistic_end")
|
||||
Rails.logger.info("---------------------shixun_info_statistic_end")
|
||||
end
|
||||
|
||||
task user_info_statistic: :environment do
|
||||
puts("---------------------user_info_statistic_begin")
|
||||
Rails.logger.info("---------------------user_info_statistic_begin")
|
||||
subjects = Subject.where(status: 2)
|
||||
subjects.find_each(batch_size: 100) do |subject|
|
||||
puts("---------------------user_info_statistic: #{subject.id}")
|
||||
data = Subjects::UserUsedInfoService.call(subject)
|
||||
data.each do |key|
|
||||
sui = SubjectUserInfo.find_or_create_by!(user_id: key[:user_id], subject_id: subject.id)
|
||||
update_params = {
|
||||
username: key[:name],
|
||||
passed_myshixun_count: key[:passed_myshixun_count],
|
||||
passed_games_count: key[:passed_games_count],
|
||||
code_line_count: key[:code_line_count],
|
||||
evaluate_count: key[:evaluate_count],
|
||||
cost_time: key[:cost_time]
|
||||
}
|
||||
sui.update_attributes(update_params)
|
||||
end
|
||||
end
|
||||
puts("---------------------user_info_statistic_end")
|
||||
Rails.logger.info("---------------------user_info_statistic_end")
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
After Width: | Height: | Size: 7.2 KiB |
After Width: | Height: | Size: 5.4 KiB |
@ -0,0 +1,5 @@
|
||||
import md5 from 'md5';
|
||||
export function setmiyah(logins){
|
||||
const opens ="79e33abd4b6588941ab7622aed1e67e8";
|
||||
return md5(opens+logins);
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue