add BIOYOND deck assignment and pass all tests

This commit is contained in:
Junhan Chang
2025-09-25 08:41:41 +08:00
parent 63ab1af45d
commit 5c47cd0c8a
5 changed files with 46 additions and 30 deletions

View File

@@ -4,8 +4,7 @@ from unilabos.resources.bioyond.bottle_carriers import BIOYOND_Electrolyte_6Vial
from unilabos.resources.bioyond.bottles import BIOYOND_PolymerStation_Solid_Vial, BIOYOND_PolymerStation_Solution_Beaker, BIOYOND_PolymerStation_Reagent_Bottle from unilabos.resources.bioyond.bottles import BIOYOND_PolymerStation_Solid_Vial, BIOYOND_PolymerStation_Solution_Beaker, BIOYOND_PolymerStation_Reagent_Bottle
@pytest.fixture def test_bottle_carrier() -> "BottleCarrier":
def bottle_carrier() -> "BottleCarrier":
print("创建载架...") print("创建载架...")
# 创建6瓶载架 # 创建6瓶载架
@@ -30,10 +29,10 @@ def bottle_carrier() -> "BottleCarrier":
print(f"\n测试放置容器...") print(f"\n测试放置容器...")
# 通过载架的索引操作来放置容器 # 通过载架的索引操作来放置容器
bottle_carrier[0] = powder_bottle # 放置粉末瓶到第一个位置 # bottle_carrier[0] = powder_bottle # 放置粉末瓶到第一个位置
print(f"粉末瓶已放置到6瓶载架的位置 0") print(f"粉末瓶已放置到6瓶载架的位置 0")
beaker_carrier[0] = solution_beaker # 放置烧杯到第一个位置 # beaker_carrier[0] = solution_beaker # 放置烧杯到第一个位置
print(f"溶液烧杯已放置到1烧杯载架的位置 0") print(f"溶液烧杯已放置到1烧杯载架的位置 0")
# 验证放置结果 # 验证放置结果

View File

@@ -5,6 +5,8 @@ import os
from unilabos.resources.graphio import resource_bioyond_to_plr from unilabos.resources.graphio import resource_bioyond_to_plr
from unilabos.registry.registry import lab_registry from unilabos.registry.registry import lab_registry
from unilabos.resources.bioyond.decks import BIOYOND_PolymerReactionStation_Deck
lab_registry.setup() lab_registry.setup()
@@ -25,7 +27,9 @@ def bioyond_materials() -> list[dict]:
def test_bioyond_to_plr(bioyond_materials) -> list[dict]: def test_bioyond_to_plr(bioyond_materials) -> list[dict]:
deck = BIOYOND_PolymerReactionStation_Deck("test_deck")
print("将 BioYond 物料数据转换为 PLR 格式...") print("将 BioYond 物料数据转换为 PLR 格式...")
output = resource_bioyond_to_plr(bioyond_materials, type_mapping=type_mapping) output = resource_bioyond_to_plr(bioyond_materials, type_mapping=type_mapping, deck=deck)
print(deck.summary())
print([resource.serialize() for resource in output]) print([resource.serialize() for resource in output])
print([resource.serialize_all_state() for resource in output]) print([resource.serialize_all_state() for resource in output])

View File

@@ -6,19 +6,21 @@ from unilabos.resources.bioyond.warehouses import bioyond_warehouse_1x4x4, bioyo
class BIOYOND_PolymerReactionStation_Deck(Deck): class BIOYOND_PolymerReactionStation_Deck(Deck):
def __init__(self, name: str = "PolymerReactionStation_Deck") -> None: def __init__(self, name: str = "PolymerReactionStation_Deck") -> None:
super().__init__(name=name, size_x=2700.0, size_y=1080.0, size_z=1500.0) super().__init__(name=name, size_x=2700.0, size_y=1080.0, size_z=1500.0)
self.setup()
def setup(self) -> None: def setup(self) -> None:
# 添加仓库 # 添加仓库
self.warehouses = { self.warehouses = {
"io_warehouse_left": bioyond_warehouse_1x4x4("io_warehouse_left"), "堆栈1": bioyond_warehouse_1x4x4("堆栈1"),
"io_warehouse_right": bioyond_warehouse_1x4x4("io_warehouse_right"), "堆栈2": bioyond_warehouse_1x4x4("堆栈2"),
"liquid_and_lid_handling": bioyond_warehouse_liquid_and_lid_handling("liquid_and_lid_handling"), "站内试剂存放堆栈": bioyond_warehouse_liquid_and_lid_handling("站内试剂存放堆栈"),
} }
self.warehouse_locations = { self.warehouse_locations = {
"io_warehouse_left": Coordinate(0.0, 650.0, 0.0), "堆栈1": Coordinate(0.0, 650.0, 0.0),
"io_warehouse_right": Coordinate(2550.0, 650.0, 0.0), "堆栈2": Coordinate(2550.0, 650.0, 0.0),
"liquid_and_lid_handling": Coordinate(800.0, 475.0, 0.0), "站内试剂存放堆栈": Coordinate(800.0, 475.0, 0.0),
} }
self.warehouses["站内试剂存放堆栈"].rotation = 90.0
for warehouse_name, warehouse in self.warehouses.items(): for warehouse_name, warehouse in self.warehouses.items():
self.assign_child_resource(warehouse, location=self.warehouse_locations[warehouse_name]) self.assign_child_resource(warehouse, location=self.warehouse_locations[warehouse_name])

View File

@@ -8,12 +8,12 @@ def bioyond_warehouse_1x4x4(name: str) -> WareHouse:
num_items_x=1, num_items_x=1,
num_items_y=4, num_items_y=4,
num_items_z=4, num_items_z=4,
dx=137.0, dx=10.0,
dy=96.0, dy=10.0,
dz=120.0, dz=10.0,
item_dx=10.0, item_dx=137.0,
item_dy=10.0, item_dy=96.0,
item_dz=10.0, item_dz=120.0,
category="warehouse", category="warehouse",
) )
@@ -25,12 +25,12 @@ def bioyond_warehouse_1x4x2(name: str) -> WareHouse:
num_items_x=1, num_items_x=1,
num_items_y=4, num_items_y=4,
num_items_z=2, num_items_z=2,
dx=137.0, dx=10.0,
dy=96.0, dy=10.0,
dz=120.0, dz=10.0,
item_dx=10.0, item_dx=137.0,
item_dy=10.0, item_dy=96.0,
item_dz=10.0, item_dz=120.0,
category="warehouse", category="warehouse",
removed_positions=None removed_positions=None
) )
@@ -43,12 +43,12 @@ def bioyond_warehouse_liquid_and_lid_handling(name: str) -> WareHouse:
num_items_x=2, num_items_x=2,
num_items_y=5, num_items_y=5,
num_items_z=1, num_items_z=1,
dx=137.0, dx=10.0,
dy=96.0, dy=10.0,
dz=120.0, dz=10.0,
item_dx=10.0, item_dx=137.0,
item_dy=10.0, item_dy=96.0,
item_dz=10.0, item_dz=120.0,
category="warehouse", category="warehouse",
removed_positions=None removed_positions=None
) )

View File

@@ -480,7 +480,7 @@ def resource_plr_to_ulab(resource_plr: "ResourcePLR", parent_name: str = None, w
return r return r
def resource_bioyond_to_plr(bioyond_materials: list[dict], type_mapping: dict = {}, location_id_mapping: dict = None) -> list[dict]: def resource_bioyond_to_plr(bioyond_materials: list[dict], type_mapping: dict = {}, deck: Any = None) -> list[dict]:
""" """
将 bioyond 物料格式转换为 ulab 物料格式 将 bioyond 物料格式转换为 ulab 物料格式
@@ -513,6 +513,17 @@ def resource_bioyond_to_plr(bioyond_materials: list[dict], type_mapping: dict =
plr_materials.append(plr_material) plr_materials.append(plr_material)
if deck and hasattr(deck, "warehouses"):
for loc in material.get("locations", []):
if hasattr(deck, "warehouses") and loc.get("whName") in deck.warehouses:
warehouse = deck.warehouses[loc["whName"]]
idx = (loc.get("y", 0) - 1) * warehouse.num_items_x * warehouse.num_items_y + \
(loc.get("x", 0) - 1) * warehouse.num_items_x + \
(loc.get("z", 0) - 1)
if 0 <= idx < warehouse.num_items_x * warehouse.num_items_y * warehouse.num_items_z:
if warehouse[idx].resource is None:
warehouse[idx] = plr_material
return plr_materials return plr_materials