Skip to content

Commit

Permalink
Fix abr pipfile (#16595)
Browse files Browse the repository at this point in the history
Fixes duplicate uploads to deck calibration

---------

Co-authored-by: rclarke0 <[email protected]>
  • Loading branch information
AnthonyNASC20 and rclarke0 authored Oct 25, 2024
1 parent df01e77 commit b34ecbf
Show file tree
Hide file tree
Showing 11 changed files with 1,277 additions and 836 deletions.
2 changes: 1 addition & 1 deletion abr-testing/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ abr-setup:

.PHONY: simulate
PROTOCOL_DIR := abr_testing/protocols
SIMULATION_TOOL := protocol_simulation/abr_sim_check.py
SIMULATION_TOOL := abr_testing/protocol_simulation/abr_sim_check.py
EXTENSION := .py
simulate:
$(python) $(SIMULATION_TOOL)
2 changes: 1 addition & 1 deletion abr-testing/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ slackclient = "*"
slack-sdk = "*"
pandas = "*"
pandas-stubs = "*"
numpy = "==1.8.3"
paramiko = "*"

[dev-packages]
atomicwrites = "==1.4.1"
Expand Down
1,597 changes: 957 additions & 640 deletions abr-testing/Pipfile.lock

Large diffs are not rendered by default.

47 changes: 26 additions & 21 deletions abr-testing/abr_testing/data_collection/abr_calibration_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import json
import sys
import traceback
import hashlib
from abr_testing.data_collection import read_robot_logs
from abr_testing.automation import google_drive_tool, google_sheets_tool

Expand Down Expand Up @@ -75,10 +76,6 @@ def module_helper(
for module in range(len(modules)):
one_module = modules[module]
mod_serial = one_module["serialNumber"]
modified = "No data"
x = ""
y = ""
z = ""
try:
modified = one_module["moduleOffset"].get("last_modified", "")
x = one_module["moduleOffset"]["offset"].get("x", "")
Expand All @@ -97,13 +94,21 @@ def module_helper(
return modules_upload_rows


def create_hash(
robot_name: str, deck_slot: str, pipette_calibrated_with: str, last_modified: str
) -> str:
"""Create unique hash identifier for deck calibrations."""
combined_string = robot_name + deck_slot + pipette_calibrated_with + last_modified
hashed_obj = hashlib.sha256(combined_string.encode())
return hashed_obj.hexdigest()


def deck_helper(
headers_beg: List[str],
headers_end: List[str],
calibration_log: Dict[Any, Any],
google_sheet_name: str,
deck_sheet_serials: Set[str],
deck_sheet_modify_dates: Set[str],
deck_sheet_hashes: Set[str],
storage_directory: str,
) -> List[Any]:
"""Helper for parsing deck calibration data."""
Expand All @@ -117,11 +122,16 @@ def deck_helper(
)
# DECK DATA
deck = calibration_log["Deck"]
deck_modified = deck["data"].get("lastModified", "")
deck_modified = str(deck["data"].get("lastModified"))
slots = ["D3", "D1", "A1"]
pipette_calibrated_with = deck["data"].get("pipetteCalibratedWith", "")
pipette_calibrated_with = str(deck["data"].get("pipetteCalibratedWith", ""))
for i in range(len(deck["data"]["matrix"])):
if slots[i] in deck_sheet_serials and deck_modified in deck_sheet_modify_dates:
robot = calibration_log["Robot"]
deck_slot = slots[i]
unique_hash = create_hash(
robot, deck_slot, pipette_calibrated_with, deck_modified
)
if unique_hash in deck_sheet_hashes:
continue
coords = deck["data"]["matrix"][i]
x = coords[0]
Expand All @@ -143,7 +153,7 @@ def send_batch_update(
google_sheet_deck: google_sheets_tool.google_sheet,
) -> None:
"""Executes batch updates."""
# Prepare for batch updates
# Prepare data for batch update
try:
transposed_instruments_upload_rows = list(
map(list, zip(*instruments_upload_rows))
Expand Down Expand Up @@ -197,22 +207,19 @@ def upload_calibration_offsets(
inst_sheet_serials: Set[str] = set()
inst_sheet_modify_dates: Set[str] = set()
module_sheet_serials: Set[str] = set()
deck_sheet_serials: Set[str] = set()
deck_sheet_modify_dates: Set[str] = set()

deck_sheet_hashes: Set[str] = set()
# Get current serials, and modified info from google sheet
for i, sheet in enumerate(sheets):
if i == 0:
inst_sheet_serials = sheet.get_column(8)
inst_sheet_modify_dates = sheet.get_column(15)
if i == 1:
module_sheet_serials = sheet.get_column(8)
module_sheet_serials = sheet.get_column(6)
module_modify_dates = sheet.get_column(15)
elif i == 2:
deck_sheet_serials = sheet.get_column(6)
deck_sheet_modify_dates = sheet.get_column(10)
deck_sheet_hashes = sheet.get_column(11)

# Go through caliration logs and deterine what should be added to the sheet
# Iterate through calibration logs and accumulate data
for calibration_log in calibration_data:
for sheet_ind, sheet in enumerate(sheets):
if sheet_ind == 0:
Expand Down Expand Up @@ -241,8 +248,7 @@ def upload_calibration_offsets(
headers_end,
calibration_log,
google_sheet_name,
deck_sheet_serials,
deck_sheet_modify_dates,
deck_sheet_hashes,
storage_directory,
)
send_batch_update(
Expand Down Expand Up @@ -294,7 +300,6 @@ def run(
ip, storage_directory
)
calibration_data.append(calibration)
# upload_calibration_offsets(calibration, storage_directory)
else:
try:
(
Expand All @@ -316,7 +321,7 @@ def run(
google_sheet_deck,
google_sheet_name,
)
print("Successfully uploaded callibration data!")
print("Successfully uploaded calibration data!")
except Exception:
print("No calibration data to upload: ")
traceback.print_exc()
Expand Down
2 changes: 1 addition & 1 deletion abr-testing/abr_testing/data_collection/read_robot_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ def get_calibration_offsets(
print(f"Connected to {ip}")
except Exception:
print(f"ERROR: Failed to read IP address: {ip}")
raise
pass
health_data = response.json()
robot_name = health_data.get("name", "")
api_version = health_data.get("api_version", "")
Expand Down
1 change: 1 addition & 0 deletions abr-testing/abr_testing/protocol_simulation/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""The package holding code for simulating protocols."""
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
from protocol_simulation import simulation_metrics
"""Check ABR Protocols Simulate Successfully."""
from abr_testing.protocol_simulation import simulation_metrics
import os
import traceback
from pathlib import Path

def run(file_to_simulate: Path):
protocol_name = file_to_simulate.stem

def run(file_to_simulate: str) -> None:
"""Simulate protocol and raise errors."""
protocol_name = Path(file_to_simulate).stem
try:
simulation_metrics.main(file_to_simulate, False)
except Exception as e:
except Exception:
print(f"Error in protocol: {protocol_name}")
traceback.print_exc()




if __name__ == "__main__":
# Directory to search
root_dir = 'abr_testing/protocols'
root_dir = "abr_testing/protocols"

exclude = [
'__init__.py',
'shared_vars_and_funcs.py',
"__init__.py",
"shared_vars_and_funcs.py",
]
# Walk through the root directory and its subdirectories
for root, dirs, files in os.walk(root_dir):
Expand All @@ -30,4 +31,4 @@ def run(file_to_simulate: Path):
continue
file_path = os.path.join(root, file)
print(f"Simulating protocol: {file_path}")
run(Path(file_path))
run(file_path)
Loading

0 comments on commit b34ecbf

Please sign in to comment.