Last active
January 7, 2020 21:24
-
-
Save scytacki/10b0994e4883da393ff6b036794b50cb to your computer and use it in GitHub Desktop.
scripts to run in the rails console to update activity runs
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
def update_seq_platform_info(sequence_run) | |
sequence_run.runs.each { |r| | |
r.update_attributes( | |
class_info_url: sequence_run.class_info_url, | |
context_id: sequence_run.context_id, | |
platform_id: sequence_run.platform_id, | |
platform_user_id: sequence_run.platform_user_id, | |
resource_link_id: sequence_run.resource_link_id | |
) | |
} | |
end | |
# find relevant runs | |
seq_runs = SequenceRun.where(sequence_id: 528).where('platform_id is not null'); nil | |
# for staging: it is sequence_id 252 | |
# find out how many there are... | |
seq_runs.count | |
# print out the existing platform info for each run to make sure we aren't | |
# messing something up: | |
(Proc.new { | |
output = "id, class_info_url, context_id, platform_id, platform_user_id, resource_link_id\n" | |
seq_runs.find_each{|seq_run| | |
output += "#{seq_run.id}, #{seq_run.class_info_url}, #{seq_run.context_id}, #{seq_run.platform_id}, #{seq_run.platform_user_id}, #{seq_run.resource_link_id}\n" | |
} | |
puts output | |
}).call | |
# update them | |
seq_runs.find_each{|seq_run| | |
# create activity runs for all of the activities in the sequence even if the student hasn't | |
# seen the activity yet | |
seq_run.make_or_update_runs | |
update_seq_platform_info(seq_run)}; nil | |
# Sending them to firestore | |
# check that the local environment has | |
# ENV["REPORT_SERVICE_SELF_URL"] | |
# ENV["REPORT_SERVICE_URL"] | |
# ENV["REPORT_SERVICE_TOKEN"] | |
seq_runs.find_each{|seq_run| | |
seq_run.runs.each{|run| | |
sender = ReportService::RunSender.new(run, { send_all_answers: true }) | |
result = sender.send | |
if (!result || !result["success"]) | |
puts "Failed to send Run: #{run.id}" | |
end | |
} | |
}; nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment