From 28f93737acea10d45e6a2dd0d6110d8777735ec5 Mon Sep 17 00:00:00 2001 From: Xuwznln <18435084+Xuwznln@users.noreply.github.com> Date: Sun, 28 Dec 2025 23:22:50 +0800 Subject: [PATCH] Close #208. Fix mock devices. --- unilabos/app/ws_client.py | 2 +- .../experiments/mock_devices/mock_all.json | 20 ++-- .../mock_devices/mock_chiller.json | 2 +- .../experiments/mock_devices/mock_filter.json | 2 +- .../experiments/mock_devices/mock_heater.json | 2 +- .../experiments/mock_devices/mock_pump.json | 2 +- .../mock_devices/mock_rotavap.json | 2 +- .../mock_devices/mock_separator.json | 2 +- .../mock_devices/mock_solenoid_valve.json | 2 +- .../mock_devices/mock_stirrer.json | 2 +- .../mock_devices/mock_stirrer_new.json | 2 +- .../experiments/mock_devices/mock_vacuum.json | 2 +- .../mock_protocol/centrifugeteststation.json | 2 +- .../mock_protocol/filterteststation.json | 2 +- .../mock_protocol/heatchillteststation.json | 2 +- .../mock_protocol/stirteststation.json | 2 +- unilabos/test/resources/__init__.py | 0 unilabos/test/ros/__init__.py | 0 unilabos/test/workflow/__init__.py | 0 unilabos/test/workflow/merge_workflow.py | 94 ------------------- 20 files changed, 25 insertions(+), 119 deletions(-) delete mode 100644 unilabos/test/resources/__init__.py delete mode 100644 unilabos/test/ros/__init__.py delete mode 100644 unilabos/test/workflow/__init__.py delete mode 100644 unilabos/test/workflow/merge_workflow.py diff --git a/unilabos/app/ws_client.py b/unilabos/app/ws_client.py index 50204a2..517892e 100644 --- a/unilabos/app/ws_client.py +++ b/unilabos/app/ws_client.py @@ -1243,7 +1243,7 @@ class WebSocketClient(BaseCommunicationClient): }, } self.message_processor.send_message(message) - logger.debug(f"[WebSocketClient] Device status published: {device_id}.{property_name}") + logger.trace(f"[WebSocketClient] Device status published: {device_id}.{property_name}") def publish_job_status( self, feedback_data: dict, item: QueueItem, status: str, return_info: Optional[dict] = None diff --git a/unilabos/test/experiments/mock_devices/mock_all.json b/unilabos/test/experiments/mock_devices/mock_all.json index 10d224f..7327b54 100644 --- a/unilabos/test/experiments/mock_devices/mock_all.json +++ b/unilabos/test/experiments/mock_devices/mock_all.json @@ -8,7 +8,7 @@ ], "parent": null, "type": "device", - "class": "mock_chiller", + "class": "virtual_heatchill", "position": { "x": 620.6111111111111, "y": 171, @@ -49,7 +49,7 @@ "children": [], "parent": null, "type": "device", - "class": "mock_filter", + "class": "virtual_filter", "position": { "x": 620.6111111111111, "y": 171, @@ -80,7 +80,7 @@ "children": [], "parent": null, "type": "device", - "class": "mock_heater", + "class": "virtual_heatchill", "position": { "x": 620.6111111111111, "y": 171, @@ -108,7 +108,7 @@ "children": [], "parent": null, "type": "device", - "class": "mock_pump", + "class": "virtual_transfer_pump", "position": { "x": 620.6111111111111, "y": 171, @@ -147,7 +147,7 @@ "children": [], "parent": null, "type": "device", - "class": "mock_rotavap", + "class": "virtual_rotavap", "position": { "x": 620.6111111111111, "y": 171, @@ -175,7 +175,7 @@ "children": [], "parent": null, "type": "device", - "class": "mock_separator", + "class": "virtual_separator", "position": { "x": 620.6111111111111, "y": 171, @@ -213,7 +213,7 @@ "children": [], "parent": null, "type": "device", - "class": "mock_solenoid_valve", + "class": "virtual_solenoid_valve", "position": { "x": 620.6111111111111, "y": 171, @@ -233,7 +233,7 @@ "children": [], "parent": null, "type": "device", - "class": "mock_stirrer_new", + "class": "virtual_stirrer", "position": { "x": 620.6111111111111, "y": 171, @@ -261,7 +261,7 @@ "children": [], "parent": null, "type": "device", - "class": "mock_stirrer", + "class": "virtual_stirrer", "position": { "x": 620.6111111111111, "y": 171, @@ -289,7 +289,7 @@ "children": [], "parent": null, "type": "device", - "class": "mock_vacuum", + "class": "virtual_vacuum_pump", "position": { "x": 620.6111111111111, "y": 171, diff --git a/unilabos/test/experiments/mock_devices/mock_chiller.json b/unilabos/test/experiments/mock_devices/mock_chiller.json index fc0e2f4..26e48d5 100644 --- a/unilabos/test/experiments/mock_devices/mock_chiller.json +++ b/unilabos/test/experiments/mock_devices/mock_chiller.json @@ -6,7 +6,7 @@ "children": [], "parent": null, "type": "device", - "class": "mock_chiller", + "class": "virtual_heatchill", "position": { "x": 620.6111111111111, "y": 171, diff --git a/unilabos/test/experiments/mock_devices/mock_filter.json b/unilabos/test/experiments/mock_devices/mock_filter.json index d8d8029..d58e8c7 100644 --- a/unilabos/test/experiments/mock_devices/mock_filter.json +++ b/unilabos/test/experiments/mock_devices/mock_filter.json @@ -6,7 +6,7 @@ "children": [], "parent": null, "type": "device", - "class": "mock_filter", + "class": "virtual_filter", "position": { "x": 620.6111111111111, "y": 171, diff --git a/unilabos/test/experiments/mock_devices/mock_heater.json b/unilabos/test/experiments/mock_devices/mock_heater.json index 1aca968..ebb82fd 100644 --- a/unilabos/test/experiments/mock_devices/mock_heater.json +++ b/unilabos/test/experiments/mock_devices/mock_heater.json @@ -6,7 +6,7 @@ "children": [], "parent": null, "type": "device", - "class": "mock_heater", + "class": "virtual_heatchill", "position": { "x": 620.6111111111111, "y": 171, diff --git a/unilabos/test/experiments/mock_devices/mock_pump.json b/unilabos/test/experiments/mock_devices/mock_pump.json index d1c1394..6b54670 100644 --- a/unilabos/test/experiments/mock_devices/mock_pump.json +++ b/unilabos/test/experiments/mock_devices/mock_pump.json @@ -6,7 +6,7 @@ "children": [], "parent": null, "type": "device", - "class": "mock_pump", + "class": "virtual_transfer_pump", "position": { "x": 620.6111111111111, "y": 171, diff --git a/unilabos/test/experiments/mock_devices/mock_rotavap.json b/unilabos/test/experiments/mock_devices/mock_rotavap.json index b28cfe2..04f0276 100644 --- a/unilabos/test/experiments/mock_devices/mock_rotavap.json +++ b/unilabos/test/experiments/mock_devices/mock_rotavap.json @@ -6,7 +6,7 @@ "children": [], "parent": null, "type": "device", - "class": "mock_rotavap", + "class": "virtual_rotavap", "position": { "x": 620.6111111111111, "y": 171, diff --git a/unilabos/test/experiments/mock_devices/mock_separator.json b/unilabos/test/experiments/mock_devices/mock_separator.json index 20f2671..2fc7ce7 100644 --- a/unilabos/test/experiments/mock_devices/mock_separator.json +++ b/unilabos/test/experiments/mock_devices/mock_separator.json @@ -6,7 +6,7 @@ "children": [], "parent": null, "type": "device", - "class": "mock_separator", + "class": "virtual_separator", "position": { "x": 620.6111111111111, "y": 171, diff --git a/unilabos/test/experiments/mock_devices/mock_solenoid_valve.json b/unilabos/test/experiments/mock_devices/mock_solenoid_valve.json index e4e23cc..50d60c7 100644 --- a/unilabos/test/experiments/mock_devices/mock_solenoid_valve.json +++ b/unilabos/test/experiments/mock_devices/mock_solenoid_valve.json @@ -6,7 +6,7 @@ "children": [], "parent": null, "type": "device", - "class": "mock_solenoid_valve", + "class": "virtual_solenoid_valve", "position": { "x": 620.6111111111111, "y": 171, diff --git a/unilabos/test/experiments/mock_devices/mock_stirrer.json b/unilabos/test/experiments/mock_devices/mock_stirrer.json index 9dfc59c..be419de 100644 --- a/unilabos/test/experiments/mock_devices/mock_stirrer.json +++ b/unilabos/test/experiments/mock_devices/mock_stirrer.json @@ -6,7 +6,7 @@ "children": [], "parent": null, "type": "device", - "class": "mock_stirrer", + "class": "virtual_stirrer", "position": { "x": 620.6111111111111, "y": 171, diff --git a/unilabos/test/experiments/mock_devices/mock_stirrer_new.json b/unilabos/test/experiments/mock_devices/mock_stirrer_new.json index 837b2fe..b0f58db 100644 --- a/unilabos/test/experiments/mock_devices/mock_stirrer_new.json +++ b/unilabos/test/experiments/mock_devices/mock_stirrer_new.json @@ -6,7 +6,7 @@ "children": [], "parent": null, "type": "device", - "class": "mock_stirrer_new", + "class": "virtual_stirrer", "position": { "x": 620.6111111111111, "y": 171, diff --git a/unilabos/test/experiments/mock_devices/mock_vacuum.json b/unilabos/test/experiments/mock_devices/mock_vacuum.json index 31406ae..66d4377 100644 --- a/unilabos/test/experiments/mock_devices/mock_vacuum.json +++ b/unilabos/test/experiments/mock_devices/mock_vacuum.json @@ -6,7 +6,7 @@ "children": [], "parent": null, "type": "device", - "class": "mock_vacuum", + "class": "virtual_vacuum_pump", "position": { "x": 620.6111111111111, "y": 171, diff --git a/unilabos/test/experiments/mock_protocol/centrifugeteststation.json b/unilabos/test/experiments/mock_protocol/centrifugeteststation.json index e691834..eefed3e 100644 --- a/unilabos/test/experiments/mock_protocol/centrifugeteststation.json +++ b/unilabos/test/experiments/mock_protocol/centrifugeteststation.json @@ -32,7 +32,7 @@ "children": [], "parent": "CentrifugeTestStation", "type": "device", - "class": "virtual_pump", + "class": "virtual_transfer_pump", "position": { "x": 520.6111111111111, "y": 300, diff --git a/unilabos/test/experiments/mock_protocol/filterteststation.json b/unilabos/test/experiments/mock_protocol/filterteststation.json index a816def..8069e80 100644 --- a/unilabos/test/experiments/mock_protocol/filterteststation.json +++ b/unilabos/test/experiments/mock_protocol/filterteststation.json @@ -32,7 +32,7 @@ "children": [], "parent": "FilterTestStation", "type": "device", - "class": "virtual_pump", + "class": "virtual_transfer_pump", "position": { "x": 520.6111111111111, "y": 300, diff --git a/unilabos/test/experiments/mock_protocol/heatchillteststation.json b/unilabos/test/experiments/mock_protocol/heatchillteststation.json index 9d243b8..f103e13 100644 --- a/unilabos/test/experiments/mock_protocol/heatchillteststation.json +++ b/unilabos/test/experiments/mock_protocol/heatchillteststation.json @@ -32,7 +32,7 @@ "children": [], "parent": "HeatChillTestStation", "type": "device", - "class": "virtual_pump", + "class": "virtual_transfer_pump", "position": { "x": 520.6111111111111, "y": 300, diff --git a/unilabos/test/experiments/mock_protocol/stirteststation.json b/unilabos/test/experiments/mock_protocol/stirteststation.json index 20694d1..4563c9c 100644 --- a/unilabos/test/experiments/mock_protocol/stirteststation.json +++ b/unilabos/test/experiments/mock_protocol/stirteststation.json @@ -32,7 +32,7 @@ "children": [], "parent": "StirTestStation", "type": "device", - "class": "virtual_pump", + "class": "virtual_transfer_pump", "position": { "x": 520.6111111111111, "y": 300, diff --git a/unilabos/test/resources/__init__.py b/unilabos/test/resources/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/unilabos/test/ros/__init__.py b/unilabos/test/ros/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/unilabos/test/workflow/__init__.py b/unilabos/test/workflow/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/unilabos/test/workflow/merge_workflow.py b/unilabos/test/workflow/merge_workflow.py deleted file mode 100644 index fb40976..0000000 --- a/unilabos/test/workflow/merge_workflow.py +++ /dev/null @@ -1,94 +0,0 @@ -import json -import sys -from datetime import datetime -from pathlib import Path - -ROOT_DIR = Path(__file__).resolve().parents[2] -if str(ROOT_DIR) not in sys.path: - sys.path.insert(0, str(ROOT_DIR)) - -import pytest - -from scripts.workflow import build_protocol_graph, draw_protocol_graph, draw_protocol_graph_with_ports - - -ROOT_DIR = Path(__file__).resolve().parents[2] -if str(ROOT_DIR) not in sys.path: - sys.path.insert(0, str(ROOT_DIR)) - - -def _normalize_steps(data): - normalized = [] - for step in data: - action = step.get("action") or step.get("operation") - if not action: - continue - raw_params = step.get("parameters") or step.get("action_args") or {} - params = dict(raw_params) - - if "source" in raw_params and "sources" not in raw_params: - params["sources"] = raw_params["source"] - if "target" in raw_params and "targets" not in raw_params: - params["targets"] = raw_params["target"] - - description = step.get("description") or step.get("purpose") - step_dict = {"action": action, "parameters": params} - if description: - step_dict["description"] = description - normalized.append(step_dict) - return normalized - - -def _normalize_labware(data): - labware = {} - for item in data: - reagent_name = item.get("reagent_name") - key = reagent_name or item.get("material_name") or item.get("name") - if not key: - continue - key = str(key) - idx = 1 - original_key = key - while key in labware: - idx += 1 - key = f"{original_key}_{idx}" - - labware[key] = { - "slot": item.get("positions") or item.get("slot"), - "labware": item.get("material_name") or item.get("labware"), - "well": item.get("well", []), - "type": item.get("type", "reagent"), - "role": item.get("role", ""), - "name": key, - } - return labware - - -@pytest.mark.parametrize("protocol_name", [ - "example_bio", - # "bioyond_materials_liquidhandling_1", - "example_prcxi", -]) -def test_build_protocol_graph(protocol_name): - data_path = Path(__file__).with_name(f"{protocol_name}.json") - with data_path.open("r", encoding="utf-8") as fp: - d = json.load(fp) - - if "workflow" in d and "reagent" in d: - protocol_steps = d["workflow"] - labware_info = d["reagent"] - elif "steps_info" in d and "labware_info" in d: - protocol_steps = _normalize_steps(d["steps_info"]) - labware_info = _normalize_labware(d["labware_info"]) - else: - raise ValueError("Unsupported protocol format") - - graph = build_protocol_graph( - labware_info=labware_info, - protocol_steps=protocol_steps, - workstation_name="PRCXi", - ) - timestamp = datetime.now().strftime("%Y%m%d_%H%M") - output_path = data_path.with_name(f"{protocol_name}_graph_{timestamp}.png") - draw_protocol_graph_with_ports(graph, str(output_path)) - print(graph) \ No newline at end of file