Last active
August 10, 2022 18:25
-
-
Save scytacki/ead6b5244fbfe53d9bb49abc01bb6f3b to your computer and use it in GitHub Desktop.
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
ManagedInteractive.where(library_interactive_id: 41).where("authored_state like '%\"answerPrompt\":null%' or authored_state like '%\"answerPrompt\":\"\"%'").where("legacy_ref_id is null").count | |
def add_describe_the_drawing | |
mis_processed = 0 | |
managed_interactives = ManagedInteractive.where(library_interactive_id: 41).where("authored_state like '%\"answerPrompt\":null%' or authored_state like '%\"answerPrompt\":\"\"%'").where("legacy_ref_id is null") | |
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.authored_state = authored_state.to_json | |
mi.save! | |
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 like '%\"answerPrompt\":\"Describe the drawing.\"%' ").where("legacy_ref_id is null"); 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" | |
] | |
} | |
};nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment