Skip to content

Commit

Permalink
fix (abr-testing): Checks that most recent run is completed in abr_sc…
Browse files Browse the repository at this point in the history
…ale script (#15661)

<!--
Thanks for taking the time to open a pull request! Please make sure
you've read the "Opening Pull Requests" section of our Contributing
Guide:


https://github.com/Opentrons/opentrons/blob/edge/CONTRIBUTING.md#opening-pull-requests

To ensure your code is reviewed quickly and thoroughly, please fill out
the sections below to the best of your ability!
-->

# Overview

Checks that run being pulled is completed. Adds error handling if no new
runs need to be added.

# Test Plan

<!--
Use this section to describe the steps that you took to test your Pull
Request.
If you did not perform any testing provide justification why.

OT-3 Developers: You should default to testing on actual physical
hardware.
Once again, if you did not perform testing against hardware, justify
why.

Note: It can be helpful to write a test plan before doing development

Example Test Plan (HTTP API Change)

- Verified that new optional argument `dance-party` causes the robot to
flash its lights, move the pipettes,
then home.
- Verified that when you omit the `dance-party` option the robot homes
normally
- Added protocol that uses `dance-party` argument to G-Code Testing
Suite
- Ran protocol that did not use `dance-party` argument and everything
was successful
- Added unit tests to validate that changes to pydantic model are
correct

-->

# Changelog

<!--
List out the changes to the code in this PR. Please try your best to
categorize your changes and describe what has changed and why.

Example changelog:
- Fixed app crash when trying to calibrate an illegal pipette
- Added state to API to track pipette usage
- Updated API docs to mention only two pipettes are supported

IMPORTANT: MAKE SURE ANY BREAKING CHANGES ARE PROPERLY COMMUNICATED
-->

# Review requests

<!--
Describe any requests for your reviewers here.
-->

# Risk assessment

<!--
Carefully go over your pull request and look at the other parts of the
codebase it may affect. Look for the possibility, even if you think it's
small, that your change may affect some other part of the system - for
instance, changing return tip behavior in protocol may also change the
behavior of labware calibration.

Identify the other parts of the system your codebase may affect, so that
in addition to your own review and testing, other people who may not
have the system internalized as much as you can focus their attention
and testing there.
-->
  • Loading branch information
rclarke0 authored Jul 19, 2024
1 parent a60d240 commit c37c95e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
6 changes: 4 additions & 2 deletions abr-testing/abr_testing/automation/google_sheets_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ def column_letter_to_index(column_letter: str) -> int:

for col_offset, col_values in enumerate(data):
column_index = start_column_index + col_offset
# column_letter = index_to_column_letter(column_index)
for row_offset, value in enumerate(col_values):
row_index = start_row + row_offset
try:
Expand All @@ -163,7 +162,10 @@ def column_letter_to_index(column_letter: str) -> int:
)

body = {"requests": requests}
self.spread_sheet.batch_update(body=body)
try:
self.spread_sheet.batch_update(body=body)
except gspread.exceptions.APIError as e:
print(f"ERROR MESSAGE: {e}")

def update_cell(
self, sheet_title: str, row: int, column: int, single_data: Any
Expand Down
20 changes: 15 additions & 5 deletions abr-testing/abr_testing/data_collection/abr_google_drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def create_data_dictionary(
"""Pull data from run files and format into a dictionary."""
runs_and_robots: List[Any] = []
runs_and_lpc: List[Dict[str, Any]] = []
headers: List[str] = []
headers_lpc: List[str] = []
for filename in os.listdir(storage_directory):
file_path = os.path.join(storage_directory, filename)
if file_path.endswith(".json"):
Expand All @@ -49,7 +51,14 @@ def create_data_dictionary(
if not isinstance(file_results, dict):
continue
run_id = file_results.get("run_id", "NaN")
try:
start_time_test = file_results["startedAt"]
completed_time_test = file_results["completedAt"]
except KeyError:
print(f"Run {run_id} is incomplete. Skipping run.")
continue
if run_id in runs_to_save:
print("started reading run.")
robot = file_results.get("robot_name")
protocol_name = file_results["protocol"]["metadata"].get("protocolName", "")
software_version = file_results.get("API_Version", "")
Expand All @@ -74,13 +83,13 @@ def create_data_dictionary(
)
try:
start_time = datetime.strptime(
file_results.get("startedAt", ""), "%Y-%m-%dT%H:%M:%S.%f%z"
start_time_test, "%Y-%m-%dT%H:%M:%S.%f%z"
)
adjusted_start_time = start_time - timedelta(hours=4)
start_date = str(adjusted_start_time.date())
start_time_str = str(adjusted_start_time).split("+")[0]
complete_time = datetime.strptime(
file_results.get("completedAt", ""), "%Y-%m-%dT%H:%M:%S.%f%z"
completed_time_test, "%Y-%m-%dT%H:%M:%S.%f%z"
)
adjusted_complete_time = complete_time - timedelta(hours=4)
complete_time_str = str(adjusted_complete_time).split("+")[0]
Expand Down Expand Up @@ -130,15 +139,16 @@ def create_data_dictionary(
**pipette_dict,
**plate_measure,
}
headers: List[str] = list(row_2.keys())
# runs_and_robots[run_id] = row_2
headers = list(row_2.keys())
runs_and_robots.append(list(row_2.values()))
# LPC Data Recording
runs_and_lpc, headers_lpc = read_robot_logs.lpc_data(
file_results, row_for_lpc, runs_and_lpc
)
else:
continue
num_of_runs_read = len(runs_and_robots)
print(f"Number of runs read: {num_of_runs_read}")
transposed_runs_and_robots = list(map(list, zip(*runs_and_robots)))
transposed_runs_and_lpc = list(map(list, zip(*runs_and_lpc)))
return transposed_runs_and_robots, headers, transposed_runs_and_lpc, headers_lpc
Expand Down Expand Up @@ -207,7 +217,6 @@ def create_data_dictionary(
start_row = google_sheet.get_index_row() + 1
print(start_row)
google_sheet.batch_update_cells(transposed_runs_and_robots, "A", start_row, "0")
# Calculate Robot Lifetimes

# Add LPC to google sheet
google_sheet_lpc = google_sheets_tool.google_sheet(credentials_path, "ABR-LPC", 0)
Expand All @@ -216,4 +225,5 @@ def create_data_dictionary(
transposed_runs_and_lpc, "A", start_row_lpc, "0"
)
robots = list(set(google_sheet.get_column(1)))
# Calculate Robot Lifetimes
sync_abr_sheet.determine_lifetime(google_sheet)
18 changes: 17 additions & 1 deletion abr-testing/abr_testing/tools/abr_scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,25 @@ def get_most_recent_run_and_record(
most_recent_run_id = run_list[-1]["id"]
results = get_run_logs.get_run_data(most_recent_run_id, ip)
# Save run information to local directory as .json file
read_robot_logs.save_run_log_to_json(ip, results, storage_directory)
saved_file_path = read_robot_logs.save_run_log_to_json(
ip, results, storage_directory
)
# Check that last run is completed.
with open(saved_file_path) as file:
file_results = json.load(file)
try:
file_results["completedAt"]
except ValueError:
# no completedAt field, get run before the last run.
most_recent_run_id = run_list[-2]["id"]
results = get_run_logs.get_run_data(most_recent_run_id, ip)
# Save run information to local directory as .json file
saved_file_path = read_robot_logs.save_run_log_to_json(
ip, results, storage_directory
)
# Record run to google sheets.
print(most_recent_run_id)

(
runs_and_robots,
headers,
Expand Down

0 comments on commit c37c95e

Please sign in to comment.