mirror of
https://github.com/dptech-corp/Uni-Lab-OS.git
synced 2026-02-12 18:55:11 +00:00
Compare commits
2 Commits
f8ef6e0686
...
f13156e792
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f13156e792 | ||
|
|
13fd1ac572 |
@@ -66,7 +66,6 @@ class HTTPClient:
|
||||
|
||||
Args:
|
||||
resources: 要添加的资源列表
|
||||
database_process_later: 后台处理资源
|
||||
Returns:
|
||||
Response: API响应对象
|
||||
"""
|
||||
@@ -131,14 +130,19 @@ class HTTPClient:
|
||||
Returns:
|
||||
Response: API响应对象
|
||||
"""
|
||||
return self.resource_add(resources)
|
||||
response = requests.patch(
|
||||
f"{self.remote_addr}/lab/resource/batch_update/?edge_format=1",
|
||||
response = requests.put(
|
||||
f"{self.remote_addr}/lab/material",
|
||||
json=resources,
|
||||
headers={"Authorization": f"Lab {self.auth}"},
|
||||
timeout=100,
|
||||
)
|
||||
return response
|
||||
if response.status_code == 200:
|
||||
res = response.json()
|
||||
if "code" in res and res["code"] != 0:
|
||||
logger.error(f"添加物料失败: {response.text}")
|
||||
if response.status_code != 200:
|
||||
logger.error(f"添加物料失败: {response.text}")
|
||||
return response.json()
|
||||
|
||||
def upload_file(self, file_path: str, scene: str = "models") -> requests.Response:
|
||||
"""
|
||||
|
||||
@@ -1093,7 +1093,7 @@ class WebSocketClient(BaseCommunicationClient):
|
||||
},
|
||||
}
|
||||
self.message_processor.send_message(message)
|
||||
logger.trace(f"[WebSocketClient] Device status published: {device_id}.{property_name}")
|
||||
logger.debug(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
|
||||
|
||||
@@ -218,14 +218,20 @@ 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]
|
||||
is_root = {node["id"]: True for node in nodes_list}
|
||||
|
||||
# 初始化每个节点的 children 为包含节点字典的列表
|
||||
for node in nodes_list:
|
||||
node["children"] = [nodes[child_id] for child_id in node.get("children", [])]
|
||||
for child_id in node.get("children", []):
|
||||
if child_id in is_root:
|
||||
is_root[child_id] = False
|
||||
|
||||
# 找到根节点并返回
|
||||
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] or node.get("parent", node.get("parent_name")) not in id_list
|
||||
node
|
||||
for node in nodes_list
|
||||
if is_root.get(node["id"], False) or len(nodes_list) == 1
|
||||
]
|
||||
|
||||
# 如果存在多个根节点,返回所有根节点
|
||||
@@ -235,6 +241,7 @@ def dict_to_tree(nodes: dict, devices_only: bool = False) -> list[dict]:
|
||||
def dict_to_nested_dict(nodes: dict, devices_only: bool = False) -> dict:
|
||||
# 将节点转换为字典,以便通过 ID 快速查找
|
||||
nodes_list = [node for node in nodes.values() if node.get("type") == "device" or not devices_only]
|
||||
is_root = {node["id"]: True for node in nodes_list}
|
||||
|
||||
# 初始化每个节点的 children 为包含节点字典的列表
|
||||
for node in nodes_list:
|
||||
@@ -243,14 +250,17 @@ def dict_to_nested_dict(nodes: dict, devices_only: bool = False) -> dict:
|
||||
for child_id in node.get("children", [])
|
||||
if nodes[child_id].get("type") == "device" or not devices_only
|
||||
}
|
||||
if len(node["children"]) > 0 and node["type"].lower() == "device" and devices_only:
|
||||
for child_id in node.get("children", []):
|
||||
if child_id in is_root:
|
||||
is_root[child_id] = False
|
||||
if len(node["children"]) > 0 and node["type"].lower() == "device":
|
||||
node["config"]["children"] = node["children"]
|
||||
|
||||
# 找到根节点并返回
|
||||
root_nodes = {
|
||||
node["id"]: node
|
||||
for node in nodes_list
|
||||
if node.get("parent", node.get("parent_name")) in [None, "", "None", np.nan] or len(nodes_list) == 1
|
||||
if is_root.get(node["id"], False) or len(nodes_list) == 1
|
||||
}
|
||||
|
||||
# 如果存在多个根节点,返回所有根节点
|
||||
|
||||
Reference in New Issue
Block a user