Last active
January 23, 2020 22:25
-
-
Save scytacki/ece01426c8b3dd43a0db9510de409cb3 to your computer and use it in GitHub Desktop.
Fix moved student in LARA
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
# get offering and class json api responses from running teacher report | |
# URL templates: | |
# https://learn.concord.org/api/v1/classes/[class_id] | |
# https://learn.concord.org/api/v1/offerings/[offering_id] | |
# modify offering json by adding class_hash property from the class json | |
# The following commands are to be run in the LARA rails console | |
offering_json = <<-EOS | |
# Paste modified offering json string inside here | |
EOS | |
offering_obj = JSON.parse(offering_json) | |
# function for updating the platform_info in the child runs | |
# in future versions of LARA this won't be necessary | |
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 | |
# save our modified sequence runs | |
seq_runs = [] | |
error_log = "" | |
# Collect the sequence runs and check for inconsistencies | |
# if there are errors printed out then they should probably be resolved | |
# before going forward | |
offering_obj['students'].each{|student| | |
seq_run = SequenceRun.where(remote_endpoint: student['endpoint_url']).first | |
if seq_run.platform_user_id != student['user_id'].to_s | |
error_log += "SequenceRun for #{student['endpoint_url']} doesn't match user_id\n" | |
next | |
end | |
if seq_run.platform_id != "https://learn.concord.org" | |
error_log += "SequenceRun for #{student['endpoint_url']} doesn't have valid platform_id\n" | |
next | |
end | |
seq_runs << seq_run | |
}; nil | |
puts error_log | |
# print out the existing platform info for each run to make sure we aren't | |
# messing something up: | |
def print_info_on_runs(_seq_runs) | |
output = "id, class_info_url, context_id, platform_id, platform_user_id, remote_endpoint, resource_link_id\n" | |
_seq_runs.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.remote_endpoint}, #{seq_run.resource_link_id}\n" | |
} | |
puts output | |
end | |
print_info_on_runs(seq_runs) | |
# find out how many there are... | |
seq_runs.count | |
# update them with out saving first | |
# this provides the oportunity to check them again with the Proc above | |
seq_runs.each{|seq_run| | |
seq_run.class_info_url = offering_obj['clazz_info_url'] | |
seq_run.context_id = offering_obj['class_hash'] | |
seq_run.resource_link_id = offering_obj['id'].to_s | |
}; nil | |
# look at the info again to make sure things are updated as expected | |
print_info_on_runs(seq_runs) | |
# Save the updated sequence runs and update the activity runs | |
seq_runs.each{|seq_run| | |
seq_run.save! | |
# 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.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