diff --git a/abr-testing/abr_testing/tools/abr_scale.py b/abr-testing/abr_testing/tools/abr_scale.py index 8f2f46a7757..89e85bc0132 100644 --- a/abr-testing/abr_testing/tools/abr_scale.py +++ b/abr-testing/abr_testing/tools/abr_scale.py @@ -9,9 +9,12 @@ import requests from typing import Any, Tuple import sys +import json -def get_protocol_step_as_int() -> Tuple[int, float, str]: +def get_protocol_step_as_int( + storage_directory: str, robot: str +) -> Tuple[int, float, str]: """Get user input as integer.""" expected_liquid_moved = 0.0 ip = "" @@ -26,14 +29,25 @@ def get_protocol_step_as_int() -> Tuple[int, float, str]: print("Protocol step should be an integer value 1, 2, or 3.") if int(protocol_step) == 3: - ip = input("Robot IP: ") - while True: - try: - expected_liquid_moved = float(input("Expected volume moved: ")) - if expected_liquid_moved >= 0 or expected_liquid_moved <= 0: - break - except ValueError: - print("Expected liquid moved volume should be an float.") + # setup IP sheet + ip_json_file = os.path.join(storage_directory, "IP_N_VOLUMES.json") + # create an dict copying the contents of IP_N_Volumes + try: + ip_file = json.load(open(ip_json_file)) + except FileNotFoundError: + print( + f"Please add json file with robot IPs and expected volumes to: {storage_directory}." + ) + sys.exit() + # grab IP and volume from the dict + tot_info = ip_file["information"] + robot_info = tot_info[robot] + IP_add = robot_info["IP"] + exp_volume = robot_info["volume"] + # sets return variables equal to those grabbed from the sheet + ip = IP_add + expected_liquid_moved = float(exp_volume) + return protocol_step, expected_liquid_moved, ip @@ -168,8 +182,11 @@ def get_most_recent_run_and_record( ) robot = input("Robot: ") labware = input("Labware: ") - protocol_step, expected_liquid_moved, ip = get_protocol_step_as_int() - + protocol_step, expected_liquid_moved, ip = get_protocol_step_as_int( + storage_directory, robot + ) + print(ip) + print(expected_liquid_moved) # Scale Loop grams, is_stable = scale.read_mass() grams, is_stable = scale.read_mass() @@ -197,16 +214,23 @@ def get_most_recent_run_and_record( get_most_recent_run_and_record(ip, storage_directory, labware, accuracy) is_stable = False - y_or_no = input("Do you want to weigh another sample? (Y/N): ") - if y_or_no == "Y": - # Uses same storage directory and file. - grams, is_stable = scale.read_mass() - is_stable = False - robot = input("Robot: ") - labware = input("Labware: ") - protocol_step, expected_liquid_moved, ip = get_protocol_step_as_int() - grams, is_stable = scale.read_mass() - elif y_or_no == "N": - break_all = True + while True: + y_or_no = input("Do you want to weigh another sample? (Y/N): ") + if y_or_no == "Y" or y_or_no == "y": + # Uses same storage directory and file. + grams, is_stable = scale.read_mass() + is_stable = False + robot = input("Robot: ") + labware = input("Labware: ") + protocol_step, expected_liquid_moved, ip = get_protocol_step_as_int( + storage_directory, robot + ) + grams, is_stable = scale.read_mass() + break + elif y_or_no == "N" or y_or_no == "n": + break_all = True + break + else: + print("Please Choose a Valid Option") if break_all: break