-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'add_modules_to_deck_config' of https://github.com/Opent…
…rons/opentrons into add_modules_to_deck_config
- Loading branch information
Showing
198 changed files
with
3,571 additions
and
1,269 deletions.
There are no files selected for viewing
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
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
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
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
154 changes: 154 additions & 0 deletions
154
abr-testing/abr_testing/data_collection/module_ramp_rates.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,154 @@ | ||
"""Get ramp rates of modules.""" | ||
from abr_testing.automation import google_sheets_tool | ||
from abr_testing.data_collection import read_robot_logs | ||
import gspread # type: ignore[import] | ||
import argparse | ||
import os | ||
import sys | ||
import json | ||
from datetime import datetime | ||
from typing import Dict, Any | ||
import requests | ||
|
||
|
||
def ramp_rate(file_results: Dict[str, Any]) -> Dict[int, float]: | ||
"""Get ramp rates.""" | ||
i = 0 | ||
commands = file_results["commands"] | ||
for command in commands: | ||
commandType = command["commandType"] | ||
if ( | ||
commandType == "thermocycler/setTargetBlockTemperature" | ||
or commandType == "temperatureModule/setTargetTemperature" | ||
or commandType == "heaterShaker/setTargetTemperature" | ||
): | ||
temp = command["params"].get("celsius", 0.0) | ||
if ( | ||
commandType == "thermocycler/waitForBlockTemperature" | ||
or commandType == "temperatureModule/waitForTemperature" | ||
or commandType == "heaterShaker/waitForTemperature" | ||
): | ||
start_time = datetime.strptime( | ||
command.get("startedAt", ""), "%Y-%m-%dT%H:%M:%S.%f%z" | ||
) | ||
end_time = datetime.strptime( | ||
command.get("completedAt", ""), "%Y-%m-%dT%H:%M:%S.%f%z" | ||
) | ||
duration = (end_time - start_time).total_seconds() | ||
i += 1 | ||
temps_and_durations[duration] = temp | ||
ramp_rates = {} | ||
times = list(temps_and_durations.keys()) | ||
for i in range(len(times) - 1): | ||
time1 = times[i] | ||
time2 = times[i + 1] | ||
temp1 = temps_and_durations[time1] | ||
temp2 = temps_and_durations[time2] | ||
ramp_rate = (temp2 - temp1) / (time2) | ||
ramp_rates[i] = ramp_rate | ||
return ramp_rates | ||
|
||
|
||
if __name__ == "__main__": | ||
# SCRIPT ARGUMENTS | ||
parser = argparse.ArgumentParser(description="Read run logs on google drive.") | ||
parser.add_argument( | ||
"storage_directory", | ||
metavar="STORAGE_DIRECTORY", | ||
type=str, | ||
nargs=1, | ||
help="Path to long term storage directory for run logs.", | ||
) | ||
parser.add_argument( | ||
"google_sheet_name", | ||
metavar="GOOGLE_SHEET_NAME", | ||
type=str, | ||
nargs=1, | ||
help="Google sheet name.", | ||
) | ||
parser.add_argument( | ||
"email", metavar="EMAIL", type=str, nargs=1, help="opentrons gmail." | ||
) | ||
args = parser.parse_args() | ||
storage_directory = args.storage_directory[0] | ||
google_sheet_name = args.google_sheet_name[0] | ||
# FIND CREDENTIALS FILE | ||
try: | ||
credentials_path = os.path.join(storage_directory, "credentials.json") | ||
except FileNotFoundError: | ||
print(f"Add credentials.json file to: {storage_directory}.") | ||
sys.exit() | ||
# CONNECT TO GOOGLE SHEET | ||
try: | ||
google_sheet = google_sheets_tool.google_sheet( | ||
credentials_path, google_sheet_name, 1 | ||
) | ||
print(f"Connected to google sheet: {google_sheet_name}") | ||
except gspread.exceptions.APIError: | ||
print("ERROR: Check google sheet name. Check credentials file.") | ||
sys.exit() | ||
run_ids_on_sheet = google_sheet.get_column(2) | ||
runs_and_robots = {} | ||
for filename in os.listdir(storage_directory): | ||
file_path = os.path.join(storage_directory, filename) | ||
if file_path.endswith(".json"): | ||
with open(file_path) as file: | ||
file_results = json.load(file) | ||
else: | ||
continue | ||
# CHECK if file is ramp rate run | ||
run_id = file_results.get("run_id", None) | ||
temps_and_durations: Dict[float, float] = dict() | ||
if run_id is not None and run_id not in run_ids_on_sheet: | ||
|
||
ramp_rates = ramp_rate(file_results) | ||
protocol_name = file_results["protocol"]["metadata"].get("protocolName", "") | ||
if "Ramp Rate" in protocol_name: | ||
ip = filename.split("_")[0] | ||
if len(ramp_rates) > 1: | ||
cooling_ramp_rate = abs(min(ramp_rates.values())) | ||
heating_ramp_rate = abs(max(ramp_rates.values())) | ||
start_time = datetime.strptime( | ||
file_results.get("startedAt", ""), "%Y-%m-%dT%H:%M:%S.%f%z" | ||
) | ||
start_date = str(start_time.date()) | ||
module_serial_number = file_results["modules"][0].get( | ||
"serialNumber", "NaN" | ||
) | ||
try: | ||
response = requests.get( | ||
f"http://{ip}:31950/modules", | ||
headers={"opentrons-version": "3"}, | ||
) | ||
modules = response.json() | ||
for module in modules["data"]: | ||
if module["serialNumber"] == module_serial_number: | ||
firmwareVersion = module["firmwareVersion"] | ||
else: | ||
firmwareVersion = "NaN" | ||
except requests.exceptions.ConnectionError: | ||
firmwareVersion = "NaN" | ||
row = { | ||
"Robot": file_results.get("robot_name", ""), | ||
"Run_ID": run_id, | ||
"Protocol_Name": file_results["protocol"]["metadata"].get( | ||
"protocolName", "" | ||
), | ||
"Software Version": file_results.get("API_Version", ""), | ||
"Firmware Version": firmwareVersion, | ||
"Date": start_date, | ||
"Serial Number": module_serial_number, | ||
"Approx. Average Heating Ramp Rate (C/s)": heating_ramp_rate, | ||
"Approx. Average Cooling Ramp Rate (C/s)": cooling_ramp_rate, | ||
} | ||
headers = list(row.keys()) | ||
runs_and_robots[run_id] = row | ||
read_robot_logs.write_to_local_and_google_sheet( | ||
runs_and_robots, | ||
storage_directory, | ||
google_sheet_name, | ||
google_sheet, | ||
headers, | ||
) | ||
else: | ||
continue |
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,28 @@ | ||
import { POST, request } from '../request' | ||
|
||
import type { ProtocolAnalysisSummary } from '@opentrons/shared-data' | ||
import type { ResponsePromise } from '../request' | ||
import type { HostConfig } from '../types' | ||
import type { RunTimeParameterCreateData } from '../runs' | ||
|
||
interface CreateProtocolAnalysisData { | ||
runTimeParameterValues: RunTimeParameterCreateData | ||
forceReAnalyze: boolean | ||
} | ||
|
||
export function createProtocolAnalysis( | ||
config: HostConfig, | ||
protocolKey: string, | ||
runTimeParameterValues?: RunTimeParameterCreateData, | ||
forceReAnalyze?: boolean | ||
): ResponsePromise<ProtocolAnalysisSummary[]> { | ||
const data = { | ||
runTimeParameterValues: runTimeParameterValues ?? {}, | ||
forceReAnalyze: forceReAnalyze ?? false, | ||
} | ||
const response = request< | ||
ProtocolAnalysisSummary[], | ||
{ data: CreateProtocolAnalysisData } | ||
>(POST, `/protocols/${protocolKey}/analyses`, { data }, config) | ||
return response | ||
} |
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
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,11 @@ | ||
import { GET, request } from '../request' | ||
|
||
import type { ResponsePromise } from '../request' | ||
import type { HostConfig } from '../types' | ||
import type { RobotSettingsResponse } from './types' | ||
|
||
export function getRobotSettings( | ||
config: HostConfig | ||
): ResponsePromise<RobotSettingsResponse> { | ||
return request<RobotSettingsResponse>(GET, '/settings', null, config) | ||
} |
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
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
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
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
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
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
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
Oops, something went wrong.