mirror of
https://github.com/dptech-corp/Uni-Lab-OS.git
synced 2025-12-18 05:21:19 +00:00
Merge branch 'main' into pr/39
This commit is contained in:
@@ -189,6 +189,7 @@ def dict_from_graph(graph: nx.Graph) -> dict:
|
||||
def dict_to_tree(nodes: dict, devices_only: bool = False) -> list[dict]:
|
||||
# 将节点转换为字典,以便通过 ID 快速查找
|
||||
nodes_list = [node for node in nodes.values() if node.get("type") == "device" or not devices_only]
|
||||
id_list = [node["id"] for node in nodes_list]
|
||||
|
||||
# 初始化每个节点的 children 为包含节点字典的列表
|
||||
for node in nodes_list:
|
||||
@@ -196,7 +197,7 @@ def dict_to_tree(nodes: dict, devices_only: bool = False) -> list[dict]:
|
||||
|
||||
# 找到根节点并返回
|
||||
root_nodes = [
|
||||
node for node in nodes_list if len(nodes_list) == 1 or node.get("parent", node.get("parent_name")) in [None, "", "None", np.nan]
|
||||
node for node in nodes_list if len(nodes_list) == 1 or node.get("parent", node.get("parent_name")) in [None, "", "None", np.nan] or node.get("parent", node.get("parent_name")) not in id_list
|
||||
]
|
||||
|
||||
# 如果存在多个根节点,返回所有根节点
|
||||
@@ -430,7 +431,7 @@ def resource_plr_to_ulab(resource_plr: "ResourcePLR", parent_name: str = None):
|
||||
return r
|
||||
|
||||
|
||||
def initialize_resource(resource_config: dict, lab_registry: dict) -> list[dict]:
|
||||
def initialize_resource(resource_config: dict) -> list[dict]:
|
||||
"""Initializes a resource based on its configuration.
|
||||
|
||||
If the config is detailed, then do nothing;
|
||||
@@ -442,6 +443,7 @@ def initialize_resource(resource_config: dict, lab_registry: dict) -> list[dict]
|
||||
Returns:
|
||||
None
|
||||
"""
|
||||
from unilabos.registry.registry import lab_registry
|
||||
resource_class_config = resource_config.get("class", None)
|
||||
if resource_class_config is None:
|
||||
return [resource_config]
|
||||
@@ -485,11 +487,8 @@ def initialize_resources(resources_config) -> list[dict]:
|
||||
None
|
||||
"""
|
||||
|
||||
from unilabos.registry.registry import lab_registry
|
||||
resources = []
|
||||
for resource_config in resources_config:
|
||||
if resource_config["parent"] == "tip_rack" or resource_config["parent"] == "plate_well":
|
||||
continue
|
||||
resources.extend(initialize_resource(resource_config, lab_registry))
|
||||
resources.extend(initialize_resource(resource_config))
|
||||
|
||||
return resources
|
||||
|
||||
Reference in New Issue
Block a user