dev_local
daiao 6 years ago
parent 373de30f3b
commit b4383f31d7

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

Loading…
Cancel
Save