Skip to content

Instantly share code, notes, and snippets.

@apangeajwrubel
Created August 19, 2012 22:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apangeajwrubel/3398045 to your computer and use it in GitHub Desktop.
Save apangeajwrubel/3398045 to your computer and use it in GitHub Desktop.
fixing students with orphaned attempts
# 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