dev_local
daiao 6 years ago
parent 373de30f3b
commit b4383f31d7

@ -2,54 +2,54 @@
class AddShixunMembersForShixuns < ActiveRecord::Migration
def up
ActiveRecord::Base.transaction do
begin
# 添加实训合作的用户
mail = ["358551898@qq.com", "a358551898@163.com"] #修改这里
user_ids = User.where(mail: mail).pluck(:id)
if mail.count != user_ids.count
raise("添加的用户人数与平台不一致,请检查邮箱")
end
# identifiers = ["yzi73hov", "rtl4hfjm", "7brio4fn", "ljqz2xft", "jps8tzi7", "su3j58cm", "k6842ose", "nvzi5xbo",
# "j9aq3lbi", "3xovlgp5", "z6ve4afx", "93porv58", "e8surftc", "eirw5n2m", "pnvbt2aj", "t2mi45rf",
# "gflejmqb", "fsaz9pu8", "3siy4fca", "jzpycn4f", "nlebmku2", "npbso5fc", "96wxjrob", "s2gxjuet",
# "3o5qyha4", "bt2ipsmv", "9fls43hx", "yxcs79vp", "59gi4cvy", "oj3wrmty", "wpsc7nli", "fiyvtqp8",
# "2wuo9ykb", "45uqw3se", "ugrq4p83", "vkgn8cfy", "avgffhtb"]
shixuns = Shixun.includes(challenges: [:test_sets, :challenge_tags]).where("shixuns.name like '%期末%'")
shixuns.each do |shixun|
if shixun.shixun_members.blank?
ShixunMember.create!(user_id: shixun.user_id, shixun_id: shixun.id, role: 1)
end
user_ids.each do |user_id|
unless shixun.shixun_members.pluck(:user_id).include?(user_id)
ShixunMember.create!(user_id: user_id, shixun_id: shixun.id, role: 2)
end
end
shixun.challenges.update_all(test_set_score: true)
shixun.challenges.each do |challenge|
all_score = 0
set_count = challenge.test_sets.count
raise("测试集的个数不能为0") if set_count == 0
score = (100 / set_count).to_i
challenge.test_sets.each_with_index do |test_set, index|
# 如果是最后一个测试集,则把剩下的分数全给你它
if index+1 == set_count
score = 100 - all_score
end
test_set.update_column(:score, score)
all_score += score
end
# 增加标签
unless challenge.challenge_tags.pluck(:name).include?("2019上半年C语言期末考试题库")
ChallengeTag.create!(name: "2019上半年C语言期末考试题库", challenge_id: challenge.id)
end
end
end
rescue Exception => e
puts "#########error_message: ##{e.message}"
raise ActiveRecord::Rollback
end
# begin
# # 添加实训合作的用户
# mail = ["358551898@qq.com", "a358551898@163.com"] #修改这里
# user_ids = User.where(mail: mail).pluck(:id)
# if mail.count != user_ids.count
# raise("添加的用户人数与平台不一致,请检查邮箱")
# end
# # identifiers = ["yzi73hov", "rtl4hfjm", "7brio4fn", "ljqz2xft", "jps8tzi7", "su3j58cm", "k6842ose", "nvzi5xbo",
# # "j9aq3lbi", "3xovlgp5", "z6ve4afx", "93porv58", "e8surftc", "eirw5n2m", "pnvbt2aj", "t2mi45rf",
# # "gflejmqb", "fsaz9pu8", "3siy4fca", "jzpycn4f", "nlebmku2", "npbso5fc", "96wxjrob", "s2gxjuet",
# # "3o5qyha4", "bt2ipsmv", "9fls43hx", "yxcs79vp", "59gi4cvy", "oj3wrmty", "wpsc7nli", "fiyvtqp8",
# # "2wuo9ykb", "45uqw3se", "ugrq4p83", "vkgn8cfy", "avgffhtb"]
# shixuns = Shixun.includes(challenges: [:test_sets, :challenge_tags]).where("shixuns.name like '%期末%'")
# shixuns.each do |shixun|
# if shixun.shixun_members.blank?
# ShixunMember.create!(user_id: shixun.user_id, shixun_id: shixun.id, role: 1)
# end
# user_ids.each do |user_id|
# unless shixun.shixun_members.pluck(:user_id).include?(user_id)
# ShixunMember.create!(user_id: user_id, shixun_id: shixun.id, role: 2)
# end
# end
# #把测试集设置成按均分比
# shixun.challenges.update_all(test_set_score: true)
# shixun.challenges.each do |challenge|
# all_score = 0
# set_count = challenge.test_sets.count
# raise("测试集的个数不能为0") if set_count == 0
# score = (100 / set_count).to_i
# challenge.test_sets.each_with_index do |test_set, index|
# # 如果是最后一个测试集,则把剩下的分数全给你它
# if index+1 == set_count
# score = 100 - all_score
# end
# test_set.update_column(:score, score)
# all_score += score
# end
# # 增加标签
# unless challenge.challenge_tags.pluck(:name).include?("2019上半年C语言期末考试题库")
# ChallengeTag.create!(name: "2019上半年C语言期末考试题库", challenge_id: challenge.id)
# end
# end
# end
#
# rescue Exception => e
# puts "#########error_message: ##{e.message}"
# raise ActiveRecord::Rollback
# end
end
end

Loading…
Cancel
Save