某个学生分数异常

This commit is contained in:
cxt 2016-02-24 16:05:16 +08:00
parent adf9465443
commit 72c3fa1166
2 changed files with 39 additions and 2 deletions

View File

@ -0,0 +1,38 @@
class UpdateOneStudentScore < ActiveRecord::Migration
def up
student_work_score = StudentWorksScore.where("user_id = 11688 AND student_work_id = 34414").first
student_work_score.score = 100
student_work_score.save
student_works = StudentWork.where("user_id = 6456")
student_works.each do |work|
unless work.student_works_scores.empty?
if work.student_works_scores.where(:reviewer_role => 2).empty?
work.teaching_asistant_score = nil
else
work.teaching_asistant_score = work.student_works_scores.where(:reviewer_role => 2).average(:score).try(:round, 2).to_f
end
if work.student_works_scores.where(:reviewer_role => 3).empty?
work.student_score = nil
else
work.student_score = work.student_works_scores.where(:reviewer_role => 3).average(:score).try(:round, 2).to_f
end
end
if work.teaching_asistant_score.nil?
work.final_score = work.student_score
elsif work.student_score.nil?
work.final_score = work.teaching_asistant_score
else
homework = HomeworkCommon.find work.homework_common_id
ta_proportion = homework.homework_detail_manual.ta_proportion
final_ta_score = BigDecimal.new("#{work.teaching_asistant_score}") * BigDecimal.new("#{ta_proportion}")
final_s_score = BigDecimal.new("#{work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{ta_proportion}"))
final_score = final_ta_score + final_s_score
work.final_score = format("%.2f",final_score.to_f)
end
work.save
end
end
def down
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20160223073859) do
ActiveRecord::Schema.define(:version => 20160224074034) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -1269,7 +1269,6 @@ ActiveRecord::Schema.define(:version => 20160223073859) do
t.text "description"
t.integer "creator_id"
t.integer "home_id"
t.string "domain"
t.boolean "is_public"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false