-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Script to pull unique run logs from ABR robots #14553
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
"""ABR Robot IPs.""" | ||
|
||
ABR_IPS = [ | ||
"10.14.12.159", | ||
"10.14.12.161", | ||
"10.14.12.126", | ||
"10.14.12.112", | ||
"10.14.12.124", | ||
"10.14.12.163", | ||
"10.14.12.162", | ||
"10.14.12.165", | ||
"10.14.12.164", | ||
"10.14.12.168", | ||
"10.14.12.167", | ||
] |
134 changes: 134 additions & 0 deletions
134
hardware-testing/hardware_testing/abr_tools/abr_run_logs.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
"""ABR Run Log Pull.""" | ||
from .abr_robots import ABR_IPS | ||
import argparse | ||
import os | ||
import json | ||
import traceback | ||
import requests | ||
from typing import Set, Dict, Any | ||
|
||
|
||
def get_run_ids_from_storage(storage_directory: str) -> Set[str]: | ||
"""Read all files in long term storage directory and read run id. Add run id to a set. Return run id set.""" | ||
os.makedirs(storage_directory, exist_ok=True) | ||
list_of_files = os.listdir(storage_directory) | ||
run_ids = set() | ||
for this_file in list_of_files: | ||
read_file = os.path.join(storage_directory, this_file) | ||
try: | ||
file_results = json.load(open(read_file)) | ||
except json.JSONDecodeError: | ||
print(f"Ignoring unparsable file {read_file}.") | ||
continue | ||
run_id = file_results["run_id"] | ||
run_ids.add(run_id) | ||
return run_ids | ||
|
||
|
||
def get_unseen_run_ids(runs: Set[str], runs_from_storage: Set[str]) -> Set[str]: | ||
"""Subtracts runs from storage from current runs being read.""" | ||
runs_to_save = runs - runs_from_storage | ||
return runs_to_save | ||
|
||
|
||
def get_run_ids_from_robot(ip: str) -> Set[str]: | ||
"""Get all completed runs from each robot.""" | ||
run_ids = set() | ||
response = requests.get( | ||
f"http://{ip}:31950/runs", headers={"opentrons-version": "3"} | ||
) | ||
run_data = response.json() | ||
run_list = run_data["data"] | ||
for run in run_list: | ||
run_id = run["id"] | ||
if not run["current"]: | ||
run_ids.add(run_id) | ||
return run_ids | ||
|
||
|
||
def get_run_data(one_run: Any, ip: str) -> Dict[str, Any]: | ||
response = requests.get( | ||
f"http://{ip}:31950/runs/{one_run}/commands", | ||
headers={"opentrons-version": "3"}, | ||
params={"cursor": 0, "pageLength": 0}, | ||
) | ||
data = response.json() | ||
command_count = data["meta"]["totalLength"] | ||
page_length = 100 | ||
commands = list() | ||
run = dict() | ||
for cursor in range(0, command_count, page_length): | ||
response = requests.get( | ||
f"http://{ip}:31950/runs/{one_run}/commands", | ||
headers={"opentrons-version": "3"}, | ||
params={"cursor": cursor, "pageLength": page_length}, | ||
) | ||
command_data = response.json() | ||
commands.extend(command_data["data"]) | ||
run["commands"] = commands | ||
response = requests.get( | ||
f"http://{ip}:31950/runs/{one_run}", headers={"opentrons-version": "3"} | ||
) | ||
run_meta_data = response.json() | ||
protocol_id = run_meta_data["data"]["protocolId"] | ||
run.update(run_meta_data["data"]) | ||
response = requests.get( | ||
f"http://{ip}:31950/protocols/{protocol_id}", headers={"opentrons-version": "3"} | ||
) | ||
protocol_data = response.json() | ||
run["protocol"] = protocol_data["data"] | ||
response = requests.get( | ||
f"http://{ip}:31950/health", headers={"opentrons-version": "3"} | ||
) | ||
health_data = response.json() | ||
robot_name = health_data["name"] | ||
try: | ||
robot_serial = health_data["robot_serial"] | ||
except: | ||
robot_serial = "unknown" | ||
run["robot_name"] = robot_name | ||
run["run_id"] = one_run | ||
run["robot_serial"] = robot_serial | ||
return run | ||
|
||
|
||
def save_runs(runs_to_save: Set[str], ip: str, storage_directory: str) -> None: | ||
for a_run in runs_to_save: | ||
data = get_run_data(a_run, ip) | ||
robot_name = data["robot_name"] | ||
data_file_name = data["robot_name"] + "_" + data["run_id"] + ".json" | ||
json.dump(data, open(os.path.join(storage_directory, data_file_name), mode="w")) | ||
print( | ||
f"Saved {len(runs_to_save)} run(s) from robot {robot_name} with IP address {ip}." | ||
) | ||
pass | ||
|
||
|
||
def get_all_run_logs(storage_directory: str): | ||
"""Connect to each ABR robot to read run log data. | ||
Read each robot's list of unique run log IDs and compare them to all IDs for all of the runs in storage. | ||
Any ID that is not in storage, download the run log and put it in storage.""" | ||
|
||
runs_from_storage = get_run_ids_from_storage(storage_directory) | ||
for ip in ABR_IPS: | ||
try: | ||
runs = get_run_ids_from_robot(ip) | ||
runs_to_save = get_unseen_run_ids(runs, runs_from_storage) | ||
save_runs(runs_to_save, ip, storage_directory) | ||
except Exception: | ||
print(f"Failed to read IP address: {ip}.") | ||
traceback.print_exc() | ||
pass | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed. |
||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser(description="Pulls run logs from ABR robots.") | ||
parser.add_argument( | ||
"storage_directory", | ||
metavar="STORAGE_DIRECTORY", | ||
type=str, | ||
nargs=1, | ||
help="Path to long term storage directory for run logs.", | ||
) | ||
args = parser.parse_args() | ||
get_all_run_logs(args.storage_directory[0]) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should remove the
pass
, not necessary anymoreThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed.