@ -1,5 +1,5 @@
|
|||||||
class MessageDetail < ApplicationRecord
|
class MessageDetail < ApplicationRecord
|
||||||
belongs_to :message, :touch => true
|
belongs_to :message, :touch => true
|
||||||
validates :content, length: { maximum: 5000, too_long: "内容不能超过5000个字符" }
|
validates :content, length: { maximum: 10000, too_long: "内容不能超过10000个字符" }
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
json.single_questions_count @single_questions_count
|
json.single_questions_count @basket_count&.fetch("SINGLE", 0)
|
||||||
json.multiple_questions_count @multiple_questions_count
|
json.multiple_questions_count @basket_count&.fetch("MULTIPLE", 0)
|
||||||
json.judgement_questions_count @judgement_questions_count
|
json.judgement_questions_count @basket_count&.fetch("JUDGMENT", 0)
|
||||||
json.completion_questions_count @completion_questions_count
|
json.completion_questions_count @basket_count&.fetch("COMPLETION", 0)
|
||||||
json.subjective_questions_count @subjective_questions_count
|
json.subjective_questions_count @basket_count&.fetch("SUBJECTIVE", 0)
|
||||||
json.practical_questions_count @practical_questions_count
|
json.practical_questions_count @basket_count&.fetch("PRACTICAL", 0)
|
||||||
json.program_questions_count @program_questions_count
|
json.program_questions_count @basket_count&.fetch("PROGRAM", 0)
|
@ -0,0 +1,8 @@
|
|||||||
|
json.status 0
|
||||||
|
json.message "success"
|
||||||
|
json.data do
|
||||||
|
json.subject_info @subject.subject_record
|
||||||
|
json.other_info @data
|
||||||
|
json.total_count @data_count
|
||||||
|
json.total @total
|
||||||
|
end
|
@ -1,6 +1,6 @@
|
|||||||
class AddIndexForSubjectRecords < ActiveRecord::Migration[5.2]
|
class AddIndexForSubjectRecords < ActiveRecord::Migration[5.2]
|
||||||
def change
|
def change
|
||||||
remove_index :subject_records, :subject_id
|
# remove_index :subject_records, :subject_id
|
||||||
add_index :subject_records, :subject_id, unique: true
|
add_index :subject_records, :subject_id, unique: true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -0,0 +1,50 @@
|
|||||||
|
class Migrate3176ExerciseScore < ActiveRecord::Migration[5.2]
|
||||||
|
|
||||||
|
def calculate_student_score(exercise,user)
|
||||||
|
score5 = 0.0 #实训题
|
||||||
|
exercise_end_time = exercise.end_time
|
||||||
|
exercise_questions = exercise.exercise_questions.includes(:exercise_standard_answers,:exercise_shixun_challenges)
|
||||||
|
exercise_questions.each do |q|
|
||||||
|
if q.question_type == 5
|
||||||
|
q.exercise_shixun_challenges.each do |exercise_cha|
|
||||||
|
game = Game.user_games(user.id,exercise_cha.challenge_id)&.first #当前用户的关卡
|
||||||
|
if game.present?
|
||||||
|
exercise_cha_score = 0.0
|
||||||
|
answer_status = 0
|
||||||
|
# if game.status == 2 && game.final_score >= 0
|
||||||
|
if game.final_score > 0 && (game.end_time.nil? || game.end_time < exercise_end_time)
|
||||||
|
exercise_cha_score = game.real_score(exercise_cha.question_score)
|
||||||
|
# exercise_cha_score = exercise_cha.question_score #每一关卡的得分
|
||||||
|
answer_status = 1
|
||||||
|
end
|
||||||
|
ex_shixun_answer_content = exercise_cha.exercise_shixun_answers.find_by(user_id:user.id,exercise_question_id:q.id)
|
||||||
|
if ex_shixun_answer_content.present? && !(ex_shixun_answer_content.score >0) #把关卡的答案存入试卷的实训里
|
||||||
|
ex_shixun_answer_content.update_attributes!(score:exercise_cha_score.round(1),status:answer_status)
|
||||||
|
end
|
||||||
|
score5 += exercise_cha_score
|
||||||
|
else
|
||||||
|
score5 += 0.0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
score5
|
||||||
|
end
|
||||||
|
|
||||||
|
def change
|
||||||
|
exercise = Exercise.find_by(id: 3176)
|
||||||
|
if exercise
|
||||||
|
exercise_users = exercise.exercise_users.where("start_at is not null")
|
||||||
|
exercise_users.each do |exercise_user|
|
||||||
|
calculate_score = calculate_student_score(exercise, exercise_user.user)
|
||||||
|
subjective_score = exercise_user.subjective_score
|
||||||
|
total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score
|
||||||
|
total_score = calculate_score + total_score_subjective_score
|
||||||
|
if exercise_user.end_at.present?
|
||||||
|
exercise_user.update_attributes!(score:total_score,objective_score:calculate_score)
|
||||||
|
end
|
||||||
|
puts exercise_user.id
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,49 @@
|
|||||||
|
class Migrate3517ExerciseScore < ActiveRecord::Migration[5.2]
|
||||||
|
def calculate_student_score(exercise,user)
|
||||||
|
score5 = 0.0 #实训题
|
||||||
|
exercise_end_time = exercise.end_time
|
||||||
|
exercise_questions = exercise.exercise_questions.includes(:exercise_standard_answers,:exercise_shixun_challenges)
|
||||||
|
exercise_questions.each do |q|
|
||||||
|
if q.question_type == 5
|
||||||
|
q.exercise_shixun_challenges.each do |exercise_cha|
|
||||||
|
game = Game.user_games(user.id,exercise_cha.challenge_id)&.first #当前用户的关卡
|
||||||
|
if game.present?
|
||||||
|
exercise_cha_score = 0.0
|
||||||
|
answer_status = 0
|
||||||
|
# if game.status == 2 && game.final_score >= 0
|
||||||
|
if game.final_score > 0 && (game.end_time.nil? || game.end_time < exercise_end_time)
|
||||||
|
exercise_cha_score = game.real_score(exercise_cha.question_score)
|
||||||
|
# exercise_cha_score = exercise_cha.question_score #每一关卡的得分
|
||||||
|
answer_status = 1
|
||||||
|
end
|
||||||
|
ex_shixun_answer_content = exercise_cha.exercise_shixun_answers.find_by(user_id:user.id,exercise_question_id:q.id)
|
||||||
|
if ex_shixun_answer_content.present? && !(ex_shixun_answer_content.score >0) #把关卡的答案存入试卷的实训里
|
||||||
|
ex_shixun_answer_content.update_attributes!(score:exercise_cha_score.round(1),status:answer_status)
|
||||||
|
end
|
||||||
|
score5 += exercise_cha_score
|
||||||
|
else
|
||||||
|
score5 += 0.0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
score5
|
||||||
|
end
|
||||||
|
|
||||||
|
def change
|
||||||
|
exercise = Exercise.find_by(id: 3517)
|
||||||
|
if exercise
|
||||||
|
exercise_users = exercise.exercise_users.where("start_at is not null")
|
||||||
|
exercise_users.each do |exercise_user|
|
||||||
|
calculate_score = calculate_student_score(exercise, exercise_user.user)
|
||||||
|
subjective_score = exercise_user.subjective_score
|
||||||
|
total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score
|
||||||
|
total_score = calculate_score + total_score_subjective_score
|
||||||
|
if exercise_user.end_at.present?
|
||||||
|
exercise_user.update_attributes!(score:total_score,objective_score:calculate_score)
|
||||||
|
end
|
||||||
|
puts exercise_user.id
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,5 @@
|
|||||||
|
class AddWecharSupportForShixuns < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
add_column :shixuns, :is_wechat_support, :boolean, :default => false
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,25 @@
|
|||||||
|
class MigrateCouresMemberGroup < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
course_ids = [377, 657, 715, 777, 973, 1093, 1131, 1180, 1309, 1920, 2037, 2346, 2354, 2493, 2752, 2920, 3000,
|
||||||
|
3141, 3240, 3350, 3351, 3353, 3387, 3533, 3796]
|
||||||
|
|
||||||
|
courses = Course.where(id: course_ids)
|
||||||
|
|
||||||
|
courses.each do |course|
|
||||||
|
group_ids = course.course_groups.pluck(:id) + [0]
|
||||||
|
course.course_members.where.not(course_group_id: group_ids).each do |member|
|
||||||
|
if CourseGroup.where(course_id: course.id, name: member.course_group_name).exists?
|
||||||
|
new_group = CourseGroup.where(course_id: course.id, name: member.course_group_name).first
|
||||||
|
else
|
||||||
|
# position = CourseGroup.where(course_id: course.id).order("position desc").first&.position.to_i + 1
|
||||||
|
new_group = course.course_groups.create!(name: member.course_group_name)
|
||||||
|
course.exercise_group_settings.where(course_group_id: member.course_group_id).update_all(course_group_id: new_group.id)
|
||||||
|
course.attachment_group_settings.where(course_group_id: member.course_group_id).update_all(course_group_id: new_group.id)
|
||||||
|
HomeworkGroupReview.where(homework_common_id: course.homework_commons.pluck(:id)).where(course_group_id: member.course_group_id).update_all(course_group_id: new_group.id)
|
||||||
|
course.homework_group_settings.where(course_group_id: member.course_group_id).update_all(course_group_id: new_group.id)
|
||||||
|
end
|
||||||
|
member.update!(course_group_id: new_group.id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,14 @@
|
|||||||
|
class MigrateCoureGroupPosition < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
course_ids = [377, 657, 715, 777, 973, 1093, 1131, 1180, 1309, 1920, 2037, 2346, 2354, 2493, 2752, 2920, 3000,
|
||||||
|
3141, 3240, 3350, 3351, 3353, 3387, 3533, 3796]
|
||||||
|
|
||||||
|
courses = Course.where(id: course_ids)
|
||||||
|
|
||||||
|
courses.each do |course|
|
||||||
|
CourseGroup.where(course_id: course.id).reorder("position ASC, CONVERT(course_groups.name USING gbk) COLLATE gbk_chinese_ci ASC").each_with_index do |group, index|
|
||||||
|
group.update!(position: index+1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,8 @@
|
|||||||
|
class ModifyWechatSupportForShixuns < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
name = ["Python基础", "C语言基础", "C++基础", "Java"]
|
||||||
|
shixuns = Shixun.includes(:tag_repertoires)
|
||||||
|
.where(tag_repertoires: {name: name}, shixuns: {status: 2, hide_code: false})
|
||||||
|
shixuns.update_all(is_wechat_support: true)
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,17 @@
|
|||||||
|
class AddChoiceIndexToExerciseAnswers < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
add_column :exercise_answers, :choice_index, :integer, default: 1
|
||||||
|
|
||||||
|
multi_questions = ExerciseQuestion.where(question_type: 1)
|
||||||
|
multi_questions.includes(:exercise_choices, :exercise_answers).find_each do |question|
|
||||||
|
exercise_answers = question.exercise_answers
|
||||||
|
exercise_answers.find_each do |answer|
|
||||||
|
choice_index = question.exercise_choices.pluck(:id).index(answer.exercise_choice_id).to_i + 1
|
||||||
|
answer.update_column('choice_index', choice_index)
|
||||||
|
end
|
||||||
|
puts "multi_questions: #{question.id}"
|
||||||
|
end
|
||||||
|
|
||||||
|
ExerciseAnswer.joins(:exercise_question).where(exercise_questions: {question_type: 3}).update_all("choice_index = exercise_choice_id")
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,13 @@
|
|||||||
|
class AddChoiceIndexUniqIndexToExerciseAnswers < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
sql = %Q(delete from exercise_answers where (exercise_question_id, user_id, choice_index) in
|
||||||
|
(select * from (select exercise_question_id, user_id, choice_index from exercise_answers group by exercise_question_id, user_id, choice_index having count(*) > 1) a)
|
||||||
|
and id not in (select * from (select max(id) from exercise_answers group by exercise_question_id, user_id, choice_index having count(*) > 1 order by id) b))
|
||||||
|
ActiveRecord::Base.connection.execute sql
|
||||||
|
|
||||||
|
add_index :exercise_answers, [:exercise_question_id, :user_id, :choice_index], name: 'exercise_user_choice_index', unique: true
|
||||||
|
|
||||||
|
remove_index :exercise_answers, name: :exercise_choice_index
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
After Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 7.2 KiB After Width: | Height: | Size: 7.6 KiB |
After Width: | Height: | Size: 20 KiB |
After Width: | Height: | Size: 36 KiB |
Before Width: | Height: | Size: 5.4 KiB After Width: | Height: | Size: 5.9 KiB |
Before Width: | Height: | Size: 210 KiB After Width: | Height: | Size: 154 KiB |
After Width: | Height: | Size: 53 KiB |
After Width: | Height: | Size: 451 B |
After Width: | Height: | Size: 128 KiB |
Before Width: | Height: | Size: 381 KiB After Width: | Height: | Size: 383 KiB |