Skip to content

Instantly share code, notes, and snippets.

@scytacki
Created August 10, 2022 18:55
Show Gist options
  • Save scytacki/c626b50392ca5977bc56bf126bfe9ad3 to your computer and use it in GitHub Desktop.
Save scytacki/c626b50392ca5977bc56bf126bfe9ad3 to your computer and use it in GitHub Desktop.
# First pass off this missed interactives that had no answerPrompt field in their JSON
# this is a revised version of that first pass to pick up these new ones
# Get interactives without answer prompt fields that were not modified after the new interactive
# was released
ManagedInteractive.where(library_interactive_id: 41).where("authored_state not like '%\"answerPrompt\":%'").where("legacy_ref_id is null").where("updated_at < '2022-08-05 14:22'").count
def add_describe_the_drawing
mis_processed = 0
managed_interactives = ManagedInteractive.where(library_interactive_id: 41).where("authored_state not like '%\"answerPrompt\":%'").where("legacy_ref_id is null").where("updated_at < '2022-08-05 14:22'")
mis_to_process = managed_interactives.count
managed_interactives.find_in_batches(batch_size: 100) { |batch|
ActiveRecord::Base.transaction {
batch.each { |mi|
authored_state = JSON.parse(mi.authored_state)
authored_state["answerPrompt"] = "Describe the drawing."
mi.update_column(:authored_state, authored_state.to_json)
mis_processed += 1
}
puts "#{mis_processed} of #{mis_to_process} processed."
}
}
puts "Processed #{mis_processed} of #{mis_to_process}."
end
# Generate CSV of what was modified
mis = ManagedInteractive.where(library_interactive_id: 41).where("authored_state not like '%\"answerPrompt\":%'").where("legacy_ref_id is null").where("updated_at < '2022-08-05 14:22'"); nil
output = CSV.generate { |csv|
mis.each{ |mi|
page = mi.interactive_page
activity = page&.lightweight_activity
next if !page || !activity
csv << [
mi.id,
activity.project&.title,
activity.user.email,
"https://authoring.concord.org/activities/#{activity.id}/pages/#{page.id}/edit",
mi.updated_at
]
}
};nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment