Created
December 10, 2014 20:25
-
-
Save knowuh/437b8432ede430daa603 to your computer and use it in GitHub Desktop.
Given a sequence run, and an anonymous activity_run, insert the anonymous run into the sequence_run.
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 replace_run_in_sequence(seq_r_id, new_run_id) | |
new_run = Run.find(new_run_id) | |
sequence_run = SequenceRun.find(seq_r_id) | |
old_run = sequence_run.runs.detect { |r| r.activity_id == new_run.activity_id } | |
if old_run | |
clone_run(old_run,new_run) | |
if new_run.percent_complete > old_run.percent_complete | |
puts "removing run #{old_run.id}" | |
sequence_run.runs.delete(old_run) | |
puts "adding run #{new_run.id}" | |
sequence_run.runs << new_run | |
else | |
puts "something is wrong, the old run has more data than the new one" | |
end | |
else | |
puts "Cant find matching activity run in sequence run" | |
end | |
end | |
def clone_run(with_endpoint,anonymous) | |
anonymous.remote_endpoint = with_endpoint.remote_endpoint | |
anonymous.remote_id = with_endpoint.remote_id | |
anonymous.collaboration_run_id = with_endpoint.collaboration_run_id | |
anonymous.user = with_endpoint.user | |
anonymous.sequence_run_id = with_endpoint.sequence_run_id | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment