Created
August 19, 2012 22:03
fixing students with orphaned attempts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# first one | |
item_step = Item.find(829).item_steps.first | |
bad_item_step_id = 829 | |
Attempt.where("attemptable_type = 'ItemStep' and attemptable_id = ?", bad_item_step_id).each do |a| | |
a.attemptable_id = item_step.id | |
if a.correct | |
a.response_id = item_step.correct_responses.first.id | |
else | |
a.response_id = item_step.incorrect_responses.first.id | |
end | |
a.save! | |
end | |
# second one | |
item_step = Item.find(1943).item_steps.first | |
bad_item_step_id = 33244 | |
Attempt.where("attemptable_type = 'ItemStep' and attemptable_id = ?", bad_item_step_id).each do |a| | |
a.attemptable_id = item_step.id | |
if a.correct | |
a.response_id = item_step.correct_responses.first.id | |
else | |
a.response_id = item_step.incorrect_responses.first.id | |
end | |
a.save! | |
end | |
=begin | |
# problem with orphaned response_id for student 512 | |
attempts = Attempt.where(student_id: 512, correct: false) | |
attempts.each do |attempt| | |
pp Response.find(attempt.response_id).item_step | |
end | |
# => item step id 569 => Couldn't find Response with id=19952 | |
Attempt.where(response_id: 19952) | |
Activity.find(1089).items.each do |item| | |
pp item.item_steps.first | |
end | |
5032 -> 33502 | |
=end | |
# third one | |
item_step = Item.find(5032).item_steps.first | |
bad_item_step_id = 5032 | |
Attempt.where("attemptable_type = 'ItemStep' and attemptable_id = ?", bad_item_step_id).each do |a| | |
a.attemptable_id = item_step.id | |
if a.correct | |
a.response_id = item_step.correct_responses.first.id | |
else | |
a.response_id = item_step.incorrect_responses.first.id | |
end | |
a.save! | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment