mirror of
https://github.com/deepmodeling/Uni-Lab-OS
synced 2026-05-25 08:40:03 +00:00
Compare commits
39 Commits
prcix9320
...
a1c0b83490
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a1c0b83490 | ||
|
|
570d6763c0 | ||
|
|
633c8b3d2c | ||
|
|
e6ee6fc964 | ||
|
|
765342c4ff | ||
|
|
3fc94c6720 | ||
|
|
d5f0bca643 | ||
|
|
de51b19e88 | ||
|
|
6b94bdd2da | ||
|
|
d009863c8c | ||
|
|
cae828ce74 | ||
|
|
5b9f77e81f | ||
|
|
7c83e1bd51 | ||
|
|
1f93740580 | ||
|
|
98c27cde40 | ||
|
|
18c3263e92 | ||
|
|
1519a7d985 | ||
|
|
96c3f5a3e5 | ||
|
|
927c7e95f5 | ||
|
|
16910fe25c | ||
|
|
c38987d94d | ||
|
|
e4132111bc | ||
|
|
211ee3027d | ||
|
|
32c195d875 | ||
|
|
f145dc04bb | ||
|
|
195fad9398 | ||
|
|
898ed5d34b | ||
|
|
60cbedc4b2 | ||
|
|
2d6a9f7db9 | ||
|
|
5dca3d8c3d | ||
|
|
37cbed722a | ||
|
|
132cffbe7c | ||
|
|
36e5ff804c | ||
|
|
eaf8ad5609 | ||
|
|
16122ad2fa | ||
|
|
d3fef85dd8 | ||
|
|
f77ac2a5e8 | ||
|
|
93ac55a65b | ||
|
|
af35debe38 |
@@ -1,9 +0,0 @@
|
|||||||
@echo off
|
|
||||||
setlocal enabledelayedexpansion
|
|
||||||
|
|
||||||
REM upgrade pip
|
|
||||||
"%PREFIX%\python.exe" -m pip install --upgrade pip
|
|
||||||
|
|
||||||
REM install extra deps
|
|
||||||
"%PREFIX%\python.exe" -m pip install paho-mqtt opentrons_shared_data
|
|
||||||
"%PREFIX%\python.exe" -m pip install git+https://github.com/Xuwznln/pylabrobot.git
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
set -euxo pipefail
|
|
||||||
|
|
||||||
# make sure pip is available
|
|
||||||
"$PREFIX/bin/python" -m pip install --upgrade pip
|
|
||||||
|
|
||||||
# install extra deps
|
|
||||||
"$PREFIX/bin/python" -m pip install paho-mqtt opentrons_shared_data
|
|
||||||
"$PREFIX/bin/python" -m pip install git+https://github.com/Xuwznln/pylabrobot.git
|
|
||||||
450
.cursor/skills/filter-workflow-by-tags/SKILL.md
Normal file
450
.cursor/skills/filter-workflow-by-tags/SKILL.md
Normal file
@@ -0,0 +1,450 @@
|
|||||||
|
---
|
||||||
|
name: filter-workflow-by-tags
|
||||||
|
description: Query backend workflow list, aggregate all tags, and filter workflows by domain/scenario requirements using tags. Use when the user wants to search workflows, find workflows by tags, list available workflow tags, filter workflows by category/domain/scenario, or mentions 工作流筛选/标签查询/workflow tags/按领域查找工作流.
|
||||||
|
---
|
||||||
|
# Uni-Lab 工作流标签筛选指南
|
||||||
|
|
||||||
|
通过 Uni-Lab 云端 API 查询工作流列表,汇总所有可用标签(tags),并根据领域和场景要求筛选工作流。
|
||||||
|
|
||||||
|
> **重要**:本指南中的 `Authorization: Lab <token>` 是 **Uni-Lab 平台专用的认证方式**,`Lab` 是 Uni-Lab 的 auth scheme 关键字,**不是** HTTP Basic 认证。请勿将其替换为 `Basic`。
|
||||||
|
|
||||||
|
## 使用模式识别
|
||||||
|
|
||||||
|
**用户可能一开始就给出场景目标**(如"我要做有机合成实验"、"找柱层析相关的 protocol")。此时:
|
||||||
|
|
||||||
|
1. **识别场景关键词** → 映射到可能的 tags(如 synthesis、organic、chromatography、purification)
|
||||||
|
2. **直接执行完整流程**(获取 ak/sk/addr → 拉取所有工作流 → 汇总 tags → 按场景筛选)
|
||||||
|
3. **展示筛选结果** → 引导用户从候选 workflow 中**选择明确的实验 protocol**
|
||||||
|
4. **如果用户确认某个 workflow** → 记录 `workflow_uuid`,准备对接“与其他 Skill 的协作”
|
||||||
|
|
||||||
|
**如果用户未给场景目标**,则按标准 checklist 询问筛选条件。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 前置条件
|
||||||
|
|
||||||
|
使用本指南前,**必须**先确认以下信息。如果缺少任何一项,**立即向用户询问并终止**,等补齐后再继续。
|
||||||
|
|
||||||
|
### 1. ak / sk → AUTH
|
||||||
|
|
||||||
|
询问用户的启动参数,从 `--ak` `--sk` 或 config.py 中获取。
|
||||||
|
|
||||||
|
生成 AUTH token:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python -c "import base64,sys; print('Authorization: Lab ' + base64.b64encode(f'{sys.argv[1]}:{sys.argv[2]}'.encode()).decode())" <ak> <sk>
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. --addr → BASE URL
|
||||||
|
|
||||||
|
| `--addr` 值 | BASE |
|
||||||
|
| ------------- | ------------------------------------- |
|
||||||
|
| `test` | `https://leap-lab.test.bohrium.com` |
|
||||||
|
| `uat` | `https://leap-lab.uat.bohrium.com` |
|
||||||
|
| `local` | `http://127.0.0.1:48197` |
|
||||||
|
| 不传(默认) | `https://leap-lab.bohrium.com` |
|
||||||
|
|
||||||
|
确认后设置:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
BASE="<根据 addr 确定的 URL>"
|
||||||
|
AUTH="Authorization: Lab <上面命令输出的 token>"
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. lab_uuid(实验室 UUID)
|
||||||
|
|
||||||
|
如果用户未提供 `lab_uuid`,通过以下 API 自动获取:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X GET "$BASE/api/v1/edge/lab/info" -H "$AUTH"
|
||||||
|
```
|
||||||
|
|
||||||
|
返回 `data.uuid` 即为 `lab_uuid`。
|
||||||
|
|
||||||
|
**三项全部就绪后才可开始。**
|
||||||
|
|
||||||
|
## Session State
|
||||||
|
|
||||||
|
在整个对话过程中,agent 需要记住以下状态:
|
||||||
|
|
||||||
|
- `lab_uuid` — 实验室 UUID
|
||||||
|
- `all_workflows` — 完整工作流列表(分页获取后缓存到内存或临时文件)
|
||||||
|
- `all_tags` — 所有工作流的标签汇总
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## API 端点
|
||||||
|
|
||||||
|
### 查询工作流列表(支持分页)
|
||||||
|
|
||||||
|
```
|
||||||
|
GET $BASE/api/v1/lab/workflow/owner/list?page=<page>&page_size=<page_size>&lab_uuid=$lab_uuid
|
||||||
|
```
|
||||||
|
|
||||||
|
**参数:**
|
||||||
|
|
||||||
|
- `page` — 页码,从 1 开始
|
||||||
|
- `page_size` — 每页数量,建议 1000
|
||||||
|
- `lab_uuid` — 实验室 UUID
|
||||||
|
|
||||||
|
**返回结构:**
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"code": 0,
|
||||||
|
"data": {
|
||||||
|
"has_more": true,
|
||||||
|
"data": [
|
||||||
|
{
|
||||||
|
"uuid": "9661bba2-1b9f-4687-a63d-910245df174b",
|
||||||
|
"name": "Untitled",
|
||||||
|
"description": "",
|
||||||
|
"user_id": "114211",
|
||||||
|
"published": false,
|
||||||
|
"tags": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"uuid": "e0436638-190b-46bc-b1a1-2711d9602f6a",
|
||||||
|
"name": "Synthesis v2",
|
||||||
|
"user_id": "114211",
|
||||||
|
"published": true,
|
||||||
|
"tags": ["synthesis", "organic"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**字段说明:**
|
||||||
|
|
||||||
|
- `has_more` — 若为 `true`,需要继续请求 `page+1`
|
||||||
|
- `tags` — 可能为 `null`、空数组或字符串数组;聚合时必须容忍 `null`
|
||||||
|
|
||||||
|
### 启动工作流(直接运行)
|
||||||
|
|
||||||
|
```
|
||||||
|
POST $BASE/api/v1/lab/workflow/<workflow_uuid>/run
|
||||||
|
```
|
||||||
|
|
||||||
|
**用途:** 直接启动一个 workflow 的默认执行(使用模板中预设的参数),无需创建 notebook。适用于快速测试或无参数变化的重复执行。
|
||||||
|
|
||||||
|
**请求体:** 空 JSON `{}` 或省略
|
||||||
|
|
||||||
|
**返回:**
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"code": 0,
|
||||||
|
"data": "<run_uuid>"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- `run_uuid` — 本次执行的唯一标识(不是 notebook UUID)
|
||||||
|
|
||||||
|
**注意:**
|
||||||
|
|
||||||
|
- 该接口会使用 workflow 模板中保存的默认参数直接执行
|
||||||
|
- 如果 workflow 需要动态参数(如 CSV 路径、样品 UUID),应使用 `POST /lab/notebook` 创建 notebook 并传入 `node_params`
|
||||||
|
- 返回的 `run_uuid` 可直接传入下方「查询任务状态」接口查询实时进度
|
||||||
|
|
||||||
|
### 查询任务状态
|
||||||
|
|
||||||
|
```
|
||||||
|
GET $BASE/api/v1/lab/mcp/task/<task_uuid>
|
||||||
|
```
|
||||||
|
|
||||||
|
**用途:** 查询由 `POST /lab/workflow/<uuid>/run` 返回的 `run_uuid`(即 task_uuid)的实时执行状态,包括整体状态和每个节点(JOS:Job On Station)的执行详情。
|
||||||
|
|
||||||
|
**路径参数:**
|
||||||
|
|
||||||
|
- `task_uuid` — 等同于启动工作流接口返回的 `run_uuid`
|
||||||
|
|
||||||
|
**返回:**
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"code": 0,
|
||||||
|
"data": {
|
||||||
|
"status": "running",
|
||||||
|
"jos_status": [
|
||||||
|
{
|
||||||
|
"uuid": "d0e24bfe-8d99-450e-b19d-f25849dfbaad",
|
||||||
|
"node_name": "PRCXI_BioER_96_wellplate_slot_1",
|
||||||
|
"action_name": "create_resource",
|
||||||
|
"status": "success",
|
||||||
|
"return_info": {
|
||||||
|
"suc": true,
|
||||||
|
"error": "",
|
||||||
|
"return_value": { ... }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"uuid": "...",
|
||||||
|
"node_name": "...",
|
||||||
|
"action_name": "transfer_liquid",
|
||||||
|
"status": "pending",
|
||||||
|
"return_info": null
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**字段说明:**
|
||||||
|
|
||||||
|
- `data.status` — 整体任务状态
|
||||||
|
- `running` — 正在执行(至少一个节点 pending 或 running)
|
||||||
|
- `success` — 全部节点成功
|
||||||
|
- `failed` — 有节点失败
|
||||||
|
- `data.jos_status[]` — 节点级执行列表(按执行顺序)
|
||||||
|
- `uuid` — 节点执行实例 UUID
|
||||||
|
- `node_name` — 节点名称(资源/设备名或工位名)
|
||||||
|
- `action_name` — 动作类型(`create_resource`、`transfer_liquid`、`centrifuge`、等)
|
||||||
|
- `status` — 节点状态:`success`、`pending`、`running`、`failed`
|
||||||
|
- `return_info` — 执行返回,失败时 `suc=false` 且 `error` 有错误信息
|
||||||
|
|
||||||
|
**注意:**
|
||||||
|
|
||||||
|
- 此接口的 `task_uuid` **是** `POST /lab/workflow/<uuid>/run` 返回的 `run_uuid`,二者为同一个 ID 的不同称呼
|
||||||
|
- **不要**把 notebook UUID(`POST /lab/notebook` 返回)传进来——那条路径用 `GET /lab/notebook/status` 查询
|
||||||
|
- `jos_status` 数组按节点执行顺序给出;从 pending 数量可以估算剩余进度
|
||||||
|
- 返回体可能较大(`return_info.return_value` 中可能包含完整 resource tree),可在脚本中只提取 `status` + `node_name` + `action_name` 做摘要
|
||||||
|
|
||||||
|
**状态轮询示例:**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 每 5 秒轮询一次直至完成
|
||||||
|
TASK="b183d97e-d2b5-4b24-b14b-820df04d87c0"
|
||||||
|
while :; do
|
||||||
|
st=$(curl -s -X GET "$BASE/api/v1/lab/mcp/task/$TASK" -H "$AUTH" \
|
||||||
|
| python3 -c "import json,sys; d=json.load(sys.stdin)['data']; \
|
||||||
|
print(d['status'], '|', sum(1 for j in d['jos_status'] if j['status']=='success'), '/', len(d['jos_status']))")
|
||||||
|
echo "$(date +%H:%M:%S) $st"
|
||||||
|
[[ "$st" == success* || "$st" == failed* ]] && break
|
||||||
|
sleep 5
|
||||||
|
done
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 完整工作流 Checklist
|
||||||
|
|
||||||
|
```
|
||||||
|
Task Progress:
|
||||||
|
- [ ] Step 0: 识别用户是否已给出场景目标(如"有机合成"、"柱层析")
|
||||||
|
- 若已给出 → 记录场景关键词,自动进入后续步骤
|
||||||
|
- 若未给出 → 在 Step 6 询问用户
|
||||||
|
- [ ] Step 1: 确认 ak/sk → 生成 AUTH token
|
||||||
|
- [ ] Step 2: 确认 --addr → 设置 BASE URL
|
||||||
|
- [ ] Step 3: GET /edge/lab/info → 获取 lab_uuid(如用户未提供)
|
||||||
|
- [ ] Step 4: 分页获取所有工作流(从 page=1 开始直到 has_more=false)
|
||||||
|
- [ ] Step 5: 汇总所有非空 tags → 生成 all_tags(去重、排序、附出现次数)
|
||||||
|
- [ ] Step 6: 根据场景关键词(Step 0 或新询问)在 all_tags 中做语义映射 → 确定候选 tags
|
||||||
|
- 若语义映射不唯一,列出候选 tags 让用户确认
|
||||||
|
- [ ] Step 7: 按候选 tags 筛选工作流(默认 any 模式,召回优先)
|
||||||
|
- [ ] Step 8: 展示筛选结果(uuid、name、description、tags、published)
|
||||||
|
- [ ] Step 9: 引导用户从结果中选择**明确的实验 protocol**
|
||||||
|
- 若结果只有 1 条 → 直接确认该 workflow_uuid
|
||||||
|
- 若结果 2–10 条 → 让用户按编号选择
|
||||||
|
- 若结果过多 → 提示收紧条件(加 tag、切换 all 模式、仅 published)
|
||||||
|
- 若结果为空 → 放宽条件(去掉最稀有 tag)或提示用户换关键词
|
||||||
|
- [ ] Step 10: 记录用户选中的 workflow_uuid,并提示提交实验或查看详情
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 推荐路径:使用脚本
|
||||||
|
|
||||||
|
同目录下提供 `scripts/filter_workflows.py`,一次完成分页抓取、标签聚合与筛选:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 1. 仅汇总标签(不筛选)
|
||||||
|
python scripts/filter_workflows.py \
|
||||||
|
--auth "<Lab base64token>" \
|
||||||
|
--base "$BASE" \
|
||||||
|
--lab-uuid "$lab_uuid" \
|
||||||
|
--summary-only
|
||||||
|
|
||||||
|
# 2. 按标签筛选(ANY 模式:包含任一)
|
||||||
|
python scripts/filter_workflows.py \
|
||||||
|
--auth "<Lab base64token>" \
|
||||||
|
--base "$BASE" \
|
||||||
|
--lab-uuid "$lab_uuid" \
|
||||||
|
--tags synthesis organic \
|
||||||
|
--mode any
|
||||||
|
|
||||||
|
# 3. 按标签筛选(ALL 模式:必须同时包含)
|
||||||
|
python scripts/filter_workflows.py \
|
||||||
|
--auth "<Lab base64token>" \
|
||||||
|
--base "$BASE" \
|
||||||
|
--lab-uuid "$lab_uuid" \
|
||||||
|
--tags synthesis organic \
|
||||||
|
--mode all \
|
||||||
|
--output filtered.json
|
||||||
|
|
||||||
|
# 4. 仅筛选已发布
|
||||||
|
python scripts/filter_workflows.py \
|
||||||
|
--auth "<Lab base64token>" \
|
||||||
|
--base "$BASE" \
|
||||||
|
--lab-uuid "$lab_uuid" \
|
||||||
|
--tags synthesis \
|
||||||
|
--published-only
|
||||||
|
```
|
||||||
|
|
||||||
|
**`--auth` 参数说明**:传入 `Authorization` 头中 `Lab` 之后的 base64 token(不带 `Lab ` 前缀),脚本内部会自动补上 scheme。
|
||||||
|
|
||||||
|
**输出结构:**
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"total_workflows": 150,
|
||||||
|
"tag_counts": {"synthesis": 12, "organic": 8, "analysis": 5},
|
||||||
|
"all_tags": ["analysis", "organic", "synthesis"],
|
||||||
|
"filter": {"tags": ["synthesis", "organic"], "mode": "any"},
|
||||||
|
"filtered_workflows": [
|
||||||
|
{"uuid": "...", "name": "...", "description": "...", "tags": [...], "published": true}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 手动路径:curl + jq
|
||||||
|
|
||||||
|
如果脚本不可用或环境缺少 Python,可用 shell 实现。
|
||||||
|
|
||||||
|
### 1. 分页抓取(写入 `all_workflows.json`)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
page=1
|
||||||
|
echo "[]" > all_workflows.json
|
||||||
|
|
||||||
|
while :; do
|
||||||
|
resp=$(curl -s -X GET \
|
||||||
|
"$BASE/api/v1/lab/workflow/owner/list?page=$page&page_size=1000&lab_uuid=$lab_uuid" \
|
||||||
|
-H "$AUTH")
|
||||||
|
|
||||||
|
page_data=$(echo "$resp" | jq -c '.data.data // []')
|
||||||
|
jq -c --argjson p "$page_data" '. + $p' all_workflows.json > _tmp.json && mv _tmp.json all_workflows.json
|
||||||
|
|
||||||
|
has_more=$(echo "$resp" | jq -r '.data.has_more')
|
||||||
|
[ "$has_more" != "true" ] && break
|
||||||
|
page=$((page + 1))
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "Total: $(jq 'length' all_workflows.json)"
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. 汇总所有标签(含出现次数)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
jq '[.[].tags // [] | .[]] | group_by(.) | map({tag: .[0], count: length}) | sort_by(-.count)' \
|
||||||
|
all_workflows.json
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. 按标签筛选
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# ANY:包含任一指定标签
|
||||||
|
jq --argjson want '["synthesis","organic"]' \
|
||||||
|
'[.[] | select((.tags // []) | any(. as $t | $want | index($t)))]' \
|
||||||
|
all_workflows.json
|
||||||
|
|
||||||
|
# ALL:同时包含所有指定标签
|
||||||
|
jq --argjson want '["synthesis","organic"]' \
|
||||||
|
'[.[] | select(($want | all(. as $w | (.tags // []) | index($w))))]' \
|
||||||
|
all_workflows.json
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 筛选策略
|
||||||
|
|
||||||
|
agent 拿到用户的「领域 + 场景」自然语言描述时,按如下顺序选择 tag:
|
||||||
|
|
||||||
|
1. **优先用户显式指定的 tags**:若用户明确给出标签词,直接精确匹配。
|
||||||
|
2. **从 all_tags 中做语义映射**:若用户描述是自然语言(如"有机合成、柱层析"),在 all_tags 中找语义相关项(如 `synthesis`、`organic`、`chromatography`)。必要时展示候选 tag 让用户确认。
|
||||||
|
3. **模式选择**:
|
||||||
|
- 默认 `any`(更多召回),给出 tag 集合的并集匹配
|
||||||
|
- 用户强调"必须同时满足"时用 `all`
|
||||||
|
4. **空结果兜底**:如果筛选为空,放宽条件(去掉最稀有 tag、切换 any 模式),并提醒用户。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 引导到明确的 Protocol
|
||||||
|
|
||||||
|
筛选完成后,**最终目标是让用户确认一个具体的 workflow_uuid**,而不是停留在"一堆候选"上。按结果数量采取不同策略:
|
||||||
|
|
||||||
|
| 结果数量 | 策略 |
|
||||||
|
| --------- | ---------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
|
| 0 条 | 放宽筛选(去掉最稀有 tag → 切换 any 模式 → 去掉 `--published-only`)。仍为空则提示换关键词,或列出 `all_tags` 让用户重新选。 |
|
||||||
|
| 1 条 | 直接确认:"找到唯一匹配:`<name>` (uuid `<uuid>`),是否用它?"用户确认后记录 `workflow_uuid`。 |
|
||||||
|
| 2–10 条 | 编号列表展示,让用户选编号。每项给出 name、tags、description 摘要、published 状态。 |
|
||||||
|
| 10–30 条 | 先展示 tag 分布帮助用户进一步收紧:列出匹配结果中最常见的子标签,提示"加一个 tag 可将结果缩小到 N 条"。 |
|
||||||
|
| >30 条 | 强制要求用户补充条件:仅 published、指定具体 tag 组合、或按名称关键词过滤。 |
|
||||||
|
|
||||||
|
**确认 workflow 后**:
|
||||||
|
|
||||||
|
1. 将 `workflow_uuid` 写入 session state
|
||||||
|
2. 提示用户下一步可用的 skill:
|
||||||
|
- 提交实验 → 引导到“与其他 Skill 的协作”
|
||||||
|
- 查看 workflow 详细节点 → `GET /api/v1/lab/workflow/template/detail/<workflow_uuid>`
|
||||||
|
3. 若用户想换一个,回到筛选步骤。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 展示结果
|
||||||
|
|
||||||
|
推荐格式(表格 + 汇总统计):
|
||||||
|
|
||||||
|
```
|
||||||
|
共 150 个工作流,其中 32 个匹配筛选条件 [tags: synthesis OR organic]
|
||||||
|
|
||||||
|
| UUID (短) | 名称 | Tags | 已发布 |
|
||||||
|
|-----------|--------------------------|------------------------------|--------|
|
||||||
|
| e0436638 | Synthesis v2 | synthesis, organic | ✓ |
|
||||||
|
| 5b60dbb8 | Grignard Protocol | synthesis, organometallic | ✓ |
|
||||||
|
| ... | ... | ... | ... |
|
||||||
|
|
||||||
|
所有可用标签(按频次):
|
||||||
|
synthesis (12), organic (8), analysis (5), purification (4), ...
|
||||||
|
```
|
||||||
|
|
||||||
|
如果用户下一步想执行某工作流 → 引导到“与其他 Skill 的协作”。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 常见问题
|
||||||
|
|
||||||
|
### Q: tags 为 null 的工作流要不要展示?
|
||||||
|
|
||||||
|
默认**不展示**在筛选结果中(因为无法按 tag 匹配)。但在 `--summary-only` 或无筛选条件时,这些工作流仍会计入总数,并在输出中单独列出"未打标签"计数。
|
||||||
|
|
||||||
|
### Q: 如何按名称/描述做模糊匹配?
|
||||||
|
|
||||||
|
脚本未内置,但可在 jq 中组合:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
jq '[.[] | select((.name + " " + (.description // "")) | test("organic"; "i"))]' all_workflows.json
|
||||||
|
```
|
||||||
|
|
||||||
|
### Q: `page_size=1000` 是否会被服务端限制?
|
||||||
|
|
||||||
|
接口通常允许最大 1000;如果返回量少于 1000 且 `has_more=false`,说明已到末页。极端情况下若服务端返回错误,可降到 200 或 500 再试。
|
||||||
|
|
||||||
|
### Q: 工作流数量极大(>10k)怎么办?
|
||||||
|
|
||||||
|
1. 先跑 `--summary-only` 了解 tag 分布
|
||||||
|
2. 提示用户先限定 `--published-only` 或指定 tag
|
||||||
|
3. 考虑将 `all_workflows.json` 缓存到本地,下次直接复用
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 与其他 Skill 的协作
|
||||||
|
|
||||||
|
- 正常情况下,找到 workflow 之后可以直接用它提交实验(启动工作流的 api 端点 POST $BASE/api/v1/lab/workflow/<workflow_uuid>/run,不用别的 skill)
|
||||||
|
- **仅当需要进行多次实验时,使用 batch-submit-experiment** — 筛选到目标工作流后,`workflow_uuid` 直接用于实验提交
|
||||||
|
|
||||||
|
## 脚本依赖
|
||||||
|
|
||||||
|
`scripts/filter_workflows.py` 仅使用 Python 标准库(`urllib`、`json`、`argparse`),无需额外安装。
|
||||||
191
.cursor/skills/filter-workflow-by-tags/scripts/filter_workflows.py
Executable file
191
.cursor/skills/filter-workflow-by-tags/scripts/filter_workflows.py
Executable file
@@ -0,0 +1,191 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""分页拉取 Uni-Lab 工作流列表,汇总 tags 并按 tag 筛选。
|
||||||
|
|
||||||
|
使用示例:
|
||||||
|
python filter_workflows.py \
|
||||||
|
--auth <base64token> \
|
||||||
|
--base https://leap-lab.test.bohrium.com \
|
||||||
|
--lab-uuid a9059772-... \
|
||||||
|
--tags synthesis organic --mode any
|
||||||
|
|
||||||
|
仅依赖 Python 标准库。
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import json
|
||||||
|
import sys
|
||||||
|
import urllib.error
|
||||||
|
import urllib.parse
|
||||||
|
import urllib.request
|
||||||
|
from collections import Counter
|
||||||
|
|
||||||
|
|
||||||
|
def fetch_all_workflows(base: str, auth_token: str, lab_uuid: str, page_size: int = 1000) -> list[dict]:
|
||||||
|
"""分页拉取所有 owner 工作流,直到 has_more=false。"""
|
||||||
|
workflows: list[dict] = []
|
||||||
|
page = 1
|
||||||
|
while True:
|
||||||
|
query = urllib.parse.urlencode(
|
||||||
|
{"page": page, "page_size": page_size, "lab_uuid": lab_uuid}
|
||||||
|
)
|
||||||
|
url = f"{base.rstrip('/')}/api/v1/lab/workflow/owner/list?{query}"
|
||||||
|
req = urllib.request.Request(
|
||||||
|
url,
|
||||||
|
headers={
|
||||||
|
"Authorization": f"Lab {auth_token}",
|
||||||
|
"Accept": "application/json",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
with urllib.request.urlopen(req, timeout=30) as resp:
|
||||||
|
payload = json.loads(resp.read().decode("utf-8"))
|
||||||
|
except urllib.error.HTTPError as e:
|
||||||
|
sys.exit(f"[ERROR] HTTP {e.code} on page {page}: {e.read().decode('utf-8', 'ignore')}")
|
||||||
|
except urllib.error.URLError as e:
|
||||||
|
sys.exit(f"[ERROR] URL error on page {page}: {e.reason}")
|
||||||
|
|
||||||
|
if payload.get("code") != 0:
|
||||||
|
sys.exit(f"[ERROR] API returned non-zero code: {payload}")
|
||||||
|
|
||||||
|
data = payload.get("data") or {}
|
||||||
|
page_items = data.get("data") or []
|
||||||
|
workflows.extend(page_items)
|
||||||
|
|
||||||
|
if not data.get("has_more"):
|
||||||
|
break
|
||||||
|
page += 1
|
||||||
|
# 防御性兜底,避免接口异常导致无限循环
|
||||||
|
if page > 1000:
|
||||||
|
print(f"[WARN] page count exceeded 1000, stopping early", file=sys.stderr)
|
||||||
|
break
|
||||||
|
|
||||||
|
return workflows
|
||||||
|
|
||||||
|
|
||||||
|
def aggregate_tags(workflows: list[dict]) -> tuple[list[str], dict[str, int], int]:
|
||||||
|
"""返回 (sorted_tags, tag_counts, untagged_count)。"""
|
||||||
|
counter: Counter[str] = Counter()
|
||||||
|
untagged = 0
|
||||||
|
for wf in workflows:
|
||||||
|
tags = wf.get("tags")
|
||||||
|
if not tags:
|
||||||
|
untagged += 1
|
||||||
|
continue
|
||||||
|
for t in tags:
|
||||||
|
if isinstance(t, str) and t.strip():
|
||||||
|
counter[t.strip()] += 1
|
||||||
|
return sorted(counter.keys()), dict(counter), untagged
|
||||||
|
|
||||||
|
|
||||||
|
def filter_workflows(
|
||||||
|
workflows: list[dict],
|
||||||
|
want_tags: list[str],
|
||||||
|
mode: str,
|
||||||
|
published_only: bool,
|
||||||
|
) -> list[dict]:
|
||||||
|
"""按 tag 筛选。mode 取值 any / all。"""
|
||||||
|
want_set = {t.strip() for t in want_tags if t.strip()}
|
||||||
|
out: list[dict] = []
|
||||||
|
for wf in workflows:
|
||||||
|
if published_only and not wf.get("published"):
|
||||||
|
continue
|
||||||
|
if not want_set:
|
||||||
|
out.append(wf)
|
||||||
|
continue
|
||||||
|
tags = wf.get("tags") or []
|
||||||
|
tag_set = {t for t in tags if isinstance(t, str)}
|
||||||
|
if mode == "all":
|
||||||
|
if want_set.issubset(tag_set):
|
||||||
|
out.append(wf)
|
||||||
|
else: # any
|
||||||
|
if want_set & tag_set:
|
||||||
|
out.append(wf)
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
def project_workflow(wf: dict) -> dict:
|
||||||
|
"""精简输出字段。"""
|
||||||
|
return {
|
||||||
|
"uuid": wf.get("uuid"),
|
||||||
|
"name": wf.get("name"),
|
||||||
|
"description": wf.get("description", ""),
|
||||||
|
"tags": wf.get("tags") or [],
|
||||||
|
"published": bool(wf.get("published")),
|
||||||
|
"user_id": wf.get("user_id"),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def parse_args() -> argparse.Namespace:
|
||||||
|
p = argparse.ArgumentParser(description="Fetch & filter Uni-Lab workflows by tags.")
|
||||||
|
p.add_argument("--auth", required=True, help="Base64 token (the part after `Lab `).")
|
||||||
|
p.add_argument("--base", required=True, help="Base URL, e.g. https://leap-lab.test.bohrium.com")
|
||||||
|
p.add_argument("--lab-uuid", required=True, help="Lab UUID.")
|
||||||
|
p.add_argument("--tags", nargs="*", default=[], help="Tags to filter by (space separated).")
|
||||||
|
p.add_argument(
|
||||||
|
"--mode",
|
||||||
|
choices=["any", "all"],
|
||||||
|
default="any",
|
||||||
|
help="any: workflow contains at least one tag; all: workflow contains every tag.",
|
||||||
|
)
|
||||||
|
p.add_argument("--published-only", action="store_true", help="Only include published workflows.")
|
||||||
|
p.add_argument("--page-size", type=int, default=1000, help="Page size, default 1000.")
|
||||||
|
p.add_argument(
|
||||||
|
"--summary-only",
|
||||||
|
action="store_true",
|
||||||
|
help="Print tag summary without applying filter (still fetches everything).",
|
||||||
|
)
|
||||||
|
p.add_argument("--output", help="Write JSON result to this path. If omitted, print to stdout.")
|
||||||
|
return p.parse_args()
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
args = parse_args()
|
||||||
|
workflows = fetch_all_workflows(
|
||||||
|
base=args.base,
|
||||||
|
auth_token=args.auth,
|
||||||
|
lab_uuid=args.lab_uuid,
|
||||||
|
page_size=args.page_size,
|
||||||
|
)
|
||||||
|
sorted_tags, tag_counts, untagged = aggregate_tags(workflows)
|
||||||
|
|
||||||
|
if args.summary_only:
|
||||||
|
result = {
|
||||||
|
"total_workflows": len(workflows),
|
||||||
|
"untagged_count": untagged,
|
||||||
|
"tag_counts": tag_counts,
|
||||||
|
"all_tags": sorted_tags,
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
filtered = filter_workflows(
|
||||||
|
workflows,
|
||||||
|
want_tags=args.tags,
|
||||||
|
mode=args.mode,
|
||||||
|
published_only=args.published_only,
|
||||||
|
)
|
||||||
|
result = {
|
||||||
|
"total_workflows": len(workflows),
|
||||||
|
"untagged_count": untagged,
|
||||||
|
"tag_counts": tag_counts,
|
||||||
|
"all_tags": sorted_tags,
|
||||||
|
"filter": {
|
||||||
|
"tags": args.tags,
|
||||||
|
"mode": args.mode,
|
||||||
|
"published_only": args.published_only,
|
||||||
|
},
|
||||||
|
"matched_count": len(filtered),
|
||||||
|
"filtered_workflows": [project_workflow(wf) for wf in filtered],
|
||||||
|
}
|
||||||
|
|
||||||
|
payload = json.dumps(result, ensure_ascii=False, indent=2)
|
||||||
|
if args.output:
|
||||||
|
with open(args.output, "w", encoding="utf-8") as f:
|
||||||
|
f.write(payload)
|
||||||
|
print(f"Wrote {len(workflows)} workflows summary → {args.output}", file=sys.stderr)
|
||||||
|
else:
|
||||||
|
print(payload)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
251
.cursor/skills/host-node/SKILL.md
Normal file
251
.cursor/skills/host-node/SKILL.md
Normal file
@@ -0,0 +1,251 @@
|
|||||||
|
---
|
||||||
|
name: host-node
|
||||||
|
description: Operate Uni-Lab host node via REST API — create resources, test latency, test resource tree, manual confirm. Use when the user mentions host_node, creating resources, resource management, testing latency, or any host node operation.
|
||||||
|
---
|
||||||
|
|
||||||
|
# Host Node API Skill
|
||||||
|
|
||||||
|
## 设备信息
|
||||||
|
|
||||||
|
- **device_id**: `host_node`
|
||||||
|
- **Python 源码**: `unilabos/ros/nodes/presets/host_node.py`
|
||||||
|
- **设备类**: `HostNode`
|
||||||
|
- **动作数**: 4(`create_resource`, `test_latency`, `auto-test_resource`, `manual_confirm`)
|
||||||
|
|
||||||
|
## 前置条件(缺一不可)
|
||||||
|
|
||||||
|
使用本 skill 前,**必须**先确认以下信息。如果缺少任何一项,**立即向用户询问并终止**,等补齐后再继续。
|
||||||
|
|
||||||
|
### 1. ak / sk → AUTH
|
||||||
|
|
||||||
|
从启动参数 `--ak` `--sk` 或 config.py 中获取,生成 token:`base64(ak:sk)` → `Authorization: Lab <token>`
|
||||||
|
|
||||||
|
### 2. --addr → BASE URL
|
||||||
|
|
||||||
|
| `--addr` 值 | BASE |
|
||||||
|
| ------------ | ----------------------------------- |
|
||||||
|
| `test` | `https://leap-lab.test.bohrium.com` |
|
||||||
|
| `uat` | `https://leap-lab.uat.bohrium.com` |
|
||||||
|
| `local` | `http://127.0.0.1:48197` |
|
||||||
|
| 不传(默认) | `https://leap-lab.bohrium.com` |
|
||||||
|
|
||||||
|
确认后设置:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
BASE="<根据 addr 确定的 URL>"
|
||||||
|
AUTH="Authorization: Lab <token>"
|
||||||
|
```
|
||||||
|
|
||||||
|
**两项全部就绪后才可发起 API 请求。**
|
||||||
|
|
||||||
|
## Session State
|
||||||
|
|
||||||
|
在整个对话过程中,agent 需要记住以下状态,避免重复询问用户:
|
||||||
|
|
||||||
|
- `lab_uuid` — 实验室 UUID(首次通过 API #1 自动获取,**不需要问用户**)
|
||||||
|
- `device_name` — `host_node`
|
||||||
|
|
||||||
|
## 请求约定
|
||||||
|
|
||||||
|
所有请求使用 `curl -s`,POST/PATCH/DELETE 需加 `Content-Type: application/json`。
|
||||||
|
|
||||||
|
> **Windows 平台**必须使用 `curl.exe`(而非 PowerShell 的 `curl` 别名)。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## API Endpoints
|
||||||
|
|
||||||
|
### 1. 获取实验室信息(自动获取 lab_uuid)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X GET "$BASE/api/v1/edge/lab/info" -H "$AUTH"
|
||||||
|
```
|
||||||
|
|
||||||
|
返回 `data.uuid` 为 `lab_uuid`,`data.name` 为 `lab_name`。
|
||||||
|
|
||||||
|
### 2. 创建工作流
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X POST "$BASE/api/v1/lab/workflow/owner" \
|
||||||
|
-H "$AUTH" -H "Content-Type: application/json" \
|
||||||
|
-d '{"name":"<名称>","lab_uuid":"<lab_uuid>","description":"<描述>"}'
|
||||||
|
```
|
||||||
|
|
||||||
|
返回 `data.uuid` 为 `workflow_uuid`。创建成功后告知用户链接:`$BASE/laboratory/$lab_uuid/workflow/$workflow_uuid`
|
||||||
|
|
||||||
|
### 3. 创建节点
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X POST "$BASE/api/v1/edge/workflow/node" \
|
||||||
|
-H "$AUTH" -H "Content-Type: application/json" \
|
||||||
|
-d '{"workflow_uuid":"<workflow_uuid>","resource_template_name":"host_node","node_template_name":"<action_name>"}'
|
||||||
|
```
|
||||||
|
|
||||||
|
- `resource_template_name` 固定为 `host_node`
|
||||||
|
- `node_template_name` — action 名称(如 `create_resource`, `test_latency`)
|
||||||
|
|
||||||
|
### 4. 删除节点
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X DELETE "$BASE/api/v1/lab/workflow/nodes" \
|
||||||
|
-H "$AUTH" -H "Content-Type: application/json" \
|
||||||
|
-d '{"node_uuids":["<uuid1>"],"workflow_uuid":"<workflow_uuid>"}'
|
||||||
|
```
|
||||||
|
|
||||||
|
### 5. 更新节点参数
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X PATCH "$BASE/api/v1/lab/workflow/node" \
|
||||||
|
-H "$AUTH" -H "Content-Type: application/json" \
|
||||||
|
-d '{"workflow_uuid":"<wf_uuid>","uuid":"<node_uuid>","param":{...}}'
|
||||||
|
```
|
||||||
|
|
||||||
|
`param` 直接使用创建节点返回的 `data.param` 结构,修改需要填入的字段值。参考 [action-index.md](action-index.md) 确定哪些字段是 Slot。
|
||||||
|
|
||||||
|
### 6. 查询节点 handles
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X POST "$BASE/api/v1/lab/workflow/node-handles" \
|
||||||
|
-H "$AUTH" -H "Content-Type: application/json" \
|
||||||
|
-d '{"node_uuids":["<node_uuid_1>","<node_uuid_2>"]}'
|
||||||
|
```
|
||||||
|
|
||||||
|
### 7. 批量创建边
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X POST "$BASE/api/v1/lab/workflow/edges" \
|
||||||
|
-H "$AUTH" -H "Content-Type: application/json" \
|
||||||
|
-d '{"edges":[{"source_node_uuid":"<uuid>","target_node_uuid":"<uuid>","source_handle_uuid":"<uuid>","target_handle_uuid":"<uuid>"}]}'
|
||||||
|
```
|
||||||
|
|
||||||
|
### 8. 启动工作流
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X POST "$BASE/api/v1/lab/workflow/<workflow_uuid>/run" -H "$AUTH"
|
||||||
|
```
|
||||||
|
|
||||||
|
### 9. 运行设备单动作
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X POST "$BASE/api/v1/lab/mcp/run/action" \
|
||||||
|
-H "$AUTH" -H "Content-Type: application/json" \
|
||||||
|
-d '{"lab_uuid":"<lab_uuid>","device_id":"host_node","action":"<action_name>","action_type":"<type>","param":{...}}'
|
||||||
|
```
|
||||||
|
|
||||||
|
`param` 直接放 goal 里的属性,**不要**再包一层 `{"goal": {...}}`。
|
||||||
|
|
||||||
|
> **WARNING: `action_type` 必须正确,传错会导致任务永远卡住无法完成。** 从下表或 `actions/<name>.json` 的 `type` 字段获取。
|
||||||
|
|
||||||
|
#### action_type 速查表
|
||||||
|
|
||||||
|
| action | action_type |
|
||||||
|
|--------|-------------|
|
||||||
|
| `test_latency` | `UniLabJsonCommand` |
|
||||||
|
| `create_resource` | `ResourceCreateFromOuterEasy` |
|
||||||
|
| `auto-test_resource` | `UniLabJsonCommand` |
|
||||||
|
| `manual_confirm` | `UniLabJsonCommand` |
|
||||||
|
|
||||||
|
### 10. 查询任务状态
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X GET "$BASE/api/v1/lab/mcp/task/<task_uuid>" -H "$AUTH"
|
||||||
|
```
|
||||||
|
|
||||||
|
### 11. 运行工作流单节点
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X POST "$BASE/api/v1/lab/mcp/run/workflow/action" \
|
||||||
|
-H "$AUTH" -H "Content-Type: application/json" \
|
||||||
|
-d '{"node_uuid":"<node_uuid>"}'
|
||||||
|
```
|
||||||
|
|
||||||
|
### 12. 获取资源树(物料信息)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X GET "$BASE/api/v1/lab/material/download/$lab_uuid" -H "$AUTH"
|
||||||
|
```
|
||||||
|
|
||||||
|
注意 `lab_uuid` 在路径中。返回 `data.nodes[]` 含所有节点(设备 + 物料),每个节点含 `name`、`uuid`、`type`、`parent`。
|
||||||
|
|
||||||
|
### 13. 获取工作流模板详情
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X GET "$BASE/api/v1/lab/workflow/template/detail/$workflow_uuid" -H "$AUTH"
|
||||||
|
```
|
||||||
|
|
||||||
|
> 必须使用 `/lab/workflow/template/detail/{uuid}`,其他路径会返回 404。
|
||||||
|
|
||||||
|
### 14. 按名称查询物料模板
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X GET "$BASE/api/v1/lab/material/template/by-name?lab_uuid=$lab_uuid&name=<template_name>" -H "$AUTH"
|
||||||
|
```
|
||||||
|
|
||||||
|
返回 `data.uuid` 为 `res_template_uuid`,用于 API #15。
|
||||||
|
|
||||||
|
### 15. 创建物料节点
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X POST "$BASE/api/v1/edge/material/node" \
|
||||||
|
-H "$AUTH" -H "Content-Type: application/json" \
|
||||||
|
-d '{"res_template_uuid":"<uuid>","name":"<名称>","display_name":"<显示名>","parent_uuid":"<父节点uuid>","data":{...}}'
|
||||||
|
```
|
||||||
|
|
||||||
|
### 16. 更新物料节点
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X PUT "$BASE/api/v1/edge/material/node" \
|
||||||
|
-H "$AUTH" -H "Content-Type: application/json" \
|
||||||
|
-d '{"uuid":"<节点uuid>","display_name":"<新名称>","data":{...}}'
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Placeholder Slot 填写规则
|
||||||
|
|
||||||
|
| `placeholder_keys` 值 | Slot 类型 | 填写格式 | 选取范围 |
|
||||||
|
| --------------------- | ------------ | ----------------------------------------------------- | ---------------------- |
|
||||||
|
| `unilabos_resources` | ResourceSlot | `{"id": "/path/name", "name": "name", "uuid": "xxx"}` | 仅物料节点(非设备) |
|
||||||
|
| `unilabos_devices` | DeviceSlot | `"/parent/device_name"` | 仅设备节点(type=device) |
|
||||||
|
| `unilabos_nodes` | NodeSlot | `"/parent/node_name"` | 所有节点(设备 + 物料) |
|
||||||
|
| `unilabos_class` | ClassSlot | `"class_name"` | 注册表中已注册的资源类 |
|
||||||
|
|
||||||
|
### host_node 设备的 Slot 字段表
|
||||||
|
|
||||||
|
| Action | 字段 | Slot 类型 | 说明 |
|
||||||
|
| ----------------- | ----------- | ------------ | ------------------------------ |
|
||||||
|
| `create_resource` | `res_id` | ResourceSlot | 新资源路径(可填不存在的路径) |
|
||||||
|
| `create_resource` | `device_id` | DeviceSlot | 归属设备 |
|
||||||
|
| `create_resource` | `parent` | NodeSlot | 父节点路径 |
|
||||||
|
| `create_resource` | `class_name`| ClassSlot | 资源类名如 `"container"` |
|
||||||
|
| `auto-test_resource` | `resource` | ResourceSlot | 单个测试物料 |
|
||||||
|
| `auto-test_resource` | `resources` | ResourceSlot | 测试物料数组 |
|
||||||
|
| `auto-test_resource` | `device` | DeviceSlot | 测试设备 |
|
||||||
|
| `auto-test_resource` | `devices` | DeviceSlot | 测试设备 |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 渐进加载策略
|
||||||
|
|
||||||
|
1. **SKILL.md**(本文件)— API 端点 + session state 管理
|
||||||
|
2. **[action-index.md](action-index.md)** — 按分类浏览 4 个动作的描述和核心参数
|
||||||
|
3. **[actions/\<name\>.json](actions/)** — 仅在需要构建具体请求时,加载对应 action 的完整 JSON Schema
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 完整工作流 Checklist
|
||||||
|
|
||||||
|
```
|
||||||
|
Task Progress:
|
||||||
|
- [ ] Step 1: GET /edge/lab/info 获取 lab_uuid
|
||||||
|
- [ ] Step 2: 获取资源树 (GET #12) → 记住可用物料
|
||||||
|
- [ ] Step 3: 读 action-index.md 确定要用的 action 名
|
||||||
|
- [ ] Step 4: 创建工作流 (POST #2) → 记住 workflow_uuid,告知用户链接
|
||||||
|
- [ ] Step 5: 创建节点 (POST #3, resource_template_name=host_node) → 记住 node_uuid + data.param
|
||||||
|
- [ ] Step 6: 根据 _unilabos_placeholder_info 和资源树,填写 data.param 中的 Slot 字段
|
||||||
|
- [ ] Step 7: 更新节点参数 (PATCH #5)
|
||||||
|
- [ ] Step 8: 查询节点 handles (POST #6) → 获取各节点的 handle_uuid
|
||||||
|
- [ ] Step 9: 批量创建边 (POST #7) → 用 handle_uuid 连接节点
|
||||||
|
- [ ] Step 10: 启动工作流 (POST #8) 或运行单节点 (POST #11)
|
||||||
|
- [ ] Step 11: 查询任务状态 (GET #10) 确认完成
|
||||||
|
```
|
||||||
58
.cursor/skills/host-node/action-index.md
Normal file
58
.cursor/skills/host-node/action-index.md
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
# Action Index — host_node
|
||||||
|
|
||||||
|
4 个动作,按功能分类。每个动作的完整 JSON Schema 在 `actions/<name>.json`。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 资源管理
|
||||||
|
|
||||||
|
### `create_resource`
|
||||||
|
|
||||||
|
在资源树中创建新资源(容器、物料等),支持指定位置、类型和初始液体
|
||||||
|
|
||||||
|
- **action_type**: `ResourceCreateFromOuterEasy`
|
||||||
|
- **Schema**: [`actions/create_resource.json`](actions/create_resource.json)
|
||||||
|
- **可选参数**: `res_id`, `device_id`, `class_name`, `parent`, `bind_locations`, `liquid_input_slot`, `liquid_type`, `liquid_volume`, `slot_on_deck`
|
||||||
|
- **占位符字段**:
|
||||||
|
- `res_id` — **ResourceSlot**(特例:目标物料可能尚不存在,直接填期望路径)
|
||||||
|
- `device_id` — **DeviceSlot**,填路径字符串如 `"/host_node"`
|
||||||
|
- `parent` — **NodeSlot**,填路径字符串如 `"/workstation/deck"`
|
||||||
|
- `class_name` — **ClassSlot**,填类名如 `"container"`
|
||||||
|
|
||||||
|
### `auto-test_resource`
|
||||||
|
|
||||||
|
测试资源系统,返回当前资源树和设备列表
|
||||||
|
|
||||||
|
- **action_type**: `UniLabJsonCommand`
|
||||||
|
- **Schema**: [`actions/test_resource.json`](actions/test_resource.json)
|
||||||
|
- **可选参数**: `resource`, `resources`, `device`, `devices`
|
||||||
|
- **占位符字段**:
|
||||||
|
- `resource` — **ResourceSlot**,单个物料节点 `{id, name, uuid}`
|
||||||
|
- `resources` — **ResourceSlot**,物料节点数组 `[{id, name, uuid}, ...]`
|
||||||
|
- `device` — **DeviceSlot**,设备路径字符串
|
||||||
|
- `devices` — **DeviceSlot**,设备路径字符串
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 系统工具
|
||||||
|
|
||||||
|
### `test_latency`
|
||||||
|
|
||||||
|
测试设备通信延迟,返回 RTT、时间差、任务延迟等指标
|
||||||
|
|
||||||
|
- **action_type**: `UniLabJsonCommand`
|
||||||
|
- **Schema**: [`actions/test_latency.json`](actions/test_latency.json)
|
||||||
|
- **参数**: 无(零参数调用)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 人工确认
|
||||||
|
|
||||||
|
### `manual_confirm`
|
||||||
|
|
||||||
|
创建人工确认节点,等待用户手动确认后继续
|
||||||
|
|
||||||
|
- **action_type**: `UniLabJsonCommand`
|
||||||
|
- **Schema**: [`actions/manual_confirm.json`](actions/manual_confirm.json)
|
||||||
|
- **核心参数**: `timeout_seconds`(超时时间,秒), `assignee_user_ids`(指派用户 ID 列表)
|
||||||
|
- **占位符字段**: `assignee_user_ids` — `unilabos_manual_confirm` 类型
|
||||||
93
.cursor/skills/host-node/actions/create_resource.json
Normal file
93
.cursor/skills/host-node/actions/create_resource.json
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
{
|
||||||
|
"type": "ResourceCreateFromOuterEasy",
|
||||||
|
"goal": {
|
||||||
|
"res_id": "res_id",
|
||||||
|
"class_name": "class_name",
|
||||||
|
"parent": "parent",
|
||||||
|
"device_id": "device_id",
|
||||||
|
"bind_locations": "bind_locations",
|
||||||
|
"liquid_input_slot": "liquid_input_slot[]",
|
||||||
|
"liquid_type": "liquid_type[]",
|
||||||
|
"liquid_volume": "liquid_volume[]",
|
||||||
|
"slot_on_deck": "slot_on_deck"
|
||||||
|
},
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"res_id": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"device_id": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"class_name": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"parent": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"bind_locations": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"x": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"y": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"z": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"x",
|
||||||
|
"y",
|
||||||
|
"z"
|
||||||
|
],
|
||||||
|
"title": "bind_locations",
|
||||||
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"liquid_input_slot": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "integer"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"liquid_type": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"liquid_volume": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "number"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"slot_on_deck": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [],
|
||||||
|
"_unilabos_placeholder_info": {
|
||||||
|
"res_id": "unilabos_resources",
|
||||||
|
"device_id": "unilabos_devices",
|
||||||
|
"parent": "unilabos_nodes",
|
||||||
|
"class_name": "unilabos_class"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"goal_default": {},
|
||||||
|
"placeholder_keys": {
|
||||||
|
"res_id": "unilabos_resources",
|
||||||
|
"device_id": "unilabos_devices",
|
||||||
|
"parent": "unilabos_nodes",
|
||||||
|
"class_name": "unilabos_class"
|
||||||
|
}
|
||||||
|
}
|
||||||
32
.cursor/skills/host-node/actions/manual_confirm.json
Normal file
32
.cursor/skills/host-node/actions/manual_confirm.json
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
{
|
||||||
|
"type": "UniLabJsonCommand",
|
||||||
|
"goal": {
|
||||||
|
"timeout_seconds": "timeout_seconds",
|
||||||
|
"assignee_user_ids": "assignee_user_ids"
|
||||||
|
},
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"timeout_seconds": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"assignee_user_ids": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"timeout_seconds",
|
||||||
|
"assignee_user_ids"
|
||||||
|
],
|
||||||
|
"_unilabos_placeholder_info": {
|
||||||
|
"assignee_user_ids": "unilabos_manual_confirm"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"goal_default": {},
|
||||||
|
"placeholder_keys": {
|
||||||
|
"assignee_user_ids": "unilabos_manual_confirm"
|
||||||
|
}
|
||||||
|
}
|
||||||
11
.cursor/skills/host-node/actions/test_latency.json
Normal file
11
.cursor/skills/host-node/actions/test_latency.json
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"type": "UniLabJsonCommand",
|
||||||
|
"goal": {},
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {},
|
||||||
|
"required": []
|
||||||
|
},
|
||||||
|
"goal_default": {},
|
||||||
|
"placeholder_keys": {}
|
||||||
|
}
|
||||||
255
.cursor/skills/host-node/actions/test_resource.json
Normal file
255
.cursor/skills/host-node/actions/test_resource.json
Normal file
@@ -0,0 +1,255 @@
|
|||||||
|
{
|
||||||
|
"type": "UniLabJsonCommand",
|
||||||
|
"goal": {
|
||||||
|
"resource": "resource",
|
||||||
|
"resources": "resources",
|
||||||
|
"device": "device",
|
||||||
|
"devices": "devices"
|
||||||
|
},
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"resource": {
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": false,
|
||||||
|
"properties": {
|
||||||
|
"id": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"sample_id": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"children": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"parent": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"type": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"category": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"pose": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"position": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"x": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"y": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"z": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"x",
|
||||||
|
"y",
|
||||||
|
"z"
|
||||||
|
],
|
||||||
|
"title": "position",
|
||||||
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"orientation": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"x": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"y": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"z": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"w": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"x",
|
||||||
|
"y",
|
||||||
|
"z",
|
||||||
|
"w"
|
||||||
|
],
|
||||||
|
"title": "orientation",
|
||||||
|
"additionalProperties": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"position",
|
||||||
|
"orientation"
|
||||||
|
],
|
||||||
|
"title": "pose",
|
||||||
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"config": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"data": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"title": "resource"
|
||||||
|
},
|
||||||
|
"resources": {
|
||||||
|
"items": {
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": false,
|
||||||
|
"properties": {
|
||||||
|
"id": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"sample_id": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"children": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"parent": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"type": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"category": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"pose": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"position": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"x": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"y": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"z": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"x",
|
||||||
|
"y",
|
||||||
|
"z"
|
||||||
|
],
|
||||||
|
"title": "position",
|
||||||
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"orientation": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"x": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"y": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"z": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"w": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"x",
|
||||||
|
"y",
|
||||||
|
"z",
|
||||||
|
"w"
|
||||||
|
],
|
||||||
|
"title": "orientation",
|
||||||
|
"additionalProperties": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"position",
|
||||||
|
"orientation"
|
||||||
|
],
|
||||||
|
"title": "pose",
|
||||||
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"config": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"data": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"title": "resources"
|
||||||
|
},
|
||||||
|
"type": "array"
|
||||||
|
},
|
||||||
|
"device": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "device reference"
|
||||||
|
},
|
||||||
|
"devices": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "device reference"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [],
|
||||||
|
"_unilabos_placeholder_info": {
|
||||||
|
"resource": "unilabos_resources",
|
||||||
|
"resources": "unilabos_resources",
|
||||||
|
"device": "unilabos_devices",
|
||||||
|
"devices": "unilabos_devices"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"goal_default": {},
|
||||||
|
"placeholder_keys": {
|
||||||
|
"resource": "unilabos_resources",
|
||||||
|
"resources": "unilabos_resources",
|
||||||
|
"device": "unilabos_devices",
|
||||||
|
"devices": "unilabos_devices"
|
||||||
|
}
|
||||||
|
}
|
||||||
272
.cursor/skills/virtual-workbench/SKILL.md
Normal file
272
.cursor/skills/virtual-workbench/SKILL.md
Normal file
@@ -0,0 +1,272 @@
|
|||||||
|
---
|
||||||
|
name: virtual-workbench
|
||||||
|
description: Operate Virtual Workbench via REST API — prepare materials, move to heating stations, start heating, move to output, transfer resources. Use when the user mentions virtual workbench, virtual_workbench, 虚拟工作台, heating stations, material processing, or workbench operations.
|
||||||
|
---
|
||||||
|
|
||||||
|
# Virtual Workbench API Skill
|
||||||
|
|
||||||
|
## 设备信息
|
||||||
|
|
||||||
|
- **device_id**: `virtual_workbench`
|
||||||
|
- **Python 源码**: `unilabos/devices/virtual/workbench.py`
|
||||||
|
- **设备类**: `VirtualWorkbench`
|
||||||
|
- **动作数**: 6(`auto-prepare_materials`, `auto-move_to_heating_station`, `auto-start_heating`, `auto-move_to_output`, `transfer`, `manual_confirm`)
|
||||||
|
- **设备描述**: 模拟工作台,包含 1 个机械臂(每次操作 2s,独占锁)和 3 个加热台(每次加热 60s,可并行)
|
||||||
|
|
||||||
|
### 典型工作流程
|
||||||
|
|
||||||
|
1. `prepare_materials` — 生成 A1-A5 物料(5 个 output handle)
|
||||||
|
2. `move_to_heating_station` — 物料并发竞争机械臂,移动到空闲加热台
|
||||||
|
3. `start_heating` — 启动加热(3 个加热台可并行)
|
||||||
|
4. `move_to_output` — 加热完成后移到输出位置 Cn
|
||||||
|
|
||||||
|
## 前置条件(缺一不可)
|
||||||
|
|
||||||
|
使用本 skill 前,**必须**先确认以下信息。如果缺少任何一项,**立即向用户询问并终止**,等补齐后再继续。
|
||||||
|
|
||||||
|
### 1. ak / sk → AUTH
|
||||||
|
|
||||||
|
从启动参数 `--ak` `--sk` 或 config.py 中获取,生成 token:`base64(ak:sk)` → `Authorization: Lab <token>`
|
||||||
|
|
||||||
|
### 2. --addr → BASE URL
|
||||||
|
|
||||||
|
| `--addr` 值 | BASE |
|
||||||
|
| ------------ | ----------------------------------- |
|
||||||
|
| `test` | `https://leap-lab.test.bohrium.com` |
|
||||||
|
| `uat` | `https://leap-lab.uat.bohrium.com` |
|
||||||
|
| `local` | `http://127.0.0.1:48197` |
|
||||||
|
| 不传(默认) | `https://leap-lab.bohrium.com` |
|
||||||
|
|
||||||
|
确认后设置:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
BASE="<根据 addr 确定的 URL>"
|
||||||
|
AUTH="Authorization: Lab <token>"
|
||||||
|
```
|
||||||
|
|
||||||
|
**两项全部就绪后才可发起 API 请求。**
|
||||||
|
|
||||||
|
## Session State
|
||||||
|
|
||||||
|
- `lab_uuid` — 实验室 UUID(首次通过 API #1 自动获取,**不需要问用户**)
|
||||||
|
- `device_name` — `virtual_workbench`
|
||||||
|
|
||||||
|
## 请求约定
|
||||||
|
|
||||||
|
所有请求使用 `curl -s`,POST/PATCH/DELETE 需加 `Content-Type: application/json`。
|
||||||
|
|
||||||
|
> **Windows 平台**必须使用 `curl.exe`(而非 PowerShell 的 `curl` 别名)。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## API Endpoints
|
||||||
|
|
||||||
|
### 1. 获取实验室信息(自动获取 lab_uuid)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X GET "$BASE/api/v1/edge/lab/info" -H "$AUTH"
|
||||||
|
```
|
||||||
|
|
||||||
|
返回 `data.uuid` 为 `lab_uuid`,`data.name` 为 `lab_name`。
|
||||||
|
|
||||||
|
### 2. 创建工作流
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X POST "$BASE/api/v1/lab/workflow/owner" \
|
||||||
|
-H "$AUTH" -H "Content-Type: application/json" \
|
||||||
|
-d '{"name":"<名称>","lab_uuid":"<lab_uuid>","description":"<描述>"}'
|
||||||
|
```
|
||||||
|
|
||||||
|
返回 `data.uuid` 为 `workflow_uuid`。创建成功后告知用户链接:`$BASE/laboratory/$lab_uuid/workflow/$workflow_uuid`
|
||||||
|
|
||||||
|
### 3. 创建节点
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X POST "$BASE/api/v1/edge/workflow/node" \
|
||||||
|
-H "$AUTH" -H "Content-Type: application/json" \
|
||||||
|
-d '{"workflow_uuid":"<workflow_uuid>","resource_template_name":"virtual_workbench","node_template_name":"<action_name>"}'
|
||||||
|
```
|
||||||
|
|
||||||
|
- `resource_template_name` 固定为 `virtual_workbench`
|
||||||
|
- `node_template_name` — action 名称(如 `auto-prepare_materials`, `auto-move_to_heating_station`)
|
||||||
|
|
||||||
|
### 4. 删除节点
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X DELETE "$BASE/api/v1/lab/workflow/nodes" \
|
||||||
|
-H "$AUTH" -H "Content-Type: application/json" \
|
||||||
|
-d '{"node_uuids":["<uuid1>"],"workflow_uuid":"<workflow_uuid>"}'
|
||||||
|
```
|
||||||
|
|
||||||
|
### 5. 更新节点参数
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X PATCH "$BASE/api/v1/lab/workflow/node" \
|
||||||
|
-H "$AUTH" -H "Content-Type: application/json" \
|
||||||
|
-d '{"workflow_uuid":"<wf_uuid>","uuid":"<node_uuid>","param":{...}}'
|
||||||
|
```
|
||||||
|
|
||||||
|
参考 [action-index.md](action-index.md) 确定哪些字段是 Slot。
|
||||||
|
|
||||||
|
### 6. 查询节点 handles
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X POST "$BASE/api/v1/lab/workflow/node-handles" \
|
||||||
|
-H "$AUTH" -H "Content-Type: application/json" \
|
||||||
|
-d '{"node_uuids":["<node_uuid_1>","<node_uuid_2>"]}'
|
||||||
|
```
|
||||||
|
|
||||||
|
### 7. 批量创建边
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X POST "$BASE/api/v1/lab/workflow/edges" \
|
||||||
|
-H "$AUTH" -H "Content-Type: application/json" \
|
||||||
|
-d '{"edges":[{"source_node_uuid":"<uuid>","target_node_uuid":"<uuid>","source_handle_uuid":"<uuid>","target_handle_uuid":"<uuid>"}]}'
|
||||||
|
```
|
||||||
|
|
||||||
|
### 8. 启动工作流
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X POST "$BASE/api/v1/lab/workflow/<workflow_uuid>/run" -H "$AUTH"
|
||||||
|
```
|
||||||
|
|
||||||
|
### 9. 运行设备单动作
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X POST "$BASE/api/v1/lab/mcp/run/action" \
|
||||||
|
-H "$AUTH" -H "Content-Type: application/json" \
|
||||||
|
-d '{"lab_uuid":"<lab_uuid>","device_id":"virtual_workbench","action":"<action_name>","action_type":"<type>","param":{...}}'
|
||||||
|
```
|
||||||
|
|
||||||
|
`param` 直接放 goal 里的属性,**不要**再包一层 `{"goal": {...}}`。
|
||||||
|
|
||||||
|
> **WARNING: `action_type` 必须正确,传错会导致任务永远卡住无法完成。** 从下表或 `actions/<name>.json` 的 `type` 字段获取。
|
||||||
|
|
||||||
|
#### action_type 速查表
|
||||||
|
|
||||||
|
| action | action_type |
|
||||||
|
|--------|-------------|
|
||||||
|
| `auto-prepare_materials` | `UniLabJsonCommand` |
|
||||||
|
| `auto-move_to_heating_station` | `UniLabJsonCommand` |
|
||||||
|
| `auto-start_heating` | `UniLabJsonCommand` |
|
||||||
|
| `auto-move_to_output` | `UniLabJsonCommand` |
|
||||||
|
| `transfer` | `UniLabJsonCommandAsync` |
|
||||||
|
| `manual_confirm` | `UniLabJsonCommand` |
|
||||||
|
|
||||||
|
### 10. 查询任务状态
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X GET "$BASE/api/v1/lab/mcp/task/<task_uuid>" -H "$AUTH"
|
||||||
|
```
|
||||||
|
|
||||||
|
### 11. 运行工作流单节点
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X POST "$BASE/api/v1/lab/mcp/run/workflow/action" \
|
||||||
|
-H "$AUTH" -H "Content-Type: application/json" \
|
||||||
|
-d '{"node_uuid":"<node_uuid>"}'
|
||||||
|
```
|
||||||
|
|
||||||
|
### 12. 获取资源树(物料信息)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X GET "$BASE/api/v1/lab/material/download/$lab_uuid" -H "$AUTH"
|
||||||
|
```
|
||||||
|
|
||||||
|
注意 `lab_uuid` 在路径中。返回 `data.nodes[]` 含所有节点(设备 + 物料),每个节点含 `name`、`uuid`、`type`、`parent`。
|
||||||
|
|
||||||
|
### 13. 获取工作流模板详情
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X GET "$BASE/api/v1/lab/workflow/template/detail/$workflow_uuid" -H "$AUTH"
|
||||||
|
```
|
||||||
|
|
||||||
|
> 必须使用 `/lab/workflow/template/detail/{uuid}`,其他路径会返回 404。
|
||||||
|
|
||||||
|
### 14. 按名称查询物料模板
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X GET "$BASE/api/v1/lab/material/template/by-name?lab_uuid=$lab_uuid&name=<template_name>" -H "$AUTH"
|
||||||
|
```
|
||||||
|
|
||||||
|
返回 `data.uuid` 为 `res_template_uuid`,用于 API #15。
|
||||||
|
|
||||||
|
### 15. 创建物料节点
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X POST "$BASE/api/v1/edge/material/node" \
|
||||||
|
-H "$AUTH" -H "Content-Type: application/json" \
|
||||||
|
-d '{"res_template_uuid":"<uuid>","name":"<名称>","display_name":"<显示名>","parent_uuid":"<父节点uuid>","data":{...}}'
|
||||||
|
```
|
||||||
|
|
||||||
|
### 16. 更新物料节点
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X PUT "$BASE/api/v1/edge/material/node" \
|
||||||
|
-H "$AUTH" -H "Content-Type: application/json" \
|
||||||
|
-d '{"uuid":"<节点uuid>","display_name":"<新名称>","data":{...}}'
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Placeholder Slot 填写规则
|
||||||
|
|
||||||
|
| `placeholder_keys` 值 | Slot 类型 | 填写格式 | 选取范围 |
|
||||||
|
| --------------------- | ------------ | ----------------------------------------------------- | ---------------------- |
|
||||||
|
| `unilabos_resources` | ResourceSlot | `{"id": "/path/name", "name": "name", "uuid": "xxx"}` | 仅物料节点(非设备) |
|
||||||
|
| `unilabos_devices` | DeviceSlot | `"/parent/device_name"` | 仅设备节点(type=device) |
|
||||||
|
| `unilabos_nodes` | NodeSlot | `"/parent/node_name"` | 所有节点(设备 + 物料) |
|
||||||
|
| `unilabos_class` | ClassSlot | `"class_name"` | 注册表中已注册的资源类 |
|
||||||
|
|
||||||
|
### virtual_workbench 设备的 Slot 字段表
|
||||||
|
|
||||||
|
| Action | 字段 | Slot 类型 | 说明 |
|
||||||
|
| ----------------- | ---------------- | ------------ | -------------------- |
|
||||||
|
| `transfer` | `resource` | ResourceSlot | 待转移物料数组 |
|
||||||
|
| `transfer` | `target_device` | DeviceSlot | 目标设备路径 |
|
||||||
|
| `transfer` | `mount_resource` | ResourceSlot | 目标孔位数组 |
|
||||||
|
| `manual_confirm` | `resource` | ResourceSlot | 确认用物料数组 |
|
||||||
|
| `manual_confirm` | `target_device` | DeviceSlot | 确认用目标设备 |
|
||||||
|
| `manual_confirm` | `mount_resource` | ResourceSlot | 确认用目标孔位数组 |
|
||||||
|
|
||||||
|
> `prepare_materials`、`move_to_heating_station`、`start_heating`、`move_to_output` 这 4 个动作**无 Slot 字段**,参数为纯数值/整数。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 渐进加载策略
|
||||||
|
|
||||||
|
1. **SKILL.md**(本文件)— API 端点 + session state 管理 + 设备工作流概览
|
||||||
|
2. **[action-index.md](action-index.md)** — 按分类浏览 6 个动作的描述和核心参数
|
||||||
|
3. **[actions/\<name\>.json](actions/)** — 仅在需要构建具体请求时,加载对应 action 的完整 JSON Schema
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 完整工作流 Checklist
|
||||||
|
|
||||||
|
```
|
||||||
|
Task Progress:
|
||||||
|
- [ ] Step 1: GET /edge/lab/info 获取 lab_uuid
|
||||||
|
- [ ] Step 2: 获取资源树 (GET #12) → 记住可用物料
|
||||||
|
- [ ] Step 3: 读 action-index.md 确定要用的 action 名
|
||||||
|
- [ ] Step 4: 创建工作流 (POST #2) → 记住 workflow_uuid,告知用户链接
|
||||||
|
- [ ] Step 5: 创建节点 (POST #3, resource_template_name=virtual_workbench) → 记住 node_uuid + data.param
|
||||||
|
- [ ] Step 6: 根据 _unilabos_placeholder_info 和资源树,填写 data.param 中的 Slot 字段
|
||||||
|
- [ ] Step 7: 更新节点参数 (PATCH #5)
|
||||||
|
- [ ] Step 8: 查询节点 handles (POST #6) → 获取各节点的 handle_uuid
|
||||||
|
- [ ] Step 9: 批量创建边 (POST #7) → 用 handle_uuid 连接节点
|
||||||
|
- [ ] Step 10: 启动工作流 (POST #8) 或运行单节点 (POST #11)
|
||||||
|
- [ ] Step 11: 查询任务状态 (GET #10) 确认完成
|
||||||
|
```
|
||||||
|
|
||||||
|
### 典型 5 物料并发加热工作流示例
|
||||||
|
|
||||||
|
```
|
||||||
|
prepare_materials (count=5)
|
||||||
|
├─ channel_1 → move_to_heating_station (material_number=1) → start_heating → move_to_output
|
||||||
|
├─ channel_2 → move_to_heating_station (material_number=2) → start_heating → move_to_output
|
||||||
|
├─ channel_3 → move_to_heating_station (material_number=3) → start_heating → move_to_output
|
||||||
|
├─ channel_4 → move_to_heating_station (material_number=4) → start_heating → move_to_output
|
||||||
|
└─ channel_5 → move_to_heating_station (material_number=5) → start_heating → move_to_output
|
||||||
|
```
|
||||||
|
|
||||||
|
创建节点时,`prepare_materials` 的 5 个 output handle(`channel_1` ~ `channel_5`)分别连接到 5 个 `move_to_heating_station` 节点的 `material_input` handle。每个 `move_to_heating_station` 的 `heating_station_output` 和 `material_number_output` 连接到对应 `start_heating` 的 `station_id_input` 和 `material_number_input`。
|
||||||
76
.cursor/skills/virtual-workbench/action-index.md
Normal file
76
.cursor/skills/virtual-workbench/action-index.md
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
# Action Index — virtual_workbench
|
||||||
|
|
||||||
|
6 个动作,按功能分类。每个动作的完整 JSON Schema 在 `actions/<name>.json`。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 物料准备
|
||||||
|
|
||||||
|
### `auto-prepare_materials`
|
||||||
|
|
||||||
|
批量准备物料(虚拟起始节点),生成 A1-A5 物料编号,输出 5 个 handle 供后续节点使用
|
||||||
|
|
||||||
|
- **action_type**: `UniLabJsonCommand`
|
||||||
|
- **Schema**: [`actions/prepare_materials.json`](actions/prepare_materials.json)
|
||||||
|
- **可选参数**: `count`(物料数量,默认 5)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 机械臂 & 加热台操作
|
||||||
|
|
||||||
|
### `auto-move_to_heating_station`
|
||||||
|
|
||||||
|
将物料从 An 位置移动到空闲加热台(竞争机械臂,自动查找空闲加热台)
|
||||||
|
|
||||||
|
- **action_type**: `UniLabJsonCommand`
|
||||||
|
- **Schema**: [`actions/move_to_heating_station.json`](actions/move_to_heating_station.json)
|
||||||
|
- **核心参数**: `material_number`(物料编号,integer)
|
||||||
|
|
||||||
|
### `auto-start_heating`
|
||||||
|
|
||||||
|
启动指定加热台的加热程序(可并行,3 个加热台同时工作)
|
||||||
|
|
||||||
|
- **action_type**: `UniLabJsonCommand`
|
||||||
|
- **Schema**: [`actions/start_heating.json`](actions/start_heating.json)
|
||||||
|
- **核心参数**: `station_id`(加热台 ID),`material_number`(物料编号)
|
||||||
|
|
||||||
|
### `auto-move_to_output`
|
||||||
|
|
||||||
|
将加热完成的物料从加热台移动到输出位置 Cn
|
||||||
|
|
||||||
|
- **action_type**: `UniLabJsonCommand`
|
||||||
|
- **Schema**: [`actions/move_to_output.json`](actions/move_to_output.json)
|
||||||
|
- **核心参数**: `station_id`(加热台 ID),`material_number`(物料编号)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 物料转移
|
||||||
|
|
||||||
|
### `transfer`
|
||||||
|
|
||||||
|
异步转移物料到目标设备(通过 ROS 资源转移)
|
||||||
|
|
||||||
|
- **action_type**: `UniLabJsonCommandAsync`
|
||||||
|
- **Schema**: [`actions/transfer.json`](actions/transfer.json)
|
||||||
|
- **核心参数**: `resource`, `target_device`, `mount_resource`
|
||||||
|
- **占位符字段**:
|
||||||
|
- `resource` — **ResourceSlot**,待转移的物料数组 `[{id, name, uuid}, ...]`
|
||||||
|
- `target_device` — **DeviceSlot**,目标设备路径字符串
|
||||||
|
- `mount_resource` — **ResourceSlot**,目标孔位数组 `[{id, name, uuid}, ...]`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 人工确认
|
||||||
|
|
||||||
|
### `manual_confirm`
|
||||||
|
|
||||||
|
创建人工确认节点,等待用户手动确认后继续(含物料转移上下文)
|
||||||
|
|
||||||
|
- **action_type**: `UniLabJsonCommand`
|
||||||
|
- **Schema**: [`actions/manual_confirm.json`](actions/manual_confirm.json)
|
||||||
|
- **核心参数**: `resource`, `target_device`, `mount_resource`, `timeout_seconds`, `assignee_user_ids`
|
||||||
|
- **占位符字段**:
|
||||||
|
- `resource` — **ResourceSlot**,物料数组
|
||||||
|
- `target_device` — **DeviceSlot**,目标设备路径
|
||||||
|
- `mount_resource` — **ResourceSlot**,目标孔位数组
|
||||||
|
- `assignee_user_ids` — `unilabos_manual_confirm` 类型
|
||||||
270
.cursor/skills/virtual-workbench/actions/manual_confirm.json
Normal file
270
.cursor/skills/virtual-workbench/actions/manual_confirm.json
Normal file
@@ -0,0 +1,270 @@
|
|||||||
|
{
|
||||||
|
"type": "UniLabJsonCommand",
|
||||||
|
"goal": {
|
||||||
|
"resource": "resource",
|
||||||
|
"target_device": "target_device",
|
||||||
|
"mount_resource": "mount_resource",
|
||||||
|
"timeout_seconds": "timeout_seconds",
|
||||||
|
"assignee_user_ids": "assignee_user_ids"
|
||||||
|
},
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"resource": {
|
||||||
|
"items": {
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": false,
|
||||||
|
"properties": {
|
||||||
|
"id": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"sample_id": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"children": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"parent": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"type": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"category": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"pose": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"position": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"x": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"y": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"z": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"x",
|
||||||
|
"y",
|
||||||
|
"z"
|
||||||
|
],
|
||||||
|
"title": "position",
|
||||||
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"orientation": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"x": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"y": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"z": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"w": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"x",
|
||||||
|
"y",
|
||||||
|
"z",
|
||||||
|
"w"
|
||||||
|
],
|
||||||
|
"title": "orientation",
|
||||||
|
"additionalProperties": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"position",
|
||||||
|
"orientation"
|
||||||
|
],
|
||||||
|
"title": "pose",
|
||||||
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"config": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"data": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"title": "resource"
|
||||||
|
},
|
||||||
|
"type": "array"
|
||||||
|
},
|
||||||
|
"target_device": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "device reference"
|
||||||
|
},
|
||||||
|
"mount_resource": {
|
||||||
|
"items": {
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": false,
|
||||||
|
"properties": {
|
||||||
|
"id": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"sample_id": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"children": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"parent": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"type": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"category": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"pose": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"position": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"x": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"y": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"z": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"x",
|
||||||
|
"y",
|
||||||
|
"z"
|
||||||
|
],
|
||||||
|
"title": "position",
|
||||||
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"orientation": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"x": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"y": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"z": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"w": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"x",
|
||||||
|
"y",
|
||||||
|
"z",
|
||||||
|
"w"
|
||||||
|
],
|
||||||
|
"title": "orientation",
|
||||||
|
"additionalProperties": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"position",
|
||||||
|
"orientation"
|
||||||
|
],
|
||||||
|
"title": "pose",
|
||||||
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"config": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"data": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"title": "mount_resource"
|
||||||
|
},
|
||||||
|
"type": "array"
|
||||||
|
},
|
||||||
|
"timeout_seconds": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"assignee_user_ids": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"resource",
|
||||||
|
"target_device",
|
||||||
|
"mount_resource",
|
||||||
|
"timeout_seconds",
|
||||||
|
"assignee_user_ids"
|
||||||
|
],
|
||||||
|
"_unilabos_placeholder_info": {
|
||||||
|
"resource": "unilabos_resources",
|
||||||
|
"target_device": "unilabos_devices",
|
||||||
|
"mount_resource": "unilabos_resources",
|
||||||
|
"assignee_user_ids": "unilabos_manual_confirm"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"goal_default": {},
|
||||||
|
"placeholder_keys": {
|
||||||
|
"resource": "unilabos_resources",
|
||||||
|
"target_device": "unilabos_devices",
|
||||||
|
"mount_resource": "unilabos_resources",
|
||||||
|
"assignee_user_ids": "unilabos_manual_confirm"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"type": "UniLabJsonCommand",
|
||||||
|
"goal": {
|
||||||
|
"material_number": "material_number"
|
||||||
|
},
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"material_number": {
|
||||||
|
"type": "integer"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"material_number"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"goal_default": {},
|
||||||
|
"placeholder_keys": {}
|
||||||
|
}
|
||||||
24
.cursor/skills/virtual-workbench/actions/move_to_output.json
Normal file
24
.cursor/skills/virtual-workbench/actions/move_to_output.json
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"type": "UniLabJsonCommand",
|
||||||
|
"goal": {
|
||||||
|
"station_id": "station_id",
|
||||||
|
"material_number": "material_number"
|
||||||
|
},
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"station_id": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"material_number": {
|
||||||
|
"type": "integer"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"station_id",
|
||||||
|
"material_number"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"goal_default": {},
|
||||||
|
"placeholder_keys": {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"type": "UniLabJsonCommand",
|
||||||
|
"goal": {
|
||||||
|
"count": "count"
|
||||||
|
},
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"count": {
|
||||||
|
"type": "integer",
|
||||||
|
"default": 5
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": []
|
||||||
|
},
|
||||||
|
"goal_default": {
|
||||||
|
"count": 5
|
||||||
|
},
|
||||||
|
"placeholder_keys": {}
|
||||||
|
}
|
||||||
24
.cursor/skills/virtual-workbench/actions/start_heating.json
Normal file
24
.cursor/skills/virtual-workbench/actions/start_heating.json
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"type": "UniLabJsonCommand",
|
||||||
|
"goal": {
|
||||||
|
"station_id": "station_id",
|
||||||
|
"material_number": "material_number"
|
||||||
|
},
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"station_id": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"material_number": {
|
||||||
|
"type": "integer"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"station_id",
|
||||||
|
"material_number"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"goal_default": {},
|
||||||
|
"placeholder_keys": {}
|
||||||
|
}
|
||||||
255
.cursor/skills/virtual-workbench/actions/transfer.json
Normal file
255
.cursor/skills/virtual-workbench/actions/transfer.json
Normal file
@@ -0,0 +1,255 @@
|
|||||||
|
{
|
||||||
|
"type": "UniLabJsonCommandAsync",
|
||||||
|
"goal": {
|
||||||
|
"resource": "resource",
|
||||||
|
"target_device": "target_device",
|
||||||
|
"mount_resource": "mount_resource"
|
||||||
|
},
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"resource": {
|
||||||
|
"items": {
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": false,
|
||||||
|
"properties": {
|
||||||
|
"id": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"sample_id": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"children": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"parent": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"type": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"category": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"pose": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"position": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"x": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"y": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"z": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"x",
|
||||||
|
"y",
|
||||||
|
"z"
|
||||||
|
],
|
||||||
|
"title": "position",
|
||||||
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"orientation": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"x": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"y": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"z": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"w": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"x",
|
||||||
|
"y",
|
||||||
|
"z",
|
||||||
|
"w"
|
||||||
|
],
|
||||||
|
"title": "orientation",
|
||||||
|
"additionalProperties": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"position",
|
||||||
|
"orientation"
|
||||||
|
],
|
||||||
|
"title": "pose",
|
||||||
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"config": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"data": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"title": "resource"
|
||||||
|
},
|
||||||
|
"type": "array"
|
||||||
|
},
|
||||||
|
"target_device": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "device reference"
|
||||||
|
},
|
||||||
|
"mount_resource": {
|
||||||
|
"items": {
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": false,
|
||||||
|
"properties": {
|
||||||
|
"id": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"sample_id": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"children": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"parent": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"type": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"category": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"pose": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"position": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"x": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"y": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"z": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"x",
|
||||||
|
"y",
|
||||||
|
"z"
|
||||||
|
],
|
||||||
|
"title": "position",
|
||||||
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"orientation": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"x": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"y": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"z": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"w": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"x",
|
||||||
|
"y",
|
||||||
|
"z",
|
||||||
|
"w"
|
||||||
|
],
|
||||||
|
"title": "orientation",
|
||||||
|
"additionalProperties": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"position",
|
||||||
|
"orientation"
|
||||||
|
],
|
||||||
|
"title": "pose",
|
||||||
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"config": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"data": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"title": "mount_resource"
|
||||||
|
},
|
||||||
|
"type": "array"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"resource",
|
||||||
|
"target_device",
|
||||||
|
"mount_resource"
|
||||||
|
],
|
||||||
|
"_unilabos_placeholder_info": {
|
||||||
|
"resource": "unilabos_resources",
|
||||||
|
"target_device": "unilabos_devices",
|
||||||
|
"mount_resource": "unilabos_resources"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"goal_default": {},
|
||||||
|
"placeholder_keys": {
|
||||||
|
"resource": "unilabos_resources",
|
||||||
|
"target_device": "unilabos_devices",
|
||||||
|
"mount_resource": "unilabos_resources"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
.conda
|
|
||||||
# .github
|
|
||||||
.idea
|
|
||||||
# .vscode
|
|
||||||
output
|
|
||||||
pylabrobot_repo
|
|
||||||
recipes
|
|
||||||
scripts
|
|
||||||
service
|
|
||||||
temp
|
|
||||||
# unilabos/test
|
|
||||||
# unilabos/app/web
|
|
||||||
unilabos/device_mesh
|
|
||||||
unilabos_data
|
|
||||||
unilabos_msgs
|
|
||||||
unilabos.egg-info
|
|
||||||
CONTRIBUTORS
|
|
||||||
# LICENSE
|
|
||||||
MANIFEST.in
|
|
||||||
pyrightconfig.json
|
|
||||||
# README.md
|
|
||||||
# README_zh.md
|
|
||||||
setup.py
|
|
||||||
setup.cfg
|
|
||||||
.gitattrubutes
|
|
||||||
**/__pycache__
|
|
||||||
19
.github/dependabot.yml
vendored
Normal file
19
.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
# GitHub Actions
|
||||||
|
- package-ecosystem: "github-actions"
|
||||||
|
directory: "/"
|
||||||
|
target-branch: "dev"
|
||||||
|
schedule:
|
||||||
|
interval: "weekly"
|
||||||
|
day: "monday"
|
||||||
|
time: "06:00"
|
||||||
|
open-pull-requests-limit: 5
|
||||||
|
reviewers:
|
||||||
|
- "msgcenterpy-team"
|
||||||
|
labels:
|
||||||
|
- "dependencies"
|
||||||
|
- "github-actions"
|
||||||
|
commit-message:
|
||||||
|
prefix: "ci"
|
||||||
|
include: "scope"
|
||||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -252,5 +252,3 @@ ros-humble-unilabos-msgs-0.9.13-h6403a04_5.tar.bz2
|
|||||||
test_config.py
|
test_config.py
|
||||||
|
|
||||||
|
|
||||||
/.claude
|
|
||||||
/.cursor
|
|
||||||
|
|||||||
85
AGENTS.md
85
AGENTS.md
@@ -23,11 +23,8 @@ unilab --skip_env_check # skip auto-install of dependencies
|
|||||||
unilab --visual rviz|web|disable # visualization mode
|
unilab --visual rviz|web|disable # visualization mode
|
||||||
unilab --is_slave # run as slave node
|
unilab --is_slave # run as slave node
|
||||||
|
|
||||||
# Workflow upload subcommand(P6.1 新增 --target_device;P6.1.1 新增 --target_model)
|
# Workflow upload subcommand
|
||||||
unilab workflow_upload -f <workflow.json> -n <name> --tags tag1 tag2
|
unilab workflow_upload -f <workflow.json> -n <name> --tags tag1 tag2
|
||||||
unilab workflow_upload -f <workflow.json> --target_device prcxi # P6.1 默认;同上 P6 行为
|
|
||||||
unilab workflow_upload -f <workflow.json> --target_device prcxi --target_model 9320 # P6.1.1:型号粒度
|
|
||||||
unilab workflow_upload -f <workflow.json> --target_device beckman # 未来支持,需在 YAML 中声明 target_devices.beckman
|
|
||||||
|
|
||||||
# Tests
|
# Tests
|
||||||
pytest tests/ # all tests
|
pytest tests/ # all tests
|
||||||
@@ -75,86 +72,6 @@ pytest tests/resources/test_resourcetreeset.py::TestClassName::test_method # si
|
|||||||
|
|
||||||
Example device graphs and experiment configs are in `unilabos/test/experiments/` (not `tests/`). Registry test fixtures in `unilabos/test/registry/`.
|
Example device graphs and experiment configs are in `unilabos/test/experiments/` (not `tests/`). Registry test fixtures in `unilabos/test/registry/`.
|
||||||
|
|
||||||
### Labware Mapping Table (`labware_mapping.yaml`) — P6 + P6.1 + P6.1.1
|
|
||||||
|
|
||||||
Opentrons → 目标仪器(PRCXI / Beckman / Tecan ...)的「槽位重映射 + labware 归类 +
|
|
||||||
class_name 选择」全部外化到项目根的
|
|
||||||
[`labware_mapping.yaml`](./labware_mapping.yaml)(与 `pyproject.toml` 同级,最显眼的位置)。
|
|
||||||
要新增 SKU、新厂商、新型号、或调整 tip 量程档时,**只改 YAML,不改 Python**。
|
|
||||||
|
|
||||||
- **YAML 两段顶层语义**(P6.1.1 起 `slot_remap` 已下沉到 `target_devices` 内):
|
|
||||||
- `kinds` — 顺序敏感的 regex;把 labware 字符串归到 `trash / tip_rack / tube_rack / plate`。**全局段**,与目标仪器无关。
|
|
||||||
- `target_devices.<name>` — 按目标仪器组织的规则段,内含三个字段:
|
|
||||||
- `slot_remap` — 替代历史 `_map_deck_slot`(例:`4 → 13`、`8 → 14`、`12+trash → 16`)。
|
|
||||||
- `rules` — 顺序敏感的「`kind + hole_count + volume_min/volume_max` → `class_name`」规则,首个命中胜出。
|
|
||||||
- `models.<model_name>` — 可选的型号粒度覆盖(slot_remap / rules);缺失字段自动继承厂商级。
|
|
||||||
- **`target_devices` 内段名约定**:
|
|
||||||
- `default` — **固定段名**,兜底物料集 + 兜底 `slot_remap`。caller 传入的 `target_device` 在 `target_devices`
|
|
||||||
下未声明时,自动 fallback 到此段(loader 单次 warning,下游消费方零感知)。
|
|
||||||
**第一版按 prcxi 内容拷贝填充**(值仍是 `PRCXI_*`),但与 prcxi 段在 YAML 中
|
|
||||||
各自独立,可独立演进。**`default` 不支持 `models` 子段**——型号粒度差异必须落到具体仪器段。
|
|
||||||
- `prcxi` / `beckman` / `tecan` / ... — 具体仪器段(厂商粒度);caller 显式
|
|
||||||
`--target_device <name>` 时命中。可在 `models.<model>` 下声明同厂商不同型号的差异。
|
|
||||||
- **4 段 fallback 链**(`slot_remap` / `rules` 共用):
|
|
||||||
1. `target_devices.<device>.models.<model>.<field>`(caller 同时传 device + model)
|
|
||||||
2. `target_devices.<device>.<field>`(厂商级;步骤 1 缺字段时静默 fallback)
|
|
||||||
3. `target_devices.default.<field>`(caller 传未声明 device,或步骤 2 缺字段;打 warning)
|
|
||||||
4. `_BUILTIN_DEFAULT.target_devices.default.<field>`(YAML 误删 default 段时的最后兜底)
|
|
||||||
- **CLI 用法**:
|
|
||||||
- P6.1:`unilab workflow_upload -f <workflow.json> --target_device prcxi`
|
|
||||||
(`--target_device` snake-case,默认 `prcxi`;未声明的名字自动 fallback 到 `default` 段)。
|
|
||||||
- P6.1.1:可加 `--target_model <name>`(snake,可省略,默认 `None`)。
|
|
||||||
例:`unilab workflow_upload -f <workflow.json> --target_device prcxi --target_model 9320`。
|
|
||||||
- **入口代码**:`unilabos/workflow/labware_mapping.py` 暴露 `remap_slot` / `infer_kind` /
|
|
||||||
`resolve_target_class` / `reload_mapping`。
|
|
||||||
API 签名(P6.1.1):
|
|
||||||
- `remap_slot(raw_slot, object_type="", *, target_device="prcxi", target_model=None)`
|
|
||||||
- `resolve_target_class(target_device, kind, hole_count=None, volume=None, *, target_model=None)`
|
|
||||||
`workflow/common.py` 中 `_map_deck_slot` / `_infer_reagent_kind` /
|
|
||||||
`_apply_tip_rack_class_from_transfer_volumes` / `_apply_target_labware_class_auto_match` /
|
|
||||||
`_reconcile_slot_carrier_target_class` 都已转调 YAML 并透传 `target_device` / `target_model`;
|
|
||||||
YAML 未命中(孔数 / 体积超出 default 段覆盖范围)时 fallback 到
|
|
||||||
`prcxi_labware.get_prcxi_labware_template_specs` 的模板打分匹配,并打 warning 提示「请补到映射表」。
|
|
||||||
- **`labware_info` 字段重命名**:P6 的 `prcxi_class_name` → P6.1 的 `target_class_name`,
|
|
||||||
13 处全部同步刷新;旧 schema(顶层 `vendors` / `slot_remap` 或任一 rule 内 `prcxi_class`)
|
|
||||||
会触发 loader warning 并整段 fallback 到 builtin 默认表。
|
|
||||||
- **测试**:
|
|
||||||
- `pytest tests/workflow/test_labware_mapping.py` —— 45 项单元测试(含 P6.1 + P6.1.1 用例:
|
|
||||||
`test_remap_slot_model_level_overrides_device_level`、
|
|
||||||
`test_remap_slot_model_inherits_device_when_field_missing`、
|
|
||||||
`test_legacy_top_level_slot_remap_rejected`、
|
|
||||||
`test_default_section_models_subsection_warns` 等)。
|
|
||||||
- `pytest tests/workflow/test_build_protocol_graph_target_device.py` —— 6 项集成
|
|
||||||
测试(默认 / 显式 prcxi / unknown 段 fallback / per-device tip class / 字段重命名 /
|
|
||||||
P6.1.1 model-level slot_remap)。
|
|
||||||
- **设计文档**:[`product_designs/protocol_convert/06-labware-mapping-table.md`](../product_designs/protocol_convert/06-labware-mapping-table.md)
|
|
||||||
(§11.7 = P6.1 多目标仪器选择,§11.8 = P6.1.1 槽位映射按厂商+型号分叉)。
|
|
||||||
|
|
||||||
### P2 跨 slot transfer_liquid 合并(v2,已落地)
|
|
||||||
|
|
||||||
当一次 phase 中存在「单源吸取 → 跨多个 plate 分发」(典型 `steps/51b9a5.json` 9 plate × 12 well = 108 条 1:1 dispense),Stage 2 + Stage 3 现在能把它折叠成 **1 个 merged set_liquid_from_plate + 1 个 transfer_liquid** 节点。
|
|
||||||
|
|
||||||
- **Stage 2**([`Protocols/protocol_converter/change_to_transfer_group.py`](../Protocols/protocol_converter/change_to_transfer_group.py)):
|
|
||||||
- `_pair_mergeable` 只要求源 slot / tip 量程档 / use_channels 一致;不再要求 `_target_slot` 相同。
|
|
||||||
- `_merge_two_transfer_actions` 维护 `_target_slots: list[int]`(与 `_target_wells` 平行,每次 dispense 一条)。
|
|
||||||
- `export_transfer_actions` 通过 `_register_target_reagent_key` 统一注册 reagent_key:跨 slot 时按 `_target_slots` 顺序拼出 `action_args.targets: list[str]`(同板退化为 `str`)。
|
|
||||||
- 末尾 `pop` 全部 `_` 前缀字段(包括新增的 `_target_slots`)。
|
|
||||||
- **Stage 3**([`Uni-Lab-OS/unilabos/workflow/common.py`](unilabos/workflow/common.py)):
|
|
||||||
- 新增 `_emit_merged_set_liquid(...)`:对 `params.targets: list[str]` 的 transfer_liquid 节点,在其上游插入一个 **merged `set_liquid_from_plate`** 跨板聚合器;其 `param.wells` 是按 dispense 顺序通过 cursor 走 `reagent[key].well` 得出的有序跨板 well refs;多入边(每 plate 一条 `create_resource.labware → wells_identifier`),单出边(`output_wells → transfer_liquid.targets_identifier`)。
|
|
||||||
- 把 `params["targets"]` 改写为 synthetic str `_merged_targets_<idx>` 并注册 `resource_last_writer`,保证 INPUT_PORT_MAPPING 走 P3 既有的单边路径。
|
|
||||||
- `OUTPUT_PORT_MAPPING` 在原始 `step.param.targets` 为 `list[str]` 时为每个 reagent_key 分别注册 transfer_liquid 的下游 writer。
|
|
||||||
- **PRCXI runtime**([`prcxi/prcxi.py`](unilabos/devices/liquid_handling/prcxi/prcxi.py)):`change_slots` 改为遍历所有 source / target 的 parent plate 并按 plate name 去重(跨板 4 个 plate 都能 `update_pipetting_position`)。
|
|
||||||
- **`liquid_handler_abstract.transfer_liquid`**:**完全不改动**,主循环 `i % num_targets` 与单边 + 单 list 完全兼容。
|
|
||||||
|
|
||||||
CLI 行为不变:现有 `unilab workflow_upload -f <workflow.json> ...` 一切照旧;跨 slot 协议自动走 v2 路径。
|
|
||||||
|
|
||||||
测试:
|
|
||||||
- `pytest Protocols/protocol_converter/tests/test_cross_slot_merge.py` — Stage 2 单测 10 项。
|
|
||||||
- `pytest tests/workflow/test_common_cross_slot_v2.py` — Stage 3 集成测试 6 项。
|
|
||||||
- `pytest tests/devices/liquid_handling/test_set_liquid_from_plate_cross_plate.py` — device 跨板单测 6 项(pylabrobot 不全时优雅 skip)。
|
|
||||||
|
|
||||||
设计文档:[`product_designs/protocol_convert/02-cross-slot-merge.md`](../product_designs/protocol_convert/02-cross-slot-merge.md)(§9 v2 设计 + §11 落地记录)。
|
|
||||||
|
|
||||||
## Code Conventions
|
## Code Conventions
|
||||||
|
|
||||||
- Code comments and log messages in simplified Chinese
|
- Code comments and log messages in simplified Chinese
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,140 +0,0 @@
|
|||||||
# Opentrons → 目标仪器 物料映射表(P6.1.1)
|
|
||||||
#
|
|
||||||
# 两段顶层 key(P6.1.1 起 slot_remap 从顶层下沉到 target_devices 内):
|
|
||||||
# kinds : labware 字符串 → kind 归类(与目标仪器无关,**保留全局**)
|
|
||||||
# target_devices : 按目标仪器 + 型号组织;rule = kind + hole_count + volume_min/max → class_name;
|
|
||||||
# slot_remap 也内嵌在 target_devices 下(按 deck 物理布局变化)
|
|
||||||
#
|
|
||||||
# target_devices 段内结构:
|
|
||||||
# target_devices.<device>: # 厂商段(必填)
|
|
||||||
# slot_remap: {...} # 厂商级默认 slot 映射(缺失 → 继承 default 段)
|
|
||||||
# rules: [...] # 厂商级规则(缺失 → 继承 default 段)
|
|
||||||
# models: # 同厂商多型号(可选;缺失 = 仅厂商级,不区分型号)
|
|
||||||
# <model_name>: # 型号子段
|
|
||||||
# slot_remap: {...} # 型号级覆盖(缺失 → 继承厂商级)
|
|
||||||
# rules: [...] # 型号级覆盖(缺失 → 继承厂商级)
|
|
||||||
#
|
|
||||||
# 段名约定:
|
|
||||||
# target_devices.default : 兜底物料集 + 兜底 slot_remap。caller 传未声明的 target_device 时使用此段。
|
|
||||||
# **不支持 models 子段**(型号粒度差异必须落到具体仪器段,否则歧义)。
|
|
||||||
# target_devices.<name> : 具体仪器段(prcxi / beckman / tecan ...)。
|
|
||||||
#
|
|
||||||
# 解析链(remap_slot / resolve_target_class 共用,字段级 fallback):
|
|
||||||
# 1. target_devices.<device>.models.<model>.<field> (caller 同时传 device + model)
|
|
||||||
# 2. target_devices.<device>.<field> (caller 传 device,或步骤 1 缺字段)
|
|
||||||
# 3. target_devices.default.<field> (caller 传未声明 device,或步骤 2 缺字段)
|
|
||||||
# 4. _BUILTIN_DEFAULT.target_devices.default.<field> (YAML 误删 default 段时的最后兜底)
|
|
||||||
#
|
|
||||||
# 编辑建议:
|
|
||||||
# 1. 顺序敏感:kinds 与 rules 内首个命中胜出;窄规则在前、宽规则在后。
|
|
||||||
# 2. volume_min / volume_max 是闭区间(µL)。任一字段可省略;都省略 = 不限制体积。
|
|
||||||
# 3. notes 仅作注释,不参与匹配。
|
|
||||||
# 4. 新增目标仪器:复制 target_devices.prcxi 段、改 device 名、改 slot_remap + rules。
|
|
||||||
# 5. 同厂商不同型号:在 target_devices.<device>.models.<model> 下显式覆盖差异字段;
|
|
||||||
# 没声明的字段自动继承厂商级。
|
|
||||||
# 6. P6.1.1 不再支持顶层 slot_remap;检出顶层 slot_remap → warning + fallback 到 builtin。
|
|
||||||
#
|
|
||||||
# 设计文档:product_designs/protocol_convert/06-labware-mapping-table.md(§11.8)
|
|
||||||
|
|
||||||
kinds:
|
|
||||||
# 顺序敏感的 regex;第一个命中胜出
|
|
||||||
# 注意:trash 必须在 tip_rack 之前;tip_rack 必须在 tube_rack 之前("tuberack" 含 "rack")
|
|
||||||
- { pattern: "trash", kind: trash }
|
|
||||||
- { pattern: "tiprack|tip[_ ]?rack|opentrons_\\d+_tiprack", kind: tip_rack }
|
|
||||||
- { pattern: "tuberack|tube[_ ]rack|eppendorf.*rack|safelock.*rack", kind: tube_rack }
|
|
||||||
# 「<labware> 含 'rack' 但不含 'tip'」也归到 tube_rack(与历史 _infer_reagent_kind 行为一致)
|
|
||||||
- { pattern: "(?:^|[^a-z])rack(?:[^a-z]|$)", kind: tube_rack }
|
|
||||||
- { pattern: ".*", kind: plate }
|
|
||||||
|
|
||||||
target_devices:
|
|
||||||
# ─────────────────────────────────────────────────────────────────────────
|
|
||||||
# default:兜底物料集 + 兜底 slot_remap。
|
|
||||||
# caller 传未声明的 target_device 时使用本段;**不支持 models 子段**。
|
|
||||||
# 第一版内容按 prcxi 拷贝填充(值仍是 PRCXI_*),但语义独立,可独立演进。
|
|
||||||
# ─────────────────────────────────────────────────────────────────────────
|
|
||||||
default:
|
|
||||||
notes: "默认兜底物料集;caller 传未声明 target_device 时使用此段。第一版按 prcxi 拷贝填充。"
|
|
||||||
slot_remap:
|
|
||||||
# raw slot → deck slot;与对象类型无关
|
|
||||||
default:
|
|
||||||
"4": "13"
|
|
||||||
"8": "14"
|
|
||||||
# 按 object 字段覆盖 default
|
|
||||||
by_object:
|
|
||||||
trash:
|
|
||||||
"12": "16"
|
|
||||||
rules:
|
|
||||||
# ─ tip rack(默认量程档:≤10 / <300 / 否则 1000) ─
|
|
||||||
- { kind: tip_rack, hole_count: 96, volume_max: 10, class_name: PRCXI_10uL_Tips }
|
|
||||||
- { kind: tip_rack, hole_count: 96, volume_max: 299.9, class_name: PRCXI_300ul_Tips }
|
|
||||||
- { kind: tip_rack, hole_count: 96, class_name: PRCXI_1000uL_Tips }
|
|
||||||
# ─ tube rack ─
|
|
||||||
- { kind: tube_rack, hole_count: 24, class_name: PRCXI_EP_Adapter, notes: "Eppendorf 1.5/2 mL 24 位 4×6" }
|
|
||||||
- { kind: tube_rack, hole_count: 10, class_name: PRCXI_EP_Adapter, notes: "Falcon 4x50 + 6x15 mL(10 位兼容 4×6 适配器)" }
|
|
||||||
# ─ plate ─
|
|
||||||
- { kind: plate, hole_count: 96, class_name: PRCXI_BioER_96_wellplate }
|
|
||||||
- { kind: plate, hole_count: 384, class_name: PRCXI_BioER_384_wellplate }
|
|
||||||
# ─ trash ─
|
|
||||||
- { kind: trash, class_name: PRCXI_trash }
|
|
||||||
|
|
||||||
# ─────────────────────────────────────────────────────────────────────────
|
|
||||||
# prcxi:PRCXI 仪器专用段。caller 显式传 --target_device prcxi 时命中此段。
|
|
||||||
# 厂商级 slot_remap + rules 适用于"未声明 model"的调用;
|
|
||||||
# models 子段下声明同厂商不同型号的 deck 物理布局差异。
|
|
||||||
# ─────────────────────────────────────────────────────────────────────────
|
|
||||||
prcxi:
|
|
||||||
slot_remap:
|
|
||||||
# PRCXI 多数型号通用的 deck 物理布局映射
|
|
||||||
default:
|
|
||||||
"4": "13"
|
|
||||||
"8": "14"
|
|
||||||
by_object:
|
|
||||||
trash:
|
|
||||||
"12": "16"
|
|
||||||
rules:
|
|
||||||
# ─ tip rack(PRCXI 量程档:≤10 / <300 / 否则 1000) ─
|
|
||||||
- { kind: tip_rack, hole_count: 96, volume_max: 10, class_name: PRCXI_10uL_Tips }
|
|
||||||
- { kind: tip_rack, hole_count: 96, volume_max: 299.9, class_name: PRCXI_300ul_Tips }
|
|
||||||
- { kind: tip_rack, hole_count: 96, class_name: PRCXI_1000uL_Tips }
|
|
||||||
# ─ tube rack ─
|
|
||||||
- { kind: tube_rack, hole_count: 24, class_name: PRCXI_EP_Adapter, notes: "Eppendorf 1.5/2 mL 24 位 4×6" }
|
|
||||||
- { kind: tube_rack, hole_count: 10, class_name: PRCXI_EP_Adapter, notes: "Falcon 4x50 + 6x15 mL(10 位兼容 4×6 适配器)" }
|
|
||||||
# ─ plate ─
|
|
||||||
- { kind: plate, hole_count: 96, class_name: PRCXI_BioER_96_wellplate }
|
|
||||||
- { kind: plate, hole_count: 384, class_name: PRCXI_BioER_384_wellplate }
|
|
||||||
# ─ trash ─
|
|
||||||
- { kind: trash, class_name: PRCXI_trash }
|
|
||||||
models:
|
|
||||||
# PRCXI 9320 —— 与厂商级完全一致(空 dict 仅作为合法 model 名占位)。
|
|
||||||
# caller `--target_model 9320` 时所有字段继承厂商级 prcxi 段。
|
|
||||||
"9320": {}
|
|
||||||
# 演示:假想 PRCXI 4040 把 slot 4 物理位换到 16、trash 槽换到 20。
|
|
||||||
# 仅 slot_remap 不同;rules 与厂商级一致 → 不重复声明(自动继承)。
|
|
||||||
"4040":
|
|
||||||
slot_remap:
|
|
||||||
default:
|
|
||||||
"4": "16"
|
|
||||||
"8": "14"
|
|
||||||
by_object:
|
|
||||||
trash:
|
|
||||||
"12": "20"
|
|
||||||
|
|
||||||
# ─────────────────────────────────────────────────────────────────────────
|
|
||||||
# 演示:未来加新仪器只复制 prcxi 段、改 device 名 + slot_remap + rules。
|
|
||||||
# 特别注意 tip 量程档可与 PRCXI 不同。
|
|
||||||
# ─────────────────────────────────────────────────────────────────────────
|
|
||||||
# beckman:
|
|
||||||
# slot_remap:
|
|
||||||
# default: {"4": "13"}
|
|
||||||
# by_object: {trash: {"12": "16"}}
|
|
||||||
# rules:
|
|
||||||
# - { kind: tip_rack, hole_count: 96, volume_max: 20, class_name: Beckman_20uL_Tips }
|
|
||||||
# - { kind: tip_rack, hole_count: 96, volume_max: 199.9, class_name: Beckman_200uL_Tips }
|
|
||||||
# - { kind: tip_rack, hole_count: 96, class_name: Beckman_1000uL_Tips }
|
|
||||||
# - { kind: tube_rack, hole_count: 24, class_name: Beckman_24_TubeRack }
|
|
||||||
# - { kind: plate, hole_count: 96, class_name: Beckman_BioMek_96_wellplate }
|
|
||||||
# - { kind: trash, class_name: Beckman_Trash }
|
|
||||||
# models:
|
|
||||||
# "i7":
|
|
||||||
# slot_remap:
|
|
||||||
# default: {"4": "13", "5": "14"} # 假想 i7 多一个 slot 重映射
|
|
||||||
@@ -1,539 +0,0 @@
|
|||||||
import pytest
|
|
||||||
import json
|
|
||||||
import os
|
|
||||||
import asyncio
|
|
||||||
import collections
|
|
||||||
from typing import List, Dict, Any
|
|
||||||
|
|
||||||
from pylabrobot.resources import Coordinate
|
|
||||||
from pylabrobot.resources.opentrons.tip_racks import opentrons_96_tiprack_300ul, opentrons_96_tiprack_10ul
|
|
||||||
from pylabrobot.resources.opentrons.plates import corning_96_wellplate_360ul_flat, nest_96_wellplate_2ml_deep
|
|
||||||
|
|
||||||
from unilabos.devices.liquid_handling.prcxi.prcxi import (
|
|
||||||
PRCXI9300Deck,
|
|
||||||
PRCXI9300Container,
|
|
||||||
PRCXI9300Trash,
|
|
||||||
PRCXI9300Handler,
|
|
||||||
PRCXI9300Backend,
|
|
||||||
DefaultLayout,
|
|
||||||
Material,
|
|
||||||
WorkTablets,
|
|
||||||
MatrixInfo
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def prcxi_materials() -> Dict[str, Any]:
|
|
||||||
"""加载 PRCXI 物料数据"""
|
|
||||||
print("加载 PRCXI 物料数据...")
|
|
||||||
material_path = os.path.join(os.path.dirname(__file__), "..", "..", "unilabos", "devices", "liquid_handling", "prcxi", "prcxi_material.json")
|
|
||||||
with open(material_path, "r", encoding="utf-8") as f:
|
|
||||||
data = json.load(f)
|
|
||||||
print(f"加载了 {len(data)} 条物料数据")
|
|
||||||
return data
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def prcxi_9300_deck() -> PRCXI9300Deck:
|
|
||||||
"""创建 PRCXI 9300 工作台"""
|
|
||||||
return PRCXI9300Deck(name="PRCXI_Deck_9300", size_x=100, size_y=100, size_z=100, model="9300")
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def prcxi_9320_deck() -> PRCXI9300Deck:
|
|
||||||
"""创建 PRCXI 9320 工作台"""
|
|
||||||
return PRCXI9300Deck(name="PRCXI_Deck_9320", size_x=100, size_y=100, size_z=100, model="9320")
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def prcxi_9300_handler(prcxi_9300_deck) -> PRCXI9300Handler:
|
|
||||||
"""创建 PRCXI 9300 处理器(模拟模式)"""
|
|
||||||
return PRCXI9300Handler(
|
|
||||||
deck=prcxi_9300_deck,
|
|
||||||
host="192.168.1.201",
|
|
||||||
port=9999,
|
|
||||||
timeout=10.0,
|
|
||||||
channel_num=8,
|
|
||||||
axis="Left",
|
|
||||||
setup=False,
|
|
||||||
debug=True,
|
|
||||||
simulator=True,
|
|
||||||
matrix_id="test-matrix-9300"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def prcxi_9320_handler(prcxi_9320_deck) -> PRCXI9300Handler:
|
|
||||||
"""创建 PRCXI 9320 处理器(模拟模式)"""
|
|
||||||
return PRCXI9300Handler(
|
|
||||||
deck=prcxi_9320_deck,
|
|
||||||
host="192.168.1.201",
|
|
||||||
port=9999,
|
|
||||||
timeout=10.0,
|
|
||||||
channel_num=1,
|
|
||||||
axis="Right",
|
|
||||||
setup=False,
|
|
||||||
debug=True,
|
|
||||||
simulator=True,
|
|
||||||
matrix_id="test-matrix-9320",
|
|
||||||
is_9320=True
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def tip_rack_300ul(prcxi_materials) -> PRCXI9300Container:
|
|
||||||
"""创建 300μL 枪头盒"""
|
|
||||||
tip_rack = PRCXI9300Container(
|
|
||||||
name="tip_rack_300ul",
|
|
||||||
size_x=50,
|
|
||||||
size_y=50,
|
|
||||||
size_z=10,
|
|
||||||
category="tip_rack",
|
|
||||||
ordering=collections.OrderedDict()
|
|
||||||
)
|
|
||||||
tip_rack.load_state({
|
|
||||||
"Material": {
|
|
||||||
"uuid": prcxi_materials["300μL Tip头"]["uuid"],
|
|
||||||
"Code": "ZX-001-300",
|
|
||||||
"Name": "300μL Tip头"
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return tip_rack
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def tip_rack_10ul(prcxi_materials) -> PRCXI9300Container:
|
|
||||||
"""创建 10μL 枪头盒"""
|
|
||||||
tip_rack = PRCXI9300Container(
|
|
||||||
name="tip_rack_10ul",
|
|
||||||
size_x=50,
|
|
||||||
size_y=50,
|
|
||||||
size_z=10,
|
|
||||||
category="tip_rack",
|
|
||||||
ordering=collections.OrderedDict()
|
|
||||||
)
|
|
||||||
tip_rack.load_state({
|
|
||||||
"Material": {
|
|
||||||
"uuid": prcxi_materials["10μL加长 Tip头"]["uuid"],
|
|
||||||
"Code": "ZX-001-10+",
|
|
||||||
"Name": "10μL加长 Tip头"
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return tip_rack
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def well_plate_96(prcxi_materials) -> PRCXI9300Container:
|
|
||||||
"""创建 96 孔板"""
|
|
||||||
plate = PRCXI9300Container(
|
|
||||||
name="well_plate_96",
|
|
||||||
size_x=50,
|
|
||||||
size_y=50,
|
|
||||||
size_z=10,
|
|
||||||
category="plate",
|
|
||||||
ordering=collections.OrderedDict()
|
|
||||||
)
|
|
||||||
plate.load_state({
|
|
||||||
"Material": {
|
|
||||||
"uuid": prcxi_materials["96深孔板"]["uuid"],
|
|
||||||
"Code": "ZX-019-2.2",
|
|
||||||
"Name": "96深孔板"
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return plate
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def deep_well_plate(prcxi_materials) -> PRCXI9300Container:
|
|
||||||
"""创建深孔板"""
|
|
||||||
plate = PRCXI9300Container(
|
|
||||||
name="deep_well_plate",
|
|
||||||
size_x=50,
|
|
||||||
size_y=50,
|
|
||||||
size_z=10,
|
|
||||||
category="plate",
|
|
||||||
ordering=collections.OrderedDict()
|
|
||||||
)
|
|
||||||
plate.load_state({
|
|
||||||
"Material": {
|
|
||||||
"uuid": prcxi_materials["96深孔板"]["uuid"],
|
|
||||||
"Code": "ZX-019-2.2",
|
|
||||||
"Name": "96深孔板"
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return plate
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def trash_container(prcxi_materials) -> PRCXI9300Trash:
|
|
||||||
"""创建垃圾桶"""
|
|
||||||
trash = PRCXI9300Trash(name="trash", size_x=50, size_y=50, size_z=10, category="trash")
|
|
||||||
trash.load_state({
|
|
||||||
"Material": {
|
|
||||||
"uuid": prcxi_materials["废弃槽"]["uuid"]
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return trash
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def default_layout_9300() -> DefaultLayout:
|
|
||||||
"""创建 PRCXI 9300 默认布局"""
|
|
||||||
return DefaultLayout("PRCXI9300")
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def default_layout_9320() -> DefaultLayout:
|
|
||||||
"""创建 PRCXI 9320 默认布局"""
|
|
||||||
return DefaultLayout("PRCXI9320")
|
|
||||||
|
|
||||||
|
|
||||||
class TestPRCXIDeckSetup:
|
|
||||||
"""测试 PRCXI 工作台设置功能"""
|
|
||||||
|
|
||||||
def test_prcxi_9300_deck_creation(self, prcxi_9300_deck):
|
|
||||||
"""测试 PRCXI 9300 工作台创建"""
|
|
||||||
assert prcxi_9300_deck.name == "PRCXI_Deck_9300"
|
|
||||||
assert len(prcxi_9300_deck.sites) == 6
|
|
||||||
assert prcxi_9300_deck._size_x == 100
|
|
||||||
assert prcxi_9300_deck._size_y == 100
|
|
||||||
assert prcxi_9300_deck._size_z == 100
|
|
||||||
|
|
||||||
def test_prcxi_9320_deck_creation(self, prcxi_9320_deck):
|
|
||||||
"""测试 PRCXI 9320 工作台创建"""
|
|
||||||
assert prcxi_9320_deck.name == "PRCXI_Deck_9320"
|
|
||||||
assert len(prcxi_9320_deck.sites) == 16
|
|
||||||
assert prcxi_9320_deck._size_x == 100
|
|
||||||
assert prcxi_9320_deck._size_y == 100
|
|
||||||
assert prcxi_9320_deck._size_z == 100
|
|
||||||
|
|
||||||
def test_container_assignment(self, prcxi_9300_deck, tip_rack_300ul, well_plate_96, trash_container):
|
|
||||||
"""测试容器分配到工作台"""
|
|
||||||
# 分配枪头盒
|
|
||||||
prcxi_9300_deck.assign_child_resource(tip_rack_300ul, location=Coordinate(0, 0, 0))
|
|
||||||
assert tip_rack_300ul in prcxi_9300_deck.children
|
|
||||||
|
|
||||||
# 分配孔板
|
|
||||||
prcxi_9300_deck.assign_child_resource(well_plate_96, location=Coordinate(0, 0, 0))
|
|
||||||
assert well_plate_96 in prcxi_9300_deck.children
|
|
||||||
|
|
||||||
# 分配垃圾桶
|
|
||||||
prcxi_9300_deck.assign_child_resource(trash_container, location=Coordinate(0, 0, 0))
|
|
||||||
assert trash_container in prcxi_9300_deck.children
|
|
||||||
|
|
||||||
def test_container_material_loading(self, tip_rack_300ul, well_plate_96, prcxi_materials):
|
|
||||||
"""测试容器物料信息加载"""
|
|
||||||
# 测试枪头盒物料信息
|
|
||||||
tip_material = tip_rack_300ul._unilabos_state["Material"]
|
|
||||||
assert tip_material["uuid"] == prcxi_materials["300μL Tip头"]["uuid"]
|
|
||||||
assert tip_material["Name"] == "300μL Tip头"
|
|
||||||
|
|
||||||
# 测试孔板物料信息
|
|
||||||
plate_material = well_plate_96._unilabos_state["Material"]
|
|
||||||
assert plate_material["uuid"] == prcxi_materials["96深孔板"]["uuid"]
|
|
||||||
assert plate_material["Name"] == "96深孔板"
|
|
||||||
|
|
||||||
|
|
||||||
class TestPRCXISingleStepOperations:
|
|
||||||
"""测试 PRCXI 单步操作功能"""
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_pick_up_tips_single_channel(self, prcxi_9320_handler, prcxi_9320_deck, tip_rack_10ul):
|
|
||||||
"""测试单通道拾取枪头"""
|
|
||||||
# 将枪头盒添加到工作台
|
|
||||||
prcxi_9320_deck.assign_child_resource(tip_rack_10ul, location=Coordinate(0, 0, 0))
|
|
||||||
|
|
||||||
# 初始化处理器
|
|
||||||
await prcxi_9320_handler.setup()
|
|
||||||
|
|
||||||
# 设置枪头盒
|
|
||||||
prcxi_9320_handler.set_tiprack([tip_rack_10ul])
|
|
||||||
|
|
||||||
# 创建模拟的枪头位置
|
|
||||||
from pylabrobot.resources import TipSpot, Tip
|
|
||||||
tip = Tip(has_filter=False, total_tip_length=10, maximal_volume=10, fitting_depth=5)
|
|
||||||
tip_spot = TipSpot("A1", size_x=1, size_y=1, size_z=1, make_tip=lambda: tip)
|
|
||||||
tip_rack_10ul.assign_child_resource(tip_spot, location=Coordinate(0, 0, 0))
|
|
||||||
|
|
||||||
# 直接测试后端方法
|
|
||||||
from pylabrobot.liquid_handling import Pickup
|
|
||||||
pickup = Pickup(resource=tip_spot, offset=None, tip=tip)
|
|
||||||
await prcxi_9320_handler._unilabos_backend.pick_up_tips([pickup], [0])
|
|
||||||
|
|
||||||
# 验证步骤已添加到待办列表
|
|
||||||
assert len(prcxi_9320_handler._unilabos_backend.steps_todo_list) == 1
|
|
||||||
step = prcxi_9320_handler._unilabos_backend.steps_todo_list[0]
|
|
||||||
assert step["Function"] == "Load"
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_pick_up_tips_multi_channel(self, prcxi_9300_handler, tip_rack_300ul):
|
|
||||||
"""测试多通道拾取枪头"""
|
|
||||||
# 设置枪头盒
|
|
||||||
prcxi_9300_handler.set_tiprack([tip_rack_300ul])
|
|
||||||
|
|
||||||
# 拾取8个枪头
|
|
||||||
tip_spots = tip_rack_300ul.children[:8]
|
|
||||||
await prcxi_9300_handler.pick_up_tips(tip_spots, [0, 1, 2, 3, 4, 5, 6, 7])
|
|
||||||
|
|
||||||
# 验证步骤已添加到待办列表
|
|
||||||
assert len(prcxi_9300_handler._unilabos_backend.steps_todo_list) == 1
|
|
||||||
step = prcxi_9300_handler._unilabos_backend.steps_todo_list[0]
|
|
||||||
assert step["Function"] == "Load"
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_aspirate_single_channel(self, prcxi_9320_handler, well_plate_96):
|
|
||||||
"""测试单通道吸取液体"""
|
|
||||||
# 设置液体
|
|
||||||
well = well_plate_96.get_item("A1")
|
|
||||||
prcxi_9320_handler.set_liquid([well], ["water"], [50])
|
|
||||||
|
|
||||||
# 吸取液体
|
|
||||||
await prcxi_9320_handler.aspirate([well], [50], [0])
|
|
||||||
|
|
||||||
# 验证步骤已添加到待办列表
|
|
||||||
assert len(prcxi_9320_handler._unilabos_backend.steps_todo_list) == 1
|
|
||||||
step = prcxi_9320_handler._unilabos_backend.steps_todo_list[0]
|
|
||||||
assert step["Function"] == "Imbibing"
|
|
||||||
assert step["DosageNum"] == 50
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_dispense_single_channel(self, prcxi_9320_handler, well_plate_96):
|
|
||||||
"""测试单通道分配液体"""
|
|
||||||
# 分配液体
|
|
||||||
well = well_plate_96.get_item("A1")
|
|
||||||
await prcxi_9320_handler.dispense([well], [25], [0])
|
|
||||||
|
|
||||||
# 验证步骤已添加到待办列表
|
|
||||||
assert len(prcxi_9320_handler._unilabos_backend.steps_todo_list) == 1
|
|
||||||
step = prcxi_9320_handler._unilabos_backend.steps_todo_list[0]
|
|
||||||
assert step["Function"] == "Tapping"
|
|
||||||
assert step["DosageNum"] == 25
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_mix_single_channel(self, prcxi_9320_handler, well_plate_96):
|
|
||||||
"""测试单通道混合液体"""
|
|
||||||
# 混合液体
|
|
||||||
well = well_plate_96.get_item("A1")
|
|
||||||
await prcxi_9320_handler.mix([well], mix_time=3, mix_vol=50)
|
|
||||||
|
|
||||||
# 验证步骤已添加到待办列表
|
|
||||||
assert len(prcxi_9320_handler._unilabos_backend.steps_todo_list) == 1
|
|
||||||
step = prcxi_9320_handler._unilabos_backend.steps_todo_list[0]
|
|
||||||
assert step["Function"] == "Blending"
|
|
||||||
assert step["BlendingTimes"] == 3
|
|
||||||
assert step["DosageNum"] == 50
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_drop_tips_to_trash(self, prcxi_9320_handler, trash_container):
|
|
||||||
"""测试丢弃枪头到垃圾桶"""
|
|
||||||
# 丢弃枪头
|
|
||||||
await prcxi_9320_handler.drop_tips([trash_container], [0])
|
|
||||||
|
|
||||||
# 验证步骤已添加到待办列表
|
|
||||||
assert len(prcxi_9320_handler._unilabos_backend.steps_todo_list) == 1
|
|
||||||
step = prcxi_9320_handler._unilabos_backend.steps_todo_list[0]
|
|
||||||
assert step["Function"] == "UnLoad"
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_discard_tips(self, prcxi_9320_handler):
|
|
||||||
"""测试丢弃枪头"""
|
|
||||||
# 丢弃枪头
|
|
||||||
await prcxi_9320_handler.discard_tips([0])
|
|
||||||
|
|
||||||
# 验证步骤已添加到待办列表
|
|
||||||
assert len(prcxi_9320_handler._unilabos_backend.steps_todo_list) == 1
|
|
||||||
step = prcxi_9320_handler._unilabos_backend.steps_todo_list[0]
|
|
||||||
assert step["Function"] == "UnLoad"
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_liquid_transfer_workflow(self, prcxi_9320_handler, tip_rack_10ul, well_plate_96):
|
|
||||||
"""测试完整的液体转移工作流程"""
|
|
||||||
# 设置枪头盒和液体
|
|
||||||
prcxi_9320_handler.set_tiprack([tip_rack_10ul])
|
|
||||||
source_well = well_plate_96.get_item("A1")
|
|
||||||
target_well = well_plate_96.get_item("B1")
|
|
||||||
prcxi_9320_handler.set_liquid([source_well], ["water"], [100])
|
|
||||||
|
|
||||||
# 创建协议
|
|
||||||
await prcxi_9320_handler.create_protocol(protocol_name="Test Transfer Protocol")
|
|
||||||
|
|
||||||
# 执行转移流程
|
|
||||||
tip_spot = tip_rack_10ul.get_item("A1")
|
|
||||||
await prcxi_9320_handler.pick_up_tips([tip_spot], [0])
|
|
||||||
await prcxi_9320_handler.aspirate([source_well], [50], [0])
|
|
||||||
await prcxi_9320_handler.dispense([target_well], [50], [0])
|
|
||||||
await prcxi_9320_handler.discard_tips([0])
|
|
||||||
|
|
||||||
# 验证所有步骤都已添加
|
|
||||||
assert len(prcxi_9320_handler._unilabos_backend.steps_todo_list) == 4
|
|
||||||
functions = [step["Function"] for step in prcxi_9320_handler._unilabos_backend.steps_todo_list]
|
|
||||||
assert functions == ["Load", "Imbibing", "Tapping", "UnLoad"]
|
|
||||||
|
|
||||||
|
|
||||||
class TestPRCXILayoutRecommendation:
|
|
||||||
"""测试 PRCXI 板位推荐功能"""
|
|
||||||
|
|
||||||
def test_9300_layout_creation(self, default_layout_9300):
|
|
||||||
"""测试 PRCXI 9300 布局创建"""
|
|
||||||
layout_info = default_layout_9300.get_layout()
|
|
||||||
assert layout_info["rows"] == 2
|
|
||||||
assert layout_info["columns"] == 3
|
|
||||||
assert len(layout_info["layout"]) == 6
|
|
||||||
assert layout_info["trash_slot"] == 6
|
|
||||||
assert "waste_liquid_slot" not in layout_info
|
|
||||||
|
|
||||||
def test_9320_layout_creation(self, default_layout_9320):
|
|
||||||
"""测试 PRCXI 9320 布局创建"""
|
|
||||||
layout_info = default_layout_9320.get_layout()
|
|
||||||
assert layout_info["rows"] == 4
|
|
||||||
assert layout_info["columns"] == 4
|
|
||||||
assert len(layout_info["layout"]) == 16
|
|
||||||
assert layout_info["trash_slot"] == 16
|
|
||||||
assert layout_info["waste_liquid_slot"] == 12
|
|
||||||
|
|
||||||
def test_layout_recommendation_9320(self, default_layout_9320, prcxi_materials):
|
|
||||||
"""测试 PRCXI 9320 板位推荐功能"""
|
|
||||||
# 添加物料信息
|
|
||||||
default_layout_9320.add_lab_resource(prcxi_materials)
|
|
||||||
|
|
||||||
# 推荐布局
|
|
||||||
needs = [
|
|
||||||
("reagent_1", "96 细胞培养皿", 3),
|
|
||||||
("reagent_2", "12道储液槽", 1),
|
|
||||||
("reagent_3", "200μL Tip头", 7),
|
|
||||||
("reagent_4", "10μL加长 Tip头", 1),
|
|
||||||
]
|
|
||||||
|
|
||||||
matrix_layout, layout_list = default_layout_9320.recommend_layout(needs)
|
|
||||||
|
|
||||||
# 验证返回结果
|
|
||||||
assert "MatrixId" in matrix_layout
|
|
||||||
assert "MatrixName" in matrix_layout
|
|
||||||
assert "MatrixCount" in matrix_layout
|
|
||||||
assert "WorkTablets" in matrix_layout
|
|
||||||
assert len(layout_list) == 12 # 3+1+7+1 = 12个位置
|
|
||||||
|
|
||||||
# 验证推荐的位置不包含预留位置
|
|
||||||
reserved_positions = {12, 16}
|
|
||||||
recommended_positions = [item["positions"] for item in layout_list]
|
|
||||||
for pos in recommended_positions:
|
|
||||||
assert pos not in reserved_positions
|
|
||||||
|
|
||||||
def test_layout_recommendation_insufficient_space(self, default_layout_9320, prcxi_materials):
|
|
||||||
"""测试板位推荐空间不足的情况"""
|
|
||||||
# 添加物料信息
|
|
||||||
default_layout_9320.add_lab_resource(prcxi_materials)
|
|
||||||
|
|
||||||
# 尝试推荐超过可用空间的布局
|
|
||||||
needs = [
|
|
||||||
("reagent_1", "96 细胞培养皿", 15), # 需要15个位置,但只有14个可用
|
|
||||||
]
|
|
||||||
|
|
||||||
with pytest.raises(ValueError, match="需要 .* 个位置,但只有 .* 个可用位置"):
|
|
||||||
default_layout_9320.recommend_layout(needs)
|
|
||||||
|
|
||||||
def test_layout_recommendation_material_not_found(self, default_layout_9320, prcxi_materials):
|
|
||||||
"""测试板位推荐物料不存在的情况"""
|
|
||||||
# 添加物料信息
|
|
||||||
default_layout_9320.add_lab_resource(prcxi_materials)
|
|
||||||
|
|
||||||
# 尝试推荐不存在的物料
|
|
||||||
needs = [
|
|
||||||
("reagent_1", "不存在的物料", 1),
|
|
||||||
]
|
|
||||||
|
|
||||||
with pytest.raises(ValueError, match="Material .* not found in lab resources"):
|
|
||||||
default_layout_9320.recommend_layout(needs)
|
|
||||||
|
|
||||||
|
|
||||||
class TestPRCXIBackendOperations:
|
|
||||||
"""测试 PRCXI 后端操作功能"""
|
|
||||||
|
|
||||||
def test_backend_initialization(self, prcxi_9300_handler):
|
|
||||||
"""测试后端初始化"""
|
|
||||||
backend = prcxi_9300_handler._unilabos_backend
|
|
||||||
assert isinstance(backend, PRCXI9300Backend)
|
|
||||||
assert backend._num_channels == 8
|
|
||||||
assert backend.debug is True
|
|
||||||
|
|
||||||
def test_protocol_creation(self, prcxi_9300_handler):
|
|
||||||
"""测试协议创建"""
|
|
||||||
backend = prcxi_9300_handler._unilabos_backend
|
|
||||||
backend.create_protocol("Test Protocol")
|
|
||||||
assert backend.protocol_name == "Test Protocol"
|
|
||||||
assert len(backend.steps_todo_list) == 0
|
|
||||||
|
|
||||||
def test_channel_validation(self):
|
|
||||||
"""测试通道验证"""
|
|
||||||
# 测试正确的8通道配置
|
|
||||||
valid_channels = [0, 1, 2, 3, 4, 5, 6, 7]
|
|
||||||
result = PRCXI9300Backend.check_channels(valid_channels)
|
|
||||||
assert result == valid_channels
|
|
||||||
|
|
||||||
# 测试错误的通道配置
|
|
||||||
invalid_channels = [0, 1, 2, 3]
|
|
||||||
result = PRCXI9300Backend.check_channels(invalid_channels)
|
|
||||||
assert result == [0, 1, 2, 3, 4, 5, 6, 7]
|
|
||||||
|
|
||||||
def test_matrix_info_creation(self, prcxi_9300_handler):
|
|
||||||
"""测试矩阵信息创建"""
|
|
||||||
backend = prcxi_9300_handler._unilabos_backend
|
|
||||||
backend.create_protocol("Test Protocol")
|
|
||||||
|
|
||||||
# 模拟运行协议时的矩阵信息创建
|
|
||||||
run_time = 1234567890
|
|
||||||
matrix_info = MatrixInfo(
|
|
||||||
MatrixId=f"{int(run_time)}",
|
|
||||||
MatrixName=f"protocol_{run_time}",
|
|
||||||
MatrixCount=len(backend.tablets_info),
|
|
||||||
WorkTablets=backend.tablets_info,
|
|
||||||
)
|
|
||||||
|
|
||||||
assert matrix_info["MatrixId"] == str(int(run_time))
|
|
||||||
assert matrix_info["MatrixName"] == f"protocol_{run_time}"
|
|
||||||
assert "WorkTablets" in matrix_info
|
|
||||||
|
|
||||||
|
|
||||||
class TestPRCXIContainerOperations:
|
|
||||||
"""测试 PRCXI 容器操作功能"""
|
|
||||||
|
|
||||||
def test_container_serialization(self, tip_rack_300ul):
|
|
||||||
"""测试容器序列化"""
|
|
||||||
serialized = tip_rack_300ul.serialize_state()
|
|
||||||
assert "Material" in serialized
|
|
||||||
assert serialized["Material"]["Name"] == "300μL Tip头"
|
|
||||||
|
|
||||||
def test_container_deserialization(self, tip_rack_300ul):
|
|
||||||
"""测试容器反序列化"""
|
|
||||||
# 序列化
|
|
||||||
serialized = tip_rack_300ul.serialize_state()
|
|
||||||
|
|
||||||
# 创建新容器并反序列化
|
|
||||||
new_tip_rack = PRCXI9300Container(
|
|
||||||
name="new_tip_rack",
|
|
||||||
size_x=50,
|
|
||||||
size_y=50,
|
|
||||||
size_z=10,
|
|
||||||
category="tip_rack",
|
|
||||||
ordering=collections.OrderedDict()
|
|
||||||
)
|
|
||||||
new_tip_rack.load_state(serialized)
|
|
||||||
|
|
||||||
assert new_tip_rack._unilabos_state["Material"]["Name"] == "300μL Tip头"
|
|
||||||
|
|
||||||
def test_trash_container_creation(self, prcxi_materials):
|
|
||||||
"""测试垃圾桶容器创建"""
|
|
||||||
trash = PRCXI9300Trash(name="trash", size_x=50, size_y=50, size_z=10, category="trash")
|
|
||||||
trash.load_state({
|
|
||||||
"Material": {
|
|
||||||
"uuid": prcxi_materials["废弃槽"]["uuid"]
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
assert trash.name == "trash"
|
|
||||||
assert trash._unilabos_state["Material"]["uuid"] == prcxi_materials["废弃槽"]["uuid"]
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
# 运行测试
|
|
||||||
pytest.main([__file__, "-v"])
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
# Liquid handling 集成测试
|
|
||||||
|
|
||||||
`test_transfer_liquid.py` 现在会调用 PRCXI 的 RViz 仿真 backend,运行前请确保:
|
|
||||||
|
|
||||||
1. 已安装包含 `pylabrobot`、`rclpy` 的运行环境;
|
|
||||||
2. 启动 ROS 依赖(`rviz` 可选,但是 `rviz_backend` 会创建 ROS 节点);
|
|
||||||
3. 在 shell 中设置 `UNILAB_SIM_TEST=1`,否则 pytest 会自动跳过这些慢速用例:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
export UNILAB_SIM_TEST=1
|
|
||||||
pytest tests/devices/liquid_handling/test_transfer_liquid.py -m slow
|
|
||||||
```
|
|
||||||
|
|
||||||
如果只需验证逻辑层(不依赖仿真),可以直接运行 `tests/devices/liquid_handling/unit_test.py`,该文件使用 Fake backend,适合作为 CI 的快速测试。***
|
|
||||||
|
|
||||||
@@ -1,244 +0,0 @@
|
|||||||
"""P9 — ``liquid_history`` schema v3 + helper 单元测试。
|
|
||||||
|
|
||||||
测试覆盖:
|
|
||||||
- :func:`append_liquid_history`:写 v3 entry / tracker 缺失 graceful / 滚动上限
|
|
||||||
- :func:`normalize_liquid_history`:v3 dict / v2 tuple / list[str] / 混合 / 非法
|
|
||||||
- :func:`well_current_liquid_name`:tracker.liquids 末项 / get_liquids fallback / 缺失
|
|
||||||
|
|
||||||
注:``LiquidHandlerAbstract.set_liquid`` 写 history 的集成("set" action)覆盖
|
|
||||||
逻辑相同(直接调用 :func:`append_liquid_history`),由本测试间接验证;端到端走 PLR
|
|
||||||
真实 ``Well.set_liquids`` 的集成测试在 ``tests/devices/liquid_handling/unit_test.py``
|
|
||||||
范围内随 PLR 环境就绪后增补,本 P9 提交保持解耦。
|
|
||||||
|
|
||||||
详见 ``product_designs/protocol_convert/09-liquid-history-unknown-debug.md`` §8。
|
|
||||||
"""
|
|
||||||
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
from dataclasses import dataclass, field
|
|
||||||
from typing import Any, List, Tuple
|
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
# liquid_history 模块**不依赖** pylabrobot,可在 PLR 环境缺失时独立 import / 单测。
|
|
||||||
from unilabos.devices.liquid_handling.liquid_history import (
|
|
||||||
LIQUID_HISTORY_MAX_ENTRIES,
|
|
||||||
LiquidHistoryEntry,
|
|
||||||
append_liquid_history,
|
|
||||||
normalize_liquid_history,
|
|
||||||
well_current_liquid_name,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
# Fixtures:DummyTracker / DummyWell(避免引入真实 PLR Well/VolumeTracker 依赖)
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class DummyTracker:
|
|
||||||
"""模拟 PLR VolumeTracker:仅暴露 P9 hook 关心的字段。"""
|
|
||||||
|
|
||||||
liquid_history: List[Any] = field(default_factory=list)
|
|
||||||
liquids: List[Tuple[Any, float]] = field(default_factory=list)
|
|
||||||
max_volume: float = 200.0
|
|
||||||
is_disabled: bool = False
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class DummyWell:
|
|
||||||
"""模拟 PLR Well:仅暴露 ``tracker``。"""
|
|
||||||
|
|
||||||
name: str = "well_A1"
|
|
||||||
max_volume: float = 200.0
|
|
||||||
tracker: DummyTracker = field(default_factory=DummyTracker)
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
# append_liquid_history
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
class TestAppendLiquidHistory:
|
|
||||||
def test_append_creates_v3_entry(self) -> None:
|
|
||||||
well = DummyWell()
|
|
||||||
append_liquid_history(well, "Plasma", 100.0, "set")
|
|
||||||
|
|
||||||
assert len(well.tracker.liquid_history) == 1
|
|
||||||
entry = well.tracker.liquid_history[0]
|
|
||||||
assert entry["name"] == "Plasma"
|
|
||||||
assert entry["volume"] == 100.0
|
|
||||||
assert entry["action"] == "set"
|
|
||||||
assert "timestamp" in entry and isinstance(entry["timestamp"], str)
|
|
||||||
|
|
||||||
def test_append_aspirate_negative_volume(self) -> None:
|
|
||||||
well = DummyWell()
|
|
||||||
append_liquid_history(well, "Water", -50.0, "aspirate")
|
|
||||||
|
|
||||||
assert well.tracker.liquid_history[0]["volume"] == -50.0
|
|
||||||
assert well.tracker.liquid_history[0]["action"] == "aspirate"
|
|
||||||
|
|
||||||
def test_append_with_empty_name_keeps_empty_string(self) -> None:
|
|
||||||
"""name 为空时应写入 ``""`` 而非字面 "unknown"(避免视觉混淆 bottom_type)。"""
|
|
||||||
well = DummyWell()
|
|
||||||
append_liquid_history(well, "", 50.0, "dispense")
|
|
||||||
|
|
||||||
assert well.tracker.liquid_history[0]["name"] == ""
|
|
||||||
|
|
||||||
def test_append_with_none_name_normalized_to_empty_string(self) -> None:
|
|
||||||
well = DummyWell()
|
|
||||||
append_liquid_history(well, None, 50.0, "dispense") # type: ignore[arg-type]
|
|
||||||
|
|
||||||
assert well.tracker.liquid_history[0]["name"] == ""
|
|
||||||
|
|
||||||
def test_append_initializes_history_if_missing(self) -> None:
|
|
||||||
"""tracker 没有 liquid_history 属性时 helper 自动创建空 list 并写入。"""
|
|
||||||
well = DummyWell()
|
|
||||||
del well.tracker.liquid_history # 模拟全新 PLR tracker
|
|
||||||
append_liquid_history(well, "X", 10.0, "set")
|
|
||||||
|
|
||||||
assert hasattr(well.tracker, "liquid_history")
|
|
||||||
assert len(well.tracker.liquid_history) == 1
|
|
||||||
|
|
||||||
def test_append_no_tracker_is_graceful(self) -> None:
|
|
||||||
"""well 无 tracker 时静默不抛(保护主流程)。"""
|
|
||||||
|
|
||||||
class NoTrackerWell:
|
|
||||||
name = "no_tracker"
|
|
||||||
|
|
||||||
well = NoTrackerWell()
|
|
||||||
append_liquid_history(well, "X", 10.0, "set") # 不应抛
|
|
||||||
assert not hasattr(well, "tracker")
|
|
||||||
|
|
||||||
def test_append_action_defaults_to_legacy_when_empty(self) -> None:
|
|
||||||
well = DummyWell()
|
|
||||||
append_liquid_history(well, "X", 1.0, "")
|
|
||||||
|
|
||||||
assert well.tracker.liquid_history[0]["action"] == "legacy"
|
|
||||||
|
|
||||||
def test_append_respects_max_entries_rolling(self) -> None:
|
|
||||||
"""超过 ``LIQUID_HISTORY_MAX_ENTRIES`` 时丢弃头部,保留最近 entries。"""
|
|
||||||
well = DummyWell()
|
|
||||||
well.tracker.liquid_history = [
|
|
||||||
{"name": f"old_{i}"} for i in range(LIQUID_HISTORY_MAX_ENTRIES + 5)
|
|
||||||
]
|
|
||||||
append_liquid_history(well, "newest", 1.0, "set")
|
|
||||||
|
|
||||||
assert len(well.tracker.liquid_history) == LIQUID_HISTORY_MAX_ENTRIES
|
|
||||||
assert well.tracker.liquid_history[-1]["name"] == "newest"
|
|
||||||
assert well.tracker.liquid_history[0]["name"] != "old_0"
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
# normalize_liquid_history
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
class TestNormalizeLiquidHistory:
|
|
||||||
def test_v3_dict_passthrough_with_field_defaults(self) -> None:
|
|
||||||
raw = [{"name": "A", "volume": 100, "action": "set", "timestamp": "2026-05-22T00:00:00Z"}]
|
|
||||||
result = normalize_liquid_history(raw)
|
|
||||||
|
|
||||||
assert result == [{
|
|
||||||
"name": "A",
|
|
||||||
"volume": 100.0,
|
|
||||||
"action": "set",
|
|
||||||
"timestamp": "2026-05-22T00:00:00Z",
|
|
||||||
}]
|
|
||||||
|
|
||||||
def test_v3_dict_missing_optional_fields_filled_with_defaults(self) -> None:
|
|
||||||
raw = [{"name": "A"}]
|
|
||||||
result = normalize_liquid_history(raw)
|
|
||||||
|
|
||||||
assert result == [{"name": "A", "volume": 0.0, "action": "legacy"}]
|
|
||||||
assert "timestamp" not in result[0]
|
|
||||||
|
|
||||||
def test_v2_tuple_upgraded_to_v3_legacy(self) -> None:
|
|
||||||
raw = [("A", 100), ("B", 50.5)]
|
|
||||||
result = normalize_liquid_history(raw)
|
|
||||||
|
|
||||||
assert result == [
|
|
||||||
{"name": "A", "volume": 100.0, "action": "legacy"},
|
|
||||||
{"name": "B", "volume": 50.5, "action": "legacy"},
|
|
||||||
]
|
|
||||||
|
|
||||||
def test_list_of_strings_upgraded(self) -> None:
|
|
||||||
raw = ["A", "B"]
|
|
||||||
result = normalize_liquid_history(raw)
|
|
||||||
|
|
||||||
assert result == [
|
|
||||||
{"name": "A", "volume": 0.0, "action": "legacy"},
|
|
||||||
{"name": "B", "volume": 0.0, "action": "legacy"},
|
|
||||||
]
|
|
||||||
|
|
||||||
def test_mixed_input_normalized(self) -> None:
|
|
||||||
raw = [
|
|
||||||
{"name": "A", "volume": 1, "action": "set"},
|
|
||||||
("B", 2),
|
|
||||||
"C",
|
|
||||||
]
|
|
||||||
result = normalize_liquid_history(raw)
|
|
||||||
|
|
||||||
assert [e["name"] for e in result] == ["A", "B", "C"]
|
|
||||||
assert [e["action"] for e in result] == ["set", "legacy", "legacy"]
|
|
||||||
|
|
||||||
def test_invalid_entries_dropped(self) -> None:
|
|
||||||
raw = [42, None, {"name": "A"}, ("only_one",)]
|
|
||||||
result = normalize_liquid_history(raw)
|
|
||||||
|
|
||||||
# 只保留 {"name": "A"} 这一条;其它都被丢弃
|
|
||||||
assert len(result) == 1
|
|
||||||
assert result[0]["name"] == "A"
|
|
||||||
assert result[0]["volume"] == 0.0 # 缺省补 0
|
|
||||||
|
|
||||||
def test_non_list_input_returns_empty(self) -> None:
|
|
||||||
assert normalize_liquid_history(None) == []
|
|
||||||
assert normalize_liquid_history("not_a_list") == []
|
|
||||||
assert normalize_liquid_history({"name": "X"}) == []
|
|
||||||
|
|
||||||
def test_tuple_with_unconvertible_volume_falls_back_to_zero(self) -> None:
|
|
||||||
raw = [("A", "not_a_number")]
|
|
||||||
result = normalize_liquid_history(raw)
|
|
||||||
|
|
||||||
assert result[0]["volume"] == 0.0
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
# well_current_liquid_name
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
class TestWellCurrentLiquidName:
|
|
||||||
def test_returns_last_liquid_name_from_tuple(self) -> None:
|
|
||||||
well = DummyWell()
|
|
||||||
well.tracker.liquids = [("Water", 50.0), ("Plasma", 100.0)]
|
|
||||||
assert well_current_liquid_name(well) == "Plasma"
|
|
||||||
|
|
||||||
def test_returns_enum_like_name_attr(self) -> None:
|
|
||||||
class FakeLiquid:
|
|
||||||
name = "ETHANOL"
|
|
||||||
|
|
||||||
well = DummyWell()
|
|
||||||
well.tracker.liquids = [(FakeLiquid(), 100.0)]
|
|
||||||
assert well_current_liquid_name(well) == "ETHANOL"
|
|
||||||
|
|
||||||
def test_empty_liquids_returns_empty_string(self) -> None:
|
|
||||||
well = DummyWell()
|
|
||||||
well.tracker.liquids = []
|
|
||||||
assert well_current_liquid_name(well) == ""
|
|
||||||
|
|
||||||
def test_no_tracker_returns_empty_string(self) -> None:
|
|
||||||
class NoTrackerWell:
|
|
||||||
name = "x"
|
|
||||||
|
|
||||||
assert well_current_liquid_name(NoTrackerWell()) == ""
|
|
||||||
|
|
||||||
def test_none_liquid_returns_empty_string(self) -> None:
|
|
||||||
well = DummyWell()
|
|
||||||
well.tracker.liquids = [(None, 100.0)]
|
|
||||||
assert well_current_liquid_name(well) == ""
|
|
||||||
|
|
||||||
def test_string_liquid_returned_as_is(self) -> None:
|
|
||||||
well = DummyWell()
|
|
||||||
well.tracker.liquids = ["Saline"]
|
|
||||||
assert well_current_liquid_name(well) == "Saline"
|
|
||||||
@@ -1,239 +0,0 @@
|
|||||||
"""P2 v2 跨板能力验证 —— device 层 ``set_liquid_from_plate`` 单测。
|
|
||||||
|
|
||||||
对应 ``product_designs/protocol_convert/02-cross-slot-merge.md`` §9.1 / §9.5 step 6.3。
|
|
||||||
|
|
||||||
本测试聚焦于 **`_set_liquid_grouped_by_plate`** 已天然支持跨板 wells 的能力(v2 设计
|
|
||||||
的核心依据):
|
|
||||||
|
|
||||||
- 输入 ``wells`` 列表来自多个 plate(每板各一/多个 well)时,``set_liquid`` 应按 plate
|
|
||||||
分桶串行调用,每板一次(plate-bucket 顺序按 first-occurrence)。
|
|
||||||
- 同板内多孔归到同一桶。
|
|
||||||
- 返回 ``volumes`` 按 **输入 index 顺序**回拼,与 wells 一致 —— 这是 v2 Stage 3
|
|
||||||
merged ``set_liquid_from_plate.output_wells`` 的顺序权威来源。
|
|
||||||
- ``Well.set_liquids`` 在 ``set_liquid`` 链内被逐孔调用,与 PLR 实现的预期接口一致。
|
|
||||||
|
|
||||||
为了避免引入完整 PLR 资源树,测试用 duck-typed ``DummyWell`` / ``DummyPlate`` +
|
|
||||||
``ResourceTreeSet`` 的 monkeypatch(dump 直接返回输入列表)。
|
|
||||||
"""
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
from dataclasses import dataclass, field
|
|
||||||
from typing import List, Tuple
|
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
|
|
||||||
# ----------------------------------------------------------------------
|
|
||||||
# 跨环境兼容:与现有 ``tests/devices/liquid_handling/test_transfer_liquid.py`` 一致,
|
|
||||||
# 本测试通过 import ``unilabos.devices.liquid_handling.liquid_handler_abstract``
|
|
||||||
# 拉起 pylabrobot 链;某些本地开发机的 pylabrobot 版本与代码库要求不一致,
|
|
||||||
# 会在 import 阶段抛 ``ImportError``。这里用 ``importorskip`` 优雅跳过,让
|
|
||||||
# CI(统一 pylabrobot 版本)跑全;纯逻辑测试(Stage 2 / Stage 3)不受影响。
|
|
||||||
# ----------------------------------------------------------------------
|
|
||||||
LiquidHandlerAbstract = pytest.importorskip(
|
|
||||||
"unilabos.devices.liquid_handling.liquid_handler_abstract",
|
|
||||||
reason="pylabrobot 链未完整可用,跳过 device 单测;CI 上请保证 pylabrobot ≥ 项目要求版本",
|
|
||||||
exc_type=ImportError,
|
|
||||||
).LiquidHandlerAbstract
|
|
||||||
|
|
||||||
|
|
||||||
# ==================== Duck-typed PLR-like 资源 ====================
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class DummyPlate:
|
|
||||||
name: str
|
|
||||||
|
|
||||||
def __repr__(self) -> str: # pragma: no cover
|
|
||||||
return f"DummyPlate({self.name})"
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class DummyWell:
|
|
||||||
name: str
|
|
||||||
parent: DummyPlate
|
|
||||||
max_volume: float = 1000.0
|
|
||||||
liquid_history: List[Tuple[str, float]] = field(default_factory=list)
|
|
||||||
|
|
||||||
def set_liquids(self, items):
|
|
||||||
"""模拟 PLR ``Well.set_liquids([(name, vol), ...])`` 接口。"""
|
|
||||||
for name, vol in items:
|
|
||||||
self.liquid_history.append((str(name), float(vol)))
|
|
||||||
|
|
||||||
def __repr__(self) -> str: # pragma: no cover
|
|
||||||
return f"DummyWell({self.parent.name}/{self.name})"
|
|
||||||
|
|
||||||
|
|
||||||
# ==================== fixture:装一台 FakeLiquidHandler ====================
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def patched_resource_tree(monkeypatch):
|
|
||||||
"""patch ``ResourceTreeSet.from_plr_resources`` 使其接受 duck-typed wells/plates。
|
|
||||||
|
|
||||||
返回的对象只要带 ``.dump()`` 即可(``_set_liquid_grouped_by_plate`` 仅消费该方法)。
|
|
||||||
"""
|
|
||||||
from unilabos.devices.liquid_handling import liquid_handler_abstract as lha
|
|
||||||
|
|
||||||
class _FakeTree:
|
|
||||||
def __init__(self, items):
|
|
||||||
self._items = items
|
|
||||||
|
|
||||||
def dump(self):
|
|
||||||
return [
|
|
||||||
{"name": getattr(x, "name", None), "type": type(x).__name__}
|
|
||||||
for x in self._items
|
|
||||||
]
|
|
||||||
|
|
||||||
def _fake_from_plr_resources(items, known_newly_created=False): # noqa: ARG001
|
|
||||||
return _FakeTree(list(items))
|
|
||||||
|
|
||||||
monkeypatch.setattr(
|
|
||||||
lha.ResourceTreeSet,
|
|
||||||
"from_plr_resources",
|
|
||||||
staticmethod(_fake_from_plr_resources),
|
|
||||||
)
|
|
||||||
return lha
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def handler(patched_resource_tree):
|
|
||||||
"""构造一台最小 LiquidHandlerAbstract 实例,绕过真实 backend / deck。"""
|
|
||||||
|
|
||||||
class _FakeHandler(LiquidHandlerAbstract):
|
|
||||||
def __init__(self):
|
|
||||||
# 不调用 super().__init__,避免真实硬件/后端依赖
|
|
||||||
self.channel_num = 8
|
|
||||||
self.support_touch_tip = True
|
|
||||||
|
|
||||||
return _FakeHandler()
|
|
||||||
|
|
||||||
|
|
||||||
def _wells_grid(plate_name: str, well_names: List[str]) -> List[DummyWell]:
|
|
||||||
plate = DummyPlate(name=plate_name)
|
|
||||||
return [DummyWell(name=w, parent=plate) for w in well_names]
|
|
||||||
|
|
||||||
|
|
||||||
# ==================== 用例 ====================
|
|
||||||
|
|
||||||
|
|
||||||
def test_grouped_by_plate_single_plate_set_liquid_inline(handler):
|
|
||||||
"""单 plate 多孔:set_liquids 按 wells 顺序逐项调用,volumes 回拼一致。"""
|
|
||||||
wells = _wells_grid("plate_slot2", ["A1", "A2", "A3"])
|
|
||||||
ret = handler._set_liquid_grouped_by_plate(
|
|
||||||
wells=wells,
|
|
||||||
liquid_names=["reagent_X"] * 3,
|
|
||||||
volumes=[10.0, 20.0, 30.0],
|
|
||||||
)
|
|
||||||
|
|
||||||
# 每个 well 的 liquid_history 各 1 条
|
|
||||||
for w, expected_vol in zip(wells, [10.0, 20.0, 30.0]):
|
|
||||||
assert w.liquid_history == [("reagent_X", expected_vol)]
|
|
||||||
|
|
||||||
# 返回 volumes 顺序与输入一致
|
|
||||||
assert ret.volumes == [10.0, 20.0, 30.0]
|
|
||||||
|
|
||||||
|
|
||||||
def test_grouped_by_plate_cross_plate_buckets_by_parent(handler):
|
|
||||||
"""跨板 wells 列表 → 按 first-occurrence plate 顺序分桶,每板单独 set_liquid。
|
|
||||||
|
|
||||||
51b9a5 简化(每板 1 孔):4 plate × 1 well = 4 set_liquids 调用。
|
|
||||||
"""
|
|
||||||
p2 = _wells_grid("plate_slot2", ["A1"])
|
|
||||||
p3 = _wells_grid("plate_slot3", ["A1"])
|
|
||||||
p5 = _wells_grid("plate_slot5", ["A1"])
|
|
||||||
p6 = _wells_grid("plate_slot6", ["A1"])
|
|
||||||
wells = p2 + p3 + p5 + p6
|
|
||||||
|
|
||||||
ret = handler._set_liquid_grouped_by_plate(
|
|
||||||
wells=wells,
|
|
||||||
liquid_names=["l1"] * 4,
|
|
||||||
volumes=[8.3] * 4,
|
|
||||||
)
|
|
||||||
|
|
||||||
# 每个 well 都被 set_liquids 设过
|
|
||||||
for w in wells:
|
|
||||||
assert w.liquid_history == [("l1", 8.3)], f"well {w.parent.name}/{w.name} 未正确设液"
|
|
||||||
|
|
||||||
# volumes 顺序与输入对齐
|
|
||||||
assert ret.volumes == [8.3, 8.3, 8.3, 8.3]
|
|
||||||
|
|
||||||
# plate dump 应含 4 个 plate(按 first-occurrence)
|
|
||||||
plate_dump = ret.plate
|
|
||||||
plate_names = [p["name"] for p in plate_dump]
|
|
||||||
assert plate_names == ["plate_slot2", "plate_slot3", "plate_slot5", "plate_slot6"]
|
|
||||||
|
|
||||||
|
|
||||||
def test_grouped_by_plate_interleaved_cross_plate_preserves_input_order(handler):
|
|
||||||
"""交错跨板:wells=[p2.A1, p3.A1, p2.A2, p5.A1] → volumes 顺序按输入回拼。
|
|
||||||
|
|
||||||
内部仍按 plate 分桶执行 set_liquid(per-plate 串行),但返回顺序遵循输入 index。
|
|
||||||
"""
|
|
||||||
p2 = DummyPlate(name="plate_slot2")
|
|
||||||
p3 = DummyPlate(name="plate_slot3")
|
|
||||||
p5 = DummyPlate(name="plate_slot5")
|
|
||||||
w_p2_a1 = DummyWell(name="A1", parent=p2)
|
|
||||||
w_p2_a2 = DummyWell(name="A2", parent=p2)
|
|
||||||
w_p3_a1 = DummyWell(name="A1", parent=p3)
|
|
||||||
w_p5_a1 = DummyWell(name="A1", parent=p5)
|
|
||||||
|
|
||||||
wells = [w_p2_a1, w_p3_a1, w_p2_a2, w_p5_a1]
|
|
||||||
ret = handler._set_liquid_grouped_by_plate(
|
|
||||||
wells=wells,
|
|
||||||
liquid_names=["l1"] * 4,
|
|
||||||
volumes=[10.0, 20.0, 30.0, 40.0],
|
|
||||||
)
|
|
||||||
|
|
||||||
# 每个 well 都被设液
|
|
||||||
assert w_p2_a1.liquid_history == [("l1", 10.0)]
|
|
||||||
assert w_p3_a1.liquid_history == [("l1", 20.0)]
|
|
||||||
assert w_p2_a2.liquid_history == [("l1", 30.0)]
|
|
||||||
assert w_p5_a1.liquid_history == [("l1", 40.0)]
|
|
||||||
|
|
||||||
# 返回 volumes 严格按输入 index 顺序回拼
|
|
||||||
assert ret.volumes == [10.0, 20.0, 30.0, 40.0]
|
|
||||||
|
|
||||||
# plate dump:按 first-occurrence(plate_slot2 第 1 次出现于 idx=0,plate_slot3 idx=1,plate_slot5 idx=3)
|
|
||||||
plate_names = [p["name"] for p in ret.plate]
|
|
||||||
assert plate_names == ["plate_slot2", "plate_slot3", "plate_slot5"]
|
|
||||||
|
|
||||||
|
|
||||||
def test_grouped_by_plate_volumes_clamped_to_max_volume(handler):
|
|
||||||
"""``set_liquid`` 会按 ``max_volume`` 做 clamp,防止初始化液量超容器容量。"""
|
|
||||||
plate = DummyPlate(name="plate_slot2")
|
|
||||||
well = DummyWell(name="A1", parent=plate, max_volume=200.0)
|
|
||||||
|
|
||||||
ret = handler._set_liquid_grouped_by_plate(
|
|
||||||
wells=[well],
|
|
||||||
liquid_names=["overflow"],
|
|
||||||
volumes=[500.0], # 超过 max_volume=200
|
|
||||||
)
|
|
||||||
|
|
||||||
assert well.liquid_history == [("overflow", 200.0)]
|
|
||||||
assert ret.volumes == [200.0]
|
|
||||||
|
|
||||||
|
|
||||||
def test_grouped_by_plate_empty_names_short_circuit(handler):
|
|
||||||
"""``liquid_names`` 与 ``volumes`` 均为空:早返回,wells 列表回显但不设液。"""
|
|
||||||
wells = _wells_grid("plate_slot2", ["A1", "A2"])
|
|
||||||
ret = handler._set_liquid_grouped_by_plate(
|
|
||||||
wells=wells,
|
|
||||||
liquid_names=[],
|
|
||||||
volumes=[],
|
|
||||||
)
|
|
||||||
# 不调用 set_liquids
|
|
||||||
assert all(w.liquid_history == [] for w in wells)
|
|
||||||
assert ret.volumes == []
|
|
||||||
# wells dump 仍返回输入列表
|
|
||||||
assert [w["name"] for w in ret.wells] == ["A1", "A2"]
|
|
||||||
|
|
||||||
|
|
||||||
def test_grouped_by_plate_length_mismatch_raises(handler):
|
|
||||||
"""wells / liquid_names / volumes 长度不一致应直接 raise(防御性校验)。"""
|
|
||||||
wells = _wells_grid("plate_slot2", ["A1", "A2"])
|
|
||||||
with pytest.raises(ValueError, match=r"必须等长"):
|
|
||||||
handler._set_liquid_grouped_by_plate(
|
|
||||||
wells=wells,
|
|
||||||
liquid_names=["r"] * 2,
|
|
||||||
volumes=[10.0], # 长度 1,不匹配
|
|
||||||
)
|
|
||||||
@@ -1,566 +0,0 @@
|
|||||||
"""P10 v2 — Tip 复用 ``tracker.liquids`` 等价规则单元测试。
|
|
||||||
|
|
||||||
测试覆盖(详见 ``product_designs/protocol_convert/10-tip-reuse-by-liquid-history.md`` §5):
|
|
||||||
|
|
||||||
- Helper:``is_known_liquid_name`` / ``same_liquid_via_liquids`` /
|
|
||||||
``same_liquid_via_liquids_pair`` / ``capture_tip_liquid_name``(4 helper
|
|
||||||
位于 ``liquid_history.py``,PLR-free 模块)。
|
|
||||||
- 单通道 transfer_liquid 主循环:identity-keep / liquids-keep / 配置开关 /
|
|
||||||
未知 name 保守换 tip / aspirate 顶层归零时序。
|
|
||||||
- 8 通道分支:段锚孔 liquids-keep。
|
|
||||||
- 跨节点边界:两个独立 transfer_liquid 调用状态隔离。
|
|
||||||
|
|
||||||
helper 测试独立于 PLR,可在 ``pylabrobot`` 缺失环境下单独运行;端到端
|
|
||||||
``transfer_liquid`` 主循环测试需要 PLR 环境(沿用 ``test_transfer_liquid.py`` 的
|
|
||||||
``FakeLiquidHandler`` 模式:跳过 ``super().__init__``,仅 stub 4 类方法记录调用)。
|
|
||||||
若 PLR import 失败则自动 skip 端到端测试,保留 helper 测试结果。
|
|
||||||
"""
|
|
||||||
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import asyncio
|
|
||||||
from dataclasses import dataclass, field
|
|
||||||
from typing import Any, Iterable, List, Optional, Sequence, Tuple
|
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
# P10 v2 helper 位于 PLR-free 模块,无论 pylabrobot 是否安装都能 import。
|
|
||||||
from unilabos.devices.liquid_handling.liquid_history import (
|
|
||||||
capture_tip_liquid_name,
|
|
||||||
is_known_liquid_name,
|
|
||||||
same_liquid_via_liquids,
|
|
||||||
same_liquid_via_liquids_pair,
|
|
||||||
)
|
|
||||||
|
|
||||||
# 端到端测试依赖 PLR 完整环境;若 import 失败(例如本地 PLR 版本不匹配),
|
|
||||||
# 整段端到端测试自动 skip,但 helper 测试照常执行。
|
|
||||||
try:
|
|
||||||
from unilabos.devices.liquid_handling.liquid_handler_abstract import (
|
|
||||||
LiquidHandlerAbstract,
|
|
||||||
)
|
|
||||||
|
|
||||||
_PLR_AVAILABLE = True
|
|
||||||
_PLR_IMPORT_ERROR: Optional[Exception] = None
|
|
||||||
except Exception as exc: # pragma: no cover - 环境相关
|
|
||||||
LiquidHandlerAbstract = None # type: ignore[assignment, misc]
|
|
||||||
_PLR_AVAILABLE = False
|
|
||||||
_PLR_IMPORT_ERROR = exc
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
# Fixtures:DummyTracker / DummyWell / DummyTipSpot / FakeLiquidHandler
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class DummyTracker:
|
|
||||||
"""模拟 PLR ``VolumeTracker``:仅暴露 P10 v2 关心的 ``liquids`` 字段。"""
|
|
||||||
|
|
||||||
liquids: List[Tuple[Any, float]] = field(default_factory=list)
|
|
||||||
max_volume: float = 200.0
|
|
||||||
is_disabled: bool = False
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class DummyWell:
|
|
||||||
"""模拟 PLR ``Well``:仅暴露 ``tracker``。"""
|
|
||||||
|
|
||||||
name: str = "well"
|
|
||||||
tracker: DummyTracker = field(default_factory=DummyTracker)
|
|
||||||
|
|
||||||
def __repr__(self) -> str: # pragma: no cover
|
|
||||||
return f"DummyWell({self.name})"
|
|
||||||
|
|
||||||
|
|
||||||
def make_well(name: str, liquid_name: Optional[str] = None, vol: float = 100.0) -> DummyWell:
|
|
||||||
"""构造一个 well;若指定 ``liquid_name`` 则写入 ``tracker.liquids`` 顶层。"""
|
|
||||||
well = DummyWell(name=name, tracker=DummyTracker())
|
|
||||||
if liquid_name is not None:
|
|
||||||
well.tracker.liquids = [(liquid_name, vol)]
|
|
||||||
return well
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
|
||||||
class DummyTipSpot:
|
|
||||||
name: str
|
|
||||||
|
|
||||||
|
|
||||||
def make_tip_iter(n: int = 256) -> Iterable[List[DummyTipSpot]]:
|
|
||||||
for i in range(n):
|
|
||||||
yield [DummyTipSpot(f"tip_{i}")]
|
|
||||||
|
|
||||||
|
|
||||||
# E2E 测试用的 base:PLR 可用时是 ``LiquidHandlerAbstract``,否则 fallback 到
|
|
||||||
# ``object`` 让模块仍能 import;带 ``LiquidHandlerAbstract`` 的 e2e 测试用
|
|
||||||
# ``skipif`` 跳过。
|
|
||||||
_FakeBase = LiquidHandlerAbstract if _PLR_AVAILABLE else object
|
|
||||||
|
|
||||||
|
|
||||||
class FakeLiquidHandler(_FakeBase): # type: ignore[misc, valid-type]
|
|
||||||
"""不初始化真实 backend/deck;仅记录 transfer_liquid 内部 4 类调用序列。
|
|
||||||
|
|
||||||
P10 v2 测试关心 ``pick_up_tips`` / ``discard_tips`` 的触发次数 + 顺序,
|
|
||||||
以推断 tip 是否被复用(一次 pick_up_tips 多次 aspirate/dispense → 复用)。
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, channel_num: int = 1, tip_reuse_by_liquid_name: bool = True):
|
|
||||||
# 不调用 super().__init__,避免硬件 / ROS / PLR Deck 初始化。
|
|
||||||
self.channel_num = channel_num
|
|
||||||
self.support_touch_tip = True
|
|
||||||
self.current_tip = iter(make_tip_iter(2048))
|
|
||||||
self.calls: List[Tuple[str, Any]] = []
|
|
||||||
self._tip_reuse_by_liquid_name: bool = tip_reuse_by_liquid_name
|
|
||||||
|
|
||||||
def set_tiprack(self, tip_racks):
|
|
||||||
if not tip_racks:
|
|
||||||
return
|
|
||||||
# 跳过真实 set_tiprack(依赖 PLR Deck)
|
|
||||||
return
|
|
||||||
|
|
||||||
async def pick_up_tips(self, tip_spots, use_channels=None, offsets=None, **kw):
|
|
||||||
self.calls.append(("pick_up_tips", {"tips": list(tip_spots), "use_channels": use_channels}))
|
|
||||||
|
|
||||||
async def aspirate(
|
|
||||||
self,
|
|
||||||
resources: Sequence[Any],
|
|
||||||
vols: List[float],
|
|
||||||
use_channels: Optional[List[int]] = None,
|
|
||||||
flow_rates: Optional[List[Optional[float]]] = None,
|
|
||||||
offsets: Any = None,
|
|
||||||
liquid_height: Any = None,
|
|
||||||
blow_out_air_volume: Any = None,
|
|
||||||
spread: str = "wide",
|
|
||||||
**backend_kwargs,
|
|
||||||
):
|
|
||||||
self.calls.append(
|
|
||||||
("aspirate", {"resources": list(resources), "vols": list(vols)})
|
|
||||||
)
|
|
||||||
|
|
||||||
async def dispense(
|
|
||||||
self,
|
|
||||||
resources: Sequence[Any],
|
|
||||||
vols: List[float],
|
|
||||||
use_channels: Optional[List[int]] = None,
|
|
||||||
flow_rates: Optional[List[Optional[float]]] = None,
|
|
||||||
offsets: Any = None,
|
|
||||||
liquid_height: Any = None,
|
|
||||||
blow_out_air_volume: Any = None,
|
|
||||||
spread: str = "wide",
|
|
||||||
**backend_kwargs,
|
|
||||||
):
|
|
||||||
self.calls.append(
|
|
||||||
("dispense", {"resources": list(resources), "vols": list(vols)})
|
|
||||||
)
|
|
||||||
|
|
||||||
async def discard_tips(self, use_channels=None, *args, **kwargs):
|
|
||||||
self.calls.append(("discard_tips", {"use_channels": use_channels}))
|
|
||||||
|
|
||||||
|
|
||||||
class AspiratePopFakeLiquidHandler(FakeLiquidHandler):
|
|
||||||
"""T11 专用:aspirate 时模拟 PLR "顶层归零时 pop ``tracker.liquids`` 顶层" 的行为。
|
|
||||||
|
|
||||||
用于验证 P10 v2 的关键时序约束:tip name 必须在 aspirate **之前**预读,
|
|
||||||
否则 aspirate 后再读 ``tracker.liquids[-1]`` 会拿不到液体身份。
|
|
||||||
"""
|
|
||||||
|
|
||||||
async def aspirate(self, resources, vols, **kwargs):
|
|
||||||
await super().aspirate(resources, vols, **kwargs)
|
|
||||||
# 模拟 PLR 顶层归零时 pop:对每个 source well,若 liquids 非空则 pop 顶层
|
|
||||||
for r in resources:
|
|
||||||
tracker = getattr(r, "tracker", None)
|
|
||||||
if tracker is not None and tracker.liquids:
|
|
||||||
tracker.liquids.pop()
|
|
||||||
|
|
||||||
|
|
||||||
def run(coro):
|
|
||||||
return asyncio.run(coro)
|
|
||||||
|
|
||||||
|
|
||||||
def call_names(lh: FakeLiquidHandler) -> List[str]:
|
|
||||||
return [c[0] for c in lh.calls]
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
# Helper 单元测试
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
class TestIsKnownLiquidName:
|
|
||||||
def test_empty_string_is_unknown(self) -> None:
|
|
||||||
assert is_known_liquid_name("") is False
|
|
||||||
|
|
||||||
def test_none_is_unknown(self) -> None:
|
|
||||||
assert is_known_liquid_name(None) is False
|
|
||||||
|
|
||||||
def test_literal_unknown_is_unknown(self) -> None:
|
|
||||||
assert is_known_liquid_name("unknown") is False
|
|
||||||
assert is_known_liquid_name("UNKNOWN") is False
|
|
||||||
assert is_known_liquid_name(" Unknown ") is False
|
|
||||||
|
|
||||||
def test_literal_none_string_is_unknown(self) -> None:
|
|
||||||
assert is_known_liquid_name("none") is False
|
|
||||||
assert is_known_liquid_name("None") is False
|
|
||||||
|
|
||||||
def test_real_liquid_name_is_known(self) -> None:
|
|
||||||
assert is_known_liquid_name("PBS") is True
|
|
||||||
assert is_known_liquid_name("Tris HCl") is True
|
|
||||||
assert is_known_liquid_name("Liquid_3") is True
|
|
||||||
|
|
||||||
|
|
||||||
class TestSameLiquidViaLiquids:
|
|
||||||
def test_well_and_tip_same_name_match(self) -> None:
|
|
||||||
well = make_well("A1", "PBS")
|
|
||||||
assert same_liquid_via_liquids(well, "PBS") is True
|
|
||||||
|
|
||||||
def test_well_and_tip_different_names_no_match(self) -> None:
|
|
||||||
well = make_well("A1", "PBS")
|
|
||||||
assert same_liquid_via_liquids(well, "Tris HCl") is False
|
|
||||||
|
|
||||||
def test_tip_unknown_returns_false(self) -> None:
|
|
||||||
well = make_well("A1", "PBS")
|
|
||||||
assert same_liquid_via_liquids(well, None) is False
|
|
||||||
assert same_liquid_via_liquids(well, "") is False
|
|
||||||
assert same_liquid_via_liquids(well, "unknown") is False
|
|
||||||
|
|
||||||
def test_well_empty_liquids_returns_false(self) -> None:
|
|
||||||
well = make_well("A1", liquid_name=None) # 不写 liquids
|
|
||||||
assert same_liquid_via_liquids(well, "PBS") is False
|
|
||||||
|
|
||||||
def test_well_unknown_literal_returns_false(self) -> None:
|
|
||||||
well = make_well("A1", "unknown")
|
|
||||||
assert same_liquid_via_liquids(well, "unknown") is False
|
|
||||||
|
|
||||||
|
|
||||||
class TestSameLiquidViaLiquidsPair:
|
|
||||||
def test_two_wells_same_name_match(self) -> None:
|
|
||||||
a = make_well("A1", "PBS")
|
|
||||||
b = make_well("B1", "PBS")
|
|
||||||
assert same_liquid_via_liquids_pair(a, b) is True
|
|
||||||
|
|
||||||
def test_two_wells_different_names_no_match(self) -> None:
|
|
||||||
a = make_well("A1", "PBS")
|
|
||||||
b = make_well("B1", "Tris HCl")
|
|
||||||
assert same_liquid_via_liquids_pair(a, b) is False
|
|
||||||
|
|
||||||
def test_either_well_empty_returns_false(self) -> None:
|
|
||||||
a = make_well("A1", "PBS")
|
|
||||||
b = make_well("B1", liquid_name=None)
|
|
||||||
assert same_liquid_via_liquids_pair(a, b) is False
|
|
||||||
assert same_liquid_via_liquids_pair(b, a) is False
|
|
||||||
|
|
||||||
|
|
||||||
class TestCaptureTipLiquidName:
|
|
||||||
def test_known_name_returned(self) -> None:
|
|
||||||
well = make_well("A1", "PBS")
|
|
||||||
assert capture_tip_liquid_name(well) == "PBS"
|
|
||||||
|
|
||||||
def test_empty_well_returns_none(self) -> None:
|
|
||||||
well = make_well("A1", liquid_name=None)
|
|
||||||
assert capture_tip_liquid_name(well) is None
|
|
||||||
|
|
||||||
def test_unknown_literal_returns_none(self) -> None:
|
|
||||||
well = make_well("A1", "unknown")
|
|
||||||
assert capture_tip_liquid_name(well) is None
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
# T1–T12 端到端测试(单通道 transfer_liquid 主循环)
|
|
||||||
#
|
|
||||||
# 需要 PLR 完整环境(``pylabrobot.liquid_handling.LiquidHandlerBackend`` 等)。
|
|
||||||
# 若 PLR import 失败则整段 skip,helper 测试照常运行。
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
_skip_if_no_plr = pytest.mark.skipif(
|
|
||||||
not _PLR_AVAILABLE,
|
|
||||||
reason=f"pylabrobot import failed: {_PLR_IMPORT_ERROR}",
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@_skip_if_no_plr
|
|
||||||
class TestSingleChannelTipReuse:
|
|
||||||
"""覆盖 §5 矩阵 T1 / T2 / T3 / T4 / T5 / T6 / T8 / T10 / T11。"""
|
|
||||||
|
|
||||||
def test_T1_identity_hit_reuses_tip(self) -> None:
|
|
||||||
"""T1:连续 2 轮同 source/target → identity-keep 命中,复用 tip。"""
|
|
||||||
lh = FakeLiquidHandler(channel_num=1)
|
|
||||||
src = make_well("S0", "PBS")
|
|
||||||
tgt = make_well("T0")
|
|
||||||
run(
|
|
||||||
lh.transfer_liquid(
|
|
||||||
sources=[src, src],
|
|
||||||
targets=[tgt, tgt],
|
|
||||||
tip_racks=[],
|
|
||||||
use_channels=[0],
|
|
||||||
asp_vols=[1, 1],
|
|
||||||
dis_vols=[1, 1],
|
|
||||||
)
|
|
||||||
)
|
|
||||||
# 2 次 transfer,但 identity-keep → 仅 1 次 pick_up_tips / 1 次 discard_tips
|
|
||||||
assert call_names(lh).count("pick_up_tips") == 1
|
|
||||||
assert call_names(lh).count("discard_tips") == 1
|
|
||||||
assert call_names(lh).count("aspirate") == 2
|
|
||||||
assert call_names(lh).count("dispense") == 2
|
|
||||||
|
|
||||||
def test_T2_liquids_hit_across_plates(self) -> None:
|
|
||||||
"""T2:9 个独立 source well(不同 PLR Well 对象)都装 PBS → identity 全 fail,liquids-keep 全命中。"""
|
|
||||||
lh = FakeLiquidHandler(channel_num=1)
|
|
||||||
sources = [make_well(f"S{i}", "PBS") for i in range(9)]
|
|
||||||
targets = [make_well(f"T{i}") for i in range(9)]
|
|
||||||
run(
|
|
||||||
lh.transfer_liquid(
|
|
||||||
sources=sources,
|
|
||||||
targets=targets,
|
|
||||||
tip_racks=[],
|
|
||||||
use_channels=[0],
|
|
||||||
asp_vols=[1] * 9,
|
|
||||||
dis_vols=[1] * 9,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
# 9 个 source 物理上同液 → 整段共用 1 个 tip
|
|
||||||
assert call_names(lh).count("pick_up_tips") == 1
|
|
||||||
assert call_names(lh).count("discard_tips") == 1
|
|
||||||
assert call_names(lh).count("aspirate") == 9
|
|
||||||
assert call_names(lh).count("dispense") == 9
|
|
||||||
|
|
||||||
def test_T3_liquids_hit_same_plate_different_wells(self) -> None:
|
|
||||||
"""T3:同 plate 上 A1-H1 都装 PBS(8 个不同 Well 对象)→ identity 全 fail,liquids-keep 命中。"""
|
|
||||||
lh = FakeLiquidHandler(channel_num=1)
|
|
||||||
sources = [make_well(f"A{i}", "PBS") for i in range(1, 9)]
|
|
||||||
targets = [make_well(f"T{i}") for i in range(8)]
|
|
||||||
run(
|
|
||||||
lh.transfer_liquid(
|
|
||||||
sources=sources,
|
|
||||||
targets=targets,
|
|
||||||
tip_racks=[],
|
|
||||||
use_channels=[0],
|
|
||||||
asp_vols=[1] * 8,
|
|
||||||
dis_vols=[1] * 8,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
assert call_names(lh).count("pick_up_tips") == 1
|
|
||||||
assert call_names(lh).count("discard_tips") == 1
|
|
||||||
|
|
||||||
def test_T4_liquids_not_match_forces_tip_change(self) -> None:
|
|
||||||
"""T4:A1=PBS,B1=Tris HCl → liquids 名不等,强制换 tip。"""
|
|
||||||
lh = FakeLiquidHandler(channel_num=1)
|
|
||||||
sources = [make_well("A1", "PBS"), make_well("B1", "Tris HCl")]
|
|
||||||
targets = [make_well("T0"), make_well("T1")]
|
|
||||||
run(
|
|
||||||
lh.transfer_liquid(
|
|
||||||
sources=sources,
|
|
||||||
targets=targets,
|
|
||||||
tip_racks=[],
|
|
||||||
use_channels=[0],
|
|
||||||
asp_vols=[1, 1],
|
|
||||||
dis_vols=[1, 1],
|
|
||||||
)
|
|
||||||
)
|
|
||||||
# 2 次完全独立的 transfer:2 次 pick_up / 2 次 discard
|
|
||||||
assert call_names(lh).count("pick_up_tips") == 2
|
|
||||||
assert call_names(lh).count("discard_tips") == 2
|
|
||||||
|
|
||||||
def test_T5_empty_liquids_forces_tip_change(self) -> None:
|
|
||||||
"""T5:source 从未调过 set_liquids(liquids 空)→ 视为未知,强制换 tip。"""
|
|
||||||
lh = FakeLiquidHandler(channel_num=1)
|
|
||||||
sources = [make_well("A1"), make_well("B1")] # 没装液体名
|
|
||||||
targets = [make_well("T0"), make_well("T1")]
|
|
||||||
run(
|
|
||||||
lh.transfer_liquid(
|
|
||||||
sources=sources,
|
|
||||||
targets=targets,
|
|
||||||
tip_racks=[],
|
|
||||||
use_channels=[0],
|
|
||||||
asp_vols=[1, 1],
|
|
||||||
dis_vols=[1, 1],
|
|
||||||
)
|
|
||||||
)
|
|
||||||
assert call_names(lh).count("pick_up_tips") == 2
|
|
||||||
assert call_names(lh).count("discard_tips") == 2
|
|
||||||
|
|
||||||
def test_T6_switch_off_disables_liquids_keep(self) -> None:
|
|
||||||
"""T6:tip_reuse_by_liquid_name=False,T2 场景退化为 identity-only,强制换 tip。"""
|
|
||||||
lh = FakeLiquidHandler(channel_num=1, tip_reuse_by_liquid_name=False)
|
|
||||||
sources = [make_well(f"S{i}", "PBS") for i in range(9)]
|
|
||||||
targets = [make_well(f"T{i}") for i in range(9)]
|
|
||||||
run(
|
|
||||||
lh.transfer_liquid(
|
|
||||||
sources=sources,
|
|
||||||
targets=targets,
|
|
||||||
tip_racks=[],
|
|
||||||
use_channels=[0],
|
|
||||||
asp_vols=[1] * 9,
|
|
||||||
dis_vols=[1] * 9,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
# 关闭开关后 → 退化为 identity-only,9 次独立换 tip
|
|
||||||
assert call_names(lh).count("pick_up_tips") == 9
|
|
||||||
assert call_names(lh).count("discard_tips") == 9
|
|
||||||
|
|
||||||
def test_T8_mix_style_same_source_reuses_via_identity(self) -> None:
|
|
||||||
"""T8:单 source 反复 aspirate/dispense → identity-keep 命中(mix-style)。"""
|
|
||||||
lh = FakeLiquidHandler(channel_num=1)
|
|
||||||
src = make_well("S0", "Methanol")
|
|
||||||
tgt = make_well("T0")
|
|
||||||
run(
|
|
||||||
lh.transfer_liquid(
|
|
||||||
sources=[src, src, src],
|
|
||||||
targets=[tgt, tgt, tgt],
|
|
||||||
tip_racks=[],
|
|
||||||
use_channels=[0],
|
|
||||||
asp_vols=[1, 1, 1],
|
|
||||||
dis_vols=[1, 1, 1],
|
|
||||||
)
|
|
||||||
)
|
|
||||||
assert call_names(lh).count("pick_up_tips") == 1
|
|
||||||
assert call_names(lh).count("discard_tips") == 1
|
|
||||||
|
|
||||||
def test_T10_unknown_literal_treated_as_unknown(self) -> None:
|
|
||||||
"""T10:``tracker.liquids = [("unknown", v)]``(兼容旧数据)→ 视为未知,强制换 tip。"""
|
|
||||||
lh = FakeLiquidHandler(channel_num=1)
|
|
||||||
sources = [make_well("A1", "unknown"), make_well("B1", "unknown")]
|
|
||||||
targets = [make_well("T0"), make_well("T1")]
|
|
||||||
run(
|
|
||||||
lh.transfer_liquid(
|
|
||||||
sources=sources,
|
|
||||||
targets=targets,
|
|
||||||
tip_racks=[],
|
|
||||||
use_channels=[0],
|
|
||||||
asp_vols=[1, 1],
|
|
||||||
dis_vols=[1, 1],
|
|
||||||
)
|
|
||||||
)
|
|
||||||
assert call_names(lh).count("pick_up_tips") == 2
|
|
||||||
assert call_names(lh).count("discard_tips") == 2
|
|
||||||
|
|
||||||
def test_T11_aspirate_pop_timing_pre_read(self) -> None:
|
|
||||||
"""T11:aspirate 顶层归零 → PLR pop ``tracker.liquids`` 顶层;
|
|
||||||
验证 P10 v2 ``pending_tip_name`` 必须在 aspirate **之前**预读才能命中下一轮。
|
|
||||||
"""
|
|
||||||
lh = AspiratePopFakeLiquidHandler(channel_num=1)
|
|
||||||
sources = [make_well(f"S{i}", "PBS") for i in range(3)]
|
|
||||||
targets = [make_well(f"T{i}") for i in range(3)]
|
|
||||||
run(
|
|
||||||
lh.transfer_liquid(
|
|
||||||
sources=sources,
|
|
||||||
targets=targets,
|
|
||||||
tip_racks=[],
|
|
||||||
use_channels=[0],
|
|
||||||
asp_vols=[1] * 3,
|
|
||||||
dis_vols=[1] * 3,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
# 即使 aspirate 后 source.tracker.liquids 被 pop,pending_tip_name 已捕获 "PBS"
|
|
||||||
# → 下一轮 source 仍是 PBS(aspirate 还没发生),liquids-keep 命中
|
|
||||||
# → 整段 1 次 pick_up_tips
|
|
||||||
assert call_names(lh).count("pick_up_tips") == 1
|
|
||||||
assert call_names(lh).count("discard_tips") == 1
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
# T7:跨节点边界(两个独立 transfer_liquid 调用,状态隔离)
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
@_skip_if_no_plr
|
|
||||||
class TestCrossNodeBoundary:
|
|
||||||
"""T7:两个 transfer_liquid 节点之间不复用 tip(每次调用初始化 current_tip_liquid_name=None)。"""
|
|
||||||
|
|
||||||
def test_T7_two_calls_dont_share_tip_state(self) -> None:
|
|
||||||
lh = FakeLiquidHandler(channel_num=1)
|
|
||||||
src_a = make_well("A_src", "PBS")
|
|
||||||
tgt_a = make_well("A_tgt")
|
|
||||||
src_b = make_well("B_src", "PBS") # 同名液,但不同 well
|
|
||||||
tgt_b = make_well("B_tgt")
|
|
||||||
|
|
||||||
run(
|
|
||||||
lh.transfer_liquid(
|
|
||||||
sources=[src_a],
|
|
||||||
targets=[tgt_a],
|
|
||||||
tip_racks=[],
|
|
||||||
use_channels=[0],
|
|
||||||
asp_vols=[1],
|
|
||||||
dis_vols=[1],
|
|
||||||
)
|
|
||||||
)
|
|
||||||
run(
|
|
||||||
lh.transfer_liquid(
|
|
||||||
sources=[src_b],
|
|
||||||
targets=[tgt_b],
|
|
||||||
tip_racks=[],
|
|
||||||
use_channels=[0],
|
|
||||||
asp_vols=[1],
|
|
||||||
dis_vols=[1],
|
|
||||||
)
|
|
||||||
)
|
|
||||||
# 两次调用各自独立换 tip → 2 次 pick_up_tips / 2 次 discard_tips
|
|
||||||
assert call_names(lh).count("pick_up_tips") == 2
|
|
||||||
assert call_names(lh).count("discard_tips") == 2
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
# T9:8 通道段锚孔 liquids-keep
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
@_skip_if_no_plr
|
|
||||||
class TestEightChannelSegmentTipReuse:
|
|
||||||
"""T9:8 通道分段,连续两段 src_slice[0] 同名 → 段间不换 tip。"""
|
|
||||||
|
|
||||||
def test_T9_two_segments_same_anchor_liquid(self) -> None:
|
|
||||||
lh = FakeLiquidHandler(channel_num=8)
|
|
||||||
# 16 个 source wells,分 2 段;段 1 锚孔 = sources[0],段 2 锚孔 = sources[8]
|
|
||||||
sources = [make_well(f"S{i}", "PBS") for i in range(16)]
|
|
||||||
targets = [make_well(f"T{i}") for i in range(16)]
|
|
||||||
run(
|
|
||||||
lh.transfer_liquid(
|
|
||||||
sources=sources,
|
|
||||||
targets=targets,
|
|
||||||
tip_racks=[],
|
|
||||||
use_channels=list(range(8)),
|
|
||||||
asp_vols=[1] * 16,
|
|
||||||
dis_vols=[1] * 16,
|
|
||||||
mix_times=0,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
# 2 段都同液 → liquids-keep 命中 → 仅 1 次 pick_up_tips
|
|
||||||
assert call_names(lh).count("pick_up_tips") == 1
|
|
||||||
assert call_names(lh).count("discard_tips") == 1
|
|
||||||
|
|
||||||
def test_T9b_two_segments_different_anchor_liquid_forces_tip_change(self) -> None:
|
|
||||||
"""T9b:段 1 锚孔 = PBS,段 2 锚孔 = Tris → 段间强制换 tip。"""
|
|
||||||
lh = FakeLiquidHandler(channel_num=8)
|
|
||||||
seg1 = [make_well(f"S{i}", "PBS") for i in range(8)]
|
|
||||||
seg2 = [make_well(f"S{i + 8}", "Tris HCl") for i in range(8)]
|
|
||||||
sources = seg1 + seg2
|
|
||||||
targets = [make_well(f"T{i}") for i in range(16)]
|
|
||||||
run(
|
|
||||||
lh.transfer_liquid(
|
|
||||||
sources=sources,
|
|
||||||
targets=targets,
|
|
||||||
tip_racks=[],
|
|
||||||
use_channels=list(range(8)),
|
|
||||||
asp_vols=[1] * 16,
|
|
||||||
dis_vols=[1] * 16,
|
|
||||||
mix_times=0,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
# 2 段不同液 → 2 次独立换 tip
|
|
||||||
assert call_names(lh).count("pick_up_tips") == 2
|
|
||||||
assert call_names(lh).count("discard_tips") == 2
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
# 配置开关默认值 / 实例字段读取
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
@_skip_if_no_plr
|
|
||||||
class TestConfigDefault:
|
|
||||||
def test_default_switch_is_on(self) -> None:
|
|
||||||
"""默认 ``_tip_reuse_by_liquid_name`` 应为 True(测试 fixture 显式 default 一致)。"""
|
|
||||||
lh = FakeLiquidHandler()
|
|
||||||
assert lh._tip_reuse_by_liquid_name is True
|
|
||||||
|
|
||||||
def test_switch_off_takes_effect(self) -> None:
|
|
||||||
lh = FakeLiquidHandler(tip_reuse_by_liquid_name=False)
|
|
||||||
assert lh._tip_reuse_by_liquid_name is False
|
|
||||||
@@ -39,11 +39,6 @@ class FakeLiquidHandler(LiquidHandlerAbstract):
|
|||||||
self.current_tip = iter(make_tip_iter())
|
self.current_tip = iter(make_tip_iter())
|
||||||
self.calls: List[Tuple[str, Any]] = []
|
self.calls: List[Tuple[str, Any]] = []
|
||||||
|
|
||||||
def set_tiprack(self, tip_racks):
|
|
||||||
if not tip_racks:
|
|
||||||
return
|
|
||||||
super().set_tiprack(tip_racks)
|
|
||||||
|
|
||||||
async def pick_up_tips(self, tip_spots, use_channels=None, offsets=None, **backend_kwargs):
|
async def pick_up_tips(self, tip_spots, use_channels=None, offsets=None, **backend_kwargs):
|
||||||
self.calls.append(("pick_up_tips", {"tips": list(tip_spots), "use_channels": use_channels}))
|
self.calls.append(("pick_up_tips", {"tips": list(tip_spots), "use_channels": use_channels}))
|
||||||
|
|
||||||
|
|||||||
@@ -1,608 +0,0 @@
|
|||||||
import asyncio
|
|
||||||
from dataclasses import dataclass
|
|
||||||
from typing import Any, Iterable, List, Optional, Sequence, Tuple
|
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
from unilabos.devices.liquid_handling.liquid_handler_abstract import LiquidHandlerAbstract
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
|
||||||
class DummyContainer:
|
|
||||||
name: str
|
|
||||||
|
|
||||||
def __repr__(self) -> str: # pragma: no cover
|
|
||||||
return f"DummyContainer({self.name})"
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
|
||||||
class DummyTipSpot:
|
|
||||||
name: str
|
|
||||||
|
|
||||||
def __repr__(self) -> str: # pragma: no cover
|
|
||||||
return f"DummyTipSpot({self.name})"
|
|
||||||
|
|
||||||
|
|
||||||
def make_tip_iter(n: int = 256) -> Iterable[List[DummyTipSpot]]:
|
|
||||||
"""Yield lists so code can safely call `tip.extend(next(self.current_tip))`."""
|
|
||||||
for i in range(n):
|
|
||||||
yield [DummyTipSpot(f"tip_{i}")]
|
|
||||||
|
|
||||||
|
|
||||||
class FakeLiquidHandler(LiquidHandlerAbstract):
|
|
||||||
"""不初始化真实 backend/deck;仅用来记录 transfer_liquid 内部调用序列。"""
|
|
||||||
|
|
||||||
def __init__(self, channel_num: int = 8):
|
|
||||||
# 不调用 super().__init__,避免真实硬件/后端依赖
|
|
||||||
self.channel_num = channel_num
|
|
||||||
self.support_touch_tip = True
|
|
||||||
self.current_tip = iter(make_tip_iter())
|
|
||||||
self.calls: List[Tuple[str, Any]] = []
|
|
||||||
|
|
||||||
def set_tiprack(self, tip_racks):
|
|
||||||
# transfer_liquid 总会调用 set_tiprack;测试用 Dummy 枪头时 tip_racks 为空,需保留自种子的 current_tip
|
|
||||||
if not tip_racks:
|
|
||||||
return
|
|
||||||
super().set_tiprack(tip_racks)
|
|
||||||
|
|
||||||
async def pick_up_tips(self, tip_spots, use_channels=None, offsets=None, **backend_kwargs):
|
|
||||||
self.calls.append(("pick_up_tips", {"tips": list(tip_spots), "use_channels": use_channels}))
|
|
||||||
|
|
||||||
async def aspirate(
|
|
||||||
self,
|
|
||||||
resources: Sequence[Any],
|
|
||||||
vols: List[float],
|
|
||||||
use_channels: Optional[List[int]] = None,
|
|
||||||
flow_rates: Optional[List[Optional[float]]] = None,
|
|
||||||
offsets: Any = None,
|
|
||||||
liquid_height: Any = None,
|
|
||||||
blow_out_air_volume: Any = None,
|
|
||||||
spread: str = "wide",
|
|
||||||
**backend_kwargs,
|
|
||||||
):
|
|
||||||
self.calls.append(
|
|
||||||
(
|
|
||||||
"aspirate",
|
|
||||||
{
|
|
||||||
"resources": list(resources),
|
|
||||||
"vols": list(vols),
|
|
||||||
"use_channels": list(use_channels) if use_channels is not None else None,
|
|
||||||
"flow_rates": list(flow_rates) if flow_rates is not None else None,
|
|
||||||
"offsets": list(offsets) if offsets is not None else None,
|
|
||||||
"liquid_height": list(liquid_height) if liquid_height is not None else None,
|
|
||||||
"blow_out_air_volume": list(blow_out_air_volume) if blow_out_air_volume is not None else None,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
async def dispense(
|
|
||||||
self,
|
|
||||||
resources: Sequence[Any],
|
|
||||||
vols: List[float],
|
|
||||||
use_channels: Optional[List[int]] = None,
|
|
||||||
flow_rates: Optional[List[Optional[float]]] = None,
|
|
||||||
offsets: Any = None,
|
|
||||||
liquid_height: Any = None,
|
|
||||||
blow_out_air_volume: Any = None,
|
|
||||||
spread: str = "wide",
|
|
||||||
**backend_kwargs,
|
|
||||||
):
|
|
||||||
self.calls.append(
|
|
||||||
(
|
|
||||||
"dispense",
|
|
||||||
{
|
|
||||||
"resources": list(resources),
|
|
||||||
"vols": list(vols),
|
|
||||||
"use_channels": list(use_channels) if use_channels is not None else None,
|
|
||||||
"flow_rates": list(flow_rates) if flow_rates is not None else None,
|
|
||||||
"offsets": list(offsets) if offsets is not None else None,
|
|
||||||
"liquid_height": list(liquid_height) if liquid_height is not None else None,
|
|
||||||
"blow_out_air_volume": list(blow_out_air_volume) if blow_out_air_volume is not None else None,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
async def discard_tips(self, use_channels=None, *args, **kwargs):
|
|
||||||
# 有的分支是 discard_tips(use_channels=[0]),有的分支是 discard_tips([0..7])(位置参数)
|
|
||||||
self.calls.append(("discard_tips", {"use_channels": list(use_channels) if use_channels is not None else None}))
|
|
||||||
|
|
||||||
async def custom_delay(self, seconds=0, msg=None):
|
|
||||||
self.calls.append(("custom_delay", {"seconds": seconds, "msg": msg}))
|
|
||||||
|
|
||||||
async def touch_tip(self, targets):
|
|
||||||
# 原实现会访问 targets.get_size_x() 等;测试里只记录调用
|
|
||||||
self.calls.append(("touch_tip", {"targets": targets}))
|
|
||||||
|
|
||||||
def run(coro):
|
|
||||||
return asyncio.run(coro)
|
|
||||||
|
|
||||||
|
|
||||||
def test_one_to_one_single_channel_basic_calls():
|
|
||||||
lh = FakeLiquidHandler(channel_num=1)
|
|
||||||
lh.current_tip = iter(make_tip_iter(64))
|
|
||||||
|
|
||||||
sources = [DummyContainer(f"S{i}") for i in range(3)]
|
|
||||||
targets = [DummyContainer(f"T{i}") for i in range(3)]
|
|
||||||
|
|
||||||
run(
|
|
||||||
lh.transfer_liquid(
|
|
||||||
sources=sources,
|
|
||||||
targets=targets,
|
|
||||||
tip_racks=[],
|
|
||||||
use_channels=[0],
|
|
||||||
asp_vols=[1, 2, 3],
|
|
||||||
dis_vols=[4, 5, 6],
|
|
||||||
mix_times=None, # 应该仍能执行(不 mix)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
assert [c[0] for c in lh.calls].count("pick_up_tips") == 3
|
|
||||||
assert [c[0] for c in lh.calls].count("aspirate") == 3
|
|
||||||
assert [c[0] for c in lh.calls].count("dispense") == 3
|
|
||||||
assert [c[0] for c in lh.calls].count("discard_tips") == 3
|
|
||||||
|
|
||||||
# 每次 aspirate/dispense 都是单孔列表
|
|
||||||
aspirates = [payload for name, payload in lh.calls if name == "aspirate"]
|
|
||||||
assert aspirates[0]["resources"] == [sources[0]]
|
|
||||||
assert aspirates[0]["vols"] == [1.0]
|
|
||||||
|
|
||||||
dispenses = [payload for name, payload in lh.calls if name == "dispense"]
|
|
||||||
assert dispenses[2]["resources"] == [targets[2]]
|
|
||||||
assert dispenses[2]["vols"] == [6.0]
|
|
||||||
|
|
||||||
|
|
||||||
def test_one_to_one_single_channel_before_stage_mixes_prior_to_aspirate():
|
|
||||||
lh = FakeLiquidHandler(channel_num=1)
|
|
||||||
lh.current_tip = iter(make_tip_iter(16))
|
|
||||||
|
|
||||||
source = DummyContainer("S0")
|
|
||||||
target = DummyContainer("T0")
|
|
||||||
|
|
||||||
run(
|
|
||||||
lh.transfer_liquid(
|
|
||||||
sources=[source],
|
|
||||||
targets=[target],
|
|
||||||
tip_racks=[],
|
|
||||||
use_channels=[0],
|
|
||||||
asp_vols=[5],
|
|
||||||
dis_vols=[5],
|
|
||||||
mix_stage="before",
|
|
||||||
mix_times=1,
|
|
||||||
mix_vol=3,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
aspirate_calls = [(idx, payload) for idx, (name, payload) in enumerate(lh.calls) if name == "aspirate"]
|
|
||||||
assert len(aspirate_calls) >= 2
|
|
||||||
mix_idx, mix_payload = aspirate_calls[0]
|
|
||||||
assert mix_payload["resources"] == [target]
|
|
||||||
assert mix_payload["vols"] == [3]
|
|
||||||
transfer_idx, transfer_payload = aspirate_calls[1]
|
|
||||||
assert transfer_payload["resources"] == [source]
|
|
||||||
assert mix_idx < transfer_idx
|
|
||||||
|
|
||||||
|
|
||||||
def test_one_to_one_eight_channel_groups_by_8():
|
|
||||||
lh = FakeLiquidHandler(channel_num=8)
|
|
||||||
lh.current_tip = iter(make_tip_iter(256))
|
|
||||||
|
|
||||||
sources = [DummyContainer(f"S{i}") for i in range(16)]
|
|
||||||
targets = [DummyContainer(f"T{i}") for i in range(16)]
|
|
||||||
asp_vols = list(range(1, 17))
|
|
||||||
dis_vols = list(range(101, 117))
|
|
||||||
|
|
||||||
run(
|
|
||||||
lh.transfer_liquid(
|
|
||||||
sources=sources,
|
|
||||||
targets=targets,
|
|
||||||
tip_racks=[],
|
|
||||||
use_channels=list(range(8)),
|
|
||||||
asp_vols=asp_vols,
|
|
||||||
dis_vols=dis_vols,
|
|
||||||
mix_times=0, # 触发逻辑但不 mix
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
# 16 个任务 -> 2 组,每组 8 通道一起做
|
|
||||||
assert [c[0] for c in lh.calls].count("pick_up_tips") == 2
|
|
||||||
aspirates = [payload for name, payload in lh.calls if name == "aspirate"]
|
|
||||||
dispenses = [payload for name, payload in lh.calls if name == "dispense"]
|
|
||||||
assert len(aspirates) == 2
|
|
||||||
assert len(dispenses) == 2
|
|
||||||
|
|
||||||
assert aspirates[0]["resources"] == sources[0:8]
|
|
||||||
assert aspirates[0]["vols"] == [float(v) for v in asp_vols[0:8]]
|
|
||||||
assert dispenses[1]["resources"] == targets[8:16]
|
|
||||||
assert dispenses[1]["vols"] == [float(v) for v in dis_vols[8:16]]
|
|
||||||
|
|
||||||
|
|
||||||
def test_one_to_one_eight_channel_requires_multiple_of_8_targets():
|
|
||||||
lh = FakeLiquidHandler(channel_num=8)
|
|
||||||
lh.current_tip = iter(make_tip_iter(64))
|
|
||||||
|
|
||||||
sources = [DummyContainer(f"S{i}") for i in range(9)]
|
|
||||||
targets = [DummyContainer(f"T{i}") for i in range(9)]
|
|
||||||
|
|
||||||
with pytest.raises(ValueError, match="multiple of 8"):
|
|
||||||
run(
|
|
||||||
lh.transfer_liquid(
|
|
||||||
sources=sources,
|
|
||||||
targets=targets,
|
|
||||||
tip_racks=[],
|
|
||||||
use_channels=list(range(8)),
|
|
||||||
asp_vols=[1] * 9,
|
|
||||||
dis_vols=[1] * 9,
|
|
||||||
mix_times=0,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_one_to_one_eight_channel_parameter_lists_are_chunked_per_8():
|
|
||||||
lh = FakeLiquidHandler(channel_num=8)
|
|
||||||
lh.current_tip = iter(make_tip_iter(512))
|
|
||||||
|
|
||||||
sources = [DummyContainer(f"S{i}") for i in range(16)]
|
|
||||||
targets = [DummyContainer(f"T{i}") for i in range(16)]
|
|
||||||
asp_vols = [i + 1 for i in range(16)]
|
|
||||||
dis_vols = [200 + i for i in range(16)]
|
|
||||||
asp_flow_rates = [0.1 * (i + 1) for i in range(16)]
|
|
||||||
dis_flow_rates = [0.2 * (i + 1) for i in range(16)]
|
|
||||||
offsets = [f"offset_{i}" for i in range(16)]
|
|
||||||
liquid_heights = [i * 0.5 for i in range(16)]
|
|
||||||
blow_out_air_volume = [i + 0.05 for i in range(16)]
|
|
||||||
|
|
||||||
run(
|
|
||||||
lh.transfer_liquid(
|
|
||||||
sources=sources,
|
|
||||||
targets=targets,
|
|
||||||
tip_racks=[],
|
|
||||||
use_channels=list(range(8)),
|
|
||||||
asp_vols=asp_vols,
|
|
||||||
dis_vols=dis_vols,
|
|
||||||
asp_flow_rates=asp_flow_rates,
|
|
||||||
dis_flow_rates=dis_flow_rates,
|
|
||||||
offsets=offsets,
|
|
||||||
liquid_height=liquid_heights,
|
|
||||||
blow_out_air_volume=blow_out_air_volume,
|
|
||||||
mix_times=0,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
aspirates = [payload for name, payload in lh.calls if name == "aspirate"]
|
|
||||||
dispenses = [payload for name, payload in lh.calls if name == "dispense"]
|
|
||||||
assert len(aspirates) == len(dispenses) == 2
|
|
||||||
|
|
||||||
for batch_idx in range(2):
|
|
||||||
start = batch_idx * 8
|
|
||||||
end = start + 8
|
|
||||||
asp_call = aspirates[batch_idx]
|
|
||||||
dis_call = dispenses[batch_idx]
|
|
||||||
assert asp_call["resources"] == sources[start:end]
|
|
||||||
assert asp_call["flow_rates"] == asp_flow_rates[start:end]
|
|
||||||
assert asp_call["offsets"] == offsets[start:end]
|
|
||||||
assert asp_call["liquid_height"] == liquid_heights[start:end]
|
|
||||||
assert asp_call["blow_out_air_volume"] == blow_out_air_volume[start:end]
|
|
||||||
assert dis_call["flow_rates"] == dis_flow_rates[start:end]
|
|
||||||
assert dis_call["offsets"] == offsets[start:end]
|
|
||||||
assert dis_call["liquid_height"] == liquid_heights[start:end]
|
|
||||||
assert dis_call["blow_out_air_volume"] == blow_out_air_volume[start:end]
|
|
||||||
|
|
||||||
|
|
||||||
def test_one_to_one_eight_channel_handles_32_tasks_four_batches():
|
|
||||||
lh = FakeLiquidHandler(channel_num=8)
|
|
||||||
lh.current_tip = iter(make_tip_iter(1024))
|
|
||||||
|
|
||||||
sources = [DummyContainer(f"S{i}") for i in range(32)]
|
|
||||||
targets = [DummyContainer(f"T{i}") for i in range(32)]
|
|
||||||
asp_vols = [i + 1 for i in range(32)]
|
|
||||||
dis_vols = [300 + i for i in range(32)]
|
|
||||||
|
|
||||||
run(
|
|
||||||
lh.transfer_liquid(
|
|
||||||
sources=sources,
|
|
||||||
targets=targets,
|
|
||||||
tip_racks=[],
|
|
||||||
use_channels=list(range(8)),
|
|
||||||
asp_vols=asp_vols,
|
|
||||||
dis_vols=dis_vols,
|
|
||||||
mix_times=0,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
pick_calls = [name for name, _ in lh.calls if name == "pick_up_tips"]
|
|
||||||
aspirates = [payload for name, payload in lh.calls if name == "aspirate"]
|
|
||||||
dispenses = [payload for name, payload in lh.calls if name == "dispense"]
|
|
||||||
assert len(pick_calls) == 4
|
|
||||||
assert len(aspirates) == len(dispenses) == 4
|
|
||||||
assert aspirates[0]["resources"] == sources[0:8]
|
|
||||||
assert aspirates[-1]["resources"] == sources[24:32]
|
|
||||||
assert dispenses[0]["resources"] == targets[0:8]
|
|
||||||
assert dispenses[-1]["resources"] == targets[24:32]
|
|
||||||
|
|
||||||
|
|
||||||
def test_one_to_many_single_channel_aspirates_total_when_asp_vol_too_small():
|
|
||||||
lh = FakeLiquidHandler(channel_num=1)
|
|
||||||
lh.current_tip = iter(make_tip_iter(64))
|
|
||||||
|
|
||||||
source = DummyContainer("SRC")
|
|
||||||
targets = [DummyContainer(f"T{i}") for i in range(3)]
|
|
||||||
dis_vols = [10, 20, 30] # sum=60
|
|
||||||
|
|
||||||
run(
|
|
||||||
lh.transfer_liquid(
|
|
||||||
sources=[source],
|
|
||||||
targets=targets,
|
|
||||||
tip_racks=[],
|
|
||||||
use_channels=[0],
|
|
||||||
asp_vols=10, # 小于 sum(dis_vols) -> 应吸 60
|
|
||||||
dis_vols=dis_vols,
|
|
||||||
mix_times=0,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
aspirates = [payload for name, payload in lh.calls if name == "aspirate"]
|
|
||||||
assert len(aspirates) == 1
|
|
||||||
assert aspirates[0]["resources"] == [source]
|
|
||||||
assert aspirates[0]["vols"] == [60.0]
|
|
||||||
assert aspirates[0]["use_channels"] == [0]
|
|
||||||
dispenses = [payload for name, payload in lh.calls if name == "dispense"]
|
|
||||||
assert [d["vols"][0] for d in dispenses] == [10.0, 20.0, 30.0]
|
|
||||||
|
|
||||||
|
|
||||||
def test_one_to_many_eight_channel_basic():
|
|
||||||
lh = FakeLiquidHandler(channel_num=8)
|
|
||||||
lh.current_tip = iter(make_tip_iter(128))
|
|
||||||
|
|
||||||
source = DummyContainer("SRC")
|
|
||||||
targets = [DummyContainer(f"T{i}") for i in range(8)]
|
|
||||||
dis_vols = [i + 1 for i in range(8)]
|
|
||||||
|
|
||||||
run(
|
|
||||||
lh.transfer_liquid(
|
|
||||||
sources=[source],
|
|
||||||
targets=targets,
|
|
||||||
tip_racks=[],
|
|
||||||
use_channels=list(range(8)),
|
|
||||||
asp_vols=999, # one-to-many 8ch 会按 dis_vols 吸(每通道各自)
|
|
||||||
dis_vols=dis_vols,
|
|
||||||
mix_times=0,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
aspirates = [payload for name, payload in lh.calls if name == "aspirate"]
|
|
||||||
assert aspirates[0]["resources"] == [source] * 8
|
|
||||||
assert aspirates[0]["vols"] == [float(v) for v in dis_vols]
|
|
||||||
dispenses = [payload for name, payload in lh.calls if name == "dispense"]
|
|
||||||
assert dispenses[0]["resources"] == targets
|
|
||||||
assert dispenses[0]["vols"] == [float(v) for v in dis_vols]
|
|
||||||
|
|
||||||
|
|
||||||
def test_many_to_one_single_channel_standard_dispense_equals_asp_by_default():
|
|
||||||
lh = FakeLiquidHandler(channel_num=1)
|
|
||||||
lh.current_tip = iter(make_tip_iter(128))
|
|
||||||
|
|
||||||
sources = [DummyContainer(f"S{i}") for i in range(3)]
|
|
||||||
target = DummyContainer("T")
|
|
||||||
asp_vols = [5, 6, 7]
|
|
||||||
|
|
||||||
run(
|
|
||||||
lh.transfer_liquid(
|
|
||||||
sources=sources,
|
|
||||||
targets=[target],
|
|
||||||
tip_racks=[],
|
|
||||||
use_channels=[0],
|
|
||||||
asp_vols=asp_vols,
|
|
||||||
dis_vols=1, # many-to-one 允许标量;非比例模式下实际每次分液=对应 asp_vol
|
|
||||||
mix_times=0,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
dispenses = [payload for name, payload in lh.calls if name == "dispense"]
|
|
||||||
assert [d["vols"][0] for d in dispenses] == [float(v) for v in asp_vols]
|
|
||||||
assert all(d["resources"] == [target] for d in dispenses)
|
|
||||||
|
|
||||||
|
|
||||||
def test_many_to_one_single_channel_before_stage_mixes_target_once():
|
|
||||||
lh = FakeLiquidHandler(channel_num=1)
|
|
||||||
lh.current_tip = iter(make_tip_iter(128))
|
|
||||||
|
|
||||||
sources = [DummyContainer("S0"), DummyContainer("S1")]
|
|
||||||
target = DummyContainer("T")
|
|
||||||
|
|
||||||
run(
|
|
||||||
lh.transfer_liquid(
|
|
||||||
sources=sources,
|
|
||||||
targets=[target],
|
|
||||||
tip_racks=[],
|
|
||||||
use_channels=[0],
|
|
||||||
asp_vols=[5, 6],
|
|
||||||
dis_vols=1,
|
|
||||||
mix_stage="before",
|
|
||||||
mix_times=2,
|
|
||||||
mix_vol=4,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
aspirate_calls = [(idx, payload) for idx, (name, payload) in enumerate(lh.calls) if name == "aspirate"]
|
|
||||||
assert len(aspirate_calls) >= 1
|
|
||||||
mix_idx, mix_payload = aspirate_calls[0]
|
|
||||||
assert mix_payload["resources"] == [target]
|
|
||||||
assert mix_payload["vols"] == [4]
|
|
||||||
# 第一個 mix 之後會真正開始吸 source
|
|
||||||
assert any(call["resources"] == [sources[0]] for _, call in aspirate_calls[1:])
|
|
||||||
|
|
||||||
|
|
||||||
def test_many_to_one_single_channel_proportional_mixing_uses_dis_vols_per_source():
|
|
||||||
lh = FakeLiquidHandler(channel_num=1)
|
|
||||||
lh.current_tip = iter(make_tip_iter(128))
|
|
||||||
|
|
||||||
sources = [DummyContainer(f"S{i}") for i in range(3)]
|
|
||||||
target = DummyContainer("T")
|
|
||||||
asp_vols = [5, 6, 7]
|
|
||||||
dis_vols = [1, 2, 3]
|
|
||||||
|
|
||||||
run(
|
|
||||||
lh.transfer_liquid(
|
|
||||||
sources=sources,
|
|
||||||
targets=[target],
|
|
||||||
tip_racks=[],
|
|
||||||
use_channels=[0],
|
|
||||||
asp_vols=asp_vols,
|
|
||||||
dis_vols=dis_vols, # 比例模式
|
|
||||||
mix_times=0,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
dispenses = [payload for name, payload in lh.calls if name == "dispense"]
|
|
||||||
assert [d["vols"][0] for d in dispenses] == [float(v) for v in dis_vols]
|
|
||||||
|
|
||||||
|
|
||||||
def test_many_to_one_eight_channel_basic():
|
|
||||||
lh = FakeLiquidHandler(channel_num=8)
|
|
||||||
lh.current_tip = iter(make_tip_iter(256))
|
|
||||||
|
|
||||||
sources = [DummyContainer(f"S{i}") for i in range(8)]
|
|
||||||
target = DummyContainer("T")
|
|
||||||
asp_vols = [10 + i for i in range(8)]
|
|
||||||
|
|
||||||
run(
|
|
||||||
lh.transfer_liquid(
|
|
||||||
sources=sources,
|
|
||||||
targets=[target],
|
|
||||||
tip_racks=[],
|
|
||||||
use_channels=list(range(8)),
|
|
||||||
asp_vols=asp_vols,
|
|
||||||
dis_vols=999, # 非比例模式下每通道分液=对应 asp_vol
|
|
||||||
mix_times=0,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
aspirates = [payload for name, payload in lh.calls if name == "aspirate"]
|
|
||||||
dispenses = [payload for name, payload in lh.calls if name == "dispense"]
|
|
||||||
assert aspirates[0]["resources"] == sources
|
|
||||||
assert aspirates[0]["vols"] == [float(v) for v in asp_vols]
|
|
||||||
assert dispenses[0]["resources"] == [target] * 8
|
|
||||||
assert dispenses[0]["vols"] == [float(v) for v in asp_vols]
|
|
||||||
|
|
||||||
|
|
||||||
def test_transfer_liquid_mode_detection_unsupported_shape_raises():
|
|
||||||
lh = FakeLiquidHandler(channel_num=8)
|
|
||||||
lh.current_tip = iter(make_tip_iter(64))
|
|
||||||
|
|
||||||
sources = [DummyContainer("S0"), DummyContainer("S1")]
|
|
||||||
targets = [DummyContainer("T0"), DummyContainer("T1"), DummyContainer("T2")]
|
|
||||||
|
|
||||||
with pytest.raises(ValueError, match="Unsupported transfer mode"):
|
|
||||||
run(
|
|
||||||
lh.transfer_liquid(
|
|
||||||
sources=sources,
|
|
||||||
targets=targets,
|
|
||||||
tip_racks=[],
|
|
||||||
use_channels=[0],
|
|
||||||
asp_vols=[1, 1],
|
|
||||||
dis_vols=[1, 1, 1],
|
|
||||||
mix_times=0,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_mix_single_target_produces_matching_cycles():
|
|
||||||
lh = FakeLiquidHandler(channel_num=1)
|
|
||||||
target = DummyContainer("T_mix")
|
|
||||||
|
|
||||||
run(lh.mix(targets=[target], mix_time=2, mix_vol=5))
|
|
||||||
|
|
||||||
aspirates = [payload for name, payload in lh.calls if name == "aspirate"]
|
|
||||||
dispenses = [payload for name, payload in lh.calls if name == "dispense"]
|
|
||||||
assert len(aspirates) == len(dispenses) == 2
|
|
||||||
assert all(call["resources"] == [target] for call in aspirates)
|
|
||||||
assert all(call["vols"] == [5] for call in aspirates)
|
|
||||||
assert all(call["resources"] == [target] for call in dispenses)
|
|
||||||
assert all(call["vols"] == [5] for call in dispenses)
|
|
||||||
|
|
||||||
|
|
||||||
def test_mix_multiple_targets_supports_per_target_offsets():
|
|
||||||
lh = FakeLiquidHandler(channel_num=1)
|
|
||||||
targets = [DummyContainer("T0"), DummyContainer("T1")]
|
|
||||||
offsets = ["left", "right"]
|
|
||||||
heights = [0.1, 0.2]
|
|
||||||
rates = [0.5, 1.0]
|
|
||||||
|
|
||||||
run(
|
|
||||||
lh.mix(
|
|
||||||
targets=targets,
|
|
||||||
mix_time=1,
|
|
||||||
mix_vol=3,
|
|
||||||
offsets=offsets,
|
|
||||||
height_to_bottom=heights,
|
|
||||||
mix_rate=rates,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
aspirates = [payload for name, payload in lh.calls if name == "aspirate"]
|
|
||||||
assert len(aspirates) == 2
|
|
||||||
assert aspirates[0]["resources"] == [targets[0]]
|
|
||||||
assert aspirates[0]["offsets"] == [offsets[0]]
|
|
||||||
assert aspirates[0]["liquid_height"] == [heights[0]]
|
|
||||||
assert aspirates[0]["flow_rates"] == [rates[0]]
|
|
||||||
assert aspirates[1]["resources"] == [targets[1]]
|
|
||||||
assert aspirates[1]["offsets"] == [offsets[1]]
|
|
||||||
assert aspirates[1]["liquid_height"] == [heights[1]]
|
|
||||||
assert aspirates[1]["flow_rates"] == [rates[1]]
|
|
||||||
|
|
||||||
|
|
||||||
def test_set_tiprack_per_type_resumes_first_physical_rack():
|
|
||||||
"""同型号多次 set_tiprack 时接续第一盒剩余孔位,而非从新盒 A1 开始。"""
|
|
||||||
from pylabrobot.liquid_handling import LiquidHandlerChatterboxBackend
|
|
||||||
from pylabrobot.resources import Deck, Tip, TipRack, TipSpot, create_equally_spaced
|
|
||||||
|
|
||||||
mk = lambda: Tip(
|
|
||||||
has_filter=False, total_tip_length=10.0, maximal_volume=300.0, fitting_depth=2.0
|
|
||||||
)
|
|
||||||
|
|
||||||
class TipTypeAlpha(TipRack):
|
|
||||||
pass
|
|
||||||
|
|
||||||
class TipTypeBeta(TipRack):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def make_rack(cls: type, name: str) -> TipRack:
|
|
||||||
items = create_equally_spaced(
|
|
||||||
TipSpot,
|
|
||||||
num_items_x=12,
|
|
||||||
num_items_y=2,
|
|
||||||
dx=0,
|
|
||||||
dy=0,
|
|
||||||
dz=0,
|
|
||||||
item_dx=9,
|
|
||||||
item_dy=9,
|
|
||||||
size_x=1,
|
|
||||||
size_y=1,
|
|
||||||
make_tip=mk,
|
|
||||||
)
|
|
||||||
return cls(name, 120, 40, 10, items=items)
|
|
||||||
|
|
||||||
rack1 = make_rack(TipTypeAlpha, "rack_phys_1")
|
|
||||||
rack2 = make_rack(TipTypeBeta, "rack_phys_2")
|
|
||||||
rack3 = make_rack(TipTypeAlpha, "rack_phys_3")
|
|
||||||
|
|
||||||
lh = LiquidHandlerAbstract(
|
|
||||||
LiquidHandlerChatterboxBackend(1), Deck(), channel_num=1, simulator=False
|
|
||||||
)
|
|
||||||
flat1 = lh._flatten_tips_from_one(rack1)
|
|
||||||
assert len(flat1) == 24
|
|
||||||
|
|
||||||
lh.set_tiprack([rack1])
|
|
||||||
for i in range(12):
|
|
||||||
assert lh._get_next_tip() is flat1[i]
|
|
||||||
|
|
||||||
lh.set_tiprack([rack2])
|
|
||||||
spot_b = lh._get_next_tip()
|
|
||||||
assert "rack_phys_2" in spot_b.name
|
|
||||||
|
|
||||||
lh.set_tiprack([rack3])
|
|
||||||
spot_resume = lh._get_next_tip()
|
|
||||||
assert spot_resume is flat1[12], "第三次同型号应接续 rack1 第二行首孔,而非 rack3 首孔"
|
|
||||||
assert spot_resume is not lh._flatten_tips_from_one(rack3)[0]
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,137 +0,0 @@
|
|||||||
"""P9 — ``_augment_states_with_liquid_history`` 单元测试(OS→Cloud sync 链路 Phase C)。
|
|
||||||
|
|
||||||
详见 ``product_designs/protocol_convert/09-liquid-history-unknown-debug.md`` §6.3 / §8 T4。
|
|
||||||
"""
|
|
||||||
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
from dataclasses import dataclass, field
|
|
||||||
from typing import Any, Dict, List
|
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
from unilabos.resources.resource_tracker import _augment_states_with_liquid_history
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
# Fixtures:纯 dataclass 模拟 PLR 资源树(避免引入 PLR 真实实例化)
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class FakeTracker:
|
|
||||||
liquid_history: Any = field(default_factory=list)
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class FakeResource:
|
|
||||||
name: str
|
|
||||||
tracker: Any = None
|
|
||||||
children: List["FakeResource"] = field(default_factory=list)
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
# Tests
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
class TestAugmentStatesWithLiquidHistory:
|
|
||||||
def test_single_well_history_attached(self) -> None:
|
|
||||||
well = FakeResource("well_A1", tracker=FakeTracker(liquid_history=[
|
|
||||||
{"name": "Plasma", "volume": 100, "action": "set"}
|
|
||||||
]))
|
|
||||||
states: Dict[str, Any] = {"well_A1": {"liquids": [], "pending_liquids": []}}
|
|
||||||
|
|
||||||
_augment_states_with_liquid_history(well, states)
|
|
||||||
|
|
||||||
assert "liquid_history" in states["well_A1"]
|
|
||||||
assert states["well_A1"]["liquid_history"] == [
|
|
||||||
{"name": "Plasma", "volume": 100, "action": "set"}
|
|
||||||
]
|
|
||||||
|
|
||||||
def test_recursive_walk_attaches_to_all_wells(self) -> None:
|
|
||||||
"""resource 树有多层时,每个有 tracker 的节点都会被并入 states。"""
|
|
||||||
wells = [
|
|
||||||
FakeResource(f"well_{i}", tracker=FakeTracker(liquid_history=[
|
|
||||||
{"name": f"L_{i}", "volume": i * 10, "action": "set"}
|
|
||||||
]))
|
|
||||||
for i in range(3)
|
|
||||||
]
|
|
||||||
plate = FakeResource("plate", children=wells)
|
|
||||||
deck = FakeResource("deck", children=[plate])
|
|
||||||
states: Dict[str, Any] = {
|
|
||||||
"deck": {"liquids": []},
|
|
||||||
"plate": {"liquids": []},
|
|
||||||
"well_0": {"liquids": []},
|
|
||||||
"well_1": {"liquids": []},
|
|
||||||
"well_2": {"liquids": []},
|
|
||||||
}
|
|
||||||
|
|
||||||
_augment_states_with_liquid_history(deck, states)
|
|
||||||
|
|
||||||
assert states["well_0"]["liquid_history"] == [{"name": "L_0", "volume": 0, "action": "set"}]
|
|
||||||
assert states["well_1"]["liquid_history"] == [{"name": "L_1", "volume": 10, "action": "set"}]
|
|
||||||
assert states["well_2"]["liquid_history"] == [{"name": "L_2", "volume": 20, "action": "set"}]
|
|
||||||
|
|
||||||
def test_no_tracker_node_skipped(self) -> None:
|
|
||||||
"""没有 tracker 的节点(如 deck 自身)跳过,state dict 不被污染。"""
|
|
||||||
deck = FakeResource("deck") # tracker=None
|
|
||||||
states: Dict[str, Any] = {"deck": {"some_field": 1}}
|
|
||||||
|
|
||||||
_augment_states_with_liquid_history(deck, states)
|
|
||||||
|
|
||||||
assert "liquid_history" not in states["deck"]
|
|
||||||
|
|
||||||
def test_existing_liquid_history_in_state_not_overwritten(self) -> None:
|
|
||||||
"""state 已经有 liquid_history 字段(例如 PLR 升级未来支持了)→ 不覆盖。"""
|
|
||||||
well = FakeResource("well_A1", tracker=FakeTracker(liquid_history=[
|
|
||||||
{"name": "Plasma", "volume": 100, "action": "set"}
|
|
||||||
]))
|
|
||||||
states: Dict[str, Any] = {"well_A1": {"liquid_history": ["preexisting"]}}
|
|
||||||
|
|
||||||
_augment_states_with_liquid_history(well, states)
|
|
||||||
|
|
||||||
assert states["well_A1"]["liquid_history"] == ["preexisting"]
|
|
||||||
|
|
||||||
def test_history_is_shallow_copied(self) -> None:
|
|
||||||
"""augment 后的 history 应是独立 list(避免运行时 mutate 污染 dump 结果)。"""
|
|
||||||
original_history = [{"name": "X", "volume": 1, "action": "set"}]
|
|
||||||
well = FakeResource("well_A1", tracker=FakeTracker(liquid_history=original_history))
|
|
||||||
states: Dict[str, Any] = {"well_A1": {}}
|
|
||||||
|
|
||||||
_augment_states_with_liquid_history(well, states)
|
|
||||||
|
|
||||||
# mutate runtime history 不应反映到 augmented state
|
|
||||||
original_history.append({"name": "Y", "volume": 2, "action": "set"})
|
|
||||||
assert len(states["well_A1"]["liquid_history"]) == 1
|
|
||||||
|
|
||||||
def test_node_not_in_states_silently_skipped(self) -> None:
|
|
||||||
"""resource 树中的节点 name 不在 ``states`` 字典里 → 静默跳过。"""
|
|
||||||
well = FakeResource("well_orphan", tracker=FakeTracker(liquid_history=[
|
|
||||||
{"name": "X", "volume": 1, "action": "set"}
|
|
||||||
]))
|
|
||||||
states: Dict[str, Any] = {"well_A1": {}}
|
|
||||||
|
|
||||||
_augment_states_with_liquid_history(well, states)
|
|
||||||
|
|
||||||
# 不应该新增 well_orphan 键,也不应污染 well_A1
|
|
||||||
assert "well_orphan" not in states
|
|
||||||
assert "liquid_history" not in states["well_A1"]
|
|
||||||
|
|
||||||
def test_non_list_liquid_history_skipped(self) -> None:
|
|
||||||
"""tracker.liquid_history 非 list 时(异常情况)→ 跳过,不写入 state。"""
|
|
||||||
well = FakeResource("well_A1", tracker=FakeTracker(liquid_history="broken"))
|
|
||||||
states: Dict[str, Any] = {"well_A1": {}}
|
|
||||||
|
|
||||||
_augment_states_with_liquid_history(well, states)
|
|
||||||
|
|
||||||
assert "liquid_history" not in states["well_A1"]
|
|
||||||
|
|
||||||
def test_empty_history_still_written(self) -> None:
|
|
||||||
"""tracker.liquid_history = [] 是合法状态 → 应写入空 list(表示"未有任何液体操作")。"""
|
|
||||||
well = FakeResource("well_A1", tracker=FakeTracker(liquid_history=[]))
|
|
||||||
states: Dict[str, Any] = {"well_A1": {}}
|
|
||||||
|
|
||||||
_augment_states_with_liquid_history(well, states)
|
|
||||||
|
|
||||||
assert states["well_A1"]["liquid_history"] == []
|
|
||||||
@@ -1,351 +0,0 @@
|
|||||||
"""P6.1 / P6.1.1 `build_protocol_graph` 集成测试 —— 对应 06-labware-mapping-table.md §11.7.7 C / §11.8.7 C。
|
|
||||||
|
|
||||||
6 条用例:
|
|
||||||
|
|
||||||
- `test_build_graph_default_target_device_prcxi` —— 不传 target_device 时默认 "prcxi",
|
|
||||||
与 P6 等价(PRCXI_* class_name)。
|
|
||||||
- `test_build_graph_explicit_target_device_prcxi` —— 显式 "prcxi" 与默认完全等价。
|
|
||||||
- `test_build_graph_target_device_unknown_falls_back_to_default_section` —— 未声明的
|
|
||||||
target_device 由 loader 自动 fallback 到 ``target_devices.default``;第一版 default
|
|
||||||
段按 prcxi 拷贝,所以结果应与 "prcxi" 完全一致。
|
|
||||||
- `test_build_graph_per_device_tip_class` —— 临时 YAML 同时声明 prcxi 与 beckman tip
|
|
||||||
量程档;同一 transfer_liquid 在 target_device="prcxi" / "beckman" 下命中不同 class。
|
|
||||||
- `test_field_renamed_target_class_name` —— `labware_info` 写入的字段是
|
|
||||||
`target_class_name`,**旧字段 `prcxi_class_name` 不存在**。
|
|
||||||
- `test_build_graph_model_level_slot_remap` —— P6.1.1:``target_model`` 透传到
|
|
||||||
``_map_deck_slot`` 后改变 create_resource 的 slot(同厂商不同型号 deck 物理布局不同)。
|
|
||||||
|
|
||||||
本测试在导入 common.py 之前 mock 掉 matplotlib / networkx.drawing.nx_agraph,避免在
|
|
||||||
没有图形依赖的最小 Python 环境下也能跑(与 P6 批量回归脚本同样的策略)。
|
|
||||||
"""
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import sys
|
|
||||||
import types
|
|
||||||
import warnings
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
ROOT_DIR = Path(__file__).resolve().parents[2]
|
|
||||||
if str(ROOT_DIR) not in sys.path:
|
|
||||||
sys.path.insert(0, str(ROOT_DIR))
|
|
||||||
|
|
||||||
|
|
||||||
def _install_fake_optional_deps() -> None:
|
|
||||||
"""安装 matplotlib / networkx.drawing.nx_agraph 的 fake 实现,避免本地环境硬依赖。
|
|
||||||
|
|
||||||
common.py 在模块级 import 这些库做可视化辅助;build_protocol_graph 主路径不会真用到。
|
|
||||||
fake 模块只需要满足 ``from X import Y`` 的查找即可。
|
|
||||||
"""
|
|
||||||
if "matplotlib" not in sys.modules:
|
|
||||||
fake_matplotlib = types.ModuleType("matplotlib")
|
|
||||||
sys.modules["matplotlib"] = fake_matplotlib
|
|
||||||
if "matplotlib.pyplot" not in sys.modules:
|
|
||||||
fake_plt = types.ModuleType("matplotlib.pyplot")
|
|
||||||
sys.modules["matplotlib.pyplot"] = fake_plt
|
|
||||||
# networkx.drawing.nx_agraph.to_agraph 依赖 pygraphviz;不可用时给个空 stub
|
|
||||||
try:
|
|
||||||
from networkx.drawing import nx_agraph # noqa: F401
|
|
||||||
except Exception:
|
|
||||||
nx_drawing = types.ModuleType("networkx.drawing")
|
|
||||||
nx_agraph_mod = types.ModuleType("networkx.drawing.nx_agraph")
|
|
||||||
|
|
||||||
def _to_agraph(_g): # type: ignore[no-untyped-def]
|
|
||||||
raise RuntimeError("nx_agraph fake — not used in build_protocol_graph main path")
|
|
||||||
|
|
||||||
nx_agraph_mod.to_agraph = _to_agraph # type: ignore[attr-defined]
|
|
||||||
nx_drawing.nx_agraph = nx_agraph_mod # type: ignore[attr-defined]
|
|
||||||
sys.modules["networkx.drawing"] = nx_drawing
|
|
||||||
sys.modules["networkx.drawing.nx_agraph"] = nx_agraph_mod
|
|
||||||
|
|
||||||
|
|
||||||
_install_fake_optional_deps()
|
|
||||||
|
|
||||||
from unilabos.workflow import labware_mapping as lm # noqa: E402
|
|
||||||
from unilabos.workflow.common import build_protocol_graph # noqa: E402
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
|
||||||
def _reset_mapping_cache():
|
|
||||||
"""每个用例后清 lru_cache,避免跨用例污染。"""
|
|
||||||
yield
|
|
||||||
lm.reload_mapping()
|
|
||||||
|
|
||||||
|
|
||||||
# ==================== 公共 fixture:最小 transfer_liquid 协议 ====================
|
|
||||||
|
|
||||||
|
|
||||||
def _minimal_labware_info() -> dict:
|
|
||||||
"""返回最小可用的 labware_info(mutable,每个 case 独立 build 一份)。
|
|
||||||
|
|
||||||
包含 tip rack + 24-tube rack + 96 wellplate(slot 1/2/3),覆盖 P6.1 主要 kind。
|
|
||||||
tube rack / plate 显式声明 ``num_wells``,避免在无 labware_defs / 无 prcxi_labware 模板
|
|
||||||
时通过 well-count 启发式(well_n=3)误判孔数;与真实协议中 labware_defs 提供 num_wells
|
|
||||||
的行为对齐。
|
|
||||||
"""
|
|
||||||
return {
|
|
||||||
"tips": {
|
|
||||||
"slot": 1,
|
|
||||||
"well": [],
|
|
||||||
"labware": "opentrons_96_tiprack_300ul",
|
|
||||||
"object": "tiprack",
|
|
||||||
},
|
|
||||||
"samples": {
|
|
||||||
"slot": 2,
|
|
||||||
"well": ["A1", "A2", "A3"],
|
|
||||||
"labware": "opentrons_24_tuberack_eppendorf_2ml_safelock_snapcap",
|
|
||||||
"object": "source",
|
|
||||||
"num_wells": 24,
|
|
||||||
},
|
|
||||||
"plate_target": {
|
|
||||||
"slot": 3,
|
|
||||||
"well": ["A1", "A2", "A3"],
|
|
||||||
"labware": "opentrons_96_wellplate_300ul_pcr",
|
|
||||||
"object": "target",
|
|
||||||
"num_wells": 96,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def _minimal_protocol_steps() -> list:
|
|
||||||
"""最小 transfer_liquid 协议步骤:asp_vols/dis_vols 最大 200 µL → PRCXI 300ul 档。"""
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
"action": "transfer_liquid",
|
|
||||||
"parameters": {
|
|
||||||
"sources": "samples",
|
|
||||||
"targets": "plate_target",
|
|
||||||
"tip_racks": "tips",
|
|
||||||
"asp_vols": [200.0, 200.0, 200.0],
|
|
||||||
"dis_vols": [200.0, 200.0, 200.0],
|
|
||||||
},
|
|
||||||
"step_number": 1,
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def _collect_create_resource_classes(graph) -> dict:
|
|
||||||
"""从工作流图中提取每个 create_resource 节点的 ``slot_on_deck → class_name``。"""
|
|
||||||
out: dict = {}
|
|
||||||
for _nid, node in graph.nodes.items():
|
|
||||||
if node.get("template_name") != "create_resource":
|
|
||||||
continue
|
|
||||||
param = node.get("param") or {}
|
|
||||||
slot = str(param.get("slot_on_deck") or "")
|
|
||||||
cls = str(param.get("class_name") or "")
|
|
||||||
if slot:
|
|
||||||
out[slot] = cls
|
|
||||||
return out
|
|
||||||
|
|
||||||
|
|
||||||
# ==================== 5 条核心用例 ====================
|
|
||||||
|
|
||||||
|
|
||||||
def test_build_graph_default_target_device_prcxi():
|
|
||||||
"""不传 target_device → 默认 "prcxi" → 与 P6 等价(PRCXI_* class_name)。"""
|
|
||||||
labware_info = _minimal_labware_info()
|
|
||||||
g = build_protocol_graph(
|
|
||||||
labware_info=labware_info,
|
|
||||||
protocol_steps=_minimal_protocol_steps(),
|
|
||||||
workstation_name="PRCXI",
|
|
||||||
)
|
|
||||||
classes = _collect_create_resource_classes(g)
|
|
||||||
assert classes["1"] == "PRCXI_300ul_Tips" # 200 µL → 300 档
|
|
||||||
assert classes["2"] == "PRCXI_EP_Adapter" # 24-tube rack
|
|
||||||
assert classes["3"] == "PRCXI_BioER_96_wellplate" # 96 wellplate
|
|
||||||
|
|
||||||
|
|
||||||
def test_build_graph_explicit_target_device_prcxi():
|
|
||||||
"""显式传 target_device="prcxi" 应与默认完全等价。"""
|
|
||||||
labware_info_a = _minimal_labware_info()
|
|
||||||
labware_info_b = _minimal_labware_info()
|
|
||||||
g_default = build_protocol_graph(
|
|
||||||
labware_info=labware_info_a,
|
|
||||||
protocol_steps=_minimal_protocol_steps(),
|
|
||||||
workstation_name="PRCXI",
|
|
||||||
)
|
|
||||||
g_prcxi = build_protocol_graph(
|
|
||||||
labware_info=labware_info_b,
|
|
||||||
protocol_steps=_minimal_protocol_steps(),
|
|
||||||
workstation_name="PRCXI",
|
|
||||||
target_device="prcxi",
|
|
||||||
)
|
|
||||||
assert _collect_create_resource_classes(g_default) == _collect_create_resource_classes(g_prcxi)
|
|
||||||
|
|
||||||
|
|
||||||
def test_build_graph_target_device_unknown_falls_back_to_default_section():
|
|
||||||
"""未声明的 target_device → loader 自动 fallback 到固定段 target_devices.default + warning。
|
|
||||||
|
|
||||||
第一版 default 段按 prcxi 拷贝填充 → 结果应与 target_device="prcxi" 完全等价(PRCXI_*)。
|
|
||||||
"""
|
|
||||||
labware_info_a = _minimal_labware_info()
|
|
||||||
labware_info_b = _minimal_labware_info()
|
|
||||||
g_prcxi = build_protocol_graph(
|
|
||||||
labware_info=labware_info_a,
|
|
||||||
protocol_steps=_minimal_protocol_steps(),
|
|
||||||
workstation_name="PRCXI",
|
|
||||||
target_device="prcxi",
|
|
||||||
)
|
|
||||||
with warnings.catch_warnings(record=True) as caught:
|
|
||||||
warnings.simplefilter("always")
|
|
||||||
g_unknown = build_protocol_graph(
|
|
||||||
labware_info=labware_info_b,
|
|
||||||
protocol_steps=_minimal_protocol_steps(),
|
|
||||||
workstation_name="PRCXI",
|
|
||||||
target_device="unknown_xxx",
|
|
||||||
)
|
|
||||||
assert _collect_create_resource_classes(g_unknown) == _collect_create_resource_classes(g_prcxi)
|
|
||||||
# loader 至少打 1 次 warning 提示「未声明、已回退到 default」
|
|
||||||
assert any(
|
|
||||||
("未在 labware_mapping.yaml" in str(w.message))
|
|
||||||
or ("target_devices.default" in str(w.message))
|
|
||||||
for w in caught
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_build_graph_per_device_tip_class(tmp_path, monkeypatch):
|
|
||||||
"""同一 protocol,target_device="prcxi" / "beckman" 在 200µL 下命中不同 tip 档(P6.1.1 schema)。"""
|
|
||||||
yaml_path = tmp_path / "labware_mapping.yaml"
|
|
||||||
yaml_path.write_text(
|
|
||||||
'kinds:\n'
|
|
||||||
' - {pattern: "trash", kind: trash}\n'
|
|
||||||
' - {pattern: "tiprack|tip[_ ]?rack|opentrons_\\\\d+_tiprack", kind: tip_rack}\n'
|
|
||||||
' - {pattern: "tuberack|tube[_ ]rack|eppendorf.*rack|safelock.*rack", kind: tube_rack}\n'
|
|
||||||
' - {pattern: ".*", kind: plate}\n'
|
|
||||||
'target_devices:\n'
|
|
||||||
' default:\n'
|
|
||||||
' slot_remap: {default: {"4": "13", "8": "14"}, by_object: {trash: {"12": "16"}}}\n'
|
|
||||||
' rules:\n'
|
|
||||||
' - {kind: tip_rack, hole_count: 96, volume_max: 10, class_name: PRCXI_10uL_Tips}\n'
|
|
||||||
' - {kind: tip_rack, hole_count: 96, volume_max: 299.9, class_name: PRCXI_300ul_Tips}\n'
|
|
||||||
' - {kind: tip_rack, hole_count: 96, class_name: PRCXI_1000uL_Tips}\n'
|
|
||||||
' - {kind: tube_rack, hole_count: 24, class_name: PRCXI_EP_Adapter}\n'
|
|
||||||
' - {kind: plate, hole_count: 96, class_name: PRCXI_BioER_96_wellplate}\n'
|
|
||||||
' prcxi:\n'
|
|
||||||
' slot_remap: {default: {"4": "13", "8": "14"}, by_object: {trash: {"12": "16"}}}\n'
|
|
||||||
' rules:\n'
|
|
||||||
' - {kind: tip_rack, hole_count: 96, volume_max: 10, class_name: PRCXI_10uL_Tips}\n'
|
|
||||||
' - {kind: tip_rack, hole_count: 96, volume_max: 299.9, class_name: PRCXI_300ul_Tips}\n'
|
|
||||||
' - {kind: tip_rack, hole_count: 96, class_name: PRCXI_1000uL_Tips}\n'
|
|
||||||
' - {kind: tube_rack, hole_count: 24, class_name: PRCXI_EP_Adapter}\n'
|
|
||||||
' - {kind: plate, hole_count: 96, class_name: PRCXI_BioER_96_wellplate}\n'
|
|
||||||
' beckman:\n'
|
|
||||||
' slot_remap: {default: {"4": "13"}, by_object: {trash: {"12": "16"}}}\n'
|
|
||||||
' rules:\n'
|
|
||||||
' - {kind: tip_rack, hole_count: 96, volume_max: 20, class_name: Beckman_20uL_Tips}\n'
|
|
||||||
' - {kind: tip_rack, hole_count: 96, volume_max: 199.9, class_name: Beckman_200uL_Tips}\n'
|
|
||||||
' - {kind: tip_rack, hole_count: 96, class_name: Beckman_1000uL_Tips}\n'
|
|
||||||
' - {kind: tube_rack, hole_count: 24, class_name: Beckman_24_TubeRack}\n'
|
|
||||||
' - {kind: plate, hole_count: 96, class_name: Beckman_BioMek_96_wellplate}\n',
|
|
||||||
encoding="utf-8",
|
|
||||||
)
|
|
||||||
monkeypatch.setattr(lm, "_DEFAULT_PATH", yaml_path)
|
|
||||||
lm.reload_mapping()
|
|
||||||
|
|
||||||
g_prcxi = build_protocol_graph(
|
|
||||||
labware_info=_minimal_labware_info(),
|
|
||||||
protocol_steps=_minimal_protocol_steps(),
|
|
||||||
workstation_name="PRCXI",
|
|
||||||
target_device="prcxi",
|
|
||||||
)
|
|
||||||
g_beckman = build_protocol_graph(
|
|
||||||
labware_info=_minimal_labware_info(),
|
|
||||||
protocol_steps=_minimal_protocol_steps(),
|
|
||||||
workstation_name="PRCXI",
|
|
||||||
target_device="beckman",
|
|
||||||
)
|
|
||||||
|
|
||||||
classes_prcxi = _collect_create_resource_classes(g_prcxi)
|
|
||||||
classes_beckman = _collect_create_resource_classes(g_beckman)
|
|
||||||
|
|
||||||
# 200 µL:prcxi 走 300 档;beckman 200 档已超 → 1000 档
|
|
||||||
assert classes_prcxi["1"] == "PRCXI_300ul_Tips"
|
|
||||||
assert classes_beckman["1"] == "Beckman_1000uL_Tips"
|
|
||||||
# plate / tube rack 也按 target_device 输出对应厂商类
|
|
||||||
assert classes_prcxi["2"] == "PRCXI_EP_Adapter"
|
|
||||||
assert classes_beckman["2"] == "Beckman_24_TubeRack"
|
|
||||||
assert classes_prcxi["3"] == "PRCXI_BioER_96_wellplate"
|
|
||||||
assert classes_beckman["3"] == "Beckman_BioMek_96_wellplate"
|
|
||||||
|
|
||||||
|
|
||||||
def test_field_renamed_target_class_name():
|
|
||||||
"""`labware_info` 写入的字段是 `target_class_name`;旧字段 `prcxi_class_name` 不存在。"""
|
|
||||||
labware_info = _minimal_labware_info()
|
|
||||||
build_protocol_graph(
|
|
||||||
labware_info=labware_info,
|
|
||||||
protocol_steps=_minimal_protocol_steps(),
|
|
||||||
workstation_name="PRCXI",
|
|
||||||
)
|
|
||||||
for lid, item in labware_info.items():
|
|
||||||
assert "target_class_name" in item, f"{lid!r} 缺少 target_class_name 字段"
|
|
||||||
assert "prcxi_class_name" not in item, f"{lid!r} 残留了旧字段 prcxi_class_name"
|
|
||||||
assert item["target_class_name"], f"{lid!r} target_class_name 为空"
|
|
||||||
|
|
||||||
|
|
||||||
# ==================== P6.1.1 新增集成测试 ====================
|
|
||||||
|
|
||||||
|
|
||||||
def _labware_info_slot4_plate() -> dict:
|
|
||||||
"""slot=4 的 96 板:用来验证 target_model 透传后 slot_remap 改变 create_resource 的槽位。"""
|
|
||||||
return {
|
|
||||||
"plate_slot4": {
|
|
||||||
"slot": 4,
|
|
||||||
"well": ["A1"],
|
|
||||||
"labware": "opentrons_96_wellplate_300ul_pcr",
|
|
||||||
"object": "target",
|
|
||||||
"num_wells": 96,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def test_build_graph_model_level_slot_remap(tmp_path, monkeypatch):
|
|
||||||
"""P6.1.1:target_model 透传到 _map_deck_slot 后改变 create_resource 的 slot_on_deck。
|
|
||||||
|
|
||||||
YAML 中 prcxi 厂商级 slot_remap 4→13;模型 "4040" 显式覆盖 4→16。
|
|
||||||
同一份 labware_info(slot=4)build 出的两份图,slot_on_deck 应分别为 "13" 与 "16"。
|
|
||||||
"""
|
|
||||||
yaml_path = tmp_path / "labware_mapping.yaml"
|
|
||||||
yaml_path.write_text(
|
|
||||||
'kinds: [{pattern: ".*", kind: plate}]\n'
|
|
||||||
'target_devices:\n'
|
|
||||||
' default:\n'
|
|
||||||
' slot_remap: {default: {"4": "13"}, by_object: {}}\n'
|
|
||||||
' rules: [{kind: plate, hole_count: 96, class_name: PRCXI_BioER_96_wellplate}]\n'
|
|
||||||
' prcxi:\n'
|
|
||||||
' slot_remap: {default: {"4": "13"}, by_object: {}}\n'
|
|
||||||
' rules: [{kind: plate, hole_count: 96, class_name: PRCXI_BioER_96_wellplate}]\n'
|
|
||||||
' models:\n'
|
|
||||||
' "4040":\n'
|
|
||||||
' slot_remap: {default: {"4": "16"}, by_object: {}}\n',
|
|
||||||
encoding="utf-8",
|
|
||||||
)
|
|
||||||
monkeypatch.setattr(lm, "_DEFAULT_PATH", yaml_path)
|
|
||||||
lm.reload_mapping()
|
|
||||||
|
|
||||||
g_default = build_protocol_graph(
|
|
||||||
labware_info=_labware_info_slot4_plate(),
|
|
||||||
protocol_steps=[],
|
|
||||||
workstation_name="PRCXI",
|
|
||||||
target_device="prcxi",
|
|
||||||
)
|
|
||||||
g_model_4040 = build_protocol_graph(
|
|
||||||
labware_info=_labware_info_slot4_plate(),
|
|
||||||
protocol_steps=[],
|
|
||||||
workstation_name="PRCXI",
|
|
||||||
target_device="prcxi",
|
|
||||||
target_model="4040",
|
|
||||||
)
|
|
||||||
|
|
||||||
classes_default = _collect_create_resource_classes(g_default)
|
|
||||||
classes_4040 = _collect_create_resource_classes(g_model_4040)
|
|
||||||
|
|
||||||
# 厂商级(无 model)→ slot 4 → "13"
|
|
||||||
assert "13" in classes_default, f"未找到 slot 13,实际生成的 slots: {list(classes_default)}"
|
|
||||||
assert "16" not in classes_default
|
|
||||||
# 模型 4040 → slot 4 → "16"
|
|
||||||
assert "16" in classes_4040, f"未找到 slot 16,实际生成的 slots: {list(classes_4040)}"
|
|
||||||
assert "13" not in classes_4040
|
|
||||||
# class_name 不变(rules 继承厂商级)
|
|
||||||
assert classes_default["13"] == "PRCXI_BioER_96_wellplate"
|
|
||||||
assert classes_4040["16"] == "PRCXI_BioER_96_wellplate"
|
|
||||||
@@ -1,369 +0,0 @@
|
|||||||
"""P2 v2 跨 slot transfer_liquid 合并 —— Stage 3 (`workflow/common.py`) 集成测试。
|
|
||||||
|
|
||||||
对应 ``product_designs/protocol_convert/02-cross-slot-merge.md`` §9.5 step 6.2。
|
|
||||||
|
|
||||||
v2 设计要点(与本测试用例的映射)
|
|
||||||
-----------------------------------
|
|
||||||
当 transfer_liquid 节点 ``params.targets`` 是 ``list[str]`` 时,``build_protocol_graph``
|
|
||||||
在该 transfer_liquid 之前**插入一个 merged ``set_liquid_from_plate`` 节点**:
|
|
||||||
|
|
||||||
- merged 节点的 ``param.wells`` 是按 ``params.targets`` 顺序通过 cursor 拼出来的有序跨板
|
|
||||||
well refs(每个元素是 ``{id, name, parent: reagent_key, type: "well"}``)。
|
|
||||||
- merged 节点接收来自每个涉及 plate 的 ``create_resource`` 节点的多入边
|
|
||||||
(``labware`` → ``wells_identifier``)。
|
|
||||||
- merged 节点的 ``output_wells`` 通过**单条边**连到 transfer_liquid 的 ``targets_identifier``。
|
|
||||||
- transfer_liquid 节点的 ``params.targets`` 被改写为 synthetic key
|
|
||||||
``_merged_targets_<idx>``(runtime 不消费 list 形态),保证 INPUT_PORT_MAPPING 走单边路径。
|
|
||||||
|
|
||||||
用例
|
|
||||||
----
|
|
||||||
- ``test_emit_merged_set_liquid_basic`` — 4 个 distinct reagent_key(51b9a5 主场景)。
|
|
||||||
- ``test_emit_merged_set_liquid_repeat_key`` — 同 reagent_key 重复(同板多孔)。
|
|
||||||
- ``test_emit_merged_set_liquid_mixed`` — 跨板混合 + 同板重复(cursor 推进)。
|
|
||||||
- ``test_emit_merged_set_liquid_8ch`` — 与 P1 multi-channel 复合(8 通道 cross-slot)。
|
|
||||||
- ``test_transfer_liquid_targets_rewrite`` — transfer_liquid 节点改写后只剩 1 条
|
|
||||||
``targets_identifier`` 入边;params.targets 不再是 list。
|
|
||||||
"""
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import sys
|
|
||||||
import types
|
|
||||||
from pathlib import Path
|
|
||||||
from typing import Any, Dict, List
|
|
||||||
|
|
||||||
|
|
||||||
ROOT_DIR = Path(__file__).resolve().parents[2]
|
|
||||||
if str(ROOT_DIR) not in sys.path:
|
|
||||||
sys.path.insert(0, str(ROOT_DIR))
|
|
||||||
|
|
||||||
|
|
||||||
def _install_fake_optional_deps() -> None:
|
|
||||||
"""与 test_build_protocol_graph_target_device.py 一致的可选依赖 stub。"""
|
|
||||||
if "matplotlib" not in sys.modules:
|
|
||||||
sys.modules["matplotlib"] = types.ModuleType("matplotlib")
|
|
||||||
if "matplotlib.pyplot" not in sys.modules:
|
|
||||||
sys.modules["matplotlib.pyplot"] = types.ModuleType("matplotlib.pyplot")
|
|
||||||
try:
|
|
||||||
from networkx.drawing import nx_agraph # noqa: F401
|
|
||||||
except Exception:
|
|
||||||
nx_drawing = types.ModuleType("networkx.drawing")
|
|
||||||
nx_agraph_mod = types.ModuleType("networkx.drawing.nx_agraph")
|
|
||||||
nx_agraph_mod.to_agraph = lambda _g: None # type: ignore[attr-defined]
|
|
||||||
nx_drawing.nx_agraph = nx_agraph_mod # type: ignore[attr-defined]
|
|
||||||
sys.modules["networkx.drawing"] = nx_drawing
|
|
||||||
sys.modules["networkx.drawing.nx_agraph"] = nx_agraph_mod
|
|
||||||
|
|
||||||
|
|
||||||
_install_fake_optional_deps()
|
|
||||||
|
|
||||||
import pytest # noqa: E402
|
|
||||||
|
|
||||||
from unilabos.workflow.common import build_protocol_graph # noqa: E402
|
|
||||||
|
|
||||||
|
|
||||||
# ==================== 测试辅助:从工作流图中提取节点/边 ====================
|
|
||||||
|
|
||||||
|
|
||||||
def _nodes_by_template(graph, template_name: str) -> List[Dict[str, Any]]:
|
|
||||||
return [
|
|
||||||
{"id": nid, **node}
|
|
||||||
for nid, node in graph.nodes.items()
|
|
||||||
if node.get("template_name") == template_name
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def _create_resource_by_slot(graph) -> Dict[str, str]:
|
|
||||||
"""slot_on_deck (str) -> create_resource 节点 ID。"""
|
|
||||||
out: Dict[str, str] = {}
|
|
||||||
for nid, node in graph.nodes.items():
|
|
||||||
if node.get("template_name") == "create_resource":
|
|
||||||
slot = str(node.get("param", {}).get("slot_on_deck") or "")
|
|
||||||
if slot:
|
|
||||||
out[slot] = nid
|
|
||||||
return out
|
|
||||||
|
|
||||||
|
|
||||||
def _edges_to(graph, target_id: str) -> List[Dict[str, Any]]:
|
|
||||||
return [e for e in graph.edges if e["target"] == target_id]
|
|
||||||
|
|
||||||
|
|
||||||
def _edges_from(graph, source_id: str) -> List[Dict[str, Any]]:
|
|
||||||
return [e for e in graph.edges if e["source"] == source_id]
|
|
||||||
|
|
||||||
|
|
||||||
# ==================== fixture:构造跨板 labware + steps ====================
|
|
||||||
|
|
||||||
|
|
||||||
def _cross_slot_labware_info() -> Dict[str, Dict[str, Any]]:
|
|
||||||
"""51b9a5 简化:slot1 source + slot2/3/5/6 target plates + slot12 tip。"""
|
|
||||||
return {
|
|
||||||
"l1": {
|
|
||||||
"slot": 1,
|
|
||||||
"well": ["A1"],
|
|
||||||
"labware": "nest_12_reservoir_15ml",
|
|
||||||
"object": "source",
|
|
||||||
},
|
|
||||||
"plate_slot2": {
|
|
||||||
"slot": 2,
|
|
||||||
"well": ["A1"],
|
|
||||||
"labware": "nest_96_wellplate_2ml_deep",
|
|
||||||
"object": "target",
|
|
||||||
},
|
|
||||||
"plate_slot3": {
|
|
||||||
"slot": 3,
|
|
||||||
"well": ["A1"],
|
|
||||||
"labware": "nest_96_wellplate_2ml_deep",
|
|
||||||
"object": "target",
|
|
||||||
},
|
|
||||||
"plate_slot5": {
|
|
||||||
"slot": 5,
|
|
||||||
"well": ["A1"],
|
|
||||||
"labware": "nest_96_wellplate_2ml_deep",
|
|
||||||
"object": "target",
|
|
||||||
},
|
|
||||||
"plate_slot6": {
|
|
||||||
"slot": 6,
|
|
||||||
"well": ["A1"],
|
|
||||||
"labware": "nest_96_wellplate_2ml_deep",
|
|
||||||
"object": "target",
|
|
||||||
},
|
|
||||||
"tiprack_12": {
|
|
||||||
"slot": 12,
|
|
||||||
"well": [],
|
|
||||||
"labware": "opentrons_96_tiprack_300ul",
|
|
||||||
"object": "tiprack",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def _cross_slot_protocol_steps(targets: List[str], dis_vols: List[float]) -> List[Dict[str, Any]]:
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
"action": "transfer_liquid",
|
|
||||||
"parameters": {
|
|
||||||
"sources": "l1",
|
|
||||||
"targets": targets,
|
|
||||||
"tip_racks": "tiprack_12",
|
|
||||||
"asp_vols": dis_vols.copy(),
|
|
||||||
"dis_vols": dis_vols.copy(),
|
|
||||||
},
|
|
||||||
"step_number": 1,
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
# ==================== 用例 ====================
|
|
||||||
|
|
||||||
|
|
||||||
def test_emit_merged_set_liquid_basic():
|
|
||||||
"""51b9a5 主场景:targets=[A,B,C,D] → 1 merged set_liquid 节点
|
|
||||||
+ 4 条入边(来自 4 个 distinct create_resource)+ 1 条出边(去 transfer_liquid)。
|
|
||||||
"""
|
|
||||||
targets = ["plate_slot2", "plate_slot3", "plate_slot5", "plate_slot6"]
|
|
||||||
dis_vols = [8.3, 8.3, 8.3, 8.3]
|
|
||||||
g = build_protocol_graph(
|
|
||||||
labware_info=_cross_slot_labware_info(),
|
|
||||||
protocol_steps=_cross_slot_protocol_steps(targets, dis_vols),
|
|
||||||
workstation_name="PRCXI",
|
|
||||||
)
|
|
||||||
|
|
||||||
set_liquid_nodes = _nodes_by_template(g, "set_liquid_from_plate")
|
|
||||||
merged_nodes = [n for n in set_liquid_nodes if str(n.get("name", "")).startswith("_merged_targets_")]
|
|
||||||
assert len(merged_nodes) == 1, (
|
|
||||||
f"应有且仅有 1 个 merged set_liquid_from_plate 节点(v2 跨板聚合器);"
|
|
||||||
f" 实际找到 {len(merged_nodes)}: {[n.get('name') for n in merged_nodes]}"
|
|
||||||
)
|
|
||||||
merged = merged_nodes[0]
|
|
||||||
merged_id = merged["id"]
|
|
||||||
|
|
||||||
# param.wells:长度 4,每元素的 parent 是对应 reagent_key
|
|
||||||
wells = merged.get("param", {}).get("wells") or []
|
|
||||||
assert len(wells) == 4
|
|
||||||
assert [w["parent"] for w in wells] == targets, "merged.wells 顺序必须严格按 targets 列表"
|
|
||||||
# well 字段映射到 reagent.well[0](都是 "A1")
|
|
||||||
for w, key in zip(wells, targets):
|
|
||||||
assert w["id"].endswith("/A1"), f"well id 应包含 well 名: {w}"
|
|
||||||
assert w["parent"] == key
|
|
||||||
|
|
||||||
# 入边:4 条来自 distinct create_resource 节点(slot 2/3/5/6),target_port=wells_identifier
|
|
||||||
cr_by_slot = _create_resource_by_slot(g)
|
|
||||||
in_edges = _edges_to(g, merged_id)
|
|
||||||
in_sources = {e["source"] for e in in_edges if e.get("target_handle_key") == "wells_identifier"}
|
|
||||||
expected_sources = {cr_by_slot[s] for s in ("2", "3", "5", "6")}
|
|
||||||
assert in_sources == expected_sources, (
|
|
||||||
f"merged 节点应接收 4 个 distinct create_resource 的 wells_identifier 边;"
|
|
||||||
f" 实际 {in_sources} vs 期望 {expected_sources}"
|
|
||||||
)
|
|
||||||
|
|
||||||
# 出边:1 条到 transfer_liquid(targets_identifier)
|
|
||||||
transfer_nodes = _nodes_by_template(g, "transfer_liquid")
|
|
||||||
assert len(transfer_nodes) == 1
|
|
||||||
transfer_id = transfer_nodes[0]["id"]
|
|
||||||
out_to_transfer = [
|
|
||||||
e for e in _edges_from(g, merged_id)
|
|
||||||
if e["target"] == transfer_id and e.get("target_handle_key") == "targets_identifier"
|
|
||||||
]
|
|
||||||
assert len(out_to_transfer) == 1, (
|
|
||||||
f"merged 节点应向 transfer_liquid.targets_identifier 发出唯一 1 条边;"
|
|
||||||
f" 实际 {len(out_to_transfer)}"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_emit_merged_set_liquid_repeat_key():
|
|
||||||
"""同 reagent_key 重复(同板多孔):targets=[A,A,A] + reagent.A.well=[A1,A2,A3]
|
|
||||||
→ merged.wells 顺序 = [A/A1, A/A2, A/A3](cursor 推进取每个 well)。
|
|
||||||
"""
|
|
||||||
labware = _cross_slot_labware_info()
|
|
||||||
labware["plate_slot2"]["well"] = ["A1", "A2", "A3"]
|
|
||||||
|
|
||||||
targets = ["plate_slot2", "plate_slot2", "plate_slot2"]
|
|
||||||
dis_vols = [10.0, 20.0, 30.0]
|
|
||||||
g = build_protocol_graph(
|
|
||||||
labware_info=labware,
|
|
||||||
protocol_steps=_cross_slot_protocol_steps(targets, dis_vols),
|
|
||||||
workstation_name="PRCXI",
|
|
||||||
)
|
|
||||||
|
|
||||||
merged_nodes = [
|
|
||||||
n for n in _nodes_by_template(g, "set_liquid_from_plate")
|
|
||||||
if str(n.get("name", "")).startswith("_merged_targets_")
|
|
||||||
]
|
|
||||||
assert len(merged_nodes) == 1
|
|
||||||
wells = merged_nodes[0]["param"]["wells"]
|
|
||||||
assert [w["id"].rsplit("/", 1)[-1] for w in wells] == ["A1", "A2", "A3"], (
|
|
||||||
"cursor 应依次取 reagent.A.well[0/1/2]"
|
|
||||||
)
|
|
||||||
assert all(w["parent"] == "plate_slot2" for w in wells)
|
|
||||||
|
|
||||||
|
|
||||||
def test_emit_merged_set_liquid_mixed():
|
|
||||||
"""跨板 + 同板重复:targets=[A,B,A,C] + reagent.A.well=[A1,A2]
|
|
||||||
→ merged.wells = [A/A1, B/A1, A/A2, C/A1]。
|
|
||||||
"""
|
|
||||||
labware = _cross_slot_labware_info()
|
|
||||||
labware["plate_slot2"]["well"] = ["A1", "A2"]
|
|
||||||
|
|
||||||
targets = ["plate_slot2", "plate_slot3", "plate_slot2", "plate_slot5"]
|
|
||||||
dis_vols = [10.0, 20.0, 30.0, 40.0]
|
|
||||||
g = build_protocol_graph(
|
|
||||||
labware_info=labware,
|
|
||||||
protocol_steps=_cross_slot_protocol_steps(targets, dis_vols),
|
|
||||||
workstation_name="PRCXI",
|
|
||||||
)
|
|
||||||
|
|
||||||
merged_nodes = [
|
|
||||||
n for n in _nodes_by_template(g, "set_liquid_from_plate")
|
|
||||||
if str(n.get("name", "")).startswith("_merged_targets_")
|
|
||||||
]
|
|
||||||
assert len(merged_nodes) == 1
|
|
||||||
wells = merged_nodes[0]["param"]["wells"]
|
|
||||||
ids = [(w["parent"], w["id"].rsplit("/", 1)[-1]) for w in wells]
|
|
||||||
assert ids == [
|
|
||||||
("plate_slot2", "A1"),
|
|
||||||
("plate_slot3", "A1"),
|
|
||||||
("plate_slot2", "A2"),
|
|
||||||
("plate_slot5", "A1"),
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def test_emit_merged_set_liquid_8ch():
|
|
||||||
"""与 P1 multi-channel 复合:targets=[A]*8+[B]*8(每列 8 通道)。
|
|
||||||
|
|
||||||
merged.wells 长度 16,前 8 全 plate_slot2 的 8 个 well,后 8 全 plate_slot3 的 8 个 well。
|
|
||||||
"""
|
|
||||||
labware = _cross_slot_labware_info()
|
|
||||||
# 8 通道场景 reagent.well 已被 P1 multi 展开为长度 8
|
|
||||||
labware["plate_slot2"]["well"] = [f"{r}1" for r in "ABCDEFGH"]
|
|
||||||
labware["plate_slot3"]["well"] = [f"{r}1" for r in "ABCDEFGH"]
|
|
||||||
|
|
||||||
targets = ["plate_slot2"] * 8 + ["plate_slot3"] * 8
|
|
||||||
dis_vols = [5.0] * 16
|
|
||||||
g = build_protocol_graph(
|
|
||||||
labware_info=labware,
|
|
||||||
protocol_steps=_cross_slot_protocol_steps(targets, dis_vols),
|
|
||||||
workstation_name="PRCXI",
|
|
||||||
)
|
|
||||||
|
|
||||||
merged_nodes = [
|
|
||||||
n for n in _nodes_by_template(g, "set_liquid_from_plate")
|
|
||||||
if str(n.get("name", "")).startswith("_merged_targets_")
|
|
||||||
]
|
|
||||||
assert len(merged_nodes) == 1
|
|
||||||
wells = merged_nodes[0]["param"]["wells"]
|
|
||||||
assert len(wells) == 16
|
|
||||||
# 前 8 全 plate_slot2,后 8 全 plate_slot3(满足 cross-slot × 8ch 列对齐约束)
|
|
||||||
assert all(w["parent"] == "plate_slot2" for w in wells[:8])
|
|
||||||
assert all(w["parent"] == "plate_slot3" for w in wells[8:])
|
|
||||||
# well 名顺序:A1..H1 重复两遍
|
|
||||||
assert [w["id"].rsplit("/", 1)[-1] for w in wells[:8]] == [f"{r}1" for r in "ABCDEFGH"]
|
|
||||||
assert [w["id"].rsplit("/", 1)[-1] for w in wells[8:]] == [f"{r}1" for r in "ABCDEFGH"]
|
|
||||||
|
|
||||||
|
|
||||||
def test_transfer_liquid_targets_rewrite():
|
|
||||||
"""transfer_liquid 节点改写后只剩 1 条 targets_identifier 入边;params.targets 不再是 list。"""
|
|
||||||
targets = ["plate_slot2", "plate_slot3", "plate_slot5", "plate_slot6"]
|
|
||||||
dis_vols = [8.3, 8.3, 8.3, 8.3]
|
|
||||||
g = build_protocol_graph(
|
|
||||||
labware_info=_cross_slot_labware_info(),
|
|
||||||
protocol_steps=_cross_slot_protocol_steps(targets, dis_vols),
|
|
||||||
workstation_name="PRCXI",
|
|
||||||
)
|
|
||||||
|
|
||||||
transfer_nodes = _nodes_by_template(g, "transfer_liquid")
|
|
||||||
assert len(transfer_nodes) == 1
|
|
||||||
tnode = transfer_nodes[0]
|
|
||||||
transfer_id = tnode["id"]
|
|
||||||
|
|
||||||
# params.targets:v2 中 list 形态在 INPUT_PORT_MAPPING 处理后被清空([])或为单字符串
|
|
||||||
# (不再是原始 list[str]——避免下游 runtime 对其再做无序聚合)
|
|
||||||
tparams = tnode.get("param", {}) or {}
|
|
||||||
assert not isinstance(tparams.get("targets"), list) or tparams.get("targets") == [], (
|
|
||||||
f"v2:params.targets 不再是非空 list;实际 {tparams.get('targets')!r}"
|
|
||||||
)
|
|
||||||
|
|
||||||
# targets_identifier 端口:只有 1 条入边
|
|
||||||
in_targets_edges = [
|
|
||||||
e for e in _edges_to(g, transfer_id)
|
|
||||||
if e.get("target_handle_key") == "targets_identifier"
|
|
||||||
]
|
|
||||||
assert len(in_targets_edges) == 1, (
|
|
||||||
f"v2:transfer_liquid.targets_identifier 必须是单入边(来自 merged set_liquid);"
|
|
||||||
f" 实际 {len(in_targets_edges)}"
|
|
||||||
)
|
|
||||||
|
|
||||||
# 这条入边的源端口必须是 output_wells
|
|
||||||
edge = in_targets_edges[0]
|
|
||||||
assert edge.get("source_handle_key") == "output_wells"
|
|
||||||
|
|
||||||
|
|
||||||
def test_str_targets_no_merged_node_emitted():
|
|
||||||
"""对照组:targets 为 str(单 reagent) → 不插入 merged set_liquid_from_plate 节点。
|
|
||||||
|
|
||||||
保证 v2 改造**只**对 list 形态触发,单 reagent 走 P3 原有 per-plate set_liquid 路径。
|
|
||||||
"""
|
|
||||||
labware = _cross_slot_labware_info()
|
|
||||||
labware["plate_slot2"]["well"] = ["A1", "A2", "A3"]
|
|
||||||
|
|
||||||
steps = [
|
|
||||||
{
|
|
||||||
"action": "transfer_liquid",
|
|
||||||
"parameters": {
|
|
||||||
"sources": "l1",
|
|
||||||
"targets": "plate_slot2", # ← 单 str,非 list
|
|
||||||
"tip_racks": "tiprack_12",
|
|
||||||
"asp_vols": [8.3, 8.3, 8.3],
|
|
||||||
"dis_vols": [8.3, 8.3, 8.3],
|
|
||||||
},
|
|
||||||
"step_number": 1,
|
|
||||||
}
|
|
||||||
]
|
|
||||||
g = build_protocol_graph(
|
|
||||||
labware_info=labware,
|
|
||||||
protocol_steps=steps,
|
|
||||||
workstation_name="PRCXI",
|
|
||||||
)
|
|
||||||
merged_nodes = [
|
|
||||||
n for n in _nodes_by_template(g, "set_liquid_from_plate")
|
|
||||||
if str(n.get("name", "")).startswith("_merged_targets_")
|
|
||||||
]
|
|
||||||
assert merged_nodes == [], "str 形态 targets 不应触发 v2 merged 聚合节点"
|
|
||||||
@@ -1,452 +0,0 @@
|
|||||||
"""P8 — Stage 3 (``workflow/common.py``) 写入 ``set_liquid_from_plate.param.liquid_names`` 时
|
|
||||||
优先取 ``reagent[key].liquid_name``,缺省时 fallback 到 reagent_key。
|
|
||||||
|
|
||||||
对应 ``product_designs/protocol_convert/08-liquid-name-from-reagent-block.md`` §3.4 + §5。
|
|
||||||
|
|
||||||
设计要点
|
|
||||||
--------
|
|
||||||
- ``reagent[key].liquid_name`` 是 P8 新增的**可选**字段,承载真实化学名(与 reagent_key
|
|
||||||
解耦:reagent_key 仍是数据流引用名 / 业务别名,``liquid_name`` 是写入 PLR tracker /
|
|
||||||
前端的 human-readable 名称)。
|
|
||||||
- ``liquid_name`` 来源优先级:Stage 0 mock ``Well.load_liquid(liquid=...)`` 实参 >
|
|
||||||
README 语义词 > 不写(Stage 3 fallback 到 reagent_key)。
|
|
||||||
- ``liquid_name`` 保留空格 / 中文 / 括号等原字符,**不**做 snake_case / underscore 替换。
|
|
||||||
- 旧 JSON(无 ``liquid_name`` 字段)行为完全不变(设计点 §7.A)。
|
|
||||||
|
|
||||||
测试用例
|
|
||||||
--------
|
|
||||||
- ``test_per_plate_fallback_when_no_liquid_name`` —— 缺省 fallback:
|
|
||||||
reagent 块无 ``liquid_name`` → liquid_names[i] == reagent_key(与 P8 前一致)。
|
|
||||||
- ``test_per_plate_uses_explicit_liquid_name`` —— 显式 liquid_name:
|
|
||||||
liquid_names[i] == "EDTA Plasma"。
|
|
||||||
- ``test_per_plate_preserves_spaces_and_special_chars`` —— 含空格 / 括号:
|
|
||||||
liquid_names[i] 不被 ``replace(" ", "_")`` 处理(不同于 reagent_key 用的 res_id)。
|
|
||||||
- ``test_merged_node_uses_explicit_liquid_name_per_dispense`` —— merged 节点
|
|
||||||
每个 dispense 独立取 ``liquid_name or key``,部分有部分无能共存。
|
|
||||||
- ``test_liquid_name_independent_of_reagent_key_normalization`` —— 与 P4 共存:
|
|
||||||
reagent_key 仍是 ``samples_2`` 等去重后缀,但 liquid_names 写的是真实化学名。
|
|
||||||
"""
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import sys
|
|
||||||
import types
|
|
||||||
from pathlib import Path
|
|
||||||
from typing import Any, Dict, List
|
|
||||||
|
|
||||||
|
|
||||||
ROOT_DIR = Path(__file__).resolve().parents[2]
|
|
||||||
if str(ROOT_DIR) not in sys.path:
|
|
||||||
sys.path.insert(0, str(ROOT_DIR))
|
|
||||||
|
|
||||||
|
|
||||||
def _install_fake_optional_deps() -> None:
|
|
||||||
"""与 test_common_set_liquid_dedup.py 一致的可选依赖 stub。"""
|
|
||||||
if "matplotlib" not in sys.modules:
|
|
||||||
sys.modules["matplotlib"] = types.ModuleType("matplotlib")
|
|
||||||
if "matplotlib.pyplot" not in sys.modules:
|
|
||||||
sys.modules["matplotlib.pyplot"] = types.ModuleType("matplotlib.pyplot")
|
|
||||||
try:
|
|
||||||
from networkx.drawing import nx_agraph # noqa: F401
|
|
||||||
except Exception:
|
|
||||||
nx_drawing = types.ModuleType("networkx.drawing")
|
|
||||||
nx_agraph_mod = types.ModuleType("networkx.drawing.nx_agraph")
|
|
||||||
nx_agraph_mod.to_agraph = lambda _g: None # type: ignore[attr-defined]
|
|
||||||
nx_drawing.nx_agraph = nx_agraph_mod # type: ignore[attr-defined]
|
|
||||||
sys.modules["networkx.drawing"] = nx_drawing
|
|
||||||
sys.modules["networkx.drawing.nx_agraph"] = nx_agraph_mod
|
|
||||||
|
|
||||||
|
|
||||||
_install_fake_optional_deps()
|
|
||||||
|
|
||||||
import pytest # noqa: E402
|
|
||||||
|
|
||||||
from unilabos.workflow.common import build_protocol_graph # noqa: E402
|
|
||||||
|
|
||||||
|
|
||||||
# ==================== 辅助 ====================
|
|
||||||
|
|
||||||
|
|
||||||
def _set_liquid_nodes(graph) -> List[Dict[str, Any]]:
|
|
||||||
return [
|
|
||||||
{"id": nid, **node}
|
|
||||||
for nid, node in graph.nodes.items()
|
|
||||||
if node.get("template_name") == "set_liquid_from_plate"
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def _per_plate_for(graph, reagent_key: str) -> Dict[str, Any]:
|
|
||||||
"""根据 ``description = "Set liquid: <reagent_key>"`` 反查 per-plate 节点。"""
|
|
||||||
for n in _set_liquid_nodes(graph):
|
|
||||||
if n.get("description") == f"Set liquid: {reagent_key}":
|
|
||||||
return n
|
|
||||||
raise AssertionError(f"未找到 per-plate set_liquid_from_plate(reagent_key={reagent_key!r})")
|
|
||||||
|
|
||||||
|
|
||||||
def _merged_nodes(graph) -> List[Dict[str, Any]]:
|
|
||||||
return [
|
|
||||||
n for n in _set_liquid_nodes(graph)
|
|
||||||
if str(n.get("name", "")).startswith("_merged_targets_")
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def _make_source_target_labware(
|
|
||||||
*,
|
|
||||||
source_key: str = "src_1",
|
|
||||||
source_liquid_name: str | None = None,
|
|
||||||
target_keys: List[str] | None = None,
|
|
||||||
target_liquid_names: Dict[str, str] | None = None,
|
|
||||||
) -> Dict[str, Dict[str, Any]]:
|
|
||||||
"""构造 1 个 source + N 个 target reagent + 1 个 tip rack。
|
|
||||||
|
|
||||||
``*_liquid_name`` 为 None / 缺省时**不**写入 ``liquid_name`` 字段,
|
|
||||||
模拟旧 schema / mock 未给 liquid_name 的真实回归场景。
|
|
||||||
"""
|
|
||||||
info: Dict[str, Dict[str, Any]] = {}
|
|
||||||
source_entry: Dict[str, Any] = {
|
|
||||||
"slot": 1,
|
|
||||||
"well": ["A1"],
|
|
||||||
"labware": "nest_12_reservoir_15ml",
|
|
||||||
"object": "source",
|
|
||||||
}
|
|
||||||
if source_liquid_name is not None:
|
|
||||||
source_entry["liquid_name"] = source_liquid_name
|
|
||||||
info[source_key] = source_entry
|
|
||||||
|
|
||||||
target_keys = target_keys or ["t_A"]
|
|
||||||
target_liquid_names = target_liquid_names or {}
|
|
||||||
for i, tk in enumerate(target_keys, start=1):
|
|
||||||
entry: Dict[str, Any] = {
|
|
||||||
"slot": 2 + i,
|
|
||||||
"well": ["A1"],
|
|
||||||
"labware": "nest_96_wellplate_2ml_deep",
|
|
||||||
"object": "target",
|
|
||||||
}
|
|
||||||
if tk in target_liquid_names:
|
|
||||||
entry["liquid_name"] = target_liquid_names[tk]
|
|
||||||
info[tk] = entry
|
|
||||||
|
|
||||||
info["tiprack_12"] = {
|
|
||||||
"slot": 12,
|
|
||||||
"well": [],
|
|
||||||
"labware": "opentrons_96_tiprack_300ul",
|
|
||||||
"object": "tiprack",
|
|
||||||
}
|
|
||||||
return info
|
|
||||||
|
|
||||||
|
|
||||||
# ==================== T1 缺省 fallback ====================
|
|
||||||
|
|
||||||
|
|
||||||
def test_per_plate_fallback_when_no_liquid_name():
|
|
||||||
"""reagent block 无 ``liquid_name`` 字段 → liquid_names[i] == reagent_key(P8 前行为)。"""
|
|
||||||
labware = _make_source_target_labware(
|
|
||||||
source_key="src_1",
|
|
||||||
target_keys=["t_A"],
|
|
||||||
# 都不给 liquid_name
|
|
||||||
)
|
|
||||||
steps = [
|
|
||||||
{
|
|
||||||
"action": "transfer_liquid",
|
|
||||||
"parameters": {
|
|
||||||
"sources": "src_1",
|
|
||||||
"targets": "t_A",
|
|
||||||
"tip_racks": "tiprack_12",
|
|
||||||
"asp_vols": [10.0],
|
|
||||||
"dis_vols": [10.0],
|
|
||||||
},
|
|
||||||
"step_number": 1,
|
|
||||||
}
|
|
||||||
]
|
|
||||||
g = build_protocol_graph(
|
|
||||||
labware_info=labware,
|
|
||||||
protocol_steps=steps,
|
|
||||||
workstation_name="PRCXI",
|
|
||||||
)
|
|
||||||
|
|
||||||
src_node = _per_plate_for(g, "src_1")
|
|
||||||
tgt_node = _per_plate_for(g, "t_A")
|
|
||||||
assert src_node["param"]["liquid_names"] == ["src_1"], (
|
|
||||||
f"无 liquid_name 时 source per-plate 应 fallback 到 reagent_key;"
|
|
||||||
f" 实际 {src_node['param']['liquid_names']}"
|
|
||||||
)
|
|
||||||
assert tgt_node["param"]["liquid_names"] == ["t_A"], (
|
|
||||||
f"无 liquid_name 时 target per-plate 应 fallback 到 reagent_key;"
|
|
||||||
f" 实际 {tgt_node['param']['liquid_names']}"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
# ==================== T2 显式 liquid_name ====================
|
|
||||||
|
|
||||||
|
|
||||||
def test_per_plate_uses_explicit_liquid_name():
|
|
||||||
"""reagent block 含 ``liquid_name`` → liquid_names[i] 用该值(不是 reagent_key)。"""
|
|
||||||
labware = _make_source_target_labware(
|
|
||||||
source_key="src_1",
|
|
||||||
source_liquid_name="EDTA Plasma",
|
|
||||||
target_keys=["t_A"],
|
|
||||||
target_liquid_names={"t_A": "PBS Diluent"},
|
|
||||||
)
|
|
||||||
steps = [
|
|
||||||
{
|
|
||||||
"action": "transfer_liquid",
|
|
||||||
"parameters": {
|
|
||||||
"sources": "src_1",
|
|
||||||
"targets": "t_A",
|
|
||||||
"tip_racks": "tiprack_12",
|
|
||||||
"asp_vols": [10.0],
|
|
||||||
"dis_vols": [10.0],
|
|
||||||
},
|
|
||||||
"step_number": 1,
|
|
||||||
}
|
|
||||||
]
|
|
||||||
g = build_protocol_graph(
|
|
||||||
labware_info=labware,
|
|
||||||
protocol_steps=steps,
|
|
||||||
workstation_name="PRCXI",
|
|
||||||
)
|
|
||||||
|
|
||||||
src_node = _per_plate_for(g, "src_1")
|
|
||||||
tgt_node = _per_plate_for(g, "t_A")
|
|
||||||
assert src_node["param"]["liquid_names"] == ["EDTA Plasma"], (
|
|
||||||
f"source per-plate 应使用 reagent.liquid_name;实际 {src_node['param']['liquid_names']}"
|
|
||||||
)
|
|
||||||
assert tgt_node["param"]["liquid_names"] == ["PBS Diluent"], (
|
|
||||||
f"target per-plate 应使用 reagent.liquid_name;实际 {tgt_node['param']['liquid_names']}"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
# ==================== T3 空格 / 括号 ====================
|
|
||||||
|
|
||||||
|
|
||||||
def test_per_plate_preserves_spaces_and_special_chars():
|
|
||||||
"""``liquid_name`` 保留空格 / 括号 / 中文等原字符,不被 replace(' ', '_') 处理。
|
|
||||||
|
|
||||||
这条与 reagent_key 走 ``res_id = str(labware_id).replace(' ', '_')`` 的语义不同。
|
|
||||||
"""
|
|
||||||
labware = _make_source_target_labware(
|
|
||||||
source_key="src_1",
|
|
||||||
source_liquid_name="Tris HCl pH 8.0 (1×)",
|
|
||||||
target_keys=["t_A"],
|
|
||||||
target_liquid_names={"t_A": "稀释液 A"},
|
|
||||||
)
|
|
||||||
steps = [
|
|
||||||
{
|
|
||||||
"action": "transfer_liquid",
|
|
||||||
"parameters": {
|
|
||||||
"sources": "src_1",
|
|
||||||
"targets": "t_A",
|
|
||||||
"tip_racks": "tiprack_12",
|
|
||||||
"asp_vols": [10.0],
|
|
||||||
"dis_vols": [10.0],
|
|
||||||
},
|
|
||||||
"step_number": 1,
|
|
||||||
}
|
|
||||||
]
|
|
||||||
g = build_protocol_graph(
|
|
||||||
labware_info=labware,
|
|
||||||
protocol_steps=steps,
|
|
||||||
workstation_name="PRCXI",
|
|
||||||
)
|
|
||||||
|
|
||||||
src_node = _per_plate_for(g, "src_1")
|
|
||||||
tgt_node = _per_plate_for(g, "t_A")
|
|
||||||
|
|
||||||
assert src_node["param"]["liquid_names"] == ["Tris HCl pH 8.0 (1×)"], (
|
|
||||||
f"空格 / 括号应原样保留;实际 {src_node['param']['liquid_names']}"
|
|
||||||
)
|
|
||||||
assert tgt_node["param"]["liquid_names"] == ["稀释液 A"], (
|
|
||||||
f"中文应原样保留;实际 {tgt_node['param']['liquid_names']}"
|
|
||||||
)
|
|
||||||
|
|
||||||
# reagent_key 自身仍受 ``res_id = replace(' ', '_')`` 影响,
|
|
||||||
# 但本测试 reagent_key 不含空格,故 sl_node_title 仍以 reagent_key 为根。
|
|
||||||
# 这里仅断言 liquid_names 字段独立于 reagent_key normalize。
|
|
||||||
|
|
||||||
|
|
||||||
# ==================== T4 merged 节点跨板部分有部分无 ====================
|
|
||||||
|
|
||||||
|
|
||||||
def test_merged_node_uses_explicit_liquid_name_per_dispense():
|
|
||||||
"""merged 节点 ``liquid_names`` 与 list-targets 同长,每个元素独立取
|
|
||||||
``reagent[key].liquid_name or key``:本例 3 个 target,2 个有显式名、1 个无。
|
|
||||||
"""
|
|
||||||
labware = _make_source_target_labware(
|
|
||||||
source_key="src_1",
|
|
||||||
target_keys=["t_A", "t_B", "t_C"],
|
|
||||||
target_liquid_names={
|
|
||||||
"t_A": "Plasma",
|
|
||||||
# t_B 无 liquid_name
|
|
||||||
"t_C": "Buffer X",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
steps = [
|
|
||||||
{
|
|
||||||
"action": "transfer_liquid",
|
|
||||||
"parameters": {
|
|
||||||
"sources": "src_1",
|
|
||||||
"targets": ["t_A", "t_B", "t_C"],
|
|
||||||
"tip_racks": "tiprack_12",
|
|
||||||
"asp_vols": [5.0] * 3,
|
|
||||||
"dis_vols": [5.0] * 3,
|
|
||||||
},
|
|
||||||
"step_number": 1,
|
|
||||||
}
|
|
||||||
]
|
|
||||||
g = build_protocol_graph(
|
|
||||||
labware_info=labware,
|
|
||||||
protocol_steps=steps,
|
|
||||||
workstation_name="PRCXI",
|
|
||||||
)
|
|
||||||
|
|
||||||
merged = _merged_nodes(g)
|
|
||||||
assert len(merged) == 1, f"应有 1 个 merged 节点,实际 {len(merged)}"
|
|
||||||
liquid_names = merged[0]["param"]["liquid_names"]
|
|
||||||
assert liquid_names == ["Plasma", "t_B", "Buffer X"], (
|
|
||||||
f"merged 每 dispense 独立取 liquid_name or key;实际 {liquid_names}"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
# ==================== T5 与 P4 reagent_key 后缀共存 ====================
|
|
||||||
|
|
||||||
|
|
||||||
def test_liquid_name_independent_of_reagent_key_normalization():
|
|
||||||
"""P4 命名链产生 ``samples_2`` 这种带后缀的 reagent_key(跨板去重);
|
|
||||||
P8 ``liquid_name`` 应保持原始化学名,**不**带 P4 的去重后缀。
|
|
||||||
|
|
||||||
构造:2 个 target reagent_keys ``samples`` / ``samples_2``(不同 slot,
|
|
||||||
模拟跨板同液体被 Stage 2 去重),都标 liquid_name="Bacterial Culture"。
|
|
||||||
"""
|
|
||||||
labware = _make_source_target_labware(
|
|
||||||
source_key="src_1",
|
|
||||||
target_keys=["samples", "samples_2"],
|
|
||||||
target_liquid_names={
|
|
||||||
"samples": "Bacterial Culture",
|
|
||||||
"samples_2": "Bacterial Culture",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
steps = [
|
|
||||||
{
|
|
||||||
"action": "transfer_liquid",
|
|
||||||
"parameters": {
|
|
||||||
"sources": "src_1",
|
|
||||||
"targets": ["samples", "samples_2"],
|
|
||||||
"tip_racks": "tiprack_12",
|
|
||||||
"asp_vols": [5.0, 5.0],
|
|
||||||
"dis_vols": [5.0, 5.0],
|
|
||||||
},
|
|
||||||
"step_number": 1,
|
|
||||||
}
|
|
||||||
]
|
|
||||||
g = build_protocol_graph(
|
|
||||||
labware_info=labware,
|
|
||||||
protocol_steps=steps,
|
|
||||||
workstation_name="PRCXI",
|
|
||||||
)
|
|
||||||
|
|
||||||
merged = _merged_nodes(g)
|
|
||||||
assert len(merged) == 1
|
|
||||||
liquid_names = merged[0]["param"]["liquid_names"]
|
|
||||||
assert liquid_names == ["Bacterial Culture", "Bacterial Culture"], (
|
|
||||||
f"P8 liquid_name 应与 P4 reagent_key 后缀解耦:同液体的两个 reagent_key 应得相同"
|
|
||||||
f" liquid_name;实际 {liquid_names}"
|
|
||||||
)
|
|
||||||
# 同时 reagent_key 仍是 samples / samples_2(不变)
|
|
||||||
wells = merged[0]["param"]["wells"]
|
|
||||||
parents = [w["parent"] for w in wells]
|
|
||||||
assert parents == ["samples", "samples_2"], (
|
|
||||||
f"merged wells.parent 应等于 list-targets reagent_keys;实际 {parents}"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
# ==================== T6 source per-plate / target per-plate 同步生效 ====================
|
|
||||||
|
|
||||||
|
|
||||||
def test_both_source_and_target_per_plate_use_liquid_name():
|
|
||||||
"""str-targets 路径(无 merged)下,source 和 target 都走 per-plate emit,
|
|
||||||
各自独立取 ``liquid_name``。"""
|
|
||||||
labware = _make_source_target_labware(
|
|
||||||
source_key="src_1",
|
|
||||||
source_liquid_name="Reagent A",
|
|
||||||
target_keys=["t_A"],
|
|
||||||
target_liquid_names={"t_A": "Reagent B"},
|
|
||||||
)
|
|
||||||
steps = [
|
|
||||||
{
|
|
||||||
"action": "transfer_liquid",
|
|
||||||
"parameters": {
|
|
||||||
"sources": "src_1",
|
|
||||||
"targets": "t_A", # str-targets,不触发 merged
|
|
||||||
"tip_racks": "tiprack_12",
|
|
||||||
"asp_vols": [10.0],
|
|
||||||
"dis_vols": [10.0],
|
|
||||||
},
|
|
||||||
"step_number": 1,
|
|
||||||
}
|
|
||||||
]
|
|
||||||
g = build_protocol_graph(
|
|
||||||
labware_info=labware,
|
|
||||||
protocol_steps=steps,
|
|
||||||
workstation_name="PRCXI",
|
|
||||||
)
|
|
||||||
|
|
||||||
assert _merged_nodes(g) == [], "str-targets 不应产生 merged 节点"
|
|
||||||
src_node = _per_plate_for(g, "src_1")
|
|
||||||
tgt_node = _per_plate_for(g, "t_A")
|
|
||||||
assert src_node["param"]["liquid_names"] == ["Reagent A"]
|
|
||||||
assert tgt_node["param"]["liquid_names"] == ["Reagent B"]
|
|
||||||
|
|
||||||
|
|
||||||
# ==================== T7 多孔同 reagent → 整列 liquid_names 一致 ====================
|
|
||||||
|
|
||||||
|
|
||||||
def test_multi_well_reagent_replicates_liquid_name():
|
|
||||||
"""1 个 reagent 含 8 wells(multi-channel 扩展场景)→ liquid_names 应是
|
|
||||||
``[liquid_name] * 8``,与 wells 长度一致。"""
|
|
||||||
labware: Dict[str, Dict[str, Any]] = {
|
|
||||||
"src_1": {
|
|
||||||
"slot": 1,
|
|
||||||
"well": ["A1", "B1", "C1", "D1", "E1", "F1", "G1", "H1"],
|
|
||||||
"labware": "nest_96_wellplate_100ul_pcr_full_skirt",
|
|
||||||
"object": "source",
|
|
||||||
"liquid_name": "Mastermix",
|
|
||||||
},
|
|
||||||
"t_A": {
|
|
||||||
"slot": 3,
|
|
||||||
"well": ["A1"],
|
|
||||||
"labware": "nest_96_wellplate_2ml_deep",
|
|
||||||
"object": "target",
|
|
||||||
},
|
|
||||||
"tiprack_12": {
|
|
||||||
"slot": 12,
|
|
||||||
"well": [],
|
|
||||||
"labware": "opentrons_96_tiprack_300ul",
|
|
||||||
"object": "tiprack",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
steps = [
|
|
||||||
{
|
|
||||||
"action": "transfer_liquid",
|
|
||||||
"parameters": {
|
|
||||||
"sources": "src_1",
|
|
||||||
"targets": "t_A",
|
|
||||||
"tip_racks": "tiprack_12",
|
|
||||||
"asp_vols": [10.0],
|
|
||||||
"dis_vols": [10.0],
|
|
||||||
},
|
|
||||||
"step_number": 1,
|
|
||||||
}
|
|
||||||
]
|
|
||||||
g = build_protocol_graph(
|
|
||||||
labware_info=labware,
|
|
||||||
protocol_steps=steps,
|
|
||||||
workstation_name="PRCXI",
|
|
||||||
)
|
|
||||||
|
|
||||||
src_node = _per_plate_for(g, "src_1")
|
|
||||||
liquid_names = src_node["param"]["liquid_names"]
|
|
||||||
assert liquid_names == ["Mastermix"] * 8, (
|
|
||||||
f"per-plate 应把 liquid_name 复制 well_count 份;实际 {liquid_names}"
|
|
||||||
)
|
|
||||||
# 同时 wells / volumes 长度一致
|
|
||||||
assert len(src_node["param"]["wells"]) == 8
|
|
||||||
assert len(src_node["param"]["volumes"]) == 8
|
|
||||||
@@ -1,174 +0,0 @@
|
|||||||
"""P6 §17 hint bug —— `_infer_plate_num_children_from_labware_hint` 误把
|
|
||||||
reagent_id 末尾数字(如 ``samples_6`` 的 ``_6``)当作孔板规格,导致
|
|
||||||
``_apply_target_labware_class_auto_match`` fallback 到 PRCXI 4-孔 trough 模板。
|
|
||||||
|
|
||||||
跨板 fix(P2 v2 §14)把 plate name 作为 prefix 编码进 ``well_names`` 之后,
|
|
||||||
runtime 调用 ``plate.get_well("A5")`` 严格定位 well,trough plate 上不存在
|
|
||||||
``A5`` 会直接 IndexError,使得这个隐藏多年的孔数推断 bug 浮出。
|
|
||||||
|
|
||||||
修复策略(方案 A)
|
|
||||||
-----
|
|
||||||
hint 只用 ``item.get("labware", "")``,**不再**拼上 ``labware_id``(reagent_key
|
|
||||||
是业务名,不应参与孔板规格推断)。
|
|
||||||
|
|
||||||
测试矩阵
|
|
||||||
----
|
|
||||||
- ``test_reagent_key_numeric_suffix_must_not_match_hint`` —— samples_6 / samples_24 /
|
|
||||||
samples_96 + nunc_rectangular_agar_plate → hint 返回 None(labware string 不带孔数信息)。
|
|
||||||
- ``test_labware_string_X_well_correctly_inferred`` —— labware="nest_96_wellplate..." → 96;
|
|
||||||
"custom_384_wellplate" → 384;"nest_24_wellplate_2ml_pcr" → 24。
|
|
||||||
- ``test_apply_does_not_classify_samples_6_as_trough`` —— 集成:构造 Agar Plating-like
|
|
||||||
reagent block(slot 8 上 12 个 samples_X,X 末尾含 6/24/96),跑
|
|
||||||
``_apply_target_labware_class_auto_match`` 后,samples_6/24 不再得到 trough class。
|
|
||||||
- ``test_real_labware_96_wellplate_still_inferred_via_labware_str`` —— 即便 labware_id
|
|
||||||
与孔数无关,``nest_96_wellplate_100ul_pcr_full_skirt`` 这种 labware 命名仍应被识别为 96。
|
|
||||||
"""
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import sys
|
|
||||||
import types
|
|
||||||
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))
|
|
||||||
|
|
||||||
|
|
||||||
def _install_fake_optional_deps() -> None:
|
|
||||||
if "matplotlib" not in sys.modules:
|
|
||||||
sys.modules["matplotlib"] = types.ModuleType("matplotlib")
|
|
||||||
if "matplotlib.pyplot" not in sys.modules:
|
|
||||||
sys.modules["matplotlib.pyplot"] = types.ModuleType("matplotlib.pyplot")
|
|
||||||
|
|
||||||
|
|
||||||
_install_fake_optional_deps()
|
|
||||||
|
|
||||||
import pytest # noqa: E402
|
|
||||||
|
|
||||||
from unilabos.workflow.common import ( # noqa: E402
|
|
||||||
_apply_target_labware_class_auto_match,
|
|
||||||
_infer_plate_num_children_from_labware_hint,
|
|
||||||
_reconcile_slot_carrier_target_class,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
# ==================== unit:hint 函数本身 ====================
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
"labware_id",
|
|
||||||
["samples_6", "samples_24", "samples_96", "samples_12", "samples_48"],
|
|
||||||
)
|
|
||||||
def test_reagent_key_numeric_suffix_must_not_match_hint(labware_id):
|
|
||||||
"""reagent_id 末尾的孔数关键字数字不应被识别为孔板规格。"""
|
|
||||||
item = {
|
|
||||||
"slot": 8,
|
|
||||||
"well": ["A5"],
|
|
||||||
"labware": "nunc_rectangular_agar_plate",
|
|
||||||
"object": "target",
|
|
||||||
}
|
|
||||||
assert _infer_plate_num_children_from_labware_hint(labware_id, item) is None, (
|
|
||||||
f"reagent_id {labware_id!r} 不应被识别为孔板规格 "
|
|
||||||
f"(其末尾数字应当被忽略;labware string 不含 96/384/etc 关键字)"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
"labware_str,expected",
|
|
||||||
[
|
|
||||||
("nest_96_wellplate_100ul_pcr_full_skirt", 96),
|
|
||||||
("custom_384_wellplate", 384),
|
|
||||||
("nest_24_wellplate_2ml_pcr", 24),
|
|
||||||
("custom_48_wellplate", 48),
|
|
||||||
("opentrons_12_wellplate_15ml", 12),
|
|
||||||
("nest_6_wellplate_5ml", 6),
|
|
||||||
("nunc_rectangular_agar_plate", None),
|
|
||||||
("", None),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
def test_labware_string_well_count_inferred(labware_str, expected):
|
|
||||||
item = {"labware": labware_str}
|
|
||||||
assert (
|
|
||||||
_infer_plate_num_children_from_labware_hint("samples", item) == expected
|
|
||||||
), f"labware {labware_str!r} 应推断为 {expected!r}"
|
|
||||||
|
|
||||||
|
|
||||||
# ==================== integration:模拟 Agar Plating ====================
|
|
||||||
|
|
||||||
|
|
||||||
def _agar_plating_reagent_block():
|
|
||||||
"""反推自 unilabos_data/req_workflow_upload.json:12 列 × 9 reagent per step。
|
|
||||||
|
|
||||||
slot 8 (mapped 14) 上 12 个 reagent_keys: samples_6, samples_15, samples_24,
|
|
||||||
samples_33, samples_42, samples_51, samples_60, samples_69, samples_78,
|
|
||||||
samples_87, samples_96, samples_105.
|
|
||||||
"""
|
|
||||||
info = {}
|
|
||||||
slot_for_idx = {0: 3, 1: 4, 2: 5, 3: 6, 4: 7, 5: 8, 6: 9, 7: 10, 8: 11}
|
|
||||||
cols = [f"A{i + 1}" for i in range(12)]
|
|
||||||
for col_i, col in enumerate(cols):
|
|
||||||
for di in range(9):
|
|
||||||
n = col_i * 9 + di + 1
|
|
||||||
key = "samples" if n == 1 else f"samples_{n}"
|
|
||||||
info[key] = {
|
|
||||||
"slot": slot_for_idx[di],
|
|
||||||
"well": [col],
|
|
||||||
"labware": "nunc_rectangular_agar_plate",
|
|
||||||
"object": "target",
|
|
||||||
}
|
|
||||||
for i in range(12):
|
|
||||||
key = "sources" if i == 0 else f"sources_{i + 1}"
|
|
||||||
info[key] = {
|
|
||||||
"slot": 2,
|
|
||||||
"well": [cols[i]],
|
|
||||||
"labware": "nest_96_wellplate_100ul_pcr_full_skirt",
|
|
||||||
"object": "source",
|
|
||||||
}
|
|
||||||
info["tiprack_1"] = {
|
|
||||||
"slot": 1,
|
|
||||||
"well": None,
|
|
||||||
"labware": "opentrons_96_tiprack_10ul",
|
|
||||||
"object": "tiprack",
|
|
||||||
}
|
|
||||||
info["trash"] = {
|
|
||||||
"slot": 12,
|
|
||||||
"well": None,
|
|
||||||
"labware": "opentrons_1_trash_1100ml_fixed",
|
|
||||||
"object": "trash",
|
|
||||||
}
|
|
||||||
return info
|
|
||||||
|
|
||||||
|
|
||||||
def test_apply_does_not_classify_samples_6_as_trough():
|
|
||||||
"""集成回归:Agar Plating-like reagent block 跑完类匹配 + slot 统一后,
|
|
||||||
slot 8 上 12 个 reagent 不应得到 4-孔 trough class。"""
|
|
||||||
info = _agar_plating_reagent_block()
|
|
||||||
_apply_target_labware_class_auto_match(
|
|
||||||
info, preserve_tip_rack_incoming_class=True, target_device="prcxi"
|
|
||||||
)
|
|
||||||
_reconcile_slot_carrier_target_class(
|
|
||||||
info, preserve_tip_rack_incoming_class=True, target_device="prcxi"
|
|
||||||
)
|
|
||||||
slot8_keys = [
|
|
||||||
"samples_6", "samples_15", "samples_24", "samples_33",
|
|
||||||
"samples_42", "samples_51", "samples_60", "samples_69",
|
|
||||||
"samples_78", "samples_87", "samples_96", "samples_105",
|
|
||||||
]
|
|
||||||
for k in slot8_keys:
|
|
||||||
cls = info[k].get("target_class_name") or ""
|
|
||||||
assert "trough" not in cls.lower(), (
|
|
||||||
f"reagent {k} 被误识别为 trough class: {cls!r};"
|
|
||||||
"这通常是 hint 误把 reagent_id 末尾数字当孔板规格"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_real_labware_96_wellplate_still_inferred_via_labware_str():
|
|
||||||
"""labware string 含 96_wellplate 时应该正常识别为 96,不被 fix 破坏。"""
|
|
||||||
item = {
|
|
||||||
"slot": 2,
|
|
||||||
"well": ["A1"],
|
|
||||||
"labware": "nest_96_wellplate_100ul_pcr_full_skirt",
|
|
||||||
"object": "source",
|
|
||||||
}
|
|
||||||
assert _infer_plate_num_children_from_labware_hint("sources", item) == 96
|
|
||||||
@@ -1,379 +0,0 @@
|
|||||||
"""P2 v2 §14 set_liquid_from_plate 去重 —— Stage 3 (`workflow/common.py`) 集成测试。
|
|
||||||
|
|
||||||
对应 ``product_designs/protocol_convert/02-cross-slot-merge.md`` §14(2026-05-22 plan)。
|
|
||||||
|
|
||||||
§14 设计要点
|
|
||||||
-----------------
|
|
||||||
当 ``transfer_liquid.params.targets`` 是 ``list[str]`` 时,``_emit_merged_set_liquid``
|
|
||||||
已经为该 transfer 插入一个 merged ``set_liquid_from_plate`` 节点,
|
|
||||||
其 ``param.wells`` 聚合了 list 中所有 reagent_keys 的跨板 wells。
|
|
||||||
|
|
||||||
§14 之前:第二步循环(``for labware_id, item in labware_info.items()``)仍然为
|
|
||||||
list-targets 中出现的每个 reagent_key 创建一个 per-plate ``set_liquid_from_plate`` 节点,
|
|
||||||
导致**节点冗余**(per-plate 节点的 ``output_wells`` 对 transfer_liquid 的
|
|
||||||
``targets_identifier`` 边毫无贡献 —— transfer_liquid 单边只接 merged 节点)。
|
|
||||||
|
|
||||||
§14 改造:在第二步循环**之前**预扫描 protocol_steps,收集
|
|
||||||
``set_liquid_covered_by_merged: Set[str]``(出现在某个 list[str] targets 中的所有 keys)
|
|
||||||
与 ``set_liquid_referenced_by_str: Set[str]``(出现在 str targets 中的所有 keys)。
|
|
||||||
循环内对 ``object="target"`` 且 ``key ∈ covered ∧ key ∉ referenced_by_str`` 的 reagent_key
|
|
||||||
**跳过** per-plate 节点创建。
|
|
||||||
|
|
||||||
测试用例
|
|
||||||
----
|
|
||||||
- ``test_per_plate_skipped_when_covered_by_merged`` —— list-targets 覆盖的
|
|
||||||
target reagent_keys 不再产生 per-plate set_liquid_from_plate。
|
|
||||||
- ``test_per_plate_kept_when_also_referenced_by_str_targets`` —— R1 缓解:
|
|
||||||
同时被 list-targets 和 str-targets 引用的 reagent_key 仍保留 per-plate。
|
|
||||||
- ``test_str_targets_protocol_unaffected`` —— 单 slot 协议(仅 str-targets)
|
|
||||||
节点数完全不变(回归防护)。
|
|
||||||
- ``test_51b9a5_style_node_count`` —— 12 list-targets × len=9 大规模场景:
|
|
||||||
set_liquid_from_plate 总节点数 = source per-plate + merged + 0 target per-plate。
|
|
||||||
- ``test_source_per_plate_always_kept`` —— source 端不受 §14 影响:source
|
|
||||||
reagent_keys 不出现在 targets 字段中,per-plate 节点恒在。
|
|
||||||
"""
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import sys
|
|
||||||
import types
|
|
||||||
from pathlib import Path
|
|
||||||
from typing import Any, Dict, List
|
|
||||||
|
|
||||||
|
|
||||||
ROOT_DIR = Path(__file__).resolve().parents[2]
|
|
||||||
if str(ROOT_DIR) not in sys.path:
|
|
||||||
sys.path.insert(0, str(ROOT_DIR))
|
|
||||||
|
|
||||||
|
|
||||||
def _install_fake_optional_deps() -> None:
|
|
||||||
"""与 test_common_cross_slot_v2.py 一致的可选依赖 stub。"""
|
|
||||||
if "matplotlib" not in sys.modules:
|
|
||||||
sys.modules["matplotlib"] = types.ModuleType("matplotlib")
|
|
||||||
if "matplotlib.pyplot" not in sys.modules:
|
|
||||||
sys.modules["matplotlib.pyplot"] = types.ModuleType("matplotlib.pyplot")
|
|
||||||
try:
|
|
||||||
from networkx.drawing import nx_agraph # noqa: F401
|
|
||||||
except Exception:
|
|
||||||
nx_drawing = types.ModuleType("networkx.drawing")
|
|
||||||
nx_agraph_mod = types.ModuleType("networkx.drawing.nx_agraph")
|
|
||||||
nx_agraph_mod.to_agraph = lambda _g: None # type: ignore[attr-defined]
|
|
||||||
nx_drawing.nx_agraph = nx_agraph_mod # type: ignore[attr-defined]
|
|
||||||
sys.modules["networkx.drawing"] = nx_drawing
|
|
||||||
sys.modules["networkx.drawing.nx_agraph"] = nx_agraph_mod
|
|
||||||
|
|
||||||
|
|
||||||
_install_fake_optional_deps()
|
|
||||||
|
|
||||||
import pytest # noqa: E402
|
|
||||||
|
|
||||||
from unilabos.workflow.common import build_protocol_graph # noqa: E402
|
|
||||||
|
|
||||||
|
|
||||||
# ==================== 辅助 ====================
|
|
||||||
|
|
||||||
|
|
||||||
def _nodes_by_template(graph, template_name: str) -> List[Dict[str, Any]]:
|
|
||||||
return [
|
|
||||||
{"id": nid, **node}
|
|
||||||
for nid, node in graph.nodes.items()
|
|
||||||
if node.get("template_name") == template_name
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def _set_liquid_nodes_split(graph):
|
|
||||||
"""返回 (per_plate_nodes, merged_nodes)。merged 节点 name 以 `_merged_targets_` 开头。"""
|
|
||||||
all_sl = _nodes_by_template(graph, "set_liquid_from_plate")
|
|
||||||
merged = [n for n in all_sl if str(n.get("name", "")).startswith("_merged_targets_")]
|
|
||||||
per_plate = [n for n in all_sl if not str(n.get("name", "")).startswith("_merged_targets_")]
|
|
||||||
return per_plate, merged
|
|
||||||
|
|
||||||
|
|
||||||
def _labware_with_targets(target_keys: List[str], source_keys: List[str] | None = None) -> Dict[str, Dict[str, Any]]:
|
|
||||||
"""构造 labware_info:source 端 1 个 + 任意数量 target plates + tip rack。"""
|
|
||||||
info: Dict[str, Dict[str, Any]] = {}
|
|
||||||
source_keys = source_keys or ["src_1"]
|
|
||||||
for i, sk in enumerate(source_keys, start=1):
|
|
||||||
info[sk] = {
|
|
||||||
"slot": 1 + i - 1, # slot 1 占位(实际可能映射)
|
|
||||||
"well": ["A1"],
|
|
||||||
"labware": "nest_12_reservoir_15ml",
|
|
||||||
"object": "source",
|
|
||||||
}
|
|
||||||
for i, tk in enumerate(target_keys, start=1):
|
|
||||||
info[tk] = {
|
|
||||||
"slot": 2 + i, # 错开 source 使用的 slot
|
|
||||||
"well": ["A1"],
|
|
||||||
"labware": "nest_96_wellplate_2ml_deep",
|
|
||||||
"object": "target",
|
|
||||||
}
|
|
||||||
info["tiprack_12"] = {
|
|
||||||
"slot": 12,
|
|
||||||
"well": [],
|
|
||||||
"labware": "opentrons_96_tiprack_300ul",
|
|
||||||
"object": "tiprack",
|
|
||||||
}
|
|
||||||
return info
|
|
||||||
|
|
||||||
|
|
||||||
# ==================== 用例 ====================
|
|
||||||
|
|
||||||
|
|
||||||
def test_per_plate_skipped_when_covered_by_merged():
|
|
||||||
"""单 list-targets transfer 覆盖 4 个 target reagent_keys → per-plate 不再出现。"""
|
|
||||||
targets = ["t_A", "t_B", "t_C", "t_D"]
|
|
||||||
labware = _labware_with_targets(targets, source_keys=["src_1"])
|
|
||||||
steps = [
|
|
||||||
{
|
|
||||||
"action": "transfer_liquid",
|
|
||||||
"parameters": {
|
|
||||||
"sources": "src_1",
|
|
||||||
"targets": targets,
|
|
||||||
"tip_racks": "tiprack_12",
|
|
||||||
"asp_vols": [8.0] * 4,
|
|
||||||
"dis_vols": [8.0] * 4,
|
|
||||||
},
|
|
||||||
"step_number": 1,
|
|
||||||
}
|
|
||||||
]
|
|
||||||
g = build_protocol_graph(
|
|
||||||
labware_info=labware,
|
|
||||||
protocol_steps=steps,
|
|
||||||
workstation_name="PRCXI",
|
|
||||||
)
|
|
||||||
|
|
||||||
per_plate, merged = _set_liquid_nodes_split(g)
|
|
||||||
|
|
||||||
# merged 节点:1 个
|
|
||||||
assert len(merged) == 1, f"应有 1 个 merged 节点;实际 {len(merged)}"
|
|
||||||
|
|
||||||
# per-plate 节点:仅 source 1 个(src_1);target 端被全部跳过
|
|
||||||
per_plate_names = {n.get("description", "") for n in per_plate}
|
|
||||||
per_plate_keys = {
|
|
||||||
n.get("description", "").replace("Set liquid: ", "")
|
|
||||||
for n in per_plate
|
|
||||||
}
|
|
||||||
assert "src_1" in per_plate_keys, "source 端 per-plate 必须保留"
|
|
||||||
for tk in targets:
|
|
||||||
assert tk not in per_plate_keys, (
|
|
||||||
f"§14:target reagent_key '{tk}' 已被 merged 覆盖,不应再有 per-plate 节点;"
|
|
||||||
f" 实际 per_plate_keys={per_plate_keys}"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_per_plate_kept_when_also_referenced_by_str_targets():
|
|
||||||
"""R1 缓解:t_A 既被 list-targets 引用,又被 str-targets 引用 → per-plate 必须保留。"""
|
|
||||||
targets_list = ["t_A", "t_B", "t_C"]
|
|
||||||
labware = _labware_with_targets(targets_list, source_keys=["src_1"])
|
|
||||||
steps = [
|
|
||||||
{
|
|
||||||
"action": "transfer_liquid",
|
|
||||||
"parameters": {
|
|
||||||
"sources": "src_1",
|
|
||||||
"targets": targets_list,
|
|
||||||
"tip_racks": "tiprack_12",
|
|
||||||
"asp_vols": [5.0] * 3,
|
|
||||||
"dis_vols": [5.0] * 3,
|
|
||||||
},
|
|
||||||
"step_number": 1,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"action": "transfer_liquid",
|
|
||||||
"parameters": {
|
|
||||||
"sources": "src_1",
|
|
||||||
"targets": "t_A",
|
|
||||||
"tip_racks": "tiprack_12",
|
|
||||||
"asp_vols": [10.0],
|
|
||||||
"dis_vols": [10.0],
|
|
||||||
},
|
|
||||||
"step_number": 2,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
g = build_protocol_graph(
|
|
||||||
labware_info=labware,
|
|
||||||
protocol_steps=steps,
|
|
||||||
workstation_name="PRCXI",
|
|
||||||
)
|
|
||||||
|
|
||||||
per_plate, merged = _set_liquid_nodes_split(g)
|
|
||||||
per_plate_keys = {
|
|
||||||
n.get("description", "").replace("Set liquid: ", "")
|
|
||||||
for n in per_plate
|
|
||||||
}
|
|
||||||
|
|
||||||
assert "t_A" in per_plate_keys, (
|
|
||||||
f"R1:t_A 被 str transfer #2 引用,必须保留 per-plate 节点;"
|
|
||||||
f" 实际 per_plate_keys={per_plate_keys}"
|
|
||||||
)
|
|
||||||
assert "t_B" not in per_plate_keys, "t_B 仅出现在 list-targets,应跳过"
|
|
||||||
assert "t_C" not in per_plate_keys, "t_C 仅出现在 list-targets,应跳过"
|
|
||||||
|
|
||||||
# merged 节点数:1(仅 list-targets transfer #1 生成)
|
|
||||||
assert len(merged) == 1
|
|
||||||
|
|
||||||
|
|
||||||
def test_str_targets_protocol_unaffected():
|
|
||||||
"""单 slot 协议(全 str-targets)→ 每个 target reagent_key 仍有 per-plate(零回归)。"""
|
|
||||||
labware = _labware_with_targets(["t_A", "t_B"], source_keys=["src_1"])
|
|
||||||
steps = [
|
|
||||||
{
|
|
||||||
"action": "transfer_liquid",
|
|
||||||
"parameters": {
|
|
||||||
"sources": "src_1",
|
|
||||||
"targets": "t_A",
|
|
||||||
"tip_racks": "tiprack_12",
|
|
||||||
"asp_vols": [10.0],
|
|
||||||
"dis_vols": [10.0],
|
|
||||||
},
|
|
||||||
"step_number": 1,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"action": "transfer_liquid",
|
|
||||||
"parameters": {
|
|
||||||
"sources": "src_1",
|
|
||||||
"targets": "t_B",
|
|
||||||
"tip_racks": "tiprack_12",
|
|
||||||
"asp_vols": [20.0],
|
|
||||||
"dis_vols": [20.0],
|
|
||||||
},
|
|
||||||
"step_number": 2,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
g = build_protocol_graph(
|
|
||||||
labware_info=labware,
|
|
||||||
protocol_steps=steps,
|
|
||||||
workstation_name="PRCXI",
|
|
||||||
)
|
|
||||||
|
|
||||||
per_plate, merged = _set_liquid_nodes_split(g)
|
|
||||||
per_plate_keys = {
|
|
||||||
n.get("description", "").replace("Set liquid: ", "")
|
|
||||||
for n in per_plate
|
|
||||||
}
|
|
||||||
|
|
||||||
assert merged == [], "全 str-targets 协议不应触发 merged 节点"
|
|
||||||
assert {"src_1", "t_A", "t_B"}.issubset(per_plate_keys), (
|
|
||||||
f"单 slot 协议每个 reagent_key(含 source/target)都应保留 per-plate;"
|
|
||||||
f" 实际 {per_plate_keys}"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_51b9a5_style_node_count():
|
|
||||||
"""大规模场景:N 个 list-targets transfers,每个长度 M(同 source 不同跨板)。
|
|
||||||
|
|
||||||
构造:2 个 source(src_A1、src_A2)+ 9 个 target plates × 2 个 well = 18 target reagent_keys。
|
|
||||||
2 个 transfer:
|
|
||||||
- transfer #1: targets = [t_A1_1, t_A1_2, ..., t_A1_9](同 source src_A1,跨 9 plate)
|
|
||||||
- transfer #2: targets = [t_A2_1, t_A2_2, ..., t_A2_9](同 source src_A2,跨 9 plate)
|
|
||||||
|
|
||||||
期望 set_liquid_from_plate 总节点数 = 2 source per-plate + 2 merged + 0 target per-plate = 4。
|
|
||||||
"""
|
|
||||||
target_keys_a1 = [f"t_A1_{i}" for i in range(1, 10)]
|
|
||||||
target_keys_a2 = [f"t_A2_{i}" for i in range(1, 10)]
|
|
||||||
all_target_keys = target_keys_a1 + target_keys_a2
|
|
||||||
|
|
||||||
labware = _labware_with_targets(
|
|
||||||
all_target_keys,
|
|
||||||
source_keys=["src_A1", "src_A2"],
|
|
||||||
)
|
|
||||||
|
|
||||||
steps = [
|
|
||||||
{
|
|
||||||
"action": "transfer_liquid",
|
|
||||||
"parameters": {
|
|
||||||
"sources": "src_A1",
|
|
||||||
"targets": target_keys_a1,
|
|
||||||
"tip_racks": "tiprack_12",
|
|
||||||
"asp_vols": [8.3] * 9,
|
|
||||||
"dis_vols": [8.3] * 9,
|
|
||||||
},
|
|
||||||
"step_number": 1,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"action": "transfer_liquid",
|
|
||||||
"parameters": {
|
|
||||||
"sources": "src_A2",
|
|
||||||
"targets": target_keys_a2,
|
|
||||||
"tip_racks": "tiprack_12",
|
|
||||||
"asp_vols": [8.3] * 9,
|
|
||||||
"dis_vols": [8.3] * 9,
|
|
||||||
},
|
|
||||||
"step_number": 2,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
g = build_protocol_graph(
|
|
||||||
labware_info=labware,
|
|
||||||
protocol_steps=steps,
|
|
||||||
workstation_name="PRCXI",
|
|
||||||
)
|
|
||||||
|
|
||||||
per_plate, merged = _set_liquid_nodes_split(g)
|
|
||||||
|
|
||||||
assert len(merged) == 2, f"应有 2 个 merged 节点;实际 {len(merged)}"
|
|
||||||
|
|
||||||
per_plate_keys = {
|
|
||||||
n.get("description", "").replace("Set liquid: ", "")
|
|
||||||
for n in per_plate
|
|
||||||
}
|
|
||||||
|
|
||||||
# source 端:2 个 per-plate
|
|
||||||
assert "src_A1" in per_plate_keys and "src_A2" in per_plate_keys, (
|
|
||||||
f"source 端必须有 src_A1 + src_A2 per-plate;实际 {per_plate_keys}"
|
|
||||||
)
|
|
||||||
|
|
||||||
# target 端:18 个全部被跳过
|
|
||||||
for tk in all_target_keys:
|
|
||||||
assert tk not in per_plate_keys, (
|
|
||||||
f"§14:target reagent_key '{tk}' 应被 merged 覆盖并跳过;"
|
|
||||||
f" 实际 per_plate_keys 包含 {tk}"
|
|
||||||
)
|
|
||||||
|
|
||||||
# 总节点数 == 2 + 2
|
|
||||||
assert len(per_plate) + len(merged) == 4, (
|
|
||||||
f"set_liquid_from_plate 总节点数应为 4 (2 source + 2 merged + 0 target per-plate);"
|
|
||||||
f" 实际 per_plate={len(per_plate)} merged={len(merged)}"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_source_per_plate_always_kept():
|
|
||||||
"""source reagent_keys 不出现在任何 targets 字段中 → per-plate 节点恒保留(与 §14 无关)。"""
|
|
||||||
target_keys = ["t_A", "t_B", "t_C"]
|
|
||||||
labware = _labware_with_targets(target_keys, source_keys=["src_X", "src_Y"])
|
|
||||||
|
|
||||||
steps = [
|
|
||||||
{
|
|
||||||
"action": "transfer_liquid",
|
|
||||||
"parameters": {
|
|
||||||
"sources": "src_X",
|
|
||||||
"targets": target_keys,
|
|
||||||
"tip_racks": "tiprack_12",
|
|
||||||
"asp_vols": [5.0] * 3,
|
|
||||||
"dis_vols": [5.0] * 3,
|
|
||||||
},
|
|
||||||
"step_number": 1,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"action": "transfer_liquid",
|
|
||||||
"parameters": {
|
|
||||||
"sources": "src_Y",
|
|
||||||
"targets": "t_A",
|
|
||||||
"tip_racks": "tiprack_12",
|
|
||||||
"asp_vols": [10.0],
|
|
||||||
"dis_vols": [10.0],
|
|
||||||
},
|
|
||||||
"step_number": 2,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
g = build_protocol_graph(
|
|
||||||
labware_info=labware,
|
|
||||||
protocol_steps=steps,
|
|
||||||
workstation_name="PRCXI",
|
|
||||||
)
|
|
||||||
|
|
||||||
per_plate, _ = _set_liquid_nodes_split(g)
|
|
||||||
per_plate_keys = {
|
|
||||||
n.get("description", "").replace("Set liquid: ", "")
|
|
||||||
for n in per_plate
|
|
||||||
}
|
|
||||||
|
|
||||||
assert "src_X" in per_plate_keys, "source src_X 必须有 per-plate(source 不会被 §14 跳过)"
|
|
||||||
assert "src_Y" in per_plate_keys, "source src_Y 必须有 per-plate"
|
|
||||||
@@ -1,534 +0,0 @@
|
|||||||
"""P6 / P6.1 / P6.1.1 `labware_mapping.py` 单元测试 —— 对应 06-labware-mapping-table.md §11.7.7 / §11.8.7。
|
|
||||||
|
|
||||||
这些用例只依赖 `unilabos.workflow.labware_mapping` 自身与 PyYAML,
|
|
||||||
不需要 ROS2 / matplotlib / networkx 等环境,可直接 `pytest tests/workflow/test_labware_mapping.py`。
|
|
||||||
|
|
||||||
P6.1.1 schema(v1.9):
|
|
||||||
- 顶层 key 两段:``kinds`` / ``target_devices``(**P6.1.1 起顶层 `slot_remap` 已不支持**,下沉到 ``target_devices.<device>`` 内)
|
|
||||||
- ``target_devices.default`` 是固定段名,作为兜底物料集,第一版按 prcxi 拷贝填充,**不支持 `models` 子段**
|
|
||||||
- ``target_devices.<device>.models.<model>`` 是可选的型号粒度覆盖(slot_remap / rules)
|
|
||||||
- 旧 schema(顶层 ``vendors`` / ``slot_remap`` 或 rule 含 ``prcxi_class``)会触发 warning + fallback 到 builtin
|
|
||||||
"""
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import sys
|
|
||||||
import warnings
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
ROOT_DIR = Path(__file__).resolve().parents[2]
|
|
||||||
if str(ROOT_DIR) not in sys.path:
|
|
||||||
sys.path.insert(0, str(ROOT_DIR))
|
|
||||||
|
|
||||||
from unilabos.workflow import labware_mapping as lm
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
|
||||||
def _reset_lru_cache():
|
|
||||||
"""每个用例后清缓存,避免 monkeypatch 跨用例污染。"""
|
|
||||||
yield
|
|
||||||
lm.reload_mapping()
|
|
||||||
|
|
||||||
|
|
||||||
# ==================== slot_remap ====================
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
"raw,object_type,want",
|
|
||||||
[
|
|
||||||
("4", "", "13"),
|
|
||||||
("8", "", "14"),
|
|
||||||
("12", "trash", "16"),
|
|
||||||
("12", "source", "12"),
|
|
||||||
("1", "", "1"),
|
|
||||||
("", "", ""),
|
|
||||||
(4, "", "13"), # 非字符串入参也应规整
|
|
||||||
],
|
|
||||||
)
|
|
||||||
def test_remap_slot_basic(raw, object_type, want):
|
|
||||||
assert lm.remap_slot(raw, object_type) == want
|
|
||||||
|
|
||||||
|
|
||||||
def test_remap_slot_none_returns_empty():
|
|
||||||
assert lm.remap_slot(None) == ""
|
|
||||||
|
|
||||||
|
|
||||||
def test_remap_slot_passthrough_unknown():
|
|
||||||
assert lm.remap_slot("99") == "99"
|
|
||||||
|
|
||||||
|
|
||||||
# ==================== infer_kind ====================
|
|
||||||
|
|
||||||
|
|
||||||
def test_infer_kind_trash_priority():
|
|
||||||
"""`trash` 在 kinds 列表第 1 条 → 优先于含 'rack' 的字符串。"""
|
|
||||||
assert lm.infer_kind("foo_trash_bar") == "trash"
|
|
||||||
assert lm.infer_kind("opentrons_fixed_trash") == "trash"
|
|
||||||
|
|
||||||
|
|
||||||
def test_infer_kind_tiprack_before_tuberack():
|
|
||||||
"""`tiprack` 子串包含 'rack',但应被 tip_rack 规则先抓到(顺序敏感)。"""
|
|
||||||
assert lm.infer_kind("opentrons_96_tiprack_300ul") == "tip_rack"
|
|
||||||
assert lm.infer_kind("opentrons_96_tiprack_20ul") == "tip_rack"
|
|
||||||
|
|
||||||
|
|
||||||
def test_infer_kind_tube_rack_variants():
|
|
||||||
assert (
|
|
||||||
lm.infer_kind("opentrons_24_tuberack_eppendorf_2ml_safelock_snapcap")
|
|
||||||
== "tube_rack"
|
|
||||||
)
|
|
||||||
assert lm.infer_kind("opentrons_10_tuberack_falcon_4x50ml_6x15ml_conical") == "tube_rack"
|
|
||||||
|
|
||||||
|
|
||||||
def test_infer_kind_object_overrides_string():
|
|
||||||
"""object 字段优先:即使字符串看起来像 plate,trash / tiprack 也能强制归类。"""
|
|
||||||
assert lm.infer_kind("anything_at_all", "tiprack") == "tip_rack"
|
|
||||||
assert lm.infer_kind("opentrons_96_wellplate", "trash") == "trash"
|
|
||||||
|
|
||||||
|
|
||||||
def test_infer_kind_default_plate():
|
|
||||||
assert lm.infer_kind("opentrons_96_wellplate_300ul_pcr") == "plate"
|
|
||||||
assert lm.infer_kind("custom_384_wellplate_2200ul") == "plate"
|
|
||||||
|
|
||||||
|
|
||||||
def test_infer_kind_rack_without_tip_is_tube_rack():
|
|
||||||
"""复现历史 `_infer_reagent_kind` 中「含 rack 不含 tip → tube_rack」的语义。"""
|
|
||||||
assert lm.infer_kind("nest_4x6_rack") == "tube_rack"
|
|
||||||
|
|
||||||
|
|
||||||
def test_infer_kind_empty_hint_returns_plate():
|
|
||||||
assert lm.infer_kind("") == "plate"
|
|
||||||
assert lm.infer_kind(None) == "plate" # type: ignore[arg-type]
|
|
||||||
|
|
||||||
|
|
||||||
# ==================== resolve_target_class(target_device="prcxi") ====================
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
"vol,want",
|
|
||||||
[
|
|
||||||
(1, "PRCXI_10uL_Tips"),
|
|
||||||
(9, "PRCXI_10uL_Tips"),
|
|
||||||
(10, "PRCXI_10uL_Tips"), # 闭区间 ≤10
|
|
||||||
(11, "PRCXI_300ul_Tips"),
|
|
||||||
(200, "PRCXI_300ul_Tips"),
|
|
||||||
(299.9, "PRCXI_300ul_Tips"),
|
|
||||||
(300, "PRCXI_1000uL_Tips"), # 300 上一档(与 <300 半开等价)
|
|
||||||
(500, "PRCXI_1000uL_Tips"),
|
|
||||||
(1000, "PRCXI_1000uL_Tips"),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
def test_resolve_tip_volume_buckets(vol, want):
|
|
||||||
assert lm.resolve_target_class("prcxi", "tip_rack", 96, vol) == want
|
|
||||||
|
|
||||||
|
|
||||||
def test_resolve_tube_rack_holes():
|
|
||||||
assert lm.resolve_target_class("prcxi", "tube_rack", 24, None) == "PRCXI_EP_Adapter"
|
|
||||||
assert lm.resolve_target_class("prcxi", "tube_rack", 10, None) == "PRCXI_EP_Adapter"
|
|
||||||
|
|
||||||
|
|
||||||
def test_resolve_plate_holes():
|
|
||||||
assert lm.resolve_target_class("prcxi", "plate", 96, None) == "PRCXI_BioER_96_wellplate"
|
|
||||||
assert (
|
|
||||||
lm.resolve_target_class("prcxi", "plate", 384, None) == "PRCXI_BioER_384_wellplate"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_resolve_plate_unknown_holes_returns_none():
|
|
||||||
"""48 孔板未在 YAML 列出 → None;交给 PRCXI 模板打分匹配 fallback。"""
|
|
||||||
assert lm.resolve_target_class("prcxi", "plate", 48, 2200) is None
|
|
||||||
|
|
||||||
|
|
||||||
def test_resolve_trash_any():
|
|
||||||
assert lm.resolve_target_class("prcxi", "trash", None, None) == "PRCXI_trash"
|
|
||||||
# trash 规则未约束 hole_count / volume,所以任意值都命中
|
|
||||||
assert lm.resolve_target_class("prcxi", "trash", 0, 0) == "PRCXI_trash"
|
|
||||||
|
|
||||||
|
|
||||||
# ==================== YAML 缺失 / 热加载 ====================
|
|
||||||
|
|
||||||
|
|
||||||
def test_missing_yaml_uses_builtin(monkeypatch, tmp_path):
|
|
||||||
"""YAML 文件不存在时,应自动落到 `_BUILTIN_DEFAULT`,且打 warning。"""
|
|
||||||
bogus = tmp_path / "no_such_labware_mapping.yaml"
|
|
||||||
monkeypatch.setattr(lm, "_DEFAULT_PATH", bogus)
|
|
||||||
lm._load_mapping.cache_clear()
|
|
||||||
with warnings.catch_warnings(record=True) as caught:
|
|
||||||
warnings.simplefilter("always")
|
|
||||||
assert lm.remap_slot("4") == "13"
|
|
||||||
assert (
|
|
||||||
lm.resolve_target_class("prcxi", "plate", 96, None)
|
|
||||||
== "PRCXI_BioER_96_wellplate"
|
|
||||||
)
|
|
||||||
assert any("labware_mapping.yaml 未找到" in str(w.message) for w in caught)
|
|
||||||
|
|
||||||
|
|
||||||
def test_invalid_yaml_uses_builtin(monkeypatch, tmp_path):
|
|
||||||
"""YAML 解析失败也应回退到 builtin,且打 warning。"""
|
|
||||||
bad = tmp_path / "labware_mapping.yaml"
|
|
||||||
bad.write_text("this is :: not valid: yaml: [unclosed", encoding="utf-8")
|
|
||||||
monkeypatch.setattr(lm, "_DEFAULT_PATH", bad)
|
|
||||||
lm._load_mapping.cache_clear()
|
|
||||||
with warnings.catch_warnings(record=True) as caught:
|
|
||||||
warnings.simplefilter("always")
|
|
||||||
assert lm.remap_slot("4") == "13"
|
|
||||||
assert any(
|
|
||||||
"labware_mapping.yaml 解析失败" in str(w.message)
|
|
||||||
or "labware_mapping.yaml 根不是 dict" in str(w.message)
|
|
||||||
for w in caught
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_yaml_reload_after_edit(monkeypatch, tmp_path):
|
|
||||||
"""临时 YAML 覆盖 + reload_mapping → 新规则生效,且原规则失效(P6.1.1 schema)。"""
|
|
||||||
tmp_yaml = tmp_path / "labware_mapping.yaml"
|
|
||||||
tmp_yaml.write_text(
|
|
||||||
'kinds:\n'
|
|
||||||
" - { pattern: 'trash', kind: trash }\n"
|
|
||||||
" - { pattern: '.*', kind: plate }\n"
|
|
||||||
'target_devices:\n'
|
|
||||||
' default:\n'
|
|
||||||
' slot_remap:\n'
|
|
||||||
' default: {"4": "99"}\n'
|
|
||||||
' by_object: {}\n'
|
|
||||||
' rules:\n'
|
|
||||||
" - { kind: plate, hole_count: 96, class_name: PRCXI_FooPlate }\n"
|
|
||||||
' prcxi:\n'
|
|
||||||
' slot_remap:\n'
|
|
||||||
' default: {"4": "99"}\n'
|
|
||||||
' by_object: {}\n'
|
|
||||||
' rules:\n'
|
|
||||||
" - { kind: plate, hole_count: 96, class_name: PRCXI_FooPlate }\n",
|
|
||||||
encoding="utf-8",
|
|
||||||
)
|
|
||||||
monkeypatch.setattr(lm, "_DEFAULT_PATH", tmp_yaml)
|
|
||||||
lm.reload_mapping()
|
|
||||||
assert lm.remap_slot("4") == "99"
|
|
||||||
assert lm.resolve_target_class("prcxi", "plate", 96, None) == "PRCXI_FooPlate"
|
|
||||||
# 新表里只有 96,没有 384 → None
|
|
||||||
assert lm.resolve_target_class("prcxi", "plate", 384, None) is None
|
|
||||||
# tube_rack / tip_rack 在新表里没规则 → None
|
|
||||||
assert lm.resolve_target_class("prcxi", "tip_rack", 96, 200) is None
|
|
||||||
|
|
||||||
|
|
||||||
def test_missing_section_uses_builtin(monkeypatch, tmp_path):
|
|
||||||
"""YAML 缺 `kinds` 段 → 该段使用 builtin,其它段保留用户值(P6.1.1 schema)。"""
|
|
||||||
partial = tmp_path / "labware_mapping.yaml"
|
|
||||||
partial.write_text(
|
|
||||||
'target_devices:\n'
|
|
||||||
' default:\n'
|
|
||||||
' slot_remap:\n'
|
|
||||||
' default: {"4": "88"}\n'
|
|
||||||
' by_object: {}\n'
|
|
||||||
' rules: []\n'
|
|
||||||
' prcxi:\n'
|
|
||||||
' slot_remap:\n'
|
|
||||||
' default: {"4": "88"}\n'
|
|
||||||
' by_object: {}\n'
|
|
||||||
' rules: []\n', # 故意没有 kinds 段
|
|
||||||
encoding="utf-8",
|
|
||||||
)
|
|
||||||
monkeypatch.setattr(lm, "_DEFAULT_PATH", partial)
|
|
||||||
lm._load_mapping.cache_clear()
|
|
||||||
with warnings.catch_warnings(record=True) as caught:
|
|
||||||
warnings.simplefilter("always")
|
|
||||||
# slot_remap 用 YAML 中的覆盖值
|
|
||||||
assert lm.remap_slot("4") == "88"
|
|
||||||
# kinds 段缺失 → 使用 builtin 的 tiprack 规则
|
|
||||||
assert lm.infer_kind("opentrons_96_tiprack_300ul") == "tip_rack"
|
|
||||||
assert any("缺少 `kinds` 段" in str(w.message) for w in caught)
|
|
||||||
|
|
||||||
|
|
||||||
# ==================== P6.1 新增用例 ====================
|
|
||||||
|
|
||||||
|
|
||||||
def test_resolve_target_class_prcxi_tip_buckets():
|
|
||||||
"""PRCXI tip 量程档:≤10 / <300 / 否则 1000(与历史 _tip_prcxi_class_for_max_ul 等价)。"""
|
|
||||||
assert lm.resolve_target_class("prcxi", "tip_rack", 96, 10) == "PRCXI_10uL_Tips"
|
|
||||||
assert lm.resolve_target_class("prcxi", "tip_rack", 96, 200) == "PRCXI_300ul_Tips"
|
|
||||||
assert lm.resolve_target_class("prcxi", "tip_rack", 96, 1000) == "PRCXI_1000uL_Tips"
|
|
||||||
|
|
||||||
|
|
||||||
def test_resolve_target_class_unknown_device_falls_back_to_default_section():
|
|
||||||
"""未声明的 target_device 自动回退到固定段 target_devices.default,打 warning。
|
|
||||||
第一版 default 段内容按 prcxi 拷贝 → 断言:caller 传 'tecan' 时,结果应等于查 default 段。"""
|
|
||||||
with warnings.catch_warnings(record=True) as caught:
|
|
||||||
warnings.simplefilter("always")
|
|
||||||
# tecan / beckman / 任意未声明名字 → 全部回退到固定段 "default"
|
|
||||||
assert (
|
|
||||||
lm.resolve_target_class("tecan", "tip_rack", 96, 200)
|
|
||||||
== lm.resolve_target_class("default", "tip_rack", 96, 200)
|
|
||||||
== "PRCXI_300ul_Tips" # 第一版 default 段按 prcxi 填,所以值仍是 PRCXI_*
|
|
||||||
)
|
|
||||||
assert (
|
|
||||||
lm.resolve_target_class("unknown_xxx", "plate", 96, None)
|
|
||||||
== lm.resolve_target_class("default", "plate", 96, None)
|
|
||||||
)
|
|
||||||
# 至少打 1 次 warning,提示「未声明、已回退到 default 段」
|
|
||||||
assert any(
|
|
||||||
("未在 labware_mapping.yaml" in str(w.message))
|
|
||||||
or ("target_devices.default" in str(w.message))
|
|
||||||
for w in caught
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_resolve_target_class_per_device_tip_buckets(tmp_path, monkeypatch):
|
|
||||||
"""**P6.1 核心断言**:不同 target_device 在同一体积下命中不同 tip 量程档(P6.1.1 schema)。"""
|
|
||||||
yaml_path = tmp_path / "labware_mapping.yaml"
|
|
||||||
yaml_path.write_text(
|
|
||||||
'kinds: [{pattern: ".*", kind: plate}]\n'
|
|
||||||
'target_devices:\n'
|
|
||||||
' default:\n'
|
|
||||||
' slot_remap: {default: {}, by_object: {}}\n'
|
|
||||||
' rules:\n'
|
|
||||||
' - {kind: tip_rack, hole_count: 96, volume_max: 10, class_name: PRCXI_10uL_Tips}\n'
|
|
||||||
' - {kind: tip_rack, hole_count: 96, volume_max: 299.9, class_name: PRCXI_300ul_Tips}\n'
|
|
||||||
' - {kind: tip_rack, hole_count: 96, class_name: PRCXI_1000uL_Tips}\n'
|
|
||||||
' prcxi:\n'
|
|
||||||
' slot_remap: {default: {}, by_object: {}}\n'
|
|
||||||
' rules:\n'
|
|
||||||
' - {kind: tip_rack, hole_count: 96, volume_max: 10, class_name: PRCXI_10uL_Tips}\n'
|
|
||||||
' - {kind: tip_rack, hole_count: 96, volume_max: 299.9, class_name: PRCXI_300ul_Tips}\n'
|
|
||||||
' - {kind: tip_rack, hole_count: 96, class_name: PRCXI_1000uL_Tips}\n'
|
|
||||||
' beckman:\n'
|
|
||||||
' slot_remap: {default: {}, by_object: {}}\n'
|
|
||||||
' rules:\n'
|
|
||||||
' - {kind: tip_rack, hole_count: 96, volume_max: 20, class_name: Beckman_20uL_Tips}\n'
|
|
||||||
' - {kind: tip_rack, hole_count: 96, volume_max: 199.9, class_name: Beckman_200uL_Tips}\n'
|
|
||||||
' - {kind: tip_rack, hole_count: 96, class_name: Beckman_1000uL_Tips}\n',
|
|
||||||
encoding="utf-8",
|
|
||||||
)
|
|
||||||
monkeypatch.setattr(lm, "_DEFAULT_PATH", yaml_path)
|
|
||||||
lm.reload_mapping()
|
|
||||||
|
|
||||||
# 同样的体积 200:prcxi 走 300 档、beckman 已超出 200 档 → 1000 档
|
|
||||||
assert lm.resolve_target_class("prcxi", "tip_rack", 96, 200) == "PRCXI_300ul_Tips"
|
|
||||||
assert lm.resolve_target_class("beckman", "tip_rack", 96, 200) == "Beckman_1000uL_Tips"
|
|
||||||
# 同样的体积 15:prcxi 已超出 10 档 → 300 档;beckman 仍在 20 档
|
|
||||||
assert lm.resolve_target_class("prcxi", "tip_rack", 96, 15) == "PRCXI_300ul_Tips"
|
|
||||||
assert lm.resolve_target_class("beckman", "tip_rack", 96, 15) == "Beckman_20uL_Tips"
|
|
||||||
|
|
||||||
|
|
||||||
def test_default_section_independent_from_prcxi(tmp_path, monkeypatch):
|
|
||||||
"""default 与 prcxi 是两段独立物料集:改 default 不影响 prcxi、改 prcxi 不影响 default。
|
|
||||||
|
|
||||||
断言:把 default 段改成 Generic_Plate96,prcxi 段保持 PRCXI_Plate96 时,
|
|
||||||
caller 传未声明的名字回退到 default 拿 Generic_Plate96,传 prcxi 仍拿 PRCXI_Plate96。
|
|
||||||
"""
|
|
||||||
yaml_path = tmp_path / "labware_mapping.yaml"
|
|
||||||
yaml_path.write_text(
|
|
||||||
'kinds: [{pattern: ".*", kind: plate}]\n'
|
|
||||||
'target_devices:\n'
|
|
||||||
' default:\n' # ← 独立改 default 段
|
|
||||||
' slot_remap: {default: {}, by_object: {}}\n'
|
|
||||||
' rules:\n'
|
|
||||||
' - {kind: plate, hole_count: 96, class_name: Generic_Plate96}\n'
|
|
||||||
' prcxi:\n' # ← prcxi 段保持 PRCXI_*
|
|
||||||
' slot_remap: {default: {}, by_object: {}}\n'
|
|
||||||
' rules:\n'
|
|
||||||
' - {kind: plate, hole_count: 96, class_name: PRCXI_Plate96}\n',
|
|
||||||
encoding="utf-8",
|
|
||||||
)
|
|
||||||
monkeypatch.setattr(lm, "_DEFAULT_PATH", yaml_path)
|
|
||||||
lm.reload_mapping()
|
|
||||||
|
|
||||||
# caller 传未声明的 tecan → 走 default 段 → Generic_*
|
|
||||||
assert lm.resolve_target_class("tecan", "plate", 96, None) == "Generic_Plate96"
|
|
||||||
# caller 显式传 prcxi → 走 prcxi 段 → PRCXI_*(**不**受 default 影响)
|
|
||||||
assert lm.resolve_target_class("prcxi", "plate", 96, None) == "PRCXI_Plate96"
|
|
||||||
# 显式传 "default" 也合法(caller 可主动选择走 default 段)
|
|
||||||
assert lm.resolve_target_class("default", "plate", 96, None) == "Generic_Plate96"
|
|
||||||
|
|
||||||
|
|
||||||
def test_legacy_yaml_schema_rejected_with_warning(tmp_path, monkeypatch):
|
|
||||||
"""旧 schema(vendors / prcxi_class)应被拒绝 + warning + 整段 fallback 到 builtin(P6.1.1 schema)。"""
|
|
||||||
legacy = tmp_path / "labware_mapping.yaml"
|
|
||||||
legacy.write_text(
|
|
||||||
'kinds: [{pattern: ".*", kind: plate}]\n'
|
|
||||||
'vendors:\n' # ← 旧顶层 key
|
|
||||||
' opentrons:\n'
|
|
||||||
' rules:\n'
|
|
||||||
" - {kind: plate, hole_count: 96, prcxi_class: PRCXI_FooPlate}\n", # ← 旧字段
|
|
||||||
encoding="utf-8",
|
|
||||||
)
|
|
||||||
monkeypatch.setattr(lm, "_DEFAULT_PATH", legacy)
|
|
||||||
lm._load_mapping.cache_clear()
|
|
||||||
with warnings.catch_warnings(record=True) as caught:
|
|
||||||
warnings.simplefilter("always")
|
|
||||||
# 整段走 builtin → 96 板还是 PRCXI_BioER_96_wellplate(**不是**用户旧 YAML 中的 PRCXI_FooPlate)
|
|
||||||
assert lm.resolve_target_class("prcxi", "plate", 96, None) == "PRCXI_BioER_96_wellplate"
|
|
||||||
assert any(
|
|
||||||
("旧 schema" in str(w.message))
|
|
||||||
or ("vendors" in str(w.message))
|
|
||||||
or ("prcxi_class" in str(w.message))
|
|
||||||
for w in caught
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_resolve_target_class_unknown_kind_returns_none():
|
|
||||||
"""target_device 存在、kind 不存在 → None。"""
|
|
||||||
assert lm.resolve_target_class("prcxi", "reservoir", 12, None) is None
|
|
||||||
|
|
||||||
|
|
||||||
# ==================== P6.1.1 新增用例(slot_remap 按 device + model 分叉) ====================
|
|
||||||
|
|
||||||
|
|
||||||
def test_remap_slot_model_level_overrides_device_level(tmp_path, monkeypatch):
|
|
||||||
"""型号级 slot_remap 优先级 > 厂商级。"""
|
|
||||||
yaml_path = tmp_path / "labware_mapping.yaml"
|
|
||||||
yaml_path.write_text(
|
|
||||||
'kinds: [{pattern: ".*", kind: plate}]\n'
|
|
||||||
'target_devices:\n'
|
|
||||||
' default:\n'
|
|
||||||
' slot_remap: {default: {"4": "13"}, by_object: {}}\n'
|
|
||||||
' rules: []\n'
|
|
||||||
' prcxi:\n'
|
|
||||||
' slot_remap: {default: {"4": "13"}, by_object: {trash: {"12": "16"}}}\n'
|
|
||||||
' rules: []\n'
|
|
||||||
' models:\n'
|
|
||||||
' "4040":\n'
|
|
||||||
' slot_remap: {default: {"4": "16"}, by_object: {}}\n',
|
|
||||||
encoding="utf-8",
|
|
||||||
)
|
|
||||||
monkeypatch.setattr(lm, "_DEFAULT_PATH", yaml_path)
|
|
||||||
lm.reload_mapping()
|
|
||||||
# device 级(不传 model)→ "13"
|
|
||||||
assert lm.remap_slot("4", target_device="prcxi") == "13"
|
|
||||||
# model "4040" 覆盖 → "16"
|
|
||||||
assert lm.remap_slot("4", target_device="prcxi", target_model="4040") == "16"
|
|
||||||
# model "9320" 未声明 → 静默 fallback 到 device 级 → "13"
|
|
||||||
assert lm.remap_slot("4", target_device="prcxi", target_model="9320") == "13"
|
|
||||||
|
|
||||||
|
|
||||||
def test_remap_slot_model_inherits_device_when_field_missing(tmp_path, monkeypatch):
|
|
||||||
"""model 子段声明但 slot_remap 字段缺失 → 静默继承厂商级;rules 同理。"""
|
|
||||||
yaml_path = tmp_path / "labware_mapping.yaml"
|
|
||||||
yaml_path.write_text(
|
|
||||||
'kinds: [{pattern: ".*", kind: plate}]\n'
|
|
||||||
'target_devices:\n'
|
|
||||||
' default:\n'
|
|
||||||
' slot_remap: {default: {}, by_object: {}}\n'
|
|
||||||
' rules: []\n'
|
|
||||||
' prcxi:\n'
|
|
||||||
' slot_remap: {default: {"4": "13", "8": "14"}, by_object: {}}\n'
|
|
||||||
' rules: [{kind: plate, hole_count: 96, class_name: PRCXI_PlateA}]\n'
|
|
||||||
' models:\n'
|
|
||||||
' "9320":\n'
|
|
||||||
' rules: [{kind: plate, hole_count: 96, class_name: PRCXI_PlateB}]\n', # 仅覆盖 rules,未声明 slot_remap
|
|
||||||
encoding="utf-8",
|
|
||||||
)
|
|
||||||
monkeypatch.setattr(lm, "_DEFAULT_PATH", yaml_path)
|
|
||||||
lm.reload_mapping()
|
|
||||||
# model 9320 的 slot_remap 缺字段 → 继承 prcxi.slot_remap → "4" → "13"
|
|
||||||
assert lm.remap_slot("4", target_device="prcxi", target_model="9320") == "13"
|
|
||||||
# model 9320 的 rules 覆盖 → PRCXI_PlateB
|
|
||||||
assert (
|
|
||||||
lm.resolve_target_class("prcxi", "plate", 96, None, target_model="9320")
|
|
||||||
== "PRCXI_PlateB"
|
|
||||||
)
|
|
||||||
# 不传 model → 用厂商级 rules → PRCXI_PlateA
|
|
||||||
assert lm.resolve_target_class("prcxi", "plate", 96, None) == "PRCXI_PlateA"
|
|
||||||
|
|
||||||
|
|
||||||
def test_legacy_top_level_slot_remap_rejected(tmp_path, monkeypatch):
|
|
||||||
"""P6.1.1:顶层 slot_remap 段被视为旧 schema → warning + 整段 fallback 到 builtin。"""
|
|
||||||
legacy = tmp_path / "labware_mapping.yaml"
|
|
||||||
legacy.write_text(
|
|
||||||
'slot_remap:\n' # ← P6.1.1 已不支持的顶层段
|
|
||||||
' default: {"4": "99"}\n'
|
|
||||||
' by_object: {}\n'
|
|
||||||
'kinds: [{pattern: ".*", kind: plate}]\n'
|
|
||||||
'target_devices:\n'
|
|
||||||
' default:\n'
|
|
||||||
' slot_remap: {default: {"4": "13"}, by_object: {}}\n'
|
|
||||||
' rules: []\n'
|
|
||||||
' prcxi:\n'
|
|
||||||
' slot_remap: {default: {"4": "13"}, by_object: {}}\n'
|
|
||||||
' rules: []\n',
|
|
||||||
encoding="utf-8",
|
|
||||||
)
|
|
||||||
monkeypatch.setattr(lm, "_DEFAULT_PATH", legacy)
|
|
||||||
lm._load_mapping.cache_clear()
|
|
||||||
with warnings.catch_warnings(record=True) as caught:
|
|
||||||
warnings.simplefilter("always")
|
|
||||||
# 整段走 builtin → "4" 仍然 → "13"(builtin 值),**不是** YAML 顶层的 "99"
|
|
||||||
assert lm.remap_slot("4", target_device="prcxi") == "13"
|
|
||||||
assert any(
|
|
||||||
("顶层" in str(w.message) and "slot_remap" in str(w.message))
|
|
||||||
or ("旧 schema" in str(w.message))
|
|
||||||
for w in caught
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_remap_slot_unknown_device_falls_back_with_warning(tmp_path, monkeypatch):
|
|
||||||
"""未声明的 target_device → fallback 到 default.slot_remap + warning(与 resolve_target_class 同语义)。"""
|
|
||||||
yaml_path = tmp_path / "labware_mapping.yaml"
|
|
||||||
yaml_path.write_text(
|
|
||||||
'kinds: [{pattern: ".*", kind: plate}]\n'
|
|
||||||
'target_devices:\n'
|
|
||||||
' default:\n'
|
|
||||||
' slot_remap: {default: {"4": "13"}, by_object: {}}\n'
|
|
||||||
' rules: []\n'
|
|
||||||
' prcxi:\n'
|
|
||||||
' slot_remap: {default: {"4": "13"}, by_object: {}}\n'
|
|
||||||
' rules: []\n',
|
|
||||||
encoding="utf-8",
|
|
||||||
)
|
|
||||||
monkeypatch.setattr(lm, "_DEFAULT_PATH", yaml_path)
|
|
||||||
lm.reload_mapping()
|
|
||||||
with warnings.catch_warnings(record=True) as caught:
|
|
||||||
warnings.simplefilter("always")
|
|
||||||
assert lm.remap_slot("4", target_device="tecan") == "13" # fallback 到 default
|
|
||||||
assert any(
|
|
||||||
("tecan" in str(w.message)) or ("target_devices.default" in str(w.message))
|
|
||||||
for w in caught
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_remap_slot_model_only_no_device_passthrough(tmp_path, monkeypatch):
|
|
||||||
"""caller 传 target_model 但 target_device 段不存在 → 直接走 default.slot_remap(model 名忽略)。"""
|
|
||||||
yaml_path = tmp_path / "labware_mapping.yaml"
|
|
||||||
yaml_path.write_text(
|
|
||||||
'kinds: [{pattern: ".*", kind: plate}]\n'
|
|
||||||
'target_devices:\n'
|
|
||||||
' default:\n'
|
|
||||||
' slot_remap: {default: {"4": "13"}, by_object: {}}\n'
|
|
||||||
' rules: []\n', # 没有 prcxi 段
|
|
||||||
encoding="utf-8",
|
|
||||||
)
|
|
||||||
monkeypatch.setattr(lm, "_DEFAULT_PATH", yaml_path)
|
|
||||||
lm.reload_mapping()
|
|
||||||
with warnings.catch_warnings(record=True):
|
|
||||||
warnings.simplefilter("always")
|
|
||||||
# target_device "prcxi" 不存在、target_model 即使传也忽略 → 走 default
|
|
||||||
assert lm.remap_slot("4", target_device="prcxi", target_model="9320") == "13"
|
|
||||||
|
|
||||||
|
|
||||||
def test_default_section_models_subsection_warns(tmp_path, monkeypatch):
|
|
||||||
"""target_devices.default.models 不被支持 → warning,但 default.slot_remap 仍生效。"""
|
|
||||||
yaml_path = tmp_path / "labware_mapping.yaml"
|
|
||||||
yaml_path.write_text(
|
|
||||||
'kinds: [{pattern: ".*", kind: plate}]\n'
|
|
||||||
'target_devices:\n'
|
|
||||||
' default:\n'
|
|
||||||
' slot_remap: {default: {"4": "13"}, by_object: {}}\n'
|
|
||||||
' rules: []\n'
|
|
||||||
' models:\n' # ← default 段不支持 models
|
|
||||||
' "ghost":\n'
|
|
||||||
' slot_remap: {default: {"4": "99"}, by_object: {}}\n'
|
|
||||||
' prcxi:\n'
|
|
||||||
' slot_remap: {default: {"4": "13"}, by_object: {}}\n'
|
|
||||||
' rules: []\n',
|
|
||||||
encoding="utf-8",
|
|
||||||
)
|
|
||||||
monkeypatch.setattr(lm, "_DEFAULT_PATH", yaml_path)
|
|
||||||
lm._load_mapping.cache_clear()
|
|
||||||
with warnings.catch_warnings(record=True) as caught:
|
|
||||||
warnings.simplefilter("always")
|
|
||||||
# default 段的 models 被忽略 → 走 default.slot_remap → "13"(不是 "99")
|
|
||||||
assert lm.remap_slot("4", target_device="tecan", target_model="ghost") == "13"
|
|
||||||
assert any(
|
|
||||||
("default" in str(w.message) and "models" in str(w.message))
|
|
||||||
for w in caught
|
|
||||||
)
|
|
||||||
@@ -1,178 +0,0 @@
|
|||||||
"""``unilabos.workflow.wf_utils.upload_workflow`` 工作流名称 fallback 链单元测试。
|
|
||||||
|
|
||||||
对应需求:上传工作流时,**优先取 metadata.workflow_name**;缺失时再回退到顶层
|
|
||||||
``workflow_name``(旧 node-link 形态遗留字段);最后才回退到文件名(去 ``.json`` 后缀)。
|
|
||||||
CLI 显式 ``-n/--workflow_name`` 永远最优先。
|
|
||||||
|
|
||||||
本测试只校验「**名称 fallback 链 + tags fallback 链**」的纯逻辑路径,
|
|
||||||
不实际访问 HTTP / 后端;通过 monkeypatch 把 ``http_client.workflow_import``
|
|
||||||
桩成可观察的捕获函数。
|
|
||||||
"""
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import json
|
|
||||||
import sys
|
|
||||||
from pathlib import Path
|
|
||||||
from typing import Any, Dict, List, Optional
|
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
|
|
||||||
# 让 import 走 Uni-Lab-OS 包根
|
|
||||||
ROOT = Path(__file__).resolve().parents[2]
|
|
||||||
SRC = ROOT / "unilabos"
|
|
||||||
if str(ROOT) not in sys.path:
|
|
||||||
sys.path.insert(0, str(ROOT))
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def stub_upload(monkeypatch, tmp_path):
|
|
||||||
"""Monkeypatch ``http_client.workflow_import`` + ``_convert_to_node_link``,
|
|
||||||
返回 (helper, captured) 二元组:
|
|
||||||
|
|
||||||
- ``helper(workflow_data, **upload_kwargs)`` 写入 tmp_path/wf.json
|
|
||||||
并调用 ``upload_workflow``;
|
|
||||||
- ``captured`` 是 dict,记录 ``workflow_import`` 实际收到的 kwargs,
|
|
||||||
以及 ``_convert_to_node_link`` 是否被调过。
|
|
||||||
|
|
||||||
本测试不依赖真实 ``unilabos.app.web``(其级联依赖含 ``fastapi`` 等重型
|
|
||||||
package,本地 dev venv 不必装)。通过在 sys.modules 注入空壳 module 拦截
|
|
||||||
delayed import。
|
|
||||||
"""
|
|
||||||
import types
|
|
||||||
|
|
||||||
captured: Dict[str, Any] = {"workflow_import_kwargs": None, "converted": False}
|
|
||||||
|
|
||||||
def fake_workflow_import(**kwargs): # noqa: ANN003
|
|
||||||
captured["workflow_import_kwargs"] = kwargs
|
|
||||||
return {"code": 0, "data": {"uuid": "fake-uuid", "name": kwargs.get("name")}}
|
|
||||||
|
|
||||||
# 关键:在 wf_utils 触发 `from unilabos.app.web import http_client` 之前
|
|
||||||
# 用空壳 module 占位(避免触发真实 web 包的 fastapi 依赖链)。
|
|
||||||
fake_http_client = types.ModuleType("unilabos.app.web.http_client")
|
|
||||||
fake_http_client.workflow_import = fake_workflow_import # type: ignore[attr-defined]
|
|
||||||
fake_web_pkg = types.ModuleType("unilabos.app.web")
|
|
||||||
fake_web_pkg.http_client = fake_http_client # type: ignore[attr-defined]
|
|
||||||
monkeypatch.setitem(sys.modules, "unilabos.app.web", fake_web_pkg)
|
|
||||||
monkeypatch.setitem(sys.modules, "unilabos.app.web.http_client", fake_http_client)
|
|
||||||
|
|
||||||
from unilabos.workflow import wf_utils
|
|
||||||
|
|
||||||
# _convert_to_node_link 走真实路径会拉重型依赖,这里桩为 node-link 直返回
|
|
||||||
def fake_convert_to_node_link(workflow_file, workflow_data, *, target_device="prcxi", target_model=None):
|
|
||||||
captured["converted"] = True
|
|
||||||
# 返回最小合法 node-link 形态(不带 metadata,模拟当前行为)
|
|
||||||
return {"nodes": [], "edges": [], "workflow_uuid": ""}
|
|
||||||
|
|
||||||
monkeypatch.setattr(wf_utils, "_convert_to_node_link", fake_convert_to_node_link)
|
|
||||||
|
|
||||||
def helper(workflow_data: Dict[str, Any], **upload_kwargs: Any) -> Dict[str, Any]:
|
|
||||||
wf_path = tmp_path / "transfer_actions_sample.json"
|
|
||||||
wf_path.write_text(json.dumps(workflow_data, ensure_ascii=False), encoding="utf-8")
|
|
||||||
return wf_utils.upload_workflow(str(wf_path), **upload_kwargs)
|
|
||||||
|
|
||||||
return helper, captured
|
|
||||||
|
|
||||||
|
|
||||||
# ==================== workflow_name fallback 链 ====================
|
|
||||||
|
|
||||||
|
|
||||||
def test_metadata_workflow_name_wins_over_filename(stub_upload):
|
|
||||||
"""P5 主路径:transfer_actions JSON 含 metadata.workflow_name → 优先于文件名。"""
|
|
||||||
helper, captured = stub_upload
|
|
||||||
data = {
|
|
||||||
"metadata": {"workflow_name": "PCR Prep with Categories", "tags": []},
|
|
||||||
"workflow": [],
|
|
||||||
"reagent": {},
|
|
||||||
}
|
|
||||||
helper(data)
|
|
||||||
kwargs = captured["workflow_import_kwargs"]
|
|
||||||
assert kwargs is not None and captured["converted"] is True
|
|
||||||
assert kwargs["name"] == "PCR Prep with Categories"
|
|
||||||
assert kwargs["workflow_name"] == "PCR Prep with Categories"
|
|
||||||
|
|
||||||
|
|
||||||
def test_cli_workflow_name_overrides_metadata(stub_upload):
|
|
||||||
"""CLI 显式 -n/--workflow_name 永远最优先。"""
|
|
||||||
helper, captured = stub_upload
|
|
||||||
data = {
|
|
||||||
"metadata": {"workflow_name": "Metadata Wins By Default"},
|
|
||||||
"workflow": [],
|
|
||||||
"reagent": {},
|
|
||||||
}
|
|
||||||
helper(data, workflow_name="CLI Override Name")
|
|
||||||
kwargs = captured["workflow_import_kwargs"]
|
|
||||||
assert kwargs["name"] == "CLI Override Name"
|
|
||||||
assert kwargs["workflow_name"] == "CLI Override Name"
|
|
||||||
|
|
||||||
|
|
||||||
def test_filename_used_when_no_metadata_and_no_legacy(stub_upload):
|
|
||||||
"""P5 之前的旧文件、且无顶层 workflow_name → 回退到去 .json 后缀的文件名。"""
|
|
||||||
helper, captured = stub_upload
|
|
||||||
data = {"workflow": [], "reagent": {}} # 既无 metadata,也无 workflow_name
|
|
||||||
helper(data)
|
|
||||||
kwargs = captured["workflow_import_kwargs"]
|
|
||||||
# 文件名由 fixture 固定为 transfer_actions_sample.json
|
|
||||||
assert kwargs["name"] == "transfer_actions_sample"
|
|
||||||
assert kwargs["workflow_name"] == "transfer_actions_sample"
|
|
||||||
|
|
||||||
|
|
||||||
def test_metadata_empty_string_falls_back_to_filename(stub_upload):
|
|
||||||
"""metadata.workflow_name 为空字符串(而非缺失)也应回退到文件名。"""
|
|
||||||
helper, captured = stub_upload
|
|
||||||
data = {
|
|
||||||
"metadata": {"workflow_name": " "}, # whitespace-only
|
|
||||||
"workflow": [],
|
|
||||||
"reagent": {},
|
|
||||||
}
|
|
||||||
helper(data)
|
|
||||||
kwargs = captured["workflow_import_kwargs"]
|
|
||||||
assert kwargs["name"] == "transfer_actions_sample"
|
|
||||||
|
|
||||||
|
|
||||||
def test_legacy_top_level_workflow_name_used_when_metadata_missing(stub_upload, monkeypatch):
|
|
||||||
"""旧 node-link 文件(已是 nodes/edges 形态)顶层 workflow_name → 应被使用。
|
|
||||||
|
|
||||||
覆盖路径:``_is_node_link_format`` 直接命中 → 不走转换 → workflow_data 保留顶层
|
|
||||||
workflow_name;``orig_metadata`` 为空时 fallback 到该字段。
|
|
||||||
"""
|
|
||||||
helper, captured = stub_upload
|
|
||||||
data = {
|
|
||||||
"nodes": [],
|
|
||||||
"edges": [],
|
|
||||||
"workflow_name": "Legacy Top Name",
|
|
||||||
}
|
|
||||||
helper(data)
|
|
||||||
kwargs = captured["workflow_import_kwargs"]
|
|
||||||
assert captured["converted"] is False, "node-link 输入不应触发转换"
|
|
||||||
assert kwargs["name"] == "Legacy Top Name"
|
|
||||||
assert kwargs["workflow_name"] == "Legacy Top Name"
|
|
||||||
|
|
||||||
|
|
||||||
# ==================== tags fallback 链 ====================
|
|
||||||
|
|
||||||
|
|
||||||
def test_metadata_tags_used_when_cli_tags_missing(stub_upload):
|
|
||||||
"""P5 主路径:metadata.tags 在 CLI 未传 tags 时被使用。"""
|
|
||||||
helper, captured = stub_upload
|
|
||||||
data = {
|
|
||||||
"metadata": {"workflow_name": "X", "tags": ["Opentrons", "PCR"]},
|
|
||||||
"workflow": [],
|
|
||||||
"reagent": {},
|
|
||||||
}
|
|
||||||
helper(data)
|
|
||||||
kwargs = captured["workflow_import_kwargs"]
|
|
||||||
assert kwargs["tags"] == ["Opentrons", "PCR"]
|
|
||||||
|
|
||||||
|
|
||||||
def test_cli_tags_override_metadata_tags(stub_upload):
|
|
||||||
"""CLI 显式 --tags 优先于 metadata.tags。"""
|
|
||||||
helper, captured = stub_upload
|
|
||||||
data = {
|
|
||||||
"metadata": {"workflow_name": "X", "tags": ["Opentrons", "PCR"]},
|
|
||||||
"workflow": [],
|
|
||||||
"reagent": {},
|
|
||||||
}
|
|
||||||
helper(data, tags=["CLI", "Wins"])
|
|
||||||
kwargs = captured["workflow_import_kwargs"]
|
|
||||||
assert kwargs["tags"] == ["CLI", "Wins"]
|
|
||||||
6
unilabos/__main__.py
Normal file
6
unilabos/__main__.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
"""Entry point for `python -m unilabos`."""
|
||||||
|
|
||||||
|
from unilabos.app.main import main
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -336,27 +336,6 @@ def parse_args():
|
|||||||
default="",
|
default="",
|
||||||
help="Workflow description, used when publishing the workflow",
|
help="Workflow description, used when publishing the workflow",
|
||||||
)
|
)
|
||||||
workflow_parser.add_argument(
|
|
||||||
"--target_device",
|
|
||||||
type=str,
|
|
||||||
default="prcxi",
|
|
||||||
help=(
|
|
||||||
"Target instrument name at vendor granularity (e.g. 'prcxi', 'beckman', 'tecan'). "
|
|
||||||
"Decides which target_devices.<name>.rules section in labware_mapping.yaml is used. "
|
|
||||||
"Unknown names fall back to target_devices.default. Default: 'prcxi'."
|
|
||||||
),
|
|
||||||
)
|
|
||||||
workflow_parser.add_argument(
|
|
||||||
"--target_model",
|
|
||||||
type=str,
|
|
||||||
default=None,
|
|
||||||
help=(
|
|
||||||
"Optional target instrument model name within the same vendor (e.g. '9320', '4040'). "
|
|
||||||
"Used to look up target_devices.<target_device>.models.<target_model>.slot_remap / "
|
|
||||||
".rules for model-specific deck layout or rule overrides. Falls back to the vendor-level "
|
|
||||||
"configuration when omitted or the model is not declared. Default: None."
|
|
||||||
),
|
|
||||||
)
|
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -58,14 +58,14 @@ class JobResultStore:
|
|||||||
feedback=feedback or {},
|
feedback=feedback or {},
|
||||||
timestamp=time.time(),
|
timestamp=time.time(),
|
||||||
)
|
)
|
||||||
logger.debug(f"[JobResultStore] Stored result for job {job_id[:8]}, status={status}")
|
logger.trace(f"[JobResultStore] Stored result for job {job_id[:8]}, status={status}")
|
||||||
|
|
||||||
def get_and_remove(self, job_id: str) -> Optional[JobResult]:
|
def get_and_remove(self, job_id: str) -> Optional[JobResult]:
|
||||||
"""获取并删除任务结果"""
|
"""获取并删除任务结果"""
|
||||||
with self._results_lock:
|
with self._results_lock:
|
||||||
result = self._results.pop(job_id, None)
|
result = self._results.pop(job_id, None)
|
||||||
if result:
|
if result:
|
||||||
logger.debug(f"[JobResultStore] Retrieved and removed result for job {job_id[:8]}")
|
logger.trace(f"[JobResultStore] Retrieved and removed result for job {job_id[:8]}")
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def get_result(self, job_id: str) -> Optional[JobResult]:
|
def get_result(self, job_id: str) -> Optional[JobResult]:
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -201,42 +201,17 @@ class ResourceVisualization:
|
|||||||
self.moveit_controllers_yaml['moveit_simple_controller_manager'][f"{name}_{controller_name}"] = moveit_dict['moveit_simple_controller_manager'][controller_name]
|
self.moveit_controllers_yaml['moveit_simple_controller_manager'][f"{name}_{controller_name}"] = moveit_dict['moveit_simple_controller_manager'][controller_name]
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _ensure_ros2_env() -> dict:
|
|
||||||
"""确保 ROS2 环境变量正确设置,返回可用于子进程的 env dict"""
|
|
||||||
import sys
|
|
||||||
env = dict(os.environ)
|
|
||||||
conda_prefix = os.path.dirname(os.path.dirname(sys.executable))
|
|
||||||
|
|
||||||
if "AMENT_PREFIX_PATH" not in env or not env["AMENT_PREFIX_PATH"].strip():
|
|
||||||
candidate = os.pathsep.join([conda_prefix, os.path.join(conda_prefix, "Library")])
|
|
||||||
env["AMENT_PREFIX_PATH"] = candidate
|
|
||||||
os.environ["AMENT_PREFIX_PATH"] = candidate
|
|
||||||
|
|
||||||
extra_bin_dirs = [
|
|
||||||
os.path.join(conda_prefix, "Library", "bin"),
|
|
||||||
os.path.join(conda_prefix, "Library", "lib"),
|
|
||||||
os.path.join(conda_prefix, "Scripts"),
|
|
||||||
conda_prefix,
|
|
||||||
]
|
|
||||||
current_path = env.get("PATH", "")
|
|
||||||
for d in extra_bin_dirs:
|
|
||||||
if d not in current_path:
|
|
||||||
current_path = d + os.pathsep + current_path
|
|
||||||
env["PATH"] = current_path
|
|
||||||
os.environ["PATH"] = current_path
|
|
||||||
|
|
||||||
return env
|
|
||||||
|
|
||||||
def create_launch_description(self) -> LaunchDescription:
|
def create_launch_description(self) -> LaunchDescription:
|
||||||
"""
|
"""
|
||||||
创建launch描述,包含robot_state_publisher和move_group节点
|
创建launch描述,包含robot_state_publisher和move_group节点
|
||||||
|
|
||||||
|
Args:
|
||||||
|
urdf_str: URDF文本
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
LaunchDescription: launch描述对象
|
LaunchDescription: launch描述对象
|
||||||
"""
|
"""
|
||||||
launch_env = self._ensure_ros2_env()
|
# 检查ROS 2环境变量
|
||||||
|
|
||||||
if "AMENT_PREFIX_PATH" not in os.environ:
|
if "AMENT_PREFIX_PATH" not in os.environ:
|
||||||
raise OSError(
|
raise OSError(
|
||||||
"ROS 2环境未正确设置。需要设置 AMENT_PREFIX_PATH 环境变量。\n"
|
"ROS 2环境未正确设置。需要设置 AMENT_PREFIX_PATH 环境变量。\n"
|
||||||
@@ -315,7 +290,7 @@ class ResourceVisualization:
|
|||||||
{"robot_description": robot_description},
|
{"robot_description": robot_description},
|
||||||
ros2_controllers,
|
ros2_controllers,
|
||||||
],
|
],
|
||||||
env=launch_env,
|
env=dict(os.environ)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
for controller in self.moveit_controllers_yaml['moveit_simple_controller_manager']['controller_names']:
|
for controller in self.moveit_controllers_yaml['moveit_simple_controller_manager']['controller_names']:
|
||||||
@@ -325,7 +300,7 @@ class ResourceVisualization:
|
|||||||
executable="spawner",
|
executable="spawner",
|
||||||
arguments=[f"{controller}", "--controller-manager", f"controller_manager"],
|
arguments=[f"{controller}", "--controller-manager", f"controller_manager"],
|
||||||
output="screen",
|
output="screen",
|
||||||
env=launch_env,
|
env=dict(os.environ)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
controllers.append(
|
controllers.append(
|
||||||
@@ -334,7 +309,7 @@ class ResourceVisualization:
|
|||||||
executable="spawner",
|
executable="spawner",
|
||||||
arguments=["joint_state_broadcaster", "--controller-manager", f"controller_manager"],
|
arguments=["joint_state_broadcaster", "--controller-manager", f"controller_manager"],
|
||||||
output="screen",
|
output="screen",
|
||||||
env=launch_env,
|
env=dict(os.environ)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
for i in controllers:
|
for i in controllers:
|
||||||
@@ -342,6 +317,7 @@ class ResourceVisualization:
|
|||||||
else:
|
else:
|
||||||
ros2_controllers = None
|
ros2_controllers = None
|
||||||
|
|
||||||
|
# 创建robot_state_publisher节点
|
||||||
robot_state_publisher = nd(
|
robot_state_publisher = nd(
|
||||||
package='robot_state_publisher',
|
package='robot_state_publisher',
|
||||||
executable='robot_state_publisher',
|
executable='robot_state_publisher',
|
||||||
@@ -351,8 +327,9 @@ class ResourceVisualization:
|
|||||||
'robot_description': robot_description,
|
'robot_description': robot_description,
|
||||||
'use_sim_time': False
|
'use_sim_time': False
|
||||||
},
|
},
|
||||||
|
# kinematics_dict
|
||||||
],
|
],
|
||||||
env=launch_env,
|
env=dict(os.environ)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -384,7 +361,7 @@ class ResourceVisualization:
|
|||||||
executable='move_group',
|
executable='move_group',
|
||||||
output='screen',
|
output='screen',
|
||||||
parameters=moveit_params,
|
parameters=moveit_params,
|
||||||
env=launch_env,
|
env=dict(os.environ)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -402,11 +379,13 @@ class ResourceVisualization:
|
|||||||
arguments=['-d', f"{str(self.mesh_path)}/view_robot.rviz"],
|
arguments=['-d', f"{str(self.mesh_path)}/view_robot.rviz"],
|
||||||
output='screen',
|
output='screen',
|
||||||
parameters=[
|
parameters=[
|
||||||
{'robot_description_kinematics': kinematics_dict},
|
{'robot_description_kinematics': kinematics_dict,
|
||||||
|
},
|
||||||
robot_description_planning,
|
robot_description_planning,
|
||||||
planning_pipelines,
|
planning_pipelines,
|
||||||
|
|
||||||
],
|
],
|
||||||
env=launch_env,
|
env=dict(os.environ)
|
||||||
)
|
)
|
||||||
self.launch_description.add_action(rviz_node)
|
self.launch_description.add_action(rviz_node)
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,221 +0,0 @@
|
|||||||
"""P9 — liquid_history schema v3 与 helper 函数。
|
|
||||||
|
|
||||||
独立模块,**不依赖 pylabrobot**,可在 PLR 环境缺失时单独单测。
|
|
||||||
|
|
||||||
模块由 ``liquid_handler_abstract.py`` 在 runtime 挂载点(set_liquid / aspirate /
|
|
||||||
dispense)调用,且由 ``resource_tracker._augment_states_with_liquid_history`` 在
|
|
||||||
serialize 链路使用。
|
|
||||||
|
|
||||||
详见 ``product_designs/protocol_convert/09-liquid-history-unknown-debug.md``。
|
|
||||||
"""
|
|
||||||
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
from typing import Any, List, Tuple
|
|
||||||
|
|
||||||
from typing_extensions import TypedDict
|
|
||||||
|
|
||||||
|
|
||||||
# liquid_history 元素 schema v3
|
|
||||||
# 详见 ``product_designs/protocol_convert/09-liquid-history-unknown-debug.md`` §6.1。
|
|
||||||
# 旧格式(v2 ``(name, vol)`` 元组、list[str])由 ``normalize_liquid_history`` 升级。
|
|
||||||
class LiquidHistoryEntry(TypedDict, total=False):
|
|
||||||
name: str # 液体名(如 "Plasma";与 P8 reagent.liquid_name 联动;缺省 "")
|
|
||||||
volume: float # 操作体积(µL;aspirate 为负,dispense / set 为正)
|
|
||||||
action: str # "set" / "aspirate" / "dispense" / "legacy" / "auto_init"
|
|
||||||
timestamp: str # ISO8601 UTC(OS runtime 写入时填,前端写入时可省略)
|
|
||||||
|
|
||||||
|
|
||||||
# liquid_history 单 well 上限:超过则滚动丢弃头部
|
|
||||||
# 既限制内存(典型 8 通道 transfer 一次产生 ≤16 条),也防止极端 batch 拖慢前端渲染
|
|
||||||
LIQUID_HISTORY_MAX_ENTRIES = 1000
|
|
||||||
|
|
||||||
|
|
||||||
def well_current_liquid_name(well: Any) -> str:
|
|
||||||
"""从 ``well.tracker.liquids`` 末项读取当前液体名(PLR ``Liquid`` enum / str / None 兼容)。
|
|
||||||
|
|
||||||
P9:作为 ``aspirate`` 写入 history 时 ``name`` 字段的来源。
|
|
||||||
返回 ``""`` 表示未知(不写字面 "unknown",避免被前端误展示)。
|
|
||||||
"""
|
|
||||||
tracker = getattr(well, "tracker", None)
|
|
||||||
if tracker is None:
|
|
||||||
return ""
|
|
||||||
liquids = getattr(tracker, "liquids", None)
|
|
||||||
if not liquids:
|
|
||||||
# PLR 提供 get_liquids() 时优先用之(返回 list[(Liquid|None, vol)])
|
|
||||||
try:
|
|
||||||
liquids = tracker.get_liquids() # type: ignore[attr-defined]
|
|
||||||
except Exception:
|
|
||||||
liquids = None
|
|
||||||
if not liquids:
|
|
||||||
return ""
|
|
||||||
last = liquids[-1]
|
|
||||||
if isinstance(last, (list, tuple)) and last:
|
|
||||||
candidate = last[0]
|
|
||||||
else:
|
|
||||||
candidate = last
|
|
||||||
if candidate is None:
|
|
||||||
return ""
|
|
||||||
name = getattr(candidate, "name", None)
|
|
||||||
if isinstance(name, str) and name:
|
|
||||||
return name
|
|
||||||
if isinstance(candidate, str):
|
|
||||||
return candidate
|
|
||||||
return ""
|
|
||||||
|
|
||||||
|
|
||||||
def append_liquid_history(
|
|
||||||
well: Any,
|
|
||||||
liquid_name: str,
|
|
||||||
volume: float,
|
|
||||||
action: str,
|
|
||||||
) -> None:
|
|
||||||
"""P9 — 统一写入 ``well.tracker.liquid_history``(PLR 扩展属性)。
|
|
||||||
|
|
||||||
设计要点:
|
|
||||||
- 元素为 v3 dict 形态 ``{name, volume, action, timestamp}``,与
|
|
||||||
:class:`LiquidHistoryEntry` schema 一致。
|
|
||||||
- ``aspirate`` 的 ``volume`` 应为**负数**(与 dispense/set 正数对称,
|
|
||||||
``sum(history.volume)`` ≈ 当前残量)。
|
|
||||||
- ``well`` 无 tracker 或 tracker 不可写时 graceful 静默(避免污染主流程)。
|
|
||||||
- 滚动上限 ``LIQUID_HISTORY_MAX_ENTRIES``:超出时丢弃**头部**(保留最近)。
|
|
||||||
|
|
||||||
详见 ``product_designs/protocol_convert/09-liquid-history-unknown-debug.md`` §6.2。
|
|
||||||
"""
|
|
||||||
tracker = getattr(well, "tracker", None)
|
|
||||||
if tracker is None:
|
|
||||||
return
|
|
||||||
history = getattr(tracker, "liquid_history", None)
|
|
||||||
if not isinstance(history, list):
|
|
||||||
history = []
|
|
||||||
try:
|
|
||||||
tracker.liquid_history = history # type: ignore[attr-defined]
|
|
||||||
except Exception:
|
|
||||||
return # tracker 拒绝写扩展属性(极少见);静默放弃
|
|
||||||
# 兼容修复:PLR VolumeTracker.current_liquids 依赖 tracker.liquid_history 为
|
|
||||||
# list[(name, vol)];若写入 dict 会在 `for name, vol in liquid_history` 时崩溃。
|
|
||||||
# 这里把历史就地归一为 tuple 形态,再 append tuple,避免 unpack ValueError。
|
|
||||||
normalized_pairs: List[Tuple[str, float]] = []
|
|
||||||
for item in history:
|
|
||||||
if isinstance(item, (list, tuple)) and len(item) >= 2:
|
|
||||||
name_val = str(item[0] or "")
|
|
||||||
try:
|
|
||||||
vol_val = float(item[1])
|
|
||||||
except (TypeError, ValueError):
|
|
||||||
vol_val = 0.0
|
|
||||||
normalized_pairs.append((name_val, vol_val))
|
|
||||||
elif isinstance(item, dict):
|
|
||||||
name_val = str(item.get("name", ""))
|
|
||||||
try:
|
|
||||||
vol_val = float(item.get("volume", 0.0) or 0.0)
|
|
||||||
except (TypeError, ValueError):
|
|
||||||
vol_val = 0.0
|
|
||||||
normalized_pairs.append((name_val, vol_val))
|
|
||||||
elif isinstance(item, str):
|
|
||||||
normalized_pairs.append((item, 0.0))
|
|
||||||
history[:] = normalized_pairs
|
|
||||||
entry = (str(liquid_name or ""), float(volume))
|
|
||||||
history.append(entry)
|
|
||||||
overflow = len(history) - LIQUID_HISTORY_MAX_ENTRIES
|
|
||||||
if overflow > 0:
|
|
||||||
del history[:overflow]
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
# P10 v2 — Tip 复用 ``tracker.liquids`` 等价 helper(详见
|
|
||||||
# ``product_designs/protocol_convert/10-tip-reuse-by-liquid-history.md`` §3.2)
|
|
||||||
#
|
|
||||||
# 设计原则:
|
|
||||||
# - 信号源使用 PLR 原生 ``well.tracker.liquids`` 末项("well 此刻顶层液体"),
|
|
||||||
# 而非 P9 扩展属性 ``liquid_history``;P10 v2 因此不依赖 P9 是否落地。
|
|
||||||
# - 名称比较使用严格字符串相等;空 / "unknown" / "none" 一律保守视为未知 →
|
|
||||||
# 不触发 liquids 复用,落回 identity-only 现状(零回归)。
|
|
||||||
# - 与 P9 现有 ``liquid_names_before_aspirate`` 同模式:aspirate 之前预读
|
|
||||||
# source 当前液体名,避免 PLR 顶层归零时 pop ``liquids`` 拿不到身份。
|
|
||||||
# - 4 个 helper 共同居于本 PLR-free 模块,方便单元测试在不安装 pylabrobot
|
|
||||||
# 的环境下独立运行。
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
def is_known_liquid_name(name: Any) -> bool:
|
|
||||||
"""空字符串 / "unknown" / "none" / None 一律视为未知,不触发 liquids 复用。"""
|
|
||||||
if not name:
|
|
||||||
return False
|
|
||||||
if not isinstance(name, str):
|
|
||||||
return False
|
|
||||||
return name.strip().lower() not in {"unknown", "none"}
|
|
||||||
|
|
||||||
|
|
||||||
def same_liquid_via_liquids(well: Any, tip_liquid_name: Any) -> bool:
|
|
||||||
"""tip 残留液体名 vs ``well.tracker.liquids`` 末项 name 严格相等。
|
|
||||||
|
|
||||||
用于 pick_up 决策:判断下一轮要 aspirate 的 well 当前液体是否与 tip 残液同名。
|
|
||||||
任一侧未知(空 / "unknown")→ 返回 ``False``(保守换 tip)。
|
|
||||||
"""
|
|
||||||
if not is_known_liquid_name(tip_liquid_name):
|
|
||||||
return False
|
|
||||||
well_name = well_current_liquid_name(well)
|
|
||||||
if not is_known_liquid_name(well_name):
|
|
||||||
return False
|
|
||||||
return well_name == tip_liquid_name
|
|
||||||
|
|
||||||
|
|
||||||
def same_liquid_via_liquids_pair(cur_well: Any, next_well: Any) -> bool:
|
|
||||||
"""两个 source well 当前 ``tracker.liquids`` 末项是否同名(用于决定 drop 时机)。
|
|
||||||
|
|
||||||
注:必须在 cur_well 的 aspirate **之前**调用;aspirate 不改
|
|
||||||
``liquids[-1].name`` 只改顶层 vol(或顶层归零时 pop),故 cur/next 的判等
|
|
||||||
以 "将要被抽的那一层" 为准。
|
|
||||||
"""
|
|
||||||
cur_name = well_current_liquid_name(cur_well)
|
|
||||||
next_name = well_current_liquid_name(next_well)
|
|
||||||
if not is_known_liquid_name(cur_name) or not is_known_liquid_name(next_name):
|
|
||||||
return False
|
|
||||||
return cur_name == next_name
|
|
||||||
|
|
||||||
|
|
||||||
def capture_tip_liquid_name(source_well: Any) -> "str | None":
|
|
||||||
"""**aspirate 之前** 把 source well 的当前液体名捕获下来,作为本轮 aspirate
|
|
||||||
完成后 tip 上残留液体的身份。
|
|
||||||
|
|
||||||
必须在 ``super().aspirate`` / ``_transfer_base_method`` 调用前读取:PLR
|
|
||||||
aspirate 会从顶层扣减体积,体积归零时 PLR ``VolumeTracker`` 会 pop 顶层
|
|
||||||
``(Liquid, vol)``,事后再读 ``liquids[-1]`` 可能拿到 prev layer 或空 list。
|
|
||||||
详见 ``liquid_handler_abstract.aspirate`` 中 ``liquid_names_before_aspirate``
|
|
||||||
同样的 "预读" 模式。
|
|
||||||
"""
|
|
||||||
name = well_current_liquid_name(source_well)
|
|
||||||
return name if is_known_liquid_name(name) else None
|
|
||||||
|
|
||||||
|
|
||||||
def normalize_liquid_history(raw: Any) -> List[Tuple[str, float]]:
|
|
||||||
"""P9 — 把任意旧形态的 liquid_history 升级为 v3 dict 列表。
|
|
||||||
|
|
||||||
兼容输入:
|
|
||||||
- v3 dict: ``[{name, volume, action, timestamp?}, ...]`` 原样返回(字段补全)
|
|
||||||
- v2 tuple: ``[(name, vol), ...]`` → ``action="legacy"``
|
|
||||||
- list[str]: ``["A", "B"]`` → ``volume=0, action="legacy"``
|
|
||||||
- 其它:丢弃该 entry
|
|
||||||
|
|
||||||
详见 ``product_designs/protocol_convert/09-liquid-history-unknown-debug.md`` §6.4。
|
|
||||||
"""
|
|
||||||
if not isinstance(raw, list):
|
|
||||||
return []
|
|
||||||
result: List[Tuple[str, float]] = []
|
|
||||||
for entry in raw:
|
|
||||||
if isinstance(entry, dict):
|
|
||||||
try:
|
|
||||||
vol_val = float(entry.get("volume", 0.0) or 0.0)
|
|
||||||
except (TypeError, ValueError):
|
|
||||||
vol_val = 0.0
|
|
||||||
result.append((str(entry.get("name", "")), vol_val))
|
|
||||||
elif isinstance(entry, (list, tuple)) and len(entry) >= 2:
|
|
||||||
try:
|
|
||||||
vol_val = float(entry[1])
|
|
||||||
except (TypeError, ValueError):
|
|
||||||
vol_val = 0.0
|
|
||||||
result.append((str(entry[0] or ""), vol_val))
|
|
||||||
elif isinstance(entry, str):
|
|
||||||
result.append((entry, 0.0))
|
|
||||||
# 其它类型静默丢弃
|
|
||||||
return result
|
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,150 +0,0 @@
|
|||||||
from typing import Any, Dict, Optional
|
|
||||||
|
|
||||||
from .prcxi import PRCXI9300ModuleSite
|
|
||||||
|
|
||||||
|
|
||||||
class PRCXI9300FunctionalModule(PRCXI9300ModuleSite):
|
|
||||||
"""
|
|
||||||
PRCXI 9300 功能模块基类(加热/冷却/震荡/加热震荡/磁吸等)。
|
|
||||||
|
|
||||||
设计目标:
|
|
||||||
- 作为一个可以在工作台上拖拽摆放的实体资源(继承自 PRCXI9300ModuleSite -> ItemizedCarrier)。
|
|
||||||
- 顶面存在一个站点(site),可吸附标准板类资源(plate / tip_rack / tube_rack 等)。
|
|
||||||
- 支持注入 `material_info` (UUID 等),并且在 serialize_state 时做安全过滤。
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
name: str,
|
|
||||||
size_x: float,
|
|
||||||
size_y: float,
|
|
||||||
size_z: float,
|
|
||||||
module_type: Optional[str] = None,
|
|
||||||
category: str = "module",
|
|
||||||
model: Optional[str] = None,
|
|
||||||
material_info: Optional[Dict[str, Any]] = None,
|
|
||||||
**kwargs: Any,
|
|
||||||
):
|
|
||||||
super().__init__(
|
|
||||||
name=name,
|
|
||||||
size_x=size_x,
|
|
||||||
size_y=size_y,
|
|
||||||
size_z=size_z,
|
|
||||||
material_info=material_info,
|
|
||||||
model=model,
|
|
||||||
category=category,
|
|
||||||
**kwargs,
|
|
||||||
)
|
|
||||||
|
|
||||||
# 记录模块类型(加热 / 冷却 / 震荡 / 加热震荡 / 磁吸)
|
|
||||||
self.module_type = module_type or "generic"
|
|
||||||
|
|
||||||
# 与 PRCXI9300PlateAdapter 一致,使用 _unilabos_state 保存扩展信息
|
|
||||||
if not hasattr(self, "_unilabos_state") or self._unilabos_state is None:
|
|
||||||
self._unilabos_state = {}
|
|
||||||
|
|
||||||
# super().__init__ 已经在有 material_info 时写入 "Material",这里仅确保存在
|
|
||||||
if material_info is not None and "Material" not in self._unilabos_state:
|
|
||||||
self._unilabos_state["Material"] = material_info
|
|
||||||
|
|
||||||
# 额外标记 category 和模块类型,便于前端或上层逻辑区分
|
|
||||||
self._unilabos_state.setdefault("category", category)
|
|
||||||
self._unilabos_state["module_type"] = module_type
|
|
||||||
|
|
||||||
|
|
||||||
# ============================================================================
|
|
||||||
# 具体功能模块定义
|
|
||||||
# 这里的尺寸和 material_info 目前为占位参数,后续可根据实际测量/JSON 配置进行更新。
|
|
||||||
# 顶面站点尺寸与模块外形一致,保证可以吸附标准 96 板/储液槽等。
|
|
||||||
# ============================================================================
|
|
||||||
|
|
||||||
|
|
||||||
def PRCXI_Heating_Module(name: str) -> PRCXI9300FunctionalModule:
|
|
||||||
"""加热模块(顶面可吸附标准板)。"""
|
|
||||||
return PRCXI9300FunctionalModule(
|
|
||||||
name=name,
|
|
||||||
size_x=127.76,
|
|
||||||
size_y=85.48,
|
|
||||||
size_z=40.0,
|
|
||||||
module_type="heating",
|
|
||||||
model="PRCXI_Heating_Module",
|
|
||||||
material_info={
|
|
||||||
"uuid": "TODO-HEATING-MODULE-UUID",
|
|
||||||
"Code": "HEAT-MOD",
|
|
||||||
"Name": "PRCXI 加热模块",
|
|
||||||
"SupplyType": 3,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def PRCXI_MetalCooling_Module(name: str) -> PRCXI9300FunctionalModule:
|
|
||||||
"""金属冷却模块(顶面可吸附标准板)。"""
|
|
||||||
return PRCXI9300FunctionalModule(
|
|
||||||
name=name,
|
|
||||||
size_x=127.76,
|
|
||||||
size_y=85.48,
|
|
||||||
size_z=40.0,
|
|
||||||
module_type="metal_cooling",
|
|
||||||
model="PRCXI_MetalCooling_Module",
|
|
||||||
material_info={
|
|
||||||
"uuid": "TODO-METAL-COOLING-MODULE-UUID",
|
|
||||||
"Code": "METAL-COOL-MOD",
|
|
||||||
"Name": "PRCXI 金属冷却模块",
|
|
||||||
"SupplyType": 3,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def PRCXI_Shaking_Module(name: str) -> PRCXI9300FunctionalModule:
|
|
||||||
"""震荡模块(顶面可吸附标准板)。"""
|
|
||||||
return PRCXI9300FunctionalModule(
|
|
||||||
name=name,
|
|
||||||
size_x=127.76,
|
|
||||||
size_y=85.48,
|
|
||||||
size_z=50.0,
|
|
||||||
module_type="shaking",
|
|
||||||
model="PRCXI_Shaking_Module",
|
|
||||||
material_info={
|
|
||||||
"uuid": "TODO-SHAKING-MODULE-UUID",
|
|
||||||
"Code": "SHAKE-MOD",
|
|
||||||
"Name": "PRCXI 震荡模块",
|
|
||||||
"SupplyType": 3,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def PRCXI_Heating_Shaking_Module(name: str) -> PRCXI9300FunctionalModule:
|
|
||||||
"""加热震荡模块(顶面可吸附标准板)。"""
|
|
||||||
return PRCXI9300FunctionalModule(
|
|
||||||
name=name,
|
|
||||||
size_x=127.76,
|
|
||||||
size_y=85.48,
|
|
||||||
size_z=55.0,
|
|
||||||
module_type="heating_shaking",
|
|
||||||
model="PRCXI_Heating_Shaking_Module",
|
|
||||||
material_info={
|
|
||||||
"uuid": "TODO-HEATING-SHAKING-MODULE-UUID",
|
|
||||||
"Code": "HEAT-SHAKE-MOD",
|
|
||||||
"Name": "PRCXI 加热震荡模块",
|
|
||||||
"SupplyType": 3,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def PRCXI_Magnetic_Module(name: str) -> PRCXI9300FunctionalModule:
|
|
||||||
"""磁吸模块(顶面可吸附标准板)。"""
|
|
||||||
return PRCXI9300FunctionalModule(
|
|
||||||
name=name,
|
|
||||||
size_x=127.76,
|
|
||||||
size_y=85.48,
|
|
||||||
size_z=30.0,
|
|
||||||
module_type="magnetic",
|
|
||||||
model="PRCXI_Magnetic_Module",
|
|
||||||
material_info={
|
|
||||||
"uuid": "TODO-MAGNETIC-MODULE-UUID",
|
|
||||||
"Code": "MAG-MOD",
|
|
||||||
"Name": "PRCXI 磁吸模块",
|
|
||||||
"SupplyType": 3,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
@@ -59,7 +59,6 @@ class UniLiquidHandlerRvizBackend(LiquidHandlerBackend):
|
|||||||
self.total_height = total_height
|
self.total_height = total_height
|
||||||
self.joint_config = kwargs.get("joint_config", None)
|
self.joint_config = kwargs.get("joint_config", None)
|
||||||
self.lh_device_id = kwargs.get("lh_device_id", "lh_joint_publisher")
|
self.lh_device_id = kwargs.get("lh_device_id", "lh_joint_publisher")
|
||||||
self.simulate_rviz = kwargs.get("simulate_rviz", False)
|
|
||||||
if not rclpy.ok():
|
if not rclpy.ok():
|
||||||
rclpy.init()
|
rclpy.init()
|
||||||
self.joint_state_publisher = None
|
self.joint_state_publisher = None
|
||||||
@@ -70,7 +69,7 @@ class UniLiquidHandlerRvizBackend(LiquidHandlerBackend):
|
|||||||
self.joint_state_publisher = LiquidHandlerJointPublisher(
|
self.joint_state_publisher = LiquidHandlerJointPublisher(
|
||||||
joint_config=self.joint_config,
|
joint_config=self.joint_config,
|
||||||
lh_device_id=self.lh_device_id,
|
lh_device_id=self.lh_device_id,
|
||||||
simulate_rviz=self.simulate_rviz)
|
simulate_rviz=True)
|
||||||
|
|
||||||
# 启动ROS executor
|
# 启动ROS executor
|
||||||
self.executor = rclpy.executors.MultiThreadedExecutor()
|
self.executor = rclpy.executors.MultiThreadedExecutor()
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ class LiquidHandlerJointPublisher(Node):
|
|||||||
while self.resource_action is None:
|
while self.resource_action is None:
|
||||||
self.resource_action = self.check_tf_update_actions()
|
self.resource_action = self.check_tf_update_actions()
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
self.get_logger().info(f'Waiting for TfUpdate server: {self.resource_action}')
|
|
||||||
|
|
||||||
self.resource_action_client = ActionClient(self, SendCmd, self.resource_action)
|
self.resource_action_client = ActionClient(self, SendCmd, self.resource_action)
|
||||||
while not self.resource_action_client.wait_for_server(timeout_sec=1.0):
|
while not self.resource_action_client.wait_for_server(timeout_sec=1.0):
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import json
|
|||||||
import time
|
import time
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Optional, Sequence
|
|
||||||
|
|
||||||
from moveit_msgs.msg import JointConstraint, Constraints
|
from moveit_msgs.msg import JointConstraint, Constraints
|
||||||
from rclpy.action import ActionClient
|
from rclpy.action import ActionClient
|
||||||
@@ -172,160 +171,173 @@ class MoveitInterface:
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def pick_and_place(
|
def pick_and_place(self, command: str):
|
||||||
self,
|
|
||||||
option: str,
|
|
||||||
move_group: str,
|
|
||||||
status: str,
|
|
||||||
resource: Optional[str] = None,
|
|
||||||
x_distance: Optional[float] = None,
|
|
||||||
y_distance: Optional[float] = None,
|
|
||||||
lift_height: Optional[float] = None,
|
|
||||||
retry: Optional[int] = None,
|
|
||||||
speed: Optional[float] = None,
|
|
||||||
target: Optional[str] = None,
|
|
||||||
constraints: Optional[Sequence[float]] = None,
|
|
||||||
) -> None:
|
|
||||||
"""
|
"""
|
||||||
使用 MoveIt 完成抓取/放置等序列(pick/place/side_pick/side_place)。
|
Using MoveIt to make the robotic arm pick or place materials to a target point.
|
||||||
|
|
||||||
必选:option, move_group, status。
|
Args:
|
||||||
可选:resource, x_distance, y_distance, lift_height, retry, speed, target, constraints。
|
command: A JSON-formatted string that includes option, target, speed, lift_height, mt_height
|
||||||
无返回值;失败时提前 return 或打印异常。
|
|
||||||
|
*option (string) : Action type: pick/place/side_pick/side_place
|
||||||
|
*move_group (string): The move group moveit will plan
|
||||||
|
*status(string) : Target pose
|
||||||
|
resource(string) : The target resource
|
||||||
|
x_distance (float) : The distance to the target in x direction(meters)
|
||||||
|
y_distance (float) : The distance to the target in y direction(meters)
|
||||||
|
lift_height (float) : The height at which the material should be lifted(meters)
|
||||||
|
retry (float) : Retry times when moveit plan fails
|
||||||
|
speed (float) : The speed of the movement, speed > 0
|
||||||
|
Returns:
|
||||||
|
None
|
||||||
"""
|
"""
|
||||||
|
result = SendCmd.Result()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if option not in self.move_option:
|
cmd_str = str(command).replace("'", '"')
|
||||||
raise ValueError(f"Invalid option: {option}")
|
cmd_dict = json.loads(cmd_str)
|
||||||
|
|
||||||
option_index = self.move_option.index(option)
|
if cmd_dict["option"] in self.move_option:
|
||||||
place_flag = option_index % 2
|
option_index = self.move_option.index(cmd_dict["option"])
|
||||||
|
place_flag = option_index % 2
|
||||||
|
|
||||||
config: dict = {"move_group": move_group}
|
config = {}
|
||||||
if speed is not None:
|
function_list = []
|
||||||
config["speed"] = speed
|
|
||||||
if retry is not None:
|
|
||||||
config["retry"] = retry
|
|
||||||
|
|
||||||
function_list = []
|
status = cmd_dict["status"]
|
||||||
joint_positions_ = self.joint_poses[move_group][status]
|
joint_positions_ = self.joint_poses[cmd_dict["move_group"]][status]
|
||||||
|
|
||||||
# 夹取 / 放置:绑定 resource 与 parent
|
config.update({k: cmd_dict[k] for k in ["speed", "retry", "move_group"] if k in cmd_dict})
|
||||||
if not place_flag:
|
|
||||||
if target is not None:
|
|
||||||
function_list.append(lambda r=resource, t=target: self.resource_manager(r, t))
|
|
||||||
else:
|
|
||||||
ee = self.moveit2[move_group].end_effector_name
|
|
||||||
function_list.append(lambda r=resource: self.resource_manager(r, ee))
|
|
||||||
else:
|
|
||||||
function_list.append(lambda r=resource: self.resource_manager(r, "world"))
|
|
||||||
|
|
||||||
joint_constraint_msgs: list = []
|
# 夹取
|
||||||
if constraints is not None:
|
if not place_flag:
|
||||||
for i, c in enumerate(constraints):
|
if "target" in cmd_dict.keys():
|
||||||
v = float(c)
|
function_list.append(lambda: self.resource_manager(cmd_dict["resource"], cmd_dict["target"]))
|
||||||
if v > 0:
|
else:
|
||||||
joint_constraint_msgs.append(
|
function_list.append(
|
||||||
JointConstraint(
|
lambda: self.resource_manager(
|
||||||
joint_name=self.moveit2[move_group].joint_names[i],
|
cmd_dict["resource"], self.moveit2[cmd_dict["move_group"]].end_effector_name
|
||||||
position=joint_positions_[i],
|
|
||||||
tolerance_above=v,
|
|
||||||
tolerance_below=v,
|
|
||||||
weight=1.0,
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
function_list.append(lambda: self.resource_manager(cmd_dict["resource"], "world"))
|
||||||
|
|
||||||
if lift_height is not None:
|
constraints = []
|
||||||
retval = None
|
if "constraints" in cmd_dict.keys():
|
||||||
attempts = config.get("retry", 10)
|
|
||||||
while retval is None and attempts > 0:
|
|
||||||
retval = self.moveit2[move_group].compute_fk(joint_positions_)
|
|
||||||
time.sleep(0.1)
|
|
||||||
attempts -= 1
|
|
||||||
if retval is None:
|
|
||||||
raise ValueError("Failed to compute forward kinematics")
|
|
||||||
pose = [retval.pose.position.x, retval.pose.position.y, retval.pose.position.z]
|
|
||||||
quaternion = [
|
|
||||||
retval.pose.orientation.x,
|
|
||||||
retval.pose.orientation.y,
|
|
||||||
retval.pose.orientation.z,
|
|
||||||
retval.pose.orientation.w,
|
|
||||||
]
|
|
||||||
|
|
||||||
function_list = [
|
for i in range(len(cmd_dict["constraints"])):
|
||||||
lambda: self.moveit_task(
|
v = float(cmd_dict["constraints"][i])
|
||||||
position=[retval.pose.position.x, retval.pose.position.y, retval.pose.position.z],
|
if v > 0:
|
||||||
quaternion=quaternion,
|
constraints.append(
|
||||||
**config,
|
JointConstraint(
|
||||||
cartesian=self.cartesian_flag,
|
joint_name=self.moveit2[cmd_dict["move_group"]].joint_names[i],
|
||||||
)
|
position=joint_positions_[i],
|
||||||
] + function_list
|
tolerance_above=v,
|
||||||
|
tolerance_below=v,
|
||||||
|
weight=1.0,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
pose[2] += float(lift_height)
|
if "lift_height" in cmd_dict.keys():
|
||||||
function_list.append(
|
retval = None
|
||||||
lambda p=pose.copy(), q=quaternion, cfg=config: self.moveit_task(
|
retry = config.get("retry", 10)
|
||||||
position=p, quaternion=q, **cfg, cartesian=self.cartesian_flag
|
while retval is None and retry > 0:
|
||||||
)
|
retval = self.moveit2[cmd_dict["move_group"]].compute_fk(joint_positions_)
|
||||||
)
|
time.sleep(0.1)
|
||||||
end_pose = list(pose)
|
retry -= 1
|
||||||
|
if retval is None:
|
||||||
if x_distance is not None or y_distance is not None:
|
result.success = False
|
||||||
if x_distance is not None:
|
return result
|
||||||
deep_pose = deepcopy(pose)
|
pose = [retval.pose.position.x, retval.pose.position.y, retval.pose.position.z]
|
||||||
deep_pose[0] += float(x_distance)
|
quaternion = [
|
||||||
elif y_distance is not None:
|
retval.pose.orientation.x,
|
||||||
deep_pose = deepcopy(pose)
|
retval.pose.orientation.y,
|
||||||
deep_pose[1] += float(y_distance)
|
retval.pose.orientation.z,
|
||||||
|
retval.pose.orientation.w,
|
||||||
|
]
|
||||||
|
|
||||||
function_list = [
|
function_list = [
|
||||||
lambda p=pose.copy(), q=quaternion, cfg=config: self.moveit_task(
|
lambda: self.moveit_task(
|
||||||
position=p, quaternion=q, **cfg, cartesian=self.cartesian_flag
|
position=[retval.pose.position.x, retval.pose.position.y, retval.pose.position.z],
|
||||||
|
quaternion=quaternion,
|
||||||
|
**config,
|
||||||
|
cartesian=self.cartesian_flag,
|
||||||
)
|
)
|
||||||
] + function_list
|
] + function_list
|
||||||
|
|
||||||
|
pose[2] += float(cmd_dict["lift_height"])
|
||||||
function_list.append(
|
function_list.append(
|
||||||
lambda dp=deep_pose.copy(), q=quaternion, cfg=config: self.moveit_task(
|
lambda: self.moveit_task(
|
||||||
position=dp, quaternion=q, **cfg, cartesian=self.cartesian_flag
|
position=pose, quaternion=quaternion, **config, cartesian=self.cartesian_flag
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
end_pose = list(deep_pose)
|
end_pose = pose
|
||||||
|
|
||||||
retval_ik = None
|
if "x_distance" in cmd_dict.keys() or "y_distance" in cmd_dict.keys():
|
||||||
attempts_ik = config.get("retry", 10)
|
if "x_distance" in cmd_dict.keys():
|
||||||
while retval_ik is None and attempts_ik > 0:
|
deep_pose = deepcopy(pose)
|
||||||
retval_ik = self.moveit2[move_group].compute_ik(
|
deep_pose[0] += float(cmd_dict["x_distance"])
|
||||||
position=end_pose,
|
elif "y_distance" in cmd_dict.keys():
|
||||||
quat_xyzw=quaternion,
|
deep_pose = deepcopy(pose)
|
||||||
constraints=Constraints(joint_constraints=joint_constraint_msgs),
|
deep_pose[1] += float(cmd_dict["y_distance"])
|
||||||
)
|
|
||||||
time.sleep(0.1)
|
|
||||||
attempts_ik -= 1
|
|
||||||
if retval_ik is None:
|
|
||||||
raise ValueError("Failed to compute inverse kinematics")
|
|
||||||
position_ = [
|
|
||||||
retval_ik.position[retval_ik.name.index(i)] for i in self.moveit2[move_group].joint_names
|
|
||||||
]
|
|
||||||
jn = self.moveit2[move_group].joint_names
|
|
||||||
function_list = [
|
|
||||||
lambda pos=position_, names=jn, cfg=config: self.moveit_joint_task(
|
|
||||||
joint_positions=pos, joint_names=names, **cfg
|
|
||||||
)
|
|
||||||
] + function_list
|
|
||||||
else:
|
|
||||||
function_list = [lambda cfg=config, jp=joint_positions_: self.moveit_joint_task(**cfg, joint_positions=jp)] + function_list
|
|
||||||
|
|
||||||
for i in range(len(function_list)):
|
function_list = [
|
||||||
if i == 0:
|
lambda: self.moveit_task(
|
||||||
self.cartesian_flag = False
|
position=pose, quaternion=quaternion, **config, cartesian=self.cartesian_flag
|
||||||
|
)
|
||||||
|
] + function_list
|
||||||
|
function_list.append(
|
||||||
|
lambda: self.moveit_task(
|
||||||
|
position=deep_pose, quaternion=quaternion, **config, cartesian=self.cartesian_flag
|
||||||
|
)
|
||||||
|
)
|
||||||
|
end_pose = deep_pose
|
||||||
|
|
||||||
|
retval_ik = None
|
||||||
|
retry = config.get("retry", 10)
|
||||||
|
while retval_ik is None and retry > 0:
|
||||||
|
retval_ik = self.moveit2[cmd_dict["move_group"]].compute_ik(
|
||||||
|
position=end_pose, quat_xyzw=quaternion, constraints=Constraints(joint_constraints=constraints)
|
||||||
|
)
|
||||||
|
time.sleep(0.1)
|
||||||
|
retry -= 1
|
||||||
|
if retval_ik is None:
|
||||||
|
result.success = False
|
||||||
|
return result
|
||||||
|
position_ = [
|
||||||
|
retval_ik.position[retval_ik.name.index(i)]
|
||||||
|
for i in self.moveit2[cmd_dict["move_group"]].joint_names
|
||||||
|
]
|
||||||
|
function_list = [
|
||||||
|
lambda: self.moveit_joint_task(
|
||||||
|
joint_positions=position_,
|
||||||
|
joint_names=self.moveit2[cmd_dict["move_group"]].joint_names,
|
||||||
|
**config,
|
||||||
|
)
|
||||||
|
] + function_list
|
||||||
else:
|
else:
|
||||||
self.cartesian_flag = True
|
function_list = [
|
||||||
|
lambda: self.moveit_joint_task(**config, joint_positions=joint_positions_)
|
||||||
|
] + function_list
|
||||||
|
|
||||||
re = function_list[i]()
|
for i in range(len(function_list)):
|
||||||
if not re:
|
if i == 0:
|
||||||
print(i, re)
|
self.cartesian_flag = False
|
||||||
raise ValueError(f"Failed to execute moveit task: {i}")
|
else:
|
||||||
|
self.cartesian_flag = True
|
||||||
|
|
||||||
|
re = function_list[i]()
|
||||||
|
if not re:
|
||||||
|
print(i, re)
|
||||||
|
result.success = False
|
||||||
|
return result
|
||||||
|
result.success = True
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
self.cartesian_flag = False
|
self.cartesian_flag = False
|
||||||
raise e
|
result.success = False
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
def set_status(self, command: str):
|
def set_status(self, command: str):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -1,9 +1,5 @@
|
|||||||
# 工作站抽象基类物料系统架构说明
|
# 工作站抽象基类物料系统架构说明
|
||||||
|
|
||||||
## 设计理念
|
|
||||||
|
|
||||||
基于用户需求"请你帮我系统思考一下,工作站抽象基类的物料系统基类该如何构建",我们最终确定了一个**PyLabRobot Deck为中心**的简化架构。
|
|
||||||
|
|
||||||
### 核心原则
|
### 核心原则
|
||||||
|
|
||||||
1. **PyLabRobot为物料管理核心**:使用PyLabRobot的Deck系统作为物料管理的基础,利用其成熟的Resource体系
|
1. **PyLabRobot为物料管理核心**:使用PyLabRobot的Deck系统作为物料管理的基础,利用其成熟的Resource体系
|
||||||
|
|||||||
@@ -0,0 +1,113 @@
|
|||||||
|
# Bioyond Cell 工作站 - 多订单返回示例
|
||||||
|
|
||||||
|
本文档说明了 `create_orders` 函数如何收集并返回所有订单的完成报文。
|
||||||
|
|
||||||
|
## 问题描述
|
||||||
|
|
||||||
|
之前的实现只会等待并返回第一个订单的完成报文,如果有多个订单(例如从 Excel 解析出 3 个订单),只能得到第一个订单的推送信息。
|
||||||
|
|
||||||
|
## 解决方案
|
||||||
|
|
||||||
|
修改后的 `create_orders` 函数现在会:
|
||||||
|
|
||||||
|
1. **提取所有 orderCode**:从 LIMS 接口返回的 `data` 列表中提取所有订单编号
|
||||||
|
2. **逐个等待完成**:遍历所有 orderCode,调用 `wait_for_order_finish` 等待每个订单完成
|
||||||
|
3. **收集所有报文**:将每个订单的完成报文存入 `all_reports` 列表
|
||||||
|
4. **统一返回**:返回包含所有订单报文的 JSON 格式数据
|
||||||
|
|
||||||
|
## 返回格式
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"status": "all_completed",
|
||||||
|
"total_orders": 3,
|
||||||
|
"reports": [
|
||||||
|
{
|
||||||
|
"token": "",
|
||||||
|
"request_time": "2025-12-24T15:32:09.2148671+08:00",
|
||||||
|
"data": {
|
||||||
|
"orderId": "3a1e614d-a082-c44a-60be-68647a35e6f1",
|
||||||
|
"orderCode": "BSO2025122400024",
|
||||||
|
"orderName": "DP20251224001",
|
||||||
|
"status": "30",
|
||||||
|
"workflowStatus": "completed",
|
||||||
|
"usedMaterials": [...]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"token": "",
|
||||||
|
"request_time": "2025-12-24T15:32:09.9999039+08:00",
|
||||||
|
"data": {
|
||||||
|
"orderId": "3a1e614d-a0a2-f7a9-9360-610021c9479d",
|
||||||
|
"orderCode": "BSO2025122400025",
|
||||||
|
"orderName": "DP20251224002",
|
||||||
|
"status": "30",
|
||||||
|
"workflowStatus": "completed",
|
||||||
|
"usedMaterials": [...]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"token": "",
|
||||||
|
"request_time": "2025-12-24T15:34:00.4139986+08:00",
|
||||||
|
"data": {
|
||||||
|
"orderId": "3a1e614d-a0cd-81ca-9f7f-2f4e93af01cd",
|
||||||
|
"orderCode": "BSO2025122400026",
|
||||||
|
"orderName": "DP20251224003",
|
||||||
|
"status": "30",
|
||||||
|
"workflowStatus": "completed",
|
||||||
|
"usedMaterials": [...]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"original_response": {...}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 使用示例
|
||||||
|
|
||||||
|
```python
|
||||||
|
# 调用 create_orders
|
||||||
|
result = workstation.create_orders("20251224.xlsx")
|
||||||
|
|
||||||
|
# 访问返回数据
|
||||||
|
print(f"总订单数: {result['total_orders']}")
|
||||||
|
print(f"状态: {result['status']}")
|
||||||
|
|
||||||
|
# 遍历所有订单的报文
|
||||||
|
for i, report in enumerate(result['reports'], 1):
|
||||||
|
order_data = report.get('data', {})
|
||||||
|
print(f"\n订单 {i}:")
|
||||||
|
print(f" orderCode: {order_data.get('orderCode')}")
|
||||||
|
print(f" orderName: {order_data.get('orderName')}")
|
||||||
|
print(f" status: {order_data.get('status')}")
|
||||||
|
print(f" 使用物料数: {len(order_data.get('usedMaterials', []))}")
|
||||||
|
```
|
||||||
|
|
||||||
|
## 控制台输出示例
|
||||||
|
|
||||||
|
```
|
||||||
|
[create_orders] 即将提交订单数量: 3
|
||||||
|
[create_orders] 接口返回: {...}
|
||||||
|
[create_orders] 等待 3 个订单完成: ['BSO2025122400024', 'BSO2025122400025', 'BSO2025122400026']
|
||||||
|
[create_orders] 正在等待第 1/3 个订单: BSO2025122400024
|
||||||
|
[create_orders] ✓ 订单 BSO2025122400024 完成
|
||||||
|
[create_orders] 正在等待第 2/3 个订单: BSO2025122400025
|
||||||
|
[create_orders] ✓ 订单 BSO2025122400025 完成
|
||||||
|
[create_orders] 正在等待第 3/3 个订单: BSO2025122400026
|
||||||
|
[create_orders] ✓ 订单 BSO2025122400026 完成
|
||||||
|
[create_orders] 所有订单已完成,共收集 3 个报文
|
||||||
|
实验记录本========================create_orders========================
|
||||||
|
返回报文数量: 3
|
||||||
|
报文 1: orderCode=BSO2025122400024, status=30
|
||||||
|
报文 2: orderCode=BSO2025122400025, status=30
|
||||||
|
报文 3: orderCode=BSO2025122400026, status=30
|
||||||
|
========================
|
||||||
|
```
|
||||||
|
|
||||||
|
## 关键改进
|
||||||
|
|
||||||
|
1. ✅ **等待所有订单**:不再只等待第一个订单,而是遍历所有 orderCode
|
||||||
|
2. ✅ **收集完整报文**:每个订单的完整推送报文都被保存在 `reports` 数组中
|
||||||
|
3. ✅ **详细日志**:清晰显示正在等待哪个订单,以及完成情况
|
||||||
|
4. ✅ **错误处理**:即使某个订单失败,也会记录其状态信息
|
||||||
|
5. ✅ **统一格式**:返回的 JSON 格式便于后续处理和分析
|
||||||
Binary file not shown.
@@ -0,0 +1,204 @@
|
|||||||
|
# BioyondCellWorkstation JSON 配置迁移经验总结
|
||||||
|
|
||||||
|
**日期**: 2026-01-13
|
||||||
|
**目的**: 从 `config.py` 迁移到 JSON 配置文件
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 问题背景
|
||||||
|
|
||||||
|
原系统通过 `config.py` 管理配置,导致:
|
||||||
|
1. HTTP 服务重复启动(父类 `BioyondWorkstation` 和子类都启动)
|
||||||
|
2. 配置分散在代码中,不便于管理
|
||||||
|
3. 无法通过 JSON 统一配置所有参数
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 解决方案:嵌套配置结构
|
||||||
|
|
||||||
|
### JSON 结构设计
|
||||||
|
|
||||||
|
**正确示例** (嵌套在 `config` 中):
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"nodes": [{
|
||||||
|
"id": "bioyond_cell_workstation",
|
||||||
|
"config": {
|
||||||
|
"deck": {...},
|
||||||
|
"protocol_type": [],
|
||||||
|
"bioyond_config": {
|
||||||
|
"api_host": "http://172.16.11.219:44388",
|
||||||
|
"api_key": "8A819E5C",
|
||||||
|
"timeout": 30,
|
||||||
|
"HTTP_host": "172.16.11.206",
|
||||||
|
"HTTP_port": 8080,
|
||||||
|
"debug_mode": false,
|
||||||
|
"material_type_mappings": {...},
|
||||||
|
"warehouse_mapping": {...},
|
||||||
|
"solid_liquid_mappings": {...}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"data": {}
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**关键点**:
|
||||||
|
- ✅ `bioyond_config` 放在 `config` 中(会传递到 `__init__`)
|
||||||
|
- ❌ **不要**放在 `data` 中(`data` 是运行时状态,不会传递)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Python 代码适配
|
||||||
|
|
||||||
|
### 1. 修改 `BioyondCellWorkstation.__init__` 签名
|
||||||
|
|
||||||
|
**文件**: `bioyond_cell_workstation.py`
|
||||||
|
|
||||||
|
```python
|
||||||
|
def __init__(self, bioyond_config: dict = None, deck=None, protocol_type=None, **kwargs):
|
||||||
|
"""
|
||||||
|
Args:
|
||||||
|
bioyond_config: 从 JSON 加载的配置字典
|
||||||
|
deck: Deck 配置
|
||||||
|
protocol_type: 协议类型
|
||||||
|
"""
|
||||||
|
# 验证配置
|
||||||
|
if bioyond_config is None:
|
||||||
|
raise ValueError("需要 bioyond_config 参数")
|
||||||
|
|
||||||
|
# 保存配置
|
||||||
|
self.bioyond_config = bioyond_config
|
||||||
|
|
||||||
|
# 设置 HTTP 服务去重标志
|
||||||
|
self.bioyond_config["_disable_auto_http_service"] = True
|
||||||
|
|
||||||
|
# 调用父类
|
||||||
|
super().__init__(bioyond_config=self.bioyond_config, deck=deck, **kwargs)
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. 替换全局变量引用
|
||||||
|
|
||||||
|
**修改前**(使用全局变量):
|
||||||
|
```python
|
||||||
|
from config import MATERIAL_TYPE_MAPPINGS, WAREHOUSE_MAPPING
|
||||||
|
|
||||||
|
def create_sample(self, board_type, ...):
|
||||||
|
carrier_type_id = MATERIAL_TYPE_MAPPINGS[board_type][1]
|
||||||
|
location_id = WAREHOUSE_MAPPING[warehouse_name]["site_uuids"][location_code]
|
||||||
|
```
|
||||||
|
|
||||||
|
**修改后**(从配置读取):
|
||||||
|
```python
|
||||||
|
def create_sample(self, board_type, ...):
|
||||||
|
carrier_type_id = self.bioyond_config['material_type_mappings'][board_type][1]
|
||||||
|
location_id = self.bioyond_config['warehouse_mapping'][warehouse_name]["site_uuids"][location_code]
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. 修复父类配置访问
|
||||||
|
|
||||||
|
在 `station.py` 中安全访问配置默认值:
|
||||||
|
|
||||||
|
```python
|
||||||
|
# 修改前(会 KeyError)
|
||||||
|
self._http_service_config = {
|
||||||
|
"host": bioyond_config.get("http_service_host", HTTP_SERVICE_CONFIG["http_service_host"])
|
||||||
|
}
|
||||||
|
|
||||||
|
# 修改后(安全访问)
|
||||||
|
self._http_service_config = {
|
||||||
|
"host": bioyond_config.get("http_service_host", HTTP_SERVICE_CONFIG.get("http_service_host", ""))
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 常见陷阱
|
||||||
|
|
||||||
|
### ❌ 错误1:将配置放在 `data` 字段
|
||||||
|
```json
|
||||||
|
"config": {"deck": {...}},
|
||||||
|
"data": {"bioyond_config": {...}} // ❌ 不会传递到 __init__
|
||||||
|
```
|
||||||
|
|
||||||
|
### ❌ 错误2:扁平化配置(已废弃方案)
|
||||||
|
虽然扁平化也能工作,但不推荐:
|
||||||
|
```json
|
||||||
|
"config": {
|
||||||
|
"deck": {...},
|
||||||
|
"api_host": "...", // ❌ 不够清晰
|
||||||
|
"api_key": "...",
|
||||||
|
"HTTP_host": "..."
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### ❌ 错误3:忘记替换全局变量引用
|
||||||
|
代码中直接使用 `MATERIAL_TYPE_MAPPINGS` 等全局变量会导致 `NameError`。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 云端同步注意事项
|
||||||
|
|
||||||
|
使用 `--upload_registry` 时,云端配置可能覆盖本地配置:
|
||||||
|
- 首次上传时确保 JSON 完整
|
||||||
|
- 或使用新的 `ak/sk` 避免旧配置干扰
|
||||||
|
- 调试时可暂时移除 `--upload_registry` 参数
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 验证清单
|
||||||
|
|
||||||
|
启动成功后应看到:
|
||||||
|
```
|
||||||
|
✅ 从 JSON 配置加载 bioyond_config 成功
|
||||||
|
API Host: http://...
|
||||||
|
HTTP Service: ...
|
||||||
|
✅ BioyondCellWorkstation 初始化完成
|
||||||
|
Loaded ResourceTreeSet with ... nodes
|
||||||
|
```
|
||||||
|
|
||||||
|
运行时不应出现:
|
||||||
|
- ❌ `NameError: name 'MATERIAL_TYPE_MAPPINGS' is not defined`
|
||||||
|
- ❌ `KeyError: 'http_service_host'`
|
||||||
|
- ❌ `bioyond_config 缺少必需参数`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 调试经验
|
||||||
|
|
||||||
|
1. **添加调试日志**查看参数传递链路:
|
||||||
|
- `graphio.py`: JSON 加载后的 config 内容
|
||||||
|
- `initialize_device.py`: `device_config.res_content.config` 的键
|
||||||
|
- `bioyond_cell_workstation.py`: `__init__` 接收到的参数
|
||||||
|
|
||||||
|
2. **config vs data 区别**:
|
||||||
|
- `config`: 初始化参数,传递给 `__init__`
|
||||||
|
- `data`: 运行时状态,不传递给 `__init__`
|
||||||
|
|
||||||
|
3. **参数名必须匹配**:
|
||||||
|
- JSON 中的键名必须与 `__init__` 参数名完全一致
|
||||||
|
|
||||||
|
4. **调试代码清理**:完成后记得删除调试日志(🔍 DEBUG 标记)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 修改文件清单
|
||||||
|
|
||||||
|
| 文件 | 修改内容 |
|
||||||
|
|------|----------|
|
||||||
|
| `yibin_electrolyte_config.json` | 创建嵌套 `config.bioyond_config` 结构 |
|
||||||
|
| `bioyond_cell_workstation.py` | 修改 `__init__` 接收 `bioyond_config`,替换所有全局变量引用 |
|
||||||
|
| `station.py` | 安全访问 `HTTP_SERVICE_CONFIG` 默认值 |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 参考代码位置
|
||||||
|
|
||||||
|
- JSON 配置示例: `yibin_electrolyte_config.json` L12-L353
|
||||||
|
- `__init__` 实现: `bioyond_cell_workstation.py` L39-L94
|
||||||
|
- 全局变量替换示例: `bioyond_cell_workstation.py` L2005, L1863, L1966
|
||||||
|
- HTTP 服务配置: `station.py` L629-L634
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**总结**: 使用嵌套结构将所有配置放在 `config.bioyond_config` 中,修改 `__init__` 直接接收该参数,并替换所有全局变量引用为 `self.bioyond_config` 访问。
|
||||||
@@ -0,0 +1,312 @@
|
|||||||
|
# BioyondCell 配置迁移修改总结
|
||||||
|
|
||||||
|
**日期**: 2026-01-13
|
||||||
|
**目标**: 从 `config.py` 完全迁移到 JSON 配置,消除所有全局变量依赖
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📋 修改概览
|
||||||
|
|
||||||
|
本次修改完成了 BioyondCell 模块从 Python 配置文件到 JSON 配置的完整迁移,并清理了所有对 `config.py` 全局变量的依赖。
|
||||||
|
|
||||||
|
### 核心成果
|
||||||
|
|
||||||
|
- ✅ 完全移除对 `config.py` 的导入依赖
|
||||||
|
- ✅ 使用嵌套 JSON 结构 `config.bioyond_config`
|
||||||
|
- ✅ 修复 7 处 `bioyond_cell_workstation.py` 中的全局变量引用
|
||||||
|
- ✅ 修复 3 处其他文件中的全局变量引用
|
||||||
|
- ✅ HTTP 服务去重机制完善
|
||||||
|
- ✅ 系统成功启动并正常运行
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔧 修改文件清单
|
||||||
|
|
||||||
|
### 1. JSON 配置文件
|
||||||
|
|
||||||
|
**文件**: `yibin_electrolyte_config.json`
|
||||||
|
|
||||||
|
**修改**:
|
||||||
|
- 采用嵌套结构将所有配置放在 `config.bioyond_config` 中
|
||||||
|
- 包含:`api_host`, `api_key`, `HTTP_host`, `HTTP_port`, `material_type_mappings`, `warehouse_mapping`, `solid_liquid_mappings` 等
|
||||||
|
|
||||||
|
**示例结构**:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"nodes": [{
|
||||||
|
"id": "bioyond_cell_workstation",
|
||||||
|
"config": {
|
||||||
|
"deck": {...},
|
||||||
|
"protocol_type": [],
|
||||||
|
"bioyond_config": {
|
||||||
|
"api_host": "http://172.16.11.219:44388",
|
||||||
|
"api_key": "8A819E5C",
|
||||||
|
"HTTP_host": "172.16.11.206",
|
||||||
|
"HTTP_port": 8080,
|
||||||
|
"material_type_mappings": {...},
|
||||||
|
"warehouse_mapping": {...},
|
||||||
|
"solid_liquid_mappings": {...}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 2. bioyond_cell_workstation.py
|
||||||
|
|
||||||
|
**位置**: `unilabos/devices/workstation/bioyond_studio/bioyond_cell/bioyond_cell_workstation.py`
|
||||||
|
|
||||||
|
#### 修改 A: `__init__` 方法签名 (L39-99)
|
||||||
|
|
||||||
|
**修改前**:
|
||||||
|
```python
|
||||||
|
def __init__(self, deck=None, protocol_type=None, **kwargs):
|
||||||
|
# 从 kwargs 收集配置字段
|
||||||
|
self.bioyond_config = {}
|
||||||
|
for field in bioyond_field_names:
|
||||||
|
if field in kwargs:
|
||||||
|
self.bioyond_config[field] = kwargs.pop(field)
|
||||||
|
```
|
||||||
|
|
||||||
|
**修改后**:
|
||||||
|
```python
|
||||||
|
def __init__(self, bioyond_config: dict = None, deck=None, protocol_type=None, **kwargs):
|
||||||
|
"""直接接收 bioyond_config 参数"""
|
||||||
|
if bioyond_config is None:
|
||||||
|
raise ValueError("需要 bioyond_config 参数")
|
||||||
|
|
||||||
|
self.bioyond_config = bioyond_config
|
||||||
|
|
||||||
|
# 设置 HTTP 服务去重标志
|
||||||
|
self.bioyond_config["_disable_auto_http_service"] = True
|
||||||
|
|
||||||
|
super().__init__(bioyond_config=self.bioyond_config, deck=deck, **kwargs)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 修改 B: 替换全局变量引用 (7 处)
|
||||||
|
|
||||||
|
| 位置 | 原代码 | 修改后 |
|
||||||
|
|------|--------|--------|
|
||||||
|
| L2005 | `MATERIAL_TYPE_MAPPINGS[board_type][1]` | `self.bioyond_config['material_type_mappings'][board_type][1]` |
|
||||||
|
| L2006 | `MATERIAL_TYPE_MAPPINGS[bottle_type][1]` | `self.bioyond_config['material_type_mappings'][bottle_type][1]` |
|
||||||
|
| L2009 | `WAREHOUSE_MAPPING` | `self.bioyond_config['warehouse_mapping']` |
|
||||||
|
| L2013 | `WAREHOUSE_MAPPING[warehouse_name]` | `self.bioyond_config['warehouse_mapping'][warehouse_name]` |
|
||||||
|
| L2017 | `WAREHOUSE_MAPPING[warehouse_name]["site_uuids"]` | `self.bioyond_config['warehouse_mapping'][warehouse_name]["site_uuids"]` |
|
||||||
|
| L1863 | `SOLID_LIQUID_MAPPINGS.get(material_name)` | `self.bioyond_config.get('solid_liquid_mappings', {}).get(material_name)` |
|
||||||
|
| L1966, L1976 | `MATERIAL_TYPE_MAPPINGS.items()` | `self.bioyond_config['material_type_mappings'].items()` |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 3. station.py
|
||||||
|
|
||||||
|
**位置**: `unilabos/devices/workstation/bioyond_studio/station.py`
|
||||||
|
|
||||||
|
#### 修改 A: 删除 config 导入 (L26-28)
|
||||||
|
|
||||||
|
**修改前**:
|
||||||
|
```python
|
||||||
|
from unilabos.devices.workstation.bioyond_studio.config import (
|
||||||
|
API_CONFIG, WORKFLOW_MAPPINGS, MATERIAL_TYPE_MAPPINGS, WAREHOUSE_MAPPING, HTTP_SERVICE_CONFIG
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
**修改后**:
|
||||||
|
```python
|
||||||
|
# 已删除此导入
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 修改 B: `_create_communication_module` 方法 (L691-702)
|
||||||
|
|
||||||
|
**修改前**:
|
||||||
|
```python
|
||||||
|
def _create_communication_module(self, config: Optional[Dict[str, Any]] = None) -> None:
|
||||||
|
default_config = {
|
||||||
|
**API_CONFIG,
|
||||||
|
"workflow_mappings": WORKFLOW_MAPPINGS,
|
||||||
|
"material_type_mappings": MATERIAL_TYPE_MAPPINGS,
|
||||||
|
"warehouse_mapping": WAREHOUSE_MAPPING
|
||||||
|
}
|
||||||
|
if config:
|
||||||
|
self.bioyond_config = {**default_config, **config}
|
||||||
|
else:
|
||||||
|
self.bioyond_config = default_config
|
||||||
|
```
|
||||||
|
|
||||||
|
**修改后**:
|
||||||
|
```python
|
||||||
|
def _create_communication_module(self, config: Optional[Dict[str, Any]] = None) -> None:
|
||||||
|
"""创建Bioyond通信模块"""
|
||||||
|
# 使用传入的 config 参数(来自 bioyond_config)
|
||||||
|
# 不再依赖全局变量 API_CONFIG 等
|
||||||
|
if config:
|
||||||
|
self.bioyond_config = config
|
||||||
|
else:
|
||||||
|
# 如果没有传入配置,创建空配置(用于测试或兼容性)
|
||||||
|
self.bioyond_config = {}
|
||||||
|
|
||||||
|
self.hardware_interface = BioyondV1RPC(self.bioyond_config)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 修改 C: HTTP 服务配置 (L627-632)
|
||||||
|
|
||||||
|
**修改前**:
|
||||||
|
```python
|
||||||
|
self._http_service_config = {
|
||||||
|
"host": bioyond_config.get("http_service_host", HTTP_SERVICE_CONFIG.get("http_service_host", "")),
|
||||||
|
"port": bioyond_config.get("http_service_port", HTTP_SERVICE_CONFIG.get("http_service_port", 0))
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**修改后**:
|
||||||
|
```python
|
||||||
|
self._http_service_config = {
|
||||||
|
"host": bioyond_config.get("http_service_host", bioyond_config.get("HTTP_host", "")),
|
||||||
|
"port": bioyond_config.get("http_service_port", bioyond_config.get("HTTP_port", 0))
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 4. bioyond_rpc.py
|
||||||
|
|
||||||
|
**位置**: `unilabos/devices/workstation/bioyond_studio/bioyond_rpc.py`
|
||||||
|
|
||||||
|
#### 修改 A: 删除 config 导入 (L12)
|
||||||
|
|
||||||
|
**修改前**:
|
||||||
|
```python
|
||||||
|
from unilabos.devices.workstation.bioyond_studio.config import LOCATION_MAPPING
|
||||||
|
```
|
||||||
|
|
||||||
|
**修改后**:
|
||||||
|
```python
|
||||||
|
# 已删除此导入
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 修改 B: `material_outbound` 方法 (L278-280)
|
||||||
|
|
||||||
|
**修改前**:
|
||||||
|
```python
|
||||||
|
def material_outbound(self, material_id: str, location_name: str, quantity: int) -> dict:
|
||||||
|
"""指定库位出库物料(通过库位名称)"""
|
||||||
|
location_id = LOCATION_MAPPING.get(location_name, location_name)
|
||||||
|
```
|
||||||
|
|
||||||
|
**修改后**:
|
||||||
|
```python
|
||||||
|
def material_outbound(self, material_id: str, location_name: str, quantity: int) -> dict:
|
||||||
|
"""指定库位出库物料(通过库位名称)"""
|
||||||
|
# location_name 参数实际上应该直接是 location_id (UUID)
|
||||||
|
location_id = location_name
|
||||||
|
```
|
||||||
|
|
||||||
|
**说明**: `LOCATION_MAPPING` 在 `config-0113.py` 中本来就是空字典 `{}`,所以直接使用 `location_name` 逻辑等价。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🎯 关键设计决策
|
||||||
|
|
||||||
|
### 1. 嵌套 vs 扁平配置
|
||||||
|
|
||||||
|
**选择**: 嵌套结构 `config.bioyond_config`
|
||||||
|
|
||||||
|
**理由**:
|
||||||
|
- ✅ 语义清晰,配置分组明确
|
||||||
|
- ✅ 参数传递直观,直接对应 `__init__` 参数
|
||||||
|
- ✅ 易于维护,不需要硬编码字段列表
|
||||||
|
- ✅ 符合 UniLab 设计模式
|
||||||
|
|
||||||
|
### 2. HTTP 服务去重
|
||||||
|
|
||||||
|
**实现**: 子类设置 `_disable_auto_http_service` 标志
|
||||||
|
|
||||||
|
```python
|
||||||
|
# bioyond_cell_workstation.py
|
||||||
|
self.bioyond_config["_disable_auto_http_service"] = True
|
||||||
|
|
||||||
|
# station.py (post_init)
|
||||||
|
if self.bioyond_config.get("_disable_auto_http_service"):
|
||||||
|
logger.info("子类已自行管理HTTP服务,跳过自动启动")
|
||||||
|
return
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. 全局变量替换策略
|
||||||
|
|
||||||
|
**原则**: 所有配置从 `self.bioyond_config` 获取
|
||||||
|
|
||||||
|
**模式**:
|
||||||
|
```python
|
||||||
|
# 修改前
|
||||||
|
from config import MATERIAL_TYPE_MAPPINGS
|
||||||
|
carrier_type_id = MATERIAL_TYPE_MAPPINGS[board_type][1]
|
||||||
|
|
||||||
|
# 修改后
|
||||||
|
carrier_type_id = self.bioyond_config['material_type_mappings'][board_type][1]
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ✅ 验证结果
|
||||||
|
|
||||||
|
### 启动成功日志
|
||||||
|
```
|
||||||
|
✅ 从 JSON 配置加载 bioyond_config 成功
|
||||||
|
API Host: http://172.16.11.219:44388
|
||||||
|
HTTP Service: 172.16.11.206:8080
|
||||||
|
🔧 已设置 _disable_auto_http_service 标志,防止 HTTP 服务重复启动
|
||||||
|
✅ BioyondCellWorkstation 初始化完成
|
||||||
|
Loaded ResourceTreeSet with 1 trees, 1785 total nodes
|
||||||
|
```
|
||||||
|
|
||||||
|
### 功能验证
|
||||||
|
- ✅ 订单创建 (`create_orders_v2`)
|
||||||
|
- ✅ 质量比计算
|
||||||
|
- ✅ 物料转移 (`transfer_3_to_2_to_1`)
|
||||||
|
- ✅ HTTP 报送接收 (step_finish, sample_finish, order_finish)
|
||||||
|
- ✅ 等待机制 (`wait_for_order_finish`)
|
||||||
|
- ✅ 仓库 UUID 映射
|
||||||
|
- ✅ 物料类型映射
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📚 相关文档
|
||||||
|
|
||||||
|
- **配置迁移经验**: `2026-01-13_JSON配置迁移经验.md`
|
||||||
|
- **任务清单**: `C:\Users\AndyXie\.gemini\antigravity\brain\...\task.md`
|
||||||
|
- **实施计划**: `C:\Users\AndyXie\.gemini\antigravity\brain\...\implementation_plan.md`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ⚠️ 注意事项
|
||||||
|
|
||||||
|
### 其他工作站模块
|
||||||
|
|
||||||
|
以下文件仍在使用 `config.py` 全局变量(未包含在本次修改中):
|
||||||
|
- `reaction_station.py` - 使用 `API_CONFIG`
|
||||||
|
- `experiment.py` - 使用 `API_CONFIG`, `WORKFLOW_MAPPINGS`, `MATERIAL_TYPE_MAPPINGS`
|
||||||
|
- `dispensing_station.py` - 使用 `API_CONFIG`, `WAREHOUSE_MAPPING`
|
||||||
|
- `station.py` L176, L177, L529, L530 - 动态导入 `WAREHOUSE_MAPPING`
|
||||||
|
|
||||||
|
**建议**: 后续可以统一迁移这些模块到 JSON 配置。
|
||||||
|
|
||||||
|
### config.py 文件
|
||||||
|
|
||||||
|
`config.py` 文件已恢复但**不再被 bioyond_cell 使用**。可以:
|
||||||
|
- 保留作为其他模块的参考
|
||||||
|
- 或者完全删除(如果其他模块也迁移完成)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🚀 下一步建议
|
||||||
|
|
||||||
|
1. **清理调试代码** ✅ (已完成)
|
||||||
|
2. **提交代码到 Git**
|
||||||
|
3. **迁移其他工作站模块** (可选)
|
||||||
|
4. **更新文档和启动脚本**
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**修改完成日期**: 2026-01-13
|
||||||
|
**系统状态**: ✅ 稳定运行
|
||||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,157 @@
|
|||||||
|
# 批量出库 Excel 模板使用说明
|
||||||
|
|
||||||
|
**文件**: `outbound_template.xlsx`
|
||||||
|
**用途**: 配合 `auto_batch_outbound_from_xlsx()` 方法进行批量出库操作
|
||||||
|
**API 端点**: `/api/lims/storage/auto-batch-out-bound`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📋 Excel 列说明
|
||||||
|
|
||||||
|
| 列名 | 说明 | 示例 | 必填 |
|
||||||
|
|------|------|------|------|
|
||||||
|
| `locationId` | **库位 ID(UUID)** | `3a19da43-57b5-294f-d663-154a1cc32270` | ✅ 是 |
|
||||||
|
| `warehouseId` | **仓库 ID 或名称** | `配液站内试剂仓库` | ✅ 是 |
|
||||||
|
| `quantity` | **出库数量** | `1.0`, `2.0` | ✅ 是 |
|
||||||
|
| `x` | **X 坐标(库位横向位置)** | `1`, `2`, `3` | ✅ 是 |
|
||||||
|
| `y` | **Y 坐标(库位纵向位置)** | `1`, `2`, `3` | ✅ 是 |
|
||||||
|
| `z` | **Z 坐标(库位层数/高度)** | `1`, `2`, `3` | ✅ 是 |
|
||||||
|
| `备注说明` | 可选备注信息 | `配液站内试剂仓库-A01` | ❌ 否 |
|
||||||
|
|
||||||
|
### 📐 坐标说明
|
||||||
|
|
||||||
|
**x, y, z** 是库位在仓库内的**三维坐标**:
|
||||||
|
|
||||||
|
```
|
||||||
|
仓库(例如 WH4)
|
||||||
|
├── Z=1(第1层/加样头面)
|
||||||
|
│ ├── X=1, Y=1(位置 A)
|
||||||
|
│ ├── X=2, Y=1(位置 B)
|
||||||
|
│ ├── X=3, Y=1(位置 C)
|
||||||
|
│ └── ...
|
||||||
|
│
|
||||||
|
└── Z=2(第2层/原液瓶面)
|
||||||
|
├── X=1, Y=1(位置 A)
|
||||||
|
├── X=2, Y=1(位置 B)
|
||||||
|
└── ...
|
||||||
|
```
|
||||||
|
|
||||||
|
- **warehouseId**: 指定哪个仓库(WH3, WH4, 配液站等)
|
||||||
|
- **x, y, z**: 在该仓库内的三维坐标
|
||||||
|
- **locationId**: 该坐标位置的唯一 UUID
|
||||||
|
|
||||||
|
### 🎯 起点与终点
|
||||||
|
|
||||||
|
**重要说明**:批量出库模板**只规定了出库的"起点"**(从哪里取物料),**没有指定"终点"**(放到哪里)。
|
||||||
|
|
||||||
|
```
|
||||||
|
出库流程:
|
||||||
|
起点(Excel 指定) → ?终点(LIMS/工作流决定)
|
||||||
|
↓
|
||||||
|
locationId, x, y, z → 由 LIMS 系统或当前工作流自动分配
|
||||||
|
```
|
||||||
|
|
||||||
|
**终点由以下方式确定:**
|
||||||
|
- **LIMS 系统自动分配**:根据当前任务自动规划目标位置
|
||||||
|
- **工作流预定义**:在创建出库任务时已绑定目标位置
|
||||||
|
- **暂存区**:默认放到出库暂存区,等待下一步操作
|
||||||
|
|
||||||
|
💡 **对比**:上料操作(`auto_feeding4to3`)则有 `targetWH` 参数可以指定目标仓库
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔍 如何获取 UUID?
|
||||||
|
|
||||||
|
### 方法 1:从配置文件获取
|
||||||
|
|
||||||
|
参考 `yibin_electrolyte_config.json` 中的 `warehouse_mapping`:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"warehouse_mapping": {
|
||||||
|
"配液站内试剂仓库": {
|
||||||
|
"site_uuids": {
|
||||||
|
"A01": "3a19da43-57b5-294f-d663-154a1cc32270",
|
||||||
|
"B01": "3a19da43-57b5-7394-5f49-54efe2c9bef2",
|
||||||
|
"C01": "3a19da43-57b5-5e75-552f-8dbd0ad1075f"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"手动堆栈": {
|
||||||
|
"site_uuids": {
|
||||||
|
"A01": "3a19deae-2c7a-36f5-5e41-02c5b66feaea",
|
||||||
|
"A02": "3a19deae-2c7a-dc6d-c41e-ef285d946cfe"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 方法 2:通过 API 查询
|
||||||
|
|
||||||
|
```python
|
||||||
|
material_info = hardware_interface.material_id_query(workflow_id)
|
||||||
|
locations = material_info.get("locations", [])
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📝 填写示例
|
||||||
|
|
||||||
|
### 示例 1:从配液站内试剂仓库出库
|
||||||
|
|
||||||
|
| locationId | warehouseId | quantity | x | y | z | 备注说明 |
|
||||||
|
|------------|-------------|----------|---|---|---|----------|
|
||||||
|
| `3a19da43-57b5-294f-d663-154a1cc32270` | 配液站内试剂仓库 | 1 | 1 | 1 | 1 | A01 位置 |
|
||||||
|
| `3a19da43-57b5-7394-5f49-54efe2c9bef2` | 配液站内试剂仓库 | 2 | 2 | 1 | 1 | B01 位置 |
|
||||||
|
|
||||||
|
### 示例 2:从手动堆栈出库
|
||||||
|
|
||||||
|
| locationId | warehouseId | quantity | x | y | z | 备注说明 |
|
||||||
|
|------------|-------------|----------|---|---|---|----------|
|
||||||
|
| `3a19deae-2c7a-36f5-5e41-02c5b66feaea` | 手动堆栈 | 1 | 1 | 1 | 1 | A01 |
|
||||||
|
| `3a19deae-2c7a-dc6d-c41e-ef285d946cfe` | 手动堆栈 | 1 | 1 | 2 | 1 | A02 |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 💻 使用方法
|
||||||
|
|
||||||
|
```python
|
||||||
|
from bioyond_cell_workstation import BioyondCellWorkstation
|
||||||
|
|
||||||
|
# 初始化工作站
|
||||||
|
workstation = BioyondCellWorkstation(config=config, deck=deck)
|
||||||
|
|
||||||
|
# 调用批量出库方法
|
||||||
|
result = workstation.auto_batch_outbound_from_xlsx(
|
||||||
|
xlsx_path="outbound_template.xlsx"
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ⚠️ 注意事项
|
||||||
|
|
||||||
|
1. **locationId 必须是有效的 UUID**,不能使用库位名称
|
||||||
|
2. **x, y, z 坐标必须与 locationId 对应**,表示该库位在仓库内的位置
|
||||||
|
3. **quantity 必须是数字**,可以是整数或浮点数
|
||||||
|
4. Excel 文件必须包含表头行
|
||||||
|
5. 空行会被自动跳过
|
||||||
|
6. 确保 UUID 与实际库位对应,否则 API 会报错
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📚 相关文件
|
||||||
|
|
||||||
|
- **配置文件**: `yibin_electrolyte_config.json`
|
||||||
|
- **Python 代码**: `bioyond_cell_workstation.py` (L630-695)
|
||||||
|
- **生成脚本**: `create_outbound_template.py`
|
||||||
|
- **上料模板**: `material_template.xlsx`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔄 重新生成模板
|
||||||
|
|
||||||
|
```bash
|
||||||
|
conda activate newunilab
|
||||||
|
python create_outbound_template.py
|
||||||
|
```
|
||||||
@@ -9,7 +9,7 @@ from datetime import datetime, timezone
|
|||||||
from unilabos.device_comms.rpc import BaseRequest
|
from unilabos.device_comms.rpc import BaseRequest
|
||||||
from typing import Optional, List, Dict, Any
|
from typing import Optional, List, Dict, Any
|
||||||
import json
|
import json
|
||||||
from unilabos.devices.workstation.bioyond_studio.config import LOCATION_MAPPING
|
|
||||||
|
|
||||||
|
|
||||||
class SimpleLogger:
|
class SimpleLogger:
|
||||||
@@ -49,6 +49,14 @@ class BioyondV1RPC(BaseRequest):
|
|||||||
self.config = config
|
self.config = config
|
||||||
self.api_key = config["api_key"]
|
self.api_key = config["api_key"]
|
||||||
self.host = config["api_host"]
|
self.host = config["api_host"]
|
||||||
|
|
||||||
|
# 初始化 location_mapping
|
||||||
|
# 直接从 warehouse_mapping 构建,确保数据源所谓的单一和结构化
|
||||||
|
self.location_mapping = {}
|
||||||
|
warehouse_mapping = self.config.get("warehouse_mapping", {})
|
||||||
|
for warehouse_name, warehouse_config in warehouse_mapping.items():
|
||||||
|
if "site_uuids" in warehouse_config:
|
||||||
|
self.location_mapping.update(warehouse_config["site_uuids"])
|
||||||
self._logger = SimpleLogger()
|
self._logger = SimpleLogger()
|
||||||
self.material_cache = {}
|
self.material_cache = {}
|
||||||
self._load_material_cache()
|
self._load_material_cache()
|
||||||
@@ -176,7 +184,40 @@ class BioyondV1RPC(BaseRequest):
|
|||||||
return {}
|
return {}
|
||||||
|
|
||||||
print(f"add material data: {response['data']}")
|
print(f"add material data: {response['data']}")
|
||||||
return response.get("data", {})
|
|
||||||
|
# 自动更新缓存
|
||||||
|
data = response.get("data", {})
|
||||||
|
if data:
|
||||||
|
if isinstance(data, str):
|
||||||
|
# 如果返回的是字符串,通常是ID
|
||||||
|
mat_id = data
|
||||||
|
name = params.get("name")
|
||||||
|
else:
|
||||||
|
# 如果返回的是字典,尝试获取name和id
|
||||||
|
name = data.get("name") or params.get("name")
|
||||||
|
mat_id = data.get("id")
|
||||||
|
|
||||||
|
if name and mat_id:
|
||||||
|
self.material_cache[name] = mat_id
|
||||||
|
print(f"已自动更新缓存: {name} -> {mat_id}")
|
||||||
|
|
||||||
|
# 处理返回数据中的 details (如果有)
|
||||||
|
# 有些 API 返回结构可能直接包含 details,或者在 data 字段中
|
||||||
|
details = data.get("details", []) if isinstance(data, dict) else []
|
||||||
|
if not details and isinstance(data, dict):
|
||||||
|
details = data.get("detail", [])
|
||||||
|
|
||||||
|
if details:
|
||||||
|
for detail in details:
|
||||||
|
d_name = detail.get("name")
|
||||||
|
# 尝试从不同字段获取 ID
|
||||||
|
d_id = detail.get("id") or detail.get("detailMaterialId")
|
||||||
|
|
||||||
|
if d_name and d_id:
|
||||||
|
self.material_cache[d_name] = d_id
|
||||||
|
print(f"已自动更新 detail 缓存: {d_name} -> {d_id}")
|
||||||
|
|
||||||
|
return data
|
||||||
|
|
||||||
def query_matial_type_id(self, data) -> list:
|
def query_matial_type_id(self, data) -> list:
|
||||||
"""查找物料typeid"""
|
"""查找物料typeid"""
|
||||||
@@ -203,7 +244,7 @@ class BioyondV1RPC(BaseRequest):
|
|||||||
params={
|
params={
|
||||||
"apiKey": self.api_key,
|
"apiKey": self.api_key,
|
||||||
"requestTime": self.get_current_time_iso8601(),
|
"requestTime": self.get_current_time_iso8601(),
|
||||||
"data": {},
|
"data": 0,
|
||||||
})
|
})
|
||||||
if not response or response['code'] != 1:
|
if not response or response['code'] != 1:
|
||||||
return []
|
return []
|
||||||
@@ -273,11 +314,19 @@ class BioyondV1RPC(BaseRequest):
|
|||||||
|
|
||||||
if not response or response['code'] != 1:
|
if not response or response['code'] != 1:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
# 自动更新缓存 - 移除被删除的物料
|
||||||
|
for name, mid in list(self.material_cache.items()):
|
||||||
|
if mid == material_id:
|
||||||
|
del self.material_cache[name]
|
||||||
|
print(f"已从缓存移除物料: {name}")
|
||||||
|
break
|
||||||
|
|
||||||
return response.get("data", {})
|
return response.get("data", {})
|
||||||
|
|
||||||
def material_outbound(self, material_id: str, location_name: str, quantity: int) -> dict:
|
def material_outbound(self, material_id: str, location_name: str, quantity: int) -> dict:
|
||||||
"""指定库位出库物料(通过库位名称)"""
|
"""指定库位出库物料(通过库位名称)"""
|
||||||
location_id = LOCATION_MAPPING.get(location_name, location_name)
|
location_id = self.location_mapping.get(location_name, location_name)
|
||||||
|
|
||||||
params = {
|
params = {
|
||||||
"materialId": material_id,
|
"materialId": material_id,
|
||||||
@@ -1103,6 +1152,10 @@ class BioyondV1RPC(BaseRequest):
|
|||||||
for detail_material in detail_materials:
|
for detail_material in detail_materials:
|
||||||
detail_name = detail_material.get("name")
|
detail_name = detail_material.get("name")
|
||||||
detail_id = detail_material.get("detailMaterialId")
|
detail_id = detail_material.get("detailMaterialId")
|
||||||
|
if not detail_id:
|
||||||
|
# 尝试其他可能的字段
|
||||||
|
detail_id = detail_material.get("id")
|
||||||
|
|
||||||
if detail_name and detail_id:
|
if detail_name and detail_id:
|
||||||
self.material_cache[detail_name] = detail_id
|
self.material_cache[detail_name] = detail_id
|
||||||
print(f"加载detail材料: {detail_name} -> ID: {detail_id}")
|
print(f"加载detail材料: {detail_name} -> ID: {detail_id}")
|
||||||
@@ -1123,6 +1176,14 @@ class BioyondV1RPC(BaseRequest):
|
|||||||
print(f"从缓存找到材料: {material_name_or_id} -> ID: {material_id}")
|
print(f"从缓存找到材料: {material_name_or_id} -> ID: {material_id}")
|
||||||
return material_id
|
return material_id
|
||||||
|
|
||||||
|
# 如果缓存中没有,尝试刷新缓存
|
||||||
|
print(f"缓存中未找到材料 '{material_name_or_id}',尝试刷新缓存...")
|
||||||
|
self.refresh_material_cache()
|
||||||
|
if material_name_or_id in self.material_cache:
|
||||||
|
material_id = self.material_cache[material_name_or_id]
|
||||||
|
print(f"刷新缓存后找到材料: {material_name_or_id} -> ID: {material_id}")
|
||||||
|
return material_id
|
||||||
|
|
||||||
print(f"警告: 未在缓存中找到材料名称 '{material_name_or_id}',将使用原值")
|
print(f"警告: 未在缓存中找到材料名称 '{material_name_or_id}',将使用原值")
|
||||||
return material_name_or_id
|
return material_name_or_id
|
||||||
|
|
||||||
|
|||||||
@@ -1,142 +0,0 @@
|
|||||||
# config.py
|
|
||||||
"""
|
|
||||||
配置文件 - 包含所有配置信息和映射关系
|
|
||||||
"""
|
|
||||||
|
|
||||||
# API配置
|
|
||||||
API_CONFIG = {
|
|
||||||
"api_key": "",
|
|
||||||
"api_host": ""
|
|
||||||
}
|
|
||||||
|
|
||||||
# 工作流映射配置
|
|
||||||
WORKFLOW_MAPPINGS = {
|
|
||||||
"reactor_taken_out": "",
|
|
||||||
"reactor_taken_in": "",
|
|
||||||
"Solid_feeding_vials": "",
|
|
||||||
"Liquid_feeding_vials(non-titration)": "",
|
|
||||||
"Liquid_feeding_solvents": "",
|
|
||||||
"Liquid_feeding(titration)": "",
|
|
||||||
"liquid_feeding_beaker": "",
|
|
||||||
"Drip_back": "",
|
|
||||||
}
|
|
||||||
|
|
||||||
# 工作流名称到DisplaySectionName的映射
|
|
||||||
WORKFLOW_TO_SECTION_MAP = {
|
|
||||||
'reactor_taken_in': '反应器放入',
|
|
||||||
'liquid_feeding_beaker': '液体投料-烧杯',
|
|
||||||
'Liquid_feeding_vials(non-titration)': '液体投料-小瓶(非滴定)',
|
|
||||||
'Liquid_feeding_solvents': '液体投料-溶剂',
|
|
||||||
'Solid_feeding_vials': '固体投料-小瓶',
|
|
||||||
'Liquid_feeding(titration)': '液体投料-滴定',
|
|
||||||
'reactor_taken_out': '反应器取出'
|
|
||||||
}
|
|
||||||
|
|
||||||
# 库位映射配置
|
|
||||||
WAREHOUSE_MAPPING = {
|
|
||||||
"粉末堆栈": {
|
|
||||||
"uuid": "",
|
|
||||||
"site_uuids": {
|
|
||||||
# 样品板
|
|
||||||
"A1": "3a14198e-6929-31f0-8a22-0f98f72260df",
|
|
||||||
"A2": "3a14198e-6929-4379-affa-9a2935c17f99",
|
|
||||||
"A3": "3a14198e-6929-56da-9a1c-7f5fbd4ae8af",
|
|
||||||
"A4": "3a14198e-6929-5e99-2b79-80720f7cfb54",
|
|
||||||
"B1": "3a14198e-6929-f525-9a1b-1857552b28ee",
|
|
||||||
"B2": "3a14198e-6929-bf98-0fd5-26e1d68bf62d",
|
|
||||||
"B3": "3a14198e-6929-2d86-a468-602175a2b5aa",
|
|
||||||
"B4": "3a14198e-6929-1a98-ae57-e97660c489ad",
|
|
||||||
# 分装板
|
|
||||||
"C1": "3a14198e-6929-46fe-841e-03dd753f1e4a",
|
|
||||||
"C2": "3a14198e-6929-1bc9-a9bd-3b7ca66e7f95",
|
|
||||||
"C3": "3a14198e-6929-72ac-32ce-9b50245682b8",
|
|
||||||
"C4": "3a14198e-6929-3bd8-e6c7-4a9fd93be118",
|
|
||||||
"D1": "3a14198e-6929-8a0b-b686-6f4a2955c4e2",
|
|
||||||
"D2": "3a14198e-6929-dde1-fc78-34a84b71afdf",
|
|
||||||
"D3": "3a14198e-6929-a0ec-5f15-c0f9f339f963",
|
|
||||||
"D4": "3a14198e-6929-7ac8-915a-fea51cb2e884"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"溶液堆栈": {
|
|
||||||
"uuid": "",
|
|
||||||
"site_uuids": {
|
|
||||||
"A1": "3a14198e-d724-e036-afdc-2ae39a7f3383",
|
|
||||||
"A2": "3a14198e-d724-afa4-fc82-0ac8a9016791",
|
|
||||||
"A3": "3a14198e-d724-ca48-bb9e-7e85751e55b6",
|
|
||||||
"A4": "3a14198e-d724-df6d-5e32-5483b3cab583",
|
|
||||||
"B1": "3a14198e-d724-d818-6d4f-5725191a24b5",
|
|
||||||
"B2": "3a14198e-d724-be8a-5e0b-012675e195c6",
|
|
||||||
"B3": "3a14198e-d724-cc1e-5c2c-228a130f40a8",
|
|
||||||
"B4": "3a14198e-d724-1e28-c885-574c3df468d0",
|
|
||||||
"C1": "3a14198e-d724-b5bb-adf3-4c5a0da6fb31",
|
|
||||||
"C2": "3a14198e-d724-ab4e-48cb-817c3c146707",
|
|
||||||
"C3": "3a14198e-d724-7f18-1853-39d0c62e1d33",
|
|
||||||
"C4": "3a14198e-d724-28a2-a760-baa896f46b66",
|
|
||||||
"D1": "3a14198e-d724-d378-d266-2508a224a19f",
|
|
||||||
"D2": "3a14198e-d724-f56e-468b-0110a8feb36a",
|
|
||||||
"D3": "3a14198e-d724-0cf1-dea9-a1f40fe7e13c",
|
|
||||||
"D4": "3a14198e-d724-0ddd-9654-f9352a421de9"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"试剂堆栈": {
|
|
||||||
"uuid": "",
|
|
||||||
"site_uuids": {
|
|
||||||
"A1": "3a14198c-c2cf-8b40-af28-b467808f1c36",
|
|
||||||
"A2": "3a14198c-c2d0-f3e7-871a-e470d144296f",
|
|
||||||
"A3": "3a14198c-c2d0-dc7d-b8d0-e1d88cee3094",
|
|
||||||
"A4": "3a14198c-c2d0-2070-efc8-44e245f10c6f",
|
|
||||||
"B1": "3a14198c-c2d0-354f-39ad-642e1a72fcb8",
|
|
||||||
"B2": "3a14198c-c2d0-1559-105d-0ea30682cab4",
|
|
||||||
"B3": "3a14198c-c2d0-725e-523d-34c037ac2440",
|
|
||||||
"B4": "3a14198c-c2d0-efce-0939-69ca5a7dfd39"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# 物料类型配置
|
|
||||||
MATERIAL_TYPE_MAPPINGS = {
|
|
||||||
"烧杯": ("BIOYOND_PolymerStation_1FlaskCarrier", "3a14196b-24f2-ca49-9081-0cab8021bf1a"),
|
|
||||||
"试剂瓶": ("BIOYOND_PolymerStation_1BottleCarrier", ""),
|
|
||||||
"样品板": ("BIOYOND_PolymerStation_6StockCarrier", "3a14196e-b7a0-a5da-1931-35f3000281e9"),
|
|
||||||
"分装板": ("BIOYOND_PolymerStation_6VialCarrier", "3a14196e-5dfe-6e21-0c79-fe2036d052c4"),
|
|
||||||
"样品瓶": ("BIOYOND_PolymerStation_Solid_Stock", "3a14196a-cf7d-8aea-48d8-b9662c7dba94"),
|
|
||||||
"90%分装小瓶": ("BIOYOND_PolymerStation_Solid_Vial", "3a14196c-cdcf-088d-dc7d-5cf38f0ad9ea"),
|
|
||||||
"10%分装小瓶": ("BIOYOND_PolymerStation_Liquid_Vial", "3a14196c-76be-2279-4e22-7310d69aed68"),
|
|
||||||
}
|
|
||||||
|
|
||||||
# 步骤参数配置(各工作流的步骤UUID)
|
|
||||||
WORKFLOW_STEP_IDS = {
|
|
||||||
"reactor_taken_in": {
|
|
||||||
"config": ""
|
|
||||||
},
|
|
||||||
"liquid_feeding_beaker": {
|
|
||||||
"liquid": "",
|
|
||||||
"observe": ""
|
|
||||||
},
|
|
||||||
"liquid_feeding_vials_non_titration": {
|
|
||||||
"liquid": "",
|
|
||||||
"observe": ""
|
|
||||||
},
|
|
||||||
"liquid_feeding_solvents": {
|
|
||||||
"liquid": "",
|
|
||||||
"observe": ""
|
|
||||||
},
|
|
||||||
"solid_feeding_vials": {
|
|
||||||
"feeding": "",
|
|
||||||
"observe": ""
|
|
||||||
},
|
|
||||||
"liquid_feeding_titration": {
|
|
||||||
"liquid": "",
|
|
||||||
"observe": ""
|
|
||||||
},
|
|
||||||
"drip_back": {
|
|
||||||
"liquid": "",
|
|
||||||
"observe": ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LOCATION_MAPPING = {}
|
|
||||||
|
|
||||||
ACTION_NAMES = {}
|
|
||||||
|
|
||||||
HTTP_SERVICE_CONFIG = {}
|
|
||||||
329
unilabos/devices/workstation/bioyond_studio/config.py.deprecated
Normal file
329
unilabos/devices/workstation/bioyond_studio/config.py.deprecated
Normal file
@@ -0,0 +1,329 @@
|
|||||||
|
# config.py
|
||||||
|
"""
|
||||||
|
Bioyond工作站配置文件
|
||||||
|
包含API配置、工作流映射、物料类型映射、仓库库位映射等所有配置信息
|
||||||
|
"""
|
||||||
|
|
||||||
|
from unilabos.resources.bioyond.decks import BIOYOND_PolymerReactionStation_Deck
|
||||||
|
|
||||||
|
# ============================================================================
|
||||||
|
# 基础配置
|
||||||
|
# ============================================================================
|
||||||
|
|
||||||
|
# API配置
|
||||||
|
API_CONFIG = {
|
||||||
|
"api_key": "DE9BDDA0",
|
||||||
|
"api_host": "http://192.168.1.200:44402"
|
||||||
|
}
|
||||||
|
|
||||||
|
# HTTP 报送服务配置
|
||||||
|
HTTP_SERVICE_CONFIG = {
|
||||||
|
"http_service_host": "127.0.0.1", # 监听地址
|
||||||
|
"http_service_port": 8080, # 监听端口
|
||||||
|
}
|
||||||
|
|
||||||
|
# Deck配置 - 反应站工作台配置
|
||||||
|
DECK_CONFIG = BIOYOND_PolymerReactionStation_Deck(setup=True)
|
||||||
|
|
||||||
|
# ============================================================================
|
||||||
|
# 工作流配置
|
||||||
|
# ============================================================================
|
||||||
|
|
||||||
|
# 工作流ID映射
|
||||||
|
WORKFLOW_MAPPINGS = {
|
||||||
|
"reactor_taken_out": "3a16081e-4788-ca37-eff4-ceed8d7019d1",
|
||||||
|
"reactor_taken_in": "3a160df6-76b3-0957-9eb0-cb496d5721c6",
|
||||||
|
"Solid_feeding_vials": "3a160877-87e7-7699-7bc6-ec72b05eb5e6",
|
||||||
|
"Liquid_feeding_vials(non-titration)": "3a167d99-6158-c6f0-15b5-eb030f7d8e47",
|
||||||
|
"Liquid_feeding_solvents": "3a160824-0665-01ed-285a-51ef817a9046",
|
||||||
|
"Liquid_feeding(titration)": "3a16082a-96ac-0449-446a-4ed39f3365b6",
|
||||||
|
"liquid_feeding_beaker": "3a16087e-124f-8ddb-8ec1-c2dff09ca784",
|
||||||
|
"Drip_back": "3a162cf9-6aac-565a-ddd7-682ba1796a4a",
|
||||||
|
}
|
||||||
|
|
||||||
|
# 工作流名称到显示名称的映射
|
||||||
|
WORKFLOW_TO_SECTION_MAP = {
|
||||||
|
'reactor_taken_in': '反应器放入',
|
||||||
|
'reactor_taken_out': '反应器取出',
|
||||||
|
'Solid_feeding_vials': '固体投料-小瓶',
|
||||||
|
'Liquid_feeding_vials(non-titration)': '液体投料-小瓶(非滴定)',
|
||||||
|
'Liquid_feeding_solvents': '液体投料-溶剂',
|
||||||
|
'Liquid_feeding(titration)': '液体投料-滴定',
|
||||||
|
'liquid_feeding_beaker': '液体投料-烧杯',
|
||||||
|
'Drip_back': '液体回滴'
|
||||||
|
}
|
||||||
|
|
||||||
|
# 工作流步骤ID配置
|
||||||
|
WORKFLOW_STEP_IDS = {
|
||||||
|
"reactor_taken_in": {
|
||||||
|
"config": "60a06f85-c5b3-29eb-180f-4f62dd7e2154"
|
||||||
|
},
|
||||||
|
"liquid_feeding_beaker": {
|
||||||
|
"liquid": "6808cda7-fee7-4092-97f0-5f9c2ffa60e3",
|
||||||
|
"observe": "1753c0de-dffc-4ee6-8458-805a2e227362"
|
||||||
|
},
|
||||||
|
"liquid_feeding_vials_non_titration": {
|
||||||
|
"liquid": "62ea6e95-3d5d-43db-bc1e-9a1802673861",
|
||||||
|
"observe": "3a167d99-6172-b67b-5f22-a7892197142e"
|
||||||
|
},
|
||||||
|
"liquid_feeding_solvents": {
|
||||||
|
"liquid": "1fcea355-2545-462b-b727-350b69a313bf",
|
||||||
|
"observe": "0553dfb3-9ac5-4ace-8e00-2f11029919a8"
|
||||||
|
},
|
||||||
|
"solid_feeding_vials": {
|
||||||
|
"feeding": "f7ae7448-4f20-4c1d-8096-df6fbadd787a",
|
||||||
|
"observe": "263c7ed5-7277-426b-bdff-d6fbf77bcc05"
|
||||||
|
},
|
||||||
|
"liquid_feeding_titration": {
|
||||||
|
"liquid": "a00ec41b-e666-4422-9c20-bfcd3cd15c54",
|
||||||
|
"observe": "ac738ff6-4c58-4155-87b1-d6f65a2c9ab5"
|
||||||
|
},
|
||||||
|
"drip_back": {
|
||||||
|
"liquid": "371be86a-ab77-4769-83e5-54580547c48a",
|
||||||
|
"observe": "ce024b9d-bd20-47b8-9f78-ca5ce7f44cf1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# 工作流动作名称配置
|
||||||
|
ACTION_NAMES = {
|
||||||
|
"reactor_taken_in": {
|
||||||
|
"config": "通量-配置",
|
||||||
|
"stirring": "反应模块-开始搅拌"
|
||||||
|
},
|
||||||
|
"solid_feeding_vials": {
|
||||||
|
"feeding": "粉末加样模块-投料",
|
||||||
|
"observe": "反应模块-观察搅拌结果"
|
||||||
|
},
|
||||||
|
"liquid_feeding_vials_non_titration": {
|
||||||
|
"liquid": "稀释液瓶加液位-液体投料",
|
||||||
|
"observe": "反应模块-滴定结果观察"
|
||||||
|
},
|
||||||
|
"liquid_feeding_solvents": {
|
||||||
|
"liquid": "试剂AB放置位-试剂吸液分液",
|
||||||
|
"observe": "反应模块-观察搅拌结果"
|
||||||
|
},
|
||||||
|
"liquid_feeding_titration": {
|
||||||
|
"liquid": "稀释液瓶加液位-稀释液吸液分液",
|
||||||
|
"observe": "反应模块-滴定结果观察"
|
||||||
|
},
|
||||||
|
"liquid_feeding_beaker": {
|
||||||
|
"liquid": "烧杯溶液放置位-烧杯吸液分液",
|
||||||
|
"observe": "反应模块-观察搅拌结果"
|
||||||
|
},
|
||||||
|
"drip_back": {
|
||||||
|
"liquid": "试剂AB放置位-试剂吸液分液",
|
||||||
|
"observe": "反应模块-向下滴定结果观察"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# ============================================================================
|
||||||
|
# 仓库配置
|
||||||
|
# ============================================================================
|
||||||
|
# 说明:
|
||||||
|
# - 出库和入库操作都需要UUID
|
||||||
|
WAREHOUSE_MAPPING = {
|
||||||
|
# ========== 反应站仓库 ==========
|
||||||
|
|
||||||
|
# 堆栈1左 - 反应站左侧堆栈 (4行×4列=16个库位, A01~D04)
|
||||||
|
"堆栈1左": {
|
||||||
|
"uuid": "3a14aa17-0d49-dce4-486e-4b5c85c8b366",
|
||||||
|
"site_uuids": {
|
||||||
|
"A01": "3a14aa17-0d49-11d7-a6e1-f236b3e5e5a3",
|
||||||
|
"A02": "3a14aa17-0d49-4bc5-8836-517b75473f5f",
|
||||||
|
"A03": "3a14aa17-0d49-c2bc-6222-5cee8d2d94f8",
|
||||||
|
"A04": "3a14aa17-0d49-3ce2-8e9a-008c38d116fb",
|
||||||
|
"B01": "3a14aa17-0d49-f49c-6b66-b27f185a3b32",
|
||||||
|
"B02": "3a14aa17-0d49-cf46-df85-a979c9c9920c",
|
||||||
|
"B03": "3a14aa17-0d49-7698-4a23-f7ffb7d48ba3",
|
||||||
|
"B04": "3a14aa17-0d49-1231-99be-d5870e6478e9",
|
||||||
|
"C01": "3a14aa17-0d49-be34-6fae-4aed9d48b70b",
|
||||||
|
"C02": "3a14aa17-0d49-11d7-0897-34921dcf6b7c",
|
||||||
|
"C03": "3a14aa17-0d49-9840-0bd5-9c63c1bb2c29",
|
||||||
|
"C04": "3a14aa17-0d49-8335-3bff-01da69ea4911",
|
||||||
|
"D01": "3a14aa17-0d49-2bea-c8e5-2b32094935d5",
|
||||||
|
"D02": "3a14aa17-0d49-cff4-e9e8-5f5f0bc1ef32",
|
||||||
|
"D03": "3a14aa17-0d49-4948-cb0a-78f30d1ca9b8",
|
||||||
|
"D04": "3a14aa17-0d49-fd2f-9dfb-a29b11e84099",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
# 堆栈1右 - 反应站右侧堆栈 (4行×4列=16个库位, A05~D08)
|
||||||
|
"堆栈1右": {
|
||||||
|
"uuid": "3a14aa17-0d49-dce4-486e-4b5c85c8b366",
|
||||||
|
"site_uuids": {
|
||||||
|
"A05": "3a14aa17-0d49-2c61-edc8-72a8ca7192dd",
|
||||||
|
"A06": "3a14aa17-0d49-60c8-2b00-40b17198f397",
|
||||||
|
"A07": "3a14aa17-0d49-ec5b-0b75-634dce8eed25",
|
||||||
|
"A08": "3a14aa17-0d49-3ec9-55b3-f3189c4ec53d",
|
||||||
|
"B05": "3a14aa17-0d49-6a4e-abcf-4c113eaaeaad",
|
||||||
|
"B06": "3a14aa17-0d49-e3f6-2dd6-28c2e8194fbe",
|
||||||
|
"B07": "3a14aa17-0d49-11a6-b861-ee895121bf52",
|
||||||
|
"B08": "3a14aa17-0d49-9c7d-1145-d554a6e482f0",
|
||||||
|
"C05": "3a14aa17-0d49-45c4-7a34-5105bc3e2368",
|
||||||
|
"C06": "3a14aa17-0d49-867e-39ab-31b3fe9014be",
|
||||||
|
"C07": "3a14aa17-0d49-ec56-c4b4-39fd9b2131e7",
|
||||||
|
"C08": "3a14aa17-0d49-1128-d7d9-ffb1231c98c0",
|
||||||
|
"D05": "3a14aa17-0d49-e843-f961-ea173326a14b",
|
||||||
|
"D06": "3a14aa17-0d49-4d26-a985-f188359c4f8b",
|
||||||
|
"D07": "3a14aa17-0d49-223a-b520-bc092bb42fe0",
|
||||||
|
"D08": "3a14aa17-0d49-4fa3-401a-6a444e1cca22",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
# 站内试剂存放堆栈
|
||||||
|
"站内试剂存放堆栈": {
|
||||||
|
"uuid": "3a14aa3b-9fab-9d8e-d1a7-828f01f51f0c",
|
||||||
|
"site_uuids": {
|
||||||
|
"A01": "3a14aa3b-9fab-adac-7b9c-e1ee446b51d5",
|
||||||
|
"A02": "3a14aa3b-9fab-ca72-febc-b7c304476c78"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
# 测量小瓶仓库(测密度)
|
||||||
|
"测量小瓶仓库": {
|
||||||
|
"uuid": "3a15012f-705b-c0de-3f9e-950c205f9921",
|
||||||
|
"site_uuids": {
|
||||||
|
"A01": "3a15012f-705e-0524-3161-c523b5aebc97",
|
||||||
|
"A02": "3a15012f-705e-7cd1-32ab-ad4fd1ab75c8",
|
||||||
|
"A03": "3a15012f-705e-a5d6-edac-bdbfec236260",
|
||||||
|
"B01": "3a15012f-705e-e0ee-80e0-10a6b3fc500d",
|
||||||
|
"B02": "3a15012f-705e-e499-180d-de06d60d0b21",
|
||||||
|
"B03": "3a15012f-705e-eff6-63f1-09f742096b26"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
# 站内Tip盒堆栈 - 用于存放枪头盒 (耗材)
|
||||||
|
"站内Tip盒堆栈": {
|
||||||
|
"uuid": "3a14aa3a-2d3c-b5c1-9ddf-7c4a957d459a",
|
||||||
|
"site_uuids": {
|
||||||
|
"A01": "3a14aa3a-2d3d-e700-411a-0ddf85e1f18a",
|
||||||
|
"A02": "3a14aa3a-2d3d-a7ce-099a-d5632fdafa24",
|
||||||
|
"A03": "3a14aa3a-2d3d-bdf6-a702-c60b38b08501",
|
||||||
|
"B01": "3a14aa3a-2d3d-d704-f076-2a8d5bc72cb8",
|
||||||
|
"B02": "3a14aa3a-2d3d-c350-2526-0778d173a5ac",
|
||||||
|
"B03": "3a14aa3a-2d3d-bc38-b356-f0de2e44e0c7"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
# ========== 配液站仓库 ==========
|
||||||
|
"粉末堆栈": {
|
||||||
|
"uuid": "3a14198e-6928-121f-7ca6-88ad3ae7e6a0",
|
||||||
|
"site_uuids": {
|
||||||
|
"A01": "3a14198e-6929-31f0-8a22-0f98f72260df",
|
||||||
|
"A02": "3a14198e-6929-4379-affa-9a2935c17f99",
|
||||||
|
"A03": "3a14198e-6929-56da-9a1c-7f5fbd4ae8af",
|
||||||
|
"A04": "3a14198e-6929-5e99-2b79-80720f7cfb54",
|
||||||
|
"B01": "3a14198e-6929-f525-9a1b-1857552b28ee",
|
||||||
|
"B02": "3a14198e-6929-bf98-0fd5-26e1d68bf62d",
|
||||||
|
"B03": "3a14198e-6929-2d86-a468-602175a2b5aa",
|
||||||
|
"B04": "3a14198e-6929-1a98-ae57-e97660c489ad",
|
||||||
|
"C01": "3a14198e-6929-46fe-841e-03dd753f1e4a",
|
||||||
|
"C02": "3a14198e-6929-72ac-32ce-9b50245682b8",
|
||||||
|
"C03": "3a14198e-6929-8a0b-b686-6f4a2955c4e2",
|
||||||
|
"C04": "3a14198e-6929-a0ec-5f15-c0f9f339f963",
|
||||||
|
"D01": "3a14198e-6929-1bc9-a9bd-3b7ca66e7f95",
|
||||||
|
"D02": "3a14198e-6929-3bd8-e6c7-4a9fd93be118",
|
||||||
|
"D03": "3a14198e-6929-dde1-fc78-34a84b71afdf",
|
||||||
|
"D04": "3a14198e-6929-7ac8-915a-fea51cb2e884"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"溶液堆栈": {
|
||||||
|
"uuid": "3a14198e-d723-2c13-7d12-50143e190a23",
|
||||||
|
"site_uuids": {
|
||||||
|
"A01": "3a14198e-d724-e036-afdc-2ae39a7f3383",
|
||||||
|
"A02": "3a14198e-d724-d818-6d4f-5725191a24b5",
|
||||||
|
"A03": "3a14198e-d724-b5bb-adf3-4c5a0da6fb31",
|
||||||
|
"A04": "3a14198e-d724-d378-d266-2508a224a19f",
|
||||||
|
"B01": "3a14198e-d724-afa4-fc82-0ac8a9016791",
|
||||||
|
"B02": "3a14198e-d724-be8a-5e0b-012675e195c6",
|
||||||
|
"B03": "3a14198e-d724-ab4e-48cb-817c3c146707",
|
||||||
|
"B04": "3a14198e-d724-f56e-468b-0110a8feb36a",
|
||||||
|
"C01": "3a14198e-d724-ca48-bb9e-7e85751e55b6",
|
||||||
|
"C02": "3a14198e-d724-cc1e-5c2c-228a130f40a8",
|
||||||
|
"C03": "3a14198e-d724-7f18-1853-39d0c62e1d33",
|
||||||
|
"C04": "3a14198e-d724-0cf1-dea9-a1f40fe7e13c",
|
||||||
|
"D01": "3a14198e-d724-df6d-5e32-5483b3cab583",
|
||||||
|
"D02": "3a14198e-d724-1e28-c885-574c3df468d0",
|
||||||
|
"D03": "3a14198e-d724-28a2-a760-baa896f46b66",
|
||||||
|
"D04": "3a14198e-d724-0ddd-9654-f9352a421de9"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"试剂堆栈": {
|
||||||
|
"uuid": "3a14198c-c2cc-0290-e086-44a428fba248",
|
||||||
|
"site_uuids": {
|
||||||
|
"A01": "3a14198c-c2cf-8b40-af28-b467808f1c36", # x=1, y=1, code=0001-0001
|
||||||
|
"A02": "3a14198c-c2d0-dc7d-b8d0-e1d88cee3094", # x=1, y=2, code=0001-0002
|
||||||
|
"A03": "3a14198c-c2d0-354f-39ad-642e1a72fcb8", # x=1, y=3, code=0001-0003
|
||||||
|
"A04": "3a14198c-c2d0-725e-523d-34c037ac2440", # x=1, y=4, code=0001-0004
|
||||||
|
"B01": "3a14198c-c2d0-f3e7-871a-e470d144296f", # x=2, y=1, code=0001-0005
|
||||||
|
"B02": "3a14198c-c2d0-2070-efc8-44e245f10c6f", # x=2, y=2, code=0001-0006
|
||||||
|
"B03": "3a14198c-c2d0-1559-105d-0ea30682cab4", # x=2, y=3, code=0001-0007
|
||||||
|
"B04": "3a14198c-c2d0-efce-0939-69ca5a7dfd39" # x=2, y=4, code=0001-0008
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# ============================================================================
|
||||||
|
# 物料类型配置
|
||||||
|
# ============================================================================
|
||||||
|
# 说明:
|
||||||
|
# - 格式: PyLabRobot资源类型名称 → Bioyond系统typeId的UUID
|
||||||
|
# - 这个映射基于 resource.model 属性 (不是显示名称!)
|
||||||
|
# - UUID为空表示该类型暂未在Bioyond系统中定义
|
||||||
|
MATERIAL_TYPE_MAPPINGS = {
|
||||||
|
# ================================================配液站资源============================================================
|
||||||
|
# ==================================================样品===============================================================
|
||||||
|
"BIOYOND_PolymerStation_1FlaskCarrier": ("烧杯", "3a14196b-24f2-ca49-9081-0cab8021bf1a"), # 配液站-样品-烧杯
|
||||||
|
"BIOYOND_PolymerStation_1BottleCarrier": ("试剂瓶", "3a14196b-8bcf-a460-4f74-23f21ca79e72"), # 配液站-样品-试剂瓶
|
||||||
|
"BIOYOND_PolymerStation_6StockCarrier": ("分装板", "3a14196e-5dfe-6e21-0c79-fe2036d052c4"), # 配液站-样品-分装板
|
||||||
|
"BIOYOND_PolymerStation_Liquid_Vial": ("10%分装小瓶", "3a14196c-76be-2279-4e22-7310d69aed68"), # 配液站-样品-分装板-第一排小瓶
|
||||||
|
"BIOYOND_PolymerStation_Solid_Vial": ("90%分装小瓶", "3a14196c-cdcf-088d-dc7d-5cf38f0ad9ea"), # 配液站-样品-分装板-第二排小瓶
|
||||||
|
# ==================================================试剂===============================================================
|
||||||
|
"BIOYOND_PolymerStation_8StockCarrier": ("样品板", "3a14196e-b7a0-a5da-1931-35f3000281e9"), # 配液站-试剂-样品板(8孔)
|
||||||
|
"BIOYOND_PolymerStation_Solid_Stock": ("样品瓶", "3a14196a-cf7d-8aea-48d8-b9662c7dba94"), # 配液站-试剂-样品板-样品瓶
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
# ============================================================================
|
||||||
|
# 动态生成的库位UUID映射(从WAREHOUSE_MAPPING中提取)
|
||||||
|
# ============================================================================
|
||||||
|
|
||||||
|
LOCATION_MAPPING = {}
|
||||||
|
for warehouse_name, warehouse_config in WAREHOUSE_MAPPING.items():
|
||||||
|
if "site_uuids" in warehouse_config:
|
||||||
|
LOCATION_MAPPING.update(warehouse_config["site_uuids"])
|
||||||
|
|
||||||
|
# ============================================================================
|
||||||
|
# 物料默认参数配置
|
||||||
|
# ============================================================================
|
||||||
|
# 说明:
|
||||||
|
# - 为特定物料名称自动添加默认参数(如密度、分子量、单位等)
|
||||||
|
# - 格式: 物料名称 → {参数字典}
|
||||||
|
# - 在创建或更新物料时,会自动合并这些参数到 Parameters 字段
|
||||||
|
# - unit: 物料的计量单位(会用于 unit 字段)
|
||||||
|
# - density/densityUnit: 密度信息(会添加到 Parameters 中)
|
||||||
|
|
||||||
|
MATERIAL_DEFAULT_PARAMETERS = {
|
||||||
|
# 溶剂类
|
||||||
|
"NMP": {
|
||||||
|
"unit": "毫升",
|
||||||
|
"density": "1.03",
|
||||||
|
"densityUnit": "g/mL",
|
||||||
|
"description": "N-甲基吡咯烷酮 (N-Methyl-2-pyrrolidone)"
|
||||||
|
},
|
||||||
|
# 可以继续添加其他物料...
|
||||||
|
}
|
||||||
|
|
||||||
|
# ============================================================================
|
||||||
|
# 物料类型默认参数配置
|
||||||
|
# ============================================================================
|
||||||
|
# 说明:
|
||||||
|
# - 为特定物料类型(UUID)自动添加默认参数
|
||||||
|
# - 格式: Bioyond类型UUID → {参数字典}
|
||||||
|
# - 优先级低于按名称匹配的配置
|
||||||
|
MATERIAL_TYPE_PARAMETERS = {
|
||||||
|
# 示例:
|
||||||
|
# "3a14196b-24f2-ca49-9081-0cab8021bf1a": { # 烧杯
|
||||||
|
# "unit": "个"
|
||||||
|
# }
|
||||||
|
}
|
||||||
459
unilabos/devices/workstation/bioyond_studio/debug_call_log.py
Normal file
459
unilabos/devices/workstation/bioyond_studio/debug_call_log.py
Normal file
@@ -0,0 +1,459 @@
|
|||||||
|
"""Per-action raw call/response log for Bioyond stations.
|
||||||
|
|
||||||
|
When a debug session is active, ``wrap_rpc_http`` replaces a ``BioyondV1RPC``
|
||||||
|
instance's ``post`` / ``get`` methods with closures that perform the HTTP
|
||||||
|
transport themselves, capture the request/response details, and append a record
|
||||||
|
to the active session before returning exactly what ``BaseRequest`` would have
|
||||||
|
returned. Outside of an active session the wrapped method delegates to the
|
||||||
|
original (unwrapped) implementation, leaving non-debug behavior intact.
|
||||||
|
|
||||||
|
The session writes a Markdown file under ``out_dir`` mirroring the format of
|
||||||
|
``temp_benyao/peptide/_logs/2026-04-30_160316_day3_samplefile_only_raw_calls.md``
|
||||||
|
minus the "Raw Payload Argument" section.
|
||||||
|
|
||||||
|
This module has no dependency on ``BioyondV1RPC`` itself; the only contract is
|
||||||
|
that the wrapped instance descends from ``BaseRequest`` (i.e. has a logger
|
||||||
|
returned by ``self.get_logger()``).
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import contextvars
|
||||||
|
import copy
|
||||||
|
import inspect
|
||||||
|
import json
|
||||||
|
import re
|
||||||
|
from contextlib import contextmanager
|
||||||
|
from dataclasses import dataclass, field
|
||||||
|
from datetime import datetime
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Any, Iterator, List, Optional
|
||||||
|
|
||||||
|
import requests
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"CallRecord",
|
||||||
|
"CallLogContext",
|
||||||
|
"session",
|
||||||
|
"wrap_rpc_http",
|
||||||
|
"active_session",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
_DEFAULT_TIMEOUT_GET = 30
|
||||||
|
_DEFAULT_TIMEOUT_POST = 120
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class CallRecord:
|
||||||
|
"""One captured HTTP call inside a debug session."""
|
||||||
|
|
||||||
|
index: int
|
||||||
|
method: str
|
||||||
|
url: str
|
||||||
|
path: str
|
||||||
|
source: str
|
||||||
|
transport: str
|
||||||
|
http_status: Optional[int]
|
||||||
|
request_body: Any
|
||||||
|
response_body: Any
|
||||||
|
error: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class CallLogContext:
|
||||||
|
"""State for a single ``session()`` block.
|
||||||
|
|
||||||
|
A session lazily creates its file on the first appended record. Actions
|
||||||
|
that abort before any RPC produce no file.
|
||||||
|
"""
|
||||||
|
|
||||||
|
action: str
|
||||||
|
out_dir: Path
|
||||||
|
started_at: datetime
|
||||||
|
calls: List[CallRecord] = field(default_factory=list)
|
||||||
|
file_path: Optional[Path] = None
|
||||||
|
|
||||||
|
def append(self, record: CallRecord) -> None:
|
||||||
|
record.index = len(self.calls) + 1
|
||||||
|
self.calls.append(record)
|
||||||
|
self._write_file()
|
||||||
|
|
||||||
|
# -- file I/O -------------------------------------------------------------
|
||||||
|
|
||||||
|
def _resolve_file_path(self) -> Path:
|
||||||
|
if self.file_path is not None:
|
||||||
|
return self.file_path
|
||||||
|
timestamp = self.started_at.strftime("%Y-%m-%d_%H%M%S")
|
||||||
|
slug = _slugify_action(self.action)
|
||||||
|
candidate = self.out_dir / f"{timestamp}_{slug}_raw_calls.md"
|
||||||
|
suffix = 2
|
||||||
|
while candidate.exists():
|
||||||
|
candidate = (
|
||||||
|
self.out_dir
|
||||||
|
/ f"{timestamp}_{slug}_raw_calls_{suffix:02d}.md"
|
||||||
|
)
|
||||||
|
suffix += 1
|
||||||
|
self.file_path = candidate
|
||||||
|
return self.file_path
|
||||||
|
|
||||||
|
def _write_file(self) -> None:
|
||||||
|
path = self._resolve_file_path()
|
||||||
|
path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
path.write_text(_render_markdown(self), encoding="utf-8")
|
||||||
|
|
||||||
|
|
||||||
|
_active_session: contextvars.ContextVar[Optional[CallLogContext]] = (
|
||||||
|
contextvars.ContextVar("_active_session", default=None)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def active_session() -> Optional[CallLogContext]:
|
||||||
|
"""Return the currently active :class:`CallLogContext`, if any."""
|
||||||
|
return _active_session.get()
|
||||||
|
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def session(action: str, out_dir: Path) -> Iterator[CallLogContext]:
|
||||||
|
"""Open a per-action debug session.
|
||||||
|
|
||||||
|
On entry, sets the module-level ``_active_session`` ContextVar so any
|
||||||
|
``wrap_rpc_http``'d clients on the same thread/task record their calls.
|
||||||
|
On exit, the previous active session (if any) is restored.
|
||||||
|
"""
|
||||||
|
ctx = CallLogContext(
|
||||||
|
action=str(action),
|
||||||
|
out_dir=Path(out_dir),
|
||||||
|
started_at=datetime.now(),
|
||||||
|
)
|
||||||
|
token = _active_session.set(ctx)
|
||||||
|
try:
|
||||||
|
yield ctx
|
||||||
|
finally:
|
||||||
|
_active_session.reset(token)
|
||||||
|
|
||||||
|
|
||||||
|
def wrap_rpc_http(rpc: Any) -> None:
|
||||||
|
"""Idempotently wrap ``rpc.post`` / ``rpc.get``.
|
||||||
|
|
||||||
|
When a session is active (``_active_session.get() is not None``), the
|
||||||
|
wrapped methods perform the HTTP call themselves with ``requests`` and
|
||||||
|
record the call before returning the same value ``BaseRequest`` would have
|
||||||
|
returned. When no session is active, the wrapped methods delegate to the
|
||||||
|
original implementation, preserving stock ``BaseRequest`` behavior.
|
||||||
|
|
||||||
|
Calling this twice on the same instance is a no-op. The wrapper does not
|
||||||
|
alter ``rpc.form_post`` (no Sirna action calls it as of plan 3).
|
||||||
|
"""
|
||||||
|
if rpc is None:
|
||||||
|
return
|
||||||
|
if getattr(rpc, "_debug_call_log_wrapped", False):
|
||||||
|
return
|
||||||
|
|
||||||
|
rpc._orig_post = rpc.post
|
||||||
|
rpc._orig_get = rpc.get
|
||||||
|
|
||||||
|
def _wrapped_post(
|
||||||
|
url: str,
|
||||||
|
params: Any = None,
|
||||||
|
files: Any = None,
|
||||||
|
headers: Optional[dict] = None,
|
||||||
|
) -> Any:
|
||||||
|
ctx = _active_session.get()
|
||||||
|
if ctx is None:
|
||||||
|
kwargs = {}
|
||||||
|
if params is not None:
|
||||||
|
kwargs["params"] = params
|
||||||
|
if files is not None:
|
||||||
|
kwargs["files"] = files
|
||||||
|
if headers is not None:
|
||||||
|
kwargs["headers"] = headers
|
||||||
|
return rpc._orig_post(url, **kwargs)
|
||||||
|
effective_params = params if params is not None else {}
|
||||||
|
effective_headers = (
|
||||||
|
headers
|
||||||
|
if headers is not None
|
||||||
|
else {"Content-Type": "application/json"}
|
||||||
|
)
|
||||||
|
source = _detect_source(rpc)
|
||||||
|
request_body = _redact(effective_params)
|
||||||
|
record = CallRecord(
|
||||||
|
index=0,
|
||||||
|
method="POST",
|
||||||
|
url=str(url),
|
||||||
|
path=_url_path(url),
|
||||||
|
source=source,
|
||||||
|
transport=_pick_transport(effective_params),
|
||||||
|
http_status=None,
|
||||||
|
request_body=request_body,
|
||||||
|
response_body=None,
|
||||||
|
error=None,
|
||||||
|
)
|
||||||
|
return_value: Any = None
|
||||||
|
try:
|
||||||
|
response = requests.post(
|
||||||
|
url,
|
||||||
|
data=json.dumps(effective_params) if effective_params else None,
|
||||||
|
headers=effective_headers,
|
||||||
|
timeout=_DEFAULT_TIMEOUT_POST,
|
||||||
|
files=files,
|
||||||
|
)
|
||||||
|
except Exception as exc: # pragma: no cover - delegated to logger
|
||||||
|
record.error = f"transport error: {exc}"
|
||||||
|
try:
|
||||||
|
rpc.get_logger().error(f"Request ERROR: {exc}")
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
ctx.append(record)
|
||||||
|
return None
|
||||||
|
|
||||||
|
record.http_status = response.status_code
|
||||||
|
record.response_body, parse_error = _decode_response_body(response)
|
||||||
|
try:
|
||||||
|
rpc.get_logger().debug(
|
||||||
|
f"Request >>> : {response.request.body} "
|
||||||
|
f"{response.status_code} {response.text}"
|
||||||
|
)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if response.status_code == 200:
|
||||||
|
if parse_error is not None:
|
||||||
|
record.error = f"json parse error: {parse_error}"
|
||||||
|
return_value = None
|
||||||
|
else:
|
||||||
|
return_value = record.response_body
|
||||||
|
else:
|
||||||
|
record.error = f"HTTP {response.status_code}: {response.text}"
|
||||||
|
try:
|
||||||
|
rpc.get_logger().error(
|
||||||
|
f"Request ERROR: ('Request ERROR:', {response.text!r})"
|
||||||
|
)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
return_value = None
|
||||||
|
|
||||||
|
ctx.append(record)
|
||||||
|
return return_value
|
||||||
|
|
||||||
|
def _wrapped_get(
|
||||||
|
url: str,
|
||||||
|
params: Any = None,
|
||||||
|
headers: Optional[dict] = None,
|
||||||
|
) -> Any:
|
||||||
|
ctx = _active_session.get()
|
||||||
|
if ctx is None:
|
||||||
|
kwargs = {}
|
||||||
|
if params is not None:
|
||||||
|
kwargs["params"] = params
|
||||||
|
if headers is not None:
|
||||||
|
kwargs["headers"] = headers
|
||||||
|
return rpc._orig_get(url, **kwargs)
|
||||||
|
effective_params = params if params is not None else {}
|
||||||
|
effective_headers = (
|
||||||
|
headers
|
||||||
|
if headers is not None
|
||||||
|
else {"Content-Type": "application/json"}
|
||||||
|
)
|
||||||
|
source = _detect_source(rpc)
|
||||||
|
request_body = _redact(effective_params)
|
||||||
|
record = CallRecord(
|
||||||
|
index=0,
|
||||||
|
method="GET",
|
||||||
|
url=str(url),
|
||||||
|
path=_url_path(url),
|
||||||
|
source=source,
|
||||||
|
transport="params",
|
||||||
|
http_status=None,
|
||||||
|
request_body=request_body,
|
||||||
|
response_body=None,
|
||||||
|
error=None,
|
||||||
|
)
|
||||||
|
return_value: Any = None
|
||||||
|
try:
|
||||||
|
response = requests.get(
|
||||||
|
url,
|
||||||
|
params=effective_params,
|
||||||
|
headers=effective_headers,
|
||||||
|
timeout=_DEFAULT_TIMEOUT_GET,
|
||||||
|
)
|
||||||
|
except Exception as exc: # pragma: no cover - delegated to logger
|
||||||
|
record.error = f"transport error: {exc}"
|
||||||
|
try:
|
||||||
|
rpc.get_logger().error(f"Request ERROR: {exc}")
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
ctx.append(record)
|
||||||
|
return None
|
||||||
|
|
||||||
|
record.http_status = response.status_code
|
||||||
|
record.response_body, parse_error = _decode_response_body(response)
|
||||||
|
try:
|
||||||
|
rpc.get_logger().debug(
|
||||||
|
f"Request >>> : {effective_params} "
|
||||||
|
f"{response.status_code} {response.text}"
|
||||||
|
)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if response.status_code == 200:
|
||||||
|
if parse_error is not None:
|
||||||
|
record.error = f"json parse error: {parse_error}"
|
||||||
|
return_value = None
|
||||||
|
else:
|
||||||
|
return_value = record.response_body
|
||||||
|
|
||||||
|
ctx.append(record)
|
||||||
|
return return_value
|
||||||
|
|
||||||
|
rpc.post = _wrapped_post
|
||||||
|
rpc.get = _wrapped_get
|
||||||
|
rpc._debug_call_log_wrapped = True
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Helpers
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
_URL_PATH_RE = re.compile(r"https?://[^/]+(/.*)?$")
|
||||||
|
_SLUG_RE = re.compile(r"[^A-Za-z0-9._-]+")
|
||||||
|
|
||||||
|
|
||||||
|
def _slugify_action(action: str) -> str:
|
||||||
|
slug = _SLUG_RE.sub("_", str(action)).strip("_")
|
||||||
|
return slug or "action"
|
||||||
|
|
||||||
|
|
||||||
|
def _url_path(url: Any) -> str:
|
||||||
|
text = str(url or "")
|
||||||
|
match = _URL_PATH_RE.match(text)
|
||||||
|
if match and match.group(1):
|
||||||
|
return match.group(1)
|
||||||
|
if text.startswith("/"):
|
||||||
|
return text
|
||||||
|
return text
|
||||||
|
|
||||||
|
|
||||||
|
def _pick_transport(params: Any) -> str:
|
||||||
|
if isinstance(params, dict) and "data" in params:
|
||||||
|
return "data"
|
||||||
|
return "params"
|
||||||
|
|
||||||
|
|
||||||
|
def _detect_source(rpc: Any) -> str:
|
||||||
|
"""Walk the call stack to find the outermost frame whose ``self`` is rpc."""
|
||||||
|
try:
|
||||||
|
stack = inspect.stack()
|
||||||
|
except Exception:
|
||||||
|
return ""
|
||||||
|
candidate = ""
|
||||||
|
try:
|
||||||
|
for frame_info in stack:
|
||||||
|
frame = frame_info.frame
|
||||||
|
if frame.f_locals.get("self", None) is rpc:
|
||||||
|
candidate = frame_info.function
|
||||||
|
return candidate
|
||||||
|
finally:
|
||||||
|
del stack
|
||||||
|
|
||||||
|
|
||||||
|
def _redact(params: Any) -> Any:
|
||||||
|
"""Return a copy of ``params`` with ``apiKey`` redacted."""
|
||||||
|
try:
|
||||||
|
cloned = copy.deepcopy(params)
|
||||||
|
except Exception:
|
||||||
|
return params
|
||||||
|
_redact_in_place(cloned)
|
||||||
|
return cloned
|
||||||
|
|
||||||
|
|
||||||
|
def _redact_in_place(value: Any) -> None:
|
||||||
|
if isinstance(value, dict):
|
||||||
|
for key in list(value.keys()):
|
||||||
|
if isinstance(key, str) and key.lower() == "apikey":
|
||||||
|
value[key] = "<redacted>"
|
||||||
|
else:
|
||||||
|
_redact_in_place(value[key])
|
||||||
|
elif isinstance(value, list):
|
||||||
|
for item in value:
|
||||||
|
_redact_in_place(item)
|
||||||
|
|
||||||
|
|
||||||
|
def _decode_response_body(response: Any) -> tuple[Any, Optional[str]]:
|
||||||
|
"""Best-effort response decoding used for both record + return value."""
|
||||||
|
text = getattr(response, "text", "")
|
||||||
|
try:
|
||||||
|
return response.json(), None
|
||||||
|
except Exception as exc:
|
||||||
|
if text:
|
||||||
|
return {"raw_text": text}, str(exc)
|
||||||
|
return None, str(exc)
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Markdown rendering
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
def _render_markdown(ctx: CallLogContext) -> str:
|
||||||
|
title = f"# {ctx.action} Raw Call/Response Log"
|
||||||
|
parts: List[str] = [title, ""]
|
||||||
|
parts.append("## LIMS Calls")
|
||||||
|
parts.append("")
|
||||||
|
parts.append("| # | Method | Path | Source | HTTP |")
|
||||||
|
parts.append("|---|---|---|---|---|")
|
||||||
|
for record in ctx.calls:
|
||||||
|
anchor = _row_anchor(record)
|
||||||
|
http = (
|
||||||
|
f"`{record.http_status}`"
|
||||||
|
if record.http_status is not None
|
||||||
|
else "`-`"
|
||||||
|
)
|
||||||
|
parts.append(
|
||||||
|
f"| [{record.index}](#{anchor}) | `{record.method}` | "
|
||||||
|
f"`{record.path}` | `{record.source}` | {http} |"
|
||||||
|
)
|
||||||
|
parts.append("")
|
||||||
|
|
||||||
|
for record in ctx.calls:
|
||||||
|
parts.append(f"## {record.index} {record.method} {record.path}")
|
||||||
|
parts.append("")
|
||||||
|
parts.append(f"- Source: `{record.source}`")
|
||||||
|
parts.append(f"- Transport: `{record.transport}`")
|
||||||
|
if record.http_status is not None:
|
||||||
|
parts.append(f"- HTTP status: `{record.http_status}`")
|
||||||
|
else:
|
||||||
|
parts.append("- HTTP status: `-`")
|
||||||
|
if record.error:
|
||||||
|
parts.append(f"- Error: {record.error}")
|
||||||
|
parts.append("")
|
||||||
|
parts.append("### Request Body")
|
||||||
|
parts.append("")
|
||||||
|
parts.append("```json")
|
||||||
|
parts.append(_to_json_block(record.request_body))
|
||||||
|
parts.append("```")
|
||||||
|
parts.append("")
|
||||||
|
parts.append("### Response Body")
|
||||||
|
parts.append("")
|
||||||
|
parts.append("```json")
|
||||||
|
parts.append(_to_json_block(record.response_body))
|
||||||
|
parts.append("```")
|
||||||
|
parts.append("")
|
||||||
|
|
||||||
|
return "\n".join(parts).rstrip() + "\n"
|
||||||
|
|
||||||
|
|
||||||
|
def _row_anchor(record: CallRecord) -> str:
|
||||||
|
"""Build a GitHub-style anchor matching ``## N METHOD /path``."""
|
||||||
|
raw = f"{record.index}-{record.method}-{record.path}"
|
||||||
|
raw = raw.lower()
|
||||||
|
raw = re.sub(r"[^a-z0-9]+", "-", raw)
|
||||||
|
return raw.strip("-")
|
||||||
|
|
||||||
|
|
||||||
|
def _to_json_block(value: Any) -> str:
|
||||||
|
try:
|
||||||
|
return json.dumps(value, ensure_ascii=False, indent=2, sort_keys=True)
|
||||||
|
except TypeError:
|
||||||
|
return json.dumps(str(value), ensure_ascii=False, indent=2)
|
||||||
@@ -4,7 +4,8 @@ import time
|
|||||||
from typing import Optional, Dict, Any, List
|
from typing import Optional, Dict, Any, List
|
||||||
from typing_extensions import TypedDict
|
from typing_extensions import TypedDict
|
||||||
import requests
|
import requests
|
||||||
from unilabos.devices.workstation.bioyond_studio.config import API_CONFIG
|
import pint
|
||||||
|
|
||||||
|
|
||||||
from unilabos.devices.workstation.bioyond_studio.bioyond_rpc import BioyondException
|
from unilabos.devices.workstation.bioyond_studio.bioyond_rpc import BioyondException
|
||||||
from unilabos.devices.workstation.bioyond_studio.station import BioyondWorkstation
|
from unilabos.devices.workstation.bioyond_studio.station import BioyondWorkstation
|
||||||
@@ -25,13 +26,89 @@ class ComputeExperimentDesignReturn(TypedDict):
|
|||||||
class BioyondDispensingStation(BioyondWorkstation):
|
class BioyondDispensingStation(BioyondWorkstation):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
config,
|
config: dict = None,
|
||||||
# 桌子
|
deck=None,
|
||||||
deck,
|
protocol_type=None,
|
||||||
*args,
|
|
||||||
**kwargs,
|
**kwargs,
|
||||||
):
|
):
|
||||||
super().__init__(config, deck, *args, **kwargs)
|
"""初始化配液站
|
||||||
|
|
||||||
|
Args:
|
||||||
|
config: 配置字典,应包含material_type_mappings等配置
|
||||||
|
deck: Deck对象
|
||||||
|
protocol_type: 协议类型(由ROS系统传递,此处忽略)
|
||||||
|
**kwargs: 其他可能的参数
|
||||||
|
"""
|
||||||
|
if config is None:
|
||||||
|
config = {}
|
||||||
|
|
||||||
|
# 将 kwargs 合并到 config 中 (处理扁平化配置如 api_key)
|
||||||
|
config.update(kwargs)
|
||||||
|
|
||||||
|
if deck is None and config:
|
||||||
|
deck = config.get('deck')
|
||||||
|
|
||||||
|
# 🔧 修复: 确保 Deck 上的 warehouses 具有正确的 UUID (必须在 super().__init__ 之前执行,因为父类会触发同步)
|
||||||
|
# 从配置中读取 warehouse_mapping,并应用到实际的 deck 资源上
|
||||||
|
if config and "warehouse_mapping" in config and deck:
|
||||||
|
warehouse_mapping = config["warehouse_mapping"]
|
||||||
|
print(f"正在根据配置更新 Deck warehouse UUIDs... (共有 {len(warehouse_mapping)} 个配置)")
|
||||||
|
|
||||||
|
user_deck = deck
|
||||||
|
# 初始化 warehouses 字典
|
||||||
|
if not hasattr(user_deck, "warehouses") or user_deck.warehouses is None:
|
||||||
|
user_deck.warehouses = {}
|
||||||
|
|
||||||
|
# 1. 尝试从 children 中查找匹配的资源
|
||||||
|
for child in user_deck.children:
|
||||||
|
# 简单判断: 如果名字在 mapping 中,就认为是 warehouse
|
||||||
|
if child.name in warehouse_mapping:
|
||||||
|
user_deck.warehouses[child.name] = child
|
||||||
|
print(f" - 从子资源中找到 warehouse: {child.name}")
|
||||||
|
|
||||||
|
# 2. 如果还是没找到,且 Deck 类有 setup 方法,尝试调用 setup (针对 Deck 对象正确但未初始化的情况)
|
||||||
|
if not user_deck.warehouses and hasattr(user_deck, "setup"):
|
||||||
|
print(" - 尝试调用 deck.setup() 初始化仓库...")
|
||||||
|
try:
|
||||||
|
user_deck.setup()
|
||||||
|
# setup 后重新检查
|
||||||
|
if hasattr(user_deck, "warehouses") and user_deck.warehouses:
|
||||||
|
print(f" - setup() 成功,找到 {len(user_deck.warehouses)} 个仓库")
|
||||||
|
except Exception as e:
|
||||||
|
print(f" - 调用 setup() 失败: {e}")
|
||||||
|
|
||||||
|
# 3. 如果仍然为空,可能需要手动创建 (仅针对特定已知的 Deck 类型进行补救,这里暂时只打印警告)
|
||||||
|
if not user_deck.warehouses:
|
||||||
|
print(" - ⚠️ 仍然无法找到任何 warehouse 资源!")
|
||||||
|
|
||||||
|
for wh_name, wh_config in warehouse_mapping.items():
|
||||||
|
target_uuid = wh_config.get("uuid")
|
||||||
|
|
||||||
|
# 尝试在 deck.warehouses 中查找
|
||||||
|
wh_resource = None
|
||||||
|
if hasattr(user_deck, "warehouses") and wh_name in user_deck.warehouses:
|
||||||
|
wh_resource = user_deck.warehouses[wh_name]
|
||||||
|
|
||||||
|
# 如果没找到,尝试在所有子资源中查找
|
||||||
|
if not wh_resource:
|
||||||
|
wh_resource = user_deck.get_resource(wh_name)
|
||||||
|
|
||||||
|
if wh_resource:
|
||||||
|
if target_uuid:
|
||||||
|
current_uuid = getattr(wh_resource, "uuid", None)
|
||||||
|
print(f"✅ 更新仓库 '{wh_name}' UUID: {current_uuid} -> {target_uuid}")
|
||||||
|
|
||||||
|
# 动态添加 uuid 属性
|
||||||
|
wh_resource.uuid = target_uuid
|
||||||
|
# 同时也确保 category 正确,避免 graphio 识别错误
|
||||||
|
# wh_resource.category = "warehouse"
|
||||||
|
else:
|
||||||
|
print(f"⚠️ 仓库 '{wh_name}' 在配置中没有 UUID")
|
||||||
|
else:
|
||||||
|
print(f"❌ 在 Deck 中未找到配置的仓库: '{wh_name}'")
|
||||||
|
|
||||||
|
super().__init__(bioyond_config=config, deck=deck)
|
||||||
|
|
||||||
# self.config = config
|
# self.config = config
|
||||||
# self.api_key = config["api_key"]
|
# self.api_key = config["api_key"]
|
||||||
# self.host = config["api_host"]
|
# self.host = config["api_host"]
|
||||||
@@ -43,6 +120,41 @@ class BioyondDispensingStation(BioyondWorkstation):
|
|||||||
# 用于跟踪任务完成状态的字典: {orderCode: {status, order_id, timestamp}}
|
# 用于跟踪任务完成状态的字典: {orderCode: {status, order_id, timestamp}}
|
||||||
self.order_completion_status = {}
|
self.order_completion_status = {}
|
||||||
|
|
||||||
|
# 初始化 pint 单位注册表
|
||||||
|
self.ureg = pint.UnitRegistry()
|
||||||
|
|
||||||
|
# 化合物信息
|
||||||
|
self.compound_info = {
|
||||||
|
"MolWt": {
|
||||||
|
"MDA": 108.14 * self.ureg.g / self.ureg.mol,
|
||||||
|
"TDA": 122.16 * self.ureg.g / self.ureg.mol,
|
||||||
|
"PAPP": 521.62 * self.ureg.g / self.ureg.mol,
|
||||||
|
"BTDA": 322.23 * self.ureg.g / self.ureg.mol,
|
||||||
|
"BPDA": 294.22 * self.ureg.g / self.ureg.mol,
|
||||||
|
"6FAP": 366.26 * self.ureg.g / self.ureg.mol,
|
||||||
|
"PMDA": 218.12 * self.ureg.g / self.ureg.mol,
|
||||||
|
"MPDA": 108.14 * self.ureg.g / self.ureg.mol,
|
||||||
|
"SIDA": 248.51 * self.ureg.g / self.ureg.mol,
|
||||||
|
"ODA": 200.236 * self.ureg.g / self.ureg.mol,
|
||||||
|
"4,4'-ODA": 200.236 * self.ureg.g / self.ureg.mol,
|
||||||
|
"134": 292.34 * self.ureg.g / self.ureg.mol,
|
||||||
|
},
|
||||||
|
"FuncGroup": {
|
||||||
|
"MDA": "Amine",
|
||||||
|
"TDA": "Amine",
|
||||||
|
"PAPP": "Amine",
|
||||||
|
"BTDA": "Anhydride",
|
||||||
|
"BPDA": "Anhydride",
|
||||||
|
"6FAP": "Amine",
|
||||||
|
"MPDA": "Amine",
|
||||||
|
"SIDA": "Amine",
|
||||||
|
"PMDA": "Anhydride",
|
||||||
|
"ODA": "Amine",
|
||||||
|
"4,4'-ODA": "Amine",
|
||||||
|
"134": "Amine",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
def _post_project_api(self, endpoint: str, data: Any) -> Dict[str, Any]:
|
def _post_project_api(self, endpoint: str, data: Any) -> Dict[str, Any]:
|
||||||
"""项目接口通用POST调用
|
"""项目接口通用POST调用
|
||||||
|
|
||||||
@@ -54,7 +166,7 @@ class BioyondDispensingStation(BioyondWorkstation):
|
|||||||
dict: 服务端响应,失败时返回 {code:0,message,...}
|
dict: 服务端响应,失败时返回 {code:0,message,...}
|
||||||
"""
|
"""
|
||||||
request_data = {
|
request_data = {
|
||||||
"apiKey": API_CONFIG["api_key"],
|
"apiKey": self.bioyond_config["api_key"],
|
||||||
"requestTime": self.hardware_interface.get_current_time_iso8601(),
|
"requestTime": self.hardware_interface.get_current_time_iso8601(),
|
||||||
"data": data
|
"data": data
|
||||||
}
|
}
|
||||||
@@ -85,7 +197,7 @@ class BioyondDispensingStation(BioyondWorkstation):
|
|||||||
dict: 服务端响应,失败时返回 {code:0,message,...}
|
dict: 服务端响应,失败时返回 {code:0,message,...}
|
||||||
"""
|
"""
|
||||||
request_data = {
|
request_data = {
|
||||||
"apiKey": API_CONFIG["api_key"],
|
"apiKey": self.bioyond_config["api_key"],
|
||||||
"requestTime": self.hardware_interface.get_current_time_iso8601(),
|
"requestTime": self.hardware_interface.get_current_time_iso8601(),
|
||||||
"data": data
|
"data": data
|
||||||
}
|
}
|
||||||
@@ -118,20 +230,22 @@ class BioyondDispensingStation(BioyondWorkstation):
|
|||||||
ratio = json.loads(ratio)
|
ratio = json.loads(ratio)
|
||||||
except Exception:
|
except Exception:
|
||||||
ratio = {}
|
ratio = {}
|
||||||
root = str(Path(__file__).resolve().parents[3])
|
|
||||||
if root not in sys.path:
|
|
||||||
sys.path.append(root)
|
|
||||||
try:
|
|
||||||
mod = importlib.import_module("tem.compute")
|
|
||||||
except Exception as e:
|
|
||||||
raise BioyondException(f"无法导入计算模块: {e}")
|
|
||||||
try:
|
try:
|
||||||
wp = float(wt_percent) if isinstance(wt_percent, str) else wt_percent
|
wp = float(wt_percent) if isinstance(wt_percent, str) else wt_percent
|
||||||
mt = float(m_tot) if isinstance(m_tot, str) else m_tot
|
mt = float(m_tot) if isinstance(m_tot, str) else m_tot
|
||||||
tp = float(titration_percent) if isinstance(titration_percent, str) else titration_percent
|
tp = float(titration_percent) if isinstance(titration_percent, str) else titration_percent
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise BioyondException(f"参数解析失败: {e}")
|
raise BioyondException(f"参数解析失败: {e}")
|
||||||
res = mod.generate_experiment_design(ratio=ratio, wt_percent=wp, m_tot=mt, titration_percent=tp)
|
|
||||||
|
# 2. 调用内部计算方法
|
||||||
|
res = self._generate_experiment_design(
|
||||||
|
ratio=ratio,
|
||||||
|
wt_percent=wp,
|
||||||
|
m_tot=mt,
|
||||||
|
titration_percent=tp
|
||||||
|
)
|
||||||
|
|
||||||
|
# 3. 构造返回结果
|
||||||
out = {
|
out = {
|
||||||
"solutions": res.get("solutions", []),
|
"solutions": res.get("solutions", []),
|
||||||
"titration": res.get("titration", {}),
|
"titration": res.get("titration", {}),
|
||||||
@@ -140,11 +254,248 @@ class BioyondDispensingStation(BioyondWorkstation):
|
|||||||
"return_info": json.dumps(res, ensure_ascii=False)
|
"return_info": json.dumps(res, ensure_ascii=False)
|
||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
|
|
||||||
except BioyondException:
|
except BioyondException:
|
||||||
raise
|
raise
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise BioyondException(str(e))
|
raise BioyondException(str(e))
|
||||||
|
|
||||||
|
def _generate_experiment_design(
|
||||||
|
self,
|
||||||
|
ratio: dict,
|
||||||
|
wt_percent: float = 0.25,
|
||||||
|
m_tot: float = 70,
|
||||||
|
titration_percent: float = 0.03,
|
||||||
|
) -> dict:
|
||||||
|
"""内部方法:生成实验设计
|
||||||
|
|
||||||
|
根据FuncGroup自动区分二胺和二酐,每种二胺单独配溶液,严格按照ratio顺序投料。
|
||||||
|
|
||||||
|
参数:
|
||||||
|
ratio: 化合物配比字典,格式: {"compound_name": ratio_value}
|
||||||
|
wt_percent: 固体重量百分比
|
||||||
|
m_tot: 反应混合物总质量(g)
|
||||||
|
titration_percent: 滴定溶液百分比
|
||||||
|
|
||||||
|
返回:
|
||||||
|
包含实验设计详细参数的字典
|
||||||
|
"""
|
||||||
|
# 溶剂密度
|
||||||
|
ρ_solvent = 1.03 * self.ureg.g / self.ureg.ml
|
||||||
|
# 二酐溶解度
|
||||||
|
solubility = 0.02 * self.ureg.g / self.ureg.ml
|
||||||
|
# 投入固体时最小溶剂体积
|
||||||
|
V_min = 30 * self.ureg.ml
|
||||||
|
m_tot = m_tot * self.ureg.g
|
||||||
|
|
||||||
|
# 保持ratio中的顺序
|
||||||
|
compound_names = list(ratio.keys())
|
||||||
|
compound_ratios = list(ratio.values())
|
||||||
|
|
||||||
|
# 验证所有化合物是否在 compound_info 中定义
|
||||||
|
undefined_compounds = [name for name in compound_names if name not in self.compound_info["MolWt"]]
|
||||||
|
if undefined_compounds:
|
||||||
|
available = list(self.compound_info["MolWt"].keys())
|
||||||
|
raise ValueError(
|
||||||
|
f"以下化合物未在 compound_info 中定义: {undefined_compounds}。"
|
||||||
|
f"可用的化合物: {available}"
|
||||||
|
)
|
||||||
|
|
||||||
|
# 获取各化合物的分子量和官能团类型
|
||||||
|
molecular_weights = [self.compound_info["MolWt"][name] for name in compound_names]
|
||||||
|
func_groups = [self.compound_info["FuncGroup"][name] for name in compound_names]
|
||||||
|
|
||||||
|
# 记录化合物信息用于调试
|
||||||
|
self.hardware_interface._logger.info(f"化合物名称: {compound_names}")
|
||||||
|
self.hardware_interface._logger.info(f"官能团类型: {func_groups}")
|
||||||
|
|
||||||
|
# 按原始顺序分离二胺和二酐
|
||||||
|
ordered_compounds = list(zip(compound_names, compound_ratios, molecular_weights, func_groups))
|
||||||
|
diamine_compounds = [(name, ratio_val, mw, i) for i, (name, ratio_val, mw, fg) in enumerate(ordered_compounds) if fg == "Amine"]
|
||||||
|
anhydride_compounds = [(name, ratio_val, mw, i) for i, (name, ratio_val, mw, fg) in enumerate(ordered_compounds) if fg == "Anhydride"]
|
||||||
|
|
||||||
|
if not diamine_compounds or not anhydride_compounds:
|
||||||
|
raise ValueError(
|
||||||
|
f"需要同时包含二胺(Amine)和二酐(Anhydride)化合物。"
|
||||||
|
f"当前二胺: {[c[0] for c in diamine_compounds]}, "
|
||||||
|
f"当前二酐: {[c[0] for c in anhydride_compounds]}"
|
||||||
|
)
|
||||||
|
|
||||||
|
# 计算加权平均分子量 (基于摩尔比)
|
||||||
|
total_molar_ratio = sum(compound_ratios)
|
||||||
|
weighted_molecular_weight = sum(ratio_val * mw for ratio_val, mw in zip(compound_ratios, molecular_weights))
|
||||||
|
|
||||||
|
# 取最后一个二酐用于滴定
|
||||||
|
titration_anhydride = anhydride_compounds[-1]
|
||||||
|
solid_anhydrides = anhydride_compounds[:-1] if len(anhydride_compounds) > 1 else []
|
||||||
|
|
||||||
|
# 二胺溶液配制参数 - 每种二胺单独配制
|
||||||
|
diamine_solutions = []
|
||||||
|
total_diamine_volume = 0 * self.ureg.ml
|
||||||
|
|
||||||
|
# 计算反应物的总摩尔量
|
||||||
|
n_reactant = m_tot * wt_percent / weighted_molecular_weight
|
||||||
|
|
||||||
|
for name, ratio_val, mw, order_index in diamine_compounds:
|
||||||
|
# 跳过 SIDA
|
||||||
|
if name == "SIDA":
|
||||||
|
continue
|
||||||
|
|
||||||
|
# 计算该二胺需要的摩尔数
|
||||||
|
n_diamine_needed = n_reactant * ratio_val
|
||||||
|
|
||||||
|
# 二胺溶液配制参数 (每种二胺固定配制参数)
|
||||||
|
m_diamine_solid = 5.0 * self.ureg.g # 每种二胺固体质量
|
||||||
|
V_solvent_for_this = 20 * self.ureg.ml # 每种二胺溶剂体积
|
||||||
|
m_solvent_for_this = ρ_solvent * V_solvent_for_this
|
||||||
|
|
||||||
|
# 计算该二胺溶液的浓度
|
||||||
|
c_diamine = (m_diamine_solid / mw) / V_solvent_for_this
|
||||||
|
|
||||||
|
# 计算需要移取的溶液体积
|
||||||
|
V_diamine_needed = n_diamine_needed / c_diamine
|
||||||
|
|
||||||
|
diamine_solutions.append({
|
||||||
|
"name": name,
|
||||||
|
"order": order_index,
|
||||||
|
"solid_mass": m_diamine_solid.magnitude,
|
||||||
|
"solvent_volume": V_solvent_for_this.magnitude,
|
||||||
|
"concentration": c_diamine.magnitude,
|
||||||
|
"volume_needed": V_diamine_needed.magnitude,
|
||||||
|
"molar_ratio": ratio_val
|
||||||
|
})
|
||||||
|
|
||||||
|
total_diamine_volume += V_diamine_needed
|
||||||
|
|
||||||
|
# 按原始顺序排序
|
||||||
|
diamine_solutions.sort(key=lambda x: x["order"])
|
||||||
|
|
||||||
|
# 计算滴定二酐的质量
|
||||||
|
titration_name, titration_ratio, titration_mw, _ = titration_anhydride
|
||||||
|
m_titration_anhydride = n_reactant * titration_ratio * titration_mw
|
||||||
|
m_titration_90 = m_titration_anhydride * (1 - titration_percent)
|
||||||
|
m_titration_10 = m_titration_anhydride * titration_percent
|
||||||
|
|
||||||
|
# 计算其他固体二酐的质量 (按顺序)
|
||||||
|
solid_anhydride_masses = []
|
||||||
|
for name, ratio_val, mw, order_index in solid_anhydrides:
|
||||||
|
mass = n_reactant * ratio_val * mw
|
||||||
|
solid_anhydride_masses.append({
|
||||||
|
"name": name,
|
||||||
|
"order": order_index,
|
||||||
|
"mass": mass.magnitude,
|
||||||
|
"molar_ratio": ratio_val
|
||||||
|
})
|
||||||
|
|
||||||
|
# 按原始顺序排序
|
||||||
|
solid_anhydride_masses.sort(key=lambda x: x["order"])
|
||||||
|
|
||||||
|
# 计算溶剂用量
|
||||||
|
total_diamine_solution_mass = sum(
|
||||||
|
sol["volume_needed"] * ρ_solvent for sol in diamine_solutions
|
||||||
|
) * self.ureg.ml
|
||||||
|
|
||||||
|
# 预估滴定溶剂量、计算补加溶剂量
|
||||||
|
m_solvent_titration = m_titration_10 / solubility * ρ_solvent
|
||||||
|
m_solvent_add = m_tot * (1 - wt_percent) - total_diamine_solution_mass - m_solvent_titration
|
||||||
|
|
||||||
|
# 检查最小溶剂体积要求
|
||||||
|
total_liquid_volume = (total_diamine_solution_mass + m_solvent_add) / ρ_solvent
|
||||||
|
m_tot_min = V_min / total_liquid_volume * m_tot
|
||||||
|
|
||||||
|
# 如果需要,按比例放大
|
||||||
|
scale_factor = 1.0
|
||||||
|
if m_tot_min > m_tot:
|
||||||
|
scale_factor = (m_tot_min / m_tot).magnitude
|
||||||
|
m_titration_90 *= scale_factor
|
||||||
|
m_titration_10 *= scale_factor
|
||||||
|
m_solvent_add *= scale_factor
|
||||||
|
m_solvent_titration *= scale_factor
|
||||||
|
|
||||||
|
# 更新二胺溶液用量
|
||||||
|
for sol in diamine_solutions:
|
||||||
|
sol["volume_needed"] *= scale_factor
|
||||||
|
|
||||||
|
# 更新固体二酐用量
|
||||||
|
for anhydride in solid_anhydride_masses:
|
||||||
|
anhydride["mass"] *= scale_factor
|
||||||
|
|
||||||
|
m_tot = m_tot_min
|
||||||
|
|
||||||
|
# 生成投料顺序
|
||||||
|
feeding_order = []
|
||||||
|
|
||||||
|
# 1. 固体二酐 (按顺序)
|
||||||
|
for anhydride in solid_anhydride_masses:
|
||||||
|
feeding_order.append({
|
||||||
|
"step": len(feeding_order) + 1,
|
||||||
|
"type": "solid_anhydride",
|
||||||
|
"name": anhydride["name"],
|
||||||
|
"amount": anhydride["mass"],
|
||||||
|
"order": anhydride["order"]
|
||||||
|
})
|
||||||
|
|
||||||
|
# 2. 二胺溶液 (按顺序)
|
||||||
|
for sol in diamine_solutions:
|
||||||
|
feeding_order.append({
|
||||||
|
"step": len(feeding_order) + 1,
|
||||||
|
"type": "diamine_solution",
|
||||||
|
"name": sol["name"],
|
||||||
|
"amount": sol["volume_needed"],
|
||||||
|
"order": sol["order"]
|
||||||
|
})
|
||||||
|
|
||||||
|
# 3. 主要二酐粉末
|
||||||
|
feeding_order.append({
|
||||||
|
"step": len(feeding_order) + 1,
|
||||||
|
"type": "main_anhydride",
|
||||||
|
"name": titration_name,
|
||||||
|
"amount": m_titration_90.magnitude,
|
||||||
|
"order": titration_anhydride[3]
|
||||||
|
})
|
||||||
|
|
||||||
|
# 4. 补加溶剂
|
||||||
|
if m_solvent_add > 0:
|
||||||
|
feeding_order.append({
|
||||||
|
"step": len(feeding_order) + 1,
|
||||||
|
"type": "additional_solvent",
|
||||||
|
"name": "溶剂",
|
||||||
|
"amount": m_solvent_add.magnitude,
|
||||||
|
"order": 999
|
||||||
|
})
|
||||||
|
|
||||||
|
# 5. 滴定二酐溶液
|
||||||
|
feeding_order.append({
|
||||||
|
"step": len(feeding_order) + 1,
|
||||||
|
"type": "titration_anhydride",
|
||||||
|
"name": f"{titration_name} 滴定液",
|
||||||
|
"amount": m_titration_10.magnitude,
|
||||||
|
"titration_solvent": m_solvent_titration.magnitude,
|
||||||
|
"order": titration_anhydride[3]
|
||||||
|
})
|
||||||
|
|
||||||
|
# 返回实验设计结果
|
||||||
|
results = {
|
||||||
|
"total_mass": m_tot.magnitude,
|
||||||
|
"scale_factor": scale_factor,
|
||||||
|
"solutions": diamine_solutions,
|
||||||
|
"solids": solid_anhydride_masses,
|
||||||
|
"titration": {
|
||||||
|
"name": titration_name,
|
||||||
|
"main_portion": m_titration_90.magnitude,
|
||||||
|
"titration_portion": m_titration_10.magnitude,
|
||||||
|
"titration_solvent": m_solvent_titration.magnitude,
|
||||||
|
},
|
||||||
|
"solvents": {
|
||||||
|
"additional_solvent": m_solvent_add.magnitude,
|
||||||
|
"total_liquid_volume": total_liquid_volume.magnitude
|
||||||
|
},
|
||||||
|
"feeding_order": feeding_order,
|
||||||
|
"minimum_required_mass": m_tot_min.magnitude
|
||||||
|
}
|
||||||
|
|
||||||
|
return results
|
||||||
|
|
||||||
# 90%10%小瓶投料任务创建方法
|
# 90%10%小瓶投料任务创建方法
|
||||||
def create_90_10_vial_feeding_task(self,
|
def create_90_10_vial_feeding_task(self,
|
||||||
order_name: str = None,
|
order_name: str = None,
|
||||||
@@ -961,6 +1312,108 @@ class BioyondDispensingStation(BioyondWorkstation):
|
|||||||
'actualVolume': actual_volume
|
'actualVolume': actual_volume
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def _simplify_report(self, report) -> Dict[str, Any]:
|
||||||
|
"""简化实验报告,只保留关键信息,去除冗余的工作流参数"""
|
||||||
|
if not isinstance(report, dict):
|
||||||
|
return report
|
||||||
|
|
||||||
|
data = report.get('data', {})
|
||||||
|
if not isinstance(data, dict):
|
||||||
|
return report
|
||||||
|
|
||||||
|
# 提取关键信息
|
||||||
|
simplified = {
|
||||||
|
'name': data.get('name'),
|
||||||
|
'code': data.get('code'),
|
||||||
|
'requester': data.get('requester'),
|
||||||
|
'workflowName': data.get('workflowName'),
|
||||||
|
'workflowStep': data.get('workflowStep'),
|
||||||
|
'requestTime': data.get('requestTime'),
|
||||||
|
'startPreparationTime': data.get('startPreparationTime'),
|
||||||
|
'completeTime': data.get('completeTime'),
|
||||||
|
'useTime': data.get('useTime'),
|
||||||
|
'status': data.get('status'),
|
||||||
|
'statusName': data.get('statusName'),
|
||||||
|
}
|
||||||
|
|
||||||
|
# 提取物料信息(简化版)
|
||||||
|
pre_intakes = data.get('preIntakes', [])
|
||||||
|
if pre_intakes and isinstance(pre_intakes, list):
|
||||||
|
first_intake = pre_intakes[0]
|
||||||
|
sample_materials = first_intake.get('sampleMaterials', [])
|
||||||
|
|
||||||
|
# 简化物料信息
|
||||||
|
simplified_materials = []
|
||||||
|
for material in sample_materials:
|
||||||
|
if isinstance(material, dict):
|
||||||
|
mat_info = {
|
||||||
|
'materialName': material.get('materialName'),
|
||||||
|
'materialTypeName': material.get('materialTypeName'),
|
||||||
|
'materialCode': material.get('materialCode'),
|
||||||
|
'materialLocation': material.get('materialLocation'),
|
||||||
|
}
|
||||||
|
|
||||||
|
# 解析parameters中的关键信息(如密度、加料历史等)
|
||||||
|
params_str = material.get('parameters', '{}')
|
||||||
|
try:
|
||||||
|
params = json.loads(params_str) if isinstance(params_str, str) else params_str
|
||||||
|
if isinstance(params, dict):
|
||||||
|
# 只保留关键参数
|
||||||
|
if 'density' in params:
|
||||||
|
mat_info['density'] = params['density']
|
||||||
|
if 'feedingHistory' in params:
|
||||||
|
mat_info['feedingHistory'] = params['feedingHistory']
|
||||||
|
if 'liquidVolume' in params:
|
||||||
|
mat_info['liquidVolume'] = params['liquidVolume']
|
||||||
|
if 'm_diamine_tot' in params:
|
||||||
|
mat_info['m_diamine_tot'] = params['m_diamine_tot']
|
||||||
|
if 'wt_diamine' in params:
|
||||||
|
mat_info['wt_diamine'] = params['wt_diamine']
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
simplified_materials.append(mat_info)
|
||||||
|
|
||||||
|
simplified['sampleMaterials'] = simplified_materials
|
||||||
|
|
||||||
|
# 提取extraProperties中的实际值
|
||||||
|
extra_props = first_intake.get('extraProperties', {})
|
||||||
|
if isinstance(extra_props, dict):
|
||||||
|
simplified_extra = {}
|
||||||
|
for key, value in extra_props.items():
|
||||||
|
try:
|
||||||
|
parsed_value = json.loads(value) if isinstance(value, str) else value
|
||||||
|
simplified_extra[key] = parsed_value
|
||||||
|
except:
|
||||||
|
simplified_extra[key] = value
|
||||||
|
simplified['extraProperties'] = simplified_extra
|
||||||
|
|
||||||
|
return {
|
||||||
|
'data': simplified,
|
||||||
|
'code': report.get('code'),
|
||||||
|
'message': report.get('message'),
|
||||||
|
'timestamp': report.get('timestamp')
|
||||||
|
}
|
||||||
|
|
||||||
|
def scheduler_start(self) -> dict:
|
||||||
|
"""启动调度器 - 启动Bioyond工作站的任务调度器,开始执行队列中的任务
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
dict: 包含return_info的字典,return_info为整型(1=成功)
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
BioyondException: 调度器启动失败时抛出异常
|
||||||
|
"""
|
||||||
|
result = self.hardware_interface.scheduler_start()
|
||||||
|
self.hardware_interface._logger.info(f"调度器启动结果: {result}")
|
||||||
|
|
||||||
|
if result != 1:
|
||||||
|
error_msg = "启动调度器失败: 有未处理错误,调度无法启动。请检查Bioyond系统状态。"
|
||||||
|
self.hardware_interface._logger.error(error_msg)
|
||||||
|
raise BioyondException(error_msg)
|
||||||
|
|
||||||
|
return {"return_info": result}
|
||||||
|
|
||||||
# 等待多个任务完成并获取实验报告
|
# 等待多个任务完成并获取实验报告
|
||||||
def wait_for_multiple_orders_and_get_reports(self,
|
def wait_for_multiple_orders_and_get_reports(self,
|
||||||
batch_create_result: str = None,
|
batch_create_result: str = None,
|
||||||
@@ -1002,7 +1455,12 @@ class BioyondDispensingStation(BioyondWorkstation):
|
|||||||
|
|
||||||
# 验证batch_create_result参数
|
# 验证batch_create_result参数
|
||||||
if not batch_create_result or batch_create_result == "":
|
if not batch_create_result or batch_create_result == "":
|
||||||
raise BioyondException("batch_create_result参数为空,请确保从batch_create节点正确连接handle")
|
raise BioyondException(
|
||||||
|
"batch_create_result参数为空,请确保:\n"
|
||||||
|
"1. batch_create节点与wait节点之间正确连接了handle\n"
|
||||||
|
"2. batch_create节点成功执行并返回了结果\n"
|
||||||
|
"3. 检查上游batch_create任务是否成功创建了订单"
|
||||||
|
)
|
||||||
|
|
||||||
# 解析batch_create_result JSON对象
|
# 解析batch_create_result JSON对象
|
||||||
try:
|
try:
|
||||||
@@ -1031,7 +1489,17 @@ class BioyondDispensingStation(BioyondWorkstation):
|
|||||||
|
|
||||||
# 验证提取的数据
|
# 验证提取的数据
|
||||||
if not order_codes:
|
if not order_codes:
|
||||||
raise BioyondException("batch_create_result中未找到order_codes字段或为空")
|
self.hardware_interface._logger.error(
|
||||||
|
f"batch_create任务未生成任何订单。batch_create_result内容: {batch_create_result}"
|
||||||
|
)
|
||||||
|
raise BioyondException(
|
||||||
|
"batch_create_result中未找到order_codes或为空。\n"
|
||||||
|
"可能的原因:\n"
|
||||||
|
"1. batch_create任务执行失败(检查任务是否报错)\n"
|
||||||
|
"2. 物料配置问题(如'物料样品板分配失败')\n"
|
||||||
|
"3. Bioyond系统状态异常\n"
|
||||||
|
f"请检查batch_create任务的执行结果"
|
||||||
|
)
|
||||||
if not order_ids:
|
if not order_ids:
|
||||||
raise BioyondException("batch_create_result中未找到order_ids字段或为空")
|
raise BioyondException("batch_create_result中未找到order_ids字段或为空")
|
||||||
|
|
||||||
@@ -1114,6 +1582,8 @@ class BioyondDispensingStation(BioyondWorkstation):
|
|||||||
self.hardware_interface._logger.info(
|
self.hardware_interface._logger.info(
|
||||||
f"成功获取任务 {order_code} 的实验报告"
|
f"成功获取任务 {order_code} 的实验报告"
|
||||||
)
|
)
|
||||||
|
# 简化报告,去除冗余信息
|
||||||
|
report = self._simplify_report(report)
|
||||||
|
|
||||||
reports.append({
|
reports.append({
|
||||||
"order_code": order_code,
|
"order_code": order_code,
|
||||||
@@ -1288,7 +1758,7 @@ class BioyondDispensingStation(BioyondWorkstation):
|
|||||||
f"开始执行批量物料转移: {len(transfer_groups)}组任务 -> {target_device_id}"
|
f"开始执行批量物料转移: {len(transfer_groups)}组任务 -> {target_device_id}"
|
||||||
)
|
)
|
||||||
|
|
||||||
from .config import WAREHOUSE_MAPPING
|
warehouse_mapping = self.bioyond_config.get("warehouse_mapping", {})
|
||||||
results = []
|
results = []
|
||||||
successful_count = 0
|
successful_count = 0
|
||||||
failed_count = 0
|
failed_count = 0
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,3 @@
|
|||||||
|
from .sirna_station import BioyondSirnaStation, fetch_workflow_list, load_sirna_config
|
||||||
|
|
||||||
|
__all__ = ["BioyondSirnaStation", "fetch_workflow_list", "load_sirna_config"]
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -6,6 +6,8 @@ Bioyond Workstation Implementation
|
|||||||
"""
|
"""
|
||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
|
import threading
|
||||||
|
from contextlib import contextmanager
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Dict, Any, List, Optional, Union
|
from typing import Dict, Any, List, Optional, Union
|
||||||
import json
|
import json
|
||||||
@@ -13,6 +15,7 @@ from pathlib import Path
|
|||||||
|
|
||||||
from unilabos.devices.workstation.workstation_base import WorkstationBase, ResourceSynchronizer
|
from unilabos.devices.workstation.workstation_base import WorkstationBase, ResourceSynchronizer
|
||||||
from unilabos.devices.workstation.bioyond_studio.bioyond_rpc import BioyondV1RPC
|
from unilabos.devices.workstation.bioyond_studio.bioyond_rpc import BioyondV1RPC
|
||||||
|
from unilabos.devices.workstation.bioyond_studio import debug_call_log
|
||||||
from unilabos.registry.placeholder_type import ResourceSlot, DeviceSlot
|
from unilabos.registry.placeholder_type import ResourceSlot, DeviceSlot
|
||||||
from unilabos.resources.warehouse import WareHouse
|
from unilabos.resources.warehouse import WareHouse
|
||||||
from unilabos.utils.log import logger
|
from unilabos.utils.log import logger
|
||||||
@@ -23,12 +26,94 @@ from unilabos.ros.nodes.presets.workstation import ROS2WorkstationNode
|
|||||||
from unilabos.ros.msgs.message_converter import convert_to_ros_msg, Float64, String
|
from unilabos.ros.msgs.message_converter import convert_to_ros_msg, Float64, String
|
||||||
from pylabrobot.resources.resource import Resource as ResourcePLR
|
from pylabrobot.resources.resource import Resource as ResourcePLR
|
||||||
|
|
||||||
from unilabos.devices.workstation.bioyond_studio.config import (
|
|
||||||
API_CONFIG, WORKFLOW_MAPPINGS, MATERIAL_TYPE_MAPPINGS, WAREHOUSE_MAPPING, HTTP_SERVICE_CONFIG
|
|
||||||
)
|
|
||||||
from unilabos.devices.workstation.workstation_http_service import WorkstationHTTPService
|
from unilabos.devices.workstation.workstation_http_service import WorkstationHTTPService
|
||||||
|
|
||||||
|
|
||||||
|
class ConnectionMonitor:
|
||||||
|
"""Bioyond连接监控器"""
|
||||||
|
def __init__(self, workstation, check_interval=30):
|
||||||
|
self.workstation = workstation
|
||||||
|
self.check_interval = check_interval
|
||||||
|
self._running = False
|
||||||
|
self._thread = None
|
||||||
|
self._last_status = "unknown"
|
||||||
|
|
||||||
|
def start(self):
|
||||||
|
if self._running:
|
||||||
|
return
|
||||||
|
self._running = True
|
||||||
|
self._thread = threading.Thread(target=self._monitor_loop, daemon=True, name="BioyondConnectionMonitor")
|
||||||
|
self._thread.start()
|
||||||
|
logger.info("Bioyond连接监控器已启动")
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
self._running = False
|
||||||
|
if self._thread:
|
||||||
|
self._thread.join(timeout=2)
|
||||||
|
logger.info("Bioyond连接监控器已停止")
|
||||||
|
|
||||||
|
def _monitor_loop(self):
|
||||||
|
while self._running:
|
||||||
|
try:
|
||||||
|
# 使用 lightweight API 检查连接
|
||||||
|
# query_matial_type_list 是比较快的查询
|
||||||
|
start_time = time.time()
|
||||||
|
result = self.workstation.hardware_interface.material_type_list()
|
||||||
|
|
||||||
|
status = "online" if result else "offline"
|
||||||
|
msg = "Connection established" if status == "online" else "Failed to get material type list"
|
||||||
|
|
||||||
|
if status != self._last_status:
|
||||||
|
logger.info(f"Bioyond连接状态变更: {self._last_status} -> {status}")
|
||||||
|
self._publish_event(status, msg)
|
||||||
|
self._last_status = status
|
||||||
|
|
||||||
|
# 发布心跳 (可选,或者只在状态变更时发布)
|
||||||
|
# self._publish_event(status, msg)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Bioyond连接检查异常: {e}")
|
||||||
|
if self._last_status != "error":
|
||||||
|
self._publish_event("error", str(e))
|
||||||
|
self._last_status = "error"
|
||||||
|
|
||||||
|
time.sleep(self.check_interval)
|
||||||
|
|
||||||
|
def _publish_event(self, status, message):
|
||||||
|
try:
|
||||||
|
if hasattr(self.workstation, "_ros_node") and self.workstation._ros_node:
|
||||||
|
event_data = {
|
||||||
|
"status": status,
|
||||||
|
"message": message,
|
||||||
|
"timestamp": datetime.now().isoformat()
|
||||||
|
}
|
||||||
|
|
||||||
|
# 动态发布消息,需要在 ROS2DeviceNode 中有对应支持
|
||||||
|
# 这里假设通用事件发布机制,使用 String 类型的 topic
|
||||||
|
# 话题: /<namespace>/events/device_status
|
||||||
|
ns = self.workstation._ros_node.namespace
|
||||||
|
topic = f"{ns}/events/device_status"
|
||||||
|
|
||||||
|
# 使用 ROS2DeviceNode 的发布功能
|
||||||
|
# 如果没有预定义的 publisher,需要动态创建
|
||||||
|
# 注意:workstation base node 可能没有自动创建 arbitrary publishers 的机制
|
||||||
|
# 这里我们先尝试用 String json 发布
|
||||||
|
|
||||||
|
# 在 ROS2DeviceNode 中通常需要先 create_publisher
|
||||||
|
# 为了简单起见,我们检查是否已有 publisher,没有则创建
|
||||||
|
if not hasattr(self.workstation, "_device_status_pub"):
|
||||||
|
self.workstation._device_status_pub = self.workstation._ros_node.create_publisher(
|
||||||
|
String, topic, 10
|
||||||
|
)
|
||||||
|
|
||||||
|
self.workstation._device_status_pub.publish(
|
||||||
|
convert_to_ros_msg(String, json.dumps(event_data, ensure_ascii=False))
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"发布设备状态事件失败: {e}")
|
||||||
|
|
||||||
|
|
||||||
class BioyondResourceSynchronizer(ResourceSynchronizer):
|
class BioyondResourceSynchronizer(ResourceSynchronizer):
|
||||||
"""Bioyond资源同步器
|
"""Bioyond资源同步器
|
||||||
|
|
||||||
@@ -91,6 +176,8 @@ class BioyondResourceSynchronizer(ResourceSynchronizer):
|
|||||||
logger.warning("从Bioyond获取的物料数据为空")
|
logger.warning("从Bioyond获取的物料数据为空")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
self._update_material_cache_from_stock(all_bioyond_data)
|
||||||
|
|
||||||
# 转换为UniLab格式
|
# 转换为UniLab格式
|
||||||
unilab_resources = resource_bioyond_to_plr(
|
unilab_resources = resource_bioyond_to_plr(
|
||||||
all_bioyond_data,
|
all_bioyond_data,
|
||||||
@@ -104,6 +191,29 @@ class BioyondResourceSynchronizer(ResourceSynchronizer):
|
|||||||
logger.error(f"从Bioyond同步物料数据失败: {e}")
|
logger.error(f"从Bioyond同步物料数据失败: {e}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def _update_material_cache_from_stock(self, materials: List[Dict[str, Any]]) -> None:
|
||||||
|
"""用本次库存查询结果同步 RPC 的 name -> material id 缓存。"""
|
||||||
|
material_cache = getattr(self.bioyond_api_client, "material_cache", None)
|
||||||
|
if not isinstance(material_cache, dict):
|
||||||
|
return
|
||||||
|
|
||||||
|
before_count = len(material_cache)
|
||||||
|
for material in materials:
|
||||||
|
material_name = material.get("name")
|
||||||
|
material_id = material.get("id")
|
||||||
|
if material_name and material_id:
|
||||||
|
material_cache[material_name] = material_id
|
||||||
|
|
||||||
|
for detail_material in material.get("detail", []) or []:
|
||||||
|
detail_name = detail_material.get("name")
|
||||||
|
detail_id = detail_material.get("detailMaterialId") or detail_material.get("id")
|
||||||
|
if detail_name and detail_id:
|
||||||
|
material_cache[detail_name] = detail_id
|
||||||
|
|
||||||
|
logger.debug(
|
||||||
|
f"已用Bioyond库存同步物料缓存: {before_count} -> {len(material_cache)}"
|
||||||
|
)
|
||||||
|
|
||||||
def sync_to_external(self, resource: Any) -> bool:
|
def sync_to_external(self, resource: Any) -> bool:
|
||||||
"""将本地物料数据变更同步到Bioyond系统"""
|
"""将本地物料数据变更同步到Bioyond系统"""
|
||||||
try:
|
try:
|
||||||
@@ -174,9 +284,8 @@ class BioyondResourceSynchronizer(ResourceSynchronizer):
|
|||||||
else:
|
else:
|
||||||
logger.info(f"[同步→Bioyond] ➕ 物料不存在于 Bioyond,将创建新物料并入库")
|
logger.info(f"[同步→Bioyond] ➕ 物料不存在于 Bioyond,将创建新物料并入库")
|
||||||
|
|
||||||
# 第1步:获取仓库配置
|
# 第1步:从配置中获取仓库配置
|
||||||
from .config import WAREHOUSE_MAPPING
|
warehouse_mapping = self.bioyond_config.get("warehouse_mapping", {})
|
||||||
warehouse_mapping = WAREHOUSE_MAPPING
|
|
||||||
|
|
||||||
# 确定目标仓库名称
|
# 确定目标仓库名称
|
||||||
parent_name = None
|
parent_name = None
|
||||||
@@ -238,14 +347,20 @@ class BioyondResourceSynchronizer(ResourceSynchronizer):
|
|||||||
# 第2步:转换为 Bioyond 格式
|
# 第2步:转换为 Bioyond 格式
|
||||||
logger.info(f"[同步→Bioyond] 🔄 转换物料为 Bioyond 格式...")
|
logger.info(f"[同步→Bioyond] 🔄 转换物料为 Bioyond 格式...")
|
||||||
|
|
||||||
# 导入物料默认参数配置
|
# 从配置中获取物料默认参数
|
||||||
from .config import MATERIAL_DEFAULT_PARAMETERS
|
material_default_params = self.workstation.bioyond_config.get("material_default_parameters", {})
|
||||||
|
material_type_params = self.workstation.bioyond_config.get("material_type_parameters", {})
|
||||||
|
|
||||||
|
# 合并参数配置:物料名称参数 + typeId参数(转换为 type:<uuid> 格式)
|
||||||
|
merged_params = material_default_params.copy()
|
||||||
|
for type_id, params in material_type_params.items():
|
||||||
|
merged_params[f"type:{type_id}"] = params
|
||||||
|
|
||||||
bioyond_material = resource_plr_to_bioyond(
|
bioyond_material = resource_plr_to_bioyond(
|
||||||
[resource],
|
[resource],
|
||||||
type_mapping=self.workstation.bioyond_config["material_type_mappings"],
|
type_mapping=self.workstation.bioyond_config["material_type_mappings"],
|
||||||
warehouse_mapping=self.workstation.bioyond_config["warehouse_mapping"],
|
warehouse_mapping=self.workstation.bioyond_config["warehouse_mapping"],
|
||||||
material_params=MATERIAL_DEFAULT_PARAMETERS
|
material_params=merged_params
|
||||||
)[0]
|
)[0]
|
||||||
|
|
||||||
logger.info(f"[同步→Bioyond] 🔧 准备覆盖locations字段,目标仓库: {parent_name}, 库位: {update_site}, UUID: {target_location_uuid[:8]}...")
|
logger.info(f"[同步→Bioyond] 🔧 准备覆盖locations字段,目标仓库: {parent_name}, 库位: {update_site}, UUID: {target_location_uuid[:8]}...")
|
||||||
@@ -468,13 +583,20 @@ class BioyondResourceSynchronizer(ResourceSynchronizer):
|
|||||||
return material_bioyond_id
|
return material_bioyond_id
|
||||||
|
|
||||||
# 转换为 Bioyond 格式
|
# 转换为 Bioyond 格式
|
||||||
from .config import MATERIAL_DEFAULT_PARAMETERS
|
# 从配置中获取物料默认参数
|
||||||
|
material_default_params = self.workstation.bioyond_config.get("material_default_parameters", {})
|
||||||
|
material_type_params = self.workstation.bioyond_config.get("material_type_parameters", {})
|
||||||
|
|
||||||
|
# 合并参数配置:物料名称参数 + typeId参数(转换为 type:<uuid> 格式)
|
||||||
|
merged_params = material_default_params.copy()
|
||||||
|
for type_id, params in material_type_params.items():
|
||||||
|
merged_params[f"type:{type_id}"] = params
|
||||||
|
|
||||||
bioyond_material = resource_plr_to_bioyond(
|
bioyond_material = resource_plr_to_bioyond(
|
||||||
[resource],
|
[resource],
|
||||||
type_mapping=self.workstation.bioyond_config["material_type_mappings"],
|
type_mapping=self.workstation.bioyond_config["material_type_mappings"],
|
||||||
warehouse_mapping=self.workstation.bioyond_config["warehouse_mapping"],
|
warehouse_mapping=self.workstation.bioyond_config["warehouse_mapping"],
|
||||||
material_params=MATERIAL_DEFAULT_PARAMETERS
|
material_params=merged_params
|
||||||
)[0]
|
)[0]
|
||||||
|
|
||||||
# ⚠️ 关键:创建物料时不设置 locations,让 Bioyond 系统暂不分配库位
|
# ⚠️ 关键:创建物料时不设置 locations,让 Bioyond 系统暂不分配库位
|
||||||
@@ -528,8 +650,7 @@ class BioyondResourceSynchronizer(ResourceSynchronizer):
|
|||||||
logger.info(f"[物料入库] 目标库位: {update_site}")
|
logger.info(f"[物料入库] 目标库位: {update_site}")
|
||||||
|
|
||||||
# 获取仓库配置和目标库位 UUID
|
# 获取仓库配置和目标库位 UUID
|
||||||
from .config import WAREHOUSE_MAPPING
|
warehouse_mapping = self.workstation.bioyond_config.get("warehouse_mapping", {})
|
||||||
warehouse_mapping = WAREHOUSE_MAPPING
|
|
||||||
|
|
||||||
parent_name = None
|
parent_name = None
|
||||||
target_location_uuid = None
|
target_location_uuid = None
|
||||||
@@ -584,6 +705,108 @@ class BioyondWorkstation(WorkstationBase):
|
|||||||
集成Bioyond物料管理的工作站实现
|
集成Bioyond物料管理的工作站实现
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# 子类(如 sirna / peptide)覆写以指定默认 raw-call 日志目录。
|
||||||
|
# 路径相对仓库根;为 None 时若 debug_log=True 仍会写入临时位置。
|
||||||
|
_DEBUG_LOG_DEFAULT_DIR: Optional[str] = None
|
||||||
|
|
||||||
|
def _create_bioyond_rpc(self, config: Dict[str, Any]) -> BioyondV1RPC:
|
||||||
|
"""创建 Bioyond RPC 客户端并应用调试包装。
|
||||||
|
|
||||||
|
所有创建 ``BioyondV1RPC`` 的路径(饿汉初始化、Sirna 延迟初始化、
|
||||||
|
以及未来的前端重新配置路径)都应通过该 helper,
|
||||||
|
以确保 debug_log 包装与命名/日志策略保持一致。
|
||||||
|
"""
|
||||||
|
rpc = BioyondV1RPC(config)
|
||||||
|
debug_call_log.wrap_rpc_http(rpc)
|
||||||
|
return rpc
|
||||||
|
|
||||||
|
def _set_hardware_interface(self, rpc: BioyondV1RPC) -> BioyondV1RPC:
|
||||||
|
"""将已构造的 RPC 客户端设置到 ``self.hardware_interface``,并应用调试包装。"""
|
||||||
|
debug_call_log.wrap_rpc_http(rpc)
|
||||||
|
self.hardware_interface = rpc
|
||||||
|
return rpc
|
||||||
|
|
||||||
|
def _debug_log_resolved_dir(self) -> Path:
|
||||||
|
"""解析 ``debug_log_dir`` 为绝对路径。"""
|
||||||
|
configured = (getattr(self, "bioyond_config", {}) or {}).get("debug_log_dir")
|
||||||
|
default_dir = getattr(self, "_DEBUG_LOG_DEFAULT_DIR", None)
|
||||||
|
candidate = configured or default_dir or "temp_benyao/_logs/bioyond_debug"
|
||||||
|
path = Path(candidate)
|
||||||
|
if not path.is_absolute():
|
||||||
|
repo_root = Path(__file__).resolve().parents[4]
|
||||||
|
path = repo_root / path
|
||||||
|
return path
|
||||||
|
|
||||||
|
def _ensure_debug_log_state(self) -> None:
|
||||||
|
"""从 ``self.bioyond_config`` 派生 ``_debug_log_enabled`` / ``_debug_log_dir``。
|
||||||
|
|
||||||
|
每次进入 ``_debug_call_session`` 时都重新解析,以兼容前端在运行时
|
||||||
|
修改 ``bioyond_config['debug_log']`` 或目录的场景;同时也容忍
|
||||||
|
子类(如 Sirna 延迟初始化)在 ``__init__`` 早期未触发本方法。
|
||||||
|
"""
|
||||||
|
cfg = getattr(self, "bioyond_config", {}) or {}
|
||||||
|
self._debug_log_enabled = bool(cfg.get("debug_log"))
|
||||||
|
self._debug_log_dir = self._debug_log_resolved_dir()
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def _debug_call_session(self, action_name: str):
|
||||||
|
"""在 action 体外加一层 debug 会话上下文。
|
||||||
|
|
||||||
|
- ``debug_log`` 关闭时是空上下文,开销为 0。
|
||||||
|
- ``debug_log`` 开启时进入 :func:`debug_call_log.session`,所有
|
||||||
|
已被 ``wrap_rpc_http`` 包装过的 RPC 客户端都会捕获本次 action
|
||||||
|
产生的 HTTP 调用并写入 Markdown 文件。
|
||||||
|
|
||||||
|
子类(如 ``end_experiment``、``manual_unload`` 等)可以直接在
|
||||||
|
action 体里以 ``with self._debug_call_session("action_name"):`` 包裹。
|
||||||
|
"""
|
||||||
|
cfg = getattr(self, "bioyond_config", {}) or {}
|
||||||
|
enabled = bool(cfg.get("debug_log"))
|
||||||
|
if not enabled:
|
||||||
|
yield None
|
||||||
|
return
|
||||||
|
out_dir = BioyondWorkstation._debug_log_resolved_dir(self)
|
||||||
|
with debug_call_log.session(action_name, out_dir) as ctx:
|
||||||
|
yield ctx
|
||||||
|
|
||||||
|
def _publish_task_status(
|
||||||
|
self,
|
||||||
|
task_id: str,
|
||||||
|
task_type: str,
|
||||||
|
status: str,
|
||||||
|
result: dict = None,
|
||||||
|
progress: float = 0.0,
|
||||||
|
task_code: str = None
|
||||||
|
):
|
||||||
|
"""发布任务状态事件"""
|
||||||
|
try:
|
||||||
|
if not getattr(self, "_ros_node", None):
|
||||||
|
return
|
||||||
|
|
||||||
|
event_data = {
|
||||||
|
"task_id": task_id,
|
||||||
|
"task_code": task_code,
|
||||||
|
"task_type": task_type,
|
||||||
|
"status": status,
|
||||||
|
"progress": progress,
|
||||||
|
"timestamp": datetime.now().isoformat()
|
||||||
|
}
|
||||||
|
if result:
|
||||||
|
event_data["result"] = result
|
||||||
|
|
||||||
|
topic = f"{self._ros_node.namespace}/events/task_status"
|
||||||
|
|
||||||
|
if not hasattr(self, "_task_status_pub"):
|
||||||
|
self._task_status_pub = self._ros_node.create_publisher(
|
||||||
|
String, topic, 10
|
||||||
|
)
|
||||||
|
|
||||||
|
self._task_status_pub.publish(
|
||||||
|
convert_to_ros_msg(String, json.dumps(event_data, ensure_ascii=False))
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"发布任务状态事件失败: {e}")
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
bioyond_config: Optional[Dict[str, Any]] = None,
|
bioyond_config: Optional[Dict[str, Any]] = None,
|
||||||
@@ -605,10 +828,28 @@ class BioyondWorkstation(WorkstationBase):
|
|||||||
raise ValueError("Deck 配置不能为空,请在配置文件中添加正确的 deck 配置")
|
raise ValueError("Deck 配置不能为空,请在配置文件中添加正确的 deck 配置")
|
||||||
|
|
||||||
# 初始化 warehouses 属性
|
# 初始化 warehouses 属性
|
||||||
self.deck.warehouses = {}
|
if not hasattr(self.deck, "warehouses") or self.deck.warehouses is None:
|
||||||
for resource in self.deck.children:
|
self.deck.warehouses = {}
|
||||||
if isinstance(resource, WareHouse):
|
|
||||||
self.deck.warehouses[resource.name] = resource
|
# 仅当 warehouses 为空时尝试重新扫描(避免覆盖子类的修复)
|
||||||
|
if not self.deck.warehouses:
|
||||||
|
for resource in self.deck.children:
|
||||||
|
# 兼容性增强: 只要是仓库类别或者是 WareHouse 实例均可
|
||||||
|
is_warehouse = isinstance(resource, WareHouse) or getattr(resource, "category", "") == "warehouse"
|
||||||
|
|
||||||
|
# 如果配置中有定义,也可以认定为 warehouse
|
||||||
|
if not is_warehouse and "warehouse_mapping" in bioyond_config:
|
||||||
|
if resource.name in bioyond_config["warehouse_mapping"]:
|
||||||
|
is_warehouse = True
|
||||||
|
|
||||||
|
if is_warehouse:
|
||||||
|
self.deck.warehouses[resource.name] = resource
|
||||||
|
# 确保 category 被正确设置,方便后续使用
|
||||||
|
if getattr(resource, "category", "") != "warehouse":
|
||||||
|
try:
|
||||||
|
resource.category = "warehouse"
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
# 创建通信模块
|
# 创建通信模块
|
||||||
self._create_communication_module(bioyond_config)
|
self._create_communication_module(bioyond_config)
|
||||||
@@ -627,18 +868,22 @@ class BioyondWorkstation(WorkstationBase):
|
|||||||
self._set_workflow_mappings(bioyond_config["workflow_mappings"])
|
self._set_workflow_mappings(bioyond_config["workflow_mappings"])
|
||||||
|
|
||||||
# 准备 HTTP 报送接收服务配置(延迟到 post_init 启动)
|
# 准备 HTTP 报送接收服务配置(延迟到 post_init 启动)
|
||||||
# 从 bioyond_config 中获取,如果没有则使用 HTTP_SERVICE_CONFIG 的默认值
|
# 从 bioyond_config 中的 http_service_config 获取
|
||||||
|
http_service_cfg = bioyond_config.get("http_service_config", {})
|
||||||
self._http_service_config = {
|
self._http_service_config = {
|
||||||
"host": bioyond_config.get("http_service_host", HTTP_SERVICE_CONFIG["http_service_host"]),
|
"host": http_service_cfg.get("http_service_host", "127.0.0.1"),
|
||||||
"port": bioyond_config.get("http_service_port", HTTP_SERVICE_CONFIG["http_service_port"])
|
"port": http_service_cfg.get("http_service_port", 8080)
|
||||||
}
|
}
|
||||||
self.http_service = None # 将在 post_init 中启动
|
self.http_service = None # 将在 post_init 启动
|
||||||
|
self.connection_monitor = None # 将在 post_init 启动
|
||||||
|
|
||||||
logger.info(f"Bioyond工作站初始化完成")
|
logger.info(f"Bioyond工作站初始化完成")
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
"""析构函数:清理资源,停止 HTTP 服务"""
|
"""析构函数:清理资源,停止 HTTP 服务"""
|
||||||
try:
|
try:
|
||||||
|
if hasattr(self, 'connection_monitor') and self.connection_monitor:
|
||||||
|
self.connection_monitor.stop()
|
||||||
if hasattr(self, 'http_service') and self.http_service is not None:
|
if hasattr(self, 'http_service') and self.http_service is not None:
|
||||||
logger.info("正在停止 HTTP 报送服务...")
|
logger.info("正在停止 HTTP 报送服务...")
|
||||||
self.http_service.stop()
|
self.http_service.stop()
|
||||||
@@ -648,8 +893,19 @@ class BioyondWorkstation(WorkstationBase):
|
|||||||
def post_init(self, ros_node: ROS2WorkstationNode):
|
def post_init(self, ros_node: ROS2WorkstationNode):
|
||||||
self._ros_node = ros_node
|
self._ros_node = ros_node
|
||||||
|
|
||||||
|
# 启动连接监控
|
||||||
|
try:
|
||||||
|
self.connection_monitor = ConnectionMonitor(self)
|
||||||
|
self.connection_monitor.start()
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"启动连接监控失败: {e}")
|
||||||
|
|
||||||
# 启动 HTTP 报送接收服务(现在 device_id 已可用)
|
# 启动 HTTP 报送接收服务(现在 device_id 已可用)
|
||||||
if hasattr(self, '_http_service_config'):
|
# ⚠️ 检查子类是否已经自己管理 HTTP 服务
|
||||||
|
if self.bioyond_config.get("_disable_auto_http_service"):
|
||||||
|
logger.info("🔧 检测到 _disable_auto_http_service 标志,跳过自动启动 HTTP 服务")
|
||||||
|
logger.info(" 子类(BioyondCellWorkstation)已自行管理 HTTP 服务")
|
||||||
|
elif hasattr(self, '_http_service_config'):
|
||||||
try:
|
try:
|
||||||
self.http_service = WorkstationHTTPService(
|
self.http_service = WorkstationHTTPService(
|
||||||
workstation_instance=self,
|
workstation_instance=self,
|
||||||
@@ -688,21 +944,16 @@ class BioyondWorkstation(WorkstationBase):
|
|||||||
|
|
||||||
def _create_communication_module(self, config: Optional[Dict[str, Any]] = None) -> None:
|
def _create_communication_module(self, config: Optional[Dict[str, Any]] = None) -> None:
|
||||||
"""创建Bioyond通信模块"""
|
"""创建Bioyond通信模块"""
|
||||||
# 创建默认配置
|
# 直接使用传入的配置,不再使用默认值
|
||||||
default_config = {
|
# 所有配置必须从 JSON 文件中提供
|
||||||
**API_CONFIG,
|
|
||||||
"workflow_mappings": WORKFLOW_MAPPINGS,
|
|
||||||
"material_type_mappings": MATERIAL_TYPE_MAPPINGS,
|
|
||||||
"warehouse_mapping": WAREHOUSE_MAPPING
|
|
||||||
}
|
|
||||||
|
|
||||||
# 如果传入了 config,合并配置(config 中的值会覆盖默认值)
|
|
||||||
if config:
|
if config:
|
||||||
self.bioyond_config = {**default_config, **config}
|
self.bioyond_config = config
|
||||||
else:
|
else:
|
||||||
self.bioyond_config = default_config
|
# 如果没有配置,使用空字典(会导致后续错误,但这是预期的)
|
||||||
|
self.bioyond_config = {}
|
||||||
|
print("警告: 未提供 bioyond_config,请确保在 JSON 配置文件中提供完整配置")
|
||||||
|
|
||||||
self.hardware_interface = BioyondV1RPC(self.bioyond_config)
|
self.hardware_interface = self._create_bioyond_rpc(self.bioyond_config)
|
||||||
|
|
||||||
def resource_tree_add(self, resources: List[ResourcePLR]) -> None:
|
def resource_tree_add(self, resources: List[ResourcePLR]) -> None:
|
||||||
"""添加资源到资源树并更新ROS节点
|
"""添加资源到资源树并更新ROS节点
|
||||||
@@ -1014,7 +1265,15 @@ class BioyondWorkstation(WorkstationBase):
|
|||||||
|
|
||||||
workflow_id = self._get_workflow(actual_workflow_name)
|
workflow_id = self._get_workflow(actual_workflow_name)
|
||||||
if workflow_id:
|
if workflow_id:
|
||||||
self.workflow_sequence.append(workflow_id)
|
# 兼容 BioyondReactionStation 中 workflow_sequence 被重写为 property 的情况
|
||||||
|
if isinstance(self.workflow_sequence, list):
|
||||||
|
self.workflow_sequence.append(workflow_id)
|
||||||
|
elif hasattr(self, "_cached_workflow_sequence") and isinstance(self._cached_workflow_sequence, list):
|
||||||
|
self._cached_workflow_sequence.append(workflow_id)
|
||||||
|
else:
|
||||||
|
print(f"❌ 无法添加工作流: workflow_sequence 类型错误 {type(self.workflow_sequence)}")
|
||||||
|
return False
|
||||||
|
|
||||||
print(f"添加工作流到执行顺序: {actual_workflow_name} -> {workflow_id}")
|
print(f"添加工作流到执行顺序: {actual_workflow_name} -> {workflow_id}")
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
@@ -1170,11 +1429,7 @@ class BioyondWorkstation(WorkstationBase):
|
|||||||
if self.hardware_interface:
|
if self.hardware_interface:
|
||||||
self.hardware_interface.scheduler_reset()
|
self.hardware_interface.scheduler_reset()
|
||||||
|
|
||||||
# 刷新物料缓存
|
# 重新同步资源,并用同一次库存查询结果更新物料缓存
|
||||||
if self.hardware_interface:
|
|
||||||
self.hardware_interface.refresh_material_cache()
|
|
||||||
|
|
||||||
# 重新同步资源
|
|
||||||
if self.resource_synchronizer:
|
if self.resource_synchronizer:
|
||||||
self.resource_synchronizer.sync_from_external()
|
self.resource_synchronizer.sync_from_external()
|
||||||
|
|
||||||
@@ -1215,6 +1470,22 @@ class BioyondWorkstation(WorkstationBase):
|
|||||||
# TODO: 根据实际业务需求处理步骤完成逻辑
|
# TODO: 根据实际业务需求处理步骤完成逻辑
|
||||||
# 例如:更新数据库、触发后续流程等
|
# 例如:更新数据库、触发后续流程等
|
||||||
|
|
||||||
|
# 发布任务状态事件 (running/progress update)
|
||||||
|
self._publish_task_status(
|
||||||
|
task_id=data.get('orderCode'), # 使用 OrderCode 作为关联 ID
|
||||||
|
task_code=data.get('orderCode'),
|
||||||
|
task_type="bioyond_step",
|
||||||
|
status="running",
|
||||||
|
progress=0.5, # 步骤完成视为任务进行中
|
||||||
|
result={"step_name": data.get('stepName'), "step_id": data.get('stepId')}
|
||||||
|
)
|
||||||
|
|
||||||
|
# 更新物料信息
|
||||||
|
# 步骤完成后,物料状态可能发生变化(如位置、用量等),触发同步
|
||||||
|
logger.info(f"[步骤完成报送] 触发物料同步...")
|
||||||
|
self.resource_synchronizer.sync_from_external()
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"processed": True,
|
"processed": True,
|
||||||
"step_id": data.get('stepId'),
|
"step_id": data.get('stepId'),
|
||||||
@@ -1249,6 +1520,17 @@ class BioyondWorkstation(WorkstationBase):
|
|||||||
|
|
||||||
# TODO: 根据实际业务需求处理通量完成逻辑
|
# TODO: 根据实际业务需求处理通量完成逻辑
|
||||||
|
|
||||||
|
# 发布任务状态事件
|
||||||
|
self._publish_task_status(
|
||||||
|
task_id=data.get('orderCode'),
|
||||||
|
task_code=data.get('orderCode'),
|
||||||
|
task_type="bioyond_sample",
|
||||||
|
status="running",
|
||||||
|
progress=0.7,
|
||||||
|
result={"sample_id": data.get('sampleId'), "status": status_desc}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"processed": True,
|
"processed": True,
|
||||||
"sample_id": data.get('sampleId'),
|
"sample_id": data.get('sampleId'),
|
||||||
@@ -1288,6 +1570,32 @@ class BioyondWorkstation(WorkstationBase):
|
|||||||
# TODO: 根据实际业务需求处理任务完成逻辑
|
# TODO: 根据实际业务需求处理任务完成逻辑
|
||||||
# 例如:更新物料库存、生成报表等
|
# 例如:更新物料库存、生成报表等
|
||||||
|
|
||||||
|
# 映射状态到事件状态
|
||||||
|
event_status = "completed"
|
||||||
|
if str(data.get('status')) in ["-11", "-12"]:
|
||||||
|
event_status = "error"
|
||||||
|
elif str(data.get('status')) == "30":
|
||||||
|
event_status = "completed"
|
||||||
|
else:
|
||||||
|
event_status = "running" # 其他状态视为运行中(或根据实际定义)
|
||||||
|
|
||||||
|
# 发布任务状态事件
|
||||||
|
self._publish_task_status(
|
||||||
|
task_id=data.get('orderCode'),
|
||||||
|
task_code=data.get('orderCode'),
|
||||||
|
task_type="bioyond_order",
|
||||||
|
status=event_status,
|
||||||
|
progress=1.0 if event_status in ["completed", "error"] else 0.9,
|
||||||
|
result={"order_name": data.get('orderName'), "status": status_desc, "materials_count": len(used_materials)}
|
||||||
|
)
|
||||||
|
|
||||||
|
# 更新物料信息
|
||||||
|
# 任务完成后,且状态为完成时,触发同步以更新最终物料状态
|
||||||
|
if event_status == "completed":
|
||||||
|
logger.info(f"[任务完成报送] 触发物料同步...")
|
||||||
|
self.resource_synchronizer.sync_from_external()
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"processed": True,
|
"processed": True,
|
||||||
"order_code": data.get('orderCode'),
|
"order_code": data.get('orderCode'),
|
||||||
|
|||||||
@@ -0,0 +1,84 @@
|
|||||||
|
# Modbus CSV 地址映射说明
|
||||||
|
|
||||||
|
本文档说明 `coin_cell_assembly_a.csv` 文件如何将命名节点映射到实际的 Modbus 地址,以及如何在代码中使用它们。
|
||||||
|
|
||||||
|
## 1. CSV 文件结构
|
||||||
|
|
||||||
|
地址表文件位于同级目录下:`coin_cell_assembly_a.csv`
|
||||||
|
|
||||||
|
每一行定义了一个 Modbus 节点,包含以下关键列:
|
||||||
|
|
||||||
|
| 列名 | 说明 | 示例 |
|
||||||
|
|------|------|------|
|
||||||
|
| **Name** | **节点名称** (代码中引用的 Key) | `COIL_ALUMINUM_FOIL` |
|
||||||
|
| **DataType** | 数据类型 (BOOL, INT16, FLOAT32, STRING) | `BOOL` |
|
||||||
|
| **Comment** | 注释说明 | `使用铝箔垫` |
|
||||||
|
| **Attribute** | 属性 (通常留空或用于额外标记) | |
|
||||||
|
| **DeviceType** | Modbus 寄存器类型 (`coil`, `hold_register`) | `coil` |
|
||||||
|
| **Address** | **Modbus 地址** (十进制) | `8340` |
|
||||||
|
|
||||||
|
### 示例行 (铝箔垫片)
|
||||||
|
|
||||||
|
```csv
|
||||||
|
COIL_ALUMINUM_FOIL,BOOL,,使用铝箔垫,,coil,8340,
|
||||||
|
```
|
||||||
|
|
||||||
|
- **名称**: `COIL_ALUMINUM_FOIL`
|
||||||
|
- **类型**: `coil` (线圈,读写单个位)
|
||||||
|
- **地址**: `8340`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. 加载与注册流程
|
||||||
|
|
||||||
|
在 `coin_cell_assembly.py` 的初始化代码中:
|
||||||
|
|
||||||
|
1. **加载 CSV**: `BaseClient.load_csv()` 读取 CSV 并解析每行定义。
|
||||||
|
2. **注册节点**: `modbus_client.register_node_list()` 将解析后的节点注册到 Modbus 客户端实例中。
|
||||||
|
|
||||||
|
```python
|
||||||
|
# 代码位置: coin_cell_assembly.py (L174-175)
|
||||||
|
self.nodes = BaseClient.load_csv(os.path.join(os.path.dirname(__file__), 'coin_cell_assembly_a.csv'))
|
||||||
|
self.client = modbus_client.register_node_list(self.nodes)
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. 代码中的使用方式
|
||||||
|
|
||||||
|
注册后,通过 `self.client.use_node('节点名称')` 即可获取该节点对象并进行读写操作,无需关心具体地址。
|
||||||
|
|
||||||
|
### 控制铝箔垫片 (COIL_ALUMINUM_FOIL)
|
||||||
|
|
||||||
|
```python
|
||||||
|
# 代码位置: qiming_coin_cell_code 函数 (L1048)
|
||||||
|
self.client.use_node('COIL_ALUMINUM_FOIL').write(not lvbodian)
|
||||||
|
```
|
||||||
|
|
||||||
|
- **写入 True**: 对应 Modbus 功能码 05 (Write Single Coil),向地址 `8340` 写入 `1` (ON)。
|
||||||
|
- **写入 False**: 向地址 `8340` 写入 `0` (OFF)。
|
||||||
|
|
||||||
|
> **注意**: 代码中使用了 `not lvbodian`,这意味着逻辑是反转的。如果 `lvbodian` 参数为 `True` (默认),写入的是 `False` (不使用铝箔垫)。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. 地址转换注意事项 (Modbus vs PLC)
|
||||||
|
|
||||||
|
CSV 中的 `Address` 列(如 `8340`)是 **Modbus 协议地址**。
|
||||||
|
|
||||||
|
如果使用 InoProShop (汇川 PLC 编程软件),看到的可能是 **PLC 内部地址** (如 `%QX...` 或 `%MW...`)。这两者之间通常需要转换。
|
||||||
|
|
||||||
|
### 常见的转换规则 (示例)
|
||||||
|
|
||||||
|
- **Coil (线圈) %QX**:
|
||||||
|
- `Modbus地址 = 字节地址 * 8 + 位偏移`
|
||||||
|
- *例子*: `%QX834.0` -> `834 * 8 + 0` = `6672`
|
||||||
|
- *注意*: 如果 CSV 中配置的是 `8340`,这可能是一个自定义映射,或者是基于不同规则(如直接对应 Word 地址的某种映射,或者可能就是地址写错了/使用了非标准映射)。
|
||||||
|
|
||||||
|
- **Register (寄存器) %MW**:
|
||||||
|
- 通常直接对应,或者有偏移量 (如 Modbus 40001 = PLC MW0)。
|
||||||
|
|
||||||
|
### 验证方法
|
||||||
|
由于 `test_unilab_interact.py` 中发现 `8450` (CSV风格) 不工作,而 `6760` (%QX845.0 计算值) 工作正常,**建议对 CSV 中的其他地址也进行核实**,特别是像 `8340` 这样以 0 结尾看起来像是 "字节地址+0" 的数值,可能实际上应该是 `%QX834.0` 对应的 `6672`。
|
||||||
|
|
||||||
|
如果发现设备控制无反应,请尝试按照标准的 Modbus 计算方式转换 PLC 地址。
|
||||||
@@ -0,0 +1,352 @@
|
|||||||
|
# 2026-01-13 物料搜寻确认弹窗自动处理功能
|
||||||
|
|
||||||
|
## 概述
|
||||||
|
|
||||||
|
本次更新为设备初始化流程添加了**物料搜寻确认弹窗自动检测与处理功能**。在设备初始化过程中,PLC 会弹出物料搜寻确认对话框,现在系统可以根据用户参数自动点击"是"或"否"按钮,无需手动干预。
|
||||||
|
|
||||||
|
## 背景问题
|
||||||
|
|
||||||
|
### 原有流程
|
||||||
|
1. 调用 `func_pack_device_init_auto_start_combined()` 初始化设备
|
||||||
|
2. PLC 在初始化过程中弹出物料搜寻确认对话框
|
||||||
|
3. **需要人工手动点击**"是"或"否"按钮
|
||||||
|
4. PLC 继续完成初始化并启动
|
||||||
|
|
||||||
|
### 存在的问题
|
||||||
|
- 需要人工干预,无法实现全自动化
|
||||||
|
- 影响批量生产效率
|
||||||
|
- 容易遗忘点击导致流程卡住
|
||||||
|
|
||||||
|
## 解决方案
|
||||||
|
|
||||||
|
### 新增 Modbus 地址配置
|
||||||
|
|
||||||
|
在 `coin_cell_assembly_b.csv` 第 69-71 行添加三个 coil:
|
||||||
|
|
||||||
|
| Name | DeviceType | Address | 说明 |
|
||||||
|
|------|-----------|---------|------|
|
||||||
|
| COIL_MATERIAL_SEARCH_DIALOG_APPEAR | coil | 6470 | 物料搜寻确认弹窗画面是否出现 |
|
||||||
|
| COIL_MATERIAL_SEARCH_CONFIRM_YES | coil | 6480 | 初始化物料搜寻确认按钮"是" |
|
||||||
|
| COIL_MATERIAL_SEARCH_CONFIRM_NO | coil | 6490 | 初始化物料搜寻确认按钮"否" |
|
||||||
|
|
||||||
|
**Modbus 地址转换:**
|
||||||
|
- CSV 6470 → Modbus 5176 (弹窗出现)
|
||||||
|
- CSV 6480 → Modbus 5184 (按钮"是")
|
||||||
|
- CSV 6490 → Modbus 5192 (按钮"否")
|
||||||
|
|
||||||
|
## 代码修改详情
|
||||||
|
|
||||||
|
### 1. coin_cell_assembly.py
|
||||||
|
|
||||||
|
#### 1.1 新增辅助方法 `_handle_material_search_dialog()`
|
||||||
|
|
||||||
|
**位置:** 第 799-901 行
|
||||||
|
|
||||||
|
**功能:**
|
||||||
|
- 监测物料搜寻确认弹窗是否出现(Coil 5176)
|
||||||
|
- 根据 `enable_search` 参数自动点击对应按钮
|
||||||
|
- 使用**脉冲模式**模拟真实按钮操作:`True` → 保持 0.5 秒 → `False`
|
||||||
|
|
||||||
|
**参数:**
|
||||||
|
- `enable_search: bool` - True=点击"是"(启用物料搜寻), False=点击"否"(不启用)
|
||||||
|
- `timeout: int = 30` - 等待弹窗出现的最大时间(秒)
|
||||||
|
|
||||||
|
**逻辑流程:**
|
||||||
|
```python
|
||||||
|
1. 监测 COIL_MATERIAL_SEARCH_DIALOG_APPEAR (每 0.5 秒检查一次)
|
||||||
|
2. 检测到弹窗出现 (Coil = True)
|
||||||
|
3. 选择按钮:
|
||||||
|
- enable_search=True → COIL_MATERIAL_SEARCH_CONFIRM_YES
|
||||||
|
- enable_search=False → COIL_MATERIAL_SEARCH_CONFIRM_NO
|
||||||
|
4. 执行脉冲操作:
|
||||||
|
- 写入 True (按下按钮)
|
||||||
|
- 等待 0.5 秒
|
||||||
|
- 写入 False (释放按钮)
|
||||||
|
- 验证状态
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 1.2 修改 `func_pack_device_init_auto_start_combined()`
|
||||||
|
|
||||||
|
**位置:** 第 904-1115 行
|
||||||
|
|
||||||
|
**主要改动:**
|
||||||
|
|
||||||
|
1. **添加新参数**
|
||||||
|
```python
|
||||||
|
def func_pack_device_init_auto_start_combined(
|
||||||
|
self,
|
||||||
|
material_search_enable: bool = False # 新增参数
|
||||||
|
) -> bool:
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **内联初始化逻辑并集成弹窗检测**
|
||||||
|
- 不再调用 `self.func_pack_device_init()`
|
||||||
|
- 将初始化逻辑直接实现在函数内
|
||||||
|
- **在等待初始化完成的循环中实时检测弹窗**
|
||||||
|
- 避免死锁:PLC 等待弹窗确认 ↔ 代码等待初始化完成
|
||||||
|
|
||||||
|
3. **关键代码片段**
|
||||||
|
```python
|
||||||
|
# 等待初始化完成,同时检测物料搜寻弹窗
|
||||||
|
while (self._sys_init_status()) == False:
|
||||||
|
# 检查超时
|
||||||
|
if time.time() - start_wait > max_wait_time:
|
||||||
|
raise RuntimeError(f"初始化超时")
|
||||||
|
|
||||||
|
# 如果还没处理弹窗,检测弹窗是否出现
|
||||||
|
if not dialog_handled:
|
||||||
|
dialog_state = self.client.use_node('COIL_MATERIAL_SEARCH_DIALOG_APPEAR').read(1)
|
||||||
|
if dialog_actual: # 弹窗出现
|
||||||
|
# 执行脉冲按钮点击
|
||||||
|
button_node.write(True) # 按下
|
||||||
|
time.sleep(0.5) # 保持
|
||||||
|
button_node.write(False) # 释放
|
||||||
|
dialog_handled = True
|
||||||
|
|
||||||
|
time.sleep(1)
|
||||||
|
```
|
||||||
|
|
||||||
|
4. **步骤调整**
|
||||||
|
- 步骤 0: 前置条件检查
|
||||||
|
- 步骤 1: 设备初始化(**包含弹窗检测**)
|
||||||
|
- 步骤 1.5: 已在步骤 1 中完成
|
||||||
|
- 步骤 2: 切换自动模式
|
||||||
|
- 步骤 3: 启动设备
|
||||||
|
|
||||||
|
### 2. coin_cell_workstation.yaml
|
||||||
|
|
||||||
|
**位置:** 第 292-312 行
|
||||||
|
|
||||||
|
**修改内容:**
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
auto-func_pack_device_init_auto_start_combined:
|
||||||
|
goal_default:
|
||||||
|
material_search_enable: false # 新增默认值
|
||||||
|
|
||||||
|
schema:
|
||||||
|
description: 组合函数:设备初始化 + 物料搜寻确认 + 切换自动模式 + 启动。初始化过程中会自动检测物料搜寻确认弹窗,并根据参数自动点击"是"或"否"按钮
|
||||||
|
|
||||||
|
goal:
|
||||||
|
properties:
|
||||||
|
material_search_enable: # 新增参数配置
|
||||||
|
default: false
|
||||||
|
description: 是否启用物料搜寻功能。设备初始化后会弹出物料搜寻确认弹窗,此参数控制自动点击"是"(启用)或"否"(不启用)。默认为false(不启用物料搜寻)
|
||||||
|
type: boolean
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. 测试脚本(已创建,用户已删除)
|
||||||
|
|
||||||
|
#### 3.1 test_material_search_dialog.py
|
||||||
|
- 从 CSV 动态加载 Modbus 地址
|
||||||
|
- 支持 4 种测试模式:
|
||||||
|
- `query` - 查询所有状态
|
||||||
|
- `dialog <0|1>` - 设置弹窗出现/消失
|
||||||
|
- `yes` - 脉冲点击"是"按钮
|
||||||
|
- `no` - 脉冲点击"否"按钮
|
||||||
|
- 兼容 pymodbus 3.x API
|
||||||
|
|
||||||
|
#### 3.2 更新其他测试脚本
|
||||||
|
- `test_coin_cell_reset.py` - 更新为 pymodbus 3.x API
|
||||||
|
- `test_unilab_interact.py` - 更新为 pymodbus 3.x API
|
||||||
|
|
||||||
|
## 使用方法
|
||||||
|
|
||||||
|
### 参数说明
|
||||||
|
|
||||||
|
| 参数 | 类型 | 默认值 | 说明 |
|
||||||
|
|------|------|--------|------|
|
||||||
|
| `material_search_enable` | boolean | `false` | 是否启用物料搜寻功能 |
|
||||||
|
|
||||||
|
### 调用示例
|
||||||
|
|
||||||
|
#### 1. 不启用物料搜寻(默认)
|
||||||
|
```python
|
||||||
|
# 默认参数,点击"否"按钮
|
||||||
|
await device.func_pack_device_init_auto_start_combined()
|
||||||
|
```
|
||||||
|
|
||||||
|
或在 YAML workflow 中:
|
||||||
|
```yaml
|
||||||
|
# 使用默认值 false,不启用物料搜寻
|
||||||
|
- BatteryStation/auto-func_pack_device_init_auto_start_combined: {}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 2. 启用物料搜寻
|
||||||
|
```python
|
||||||
|
# 显式设置为 True,点击"是"按钮
|
||||||
|
await device.func_pack_device_init_auto_start_combined(
|
||||||
|
material_search_enable=True
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
或在 YAML workflow 中:
|
||||||
|
```yaml
|
||||||
|
- BatteryStation/auto-func_pack_device_init_auto_start_combined:
|
||||||
|
goal:
|
||||||
|
material_search_enable: true # 启用物料搜寻
|
||||||
|
```
|
||||||
|
|
||||||
|
## 执行日志示例
|
||||||
|
|
||||||
|
```
|
||||||
|
26-01-13 [21:32:44] [INFO] 开始组合操作:设备初始化 → 物料搜寻确认 → 自动模式 → 启动
|
||||||
|
26-01-13 [21:32:44] [INFO] 【步骤 0/4】前置条件检查...
|
||||||
|
26-01-13 [21:32:44] [INFO] ✓ REG_UNILAB_INTERACT 检查通过
|
||||||
|
26-01-13 [21:32:44] [INFO] ✓ COIL_GB_L_IGNORE_CMD 检查通过
|
||||||
|
26-01-13 [21:32:44] [INFO] 【步骤 1/4】设备初始化...
|
||||||
|
26-01-13 [21:32:44] [INFO] 切换手动模式...
|
||||||
|
26-01-13 [21:32:46] [INFO] 发送初始化命令...
|
||||||
|
26-01-13 [21:32:47] [INFO] 等待初始化完成(同时监测物料搜寻弹窗)...
|
||||||
|
26-01-13 [21:33:05] [INFO] ✓ 在初始化过程中检测到物料搜寻确认弹窗!
|
||||||
|
26-01-13 [21:33:05] [INFO] 用户选择: 不启用物料搜寻(点击否)
|
||||||
|
26-01-13 [21:33:05] [INFO] → 按下按钮 '否'
|
||||||
|
26-01-13 [21:33:06] [INFO] → 释放按钮 '否'
|
||||||
|
26-01-13 [21:33:07] [INFO] ✓ 成功处理物料搜寻确认弹窗(选择: 否)
|
||||||
|
26-01-13 [21:33:08] [INFO] ✓ 初始化状态完成
|
||||||
|
26-01-13 [21:33:12] [INFO] ✓ 设备初始化完成
|
||||||
|
26-01-13 [21:33:12] [INFO] 【步骤 1.5/4】物料搜寻确认已在初始化过程中完成
|
||||||
|
26-01-13 [21:33:12] [INFO] 【步骤 2/4】切换自动模式...
|
||||||
|
26-01-13 [21:33:15] [INFO] ✓ 切换自动模式完成
|
||||||
|
26-01-13 [21:33:15] [INFO] 【步骤 3/4】启动设备...
|
||||||
|
26-01-13 [21:33:18] [INFO] ✓ 启动设备完成
|
||||||
|
26-01-13 [21:33:18] [INFO] 组合操作完成:设备已成功初始化、确认物料搜寻、切换自动模式并启动
|
||||||
|
```
|
||||||
|
|
||||||
|
## 技术要点
|
||||||
|
|
||||||
|
### 1. 脉冲模式按钮操作
|
||||||
|
模拟真实按钮按压过程:
|
||||||
|
1. 写入 `True` (按下)
|
||||||
|
2. 保持 0.5 秒
|
||||||
|
3. 写入 `False` (释放)
|
||||||
|
4. 验证状态
|
||||||
|
|
||||||
|
### 2. 避免死锁
|
||||||
|
**问题:** PLC 在初始化过程中等待弹窗确认,而代码等待初始化完成
|
||||||
|
**解决:** 在初始化等待循环中实时检测弹窗,一旦出现立即处理
|
||||||
|
|
||||||
|
### 3. 超时保护
|
||||||
|
- 弹窗检测超时:30 秒(在 `_handle_material_search_dialog` 中)
|
||||||
|
- 初始化超时:120 秒(在 `func_pack_device_init_auto_start_combined` 中)
|
||||||
|
|
||||||
|
### 4. PyModbus 3.x API 兼容
|
||||||
|
所有 Modbus 操作使用 keyword arguments:
|
||||||
|
```python
|
||||||
|
# 读取
|
||||||
|
client.read_coils(address=5176, count=1)
|
||||||
|
|
||||||
|
# 写入
|
||||||
|
client.write_coil(address=5184, value=True)
|
||||||
|
```
|
||||||
|
|
||||||
|
## 向后兼容性
|
||||||
|
|
||||||
|
### 保留的原有函数
|
||||||
|
- `func_pack_device_init()` - 单独的初始化函数,不包含弹窗处理
|
||||||
|
- 仍可在 YAML 中通过 `auto-func_pack_device_init` 调用
|
||||||
|
- 用于不需要自动处理弹窗的场景
|
||||||
|
|
||||||
|
### 新增的功能
|
||||||
|
- 在 `func_pack_device_init_auto_start_combined()` 中集成弹窗处理
|
||||||
|
- 通过参数控制,默认行为与之前兼容(点击"否")
|
||||||
|
|
||||||
|
## 验证测试
|
||||||
|
|
||||||
|
### 测试场景
|
||||||
|
|
||||||
|
#### 场景 1:默认参数(不启用物料搜寻)
|
||||||
|
```bash
|
||||||
|
# 调用时不传参数
|
||||||
|
BatteryStation/auto-func_pack_device_init_auto_start_combined: {}
|
||||||
|
```
|
||||||
|
**预期结果:**
|
||||||
|
- ✅ 检测到弹窗
|
||||||
|
- ✅ 自动点击"否"按钮
|
||||||
|
- ✅ 初始化完成并启动成功
|
||||||
|
|
||||||
|
#### 场景 2:启用物料搜寻
|
||||||
|
```bash
|
||||||
|
# 设置 material_search_enable=true
|
||||||
|
BatteryStation/auto-func_pack_device_init_auto_start_combined:
|
||||||
|
goal:
|
||||||
|
material_search_enable: true
|
||||||
|
```
|
||||||
|
**预期结果:**
|
||||||
|
- ✅ 检测到弹窗
|
||||||
|
- ✅ 自动点击"是"按钮
|
||||||
|
- ✅ 初始化完成并启动成功
|
||||||
|
|
||||||
|
### 实际测试结果
|
||||||
|
|
||||||
|
**测试时间:** 2026-01-13 21:32:43
|
||||||
|
**测试参数:** `material_search_enable: false`
|
||||||
|
**测试结果:** ✅ 成功
|
||||||
|
|
||||||
|
**关键时间节点:**
|
||||||
|
- 21:33:05 - 检测到弹窗
|
||||||
|
- 21:33:05 - 按下"否"按钮
|
||||||
|
- 21:33:06 - 释放"否"按钮
|
||||||
|
- 21:33:07 - 弹窗处理完成
|
||||||
|
- 21:33:08 - 初始化状态完成
|
||||||
|
- 21:33:18 - 整个流程完成
|
||||||
|
|
||||||
|
**总耗时:** 约 35 秒(包含初始化全过程)
|
||||||
|
|
||||||
|
## 注意事项
|
||||||
|
|
||||||
|
1. **CSV 配置依赖**
|
||||||
|
- 确保 `coin_cell_assembly_b.csv` 包含 69-71 行的 coil 配置
|
||||||
|
- 地址转换逻辑:`modbus_addr = (csv_addr // 10) * 8 + (csv_addr % 10)`
|
||||||
|
|
||||||
|
2. **默认行为**
|
||||||
|
- 默认 `material_search_enable=false`,即不启用物料搜寻
|
||||||
|
- 如需启用,必须显式设置为 `true`
|
||||||
|
|
||||||
|
3. **日志级别**
|
||||||
|
- 弹窗检测过程中的 `waiting for init_cmd` 使用 DEBUG 级别
|
||||||
|
- 关键操作(检测到弹窗、按钮操作)使用 INFO 级别
|
||||||
|
|
||||||
|
4. **原有函数保留**
|
||||||
|
- `func_pack_device_init()` 仍然可用,但不包含弹窗处理
|
||||||
|
- 如果单独调用此函数,仍需手动处理弹窗
|
||||||
|
|
||||||
|
## 文件清单
|
||||||
|
|
||||||
|
### 修改的文件
|
||||||
|
1. `d:\UniLabdev\Uni-Lab-OS\unilabos\devices\workstation\coin_cell_assembly\coin_cell_assembly.py`
|
||||||
|
- 新增 `_handle_material_search_dialog()` 方法
|
||||||
|
- 修改 `func_pack_device_init_auto_start_combined()` 函数
|
||||||
|
|
||||||
|
2. `d:\UniLabdev\Uni-Lab-OS\unilabos\registry\devices\coin_cell_workstation.yaml`
|
||||||
|
- 更新 `auto-func_pack_device_init_auto_start_combined` 配置
|
||||||
|
- 添加 `material_search_enable` 参数说明
|
||||||
|
|
||||||
|
3. `d:\UniLabdev\Uni-Lab-OS\unilabos\devices\workstation\coin_cell_assembly\coin_cell_assembly_b.csv`
|
||||||
|
- 第 69-71 行添加三个 coil 配置
|
||||||
|
|
||||||
|
### 创建的测试文件(已删除)
|
||||||
|
1. `test_material_search_dialog.py` - 物料搜寻弹窗测试脚本
|
||||||
|
2. `test_coin_cell_reset.py` - 复位功能测试(更新为 pymodbus 3.x)
|
||||||
|
3. `test_unilab_interact.py` - Unilab 交互测试(更新为 pymodbus 3.x)
|
||||||
|
|
||||||
|
## 总结
|
||||||
|
|
||||||
|
本次更新成功实现了设备初始化过程中物料搜寻确认弹窗的自动化处理,主要优势:
|
||||||
|
|
||||||
|
✅ **全自动化** - 无需人工干预
|
||||||
|
✅ **参数可配** - 灵活控制是否启用物料搜寻
|
||||||
|
✅ **实时检测** - 在初始化等待循环中检测,避免死锁
|
||||||
|
✅ **脉冲模式** - 模拟真实按钮操作
|
||||||
|
✅ **向后兼容** - 保留原有函数,不影响现有流程
|
||||||
|
✅ **完整日志** - 详细记录每一步操作
|
||||||
|
✅ **超时保护** - 防止无限等待
|
||||||
|
|
||||||
|
该功能已通过实际测试验证,可投入生产使用。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**文档版本:** 1.0
|
||||||
|
**创建日期:** 2026-01-13
|
||||||
|
**作者:** Antigravity AI Assistant
|
||||||
|
**最后更新:** 2026-01-13 21:36
|
||||||
@@ -0,0 +1,645 @@
|
|||||||
|
"""
|
||||||
|
纽扣电池组装工作站物料类定义
|
||||||
|
Button Battery Assembly Station Resource Classes
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from collections import OrderedDict
|
||||||
|
from typing import Any, Dict, List, Optional, TypedDict, Union, cast
|
||||||
|
|
||||||
|
from pylabrobot.resources.coordinate import Coordinate
|
||||||
|
from pylabrobot.resources.container import Container
|
||||||
|
from pylabrobot.resources.deck import Deck
|
||||||
|
from pylabrobot.resources.itemized_resource import ItemizedResource
|
||||||
|
from pylabrobot.resources.resource import Resource
|
||||||
|
from pylabrobot.resources.resource_stack import ResourceStack
|
||||||
|
from pylabrobot.resources.tip_rack import TipRack, TipSpot
|
||||||
|
from pylabrobot.resources.trash import Trash
|
||||||
|
from pylabrobot.resources.utils import create_ordered_items_2d
|
||||||
|
|
||||||
|
from unilabos.resources.battery.magazine import MagazineHolder_4_Cathode, MagazineHolder_6_Cathode, MagazineHolder_6_Anode, MagazineHolder_6_Battery
|
||||||
|
from unilabos.resources.battery.bottle_carriers import YIHUA_Electrolyte_12VialCarrier
|
||||||
|
from unilabos.resources.battery.electrode_sheet import ElectrodeSheet
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: 这个应该只能放一个极片
|
||||||
|
class MaterialHoleState(TypedDict):
|
||||||
|
diameter: int
|
||||||
|
depth: int
|
||||||
|
max_sheets: int
|
||||||
|
info: Optional[str] # 附加信息
|
||||||
|
|
||||||
|
class MaterialHole(Resource):
|
||||||
|
"""料板洞位类"""
|
||||||
|
children: List[ElectrodeSheet] = []
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
name: str,
|
||||||
|
size_x: float,
|
||||||
|
size_y: float,
|
||||||
|
size_z: float,
|
||||||
|
category: str = "material_hole",
|
||||||
|
**kwargs
|
||||||
|
):
|
||||||
|
super().__init__(
|
||||||
|
name=name,
|
||||||
|
size_x=size_x,
|
||||||
|
size_y=size_y,
|
||||||
|
size_z=size_z,
|
||||||
|
category=category,
|
||||||
|
)
|
||||||
|
self._unilabos_state: MaterialHoleState = MaterialHoleState(
|
||||||
|
diameter=20,
|
||||||
|
depth=10,
|
||||||
|
max_sheets=1,
|
||||||
|
info=None
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_all_sheet_info(self):
|
||||||
|
info_list = []
|
||||||
|
for sheet in self.children:
|
||||||
|
info_list.append(sheet._unilabos_state["info"])
|
||||||
|
return info_list
|
||||||
|
|
||||||
|
#这个函数函数好像没用,一般不会集中赋值质量
|
||||||
|
def set_all_sheet_mass(self):
|
||||||
|
for sheet in self.children:
|
||||||
|
sheet._unilabos_state["mass"] = 0.5 # 示例:设置质量为0.5g
|
||||||
|
|
||||||
|
def load_state(self, state: Dict[str, Any]) -> None:
|
||||||
|
"""格式不变"""
|
||||||
|
super().load_state(state)
|
||||||
|
self._unilabos_state = state
|
||||||
|
|
||||||
|
def serialize_state(self) -> Dict[str, Dict[str, Any]]:
|
||||||
|
"""格式不变"""
|
||||||
|
data = super().serialize_state()
|
||||||
|
data.update(self._unilabos_state) # Container自身的信息,云端物料将保存这一data,本地也通过这里的data进行读写,当前类用来表示这个物料的长宽高大小的属性,而data(state用来表示物料的内容,细节等)
|
||||||
|
return data
|
||||||
|
#移动极片前先取出对象
|
||||||
|
def get_sheet_with_name(self, name: str) -> Optional[ElectrodeSheet]:
|
||||||
|
for sheet in self.children:
|
||||||
|
if sheet.name == name:
|
||||||
|
return sheet
|
||||||
|
return None
|
||||||
|
|
||||||
|
def has_electrode_sheet(self) -> bool:
|
||||||
|
"""检查洞位是否有极片"""
|
||||||
|
return len(self.children) > 0
|
||||||
|
|
||||||
|
def assign_child_resource(
|
||||||
|
self,
|
||||||
|
resource: ElectrodeSheet,
|
||||||
|
location: Optional[Coordinate],
|
||||||
|
reassign: bool = True,
|
||||||
|
):
|
||||||
|
"""放置极片"""
|
||||||
|
# TODO: 这里要改,diameter找不到,加入._unilabos_state后应该没问题
|
||||||
|
#if resource._unilabos_state["diameter"] > self._unilabos_state["diameter"]:
|
||||||
|
# raise ValueError(f"极片直径 {resource._unilabos_state['diameter']} 超过洞位直径 {self._unilabos_state['diameter']}")
|
||||||
|
#if len(self.children) >= self._unilabos_state["max_sheets"]:
|
||||||
|
# raise ValueError(f"洞位已满,无法放置更多极片")
|
||||||
|
super().assign_child_resource(resource, location, reassign)
|
||||||
|
|
||||||
|
# 根据children的编号取物料对象。
|
||||||
|
def get_electrode_sheet_info(self, index: int) -> ElectrodeSheet:
|
||||||
|
return self.children[index]
|
||||||
|
|
||||||
|
|
||||||
|
class MaterialPlateState(TypedDict):
|
||||||
|
hole_spacing_x: float
|
||||||
|
hole_spacing_y: float
|
||||||
|
hole_diameter: float
|
||||||
|
info: Optional[str] # 附加信息
|
||||||
|
|
||||||
|
class MaterialPlate(ItemizedResource[MaterialHole]):
|
||||||
|
"""料板类 - 4x4个洞位,每个洞位放1个极片"""
|
||||||
|
|
||||||
|
children: List[MaterialHole]
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
name: str,
|
||||||
|
size_x: float,
|
||||||
|
size_y: float,
|
||||||
|
size_z: float,
|
||||||
|
ordered_items: Optional[Dict[str, MaterialHole]] = None,
|
||||||
|
ordering: Optional[OrderedDict[str, str]] = None,
|
||||||
|
category: str = "material_plate",
|
||||||
|
model: Optional[str] = None,
|
||||||
|
fill: bool = False
|
||||||
|
):
|
||||||
|
"""初始化料板
|
||||||
|
|
||||||
|
Args:
|
||||||
|
name: 料板名称
|
||||||
|
size_x: 长度 (mm)
|
||||||
|
size_y: 宽度 (mm)
|
||||||
|
size_z: 高度 (mm)
|
||||||
|
hole_diameter: 洞直径 (mm)
|
||||||
|
hole_depth: 洞深度 (mm)
|
||||||
|
hole_spacing_x: X方向洞位间距 (mm)
|
||||||
|
hole_spacing_y: Y方向洞位间距 (mm)
|
||||||
|
number: 编号
|
||||||
|
category: 类别
|
||||||
|
model: 型号
|
||||||
|
"""
|
||||||
|
self._unilabos_state: MaterialPlateState = MaterialPlateState(
|
||||||
|
hole_spacing_x=24.0,
|
||||||
|
hole_spacing_y=24.0,
|
||||||
|
hole_diameter=20.0,
|
||||||
|
info="",
|
||||||
|
)
|
||||||
|
# 创建4x4的洞位
|
||||||
|
# TODO: 这里要改,对应不同形状
|
||||||
|
holes = create_ordered_items_2d(
|
||||||
|
klass=MaterialHole,
|
||||||
|
num_items_x=4,
|
||||||
|
num_items_y=4,
|
||||||
|
dx=(size_x - 4 * self._unilabos_state["hole_spacing_x"]) / 2, # 居中
|
||||||
|
dy=(size_y - 4 * self._unilabos_state["hole_spacing_y"]) / 2, # 居中
|
||||||
|
dz=size_z,
|
||||||
|
item_dx=self._unilabos_state["hole_spacing_x"],
|
||||||
|
item_dy=self._unilabos_state["hole_spacing_y"],
|
||||||
|
size_x = 16,
|
||||||
|
size_y = 16,
|
||||||
|
size_z = 16,
|
||||||
|
)
|
||||||
|
if fill:
|
||||||
|
super().__init__(
|
||||||
|
name=name,
|
||||||
|
size_x=size_x,
|
||||||
|
size_y=size_y,
|
||||||
|
size_z=size_z,
|
||||||
|
ordered_items=holes,
|
||||||
|
category=category,
|
||||||
|
model=model,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
super().__init__(
|
||||||
|
name=name,
|
||||||
|
size_x=size_x,
|
||||||
|
size_y=size_y,
|
||||||
|
size_z=size_z,
|
||||||
|
ordered_items=ordered_items,
|
||||||
|
ordering=ordering,
|
||||||
|
category=category,
|
||||||
|
model=model,
|
||||||
|
)
|
||||||
|
|
||||||
|
def update_locations(self):
|
||||||
|
# TODO:调多次相加
|
||||||
|
holes = create_ordered_items_2d(
|
||||||
|
klass=MaterialHole,
|
||||||
|
num_items_x=4,
|
||||||
|
num_items_y=4,
|
||||||
|
dx=(self._size_x - 3 * self._unilabos_state["hole_spacing_x"]) / 2, # 居中
|
||||||
|
dy=(self._size_y - 3 * self._unilabos_state["hole_spacing_y"]) / 2, # 居中
|
||||||
|
dz=self._size_z,
|
||||||
|
item_dx=self._unilabos_state["hole_spacing_x"],
|
||||||
|
item_dy=self._unilabos_state["hole_spacing_y"],
|
||||||
|
size_x = 1,
|
||||||
|
size_y = 1,
|
||||||
|
size_z = 1,
|
||||||
|
)
|
||||||
|
for item, original_item in zip(holes.items(), self.children):
|
||||||
|
original_item.location = item[1].location
|
||||||
|
|
||||||
|
|
||||||
|
class PlateSlot(ResourceStack):
|
||||||
|
"""板槽位类 - 1个槽上能堆放8个板,移板只能操作最上方的板"""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
name: str,
|
||||||
|
size_x: float,
|
||||||
|
size_y: float,
|
||||||
|
size_z: float,
|
||||||
|
max_plates: int = 8,
|
||||||
|
category: str = "plate_slot",
|
||||||
|
model: Optional[str] = None
|
||||||
|
):
|
||||||
|
"""初始化板槽位
|
||||||
|
|
||||||
|
Args:
|
||||||
|
name: 槽位名称
|
||||||
|
max_plates: 最大板数量
|
||||||
|
category: 类别
|
||||||
|
"""
|
||||||
|
super().__init__(
|
||||||
|
name=name,
|
||||||
|
direction="z", # Z方向堆叠
|
||||||
|
resources=[],
|
||||||
|
)
|
||||||
|
self.max_plates = max_plates
|
||||||
|
self.category = category
|
||||||
|
|
||||||
|
def can_add_plate(self) -> bool:
|
||||||
|
"""检查是否可以添加板"""
|
||||||
|
return len(self.children) < self.max_plates
|
||||||
|
|
||||||
|
def add_plate(self, plate: MaterialPlate) -> None:
|
||||||
|
"""添加料板"""
|
||||||
|
if not self.can_add_plate():
|
||||||
|
raise ValueError(f"槽位 {self.name} 已满,无法添加更多板")
|
||||||
|
self.assign_child_resource(plate)
|
||||||
|
|
||||||
|
def get_top_plate(self) -> MaterialPlate:
|
||||||
|
"""获取最上方的板"""
|
||||||
|
if len(self.children) == 0:
|
||||||
|
raise ValueError(f"槽位 {self.name} 为空")
|
||||||
|
return cast(MaterialPlate, self.get_top_item())
|
||||||
|
|
||||||
|
def take_top_plate(self) -> MaterialPlate:
|
||||||
|
"""取出最上方的板"""
|
||||||
|
top_plate = self.get_top_plate()
|
||||||
|
self.unassign_child_resource(top_plate)
|
||||||
|
return top_plate
|
||||||
|
|
||||||
|
def can_access_for_picking(self) -> bool:
|
||||||
|
"""检查是否可以进行取料操作(只有最上方的板能进行取料操作)"""
|
||||||
|
return len(self.children) > 0
|
||||||
|
|
||||||
|
def serialize(self) -> dict:
|
||||||
|
return {
|
||||||
|
**super().serialize(),
|
||||||
|
"max_plates": self.max_plates,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#是一种类型注解,不用self
|
||||||
|
class BatteryState(TypedDict):
|
||||||
|
"""电池状态字典"""
|
||||||
|
diameter: float
|
||||||
|
height: float
|
||||||
|
assembly_pressure: float
|
||||||
|
electrolyte_volume: float
|
||||||
|
electrolyte_name: str
|
||||||
|
|
||||||
|
class Battery(Resource):
|
||||||
|
"""电池类 - 可容纳极片"""
|
||||||
|
children: List[ElectrodeSheet] = []
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
name: str,
|
||||||
|
size_x=1,
|
||||||
|
size_y=1,
|
||||||
|
size_z=1,
|
||||||
|
category: str = "battery",
|
||||||
|
):
|
||||||
|
"""初始化电池
|
||||||
|
|
||||||
|
Args:
|
||||||
|
name: 电池名称
|
||||||
|
diameter: 直径 (mm)
|
||||||
|
height: 高度 (mm)
|
||||||
|
max_volume: 最大容量 (μL)
|
||||||
|
barcode: 二维码编号
|
||||||
|
category: 类别
|
||||||
|
model: 型号
|
||||||
|
"""
|
||||||
|
super().__init__(
|
||||||
|
name=name,
|
||||||
|
size_x=1,
|
||||||
|
size_y=1,
|
||||||
|
size_z=1,
|
||||||
|
category=category,
|
||||||
|
)
|
||||||
|
self._unilabos_state: BatteryState = BatteryState(
|
||||||
|
diameter = 1.0,
|
||||||
|
height = 1.0,
|
||||||
|
assembly_pressure = 1.0,
|
||||||
|
electrolyte_volume = 1.0,
|
||||||
|
electrolyte_name = "DP001"
|
||||||
|
)
|
||||||
|
|
||||||
|
def add_electrolyte_with_bottle(self, bottle: Bottle) -> bool:
|
||||||
|
to_add_name = bottle._unilabos_state["electrolyte_name"]
|
||||||
|
if bottle.aspirate_electrolyte(10):
|
||||||
|
if self.add_electrolyte(to_add_name, 10):
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
bottle._unilabos_state["electrolyte_volume"] += 10
|
||||||
|
|
||||||
|
def set_electrolyte(self, name: str, volume: float) -> None:
|
||||||
|
"""设置电解液信息"""
|
||||||
|
self._unilabos_state["electrolyte_name"] = name
|
||||||
|
self._unilabos_state["electrolyte_volume"] = volume
|
||||||
|
#这个应该没用,不会有加了后再加的事情
|
||||||
|
def add_electrolyte(self, name: str, volume: float) -> bool:
|
||||||
|
"""添加电解液信息"""
|
||||||
|
if name != self._unilabos_state["electrolyte_name"]:
|
||||||
|
return False
|
||||||
|
self._unilabos_state["electrolyte_volume"] += volume
|
||||||
|
|
||||||
|
def load_state(self, state: Dict[str, Any]) -> None:
|
||||||
|
"""格式不变"""
|
||||||
|
super().load_state(state)
|
||||||
|
self._unilabos_state = state
|
||||||
|
|
||||||
|
def serialize_state(self) -> Dict[str, Dict[str, Any]]:
|
||||||
|
"""格式不变"""
|
||||||
|
data = super().serialize_state()
|
||||||
|
data.update(self._unilabos_state) # Container自身的信息,云端物料将保存这一data,本地也通过这里的data进行读写,当前类用来表示这个物料的长宽高大小的属性,而data(state用来表示物料的内容,细节等)
|
||||||
|
return data
|
||||||
|
|
||||||
|
# 电解液作为属性放进去
|
||||||
|
|
||||||
|
class BatteryPressSlotState(TypedDict):
|
||||||
|
"""电池状态字典"""
|
||||||
|
diameter: float =20.0
|
||||||
|
depth: float = 4.0
|
||||||
|
|
||||||
|
class BatteryPressSlot(Resource):
|
||||||
|
"""电池压制槽类 - 设备,可容纳一个电池"""
|
||||||
|
children: List[Battery] = []
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
name: str = "BatteryPressSlot",
|
||||||
|
category: str = "battery_press_slot",
|
||||||
|
):
|
||||||
|
"""初始化电池压制槽
|
||||||
|
|
||||||
|
Args:
|
||||||
|
name: 压制槽名称
|
||||||
|
diameter: 直径 (mm)
|
||||||
|
depth: 深度 (mm)
|
||||||
|
category: 类别
|
||||||
|
model: 型号
|
||||||
|
"""
|
||||||
|
super().__init__(
|
||||||
|
name=name,
|
||||||
|
size_x=10,
|
||||||
|
size_y=12,
|
||||||
|
size_z=13,
|
||||||
|
category=category,
|
||||||
|
)
|
||||||
|
self._unilabos_state: BatteryPressSlotState = BatteryPressSlotState()
|
||||||
|
|
||||||
|
def has_battery(self) -> bool:
|
||||||
|
"""检查是否有电池"""
|
||||||
|
return len(self.children) > 0
|
||||||
|
|
||||||
|
def load_state(self, state: Dict[str, Any]) -> None:
|
||||||
|
"""格式不变"""
|
||||||
|
super().load_state(state)
|
||||||
|
self._unilabos_state = state
|
||||||
|
|
||||||
|
def serialize_state(self) -> Dict[str, Dict[str, Any]]:
|
||||||
|
"""格式不变"""
|
||||||
|
data = super().serialize_state()
|
||||||
|
data.update(self._unilabos_state) # Container自身的信息,云端物料将保存这一data,本地也通过这里的data进行读写,当前类用来表示这个物料的长宽高大小的属性,而data(state用来表示物料的内容,细节等)
|
||||||
|
return data
|
||||||
|
|
||||||
|
def assign_child_resource(
|
||||||
|
self,
|
||||||
|
resource: Battery,
|
||||||
|
location: Optional[Coordinate],
|
||||||
|
reassign: bool = True,
|
||||||
|
):
|
||||||
|
"""放置极片"""
|
||||||
|
# TODO: 让高京看下槽位只有一个电池时是否这么写。
|
||||||
|
if self.has_battery():
|
||||||
|
raise ValueError(f"槽位已含有一个电池,无法再放置其他电池")
|
||||||
|
super().assign_child_resource(resource, location, reassign)
|
||||||
|
|
||||||
|
# 根据children的编号取物料对象。
|
||||||
|
def get_battery_info(self, index: int) -> Battery:
|
||||||
|
return self.children[0]
|
||||||
|
|
||||||
|
|
||||||
|
def TipBox64(
|
||||||
|
name: str,
|
||||||
|
size_x: float = 127.8,
|
||||||
|
size_y: float = 85.5,
|
||||||
|
size_z: float = 60.0,
|
||||||
|
category: str = "tip_rack",
|
||||||
|
model: Optional[str] = None,
|
||||||
|
):
|
||||||
|
"""64孔枪头盒类"""
|
||||||
|
from pylabrobot.resources.tip import Tip
|
||||||
|
|
||||||
|
# 创建12x8=96个枪头位
|
||||||
|
def make_tip():
|
||||||
|
return Tip(
|
||||||
|
has_filter=False,
|
||||||
|
total_tip_length=20.0,
|
||||||
|
maximal_volume=1000, # 1mL
|
||||||
|
fitting_depth=8.0,
|
||||||
|
)
|
||||||
|
|
||||||
|
tip_spots = create_ordered_items_2d(
|
||||||
|
klass=TipSpot,
|
||||||
|
num_items_x=12,
|
||||||
|
num_items_y=8,
|
||||||
|
dx=8.0,
|
||||||
|
dy=8.0,
|
||||||
|
dz=0.0,
|
||||||
|
item_dx=9.0,
|
||||||
|
item_dy=9.0,
|
||||||
|
size_x=10,
|
||||||
|
size_y=10,
|
||||||
|
size_z=0.0,
|
||||||
|
make_tip=make_tip,
|
||||||
|
)
|
||||||
|
idx_available = list(range(0, 32)) + list(range(64, 96))
|
||||||
|
tip_spots_available = {k: v for i, (k, v) in enumerate(tip_spots.items()) if i in idx_available}
|
||||||
|
tip_rack = TipRack(
|
||||||
|
name=name,
|
||||||
|
size_x=size_x,
|
||||||
|
size_y=size_y,
|
||||||
|
size_z=size_z,
|
||||||
|
# ordered_items=tip_spots_available,
|
||||||
|
ordered_items=tip_spots,
|
||||||
|
category=category,
|
||||||
|
model=model,
|
||||||
|
with_tips=False,
|
||||||
|
)
|
||||||
|
tip_rack.set_tip_state([True]*32 + [False]*32 + [True]*32) # 前32和后32个有枪头,中间32个无枪头
|
||||||
|
return tip_rack
|
||||||
|
|
||||||
|
|
||||||
|
class WasteTipBoxstate(TypedDict):
|
||||||
|
""""废枪头盒状态字典"""
|
||||||
|
max_tips: int = 100
|
||||||
|
tip_count: int = 0
|
||||||
|
|
||||||
|
#枪头不是一次性的(同一溶液则反复使用),根据寄存器判断
|
||||||
|
class WasteTipBox(Trash):
|
||||||
|
"""废枪头盒类 - 100个枪头容量"""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
name: str,
|
||||||
|
size_x: float = 127.8,
|
||||||
|
size_y: float = 85.5,
|
||||||
|
size_z: float = 60.0,
|
||||||
|
material_z_thickness=0,
|
||||||
|
max_volume=float("inf"),
|
||||||
|
category="trash",
|
||||||
|
model=None,
|
||||||
|
compute_volume_from_height=None,
|
||||||
|
compute_height_from_volume=None,
|
||||||
|
):
|
||||||
|
"""初始化废枪头盒
|
||||||
|
|
||||||
|
Args:
|
||||||
|
name: 废枪头盒名称
|
||||||
|
size_x: 长度 (mm)
|
||||||
|
size_y: 宽度 (mm)
|
||||||
|
size_z: 高度 (mm)
|
||||||
|
max_tips: 最大枪头容量
|
||||||
|
category: 类别
|
||||||
|
model: 型号
|
||||||
|
"""
|
||||||
|
super().__init__(
|
||||||
|
name=name,
|
||||||
|
size_x=size_x,
|
||||||
|
size_y=size_y,
|
||||||
|
size_z=size_z,
|
||||||
|
category=category,
|
||||||
|
model=model,
|
||||||
|
)
|
||||||
|
self._unilabos_state: WasteTipBoxstate = WasteTipBoxstate()
|
||||||
|
|
||||||
|
def add_tip(self) -> None:
|
||||||
|
"""添加废枪头"""
|
||||||
|
if self._unilabos_state["tip_count"] >= self._unilabos_state["max_tips"]:
|
||||||
|
raise ValueError(f"废枪头盒 {self.name} 已满")
|
||||||
|
self._unilabos_state["tip_count"] += 1
|
||||||
|
|
||||||
|
def get_tip_count(self) -> int:
|
||||||
|
"""获取枪头数量"""
|
||||||
|
return self._unilabos_state["tip_count"]
|
||||||
|
|
||||||
|
def empty(self) -> None:
|
||||||
|
"""清空废枪头盒"""
|
||||||
|
self._unilabos_state["tip_count"] = 0
|
||||||
|
|
||||||
|
|
||||||
|
def load_state(self, state: Dict[str, Any]) -> None:
|
||||||
|
"""格式不变"""
|
||||||
|
super().load_state(state)
|
||||||
|
self._unilabos_state = state
|
||||||
|
|
||||||
|
def serialize_state(self) -> Dict[str, Dict[str, Any]]:
|
||||||
|
"""格式不变"""
|
||||||
|
data = super().serialize_state()
|
||||||
|
data.update(self._unilabos_state) # Container自身的信息,云端物料将保存这一data,本地也通过这里的data进行读写,当前类用来表示这个物料的长宽高大小的属性,而data(state用来表示物料的内容,细节等)
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
class CoincellDeck(Deck):
|
||||||
|
"""纽扣电池组装工作站台面类"""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
name: str = "coin_cell_deck",
|
||||||
|
size_x: float = 1450.0, # 1m
|
||||||
|
size_y: float = 1450.0, # 1m
|
||||||
|
size_z: float = 100.0, # 0.9m
|
||||||
|
origin: Coordinate = Coordinate(-2200, 0, 0),
|
||||||
|
category: str = "coin_cell_deck",
|
||||||
|
setup: bool = False, # 是否自动执行 setup
|
||||||
|
):
|
||||||
|
"""初始化纽扣电池组装工作站台面
|
||||||
|
|
||||||
|
Args:
|
||||||
|
name: 台面名称
|
||||||
|
size_x: 长度 (mm) - 1m
|
||||||
|
size_y: 宽度 (mm) - 1m
|
||||||
|
size_z: 高度 (mm) - 0.9m
|
||||||
|
origin: 原点坐标
|
||||||
|
category: 类别
|
||||||
|
setup: 是否自动执行 setup 配置标准布局
|
||||||
|
"""
|
||||||
|
super().__init__(
|
||||||
|
name=name,
|
||||||
|
size_x=1450.0,
|
||||||
|
size_y=1450.0,
|
||||||
|
size_z=100.0,
|
||||||
|
origin=origin,
|
||||||
|
)
|
||||||
|
if setup:
|
||||||
|
self.setup()
|
||||||
|
|
||||||
|
def setup(self) -> None:
|
||||||
|
"""设置工作站的标准布局 - 包含子弹夹、料盘、瓶架等完整配置"""
|
||||||
|
# ====================================== 子弹夹 ============================================
|
||||||
|
|
||||||
|
# 正极片(4个洞位,2x2布局)
|
||||||
|
zhengji_zip = MagazineHolder_4_Cathode("正极&铝箔弹夹")
|
||||||
|
self.assign_child_resource(zhengji_zip, Coordinate(x=402.0, y=830.0, z=0))
|
||||||
|
|
||||||
|
# 正极壳、平垫片(6个洞位,2x2+2布局)
|
||||||
|
zhengjike_zip = MagazineHolder_6_Cathode("正极壳&平垫片弹夹")
|
||||||
|
self.assign_child_resource(zhengjike_zip, Coordinate(x=566.0, y=272.0, z=0))
|
||||||
|
|
||||||
|
# 负极壳、弹垫片(6个洞位,2x2+2布局)
|
||||||
|
fujike_zip = MagazineHolder_6_Anode("负极壳&弹垫片弹夹")
|
||||||
|
self.assign_child_resource(fujike_zip, Coordinate(x=474.0, y=276.0, z=0))
|
||||||
|
|
||||||
|
# 成品弹夹(6个洞位,3x2布局)
|
||||||
|
chengpindanjia_zip = MagazineHolder_6_Battery("成品弹夹")
|
||||||
|
self.assign_child_resource(chengpindanjia_zip, Coordinate(x=260.0, y=156.0, z=0))
|
||||||
|
|
||||||
|
# ====================================== 物料板 ============================================
|
||||||
|
# 创建物料板(料盘carrier)- 4x4布局
|
||||||
|
# 负极料盘
|
||||||
|
fujiliaopan = MaterialPlate(name="负极料盘", size_x=120, size_y=100, size_z=10.0, fill=True)
|
||||||
|
self.assign_child_resource(fujiliaopan, Coordinate(x=708.0, y=794.0, z=0))
|
||||||
|
# for i in range(16):
|
||||||
|
# fujipian = ElectrodeSheet(name=f"{fujiliaopan.name}_jipian_{i}", size_x=12, size_y=12, size_z=0.1)
|
||||||
|
# fujiliaopan.children[i].assign_child_resource(fujipian, location=None)
|
||||||
|
|
||||||
|
# 隔膜料盘
|
||||||
|
gemoliaopan = MaterialPlate(name="隔膜料盘", size_x=120, size_y=100, size_z=10.0, fill=True)
|
||||||
|
self.assign_child_resource(gemoliaopan, Coordinate(x=718.0, y=918.0, z=0))
|
||||||
|
# for i in range(16):
|
||||||
|
# gemopian = ElectrodeSheet(name=f"{gemoliaopan.name}_jipian_{i}", size_x=12, size_y=12, size_z=0.1)
|
||||||
|
# gemoliaopan.children[i].assign_child_resource(gemopian, location=None)
|
||||||
|
|
||||||
|
# ====================================== 瓶架、移液枪 ============================================
|
||||||
|
# 在台面上放置 3x4 瓶架、6x2 瓶架 与 64孔移液枪头盒
|
||||||
|
# 奔耀上料5ml分液瓶小板 - 由奔曜跨站转运而来,不单独写,但是这里应该有一个堆栈用于摆放分液瓶小板
|
||||||
|
|
||||||
|
# bottle_rack_3x4 = BottleRack(
|
||||||
|
# name="bottle_rack_3x4",
|
||||||
|
# size_x=210.0,
|
||||||
|
# size_y=140.0,
|
||||||
|
# size_z=100.0,
|
||||||
|
# num_items_x=2,
|
||||||
|
# num_items_y=4,
|
||||||
|
# position_spacing=35.0,
|
||||||
|
# orientation="vertical",
|
||||||
|
# )
|
||||||
|
# self.assign_child_resource(bottle_rack_3x4, Coordinate(x=1542.0, y=717.0, z=0))
|
||||||
|
|
||||||
|
# 电解液缓存位 - 6x2布局
|
||||||
|
bottle_rack_6x2 = YIHUA_Electrolyte_12VialCarrier(name="bottle_rack_6x2")
|
||||||
|
self.assign_child_resource(bottle_rack_6x2, Coordinate(x=1050.0, y=358.0, z=0))
|
||||||
|
# 电解液回收位6x2
|
||||||
|
bottle_rack_6x2_2 = YIHUA_Electrolyte_12VialCarrier(name="bottle_rack_6x2_2")
|
||||||
|
self.assign_child_resource(bottle_rack_6x2_2, Coordinate(x=914.0, y=358.0, z=0))
|
||||||
|
|
||||||
|
tip_box = TipBox64(name="tip_box_64")
|
||||||
|
self.assign_child_resource(tip_box, Coordinate(x=782.0, y=514.0, z=0))
|
||||||
|
|
||||||
|
waste_tip_box = WasteTipBox(name="waste_tip_box")
|
||||||
|
self.assign_child_resource(waste_tip_box, Coordinate(x=778.0, y=622.0, z=0))
|
||||||
|
|
||||||
|
|
||||||
|
def YH_Deck(name=""):
|
||||||
|
cd = CoincellDeck(name=name)
|
||||||
|
cd.setup()
|
||||||
|
return cd
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
deck = create_coin_cell_deck()
|
||||||
|
print(deck)
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,133 @@
|
|||||||
|
Name,DataType,InitValue,Comment,Attribute,DeviceType,Address,
|
||||||
|
COIL_SYS_START_CMD,BOOL,,,,coil,8010,
|
||||||
|
COIL_SYS_STOP_CMD,BOOL,,,,coil,8020,
|
||||||
|
COIL_SYS_RESET_CMD,BOOL,,,,coil,8030,
|
||||||
|
COIL_SYS_HAND_CMD,BOOL,,,,coil,8040,
|
||||||
|
COIL_SYS_AUTO_CMD,BOOL,,,,coil,8050,
|
||||||
|
COIL_SYS_INIT_CMD,BOOL,,,,coil,8060,
|
||||||
|
COIL_UNILAB_SEND_MSG_SUCC_CMD,BOOL,,,,coil,8700,
|
||||||
|
COIL_UNILAB_REC_MSG_SUCC_CMD,BOOL,,,,coil,8710,unilab_rec_msg_succ_cmd
|
||||||
|
COIL_SYS_START_STATUS,BOOL,,,,coil,8210,
|
||||||
|
COIL_SYS_STOP_STATUS,BOOL,,,,coil,8220,
|
||||||
|
COIL_SYS_RESET_STATUS,BOOL,,,,coil,8230,
|
||||||
|
COIL_SYS_HAND_STATUS,BOOL,,,,coil,8240,
|
||||||
|
COIL_SYS_AUTO_STATUS,BOOL,,,,coil,8250,
|
||||||
|
COIL_SYS_INIT_STATUS,BOOL,,,,coil,8260,
|
||||||
|
COIL_REQUEST_REC_MSG_STATUS,BOOL,,,,coil,8500,
|
||||||
|
COIL_REQUEST_SEND_MSG_STATUS,BOOL,,,,coil,8510,request_send_msg_status
|
||||||
|
REG_MSG_ELECTROLYTE_USE_NUM,INT16,,,,hold_register,11000,
|
||||||
|
REG_MSG_ELECTROLYTE_NUM,INT16,,,,hold_register,11002,unilab_send_msg_electrolyte_num
|
||||||
|
REG_MSG_ELECTROLYTE_VOLUME,INT16,,,,hold_register,11004,unilab_send_msg_electrolyte_vol
|
||||||
|
REG_MSG_ASSEMBLY_TYPE,INT16,,,,hold_register,11006,unilab_send_msg_assembly_type
|
||||||
|
REG_MSG_ASSEMBLY_PRESSURE,INT16,,,,hold_register,11008,unilab_send_msg_assembly_pressure
|
||||||
|
REG_DATA_ASSEMBLY_COIN_CELL_NUM,INT16,,,,hold_register,10000,data_assembly_coin_cell_num
|
||||||
|
REG_DATA_OPEN_CIRCUIT_VOLTAGE,FLOAT32,,,,hold_register,10002,data_open_circuit_voltage
|
||||||
|
REG_DATA_AXIS_X_POS,FLOAT32,,,,hold_register,10004,
|
||||||
|
REG_DATA_AXIS_Y_POS,FLOAT32,,,,hold_register,10006,
|
||||||
|
REG_DATA_AXIS_Z_POS,FLOAT32,,,,hold_register,10008,
|
||||||
|
REG_DATA_POLE_WEIGHT,FLOAT32,,,,hold_register,10010,data_pole_weight
|
||||||
|
REG_DATA_ASSEMBLY_PER_TIME,FLOAT32,,,,hold_register,10012,data_assembly_time
|
||||||
|
REG_DATA_ASSEMBLY_PRESSURE,INT16,,,,hold_register,10014,data_assembly_pressure
|
||||||
|
REG_DATA_ELECTROLYTE_VOLUME,INT16,,,,hold_register,10016,data_electrolyte_volume
|
||||||
|
REG_DATA_COIN_NUM,INT16,,,,hold_register,10018,data_coin_num
|
||||||
|
REG_DATA_ELECTROLYTE_CODE,STRING,,,,hold_register,10020,data_electrolyte_code()
|
||||||
|
REG_DATA_COIN_CELL_CODE,STRING,,,,hold_register,10030,data_coin_cell_code()
|
||||||
|
REG_DATA_STACK_VISON_CODE,STRING,,,,hold_register,12004,data_stack_vision_code()
|
||||||
|
REG_DATA_GLOVE_BOX_PRESSURE,FLOAT32,,,,hold_register,10050,data_glove_box_pressure
|
||||||
|
REG_DATA_GLOVE_BOX_WATER_CONTENT,FLOAT32,,,,hold_register,10052,data_glove_box_water_content
|
||||||
|
REG_DATA_GLOVE_BOX_O2_CONTENT,FLOAT32,,,,hold_register,10054,data_glove_box_o2_content
|
||||||
|
UNILAB_SEND_ELECTROLYTE_BOTTLE_NUM,BOOL,,,,coil,8720,
|
||||||
|
UNILAB_RECE_ELECTROLYTE_BOTTLE_NUM,BOOL,,,,coil,8520,
|
||||||
|
REG_MSG_ELECTROLYTE_NUM_USED,INT16,,,,hold_register,496,
|
||||||
|
REG_DATA_ELECTROLYTE_USE_NUM,INT16,,,,hold_register,10000,
|
||||||
|
UNILAB_SEND_FINISHED_CMD,BOOL,,,,coil,8730,
|
||||||
|
UNILAB_RECE_FINISHED_CMD,BOOL,,,,coil,8530,
|
||||||
|
REG_DATA_ASSEMBLY_TYPE,INT16,,,,hold_register,10018,ASSEMBLY_TYPE7or8
|
||||||
|
REG_UNILAB_INTERACT,BOOL,,,,coil,8450,
|
||||||
|
,,,,,coil,8320,
|
||||||
|
COIL_ALUMINUM_FOIL,BOOL,,,,coil,8340,
|
||||||
|
REG_MSG_NE_PLATE_MATRIX,INT16,,,,hold_register,440,
|
||||||
|
REG_MSG_SEPARATOR_PLATE_MATRIX,INT16,,,,hold_register,450,
|
||||||
|
REG_MSG_TIP_BOX_MATRIX,INT16,,,,hold_register,480,
|
||||||
|
REG_MSG_NE_PLATE_NUM,INT16,,,,hold_register,443,
|
||||||
|
REG_MSG_SEPARATOR_PLATE_NUM,INT16,,,,hold_register,453,
|
||||||
|
REG_MSG_PRESS_MODE,BOOL,,,,coil,8360,
|
||||||
|
,BOOL,,,,coil,8300,
|
||||||
|
,BOOL,,,,coil,8310,
|
||||||
|
COIL_GB_L_IGNORE_CMD,BOOL,,,,coil,8320,
|
||||||
|
COIL_GB_R_IGNORE_CMD,BOOL,,,,coil,8420,
|
||||||
|
,BOOL,,,,coil,8350,
|
||||||
|
COIL_ELECTROLYTE_DUAL_DROP_MODE,BOOL,,,,coil,8370,
|
||||||
|
,BOOL,,,,coil,8380,
|
||||||
|
,BOOL,,,,coil,8390,
|
||||||
|
,BOOL,,,,coil,8400,
|
||||||
|
,BOOL,,,,coil,8410,
|
||||||
|
REG_MSG_DUAL_DROP_FIRST_VOLUME,INT16,,,,hold_register,4001,
|
||||||
|
COIL_DUAL_DROP_SUCTION_TIMING,BOOL,,,,coil,8430,
|
||||||
|
COIL_DUAL_DROP_START_TIMING,BOOL,,,,coil,8470,
|
||||||
|
REG_MSG_BATTERY_CLEAN_IGNORE,BOOL,,,,coil,8460,
|
||||||
|
COIL_MATERIAL_SEARCH_DIALOG_APPEAR,BOOL,,,,coil,6470,
|
||||||
|
COIL_MATERIAL_SEARCH_CONFIRM_YES,BOOL,,,,coil,6480,
|
||||||
|
COIL_MATERIAL_SEARCH_CONFIRM_NO,BOOL,,,,coil,6490,
|
||||||
|
COIL_ALARM_100_SYSTEM_ERROR,BOOL,,,,coil,1000,异常100-系统异常
|
||||||
|
COIL_ALARM_101_EMERGENCY_STOP,BOOL,,,,coil,1010,异常101-急停
|
||||||
|
COIL_ALARM_111_GLOVEBOX_EMERGENCY_STOP,BOOL,,,,coil,1110,异常111-手套箱急停
|
||||||
|
COIL_ALARM_112_GLOVEBOX_GRATING_BLOCKED,BOOL,,,,coil,1120,异常112-手套箱内光栅遮挡
|
||||||
|
COIL_ALARM_160_PIPETTE_TIP_SHORTAGE,BOOL,,,,coil,1600,异常160-移液枪头缺料
|
||||||
|
COIL_ALARM_161_POSITIVE_SHELL_SHORTAGE,BOOL,,,,coil,1610,异常161-正极壳缺料
|
||||||
|
COIL_ALARM_162_ALUMINUM_FOIL_SHORTAGE,BOOL,,,,coil,1620,异常162-铝箔垫缺料
|
||||||
|
COIL_ALARM_163_POSITIVE_PLATE_SHORTAGE,BOOL,,,,coil,1630,异常163-正极片缺料
|
||||||
|
COIL_ALARM_164_SEPARATOR_SHORTAGE,BOOL,,,,coil,1640,异常164-隔膜缺料
|
||||||
|
COIL_ALARM_165_NEGATIVE_PLATE_SHORTAGE,BOOL,,,,coil,1650,异常165-负极片缺料
|
||||||
|
COIL_ALARM_166_FLAT_WASHER_SHORTAGE,BOOL,,,,coil,1660,异常166-平垫缺料
|
||||||
|
COIL_ALARM_167_SPRING_WASHER_SHORTAGE,BOOL,,,,coil,1670,异常167-弹垫缺料
|
||||||
|
COIL_ALARM_168_NEGATIVE_SHELL_SHORTAGE,BOOL,,,,coil,1680,异常168-负极壳缺料
|
||||||
|
COIL_ALARM_169_FINISHED_BATTERY_FULL,BOOL,,,,coil,1690,异常169-成品电池满料
|
||||||
|
COIL_ALARM_201_SERVO_AXIS_01_ERROR,BOOL,,,,coil,2010,异常201-伺服轴01异常
|
||||||
|
COIL_ALARM_202_SERVO_AXIS_02_ERROR,BOOL,,,,coil,2020,异常202-伺服轴02异常
|
||||||
|
COIL_ALARM_203_SERVO_AXIS_03_ERROR,BOOL,,,,coil,2030,异常203-伺服轴03异常
|
||||||
|
COIL_ALARM_204_SERVO_AXIS_04_ERROR,BOOL,,,,coil,2040,异常204-伺服轴04异常
|
||||||
|
COIL_ALARM_205_SERVO_AXIS_05_ERROR,BOOL,,,,coil,2050,异常205-伺服轴05异常
|
||||||
|
COIL_ALARM_206_SERVO_AXIS_06_ERROR,BOOL,,,,coil,2060,异常206-伺服轴06异常
|
||||||
|
COIL_ALARM_207_SERVO_AXIS_07_ERROR,BOOL,,,,coil,2070,异常207-伺服轴07异常
|
||||||
|
COIL_ALARM_208_SERVO_AXIS_08_ERROR,BOOL,,,,coil,2080,异常208-伺服轴08异常
|
||||||
|
COIL_ALARM_209_SERVO_AXIS_09_ERROR,BOOL,,,,coil,2090,异常209-伺服轴09异常
|
||||||
|
COIL_ALARM_210_SERVO_AXIS_10_ERROR,BOOL,,,,coil,2100,异常210-伺服轴10异常
|
||||||
|
COIL_ALARM_211_SERVO_AXIS_11_ERROR,BOOL,,,,coil,2110,异常211-伺服轴11异常
|
||||||
|
COIL_ALARM_212_SERVO_AXIS_12_ERROR,BOOL,,,,coil,2120,异常212-伺服轴12异常
|
||||||
|
COIL_ALARM_213_SERVO_AXIS_13_ERROR,BOOL,,,,coil,2130,异常213-伺服轴13异常
|
||||||
|
COIL_ALARM_214_SERVO_AXIS_14_ERROR,BOOL,,,,coil,2140,异常214-伺服轴14异常
|
||||||
|
COIL_ALARM_250_OTHER_COMPONENT_ERROR,BOOL,,,,coil,2500,异常250-其他元件异常
|
||||||
|
COIL_ALARM_251_PIPETTE_COMM_ERROR,BOOL,,,,coil,2510,异常251-移液枪通讯异常
|
||||||
|
COIL_ALARM_252_PIPETTE_ALARM,BOOL,,,,coil,2520,异常252-移液枪报警
|
||||||
|
COIL_ALARM_256_ELECTRIC_GRIPPER_ERROR,BOOL,,,,coil,2560,异常256-电爪异常
|
||||||
|
COIL_ALARM_262_RB_UNKNOWN_POSITION_ERROR,BOOL,,,,coil,2620,异常262-RB报警:未知点位错误
|
||||||
|
COIL_ALARM_263_RB_XYZ_PARAM_LIMIT_ERROR,BOOL,,,,coil,2630,异常263-RB报警:X、Y、Z参数超限制
|
||||||
|
COIL_ALARM_264_RB_VISION_PARAM_ERROR,BOOL,,,,coil,2640,异常264-RB报警:视觉参数误差过大
|
||||||
|
COIL_ALARM_265_RB_NOZZLE_1_PICK_FAIL,BOOL,,,,coil,2650,异常265-RB报警:1#吸嘴取料失败
|
||||||
|
COIL_ALARM_266_RB_NOZZLE_2_PICK_FAIL,BOOL,,,,coil,2660,异常266-RB报警:2#吸嘴取料失败
|
||||||
|
COIL_ALARM_267_RB_NOZZLE_3_PICK_FAIL,BOOL,,,,coil,2670,异常267-RB报警:3#吸嘴取料失败
|
||||||
|
COIL_ALARM_268_RB_NOZZLE_4_PICK_FAIL,BOOL,,,,coil,2680,异常268-RB报警:4#吸嘴取料失败
|
||||||
|
COIL_ALARM_269_RB_TRAY_PICK_FAIL,BOOL,,,,coil,2690,异常269-RB报警:取物料盘失败
|
||||||
|
COIL_ALARM_280_RB_COLLISION_ERROR,BOOL,,,,coil,2800,异常280-RB碰撞异常
|
||||||
|
COIL_ALARM_290_VISION_SYSTEM_COMM_ERROR,BOOL,,,,coil,2900,异常290-视觉系统通讯异常
|
||||||
|
COIL_ALARM_291_VISION_ALIGNMENT_NG,BOOL,,,,coil,2910,异常291-视觉对位NG异常
|
||||||
|
COIL_ALARM_292_BARCODE_SCANNER_COMM_ERROR,BOOL,,,,coil,2920,异常292-扫码枪通讯异常
|
||||||
|
COIL_ALARM_310_OCV_TRANSFER_NOZZLE_SUCTION_ERROR,BOOL,,,,coil,3100,异常310-开电移载吸嘴吸真空异常
|
||||||
|
COIL_ALARM_311_OCV_TRANSFER_NOZZLE_BREAK_ERROR,BOOL,,,,coil,3110,异常311-开电移载吸嘴破真空异常
|
||||||
|
COIL_ALARM_312_WEIGHT_TRANSFER_NOZZLE_SUCTION_ERROR,BOOL,,,,coil,3120,异常312-称重移载吸嘴吸真空异常
|
||||||
|
COIL_ALARM_313_WEIGHT_TRANSFER_NOZZLE_BREAK_ERROR,BOOL,,,,coil,3130,异常313-称重移载吸嘴破真空异常
|
||||||
|
COIL_ALARM_340_OCV_NOZZLE_TRANSFER_CYLINDER_ERROR,BOOL,,,,coil,3400,异常340-开路电压吸嘴移载气缸异常
|
||||||
|
COIL_ALARM_342_OCV_NOZZLE_LIFT_CYLINDER_ERROR,BOOL,,,,coil,3420,异常342-开路电压吸嘴升降气缸异常
|
||||||
|
COIL_ALARM_344_OCV_CRIMPING_CYLINDER_ERROR,BOOL,,,,coil,3440,异常344-开路电压旋压气缸异常
|
||||||
|
COIL_ALARM_350_WEIGHT_NOZZLE_TRANSFER_CYLINDER_ERROR,BOOL,,,,coil,3500,异常350-称重吸嘴移载气缸异常
|
||||||
|
COIL_ALARM_352_WEIGHT_NOZZLE_LIFT_CYLINDER_ERROR,BOOL,,,,coil,3520,异常352-称重吸嘴升降气缸异常
|
||||||
|
COIL_ALARM_354_CLEANING_CLOTH_TRANSFER_CYLINDER_ERROR,BOOL,,,,coil,3540,异常354-清洗无尘布移载气缸异常
|
||||||
|
COIL_ALARM_356_CLEANING_CLOTH_PRESS_CYLINDER_ERROR,BOOL,,,,coil,3560,异常356-清洗无尘布压紧气缸异常
|
||||||
|
COIL_ALARM_360_ELECTROLYTE_BOTTLE_POSITION_CYLINDER_ERROR,BOOL,,,,coil,3600,异常360-电解液瓶定位气缸异常
|
||||||
|
COIL_ALARM_362_PIPETTE_TIP_BOX_POSITION_CYLINDER_ERROR,BOOL,,,,coil,3620,异常362-移液枪头盒定位气缸异常
|
||||||
|
COIL_ALARM_364_REAGENT_BOTTLE_GRIPPER_LIFT_CYLINDER_ERROR,BOOL,,,,coil,3640,异常364-试剂瓶夹爪升降气缸异常
|
||||||
|
COIL_ALARM_366_REAGENT_BOTTLE_GRIPPER_CYLINDER_ERROR,BOOL,,,,coil,3660,异常366-试剂瓶夹爪气缸异常
|
||||||
|
COIL_ALARM_370_PRESS_MODULE_BLOW_CYLINDER_ERROR,BOOL,,,,coil,3700,异常370-压制模块吹气气缸异常
|
||||||
|
COIL_ALARM_151_ELECTROLYTE_BOTTLE_POSITION_ERROR,BOOL,,,,coil,1510,异常151-电解液瓶定位在籍异常
|
||||||
|
COIL_ALARM_152_ELECTROLYTE_BOTTLE_CAP_ERROR,BOOL,,,,coil,1520,异常152-电解液瓶盖在籍异常
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -459,12 +459,12 @@ class WorkstationHTTPHandler(BaseHTTPRequestHandler):
|
|||||||
# 验证必需字段
|
# 验证必需字段
|
||||||
if 'brand' in request_data:
|
if 'brand' in request_data:
|
||||||
if request_data['brand'] == "bioyond": # 奔曜
|
if request_data['brand'] == "bioyond": # 奔曜
|
||||||
error_msg = request_data["text"]
|
material_data = request_data["text"]
|
||||||
logger.info(f"收到奔曜错误处理报送: {error_msg}")
|
logger.info(f"收到奔曜物料变更报送: {material_data}")
|
||||||
return HttpResponse(
|
return HttpResponse(
|
||||||
success=True,
|
success=True,
|
||||||
message=f"错误处理报送已收到: {error_msg}",
|
message=f"物料变更报送已收到: {material_data}",
|
||||||
acknowledgment_id=f"ERROR_{int(time.time() * 1000)}_{error_msg.get('action_id', 'unknown')}",
|
acknowledgment_id=f"MATERIAL_{int(time.time() * 1000)}_{material_data.get('id', 'unknown')}",
|
||||||
data=None
|
data=None
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
# PRCXI 耗材管理 Web 应用
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
"""启动入口: python -m unilabos.labware_manager"""
|
|
||||||
from unilabos.labware_manager.app import main
|
|
||||||
|
|
||||||
main()
|
|
||||||
@@ -1,196 +0,0 @@
|
|||||||
"""FastAPI 应用 + CRUD API + 启动入口。
|
|
||||||
|
|
||||||
用法: python -m unilabos.labware_manager.app
|
|
||||||
"""
|
|
||||||
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import json
|
|
||||||
import os
|
|
||||||
from pathlib import Path
|
|
||||||
from typing import List, Optional
|
|
||||||
|
|
||||||
from fastapi import FastAPI, HTTPException, Query, Request
|
|
||||||
from fastapi.responses import HTMLResponse, JSONResponse
|
|
||||||
from fastapi.staticfiles import StaticFiles
|
|
||||||
from fastapi.templating import Jinja2Templates
|
|
||||||
|
|
||||||
from unilabos.labware_manager.models import LabwareDB, LabwareItem
|
|
||||||
|
|
||||||
_HERE = Path(__file__).resolve().parent
|
|
||||||
_DB_PATH = _HERE / "labware_db.json"
|
|
||||||
|
|
||||||
app = FastAPI(title="PRCXI 耗材管理", version="1.0")
|
|
||||||
|
|
||||||
# 静态文件 + 模板
|
|
||||||
app.mount("/static", StaticFiles(directory=str(_HERE / "static")), name="static")
|
|
||||||
templates = Jinja2Templates(directory=str(_HERE / "templates"))
|
|
||||||
|
|
||||||
|
|
||||||
# ---------- DB 读写 ----------
|
|
||||||
|
|
||||||
def _load_db() -> LabwareDB:
|
|
||||||
if not _DB_PATH.exists():
|
|
||||||
return LabwareDB()
|
|
||||||
with open(_DB_PATH, "r", encoding="utf-8") as f:
|
|
||||||
return LabwareDB(**json.load(f))
|
|
||||||
|
|
||||||
|
|
||||||
def _save_db(db: LabwareDB) -> None:
|
|
||||||
with open(_DB_PATH, "w", encoding="utf-8") as f:
|
|
||||||
json.dump(db.model_dump(), f, ensure_ascii=False, indent=2)
|
|
||||||
|
|
||||||
|
|
||||||
# ---------- 页面路由 ----------
|
|
||||||
|
|
||||||
@app.get("/", response_class=HTMLResponse)
|
|
||||||
async def index_page(request: Request):
|
|
||||||
db = _load_db()
|
|
||||||
# 按 type 分组
|
|
||||||
groups = {}
|
|
||||||
for item in db.items:
|
|
||||||
groups.setdefault(item.type, []).append(item)
|
|
||||||
return templates.TemplateResponse("index.html", {
|
|
||||||
"request": request,
|
|
||||||
"groups": groups,
|
|
||||||
"total": len(db.items),
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
@app.get("/labware/new", response_class=HTMLResponse)
|
|
||||||
async def new_page(request: Request, type: str = "plate"):
|
|
||||||
return templates.TemplateResponse("edit.html", {
|
|
||||||
"request": request,
|
|
||||||
"item": None,
|
|
||||||
"labware_type": type,
|
|
||||||
"is_new": True,
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
@app.get("/labware/{item_id}", response_class=HTMLResponse)
|
|
||||||
async def detail_page(request: Request, item_id: str):
|
|
||||||
db = _load_db()
|
|
||||||
item = _find_item(db, item_id)
|
|
||||||
if not item:
|
|
||||||
raise HTTPException(404, "耗材不存在")
|
|
||||||
return templates.TemplateResponse("detail.html", {
|
|
||||||
"request": request,
|
|
||||||
"item": item,
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
@app.get("/labware/{item_id}/edit", response_class=HTMLResponse)
|
|
||||||
async def edit_page(request: Request, item_id: str):
|
|
||||||
db = _load_db()
|
|
||||||
item = _find_item(db, item_id)
|
|
||||||
if not item:
|
|
||||||
raise HTTPException(404, "耗材不存在")
|
|
||||||
return templates.TemplateResponse("edit.html", {
|
|
||||||
"request": request,
|
|
||||||
"item": item,
|
|
||||||
"labware_type": item.type,
|
|
||||||
"is_new": False,
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
# ---------- API 端点 ----------
|
|
||||||
|
|
||||||
@app.get("/api/labware")
|
|
||||||
async def api_list_labware():
|
|
||||||
db = _load_db()
|
|
||||||
return {"items": [item.model_dump() for item in db.items]}
|
|
||||||
|
|
||||||
|
|
||||||
@app.post("/api/labware")
|
|
||||||
async def api_create_labware(request: Request):
|
|
||||||
data = await request.json()
|
|
||||||
db = _load_db()
|
|
||||||
item = LabwareItem(**data)
|
|
||||||
# 确保 id 唯一
|
|
||||||
existing_ids = {it.id for it in db.items}
|
|
||||||
while item.id in existing_ids:
|
|
||||||
import uuid
|
|
||||||
item.id = uuid.uuid4().hex[:8]
|
|
||||||
db.items.append(item)
|
|
||||||
_save_db(db)
|
|
||||||
return {"status": "ok", "id": item.id}
|
|
||||||
|
|
||||||
|
|
||||||
@app.put("/api/labware/{item_id}")
|
|
||||||
async def api_update_labware(item_id: str, request: Request):
|
|
||||||
data = await request.json()
|
|
||||||
db = _load_db()
|
|
||||||
for i, it in enumerate(db.items):
|
|
||||||
if it.id == item_id or it.function_name == item_id:
|
|
||||||
updated = LabwareItem(**{**it.model_dump(), **data, "id": it.id})
|
|
||||||
db.items[i] = updated
|
|
||||||
_save_db(db)
|
|
||||||
return {"status": "ok", "id": it.id}
|
|
||||||
raise HTTPException(404, "耗材不存在")
|
|
||||||
|
|
||||||
|
|
||||||
@app.delete("/api/labware/{item_id}")
|
|
||||||
async def api_delete_labware(item_id: str):
|
|
||||||
db = _load_db()
|
|
||||||
original_len = len(db.items)
|
|
||||||
db.items = [it for it in db.items if it.id != item_id and it.function_name != item_id]
|
|
||||||
if len(db.items) == original_len:
|
|
||||||
raise HTTPException(404, "耗材不存在")
|
|
||||||
_save_db(db)
|
|
||||||
return {"status": "ok"}
|
|
||||||
|
|
||||||
|
|
||||||
@app.post("/api/generate-code")
|
|
||||||
async def api_generate_code(request: Request):
|
|
||||||
body = await request.json() if await request.body() else {}
|
|
||||||
test_mode = body.get("test_mode", True)
|
|
||||||
db = _load_db()
|
|
||||||
if not db.items:
|
|
||||||
raise HTTPException(400, "数据库为空,请先导入")
|
|
||||||
|
|
||||||
from unilabos.labware_manager.codegen import generate_code
|
|
||||||
from unilabos.labware_manager.yaml_gen import generate_yaml
|
|
||||||
|
|
||||||
py_path = generate_code(db, test_mode=test_mode)
|
|
||||||
yaml_paths = generate_yaml(db, test_mode=test_mode)
|
|
||||||
|
|
||||||
return {
|
|
||||||
"status": "ok",
|
|
||||||
"python_file": str(py_path),
|
|
||||||
"yaml_files": [str(p) for p in yaml_paths],
|
|
||||||
"test_mode": test_mode,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@app.post("/api/import-from-code")
|
|
||||||
async def api_import_from_code():
|
|
||||||
from unilabos.labware_manager.importer import import_from_code, save_db
|
|
||||||
db = import_from_code()
|
|
||||||
save_db(db)
|
|
||||||
return {
|
|
||||||
"status": "ok",
|
|
||||||
"count": len(db.items),
|
|
||||||
"items": [{"function_name": it.function_name, "type": it.type} for it in db.items],
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# ---------- 辅助函数 ----------
|
|
||||||
|
|
||||||
def _find_item(db: LabwareDB, item_id: str) -> Optional[LabwareItem]:
|
|
||||||
for item in db.items:
|
|
||||||
if item.id == item_id or item.function_name == item_id:
|
|
||||||
return item
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
# ---------- 启动入口 ----------
|
|
||||||
|
|
||||||
def main():
|
|
||||||
import uvicorn
|
|
||||||
port = int(os.environ.get("LABWARE_PORT", "8010"))
|
|
||||||
print(f"PRCXI 耗材管理 → http://localhost:{port}")
|
|
||||||
uvicorn.run(app, host="0.0.0.0", port=port)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
@@ -1,451 +0,0 @@
|
|||||||
"""JSON → prcxi_labware.py 代码生成。
|
|
||||||
|
|
||||||
读取 labware_db.json,输出完整的 prcxi_labware.py(或 prcxi_labware_test.py)。
|
|
||||||
"""
|
|
||||||
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import shutil
|
|
||||||
from pathlib import Path
|
|
||||||
from typing import List, Optional
|
|
||||||
|
|
||||||
from unilabos.labware_manager.models import LabwareDB, LabwareItem
|
|
||||||
|
|
||||||
_TARGET_DIR = Path(__file__).resolve().parents[1] / "devices" / "liquid_handling" / "prcxi"
|
|
||||||
|
|
||||||
# ---------- 固定头部 ----------
|
|
||||||
_HEADER = '''\
|
|
||||||
from typing import Any, Callable, Dict, List, Optional, Tuple
|
|
||||||
from pylabrobot.resources import Tube, Coordinate
|
|
||||||
from pylabrobot.resources.well import Well, WellBottomType, CrossSectionType
|
|
||||||
from pylabrobot.resources.tip import Tip, TipCreator
|
|
||||||
from pylabrobot.resources.tip_rack import TipRack, TipSpot
|
|
||||||
from pylabrobot.resources.utils import create_ordered_items_2d
|
|
||||||
from pylabrobot.resources.height_volume_functions import (
|
|
||||||
compute_height_from_volume_rectangle,
|
|
||||||
compute_volume_from_height_rectangle,
|
|
||||||
)
|
|
||||||
|
|
||||||
from .prcxi import PRCXI9300Plate, PRCXI9300TipRack, PRCXI9300Trash, PRCXI9300TubeRack, PRCXI9300PlateAdapter
|
|
||||||
|
|
||||||
def _make_tip_helper(volume: float, length: float, depth: float) -> Tip:
|
|
||||||
"""
|
|
||||||
PLR 的 Tip 类参数名为: maximal_volume, total_tip_length, fitting_depth
|
|
||||||
"""
|
|
||||||
return Tip(
|
|
||||||
has_filter=False, # 默认无滤芯
|
|
||||||
maximal_volume=volume,
|
|
||||||
total_tip_length=length,
|
|
||||||
fitting_depth=depth
|
|
||||||
)
|
|
||||||
|
|
||||||
'''
|
|
||||||
|
|
||||||
|
|
||||||
def _gen_plate(item: LabwareItem) -> str:
|
|
||||||
"""生成 Plate 类型的工厂函数代码。"""
|
|
||||||
lines = []
|
|
||||||
fn = item.function_name
|
|
||||||
doc = item.docstring or f"Code: {item.material_info.Code}"
|
|
||||||
|
|
||||||
has_vf = item.volume_functions is not None
|
|
||||||
|
|
||||||
if has_vf:
|
|
||||||
# 有 volume_functions 时需要 well_kwargs 方式
|
|
||||||
vf = item.volume_functions
|
|
||||||
well = item.well
|
|
||||||
grid = item.grid
|
|
||||||
|
|
||||||
lines.append(f'def {fn}(name: str) -> PRCXI9300Plate:')
|
|
||||||
lines.append(f' """')
|
|
||||||
for dl in doc.split('\n'):
|
|
||||||
lines.append(f' {dl}')
|
|
||||||
lines.append(f' """')
|
|
||||||
|
|
||||||
# 计算 well_size 变量
|
|
||||||
lines.append(f' well_size_x = {well.size_x}')
|
|
||||||
lines.append(f' well_size_y = {well.size_y}')
|
|
||||||
|
|
||||||
lines.append(f' well_kwargs = {{')
|
|
||||||
lines.append(f' "size_x": well_size_x,')
|
|
||||||
lines.append(f' "size_y": well_size_y,')
|
|
||||||
lines.append(f' "size_z": {well.size_z},')
|
|
||||||
lines.append(f' "bottom_type": WellBottomType.{well.bottom_type},')
|
|
||||||
if well.cross_section_type and well.cross_section_type != "CIRCLE":
|
|
||||||
lines.append(f' "cross_section_type": CrossSectionType.{well.cross_section_type},')
|
|
||||||
lines.append(f' "compute_height_from_volume": lambda liquid_volume: compute_height_from_volume_rectangle(')
|
|
||||||
lines.append(f' liquid_volume=liquid_volume, well_length=well_size_x, well_width=well_size_y')
|
|
||||||
lines.append(f' ),')
|
|
||||||
lines.append(f' "compute_volume_from_height": lambda liquid_height: compute_volume_from_height_rectangle(')
|
|
||||||
lines.append(f' liquid_height=liquid_height, well_length=well_size_x, well_width=well_size_y')
|
|
||||||
lines.append(f' ),')
|
|
||||||
if well.material_z_thickness is not None:
|
|
||||||
lines.append(f' "material_z_thickness": {well.material_z_thickness},')
|
|
||||||
lines.append(f' }}')
|
|
||||||
lines.append(f'')
|
|
||||||
lines.append(f' return PRCXI9300Plate(')
|
|
||||||
lines.append(f' name=name,')
|
|
||||||
lines.append(f' size_x={item.size_x},')
|
|
||||||
lines.append(f' size_y={item.size_y},')
|
|
||||||
lines.append(f' size_z={item.size_z},')
|
|
||||||
lines.append(f' lid=None,')
|
|
||||||
lines.append(f' model="{item.model}",')
|
|
||||||
lines.append(f' category="plate",')
|
|
||||||
lines.append(f' material_info={_fmt_dict(item.material_info.model_dump(exclude_none=True))},')
|
|
||||||
lines.append(f' ordered_items=create_ordered_items_2d(')
|
|
||||||
lines.append(f' Well,')
|
|
||||||
lines.append(f' num_items_x={grid.num_items_x},')
|
|
||||||
lines.append(f' num_items_y={grid.num_items_y},')
|
|
||||||
lines.append(f' dx={grid.dx},')
|
|
||||||
lines.append(f' dy={grid.dy},')
|
|
||||||
lines.append(f' dz={grid.dz},')
|
|
||||||
lines.append(f' item_dx={grid.item_dx},')
|
|
||||||
lines.append(f' item_dy={grid.item_dy},')
|
|
||||||
lines.append(f' **well_kwargs,')
|
|
||||||
lines.append(f' ),')
|
|
||||||
lines.append(f' )')
|
|
||||||
else:
|
|
||||||
# 普通 plate
|
|
||||||
well = item.well
|
|
||||||
grid = item.grid
|
|
||||||
|
|
||||||
lines.append(f'def {fn}(name: str) -> PRCXI9300Plate:')
|
|
||||||
lines.append(f' """')
|
|
||||||
for dl in doc.split('\n'):
|
|
||||||
lines.append(f' {dl}')
|
|
||||||
lines.append(f' """')
|
|
||||||
lines.append(f' return PRCXI9300Plate(')
|
|
||||||
lines.append(f' name=name,')
|
|
||||||
lines.append(f' size_x={item.size_x},')
|
|
||||||
lines.append(f' size_y={item.size_y},')
|
|
||||||
lines.append(f' size_z={item.size_z},')
|
|
||||||
if item.plate_type:
|
|
||||||
lines.append(f' plate_type="{item.plate_type}",')
|
|
||||||
lines.append(f' model="{item.model}",')
|
|
||||||
lines.append(f' category="plate",')
|
|
||||||
lines.append(f' material_info={_fmt_dict(item.material_info.model_dump(exclude_none=True))},')
|
|
||||||
if grid and well:
|
|
||||||
lines.append(f' ordered_items=create_ordered_items_2d(')
|
|
||||||
lines.append(f' Well,')
|
|
||||||
lines.append(f' num_items_x={grid.num_items_x},')
|
|
||||||
lines.append(f' num_items_y={grid.num_items_y},')
|
|
||||||
lines.append(f' dx={grid.dx},')
|
|
||||||
lines.append(f' dy={grid.dy},')
|
|
||||||
lines.append(f' dz={grid.dz},')
|
|
||||||
lines.append(f' item_dx={grid.item_dx},')
|
|
||||||
lines.append(f' item_dy={grid.item_dy},')
|
|
||||||
lines.append(f' size_x={well.size_x},')
|
|
||||||
lines.append(f' size_y={well.size_y},')
|
|
||||||
lines.append(f' size_z={well.size_z},')
|
|
||||||
if well.max_volume is not None:
|
|
||||||
lines.append(f' max_volume={well.max_volume},')
|
|
||||||
if well.material_z_thickness is not None:
|
|
||||||
lines.append(f' material_z_thickness={well.material_z_thickness},')
|
|
||||||
if well.bottom_type and well.bottom_type != "FLAT":
|
|
||||||
lines.append(f' bottom_type=WellBottomType.{well.bottom_type},')
|
|
||||||
if well.cross_section_type:
|
|
||||||
lines.append(f' cross_section_type=CrossSectionType.{well.cross_section_type},')
|
|
||||||
lines.append(f' ),')
|
|
||||||
lines.append(f' )')
|
|
||||||
|
|
||||||
return '\n'.join(lines)
|
|
||||||
|
|
||||||
|
|
||||||
def _gen_tip_rack(item: LabwareItem) -> str:
|
|
||||||
"""生成 TipRack 工厂函数代码。"""
|
|
||||||
lines = []
|
|
||||||
fn = item.function_name
|
|
||||||
doc = item.docstring or f"Code: {item.material_info.Code}"
|
|
||||||
grid = item.grid
|
|
||||||
tip = item.tip
|
|
||||||
|
|
||||||
lines.append(f'def {fn}(name: str) -> PRCXI9300TipRack:')
|
|
||||||
lines.append(f' """')
|
|
||||||
for dl in doc.split('\n'):
|
|
||||||
lines.append(f' {dl}')
|
|
||||||
lines.append(f' """')
|
|
||||||
lines.append(f' return PRCXI9300TipRack(')
|
|
||||||
lines.append(f' name=name,')
|
|
||||||
lines.append(f' size_x={item.size_x},')
|
|
||||||
lines.append(f' size_y={item.size_y},')
|
|
||||||
lines.append(f' size_z={item.size_z},')
|
|
||||||
lines.append(f' model="{item.model}",')
|
|
||||||
lines.append(f' material_info={_fmt_dict(item.material_info.model_dump(exclude_none=True))},')
|
|
||||||
if grid and tip:
|
|
||||||
lines.append(f' ordered_items=create_ordered_items_2d(')
|
|
||||||
lines.append(f' TipSpot,')
|
|
||||||
lines.append(f' num_items_x={grid.num_items_x},')
|
|
||||||
lines.append(f' num_items_y={grid.num_items_y},')
|
|
||||||
lines.append(f' dx={grid.dx},')
|
|
||||||
lines.append(f' dy={grid.dy},')
|
|
||||||
lines.append(f' dz={grid.dz},')
|
|
||||||
lines.append(f' item_dx={grid.item_dx},')
|
|
||||||
lines.append(f' item_dy={grid.item_dy},')
|
|
||||||
lines.append(f' size_x={tip.spot_size_x},')
|
|
||||||
lines.append(f' size_y={tip.spot_size_y},')
|
|
||||||
lines.append(f' size_z={tip.spot_size_z},')
|
|
||||||
lines.append(f' make_tip=lambda: _make_tip_helper(volume={tip.tip_volume}, length={tip.tip_length}, depth={tip.tip_fitting_depth})')
|
|
||||||
lines.append(f' )')
|
|
||||||
lines.append(f' )')
|
|
||||||
|
|
||||||
return '\n'.join(lines)
|
|
||||||
|
|
||||||
|
|
||||||
def _gen_trash(item: LabwareItem) -> str:
|
|
||||||
"""生成 Trash 工厂函数代码。"""
|
|
||||||
lines = []
|
|
||||||
fn = item.function_name
|
|
||||||
doc = item.docstring or f"Code: {item.material_info.Code}"
|
|
||||||
|
|
||||||
lines.append(f'def {fn}(name: str = "trash") -> PRCXI9300Trash:')
|
|
||||||
lines.append(f' """')
|
|
||||||
for dl in doc.split('\n'):
|
|
||||||
lines.append(f' {dl}')
|
|
||||||
lines.append(f' """')
|
|
||||||
lines.append(f' return PRCXI9300Trash(')
|
|
||||||
lines.append(f' name="trash",')
|
|
||||||
lines.append(f' size_x={item.size_x},')
|
|
||||||
lines.append(f' size_y={item.size_y},')
|
|
||||||
lines.append(f' size_z={item.size_z},')
|
|
||||||
lines.append(f' category="trash",')
|
|
||||||
lines.append(f' model="{item.model}",')
|
|
||||||
lines.append(f' material_info={_fmt_dict(item.material_info.model_dump(exclude_none=True))}')
|
|
||||||
lines.append(f' )')
|
|
||||||
|
|
||||||
return '\n'.join(lines)
|
|
||||||
|
|
||||||
|
|
||||||
def _gen_tube_rack(item: LabwareItem) -> str:
|
|
||||||
"""生成 TubeRack 工厂函数代码。"""
|
|
||||||
lines = []
|
|
||||||
fn = item.function_name
|
|
||||||
doc = item.docstring or f"Code: {item.material_info.Code}"
|
|
||||||
grid = item.grid
|
|
||||||
tube = item.tube
|
|
||||||
|
|
||||||
lines.append(f'def {fn}(name: str) -> PRCXI9300TubeRack:')
|
|
||||||
lines.append(f' """')
|
|
||||||
for dl in doc.split('\n'):
|
|
||||||
lines.append(f' {dl}')
|
|
||||||
lines.append(f' """')
|
|
||||||
lines.append(f' return PRCXI9300TubeRack(')
|
|
||||||
lines.append(f' name=name,')
|
|
||||||
lines.append(f' size_x={item.size_x},')
|
|
||||||
lines.append(f' size_y={item.size_y},')
|
|
||||||
lines.append(f' size_z={item.size_z},')
|
|
||||||
lines.append(f' model="{item.model}",')
|
|
||||||
lines.append(f' category="tube_rack",')
|
|
||||||
lines.append(f' material_info={_fmt_dict(item.material_info.model_dump(exclude_none=True))},')
|
|
||||||
if grid and tube:
|
|
||||||
lines.append(f' ordered_items=create_ordered_items_2d(')
|
|
||||||
lines.append(f' Tube,')
|
|
||||||
lines.append(f' num_items_x={grid.num_items_x},')
|
|
||||||
lines.append(f' num_items_y={grid.num_items_y},')
|
|
||||||
lines.append(f' dx={grid.dx},')
|
|
||||||
lines.append(f' dy={grid.dy},')
|
|
||||||
lines.append(f' dz={grid.dz},')
|
|
||||||
lines.append(f' item_dx={grid.item_dx},')
|
|
||||||
lines.append(f' item_dy={grid.item_dy},')
|
|
||||||
lines.append(f' size_x={tube.size_x},')
|
|
||||||
lines.append(f' size_y={tube.size_y},')
|
|
||||||
lines.append(f' size_z={tube.size_z},')
|
|
||||||
lines.append(f' max_volume={tube.max_volume}')
|
|
||||||
lines.append(f' )')
|
|
||||||
lines.append(f' )')
|
|
||||||
|
|
||||||
return '\n'.join(lines)
|
|
||||||
|
|
||||||
|
|
||||||
def _gen_plate_adapter(item: LabwareItem) -> str:
|
|
||||||
"""生成 PlateAdapter 工厂函数代码。"""
|
|
||||||
lines = []
|
|
||||||
fn = item.function_name
|
|
||||||
doc = item.docstring or f"Code: {item.material_info.Code}"
|
|
||||||
|
|
||||||
lines.append(f'def {fn}(name: str) -> PRCXI9300PlateAdapter:')
|
|
||||||
lines.append(f' """ {doc} """')
|
|
||||||
lines.append(f' return PRCXI9300PlateAdapter(')
|
|
||||||
lines.append(f' name=name,')
|
|
||||||
lines.append(f' size_x={item.size_x},')
|
|
||||||
lines.append(f' size_y={item.size_y},')
|
|
||||||
lines.append(f' size_z={item.size_z},')
|
|
||||||
if item.model:
|
|
||||||
lines.append(f' model="{item.model}",')
|
|
||||||
lines.append(f' material_info={_fmt_dict(item.material_info.model_dump(exclude_none=True))}')
|
|
||||||
lines.append(f' )')
|
|
||||||
|
|
||||||
return '\n'.join(lines)
|
|
||||||
|
|
||||||
|
|
||||||
def _fmt_dict(d: dict) -> str:
|
|
||||||
"""格式化字典为 Python 代码片段。"""
|
|
||||||
parts = []
|
|
||||||
for k, v in d.items():
|
|
||||||
if isinstance(v, str):
|
|
||||||
parts.append(f'"{k}": "{v}"')
|
|
||||||
elif v is None:
|
|
||||||
continue
|
|
||||||
else:
|
|
||||||
parts.append(f'"{k}": {v}')
|
|
||||||
return '{' + ', '.join(parts) + '}'
|
|
||||||
|
|
||||||
|
|
||||||
def _gen_template_factory_kinds(items: List[LabwareItem]) -> str:
|
|
||||||
"""生成 PRCXI_TEMPLATE_FACTORY_KINDS 列表。"""
|
|
||||||
lines = ['PRCXI_TEMPLATE_FACTORY_KINDS: List[Tuple[Callable[..., Any], str]] = [']
|
|
||||||
for item in items:
|
|
||||||
if item.include_in_template_matching and item.template_kind:
|
|
||||||
lines.append(f' ({item.function_name}, "{item.template_kind}"),')
|
|
||||||
lines.append(']')
|
|
||||||
return '\n'.join(lines)
|
|
||||||
|
|
||||||
|
|
||||||
def _gen_footer() -> str:
|
|
||||||
"""生成文件尾部的模板相关代码。"""
|
|
||||||
return '''
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
# 协议上传 / workflow 用:与设备端耗材字典字段对齐的模板描述(供 common 自动匹配)
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
_PRCXI_TEMPLATE_SPECS_CACHE: Optional[List[Dict[str, Any]]] = None
|
|
||||||
|
|
||||||
|
|
||||||
def _probe_prcxi_resource(factory: Callable[..., Any]) -> Any:
|
|
||||||
probe = "__unilab_template_probe__"
|
|
||||||
if factory.__name__ == "PRCXI_trash":
|
|
||||||
return factory()
|
|
||||||
return factory(probe)
|
|
||||||
|
|
||||||
|
|
||||||
def _first_child_capacity_for_match(resource: Any) -> float:
|
|
||||||
"""Well max_volume 或 Tip 的 maximal_volume,用于与设备端 Volume 类似的打分。"""
|
|
||||||
ch = getattr(resource, "children", None) or []
|
|
||||||
if not ch:
|
|
||||||
return 0.0
|
|
||||||
c0 = ch[0]
|
|
||||||
mv = getattr(c0, "max_volume", None)
|
|
||||||
if mv is not None:
|
|
||||||
return float(mv)
|
|
||||||
tip = getattr(c0, "tip", None)
|
|
||||||
if tip is not None:
|
|
||||||
mv2 = getattr(tip, "maximal_volume", None)
|
|
||||||
if mv2 is not None:
|
|
||||||
return float(mv2)
|
|
||||||
return 0.0
|
|
||||||
|
|
||||||
|
|
||||||
def get_prcxi_labware_template_specs() -> List[Dict[str, Any]]:
|
|
||||||
"""返回与 ``prcxi._match_and_create_matrix`` 中耗材字段兼容的模板列表,用于按孔数+容量打分。"""
|
|
||||||
global _PRCXI_TEMPLATE_SPECS_CACHE
|
|
||||||
if _PRCXI_TEMPLATE_SPECS_CACHE is not None:
|
|
||||||
return _PRCXI_TEMPLATE_SPECS_CACHE
|
|
||||||
|
|
||||||
out: List[Dict[str, Any]] = []
|
|
||||||
for factory, kind in PRCXI_TEMPLATE_FACTORY_KINDS:
|
|
||||||
try:
|
|
||||||
r = _probe_prcxi_resource(factory)
|
|
||||||
except Exception:
|
|
||||||
continue
|
|
||||||
nx = int(getattr(r, "num_items_x", None) or 0)
|
|
||||||
ny = int(getattr(r, "num_items_y", None) or 0)
|
|
||||||
nchild = len(getattr(r, "children", []) or [])
|
|
||||||
hole_count = nx * ny if nx > 0 and ny > 0 else nchild
|
|
||||||
hole_row = ny if nx > 0 and ny > 0 else 0
|
|
||||||
hole_col = nx if nx > 0 and ny > 0 else 0
|
|
||||||
mi = getattr(r, "material_info", None) or {}
|
|
||||||
vol = _first_child_capacity_for_match(r)
|
|
||||||
menum = mi.get("materialEnum")
|
|
||||||
if menum is None and kind == "tip_rack":
|
|
||||||
menum = 1
|
|
||||||
elif menum is None and kind == "trash":
|
|
||||||
menum = 6
|
|
||||||
out.append(
|
|
||||||
{
|
|
||||||
"class_name": factory.__name__,
|
|
||||||
"kind": kind,
|
|
||||||
"materialEnum": menum,
|
|
||||||
"HoleRow": hole_row,
|
|
||||||
"HoleColum": hole_col,
|
|
||||||
"Volume": vol,
|
|
||||||
"hole_count": hole_count,
|
|
||||||
"material_uuid": mi.get("uuid"),
|
|
||||||
"material_code": mi.get("Code"),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
_PRCXI_TEMPLATE_SPECS_CACHE = out
|
|
||||||
return out
|
|
||||||
'''
|
|
||||||
|
|
||||||
|
|
||||||
def generate_code(db: LabwareDB, test_mode: bool = True) -> Path:
|
|
||||||
"""生成 prcxi_labware.py (或 _test.py),返回输出文件路径。"""
|
|
||||||
suffix = "_test" if test_mode else ""
|
|
||||||
out_path = _TARGET_DIR / f"prcxi_labware{suffix}.py"
|
|
||||||
|
|
||||||
# 备份
|
|
||||||
if out_path.exists():
|
|
||||||
bak = out_path.with_suffix(".py.bak")
|
|
||||||
shutil.copy2(out_path, bak)
|
|
||||||
|
|
||||||
# 按类型分组的生成器
|
|
||||||
generators = {
|
|
||||||
"plate": _gen_plate,
|
|
||||||
"tip_rack": _gen_tip_rack,
|
|
||||||
"trash": _gen_trash,
|
|
||||||
"tube_rack": _gen_tube_rack,
|
|
||||||
"plate_adapter": _gen_plate_adapter,
|
|
||||||
}
|
|
||||||
|
|
||||||
# 按 type 分段
|
|
||||||
sections = {
|
|
||||||
"plate": [],
|
|
||||||
"tip_rack": [],
|
|
||||||
"trash": [],
|
|
||||||
"tube_rack": [],
|
|
||||||
"plate_adapter": [],
|
|
||||||
}
|
|
||||||
|
|
||||||
for item in db.items:
|
|
||||||
gen = generators.get(item.type)
|
|
||||||
if gen:
|
|
||||||
sections[item.type].append(gen(item))
|
|
||||||
|
|
||||||
# 组装完整文件
|
|
||||||
parts = [_HEADER]
|
|
||||||
|
|
||||||
section_titles = {
|
|
||||||
"plate": "# =========================================================================\n# Plates\n# =========================================================================",
|
|
||||||
"tip_rack": "# =========================================================================\n# Tip Racks\n# =========================================================================",
|
|
||||||
"trash": "# =========================================================================\n# Trash\n# =========================================================================",
|
|
||||||
"tube_rack": "# =========================================================================\n# Tube Racks\n# =========================================================================",
|
|
||||||
"plate_adapter": "# =========================================================================\n# Plate Adapters\n# =========================================================================",
|
|
||||||
}
|
|
||||||
|
|
||||||
for type_key in ["plate", "tip_rack", "trash", "tube_rack", "plate_adapter"]:
|
|
||||||
if sections[type_key]:
|
|
||||||
parts.append(section_titles[type_key])
|
|
||||||
for code in sections[type_key]:
|
|
||||||
parts.append(code)
|
|
||||||
|
|
||||||
# Template factory kinds
|
|
||||||
parts.append("")
|
|
||||||
parts.append(_gen_template_factory_kinds(db.items))
|
|
||||||
|
|
||||||
# Footer
|
|
||||||
parts.append(_gen_footer())
|
|
||||||
|
|
||||||
content = '\n'.join(parts)
|
|
||||||
out_path.write_text(content, encoding="utf-8")
|
|
||||||
return out_path
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
from unilabos.labware_manager.importer import load_db
|
|
||||||
db = load_db()
|
|
||||||
if not db.items:
|
|
||||||
print("labware_db.json 为空,请先运行 importer.py")
|
|
||||||
else:
|
|
||||||
out = generate_code(db, test_mode=True)
|
|
||||||
print(f"已生成 {out} ({len(db.items)} 个工厂函数)")
|
|
||||||
@@ -1,474 +0,0 @@
|
|||||||
"""从现有 prcxi_labware.py + registry YAML 导入耗材数据到 labware_db.json。
|
|
||||||
|
|
||||||
策略:
|
|
||||||
1. 实例化每个工厂函数 → 提取物理尺寸、material_info、children
|
|
||||||
2. AST 解析源码 → 提取 docstring、volume_function 参数、plate_type
|
|
||||||
3. 从 children[0].location 反推 dx/dy/dz,相邻位置差推 item_dx/item_dy
|
|
||||||
4. 同时读取现有 YAML → 提取 registry_category / description
|
|
||||||
"""
|
|
||||||
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import ast
|
|
||||||
import json
|
|
||||||
import os
|
|
||||||
import re
|
|
||||||
import sys
|
|
||||||
from pathlib import Path
|
|
||||||
from typing import Any, Dict, List, Optional, Tuple
|
|
||||||
|
|
||||||
import yaml
|
|
||||||
|
|
||||||
# 将项目根目录加入 sys.path 以便 import
|
|
||||||
_PROJECT_ROOT = Path(__file__).resolve().parents[2]
|
|
||||||
if str(_PROJECT_ROOT) not in sys.path:
|
|
||||||
sys.path.insert(0, str(_PROJECT_ROOT))
|
|
||||||
|
|
||||||
from unilabos.labware_manager.models import (
|
|
||||||
AdapterInfo,
|
|
||||||
GridInfo,
|
|
||||||
LabwareDB,
|
|
||||||
LabwareItem,
|
|
||||||
MaterialInfo,
|
|
||||||
TipInfo,
|
|
||||||
TubeInfo,
|
|
||||||
VolumeFunctions,
|
|
||||||
WellInfo,
|
|
||||||
)
|
|
||||||
|
|
||||||
# ---------- 路径常量 ----------
|
|
||||||
_LABWARE_PY = Path(__file__).resolve().parents[1] / "devices" / "liquid_handling" / "prcxi" / "prcxi_labware.py"
|
|
||||||
_REGISTRY_DIR = Path(__file__).resolve().parents[1] / "registry" / "resources" / "prcxi"
|
|
||||||
_DB_PATH = Path(__file__).resolve().parent / "labware_db.json"
|
|
||||||
|
|
||||||
# YAML 文件名 → type 映射
|
|
||||||
_YAML_MAP: Dict[str, str] = {
|
|
||||||
"plates.yaml": "plate",
|
|
||||||
"tip_racks.yaml": "tip_rack",
|
|
||||||
"trash.yaml": "trash",
|
|
||||||
"tube_racks.yaml": "tube_rack",
|
|
||||||
"plate_adapters.yaml": "plate_adapter",
|
|
||||||
}
|
|
||||||
|
|
||||||
# PRCXI_TEMPLATE_FACTORY_KINDS 中列出的函数名(include_in_template_matching=True)
|
|
||||||
_TEMPLATE_FACTORY_NAMES = {
|
|
||||||
"PRCXI_BioER_96_wellplate", "PRCXI_nest_1_troughplate",
|
|
||||||
"PRCXI_BioRad_384_wellplate", "PRCXI_AGenBio_4_troughplate",
|
|
||||||
"PRCXI_nest_12_troughplate", "PRCXI_CellTreat_96_wellplate",
|
|
||||||
"PRCXI_10ul_eTips", "PRCXI_300ul_Tips",
|
|
||||||
"PRCXI_PCR_Plate_200uL_nonskirted", "PRCXI_PCR_Plate_200uL_semiskirted",
|
|
||||||
"PRCXI_PCR_Plate_200uL_skirted", "PRCXI_trash",
|
|
||||||
"PRCXI_96_DeepWell", "PRCXI_EP_Adapter",
|
|
||||||
"PRCXI_1250uL_Tips", "PRCXI_10uL_Tips",
|
|
||||||
"PRCXI_1000uL_Tips", "PRCXI_200uL_Tips",
|
|
||||||
"PRCXI_48_DeepWell",
|
|
||||||
}
|
|
||||||
|
|
||||||
# template_kind 对应
|
|
||||||
_TEMPLATE_KINDS: Dict[str, str] = {
|
|
||||||
"PRCXI_BioER_96_wellplate": "plate",
|
|
||||||
"PRCXI_nest_1_troughplate": "plate",
|
|
||||||
"PRCXI_BioRad_384_wellplate": "plate",
|
|
||||||
"PRCXI_AGenBio_4_troughplate": "plate",
|
|
||||||
"PRCXI_nest_12_troughplate": "plate",
|
|
||||||
"PRCXI_CellTreat_96_wellplate": "plate",
|
|
||||||
"PRCXI_10ul_eTips": "tip_rack",
|
|
||||||
"PRCXI_300ul_Tips": "tip_rack",
|
|
||||||
"PRCXI_PCR_Plate_200uL_nonskirted": "plate",
|
|
||||||
"PRCXI_PCR_Plate_200uL_semiskirted": "plate",
|
|
||||||
"PRCXI_PCR_Plate_200uL_skirted": "plate",
|
|
||||||
"PRCXI_trash": "trash",
|
|
||||||
"PRCXI_96_DeepWell": "plate",
|
|
||||||
"PRCXI_EP_Adapter": "tube_rack",
|
|
||||||
"PRCXI_1250uL_Tips": "tip_rack",
|
|
||||||
"PRCXI_10uL_Tips": "tip_rack",
|
|
||||||
"PRCXI_1000uL_Tips": "tip_rack",
|
|
||||||
"PRCXI_200uL_Tips": "tip_rack",
|
|
||||||
"PRCXI_48_DeepWell": "plate",
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def _load_registry_info() -> Dict[str, Dict[str, Any]]:
|
|
||||||
"""读取所有 registry YAML 文件,返回 {function_name: {category, description}} 映射。"""
|
|
||||||
info: Dict[str, Dict[str, Any]] = {}
|
|
||||||
for fname, ltype in _YAML_MAP.items():
|
|
||||||
fpath = _REGISTRY_DIR / fname
|
|
||||||
if not fpath.exists():
|
|
||||||
continue
|
|
||||||
with open(fpath, "r", encoding="utf-8") as f:
|
|
||||||
data = yaml.safe_load(f) or {}
|
|
||||||
for func_name, entry in data.items():
|
|
||||||
info[func_name] = {
|
|
||||||
"registry_category": entry.get("category", ["prcxi", ltype.replace("plate_adapter", "plate_adapters")]),
|
|
||||||
"registry_description": entry.get("description", ""),
|
|
||||||
}
|
|
||||||
return info
|
|
||||||
|
|
||||||
|
|
||||||
def _parse_ast_info() -> Dict[str, Dict[str, Any]]:
|
|
||||||
"""AST 解析 prcxi_labware.py,提取每个工厂函数的 docstring 和 volume_function 参数。"""
|
|
||||||
source = _LABWARE_PY.read_text(encoding="utf-8")
|
|
||||||
tree = ast.parse(source)
|
|
||||||
result: Dict[str, Dict[str, Any]] = {}
|
|
||||||
|
|
||||||
for node in ast.walk(tree):
|
|
||||||
if not isinstance(node, ast.FunctionDef):
|
|
||||||
continue
|
|
||||||
fname = node.name
|
|
||||||
if not fname.startswith("PRCXI_"):
|
|
||||||
continue
|
|
||||||
if fname.startswith("_"):
|
|
||||||
continue
|
|
||||||
|
|
||||||
info: Dict[str, Any] = {"docstring": "", "volume_functions": None, "plate_type": None}
|
|
||||||
|
|
||||||
# docstring
|
|
||||||
doc = ast.get_docstring(node)
|
|
||||||
if doc:
|
|
||||||
info["docstring"] = doc.strip()
|
|
||||||
|
|
||||||
# 搜索函数体中的 plate_type 赋值和 volume_function 参数
|
|
||||||
func_source = ast.get_source_segment(source, node) or ""
|
|
||||||
|
|
||||||
# plate_type
|
|
||||||
m = re.search(r'plate_type\s*=\s*["\']([^"\']+)["\']', func_source)
|
|
||||||
if m:
|
|
||||||
info["plate_type"] = m.group(1)
|
|
||||||
|
|
||||||
# volume_functions: 检查 compute_height_from_volume_rectangle
|
|
||||||
if "compute_height_from_volume_rectangle" in func_source:
|
|
||||||
# 提取 well_length 和 well_width
|
|
||||||
vf: Dict[str, Any] = {"type": "rectangle"}
|
|
||||||
# 尝试从 lambda 中提取
|
|
||||||
wl_match = re.search(r'well_length\s*=\s*([\w_.]+)', func_source)
|
|
||||||
ww_match = re.search(r'well_width\s*=\s*([\w_.]+)', func_source)
|
|
||||||
if wl_match:
|
|
||||||
vf["well_length_var"] = wl_match.group(1)
|
|
||||||
if ww_match:
|
|
||||||
vf["well_width_var"] = ww_match.group(1)
|
|
||||||
info["volume_functions"] = vf
|
|
||||||
|
|
||||||
result[fname] = info
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
def _probe_factory(factory_func) -> Any:
|
|
||||||
"""实例化工厂函数获取 resource 对象。"""
|
|
||||||
if factory_func.__name__ == "PRCXI_trash":
|
|
||||||
return factory_func()
|
|
||||||
return factory_func("__probe__")
|
|
||||||
|
|
||||||
|
|
||||||
def _get_size(resource, attr: str) -> float:
|
|
||||||
"""获取 PLR Resource 的尺寸(兼容 size_x 和 _size_x)。"""
|
|
||||||
val = getattr(resource, attr, None)
|
|
||||||
if val is None:
|
|
||||||
val = getattr(resource, f"_{attr}", None)
|
|
||||||
if val is None:
|
|
||||||
val = getattr(resource, f"get_{attr}", lambda: 0)()
|
|
||||||
return float(val or 0)
|
|
||||||
|
|
||||||
|
|
||||||
def _extract_grid_from_children(resource) -> Optional[Dict[str, Any]]:
|
|
||||||
"""从 resource.children 提取网格信息。"""
|
|
||||||
children = getattr(resource, "children", None) or []
|
|
||||||
if not children:
|
|
||||||
return None
|
|
||||||
|
|
||||||
# 获取 num_items_x, num_items_y
|
|
||||||
num_x = getattr(resource, "num_items_x", None)
|
|
||||||
num_y = getattr(resource, "num_items_y", None)
|
|
||||||
if num_x is None or num_y is None:
|
|
||||||
return None
|
|
||||||
|
|
||||||
c0 = children[0]
|
|
||||||
loc0 = getattr(c0, "location", None)
|
|
||||||
dx = loc0.x if loc0 else 0.0
|
|
||||||
dy_raw = loc0.y if loc0 else 0.0 # 这是 PLR 布局后的位置,不是输入参数
|
|
||||||
dz = loc0.z if loc0 else 0.0
|
|
||||||
|
|
||||||
# 推算 item_dx, item_dy
|
|
||||||
item_dx = 9.0
|
|
||||||
item_dy = 9.0
|
|
||||||
if len(children) > 1:
|
|
||||||
c1 = children[1]
|
|
||||||
loc1 = getattr(c1, "location", None)
|
|
||||||
if loc1 and loc0:
|
|
||||||
diff_x = abs(loc1.x - loc0.x)
|
|
||||||
diff_y = abs(loc1.y - loc0.y)
|
|
||||||
if diff_x > 0.1:
|
|
||||||
item_dx = diff_x
|
|
||||||
if diff_y > 0.1:
|
|
||||||
item_dy = diff_y
|
|
||||||
|
|
||||||
# 如果 num_items_y > 1 且 num_items_x > 1, 找列间距
|
|
||||||
if int(num_y) > 1 and int(num_x) > 1 and len(children) >= int(num_y) + 1:
|
|
||||||
cn = children[int(num_y)]
|
|
||||||
locn = getattr(cn, "location", None)
|
|
||||||
if locn and loc0:
|
|
||||||
col_diff = abs(locn.x - loc0.x)
|
|
||||||
row_diff = abs(children[1].location.y - loc0.y) if len(children) > 1 else item_dy
|
|
||||||
if col_diff > 0.1:
|
|
||||||
item_dx = col_diff
|
|
||||||
if row_diff > 0.1:
|
|
||||||
item_dy = row_diff
|
|
||||||
|
|
||||||
# PLR create_ordered_items_2d 的 Y 轴排列是倒序的:
|
|
||||||
# child[0].y = dy_param + (num_y - 1) * item_dy (最上面一行)
|
|
||||||
# 因此反推原始 dy 参数:
|
|
||||||
dy = dy_raw - (int(num_y) - 1) * item_dy
|
|
||||||
|
|
||||||
return {
|
|
||||||
"num_items_x": int(num_x),
|
|
||||||
"num_items_y": int(num_y),
|
|
||||||
"dx": round(dx, 4),
|
|
||||||
"dy": round(dy, 4),
|
|
||||||
"dz": round(dz, 4),
|
|
||||||
"item_dx": round(item_dx, 4),
|
|
||||||
"item_dy": round(item_dy, 4),
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def _extract_well_info(child) -> Dict[str, Any]:
|
|
||||||
"""从 Well/TipSpot/Tube 子对象提取信息。"""
|
|
||||||
# material_z_thickness 在 PLR 中如果未设置会抛 NotImplementedError
|
|
||||||
mzt = None
|
|
||||||
try:
|
|
||||||
mzt = child.material_z_thickness
|
|
||||||
except (NotImplementedError, AttributeError):
|
|
||||||
mzt = getattr(child, "_material_z_thickness", None)
|
|
||||||
|
|
||||||
return {
|
|
||||||
"size_x": round(_get_size(child, "size_x"), 4),
|
|
||||||
"size_y": round(_get_size(child, "size_y"), 4),
|
|
||||||
"size_z": round(_get_size(child, "size_z"), 4),
|
|
||||||
"max_volume": getattr(child, "max_volume", None),
|
|
||||||
"bottom_type": getattr(child, "bottom_type", None),
|
|
||||||
"cross_section_type": getattr(child, "cross_section_type", None),
|
|
||||||
"material_z_thickness": mzt,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def import_from_code() -> LabwareDB:
|
|
||||||
"""执行完整的导入流程,返回 LabwareDB 对象。"""
|
|
||||||
# 1. 加载 registry 信息
|
|
||||||
reg_info = _load_registry_info()
|
|
||||||
|
|
||||||
# 2. AST 解析源码
|
|
||||||
ast_info = _parse_ast_info()
|
|
||||||
|
|
||||||
# 3. 导入工厂模块(通过包路径避免 relative import 问题)
|
|
||||||
import importlib
|
|
||||||
mod = importlib.import_module("unilabos.devices.liquid_handling.prcxi.prcxi_labware")
|
|
||||||
|
|
||||||
# 4. 获取 PRCXI_TEMPLATE_FACTORY_KINDS 列出的函数
|
|
||||||
factory_kinds = getattr(mod, "PRCXI_TEMPLATE_FACTORY_KINDS", [])
|
|
||||||
template_func_names = {f.__name__ for f, _k in factory_kinds}
|
|
||||||
|
|
||||||
# 5. 收集所有 PRCXI_ 开头的工厂函数
|
|
||||||
all_factories: List[Tuple[str, Any]] = []
|
|
||||||
for attr_name in dir(mod):
|
|
||||||
if attr_name.startswith("PRCXI_") and not attr_name.startswith("_"):
|
|
||||||
obj = getattr(mod, attr_name)
|
|
||||||
if callable(obj) and not isinstance(obj, type):
|
|
||||||
all_factories.append((attr_name, obj))
|
|
||||||
|
|
||||||
# 按源码行号排序
|
|
||||||
all_factories.sort(key=lambda x: getattr(x[1], "__code__", None) and x[1].__code__.co_firstlineno or 0)
|
|
||||||
|
|
||||||
items: List[LabwareItem] = []
|
|
||||||
|
|
||||||
for func_name, factory in all_factories:
|
|
||||||
try:
|
|
||||||
resource = _probe_factory(factory)
|
|
||||||
except Exception as e:
|
|
||||||
print(f"跳过 {func_name}: {e}")
|
|
||||||
continue
|
|
||||||
|
|
||||||
# 确定类型
|
|
||||||
type_name = "plate"
|
|
||||||
class_name = type(resource).__name__
|
|
||||||
if "TipRack" in class_name:
|
|
||||||
type_name = "tip_rack"
|
|
||||||
elif "Trash" in class_name:
|
|
||||||
type_name = "trash"
|
|
||||||
elif "TubeRack" in class_name:
|
|
||||||
type_name = "tube_rack"
|
|
||||||
elif "PlateAdapter" in class_name:
|
|
||||||
type_name = "plate_adapter"
|
|
||||||
|
|
||||||
# material_info
|
|
||||||
state = getattr(resource, "_unilabos_state", {}) or {}
|
|
||||||
mat = state.get("Material", {})
|
|
||||||
mat_info = MaterialInfo(
|
|
||||||
uuid=mat.get("uuid", ""),
|
|
||||||
Code=mat.get("Code", ""),
|
|
||||||
Name=mat.get("Name", ""),
|
|
||||||
materialEnum=mat.get("materialEnum"),
|
|
||||||
SupplyType=mat.get("SupplyType"),
|
|
||||||
)
|
|
||||||
|
|
||||||
# AST 信息
|
|
||||||
ast_data = ast_info.get(func_name, {})
|
|
||||||
docstring = ast_data.get("docstring", "")
|
|
||||||
plate_type = ast_data.get("plate_type")
|
|
||||||
|
|
||||||
# Registry 信息
|
|
||||||
reg = reg_info.get(func_name, {})
|
|
||||||
registry_category = reg.get("registry_category", ["prcxi", _type_to_yaml_subcategory(type_name)])
|
|
||||||
registry_description = reg.get("registry_description", f'{mat_info.Name} (Code: {mat_info.Code})')
|
|
||||||
|
|
||||||
# 构建 item
|
|
||||||
item = LabwareItem(
|
|
||||||
id=func_name.lower().replace("prcxi_", "")[:8] or func_name[:8],
|
|
||||||
type=type_name,
|
|
||||||
function_name=func_name,
|
|
||||||
docstring=docstring,
|
|
||||||
size_x=round(_get_size(resource, "size_x"), 4),
|
|
||||||
size_y=round(_get_size(resource, "size_y"), 4),
|
|
||||||
size_z=round(_get_size(resource, "size_z"), 4),
|
|
||||||
model=getattr(resource, "model", None),
|
|
||||||
category=getattr(resource, "category", type_name),
|
|
||||||
plate_type=plate_type,
|
|
||||||
material_info=mat_info,
|
|
||||||
registry_category=registry_category,
|
|
||||||
registry_description=registry_description,
|
|
||||||
include_in_template_matching=func_name in template_func_names,
|
|
||||||
template_kind=_TEMPLATE_KINDS.get(func_name),
|
|
||||||
)
|
|
||||||
|
|
||||||
# 提取子项信息
|
|
||||||
children = getattr(resource, "children", None) or []
|
|
||||||
grid_data = _extract_grid_from_children(resource)
|
|
||||||
|
|
||||||
if type_name == "plate" and children:
|
|
||||||
if grid_data:
|
|
||||||
item.grid = GridInfo(**grid_data)
|
|
||||||
c0 = children[0]
|
|
||||||
well_data = _extract_well_info(c0)
|
|
||||||
bt = well_data.get("bottom_type")
|
|
||||||
if bt is not None:
|
|
||||||
bt = bt.name if hasattr(bt, "name") else str(bt)
|
|
||||||
else:
|
|
||||||
bt = "FLAT"
|
|
||||||
cst = well_data.get("cross_section_type")
|
|
||||||
if cst is not None:
|
|
||||||
cst = cst.name if hasattr(cst, "name") else str(cst)
|
|
||||||
else:
|
|
||||||
cst = "CIRCLE"
|
|
||||||
item.well = WellInfo(
|
|
||||||
size_x=well_data["size_x"],
|
|
||||||
size_y=well_data["size_y"],
|
|
||||||
size_z=well_data["size_z"],
|
|
||||||
max_volume=well_data.get("max_volume"),
|
|
||||||
bottom_type=bt,
|
|
||||||
cross_section_type=cst,
|
|
||||||
material_z_thickness=well_data.get("material_z_thickness"),
|
|
||||||
)
|
|
||||||
# volume_functions
|
|
||||||
vf = ast_data.get("volume_functions")
|
|
||||||
if vf:
|
|
||||||
# 需要实际获取 well 尺寸作为 volume_function 参数
|
|
||||||
item.volume_functions = VolumeFunctions(
|
|
||||||
type="rectangle",
|
|
||||||
well_length=well_data["size_x"],
|
|
||||||
well_width=well_data["size_y"],
|
|
||||||
)
|
|
||||||
|
|
||||||
elif type_name == "tip_rack" and children:
|
|
||||||
if grid_data:
|
|
||||||
item.grid = GridInfo(**grid_data)
|
|
||||||
c0 = children[0]
|
|
||||||
tip_obj = getattr(c0, "tip", None)
|
|
||||||
tip_volume = 300.0
|
|
||||||
tip_length = 60.0
|
|
||||||
tip_depth = 51.0
|
|
||||||
tip_filter = False
|
|
||||||
if tip_obj:
|
|
||||||
tip_volume = getattr(tip_obj, "maximal_volume", 300.0)
|
|
||||||
tip_length = getattr(tip_obj, "total_tip_length", 60.0)
|
|
||||||
tip_depth = getattr(tip_obj, "fitting_depth", 51.0)
|
|
||||||
tip_filter = getattr(tip_obj, "has_filter", False)
|
|
||||||
item.tip = TipInfo(
|
|
||||||
spot_size_x=round(_get_size(c0, "size_x"), 4),
|
|
||||||
spot_size_y=round(_get_size(c0, "size_y"), 4),
|
|
||||||
spot_size_z=round(_get_size(c0, "size_z"), 4),
|
|
||||||
tip_volume=tip_volume,
|
|
||||||
tip_length=tip_length,
|
|
||||||
tip_fitting_depth=tip_depth,
|
|
||||||
has_filter=tip_filter,
|
|
||||||
)
|
|
||||||
# 计算 tip_above_rack_length = tip_length - (size_z - dz)
|
|
||||||
if grid_data:
|
|
||||||
_dz = grid_data.get("dz", 0.0)
|
|
||||||
_above = tip_length - (item.size_z - _dz)
|
|
||||||
item.tip.tip_above_rack_length = round(_above, 4) if _above > 0 else None
|
|
||||||
|
|
||||||
elif type_name == "tube_rack" and children:
|
|
||||||
if grid_data:
|
|
||||||
item.grid = GridInfo(**grid_data)
|
|
||||||
c0 = children[0]
|
|
||||||
item.tube = TubeInfo(
|
|
||||||
size_x=round(_get_size(c0, "size_x"), 4),
|
|
||||||
size_y=round(_get_size(c0, "size_y"), 4),
|
|
||||||
size_z=round(_get_size(c0, "size_z"), 4),
|
|
||||||
max_volume=getattr(c0, "max_volume", 1500.0) or 1500.0,
|
|
||||||
)
|
|
||||||
|
|
||||||
elif type_name == "plate_adapter":
|
|
||||||
# 提取 adapter 参数
|
|
||||||
ahx = getattr(resource, "adapter_hole_size_x", 127.76)
|
|
||||||
ahy = getattr(resource, "adapter_hole_size_y", 85.48)
|
|
||||||
ahz = getattr(resource, "adapter_hole_size_z", 10.0)
|
|
||||||
adx = getattr(resource, "dx", None)
|
|
||||||
ady = getattr(resource, "dy", None)
|
|
||||||
adz = getattr(resource, "dz", 0.0)
|
|
||||||
item.adapter = AdapterInfo(
|
|
||||||
adapter_hole_size_x=ahx,
|
|
||||||
adapter_hole_size_y=ahy,
|
|
||||||
adapter_hole_size_z=ahz,
|
|
||||||
dx=adx,
|
|
||||||
dy=ady,
|
|
||||||
dz=adz,
|
|
||||||
)
|
|
||||||
|
|
||||||
items.append(item)
|
|
||||||
|
|
||||||
return LabwareDB(items=items)
|
|
||||||
|
|
||||||
|
|
||||||
def _type_to_yaml_subcategory(type_name: str) -> str:
|
|
||||||
mapping = {
|
|
||||||
"plate": "plates",
|
|
||||||
"tip_rack": "tip_racks",
|
|
||||||
"trash": "trash",
|
|
||||||
"tube_rack": "tube_racks",
|
|
||||||
"plate_adapter": "plate_adapters",
|
|
||||||
}
|
|
||||||
return mapping.get(type_name, type_name)
|
|
||||||
|
|
||||||
|
|
||||||
def save_db(db: LabwareDB, path: Optional[Path] = None) -> Path:
|
|
||||||
"""保存 LabwareDB 到 JSON 文件。"""
|
|
||||||
out = path or _DB_PATH
|
|
||||||
with open(out, "w", encoding="utf-8") as f:
|
|
||||||
json.dump(db.model_dump(), f, ensure_ascii=False, indent=2)
|
|
||||||
return out
|
|
||||||
|
|
||||||
|
|
||||||
def load_db(path: Optional[Path] = None) -> LabwareDB:
|
|
||||||
"""从 JSON 文件加载 LabwareDB。"""
|
|
||||||
src = path or _DB_PATH
|
|
||||||
if not src.exists():
|
|
||||||
return LabwareDB()
|
|
||||||
with open(src, "r", encoding="utf-8") as f:
|
|
||||||
return LabwareDB(**json.load(f))
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
db = import_from_code()
|
|
||||||
out = save_db(db)
|
|
||||||
print(f"已导入 {len(db.items)} 个耗材 → {out}")
|
|
||||||
for item in db.items:
|
|
||||||
print(f" [{item.type:14s}] {item.function_name}")
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,126 +0,0 @@
|
|||||||
"""Pydantic 数据模型,描述所有 PRCXI 耗材类型的 JSON 结构。"""
|
|
||||||
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import uuid as _uuid
|
|
||||||
from typing import Any, Dict, List, Literal, Optional
|
|
||||||
|
|
||||||
from pydantic import BaseModel, Field
|
|
||||||
|
|
||||||
|
|
||||||
class MaterialInfo(BaseModel):
|
|
||||||
uuid: str = ""
|
|
||||||
Code: str = ""
|
|
||||||
Name: str = ""
|
|
||||||
materialEnum: Optional[int] = None
|
|
||||||
SupplyType: Optional[int] = None
|
|
||||||
|
|
||||||
|
|
||||||
class GridInfo(BaseModel):
|
|
||||||
"""孔位网格排列参数"""
|
|
||||||
num_items_x: int = 12
|
|
||||||
num_items_y: int = 8
|
|
||||||
dx: float = 0.0
|
|
||||||
dy: float = 0.0
|
|
||||||
dz: float = 0.0
|
|
||||||
item_dx: float = 9.0
|
|
||||||
item_dy: float = 9.0
|
|
||||||
|
|
||||||
|
|
||||||
class WellInfo(BaseModel):
|
|
||||||
"""孔参数 (Plate)"""
|
|
||||||
size_x: float = 8.0
|
|
||||||
size_y: float = 8.0
|
|
||||||
size_z: float = 10.0
|
|
||||||
max_volume: Optional[float] = None
|
|
||||||
bottom_type: str = "FLAT" # V / U / FLAT
|
|
||||||
cross_section_type: str = "CIRCLE" # CIRCLE / RECTANGLE
|
|
||||||
material_z_thickness: Optional[float] = None
|
|
||||||
|
|
||||||
|
|
||||||
class VolumeFunctions(BaseModel):
|
|
||||||
"""体积-高度计算函数参数 (矩形 well)"""
|
|
||||||
type: str = "rectangle"
|
|
||||||
well_length: float = 0.0
|
|
||||||
well_width: float = 0.0
|
|
||||||
|
|
||||||
|
|
||||||
class TipInfo(BaseModel):
|
|
||||||
"""枪头参数 (TipRack)"""
|
|
||||||
spot_size_x: float = 7.0
|
|
||||||
spot_size_y: float = 7.0
|
|
||||||
spot_size_z: float = 0.0
|
|
||||||
tip_volume: float = 300.0
|
|
||||||
tip_length: float = 60.0
|
|
||||||
tip_fitting_depth: float = 51.0
|
|
||||||
tip_above_rack_length: Optional[float] = None
|
|
||||||
has_filter: bool = False
|
|
||||||
|
|
||||||
|
|
||||||
class TubeInfo(BaseModel):
|
|
||||||
"""管参数 (TubeRack)"""
|
|
||||||
size_x: float = 10.6
|
|
||||||
size_y: float = 10.6
|
|
||||||
size_z: float = 40.0
|
|
||||||
max_volume: float = 1500.0
|
|
||||||
|
|
||||||
|
|
||||||
class AdapterInfo(BaseModel):
|
|
||||||
"""适配器参数 (PlateAdapter)"""
|
|
||||||
adapter_hole_size_x: float = 127.76
|
|
||||||
adapter_hole_size_y: float = 85.48
|
|
||||||
adapter_hole_size_z: float = 10.0
|
|
||||||
dx: Optional[float] = None
|
|
||||||
dy: Optional[float] = None
|
|
||||||
dz: float = 0.0
|
|
||||||
|
|
||||||
|
|
||||||
LabwareType = Literal["plate", "tip_rack", "trash", "tube_rack", "plate_adapter"]
|
|
||||||
|
|
||||||
|
|
||||||
class LabwareItem(BaseModel):
|
|
||||||
"""一个耗材条目的完整 JSON 表示"""
|
|
||||||
|
|
||||||
id: str = Field(default_factory=lambda: _uuid.uuid4().hex[:8])
|
|
||||||
type: LabwareType = "plate"
|
|
||||||
function_name: str = ""
|
|
||||||
docstring: str = ""
|
|
||||||
|
|
||||||
# 物理尺寸
|
|
||||||
size_x: float = 127.0
|
|
||||||
size_y: float = 85.0
|
|
||||||
size_z: float = 20.0
|
|
||||||
model: Optional[str] = None
|
|
||||||
category: Optional[str] = None
|
|
||||||
plate_type: Optional[str] = None # non-skirted / semi-skirted / skirted
|
|
||||||
|
|
||||||
# 材料信息
|
|
||||||
material_info: MaterialInfo = Field(default_factory=MaterialInfo)
|
|
||||||
|
|
||||||
# Registry 字段
|
|
||||||
registry_category: List[str] = Field(default_factory=lambda: ["prcxi", "plates"])
|
|
||||||
registry_description: str = ""
|
|
||||||
|
|
||||||
# Plate 特有
|
|
||||||
grid: Optional[GridInfo] = None
|
|
||||||
well: Optional[WellInfo] = None
|
|
||||||
volume_functions: Optional[VolumeFunctions] = None
|
|
||||||
|
|
||||||
# TipRack 特有
|
|
||||||
tip: Optional[TipInfo] = None
|
|
||||||
|
|
||||||
# TubeRack 特有
|
|
||||||
tube: Optional[TubeInfo] = None
|
|
||||||
|
|
||||||
# PlateAdapter 特有
|
|
||||||
adapter: Optional[AdapterInfo] = None
|
|
||||||
|
|
||||||
# 模板匹配
|
|
||||||
include_in_template_matching: bool = False
|
|
||||||
template_kind: Optional[str] = None
|
|
||||||
|
|
||||||
|
|
||||||
class LabwareDB(BaseModel):
|
|
||||||
"""整个 labware_db.json 的结构"""
|
|
||||||
version: str = "1.0"
|
|
||||||
items: List[LabwareItem] = Field(default_factory=list)
|
|
||||||
@@ -1,292 +0,0 @@
|
|||||||
/**
|
|
||||||
* form_handler.js — 动态表单逻辑 + 实时预览
|
|
||||||
*/
|
|
||||||
|
|
||||||
// 根据类型显示/隐藏对应的表单段
|
|
||||||
function onTypeChange() {
|
|
||||||
const type = document.getElementById('f-type').value;
|
|
||||||
const sections = {
|
|
||||||
grid: ['plate', 'tip_rack', 'tube_rack'],
|
|
||||||
well: ['plate'],
|
|
||||||
tip: ['tip_rack'],
|
|
||||||
tube: ['tube_rack'],
|
|
||||||
adapter: ['plate_adapter'],
|
|
||||||
};
|
|
||||||
|
|
||||||
for (const [sec, types] of Object.entries(sections)) {
|
|
||||||
const el = document.getElementById('section-' + sec);
|
|
||||||
if (el) el.style.display = types.includes(type) ? 'block' : 'none';
|
|
||||||
}
|
|
||||||
|
|
||||||
// plate_type 行只对 plate 显示
|
|
||||||
const ptRow = document.getElementById('row-plate_type');
|
|
||||||
if (ptRow) ptRow.style.display = type === 'plate' ? 'block' : 'none';
|
|
||||||
|
|
||||||
updatePreview();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 从表单收集数据
|
|
||||||
function collectFormData() {
|
|
||||||
const g = id => {
|
|
||||||
const el = document.getElementById(id);
|
|
||||||
if (!el) return null;
|
|
||||||
if (el.type === 'checkbox') return el.checked;
|
|
||||||
if (el.type === 'number') return el.value === '' ? null : parseFloat(el.value);
|
|
||||||
return el.value || null;
|
|
||||||
};
|
|
||||||
|
|
||||||
const type = g('f-type');
|
|
||||||
|
|
||||||
const data = {
|
|
||||||
type: type,
|
|
||||||
function_name: g('f-function_name') || 'PRCXI_new',
|
|
||||||
model: g('f-model'),
|
|
||||||
docstring: g('f-docstring') || '',
|
|
||||||
plate_type: type === 'plate' ? g('f-plate_type') : null,
|
|
||||||
size_x: g('f-size_x') || 127,
|
|
||||||
size_y: g('f-size_y') || 85,
|
|
||||||
size_z: g('f-size_z') || 20,
|
|
||||||
material_info: {
|
|
||||||
uuid: g('f-mi_uuid') || '',
|
|
||||||
Code: g('f-mi_code') || '',
|
|
||||||
Name: g('f-mi_name') || '',
|
|
||||||
materialEnum: g('f-mi_menum'),
|
|
||||||
SupplyType: g('f-mi_stype'),
|
|
||||||
},
|
|
||||||
registry_category: (g('f-reg_cat') || 'prcxi,plates').split(',').map(s => s.trim()),
|
|
||||||
registry_description: g('f-reg_desc') || '',
|
|
||||||
include_in_template_matching: g('f-in_tpl') || false,
|
|
||||||
template_kind: g('f-tpl_kind') || null,
|
|
||||||
grid: null,
|
|
||||||
well: null,
|
|
||||||
tip: null,
|
|
||||||
tube: null,
|
|
||||||
adapter: null,
|
|
||||||
volume_functions: null,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Grid
|
|
||||||
if (['plate', 'tip_rack', 'tube_rack'].includes(type)) {
|
|
||||||
data.grid = {
|
|
||||||
num_items_x: g('f-grid_nx') || 12,
|
|
||||||
num_items_y: g('f-grid_ny') || 8,
|
|
||||||
dx: g('f-grid_dx') || 0,
|
|
||||||
dy: g('f-grid_dy') || 0,
|
|
||||||
dz: g('f-grid_dz') || 0,
|
|
||||||
item_dx: g('f-grid_idx') || 9,
|
|
||||||
item_dy: g('f-grid_idy') || 9,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Well
|
|
||||||
if (type === 'plate') {
|
|
||||||
data.well = {
|
|
||||||
size_x: g('f-well_sx') || 8,
|
|
||||||
size_y: g('f-well_sy') || 8,
|
|
||||||
size_z: g('f-well_sz') || 10,
|
|
||||||
max_volume: g('f-well_vol'),
|
|
||||||
material_z_thickness: g('f-well_mzt'),
|
|
||||||
bottom_type: g('f-well_bt') || 'FLAT',
|
|
||||||
cross_section_type: g('f-well_cs') || 'CIRCLE',
|
|
||||||
};
|
|
||||||
if (g('f-has_vf')) {
|
|
||||||
data.volume_functions = {
|
|
||||||
type: 'rectangle',
|
|
||||||
well_length: data.well.size_x,
|
|
||||||
well_width: data.well.size_y,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tip
|
|
||||||
if (type === 'tip_rack') {
|
|
||||||
data.tip = {
|
|
||||||
spot_size_x: g('f-tip_sx') || 7,
|
|
||||||
spot_size_y: g('f-tip_sy') || 7,
|
|
||||||
spot_size_z: g('f-tip_sz') || 0,
|
|
||||||
tip_volume: g('f-tip_vol') || 300,
|
|
||||||
tip_length: g('f-tip_len') || 60,
|
|
||||||
tip_fitting_depth: g('f-tip_dep') || 51,
|
|
||||||
tip_above_rack_length: g('f-tip_above'),
|
|
||||||
has_filter: g('f-tip_filter') || false,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tube
|
|
||||||
if (type === 'tube_rack') {
|
|
||||||
data.tube = {
|
|
||||||
size_x: g('f-tube_sx') || 10.6,
|
|
||||||
size_y: g('f-tube_sy') || 10.6,
|
|
||||||
size_z: g('f-tube_sz') || 40,
|
|
||||||
max_volume: g('f-tube_vol') || 1500,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Adapter
|
|
||||||
if (type === 'plate_adapter') {
|
|
||||||
data.adapter = {
|
|
||||||
adapter_hole_size_x: g('f-adp_hsx') || 127.76,
|
|
||||||
adapter_hole_size_y: g('f-adp_hsy') || 85.48,
|
|
||||||
adapter_hole_size_z: g('f-adp_hsz') || 10,
|
|
||||||
dx: g('f-adp_dx'),
|
|
||||||
dy: g('f-adp_dy'),
|
|
||||||
dz: g('f-adp_dz') || 0,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 实时预览 (debounce)
|
|
||||||
let _previewTimer = null;
|
|
||||||
function updatePreview() {
|
|
||||||
if (_previewTimer) clearTimeout(_previewTimer);
|
|
||||||
_previewTimer = setTimeout(() => {
|
|
||||||
const data = collectFormData();
|
|
||||||
const topEl = document.getElementById('svg-topdown');
|
|
||||||
const sideEl = document.getElementById('svg-side');
|
|
||||||
if (topEl) renderTopDown(topEl, data);
|
|
||||||
if (sideEl) renderSideProfile(sideEl, data);
|
|
||||||
}, 200);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 给所有表单元素绑定 input 事件
|
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
|
||||||
const form = document.getElementById('labware-form');
|
|
||||||
if (!form) return;
|
|
||||||
form.addEventListener('input', updatePreview);
|
|
||||||
form.addEventListener('change', updatePreview);
|
|
||||||
|
|
||||||
// tip_above_rack_length 与 dz 互算
|
|
||||||
// 公式: tip_length = tip_above_rack_length + size_z - dz
|
|
||||||
// 规则: 填 tip_above → 自动算 dz;填 dz → 自动算 tip_above
|
|
||||||
// 改 size_z / tip_length → 优先重算 tip_above(若有值),否则算 dz
|
|
||||||
|
|
||||||
function _getVal(id) {
|
|
||||||
const el = document.getElementById(id);
|
|
||||||
return (el && el.value !== '') ? parseFloat(el.value) : null;
|
|
||||||
}
|
|
||||||
function _setVal(id, v) {
|
|
||||||
const el = document.getElementById(id);
|
|
||||||
if (el) el.value = Math.round(v * 1000) / 1000;
|
|
||||||
}
|
|
||||||
|
|
||||||
function autoCalcTipAbove(changedId) {
|
|
||||||
const typeEl = document.getElementById('f-type');
|
|
||||||
if (!typeEl || typeEl.value !== 'tip_rack') return;
|
|
||||||
|
|
||||||
const tipLen = _getVal('f-tip_len');
|
|
||||||
const sizeZ = _getVal('f-size_z');
|
|
||||||
const dz = _getVal('f-grid_dz');
|
|
||||||
const above = _getVal('f-tip_above');
|
|
||||||
|
|
||||||
// 需要 tip_length 和 size_z 才能计算
|
|
||||||
if (tipLen == null || sizeZ == null) return;
|
|
||||||
|
|
||||||
if (changedId === 'f-tip_above') {
|
|
||||||
// 用户填了 tip_above → 算 dz
|
|
||||||
if (above != null) _setVal('f-grid_dz', above + sizeZ - tipLen);
|
|
||||||
} else if (changedId === 'f-grid_dz') {
|
|
||||||
// 用户填了 dz → 算 tip_above
|
|
||||||
if (dz != null) _setVal('f-tip_above', tipLen - sizeZ + dz);
|
|
||||||
} else {
|
|
||||||
// size_z 或 tip_length 变了 → 优先重算 tip_above(若已有值或 dz 已有值)
|
|
||||||
if (dz != null) {
|
|
||||||
_setVal('f-tip_above', tipLen - sizeZ + dz);
|
|
||||||
} else if (above != null) {
|
|
||||||
_setVal('f-grid_dz', above + sizeZ - tipLen);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 绑定 input 事件
|
|
||||||
for (const id of ['f-tip_len', 'f-size_z', 'f-grid_dz', 'f-tip_above']) {
|
|
||||||
const el = document.getElementById(id);
|
|
||||||
if (el) el.addEventListener('input', () => autoCalcTipAbove(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 编辑已有 tip_rack 条目时自动补算 tip_above_rack_length
|
|
||||||
const typeEl = document.getElementById('f-type');
|
|
||||||
if (typeEl && typeEl.value === 'tip_rack') {
|
|
||||||
autoCalcTipAbove('f-grid_dz');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// 自动居中:根据板尺寸和孔阵列参数计算 dx/dy
|
|
||||||
function autoCenter() {
|
|
||||||
const g = id => { const el = document.getElementById(id); return el && el.value !== '' ? parseFloat(el.value) : 0; };
|
|
||||||
|
|
||||||
const sizeX = g('f-size_x') || 127;
|
|
||||||
const sizeY = g('f-size_y') || 85;
|
|
||||||
const nx = g('f-grid_nx') || 1;
|
|
||||||
const ny = g('f-grid_ny') || 1;
|
|
||||||
const itemDx = g('f-grid_idx') || 9;
|
|
||||||
const itemDy = g('f-grid_idy') || 9;
|
|
||||||
|
|
||||||
// 根据当前耗材类型确定子元素尺寸
|
|
||||||
const type = document.getElementById('f-type').value;
|
|
||||||
let childSx = 0, childSy = 0;
|
|
||||||
if (type === 'plate') {
|
|
||||||
childSx = g('f-well_sx') || 8;
|
|
||||||
childSy = g('f-well_sy') || 8;
|
|
||||||
} else if (type === 'tip_rack') {
|
|
||||||
childSx = g('f-tip_sx') || 7;
|
|
||||||
childSy = g('f-tip_sy') || 7;
|
|
||||||
} else if (type === 'tube_rack') {
|
|
||||||
childSx = g('f-tube_sx') || 10.6;
|
|
||||||
childSy = g('f-tube_sy') || 10.6;
|
|
||||||
}
|
|
||||||
|
|
||||||
// dx = (板宽 - 孔阵列总占宽) / 2
|
|
||||||
const dx = (sizeX - (nx - 1) * itemDx - childSx) / 2;
|
|
||||||
const dy = (sizeY - (ny - 1) * itemDy - childSy) / 2;
|
|
||||||
|
|
||||||
const elDx = document.getElementById('f-grid_dx');
|
|
||||||
const elDy = document.getElementById('f-grid_dy');
|
|
||||||
if (elDx) elDx.value = Math.round(dx * 100) / 100;
|
|
||||||
if (elDy) elDy.value = Math.round(dy * 100) / 100;
|
|
||||||
|
|
||||||
updatePreview();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 保存
|
|
||||||
function showMsg(text, ok) {
|
|
||||||
const el = document.getElementById('status-msg');
|
|
||||||
if (!el) return;
|
|
||||||
el.textContent = text;
|
|
||||||
el.className = 'status-msg ' + (ok ? 'msg-ok' : 'msg-err');
|
|
||||||
el.style.display = 'block';
|
|
||||||
setTimeout(() => el.style.display = 'none', 4000);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function saveForm() {
|
|
||||||
const data = collectFormData();
|
|
||||||
|
|
||||||
let url, method;
|
|
||||||
if (typeof IS_NEW !== 'undefined' && IS_NEW) {
|
|
||||||
url = '/api/labware';
|
|
||||||
method = 'POST';
|
|
||||||
} else {
|
|
||||||
url = '/api/labware/' + (typeof ITEM_ID !== 'undefined' ? ITEM_ID : '');
|
|
||||||
method = 'PUT';
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const r = await fetch(url, {
|
|
||||||
method: method,
|
|
||||||
headers: { 'Content-Type': 'application/json' },
|
|
||||||
body: JSON.stringify(data),
|
|
||||||
});
|
|
||||||
const d = await r.json();
|
|
||||||
if (d.status === 'ok') {
|
|
||||||
showMsg('保存成功', true);
|
|
||||||
if (IS_NEW) {
|
|
||||||
setTimeout(() => location.href = '/labware/' + data.function_name, 500);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
showMsg('保存失败: ' + JSON.stringify(d), false);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
showMsg('请求错误: ' + e.message, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,450 +0,0 @@
|
|||||||
/**
|
|
||||||
* labware_viz.js — PRCXI 耗材 SVG 2D 可视化渲染引擎
|
|
||||||
*
|
|
||||||
* renderTopDown(container, itemData) — 俯视图
|
|
||||||
* renderSideProfile(container, itemData) — 侧面截面图
|
|
||||||
*/
|
|
||||||
|
|
||||||
const TYPE_COLORS = {
|
|
||||||
plate: '#3b82f6',
|
|
||||||
tip_rack: '#10b981',
|
|
||||||
tube_rack: '#f59e0b',
|
|
||||||
trash: '#ef4444',
|
|
||||||
plate_adapter: '#8b5cf6',
|
|
||||||
};
|
|
||||||
|
|
||||||
function _svgNS() { return 'http://www.w3.org/2000/svg'; }
|
|
||||||
|
|
||||||
function _makeSVG(w, h) {
|
|
||||||
const svg = document.createElementNS(_svgNS(), 'svg');
|
|
||||||
svg.setAttribute('viewBox', `0 0 ${w} ${h}`);
|
|
||||||
svg.setAttribute('width', '100%');
|
|
||||||
svg.setAttribute('preserveAspectRatio', 'xMidYMid meet');
|
|
||||||
svg.style.background = '#fff';
|
|
||||||
return svg;
|
|
||||||
}
|
|
||||||
|
|
||||||
function _rect(svg, x, y, w, h, fill, stroke, rx) {
|
|
||||||
const r = document.createElementNS(_svgNS(), 'rect');
|
|
||||||
r.setAttribute('x', x); r.setAttribute('y', y);
|
|
||||||
r.setAttribute('width', w); r.setAttribute('height', h);
|
|
||||||
r.setAttribute('fill', fill || 'none');
|
|
||||||
r.setAttribute('stroke', stroke || '#333');
|
|
||||||
r.setAttribute('stroke-width', '0.5');
|
|
||||||
if (rx) r.setAttribute('rx', rx);
|
|
||||||
svg.appendChild(r);
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
function _circle(svg, cx, cy, r, fill, stroke) {
|
|
||||||
const c = document.createElementNS(_svgNS(), 'circle');
|
|
||||||
c.setAttribute('cx', cx); c.setAttribute('cy', cy);
|
|
||||||
c.setAttribute('r', r);
|
|
||||||
c.setAttribute('fill', fill || 'none');
|
|
||||||
c.setAttribute('stroke', stroke || '#333');
|
|
||||||
c.setAttribute('stroke-width', '0.4');
|
|
||||||
svg.appendChild(c);
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
function _text(svg, x, y, txt, size, anchor, fill) {
|
|
||||||
const t = document.createElementNS(_svgNS(), 'text');
|
|
||||||
t.setAttribute('x', x); t.setAttribute('y', y);
|
|
||||||
t.setAttribute('font-size', size || '3');
|
|
||||||
t.setAttribute('text-anchor', anchor || 'middle');
|
|
||||||
t.setAttribute('fill', fill || '#666');
|
|
||||||
t.setAttribute('font-family', 'sans-serif');
|
|
||||||
t.textContent = txt;
|
|
||||||
svg.appendChild(t);
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
|
|
||||||
function _line(svg, x1, y1, x2, y2, stroke, dash) {
|
|
||||||
const l = document.createElementNS(_svgNS(), 'line');
|
|
||||||
l.setAttribute('x1', x1); l.setAttribute('y1', y1);
|
|
||||||
l.setAttribute('x2', x2); l.setAttribute('y2', y2);
|
|
||||||
l.setAttribute('stroke', stroke || '#999');
|
|
||||||
l.setAttribute('stroke-width', '0.3');
|
|
||||||
if (dash) l.setAttribute('stroke-dasharray', dash);
|
|
||||||
svg.appendChild(l);
|
|
||||||
return l;
|
|
||||||
}
|
|
||||||
|
|
||||||
function _title(el, txt) {
|
|
||||||
const t = document.createElementNS(_svgNS(), 'title');
|
|
||||||
t.textContent = txt;
|
|
||||||
el.appendChild(t);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ==================== 俯视图 ====================
|
|
||||||
function renderTopDown(container, data) {
|
|
||||||
container.innerHTML = '';
|
|
||||||
if (!data) return;
|
|
||||||
|
|
||||||
const pad = 18;
|
|
||||||
const sx = data.size_x || 127;
|
|
||||||
const sy = data.size_y || 85;
|
|
||||||
const w = sx + pad * 2;
|
|
||||||
const h = sy + pad * 2;
|
|
||||||
const svg = _makeSVG(w, h);
|
|
||||||
|
|
||||||
const color = TYPE_COLORS[data.type] || '#3b82f6';
|
|
||||||
const lightColor = color + '22';
|
|
||||||
|
|
||||||
// 板子外轮廓
|
|
||||||
_rect(svg, pad, pad, sx, sy, lightColor, color, 3);
|
|
||||||
|
|
||||||
// 尺寸标注
|
|
||||||
_text(svg, pad + sx / 2, pad - 4, `${sx} mm`, '3.5', 'middle', '#333');
|
|
||||||
// Y 尺寸 (竖直)
|
|
||||||
const yt = document.createElementNS(_svgNS(), 'text');
|
|
||||||
yt.setAttribute('x', pad - 5);
|
|
||||||
yt.setAttribute('y', pad + sy / 2);
|
|
||||||
yt.setAttribute('font-size', '3.5');
|
|
||||||
yt.setAttribute('text-anchor', 'middle');
|
|
||||||
yt.setAttribute('fill', '#333');
|
|
||||||
yt.setAttribute('font-family', 'sans-serif');
|
|
||||||
yt.setAttribute('transform', `rotate(-90, ${pad - 5}, ${pad + sy / 2})`);
|
|
||||||
yt.textContent = `${sy} mm`;
|
|
||||||
svg.appendChild(yt);
|
|
||||||
|
|
||||||
const grid = data.grid;
|
|
||||||
const well = data.well;
|
|
||||||
const tip = data.tip;
|
|
||||||
const tube = data.tube;
|
|
||||||
|
|
||||||
if (grid && (well || tip || tube)) {
|
|
||||||
const nx = grid.num_items_x || 1;
|
|
||||||
const ny = grid.num_items_y || 1;
|
|
||||||
const dx = grid.dx || 0;
|
|
||||||
const dy = grid.dy || 0;
|
|
||||||
const idx = grid.item_dx || 9;
|
|
||||||
const idy = grid.item_dy || 9;
|
|
||||||
|
|
||||||
const child = well || tip || tube;
|
|
||||||
const csx = child.size_x || child.spot_size_x || 8;
|
|
||||||
const csy = child.size_y || child.spot_size_y || 8;
|
|
||||||
|
|
||||||
const isCircle = well ? (well.cross_section_type === 'CIRCLE') : (!!tip);
|
|
||||||
|
|
||||||
// 行列标签
|
|
||||||
for (let col = 0; col < nx; col++) {
|
|
||||||
const cx = pad + dx + csx / 2 + col * idx;
|
|
||||||
_text(svg, cx, pad + sy + 5, String(col + 1), '2.5', 'middle', '#999');
|
|
||||||
}
|
|
||||||
const rowLabels = 'ABCDEFGHIJKLMNOP';
|
|
||||||
for (let row = 0; row < ny; row++) {
|
|
||||||
const cy = pad + dy + csy / 2 + row * idy;
|
|
||||||
_text(svg, pad - 4, cy + 1, rowLabels[row] || String(row), '2.5', 'middle', '#999');
|
|
||||||
}
|
|
||||||
|
|
||||||
// 绘制孔位
|
|
||||||
for (let col = 0; col < nx; col++) {
|
|
||||||
for (let row = 0; row < ny; row++) {
|
|
||||||
const cx = pad + dx + csx / 2 + col * idx;
|
|
||||||
const cy = pad + dy + csy / 2 + row * idy;
|
|
||||||
|
|
||||||
let el;
|
|
||||||
if (isCircle) {
|
|
||||||
const r = Math.min(csx, csy) / 2;
|
|
||||||
el = _circle(svg, cx, cy, r, '#fff', color);
|
|
||||||
} else {
|
|
||||||
el = _rect(svg, cx - csx / 2, cy - csy / 2, csx, csy, '#fff', color);
|
|
||||||
}
|
|
||||||
|
|
||||||
const label = (rowLabels[row] || '') + String(col + 1);
|
|
||||||
_title(el, `${label}: ${csx}x${csy} mm`);
|
|
||||||
|
|
||||||
// hover 效果
|
|
||||||
el.style.cursor = 'pointer';
|
|
||||||
el.addEventListener('mouseenter', () => el.setAttribute('fill', color + '44'));
|
|
||||||
el.addEventListener('mouseleave', () => el.setAttribute('fill', '#fff'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// dx / dy 标注(板边到首个子元素左上角)
|
|
||||||
const dimColor = '#e67e22';
|
|
||||||
const firstLeft = pad + dx; // 首列子元素左边 X
|
|
||||||
const firstTop = pad + dy; // 首行子元素上边 Y
|
|
||||||
if (dx > 0.1) {
|
|
||||||
// dx: 板左边 → 首列子元素左边,画在第一行子元素中心高度
|
|
||||||
const annY = firstTop + csy / 2;
|
|
||||||
_line(svg, pad, annY, firstLeft, annY, dimColor, '1,1');
|
|
||||||
_line(svg, pad, annY - 2, pad, annY + 2, dimColor);
|
|
||||||
_line(svg, firstLeft, annY - 2, firstLeft, annY + 2, dimColor);
|
|
||||||
_text(svg, pad + dx / 2, annY - 2, `dx=${dx}`, '2.5', 'middle', dimColor);
|
|
||||||
}
|
|
||||||
if (dy > 0.1) {
|
|
||||||
// dy: 板上边 → 首行子元素上边,画在第一列子元素中心宽度
|
|
||||||
const annX = firstLeft + csx / 2;
|
|
||||||
_line(svg, annX, pad, annX, firstTop, dimColor, '1,1');
|
|
||||||
_line(svg, annX - 2, pad, annX + 2, pad, dimColor);
|
|
||||||
_line(svg, annX - 2, firstTop, annX + 2, firstTop, dimColor);
|
|
||||||
_text(svg, annX + 4, pad + dy / 2 + 1, `dy=${dy}`, '2.5', 'start', dimColor);
|
|
||||||
}
|
|
||||||
} else if (data.type === 'plate_adapter' && data.adapter) {
|
|
||||||
// 绘制适配器凹槽
|
|
||||||
const adp = data.adapter;
|
|
||||||
const ahx = adp.adapter_hole_size_x || 127;
|
|
||||||
const ahy = adp.adapter_hole_size_y || 85;
|
|
||||||
const adx = adp.dx != null ? adp.dx : (sx - ahx) / 2;
|
|
||||||
const ady = adp.dy != null ? adp.dy : (sy - ahy) / 2;
|
|
||||||
_rect(svg, pad + adx, pad + ady, ahx, ahy, '#f0f0ff', '#8b5cf6', 2);
|
|
||||||
_text(svg, pad + adx + ahx / 2, pad + ady + ahy / 2, `${ahx}x${ahy}`, '4', 'middle', '#8b5cf6');
|
|
||||||
} else if (data.type === 'trash') {
|
|
||||||
// 简单标记
|
|
||||||
_text(svg, pad + sx / 2, pad + sy / 2, 'TRASH', '8', 'middle', '#ef4444');
|
|
||||||
}
|
|
||||||
|
|
||||||
container.appendChild(svg);
|
|
||||||
_enableZoomPan(svg, `0 0 ${w} ${h}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ==================== 侧面截面图 ====================
|
|
||||||
function renderSideProfile(container, data) {
|
|
||||||
container.innerHTML = '';
|
|
||||||
if (!data) return;
|
|
||||||
|
|
||||||
const pad = 20;
|
|
||||||
const sx = data.size_x || 127;
|
|
||||||
const sz = data.size_z || 20;
|
|
||||||
|
|
||||||
// 按比例缩放,侧面以 X-Z 面
|
|
||||||
const scaleH = Math.max(1, sz / 60); // 让较矮的板子不会太小
|
|
||||||
|
|
||||||
// 计算枪头露出高度(仅 tip_rack)
|
|
||||||
const tip = data.tip;
|
|
||||||
const grid = data.grid;
|
|
||||||
let tipAbove = 0;
|
|
||||||
if (data.type === 'tip_rack' && tip) {
|
|
||||||
if (tip.tip_above_rack_length != null && tip.tip_above_rack_length > 0) {
|
|
||||||
tipAbove = tip.tip_above_rack_length;
|
|
||||||
} else if (tip.tip_length && grid) {
|
|
||||||
const dz = grid.dz || 0;
|
|
||||||
const calc = tip.tip_length - (sz - dz);
|
|
||||||
if (calc > 0) tipAbove = calc;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const drawW = sx;
|
|
||||||
const drawH = sz;
|
|
||||||
const w = drawW + pad * 2 + 30; // 额外空间给标注
|
|
||||||
const h = drawH + tipAbove + pad * 2 + 10;
|
|
||||||
const svg = _makeSVG(w, h);
|
|
||||||
|
|
||||||
const color = TYPE_COLORS[data.type] || '#3b82f6';
|
|
||||||
const baseY = pad + tipAbove + drawH; // 底部 Y
|
|
||||||
const rackTopY = pad + tipAbove; // rack 顶部 Y
|
|
||||||
|
|
||||||
// 板壳矩形
|
|
||||||
_rect(svg, pad, rackTopY, drawW, drawH, color + '15', color);
|
|
||||||
|
|
||||||
// 尺寸标注
|
|
||||||
// X 方向
|
|
||||||
_line(svg, pad, baseY + 5, pad + drawW, baseY + 5, '#333');
|
|
||||||
_text(svg, pad + drawW / 2, baseY + 12, `${sx} mm`, '3.5', 'middle', '#333');
|
|
||||||
|
|
||||||
// Z 方向
|
|
||||||
_line(svg, pad + drawW + 5, rackTopY, pad + drawW + 5, baseY, '#333');
|
|
||||||
const zt = document.createElementNS(_svgNS(), 'text');
|
|
||||||
zt.setAttribute('x', pad + drawW + 12);
|
|
||||||
zt.setAttribute('y', rackTopY + drawH / 2);
|
|
||||||
zt.setAttribute('font-size', '3.5');
|
|
||||||
zt.setAttribute('text-anchor', 'middle');
|
|
||||||
zt.setAttribute('fill', '#333');
|
|
||||||
zt.setAttribute('font-family', 'sans-serif');
|
|
||||||
zt.setAttribute('transform', `rotate(-90, ${pad + drawW + 12}, ${rackTopY + drawH / 2})`);
|
|
||||||
zt.textContent = `${sz} mm`;
|
|
||||||
svg.appendChild(zt);
|
|
||||||
|
|
||||||
const well = data.well;
|
|
||||||
const tube = data.tube;
|
|
||||||
|
|
||||||
if (grid && (well || tip || tube)) {
|
|
||||||
const dx = grid.dx || 0;
|
|
||||||
const dz = grid.dz || 0;
|
|
||||||
const idx = grid.item_dx || 9;
|
|
||||||
const nx = Math.min(grid.num_items_x || 1, 24); // 最多画24列
|
|
||||||
const dimColor = '#e67e22';
|
|
||||||
|
|
||||||
const child = well || tube;
|
|
||||||
const childTip = tip;
|
|
||||||
|
|
||||||
if (child) {
|
|
||||||
const csx = child.size_x || 8;
|
|
||||||
const csz = child.size_z || 10;
|
|
||||||
const bt = well ? (well.bottom_type || 'FLAT') : 'FLAT';
|
|
||||||
|
|
||||||
// 画几个代表性的孔截面
|
|
||||||
const nDraw = Math.min(nx, 12);
|
|
||||||
for (let i = 0; i < nDraw; i++) {
|
|
||||||
const cx = pad + dx + csx / 2 + i * idx;
|
|
||||||
const topZ = baseY - dz - csz;
|
|
||||||
const botZ = baseY - dz;
|
|
||||||
|
|
||||||
// 孔壁
|
|
||||||
_rect(svg, cx - csx / 2, topZ, csx, csz, '#e0e8ff', color, 0.5);
|
|
||||||
|
|
||||||
// 底部形状
|
|
||||||
if (bt === 'V') {
|
|
||||||
// V 底 三角
|
|
||||||
const triH = Math.min(csx / 2, csz * 0.3);
|
|
||||||
const p = document.createElementNS(_svgNS(), 'polygon');
|
|
||||||
p.setAttribute('points',
|
|
||||||
`${cx - csx / 2},${botZ - triH} ${cx},${botZ} ${cx + csx / 2},${botZ - triH}`);
|
|
||||||
p.setAttribute('fill', color + '33');
|
|
||||||
p.setAttribute('stroke', color);
|
|
||||||
p.setAttribute('stroke-width', '0.3');
|
|
||||||
svg.appendChild(p);
|
|
||||||
} else if (bt === 'U') {
|
|
||||||
// U 底 圆弧
|
|
||||||
const arcR = csx / 2;
|
|
||||||
const p = document.createElementNS(_svgNS(), 'path');
|
|
||||||
p.setAttribute('d', `M ${cx - csx / 2} ${botZ - arcR} A ${arcR} ${arcR} 0 0 0 ${cx + csx / 2} ${botZ - arcR}`);
|
|
||||||
p.setAttribute('fill', color + '33');
|
|
||||||
p.setAttribute('stroke', color);
|
|
||||||
p.setAttribute('stroke-width', '0.3');
|
|
||||||
svg.appendChild(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// dz 标注
|
|
||||||
if (dz > 0) {
|
|
||||||
const lx = pad + dx + 0.5 * idx * nDraw + csx / 2 + 5;
|
|
||||||
_line(svg, lx, baseY, lx, baseY - dz, dimColor, '1,1');
|
|
||||||
_line(svg, lx - 2, baseY, lx + 2, baseY, dimColor);
|
|
||||||
_line(svg, lx - 2, baseY - dz, lx + 2, baseY - dz, dimColor);
|
|
||||||
_text(svg, lx + 4, baseY - dz / 2 + 1, `dz=${dz}`, '2.5', 'start', dimColor);
|
|
||||||
}
|
|
||||||
// dx 标注
|
|
||||||
if (dx > 0.1) {
|
|
||||||
const annY = rackTopY + 4;
|
|
||||||
_line(svg, pad, annY, pad + dx, annY, dimColor, '1,1');
|
|
||||||
_line(svg, pad, annY - 2, pad, annY + 2, dimColor);
|
|
||||||
_line(svg, pad + dx, annY - 2, pad + dx, annY + 2, dimColor);
|
|
||||||
_text(svg, pad + dx / 2, annY - 2, `dx=${dx}`, '2.5', 'middle', dimColor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (childTip) {
|
|
||||||
// 枪头截面
|
|
||||||
const tipLen = childTip.tip_length || 50;
|
|
||||||
const nDraw = Math.min(nx, 12);
|
|
||||||
for (let i = 0; i < nDraw; i++) {
|
|
||||||
const cx = pad + dx + 3.5 + i * idx;
|
|
||||||
// 枪头顶部 = rack顶部 - 露出长度
|
|
||||||
const tipTopZ = rackTopY - tipAbove;
|
|
||||||
const drawLen = Math.min(tipLen, sz - dz + tipAbove);
|
|
||||||
|
|
||||||
// 枪头轮廓 (梯形)
|
|
||||||
const topW = 4;
|
|
||||||
const botW = 1.5;
|
|
||||||
const p = document.createElementNS(_svgNS(), 'polygon');
|
|
||||||
p.setAttribute('points',
|
|
||||||
`${cx - topW / 2},${tipTopZ} ${cx + topW / 2},${tipTopZ} ${cx + botW / 2},${tipTopZ + drawLen} ${cx - botW / 2},${tipTopZ + drawLen}`);
|
|
||||||
p.setAttribute('fill', '#10b98133');
|
|
||||||
p.setAttribute('stroke', '#10b981');
|
|
||||||
p.setAttribute('stroke-width', '0.3');
|
|
||||||
svg.appendChild(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
// dz 标注
|
|
||||||
if (dz > 0) {
|
|
||||||
const lx = pad + dx + nDraw * idx + 5;
|
|
||||||
_line(svg, lx, baseY, lx, baseY - dz, dimColor, '1,1');
|
|
||||||
_line(svg, lx - 2, baseY, lx + 2, baseY, dimColor);
|
|
||||||
_line(svg, lx - 2, baseY - dz, lx + 2, baseY - dz, dimColor);
|
|
||||||
_text(svg, lx + 4, baseY - dz / 2 + 1, `dz=${dz}`, '2.5', 'start', dimColor);
|
|
||||||
}
|
|
||||||
// dx 标注
|
|
||||||
if (dx > 0.1) {
|
|
||||||
const annY = rackTopY + 4;
|
|
||||||
_line(svg, pad, annY, pad + dx, annY, dimColor, '1,1');
|
|
||||||
_line(svg, pad, annY - 2, pad, annY + 2, dimColor);
|
|
||||||
_line(svg, pad + dx, annY - 2, pad + dx, annY + 2, dimColor);
|
|
||||||
_text(svg, pad + dx / 2, annY - 2, `dx=${dx}`, '2.5', 'middle', dimColor);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 露出长度标注线
|
|
||||||
if (tipAbove > 0) {
|
|
||||||
const annotX = pad + dx + nDraw * idx + 8;
|
|
||||||
// rack 顶部水平参考线
|
|
||||||
_line(svg, annotX - 3, rackTopY, annotX + 3, rackTopY, '#10b981');
|
|
||||||
// 枪头顶部水平参考线
|
|
||||||
_line(svg, annotX - 3, rackTopY - tipAbove, annotX + 3, rackTopY - tipAbove, '#10b981');
|
|
||||||
// 竖直标注线
|
|
||||||
_line(svg, annotX, rackTopY - tipAbove, annotX, rackTopY, '#10b981', '1,1');
|
|
||||||
_text(svg, annotX + 2, rackTopY - tipAbove / 2 + 1, `露出=${Math.round(tipAbove * 100) / 100}mm`, '2.5', 'start', '#10b981');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (data.type === 'plate_adapter' && data.adapter) {
|
|
||||||
const adp = data.adapter;
|
|
||||||
const ahz = adp.adapter_hole_size_z || 10;
|
|
||||||
const adz = adp.dz || 0;
|
|
||||||
const adx_val = adp.dx != null ? adp.dx : (sx - (adp.adapter_hole_size_x || 127)) / 2;
|
|
||||||
const ahx = adp.adapter_hole_size_x || 127;
|
|
||||||
|
|
||||||
// 凹槽截面
|
|
||||||
_rect(svg, pad + adx_val, rackTopY + adz, ahx, ahz, '#ede9fe', '#8b5cf6');
|
|
||||||
_text(svg, pad + adx_val + ahx / 2, rackTopY + adz + ahz / 2 + 1, `hole: ${ahz}mm deep`, '3', 'middle', '#8b5cf6');
|
|
||||||
} else if (data.type === 'trash') {
|
|
||||||
_text(svg, pad + drawW / 2, rackTopY + drawH / 2, 'TRASH', '8', 'middle', '#ef4444');
|
|
||||||
}
|
|
||||||
|
|
||||||
container.appendChild(svg);
|
|
||||||
_enableZoomPan(svg, `0 0 ${w} ${h}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ==================== 缩放 & 平移 ====================
|
|
||||||
function _enableZoomPan(svgEl, origViewBox) {
|
|
||||||
const parts = origViewBox.split(' ').map(Number);
|
|
||||||
let vx = parts[0], vy = parts[1], vw = parts[2], vh = parts[3];
|
|
||||||
const origVx = vx, origVy = vy, origW = vw, origH = vh;
|
|
||||||
const MIN_SCALE = 0.5, MAX_SCALE = 5;
|
|
||||||
|
|
||||||
function applyViewBox() {
|
|
||||||
svgEl.setAttribute('viewBox', `${vx} ${vy} ${vw} ${vh}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
function resetView() {
|
|
||||||
vx = origVx; vy = origVy; vw = origW; vh = origH;
|
|
||||||
applyViewBox();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 将 resetView 挂到 svg 元素上,方便外部调用
|
|
||||||
svgEl._resetView = resetView;
|
|
||||||
|
|
||||||
svgEl.addEventListener('wheel', function (e) {
|
|
||||||
e.preventDefault();
|
|
||||||
if (e.ctrlKey) {
|
|
||||||
// pinch / ctrl+scroll → 缩放
|
|
||||||
const factor = e.deltaY > 0 ? 1.08 : 1 / 1.08;
|
|
||||||
const newW = vw * factor;
|
|
||||||
const newH = vh * factor;
|
|
||||||
// 限制缩放范围
|
|
||||||
if (newW < origW / MAX_SCALE || newW > origW * (1 / MIN_SCALE)) return;
|
|
||||||
// 以鼠标位置为缩放中心
|
|
||||||
const rect = svgEl.getBoundingClientRect();
|
|
||||||
const mx = (e.clientX - rect.left) / rect.width;
|
|
||||||
const my = (e.clientY - rect.top) / rect.height;
|
|
||||||
vx += (vw - newW) * mx;
|
|
||||||
vy += (vh - newH) * my;
|
|
||||||
vw = newW;
|
|
||||||
vh = newH;
|
|
||||||
} else {
|
|
||||||
// 普通滚轮 → 平移
|
|
||||||
const panSpeed = vw * 0.002;
|
|
||||||
vx += e.deltaX * panSpeed;
|
|
||||||
vy += e.deltaY * panSpeed;
|
|
||||||
}
|
|
||||||
applyViewBox();
|
|
||||||
}, { passive: false });
|
|
||||||
}
|
|
||||||
|
|
||||||
// 回中按钮:重置指定容器内 SVG 的 viewBox
|
|
||||||
function resetSvgView(containerId) {
|
|
||||||
const container = document.getElementById(containerId);
|
|
||||||
if (!container) return;
|
|
||||||
const svg = container.querySelector('svg');
|
|
||||||
if (svg && svg._resetView) svg._resetView();
|
|
||||||
}
|
|
||||||
@@ -1,295 +0,0 @@
|
|||||||
/* PRCXI 耗材管理 - 全局样式 */
|
|
||||||
|
|
||||||
:root {
|
|
||||||
--c-primary: #3b82f6;
|
|
||||||
--c-primary-dark: #2563eb;
|
|
||||||
--c-danger: #ef4444;
|
|
||||||
--c-warning: #f59e0b;
|
|
||||||
--c-success: #10b981;
|
|
||||||
--c-gray-50: #f9fafb;
|
|
||||||
--c-gray-100: #f3f4f6;
|
|
||||||
--c-gray-200: #e5e7eb;
|
|
||||||
--c-gray-300: #d1d5db;
|
|
||||||
--c-gray-500: #6b7280;
|
|
||||||
--c-gray-700: #374151;
|
|
||||||
--c-gray-900: #111827;
|
|
||||||
--radius: 8px;
|
|
||||||
--shadow: 0 1px 3px rgba(0,0,0,0.1);
|
|
||||||
}
|
|
||||||
|
|
||||||
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
||||||
|
|
||||||
body {
|
|
||||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
||||||
background: var(--c-gray-50);
|
|
||||||
color: var(--c-gray-900);
|
|
||||||
line-height: 1.5;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 顶部导航 */
|
|
||||||
.topbar {
|
|
||||||
background: #fff;
|
|
||||||
border-bottom: 1px solid var(--c-gray-200);
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: space-between;
|
|
||||||
padding: 0 24px;
|
|
||||||
height: 56px;
|
|
||||||
position: sticky;
|
|
||||||
top: 0;
|
|
||||||
z-index: 100;
|
|
||||||
}
|
|
||||||
.topbar .logo {
|
|
||||||
font-weight: 700;
|
|
||||||
font-size: 1.1rem;
|
|
||||||
color: var(--c-gray-900);
|
|
||||||
text-decoration: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 容器 */
|
|
||||||
.container {
|
|
||||||
max-width: 1400px;
|
|
||||||
margin: 0 auto;
|
|
||||||
padding: 24px;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 页头 */
|
|
||||||
.page-header {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: space-between;
|
|
||||||
margin-bottom: 24px;
|
|
||||||
flex-wrap: wrap;
|
|
||||||
gap: 12px;
|
|
||||||
}
|
|
||||||
.page-header h1 { font-size: 1.5rem; }
|
|
||||||
.header-actions { display: flex; gap: 8px; flex-wrap: wrap; }
|
|
||||||
|
|
||||||
/* 按钮 */
|
|
||||||
.btn {
|
|
||||||
display: inline-flex;
|
|
||||||
align-items: center;
|
|
||||||
padding: 8px 16px;
|
|
||||||
border-radius: 6px;
|
|
||||||
font-size: 0.875rem;
|
|
||||||
font-weight: 500;
|
|
||||||
cursor: pointer;
|
|
||||||
border: 1px solid transparent;
|
|
||||||
text-decoration: none;
|
|
||||||
transition: all 0.15s;
|
|
||||||
white-space: nowrap;
|
|
||||||
}
|
|
||||||
.btn-sm { padding: 4px 10px; font-size: 0.8rem; }
|
|
||||||
.btn-primary { background: var(--c-primary); color: #fff; }
|
|
||||||
.btn-primary:hover { background: var(--c-primary-dark); }
|
|
||||||
.btn-outline { background: #fff; color: var(--c-gray-700); border-color: var(--c-gray-300); }
|
|
||||||
.btn-outline:hover { background: var(--c-gray-100); }
|
|
||||||
.btn-danger { background: var(--c-danger); color: #fff; }
|
|
||||||
.btn-danger:hover { background: #dc2626; }
|
|
||||||
.btn-warning { background: var(--c-warning); color: #fff; }
|
|
||||||
.btn-warning:hover { background: #d97706; }
|
|
||||||
|
|
||||||
/* 徽章 */
|
|
||||||
.badge {
|
|
||||||
background: var(--c-gray-200);
|
|
||||||
color: var(--c-gray-700);
|
|
||||||
font-size: 0.8rem;
|
|
||||||
padding: 2px 8px;
|
|
||||||
border-radius: 12px;
|
|
||||||
font-weight: 500;
|
|
||||||
margin-left: 4px;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 状态消息 */
|
|
||||||
.status-msg {
|
|
||||||
padding: 12px 16px;
|
|
||||||
border-radius: var(--radius);
|
|
||||||
margin-bottom: 16px;
|
|
||||||
font-size: 0.9rem;
|
|
||||||
}
|
|
||||||
.msg-ok { background: #d1fae5; color: #065f46; }
|
|
||||||
.msg-err { background: #fee2e2; color: #991b1b; }
|
|
||||||
|
|
||||||
/* 类型分段 */
|
|
||||||
.type-section { margin-bottom: 32px; }
|
|
||||||
.type-section h2 {
|
|
||||||
font-size: 1.1rem;
|
|
||||||
margin-bottom: 12px;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 8px;
|
|
||||||
}
|
|
||||||
.type-dot {
|
|
||||||
width: 12px;
|
|
||||||
height: 12px;
|
|
||||||
border-radius: 50%;
|
|
||||||
display: inline-block;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 卡片网格 */
|
|
||||||
.card-grid {
|
|
||||||
display: grid;
|
|
||||||
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
|
|
||||||
gap: 12px;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 耗材卡片 */
|
|
||||||
.labware-card {
|
|
||||||
background: #fff;
|
|
||||||
border: 1px solid var(--c-gray-200);
|
|
||||||
border-radius: var(--radius);
|
|
||||||
padding: 16px;
|
|
||||||
cursor: pointer;
|
|
||||||
transition: box-shadow 0.2s, border-color 0.2s;
|
|
||||||
}
|
|
||||||
.labware-card:hover {
|
|
||||||
border-color: var(--c-primary);
|
|
||||||
box-shadow: 0 4px 12px rgba(59,130,246,0.15);
|
|
||||||
}
|
|
||||||
.card-header {
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
align-items: center;
|
|
||||||
margin-bottom: 8px;
|
|
||||||
}
|
|
||||||
.card-title {
|
|
||||||
font-weight: 600;
|
|
||||||
font-size: 0.9rem;
|
|
||||||
color: var(--c-gray-900);
|
|
||||||
word-break: break-all;
|
|
||||||
}
|
|
||||||
.card-body { font-size: 0.85rem; color: var(--c-gray-500); }
|
|
||||||
.card-info { margin-bottom: 2px; }
|
|
||||||
.card-info .label { color: var(--c-gray-700); font-weight: 500; }
|
|
||||||
.card-footer {
|
|
||||||
margin-top: 12px;
|
|
||||||
display: flex;
|
|
||||||
gap: 8px;
|
|
||||||
border-top: 1px solid var(--c-gray-100);
|
|
||||||
padding-top: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 标签 */
|
|
||||||
.tag {
|
|
||||||
font-size: 0.7rem;
|
|
||||||
padding: 2px 6px;
|
|
||||||
border-radius: 4px;
|
|
||||||
font-weight: 600;
|
|
||||||
text-transform: uppercase;
|
|
||||||
}
|
|
||||||
.tag-tpl { background: #dbeafe; color: #1e40af; }
|
|
||||||
.tag-plate { background: #dbeafe; color: #1e40af; }
|
|
||||||
.tag-tip_rack { background: #d1fae5; color: #065f46; }
|
|
||||||
.tag-trash { background: #fee2e2; color: #991b1b; }
|
|
||||||
.tag-tube_rack { background: #fef3c7; color: #92400e; }
|
|
||||||
.tag-plate_adapter { background: #ede9fe; color: #5b21b6; }
|
|
||||||
|
|
||||||
/* 详情页布局 */
|
|
||||||
.detail-layout {
|
|
||||||
display: grid;
|
|
||||||
grid-template-columns: 1fr 1fr;
|
|
||||||
gap: 24px;
|
|
||||||
}
|
|
||||||
@media (max-width: 900px) {
|
|
||||||
.detail-layout { grid-template-columns: 1fr; }
|
|
||||||
}
|
|
||||||
.detail-info, .detail-viz { display: flex; flex-direction: column; gap: 16px; }
|
|
||||||
|
|
||||||
.info-card, .viz-card {
|
|
||||||
background: #fff;
|
|
||||||
border: 1px solid var(--c-gray-200);
|
|
||||||
border-radius: var(--radius);
|
|
||||||
padding: 16px;
|
|
||||||
}
|
|
||||||
.info-card h3, .viz-card h3 {
|
|
||||||
font-size: 0.95rem;
|
|
||||||
margin-bottom: 12px;
|
|
||||||
color: var(--c-gray-700);
|
|
||||||
border-bottom: 1px solid var(--c-gray-100);
|
|
||||||
padding-bottom: 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.info-table { width: 100%; font-size: 0.85rem; }
|
|
||||||
.info-table td { padding: 4px 8px; border-bottom: 1px solid var(--c-gray-100); }
|
|
||||||
.info-table .label { color: var(--c-gray-500); font-weight: 500; width: 140px; }
|
|
||||||
.info-table code { background: var(--c-gray-100); padding: 1px 4px; border-radius: 3px; font-size: 0.8rem; }
|
|
||||||
.info-table code.small { font-size: 0.7rem; }
|
|
||||||
|
|
||||||
/* SVG 容器 */
|
|
||||||
#svg-topdown, #svg-side {
|
|
||||||
width: 100%;
|
|
||||||
min-height: 200px;
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
#svg-topdown svg, #svg-side svg {
|
|
||||||
display: block;
|
|
||||||
width: 100%;
|
|
||||||
height: auto;
|
|
||||||
touch-action: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 编辑页布局 */
|
|
||||||
.edit-layout {
|
|
||||||
display: grid;
|
|
||||||
grid-template-columns: 1fr 1fr;
|
|
||||||
gap: 24px;
|
|
||||||
}
|
|
||||||
@media (max-width: 900px) {
|
|
||||||
.edit-layout { grid-template-columns: 1fr; }
|
|
||||||
}
|
|
||||||
.edit-form { display: flex; flex-direction: column; gap: 16px; }
|
|
||||||
.edit-preview { display: flex; flex-direction: column; gap: 16px; position: sticky; top: 72px; align-self: start; }
|
|
||||||
|
|
||||||
/* 表单 */
|
|
||||||
.form-section {
|
|
||||||
background: #fff;
|
|
||||||
border: 1px solid var(--c-gray-200);
|
|
||||||
border-radius: var(--radius);
|
|
||||||
padding: 16px;
|
|
||||||
}
|
|
||||||
.form-section h3 {
|
|
||||||
font-size: 0.95rem;
|
|
||||||
margin-bottom: 12px;
|
|
||||||
color: var(--c-gray-700);
|
|
||||||
}
|
|
||||||
.form-row { margin-bottom: 10px; }
|
|
||||||
.form-row label { display: block; font-size: 0.8rem; color: var(--c-gray-500); margin-bottom: 4px; font-weight: 500; }
|
|
||||||
.form-row input, .form-row select, .form-row textarea {
|
|
||||||
width: 100%;
|
|
||||||
padding: 8px 10px;
|
|
||||||
border: 1px solid var(--c-gray-300);
|
|
||||||
border-radius: 6px;
|
|
||||||
font-size: 0.85rem;
|
|
||||||
font-family: inherit;
|
|
||||||
}
|
|
||||||
.form-row input:focus, .form-row select:focus, .form-row textarea:focus {
|
|
||||||
outline: none;
|
|
||||||
border-color: var(--c-primary);
|
|
||||||
box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
|
|
||||||
}
|
|
||||||
.form-row-2, .form-row-3 { display: grid; gap: 12px; margin-bottom: 10px; }
|
|
||||||
.form-row-2 { grid-template-columns: 1fr 1fr; }
|
|
||||||
.form-row-3 { grid-template-columns: 1fr 1fr 1fr; }
|
|
||||||
.form-row-2 label, .form-row-3 label { display: block; font-size: 0.8rem; color: var(--c-gray-500); margin-bottom: 4px; font-weight: 500; }
|
|
||||||
.form-row-2 input, .form-row-2 select,
|
|
||||||
.form-row-3 input, .form-row-3 select {
|
|
||||||
width: 100%;
|
|
||||||
padding: 8px 10px;
|
|
||||||
border: 1px solid var(--c-gray-300);
|
|
||||||
border-radius: 6px;
|
|
||||||
font-size: 0.85rem;
|
|
||||||
}
|
|
||||||
.form-row-2 input:focus, .form-row-3 input:focus {
|
|
||||||
outline: none;
|
|
||||||
border-color: var(--c-primary);
|
|
||||||
box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
|
|
||||||
}
|
|
||||||
|
|
||||||
.form-actions {
|
|
||||||
display: flex;
|
|
||||||
gap: 10px;
|
|
||||||
margin-top: 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 双语标签中文部分 */
|
|
||||||
.label-cn { color: var(--c-gray-400, #9ca3af); font-weight: 400; margin-left: 4px; }
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="zh-CN">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<title>{% block title %}PRCXI 耗材管理{% endblock %}</title>
|
|
||||||
<link rel="stylesheet" href="/static/style.css">
|
|
||||||
{% block head_extra %}{% endblock %}
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<nav class="topbar">
|
|
||||||
<a href="/" class="logo">PRCXI 耗材管理</a>
|
|
||||||
<div class="nav-actions">
|
|
||||||
<a href="/labware/new" class="btn btn-primary btn-sm">+ 新建耗材</a>
|
|
||||||
</div>
|
|
||||||
</nav>
|
|
||||||
|
|
||||||
<main class="container">
|
|
||||||
{% block content %}{% endblock %}
|
|
||||||
</main>
|
|
||||||
|
|
||||||
{% block scripts %}{% endblock %}
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,159 +0,0 @@
|
|||||||
{% extends "base.html" %}
|
|
||||||
{% block title %}{{ item.function_name }} - PRCXI{% endblock %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
<div class="page-header">
|
|
||||||
<h1>{{ item.function_name }}</h1>
|
|
||||||
<div class="header-actions">
|
|
||||||
<a href="/labware/{{ item.function_name }}/edit" class="btn btn-primary">编辑</a>
|
|
||||||
<a href="/" class="btn btn-outline">返回列表</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="detail-layout">
|
|
||||||
<!-- 左侧: 信息 -->
|
|
||||||
<div class="detail-info">
|
|
||||||
<div class="info-card">
|
|
||||||
<h3>基本信息</h3>
|
|
||||||
<table class="info-table">
|
|
||||||
<tr><td class="label">类型</td><td><span class="tag tag-{{ item.type }}">{{ item.type }}</span></td></tr>
|
|
||||||
<tr><td class="label">函数名</td><td><code>{{ item.function_name }}</code></td></tr>
|
|
||||||
<tr><td class="label">Model</td><td>{{ item.model or '-' }}</td></tr>
|
|
||||||
{% if item.plate_type %}
|
|
||||||
<tr><td class="label">Plate Type</td><td>{{ item.plate_type }}</td></tr>
|
|
||||||
{% endif %}
|
|
||||||
<tr><td class="label">Docstring</td><td>{{ item.docstring or '-' }}</td></tr>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="info-card">
|
|
||||||
<h3>物理尺寸 (mm)</h3>
|
|
||||||
<table class="info-table">
|
|
||||||
<tr><td class="label">X</td><td>{{ item.size_x }}</td></tr>
|
|
||||||
<tr><td class="label">Y</td><td>{{ item.size_y }}</td></tr>
|
|
||||||
<tr><td class="label">Z</td><td>{{ item.size_z }}</td></tr>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="info-card">
|
|
||||||
<h3>材料信息</h3>
|
|
||||||
<table class="info-table">
|
|
||||||
<tr><td class="label">UUID</td><td><code class="small">{{ item.material_info.uuid }}</code></td></tr>
|
|
||||||
<tr><td class="label">Code</td><td>{{ item.material_info.Code }}</td></tr>
|
|
||||||
<tr><td class="label">Name</td><td>{{ item.material_info.Name }}</td></tr>
|
|
||||||
{% if item.material_info.materialEnum is not none %}
|
|
||||||
<tr><td class="label">materialEnum</td><td>{{ item.material_info.materialEnum }}</td></tr>
|
|
||||||
{% endif %}
|
|
||||||
{% if item.material_info.SupplyType is not none %}
|
|
||||||
<tr><td class="label">SupplyType</td><td>{{ item.material_info.SupplyType }}</td></tr>
|
|
||||||
{% endif %}
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{% if item.grid %}
|
|
||||||
<div class="info-card">
|
|
||||||
<h3>网格排列</h3>
|
|
||||||
<table class="info-table">
|
|
||||||
<tr><td class="label">列 x 行</td><td>{{ item.grid.num_items_x }} x {{ item.grid.num_items_y }}</td></tr>
|
|
||||||
<tr><td class="label">dx, dy, dz</td><td>{{ item.grid.dx }}, {{ item.grid.dy }}, {{ item.grid.dz }}</td></tr>
|
|
||||||
<tr><td class="label">item_dx, item_dy</td><td>{{ item.grid.item_dx }}, {{ item.grid.item_dy }}</td></tr>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if item.well %}
|
|
||||||
<div class="info-card">
|
|
||||||
<h3>孔参数 (Well)</h3>
|
|
||||||
<table class="info-table">
|
|
||||||
<tr><td class="label">尺寸</td><td>{{ item.well.size_x }} x {{ item.well.size_y }} x {{ item.well.size_z }}</td></tr>
|
|
||||||
{% if item.well.max_volume is not none %}
|
|
||||||
<tr><td class="label">最大体积</td><td>{{ item.well.max_volume }} uL</td></tr>
|
|
||||||
{% endif %}
|
|
||||||
<tr><td class="label">底部类型</td><td>{{ item.well.bottom_type }}</td></tr>
|
|
||||||
<tr><td class="label">截面类型</td><td>{{ item.well.cross_section_type }}</td></tr>
|
|
||||||
{% if item.well.material_z_thickness is not none %}
|
|
||||||
<tr><td class="label">材料Z厚度</td><td>{{ item.well.material_z_thickness }}</td></tr>
|
|
||||||
{% endif %}
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if item.tip %}
|
|
||||||
<div class="info-card">
|
|
||||||
<h3>枪头参数 (Tip)</h3>
|
|
||||||
<table class="info-table">
|
|
||||||
<tr><td class="label">Spot 尺寸</td><td>{{ item.tip.spot_size_x }} x {{ item.tip.spot_size_y }} x {{ item.tip.spot_size_z }}</td></tr>
|
|
||||||
<tr><td class="label">容量</td><td>{{ item.tip.tip_volume }} uL</td></tr>
|
|
||||||
<tr><td class="label">长度</td><td>{{ item.tip.tip_length }} mm</td></tr>
|
|
||||||
<tr><td class="label">取枪头插入深度</td><td>{{ item.tip.tip_fitting_depth }} mm</td></tr>
|
|
||||||
{% if item.tip.tip_above_rack_length is not none %}
|
|
||||||
<tr><td class="label">枪头露出枪头盒长度</td><td>{{ item.tip.tip_above_rack_length }} mm</td></tr>
|
|
||||||
{% endif %}
|
|
||||||
<tr><td class="label">有滤芯</td><td>{{ item.tip.has_filter }}</td></tr>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if item.tube %}
|
|
||||||
<div class="info-card">
|
|
||||||
<h3>管参数 (Tube)</h3>
|
|
||||||
<table class="info-table">
|
|
||||||
<tr><td class="label">尺寸</td><td>{{ item.tube.size_x }} x {{ item.tube.size_y }} x {{ item.tube.size_z }}</td></tr>
|
|
||||||
<tr><td class="label">最大体积</td><td>{{ item.tube.max_volume }} uL</td></tr>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if item.adapter %}
|
|
||||||
<div class="info-card">
|
|
||||||
<h3>适配器参数</h3>
|
|
||||||
<table class="info-table">
|
|
||||||
<tr><td class="label">Hole 尺寸</td><td>{{ item.adapter.adapter_hole_size_x }} x {{ item.adapter.adapter_hole_size_y }} x {{ item.adapter.adapter_hole_size_z }}</td></tr>
|
|
||||||
<tr><td class="label">dx, dy, dz</td><td>{{ item.adapter.dx }}, {{ item.adapter.dy }}, {{ item.adapter.dz }}</td></tr>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
<div class="info-card">
|
|
||||||
<h3>Registry</h3>
|
|
||||||
<table class="info-table">
|
|
||||||
<tr><td class="label">分类</td><td>{{ item.registry_category | join(' / ') }}</td></tr>
|
|
||||||
<tr><td class="label">描述</td><td>{{ item.registry_description }}</td></tr>
|
|
||||||
<tr><td class="label">模板匹配</td><td>{{ item.include_in_template_matching }}</td></tr>
|
|
||||||
{% if item.template_kind %}
|
|
||||||
<tr><td class="label">模板类型</td><td>{{ item.template_kind }}</td></tr>
|
|
||||||
{% endif %}
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- 右侧: 可视化 -->
|
|
||||||
<div class="detail-viz">
|
|
||||||
<div class="viz-card">
|
|
||||||
<h3 style="display:flex;align-items:center;justify-content:space-between;">
|
|
||||||
俯视图 (Top-Down)
|
|
||||||
<button type="button" class="btn btn-sm btn-outline" onclick="resetSvgView('svg-topdown')">回中</button>
|
|
||||||
</h3>
|
|
||||||
<div id="svg-topdown"></div>
|
|
||||||
</div>
|
|
||||||
<div class="viz-card">
|
|
||||||
<h3 style="display:flex;align-items:center;justify-content:space-between;">
|
|
||||||
侧面截面图 (Side Profile)
|
|
||||||
<button type="button" class="btn btn-sm btn-outline" onclick="resetSvgView('svg-side')">回中</button>
|
|
||||||
</h3>
|
|
||||||
<div id="svg-side"></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block scripts %}
|
|
||||||
<script src="/static/labware_viz.js"></script>
|
|
||||||
<script>
|
|
||||||
const itemData = {{ item.model_dump() | tojson }};
|
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
|
||||||
renderTopDown(document.getElementById('svg-topdown'), itemData);
|
|
||||||
renderSideProfile(document.getElementById('svg-side'), itemData);
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
{% endblock %}
|
|
||||||
@@ -1,257 +0,0 @@
|
|||||||
{% extends "base.html" %}
|
|
||||||
{% block title %}{% if is_new %}新建耗材{% else %}编辑 {{ item.function_name }}{% endif %} - PRCXI{% endblock %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
<div class="page-header">
|
|
||||||
<h1>{% if is_new %}新建耗材{% else %}编辑 {{ item.function_name }}{% endif %}</h1>
|
|
||||||
<div class="header-actions">
|
|
||||||
<a href="/" class="btn btn-outline">返回列表</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="status-msg" class="status-msg" style="display:none;"></div>
|
|
||||||
|
|
||||||
<div class="edit-layout">
|
|
||||||
<!-- 左侧: 表单 -->
|
|
||||||
<div class="edit-form">
|
|
||||||
<form id="labware-form" onsubmit="return false;">
|
|
||||||
<!-- 基本信息 -->
|
|
||||||
<div class="form-section">
|
|
||||||
<h3>基本信息</h3>
|
|
||||||
<div class="form-row">
|
|
||||||
<label>类型</label>
|
|
||||||
<select name="type" id="f-type" onchange="onTypeChange()">
|
|
||||||
<option value="plate" {% if labware_type == 'plate' %}selected{% endif %}>Plate (孔板)</option>
|
|
||||||
<option value="tip_rack" {% if labware_type == 'tip_rack' %}selected{% endif %}>TipRack (吸头盒)</option>
|
|
||||||
<option value="trash" {% if labware_type == 'trash' %}selected{% endif %}>Trash (废弃槽)</option>
|
|
||||||
<option value="tube_rack" {% if labware_type == 'tube_rack' %}selected{% endif %}>TubeRack (管架)</option>
|
|
||||||
<option value="plate_adapter" {% if labware_type == 'plate_adapter' %}selected{% endif %}>PlateAdapter (适配器)</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<div class="form-row">
|
|
||||||
<label>函数名</label>
|
|
||||||
<input type="text" name="function_name" id="f-function_name"
|
|
||||||
value="{{ item.function_name if item else 'PRCXI_new_labware' }}"
|
|
||||||
placeholder="PRCXI_xxx">
|
|
||||||
</div>
|
|
||||||
<div class="form-row">
|
|
||||||
<label>Model</label>
|
|
||||||
<input type="text" name="model" id="f-model"
|
|
||||||
value="{{ item.model if item and item.model else '' }}">
|
|
||||||
</div>
|
|
||||||
<div class="form-row">
|
|
||||||
<label>Docstring</label>
|
|
||||||
<textarea name="docstring" id="f-docstring" rows="2">{{ item.docstring if item else '' }}</textarea>
|
|
||||||
</div>
|
|
||||||
<div class="form-row" id="row-plate_type" style="display:none;">
|
|
||||||
<label>Plate Type</label>
|
|
||||||
<select name="plate_type" id="f-plate_type">
|
|
||||||
<option value="">-</option>
|
|
||||||
<option value="skirted" {% if item and item.plate_type == 'skirted' %}selected{% endif %}>skirted</option>
|
|
||||||
<option value="semi-skirted" {% if item and item.plate_type == 'semi-skirted' %}selected{% endif %}>semi-skirted</option>
|
|
||||||
<option value="non-skirted" {% if item and item.plate_type == 'non-skirted' %}selected{% endif %}>non-skirted</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- 物理尺寸 -->
|
|
||||||
<div class="form-section">
|
|
||||||
<h3>物理尺寸 Physical Dimensions (mm)</h3>
|
|
||||||
<div class="form-row-3">
|
|
||||||
<div><label>size_x <span class="label-cn">板长</span></label><input type="number" step="any" name="size_x" id="f-size_x" value="{{ item.size_x if item else 127 }}"></div>
|
|
||||||
<div><label>size_y <span class="label-cn">板宽</span></label><input type="number" step="any" name="size_y" id="f-size_y" value="{{ item.size_y if item else 85 }}"></div>
|
|
||||||
<div><label>size_z <span class="label-cn">板高</span></label><input type="number" step="any" name="size_z" id="f-size_z" value="{{ item.size_z if item else 20 }}"></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- 材料信息 -->
|
|
||||||
<div class="form-section">
|
|
||||||
<h3>材料信息</h3>
|
|
||||||
<div class="form-row">
|
|
||||||
<label>UUID</label>
|
|
||||||
<input type="text" name="mi_uuid" id="f-mi_uuid"
|
|
||||||
value="{{ item.material_info.uuid if item else '' }}">
|
|
||||||
</div>
|
|
||||||
<div class="form-row-2">
|
|
||||||
<div><label>Code</label><input type="text" name="mi_code" id="f-mi_code" value="{{ item.material_info.Code if item else '' }}"></div>
|
|
||||||
<div><label>Name</label><input type="text" name="mi_name" id="f-mi_name" value="{{ item.material_info.Name if item else '' }}"></div>
|
|
||||||
</div>
|
|
||||||
<div class="form-row-2">
|
|
||||||
<div><label>materialEnum</label><input type="number" name="mi_menum" id="f-mi_menum" value="{{ item.material_info.materialEnum if item and item.material_info.materialEnum is not none else '' }}"></div>
|
|
||||||
<div><label>SupplyType</label><input type="number" name="mi_stype" id="f-mi_stype" value="{{ item.material_info.SupplyType if item and item.material_info.SupplyType is not none else '' }}"></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- 网格排列 (plate/tip_rack/tube_rack) -->
|
|
||||||
<div class="form-section" id="section-grid" style="display:none;">
|
|
||||||
<h3 style="display:flex;align-items:center;justify-content:space-between;">
|
|
||||||
网格排列 Grid Layout
|
|
||||||
<button type="button" class="btn btn-sm btn-outline" onclick="autoCenter()">自动居中 Auto-Center</button>
|
|
||||||
</h3>
|
|
||||||
<div class="form-row-2">
|
|
||||||
<div><label>num_items_x <span class="label-cn">列数</span></label><input type="number" name="grid_nx" id="f-grid_nx" value="{{ item.grid.num_items_x if item and item.grid else 12 }}"></div>
|
|
||||||
<div><label>num_items_y <span class="label-cn">行数</span></label><input type="number" name="grid_ny" id="f-grid_ny" value="{{ item.grid.num_items_y if item and item.grid else 8 }}"></div>
|
|
||||||
</div>
|
|
||||||
<div class="form-row-3">
|
|
||||||
<div><label>dx <span class="label-cn">首孔X偏移</span></label><input type="number" step="any" name="grid_dx" id="f-grid_dx" value="{{ item.grid.dx if item and item.grid else 0 }}"></div>
|
|
||||||
<div><label>dy <span class="label-cn">首孔Y偏移</span></label><input type="number" step="any" name="grid_dy" id="f-grid_dy" value="{{ item.grid.dy if item and item.grid else 0 }}"></div>
|
|
||||||
<div><label>dz <span class="label-cn">孔底Z偏移</span></label><input type="number" step="any" name="grid_dz" id="f-grid_dz" value="{{ item.grid.dz if item and item.grid else 0 }}"></div>
|
|
||||||
</div>
|
|
||||||
<div class="form-row-2">
|
|
||||||
<div><label>item_dx <span class="label-cn">列间距</span></label><input type="number" step="any" name="grid_idx" id="f-grid_idx" value="{{ item.grid.item_dx if item and item.grid else 9 }}"></div>
|
|
||||||
<div><label>item_dy <span class="label-cn">行间距</span></label><input type="number" step="any" name="grid_idy" id="f-grid_idy" value="{{ item.grid.item_dy if item and item.grid else 9 }}"></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Well 参数 (plate) -->
|
|
||||||
<div class="form-section" id="section-well" style="display:none;">
|
|
||||||
<h3>孔参数 Well</h3>
|
|
||||||
<div class="form-row-3">
|
|
||||||
<div><label>size_x <span class="label-cn">孔长</span></label><input type="number" step="any" name="well_sx" id="f-well_sx" value="{{ item.well.size_x if item and item.well else 8 }}"></div>
|
|
||||||
<div><label>size_y <span class="label-cn">孔宽</span></label><input type="number" step="any" name="well_sy" id="f-well_sy" value="{{ item.well.size_y if item and item.well else 8 }}"></div>
|
|
||||||
<div><label>size_z <span class="label-cn">孔深</span></label><input type="number" step="any" name="well_sz" id="f-well_sz" value="{{ item.well.size_z if item and item.well else 10 }}"></div>
|
|
||||||
</div>
|
|
||||||
<div class="form-row-2">
|
|
||||||
<div><label>max_volume <span class="label-cn">最大容量 (uL)</span></label><input type="number" step="any" name="well_vol" id="f-well_vol" value="{{ item.well.max_volume if item and item.well and item.well.max_volume is not none else '' }}"></div>
|
|
||||||
<div><label>material_z_thickness <span class="label-cn">底壁厚度</span></label><input type="number" step="any" name="well_mzt" id="f-well_mzt" value="{{ item.well.material_z_thickness if item and item.well and item.well.material_z_thickness is not none else '' }}"></div>
|
|
||||||
</div>
|
|
||||||
<div class="form-row-2">
|
|
||||||
<div>
|
|
||||||
<label>bottom_type <span class="label-cn">底部形状</span></label>
|
|
||||||
<select name="well_bt" id="f-well_bt">
|
|
||||||
<option value="FLAT" {% if item and item.well and item.well.bottom_type == 'FLAT' %}selected{% endif %}>FLAT</option>
|
|
||||||
<option value="V" {% if item and item.well and item.well.bottom_type == 'V' %}selected{% endif %}>V</option>
|
|
||||||
<option value="U" {% if item and item.well and item.well.bottom_type == 'U' %}selected{% endif %}>U</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<label>cross_section_type <span class="label-cn">截面形状</span></label>
|
|
||||||
<select name="well_cs" id="f-well_cs">
|
|
||||||
<option value="CIRCLE" {% if item and item.well and item.well.cross_section_type == 'CIRCLE' %}selected{% endif %}>CIRCLE</option>
|
|
||||||
<option value="RECTANGLE" {% if item and item.well and item.well.cross_section_type == 'RECTANGLE' %}selected{% endif %}>RECTANGLE</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="form-row">
|
|
||||||
<label><input type="checkbox" name="has_vf" id="f-has_vf" {% if item and item.volume_functions %}checked{% endif %}> 使用 volume_functions (rectangle)</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Tip 参数 (tip_rack) -->
|
|
||||||
<div class="form-section" id="section-tip" style="display:none;">
|
|
||||||
<h3>枪头参数 Tip</h3>
|
|
||||||
<div class="form-row-3">
|
|
||||||
<div><label>spot_size_x <span class="label-cn">卡槽长</span></label><input type="number" step="any" name="tip_sx" id="f-tip_sx" value="{{ item.tip.spot_size_x if item and item.tip else 7 }}"></div>
|
|
||||||
<div><label>spot_size_y <span class="label-cn">卡槽宽</span></label><input type="number" step="any" name="tip_sy" id="f-tip_sy" value="{{ item.tip.spot_size_y if item and item.tip else 7 }}"></div>
|
|
||||||
<div><label>spot_size_z <span class="label-cn">卡槽高</span></label><input type="number" step="any" name="tip_sz" id="f-tip_sz" value="{{ item.tip.spot_size_z if item and item.tip else 0 }}"></div>
|
|
||||||
</div>
|
|
||||||
<div class="form-row-3">
|
|
||||||
<div><label>tip_volume <span class="label-cn">枪头容量 (uL)</span></label><input type="number" step="any" name="tip_vol" id="f-tip_vol" value="{{ item.tip.tip_volume if item and item.tip else 300 }}"></div>
|
|
||||||
<div><label>tip_length <span class="label-cn">枪头总长度 (mm)</span></label><input type="number" step="any" name="tip_len" id="f-tip_len" value="{{ item.tip.tip_length if item and item.tip else 60 }}"></div>
|
|
||||||
<div><label>fitting_depth <span class="label-cn">取枪头时插入的长度 (mm)</span></label><input type="number" step="any" name="tip_dep" id="f-tip_dep" value="{{ item.tip.tip_fitting_depth if item and item.tip else 51 }}"></div>
|
|
||||||
</div>
|
|
||||||
<div class="form-row">
|
|
||||||
<label>tip_above_rack_length <span class="label-cn">枪头在枪头盒上方的部分的长度 (mm)</span></label>
|
|
||||||
<input type="number" step="any" name="tip_above" id="f-tip_above"
|
|
||||||
value="{{ item.tip.tip_above_rack_length if item and item.tip and item.tip.tip_above_rack_length is not none else '' }}"
|
|
||||||
placeholder="tip_length - (size_z - dz)">
|
|
||||||
<small style="color:#888;margin-top:2px;">公式: tip_length = tip_above + size_z - dz;填 tip_above 自动算 dz,填 dz 自动算 tip_above</small>
|
|
||||||
</div>
|
|
||||||
<div class="form-row">
|
|
||||||
<label><input type="checkbox" name="tip_filter" id="f-tip_filter" {% if item and item.tip and item.tip.has_filter %}checked{% endif %}> has_filter</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Tube 参数 (tube_rack) -->
|
|
||||||
<div class="form-section" id="section-tube" style="display:none;">
|
|
||||||
<h3>管参数 Tube</h3>
|
|
||||||
<div class="form-row-3">
|
|
||||||
<div><label>size_x <span class="label-cn">管径X</span></label><input type="number" step="any" name="tube_sx" id="f-tube_sx" value="{{ item.tube.size_x if item and item.tube else 10.6 }}"></div>
|
|
||||||
<div><label>size_y <span class="label-cn">管径Y</span></label><input type="number" step="any" name="tube_sy" id="f-tube_sy" value="{{ item.tube.size_y if item and item.tube else 10.6 }}"></div>
|
|
||||||
<div><label>size_z <span class="label-cn">管高</span></label><input type="number" step="any" name="tube_sz" id="f-tube_sz" value="{{ item.tube.size_z if item and item.tube else 40 }}"></div>
|
|
||||||
</div>
|
|
||||||
<div class="form-row">
|
|
||||||
<label>max_volume <span class="label-cn">最大容量 (uL)</span></label>
|
|
||||||
<input type="number" step="any" name="tube_vol" id="f-tube_vol" value="{{ item.tube.max_volume if item and item.tube else 1500 }}">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Adapter 参数 (plate_adapter) -->
|
|
||||||
<div class="form-section" id="section-adapter" style="display:none;">
|
|
||||||
<h3>适配器参数 Adapter</h3>
|
|
||||||
<div class="form-row-3">
|
|
||||||
<div><label>hole_size_x <span class="label-cn">凹槽长</span></label><input type="number" step="any" name="adp_hsx" id="f-adp_hsx" value="{{ item.adapter.adapter_hole_size_x if item and item.adapter else 127.76 }}"></div>
|
|
||||||
<div><label>hole_size_y <span class="label-cn">凹槽宽</span></label><input type="number" step="any" name="adp_hsy" id="f-adp_hsy" value="{{ item.adapter.adapter_hole_size_y if item and item.adapter else 85.48 }}"></div>
|
|
||||||
<div><label>hole_size_z <span class="label-cn">凹槽深</span></label><input type="number" step="any" name="adp_hsz" id="f-adp_hsz" value="{{ item.adapter.adapter_hole_size_z if item and item.adapter else 10 }}"></div>
|
|
||||||
</div>
|
|
||||||
<div class="form-row-3">
|
|
||||||
<div><label>dx <span class="label-cn">X偏移</span></label><input type="number" step="any" name="adp_dx" id="f-adp_dx" value="{{ item.adapter.dx if item and item.adapter and item.adapter.dx is not none else '' }}"></div>
|
|
||||||
<div><label>dy <span class="label-cn">Y偏移</span></label><input type="number" step="any" name="adp_dy" id="f-adp_dy" value="{{ item.adapter.dy if item and item.adapter and item.adapter.dy is not none else '' }}"></div>
|
|
||||||
<div><label>dz <span class="label-cn">Z偏移</span></label><input type="number" step="any" name="adp_dz" id="f-adp_dz" value="{{ item.adapter.dz if item and item.adapter else 0 }}"></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Registry -->
|
|
||||||
<div class="form-section">
|
|
||||||
<h3>Registry / Template</h3>
|
|
||||||
<div class="form-row">
|
|
||||||
<label>registry_category (逗号分隔)</label>
|
|
||||||
<input type="text" name="reg_cat" id="f-reg_cat"
|
|
||||||
value="{{ item.registry_category | join(',') if item else 'prcxi,plates' }}">
|
|
||||||
</div>
|
|
||||||
<div class="form-row">
|
|
||||||
<label>registry_description</label>
|
|
||||||
<input type="text" name="reg_desc" id="f-reg_desc"
|
|
||||||
value="{{ item.registry_description if item else '' }}">
|
|
||||||
</div>
|
|
||||||
<div class="form-row">
|
|
||||||
<label><input type="checkbox" name="in_tpl" id="f-in_tpl" {% if item and item.include_in_template_matching %}checked{% endif %}> include_in_template_matching</label>
|
|
||||||
</div>
|
|
||||||
<div class="form-row" id="row-tpl_kind">
|
|
||||||
<label>template_kind</label>
|
|
||||||
<input type="text" name="tpl_kind" id="f-tpl_kind"
|
|
||||||
value="{{ item.template_kind if item and item.template_kind else '' }}">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-actions">
|
|
||||||
<button type="button" class="btn btn-primary" onclick="saveForm()">
|
|
||||||
{% if is_new %}创建{% else %}保存{% endif %}
|
|
||||||
</button>
|
|
||||||
<a href="/" class="btn btn-outline">取消</a>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- 右侧: 实时预览 -->
|
|
||||||
<div class="edit-preview">
|
|
||||||
<div class="viz-card">
|
|
||||||
<h3 style="display:flex;align-items:center;justify-content:space-between;">
|
|
||||||
预览: 俯视图
|
|
||||||
<button type="button" class="btn btn-sm btn-outline" onclick="resetSvgView('svg-topdown')">回中</button>
|
|
||||||
</h3>
|
|
||||||
<div id="svg-topdown"></div>
|
|
||||||
</div>
|
|
||||||
<div class="viz-card">
|
|
||||||
<h3 style="display:flex;align-items:center;justify-content:space-between;">
|
|
||||||
预览: 侧面截面图
|
|
||||||
<button type="button" class="btn btn-sm btn-outline" onclick="resetSvgView('svg-side')">回中</button>
|
|
||||||
</h3>
|
|
||||||
<div id="svg-side"></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block scripts %}
|
|
||||||
<script src="/static/labware_viz.js"></script>
|
|
||||||
<script src="/static/form_handler.js"></script>
|
|
||||||
<script>
|
|
||||||
const IS_NEW = {{ 'true' if is_new else 'false' }};
|
|
||||||
const ITEM_ID = "{{ item.function_name if item else '' }}";
|
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
|
||||||
onTypeChange();
|
|
||||||
updatePreview();
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
{% endblock %}
|
|
||||||
@@ -1,131 +0,0 @@
|
|||||||
{% extends "base.html" %}
|
|
||||||
{% block title %}耗材列表 - PRCXI{% endblock %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
<div class="page-header">
|
|
||||||
<h1>耗材列表 <span class="badge">{{ total }}</span></h1>
|
|
||||||
<div class="header-actions">
|
|
||||||
<button class="btn btn-outline" onclick="importFromCode()">从代码导入</button>
|
|
||||||
<button class="btn btn-outline" onclick="generateCode(true)">生成代码 (测试)</button>
|
|
||||||
<button class="btn btn-warning" onclick="generateCode(false)">生成代码 (正式)</button>
|
|
||||||
<a href="/labware/new" class="btn btn-primary">+ 新建耗材</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="status-msg" class="status-msg" style="display:none;"></div>
|
|
||||||
|
|
||||||
{% set type_labels = {
|
|
||||||
"plate": "孔板 (Plate)",
|
|
||||||
"tip_rack": "吸头盒 (TipRack)",
|
|
||||||
"trash": "废弃槽 (Trash)",
|
|
||||||
"tube_rack": "管架 (TubeRack)",
|
|
||||||
"plate_adapter": "适配器 (PlateAdapter)"
|
|
||||||
} %}
|
|
||||||
{% set type_colors = {
|
|
||||||
"plate": "#3b82f6",
|
|
||||||
"tip_rack": "#10b981",
|
|
||||||
"trash": "#ef4444",
|
|
||||||
"tube_rack": "#f59e0b",
|
|
||||||
"plate_adapter": "#8b5cf6"
|
|
||||||
} %}
|
|
||||||
|
|
||||||
{% for type_key in ["plate", "tip_rack", "trash", "tube_rack", "plate_adapter"] %}
|
|
||||||
{% if type_key in groups %}
|
|
||||||
<section class="type-section">
|
|
||||||
<h2>
|
|
||||||
<span class="type-dot" style="background:{{ type_colors[type_key] }}"></span>
|
|
||||||
{{ type_labels[type_key] }}
|
|
||||||
<span class="badge">{{ groups[type_key]|length }}</span>
|
|
||||||
</h2>
|
|
||||||
<div class="card-grid">
|
|
||||||
{% for item in groups[type_key] %}
|
|
||||||
<div class="labware-card" onclick="location.href='/labware/{{ item.function_name }}'">
|
|
||||||
<div class="card-header">
|
|
||||||
<span class="card-title">{{ item.function_name }}</span>
|
|
||||||
{% if item.include_in_template_matching %}
|
|
||||||
<span class="tag tag-tpl">TPL</span>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
<div class="card-body">
|
|
||||||
<div class="card-info">
|
|
||||||
<span class="label">Code:</span> {{ item.material_info.Code or '-' }}
|
|
||||||
</div>
|
|
||||||
<div class="card-info">
|
|
||||||
<span class="label">名称:</span> {{ item.material_info.Name or '-' }}
|
|
||||||
</div>
|
|
||||||
<div class="card-info">
|
|
||||||
<span class="label">尺寸:</span>
|
|
||||||
{{ item.size_x }} x {{ item.size_y }} x {{ item.size_z }} mm
|
|
||||||
</div>
|
|
||||||
{% if item.grid %}
|
|
||||||
<div class="card-info">
|
|
||||||
<span class="label">网格:</span>
|
|
||||||
{{ item.grid.num_items_x }} x {{ item.grid.num_items_y }}
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
<div class="card-footer">
|
|
||||||
<a href="/labware/{{ item.function_name }}/edit" class="btn btn-sm btn-outline"
|
|
||||||
onclick="event.stopPropagation()">编辑</a>
|
|
||||||
<button class="btn btn-sm btn-danger"
|
|
||||||
onclick="event.stopPropagation(); deleteItem('{{ item.function_name }}')">删除</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block scripts %}
|
|
||||||
<script>
|
|
||||||
function showMsg(text, ok) {
|
|
||||||
const el = document.getElementById('status-msg');
|
|
||||||
el.textContent = text;
|
|
||||||
el.className = 'status-msg ' + (ok ? 'msg-ok' : 'msg-err');
|
|
||||||
el.style.display = 'block';
|
|
||||||
setTimeout(() => el.style.display = 'none', 4000);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function importFromCode() {
|
|
||||||
if (!confirm('将从现有 prcxi_labware.py + YAML 重新导入,覆盖当前 JSON 数据?')) return;
|
|
||||||
const r = await fetch('/api/import-from-code', {method:'POST'});
|
|
||||||
const d = await r.json();
|
|
||||||
if (d.status === 'ok') {
|
|
||||||
showMsg('导入成功: ' + d.count + ' 个耗材', true);
|
|
||||||
setTimeout(() => location.reload(), 1000);
|
|
||||||
} else {
|
|
||||||
showMsg('导入失败: ' + JSON.stringify(d), false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function generateCode(testMode) {
|
|
||||||
const label = testMode ? '测试' : '正式';
|
|
||||||
if (!testMode && !confirm('正式模式将覆盖原有 prcxi_labware.py 和 YAML 文件,确定?')) return;
|
|
||||||
const r = await fetch('/api/generate-code', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {'Content-Type':'application/json'},
|
|
||||||
body: JSON.stringify({test_mode: testMode})
|
|
||||||
});
|
|
||||||
const d = await r.json();
|
|
||||||
if (d.status === 'ok') {
|
|
||||||
showMsg(`[${label}] 生成成功: ${d.python_file}`, true);
|
|
||||||
} else {
|
|
||||||
showMsg('生成失败: ' + JSON.stringify(d), false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function deleteItem(id) {
|
|
||||||
if (!confirm('确定删除 ' + id + '?')) return;
|
|
||||||
const r = await fetch('/api/labware/' + id, {method:'DELETE'});
|
|
||||||
const d = await r.json();
|
|
||||||
if (d.status === 'ok') {
|
|
||||||
showMsg('已删除', true);
|
|
||||||
setTimeout(() => location.reload(), 500);
|
|
||||||
} else {
|
|
||||||
showMsg('删除失败', false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
{% endblock %}
|
|
||||||
@@ -1,119 +0,0 @@
|
|||||||
"""JSON → Registry YAML 文件生成。
|
|
||||||
|
|
||||||
按 type 分组输出到对应 YAML 文件(与现有格式完全一致)。
|
|
||||||
"""
|
|
||||||
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import shutil
|
|
||||||
from collections import defaultdict
|
|
||||||
from pathlib import Path
|
|
||||||
from typing import Dict, List
|
|
||||||
|
|
||||||
import yaml
|
|
||||||
|
|
||||||
from unilabos.labware_manager.models import LabwareDB, LabwareItem
|
|
||||||
|
|
||||||
_REGISTRY_DIR = Path(__file__).resolve().parents[1] / "registry" / "resources" / "prcxi"
|
|
||||||
|
|
||||||
# type → yaml 文件名
|
|
||||||
_TYPE_TO_YAML = {
|
|
||||||
"plate": "plates",
|
|
||||||
"tip_rack": "tip_racks",
|
|
||||||
"trash": "trash",
|
|
||||||
"tube_rack": "tube_racks",
|
|
||||||
"plate_adapter": "plate_adapters",
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def _build_entry(item: LabwareItem) -> dict:
|
|
||||||
"""构建单个 YAML 条目(与现有格式完全一致)。"""
|
|
||||||
mi = item.material_info
|
|
||||||
desc = item.registry_description
|
|
||||||
if not desc:
|
|
||||||
desc = f'{mi.Name} (Code: {mi.Code})' if mi.Name and mi.Code else item.function_name
|
|
||||||
|
|
||||||
return {
|
|
||||||
"category": list(item.registry_category),
|
|
||||||
"class": {
|
|
||||||
"module": f"unilabos.devices.liquid_handling.prcxi.prcxi_labware:{item.function_name}",
|
|
||||||
"type": "pylabrobot",
|
|
||||||
},
|
|
||||||
"description": desc,
|
|
||||||
"handles": [],
|
|
||||||
"icon": "",
|
|
||||||
"init_param_schema": {},
|
|
||||||
"version": "1.0.0",
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class _YAMLDumper(yaml.SafeDumper):
|
|
||||||
"""自定义 Dumper: 空列表输出为 [],空字典输出为 {}。"""
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def _represent_list(dumper, data):
|
|
||||||
if not data:
|
|
||||||
return dumper.represent_sequence("tag:yaml.org,2002:seq", data, flow_style=True)
|
|
||||||
return dumper.represent_sequence("tag:yaml.org,2002:seq", data)
|
|
||||||
|
|
||||||
|
|
||||||
def _represent_dict(dumper, data):
|
|
||||||
if not data:
|
|
||||||
return dumper.represent_mapping("tag:yaml.org,2002:map", data, flow_style=True)
|
|
||||||
return dumper.represent_mapping("tag:yaml.org,2002:map", data)
|
|
||||||
|
|
||||||
|
|
||||||
def _represent_str(dumper, data):
|
|
||||||
if '\n' in data or ':' in data or "'" in data:
|
|
||||||
return dumper.represent_scalar("tag:yaml.org,2002:str", data, style="'")
|
|
||||||
return dumper.represent_scalar("tag:yaml.org,2002:str", data)
|
|
||||||
|
|
||||||
|
|
||||||
_YAMLDumper.add_representer(list, _represent_list)
|
|
||||||
_YAMLDumper.add_representer(dict, _represent_dict)
|
|
||||||
_YAMLDumper.add_representer(str, _represent_str)
|
|
||||||
|
|
||||||
|
|
||||||
def generate_yaml(db: LabwareDB, test_mode: bool = True) -> List[Path]:
|
|
||||||
"""生成所有 registry YAML 文件,返回输出文件路径列表。"""
|
|
||||||
suffix = "_test" if test_mode else ""
|
|
||||||
|
|
||||||
# 按 type 分组
|
|
||||||
groups: Dict[str, Dict[str, dict]] = defaultdict(dict)
|
|
||||||
for item in db.items:
|
|
||||||
yaml_key = _TYPE_TO_YAML.get(item.type)
|
|
||||||
if yaml_key is None:
|
|
||||||
continue
|
|
||||||
groups[yaml_key][item.function_name] = _build_entry(item)
|
|
||||||
|
|
||||||
out_paths: List[Path] = []
|
|
||||||
for yaml_key, entries in groups.items():
|
|
||||||
out_path = _REGISTRY_DIR / f"{yaml_key}{suffix}.yaml"
|
|
||||||
|
|
||||||
# 备份
|
|
||||||
if out_path.exists():
|
|
||||||
bak = out_path.with_suffix(".yaml.bak")
|
|
||||||
shutil.copy2(out_path, bak)
|
|
||||||
|
|
||||||
# 按函数名排序
|
|
||||||
sorted_entries = dict(sorted(entries.items()))
|
|
||||||
|
|
||||||
content = yaml.dump(sorted_entries, Dumper=_YAMLDumper, allow_unicode=True,
|
|
||||||
default_flow_style=False, sort_keys=False)
|
|
||||||
out_path.write_text(content, encoding="utf-8")
|
|
||||||
out_paths.append(out_path)
|
|
||||||
|
|
||||||
return out_paths
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
from unilabos.labware_manager.importer import load_db
|
|
||||||
db = load_db()
|
|
||||||
if not db.items:
|
|
||||||
print("labware_db.json 为空,请先运行 importer.py")
|
|
||||||
else:
|
|
||||||
paths = generate_yaml(db, test_mode=True)
|
|
||||||
print(f"已生成 {len(paths)} 个 YAML 文件:")
|
|
||||||
for p in paths:
|
|
||||||
print(f" {p}")
|
|
||||||
@@ -1,589 +0,0 @@
|
|||||||
workstation.bioyond_dispensing_station:
|
|
||||||
category:
|
|
||||||
- workstation
|
|
||||||
- bioyond
|
|
||||||
class:
|
|
||||||
action_value_mappings:
|
|
||||||
auto-batch_create_90_10_vial_feeding_tasks:
|
|
||||||
feedback: {}
|
|
||||||
goal: {}
|
|
||||||
goal_default:
|
|
||||||
delay_time: null
|
|
||||||
hold_m_name: null
|
|
||||||
liquid_material_name: NMP
|
|
||||||
speed: null
|
|
||||||
temperature: null
|
|
||||||
titration: null
|
|
||||||
handles: {}
|
|
||||||
placeholder_keys: {}
|
|
||||||
result: {}
|
|
||||||
schema:
|
|
||||||
description: ''
|
|
||||||
properties:
|
|
||||||
feedback: {}
|
|
||||||
goal:
|
|
||||||
properties:
|
|
||||||
delay_time:
|
|
||||||
type: string
|
|
||||||
hold_m_name:
|
|
||||||
type: string
|
|
||||||
liquid_material_name:
|
|
||||||
default: NMP
|
|
||||||
type: string
|
|
||||||
speed:
|
|
||||||
type: string
|
|
||||||
temperature:
|
|
||||||
type: string
|
|
||||||
titration:
|
|
||||||
type: string
|
|
||||||
required:
|
|
||||||
- titration
|
|
||||||
type: object
|
|
||||||
result: {}
|
|
||||||
required:
|
|
||||||
- goal
|
|
||||||
title: batch_create_90_10_vial_feeding_tasks参数
|
|
||||||
type: object
|
|
||||||
type: UniLabJsonCommand
|
|
||||||
auto-batch_create_diamine_solution_tasks:
|
|
||||||
feedback: {}
|
|
||||||
goal: {}
|
|
||||||
goal_default:
|
|
||||||
delay_time: null
|
|
||||||
liquid_material_name: NMP
|
|
||||||
solutions: null
|
|
||||||
speed: null
|
|
||||||
temperature: null
|
|
||||||
handles: {}
|
|
||||||
placeholder_keys: {}
|
|
||||||
result: {}
|
|
||||||
schema:
|
|
||||||
description: ''
|
|
||||||
properties:
|
|
||||||
feedback: {}
|
|
||||||
goal:
|
|
||||||
properties:
|
|
||||||
delay_time:
|
|
||||||
type: string
|
|
||||||
liquid_material_name:
|
|
||||||
default: NMP
|
|
||||||
type: string
|
|
||||||
solutions:
|
|
||||||
type: string
|
|
||||||
speed:
|
|
||||||
type: string
|
|
||||||
temperature:
|
|
||||||
type: string
|
|
||||||
required:
|
|
||||||
- solutions
|
|
||||||
type: object
|
|
||||||
result: {}
|
|
||||||
required:
|
|
||||||
- goal
|
|
||||||
title: batch_create_diamine_solution_tasks参数
|
|
||||||
type: object
|
|
||||||
type: UniLabJsonCommand
|
|
||||||
auto-brief_step_parameters:
|
|
||||||
feedback: {}
|
|
||||||
goal: {}
|
|
||||||
goal_default:
|
|
||||||
data: null
|
|
||||||
handles: {}
|
|
||||||
placeholder_keys: {}
|
|
||||||
result: {}
|
|
||||||
schema:
|
|
||||||
description: ''
|
|
||||||
properties:
|
|
||||||
feedback: {}
|
|
||||||
goal:
|
|
||||||
properties:
|
|
||||||
data:
|
|
||||||
type: object
|
|
||||||
required:
|
|
||||||
- data
|
|
||||||
type: object
|
|
||||||
result: {}
|
|
||||||
required:
|
|
||||||
- goal
|
|
||||||
title: brief_step_parameters参数
|
|
||||||
type: object
|
|
||||||
type: UniLabJsonCommand
|
|
||||||
auto-compute_experiment_design:
|
|
||||||
feedback: {}
|
|
||||||
goal: {}
|
|
||||||
goal_default:
|
|
||||||
m_tot: '70'
|
|
||||||
ratio: null
|
|
||||||
titration_percent: '0.03'
|
|
||||||
wt_percent: '0.25'
|
|
||||||
handles: {}
|
|
||||||
placeholder_keys: {}
|
|
||||||
result: {}
|
|
||||||
schema:
|
|
||||||
description: ''
|
|
||||||
properties:
|
|
||||||
feedback: {}
|
|
||||||
goal:
|
|
||||||
properties:
|
|
||||||
m_tot:
|
|
||||||
default: '70'
|
|
||||||
type: string
|
|
||||||
ratio:
|
|
||||||
type: object
|
|
||||||
titration_percent:
|
|
||||||
default: '0.03'
|
|
||||||
type: string
|
|
||||||
wt_percent:
|
|
||||||
default: '0.25'
|
|
||||||
type: string
|
|
||||||
required:
|
|
||||||
- ratio
|
|
||||||
type: object
|
|
||||||
result:
|
|
||||||
properties:
|
|
||||||
feeding_order:
|
|
||||||
items: {}
|
|
||||||
title: Feeding Order
|
|
||||||
type: array
|
|
||||||
return_info:
|
|
||||||
title: Return Info
|
|
||||||
type: string
|
|
||||||
solutions:
|
|
||||||
items: {}
|
|
||||||
title: Solutions
|
|
||||||
type: array
|
|
||||||
solvents:
|
|
||||||
additionalProperties: true
|
|
||||||
title: Solvents
|
|
||||||
type: object
|
|
||||||
titration:
|
|
||||||
additionalProperties: true
|
|
||||||
title: Titration
|
|
||||||
type: object
|
|
||||||
required:
|
|
||||||
- solutions
|
|
||||||
- titration
|
|
||||||
- solvents
|
|
||||||
- feeding_order
|
|
||||||
- return_info
|
|
||||||
title: ComputeExperimentDesignReturn
|
|
||||||
type: object
|
|
||||||
required:
|
|
||||||
- goal
|
|
||||||
title: compute_experiment_design参数
|
|
||||||
type: object
|
|
||||||
type: UniLabJsonCommand
|
|
||||||
auto-process_order_finish_report:
|
|
||||||
feedback: {}
|
|
||||||
goal: {}
|
|
||||||
goal_default:
|
|
||||||
report_request: null
|
|
||||||
used_materials: null
|
|
||||||
handles: {}
|
|
||||||
placeholder_keys: {}
|
|
||||||
result: {}
|
|
||||||
schema:
|
|
||||||
description: ''
|
|
||||||
properties:
|
|
||||||
feedback: {}
|
|
||||||
goal:
|
|
||||||
properties:
|
|
||||||
report_request:
|
|
||||||
type: string
|
|
||||||
used_materials:
|
|
||||||
type: string
|
|
||||||
required:
|
|
||||||
- report_request
|
|
||||||
- used_materials
|
|
||||||
type: object
|
|
||||||
result: {}
|
|
||||||
required:
|
|
||||||
- goal
|
|
||||||
title: process_order_finish_report参数
|
|
||||||
type: object
|
|
||||||
type: UniLabJsonCommand
|
|
||||||
auto-project_order_report:
|
|
||||||
feedback: {}
|
|
||||||
goal: {}
|
|
||||||
goal_default:
|
|
||||||
order_id: null
|
|
||||||
handles: {}
|
|
||||||
placeholder_keys: {}
|
|
||||||
result: {}
|
|
||||||
schema:
|
|
||||||
description: ''
|
|
||||||
properties:
|
|
||||||
feedback: {}
|
|
||||||
goal:
|
|
||||||
properties:
|
|
||||||
order_id:
|
|
||||||
type: string
|
|
||||||
required:
|
|
||||||
- order_id
|
|
||||||
type: object
|
|
||||||
result: {}
|
|
||||||
required:
|
|
||||||
- goal
|
|
||||||
title: project_order_report参数
|
|
||||||
type: object
|
|
||||||
type: UniLabJsonCommand
|
|
||||||
auto-query_resource_by_name:
|
|
||||||
feedback: {}
|
|
||||||
goal: {}
|
|
||||||
goal_default:
|
|
||||||
material_name: null
|
|
||||||
handles: {}
|
|
||||||
placeholder_keys: {}
|
|
||||||
result: {}
|
|
||||||
schema:
|
|
||||||
description: ''
|
|
||||||
properties:
|
|
||||||
feedback: {}
|
|
||||||
goal:
|
|
||||||
properties:
|
|
||||||
material_name:
|
|
||||||
type: string
|
|
||||||
required:
|
|
||||||
- material_name
|
|
||||||
type: object
|
|
||||||
result: {}
|
|
||||||
required:
|
|
||||||
- goal
|
|
||||||
title: query_resource_by_name参数
|
|
||||||
type: object
|
|
||||||
type: UniLabJsonCommand
|
|
||||||
auto-transfer_materials_to_reaction_station:
|
|
||||||
feedback: {}
|
|
||||||
goal: {}
|
|
||||||
goal_default:
|
|
||||||
target_device_id: null
|
|
||||||
transfer_groups: null
|
|
||||||
handles: {}
|
|
||||||
placeholder_keys: {}
|
|
||||||
result: {}
|
|
||||||
schema:
|
|
||||||
description: ''
|
|
||||||
properties:
|
|
||||||
feedback: {}
|
|
||||||
goal:
|
|
||||||
properties:
|
|
||||||
target_device_id:
|
|
||||||
type: string
|
|
||||||
transfer_groups:
|
|
||||||
type: array
|
|
||||||
required:
|
|
||||||
- target_device_id
|
|
||||||
- transfer_groups
|
|
||||||
type: object
|
|
||||||
result: {}
|
|
||||||
required:
|
|
||||||
- goal
|
|
||||||
title: transfer_materials_to_reaction_station参数
|
|
||||||
type: object
|
|
||||||
type: UniLabJsonCommand
|
|
||||||
auto-wait_for_multiple_orders_and_get_reports:
|
|
||||||
feedback: {}
|
|
||||||
goal: {}
|
|
||||||
goal_default:
|
|
||||||
batch_create_result: null
|
|
||||||
check_interval: 10
|
|
||||||
timeout: 7200
|
|
||||||
handles: {}
|
|
||||||
placeholder_keys: {}
|
|
||||||
result: {}
|
|
||||||
schema:
|
|
||||||
description: ''
|
|
||||||
properties:
|
|
||||||
feedback: {}
|
|
||||||
goal:
|
|
||||||
properties:
|
|
||||||
batch_create_result:
|
|
||||||
type: string
|
|
||||||
check_interval:
|
|
||||||
default: 10
|
|
||||||
type: integer
|
|
||||||
timeout:
|
|
||||||
default: 7200
|
|
||||||
type: integer
|
|
||||||
required: []
|
|
||||||
type: object
|
|
||||||
result: {}
|
|
||||||
required:
|
|
||||||
- goal
|
|
||||||
title: wait_for_multiple_orders_and_get_reports参数
|
|
||||||
type: object
|
|
||||||
type: UniLabJsonCommand
|
|
||||||
auto-workflow_sample_locations:
|
|
||||||
feedback: {}
|
|
||||||
goal: {}
|
|
||||||
goal_default:
|
|
||||||
workflow_id: null
|
|
||||||
handles: {}
|
|
||||||
placeholder_keys: {}
|
|
||||||
result: {}
|
|
||||||
schema:
|
|
||||||
description: ''
|
|
||||||
properties:
|
|
||||||
feedback: {}
|
|
||||||
goal:
|
|
||||||
properties:
|
|
||||||
workflow_id:
|
|
||||||
type: string
|
|
||||||
required:
|
|
||||||
- workflow_id
|
|
||||||
type: object
|
|
||||||
result: {}
|
|
||||||
required:
|
|
||||||
- goal
|
|
||||||
title: workflow_sample_locations参数
|
|
||||||
type: object
|
|
||||||
type: UniLabJsonCommand
|
|
||||||
create_90_10_vial_feeding_task:
|
|
||||||
feedback: {}
|
|
||||||
goal:
|
|
||||||
delay_time: delay_time
|
|
||||||
hold_m_name: hold_m_name
|
|
||||||
order_name: order_name
|
|
||||||
percent_10_1_assign_material_name: percent_10_1_assign_material_name
|
|
||||||
percent_10_1_liquid_material_name: percent_10_1_liquid_material_name
|
|
||||||
percent_10_1_target_weigh: percent_10_1_target_weigh
|
|
||||||
percent_10_1_volume: percent_10_1_volume
|
|
||||||
percent_10_2_assign_material_name: percent_10_2_assign_material_name
|
|
||||||
percent_10_2_liquid_material_name: percent_10_2_liquid_material_name
|
|
||||||
percent_10_2_target_weigh: percent_10_2_target_weigh
|
|
||||||
percent_10_2_volume: percent_10_2_volume
|
|
||||||
percent_10_3_assign_material_name: percent_10_3_assign_material_name
|
|
||||||
percent_10_3_liquid_material_name: percent_10_3_liquid_material_name
|
|
||||||
percent_10_3_target_weigh: percent_10_3_target_weigh
|
|
||||||
percent_10_3_volume: percent_10_3_volume
|
|
||||||
percent_90_1_assign_material_name: percent_90_1_assign_material_name
|
|
||||||
percent_90_1_target_weigh: percent_90_1_target_weigh
|
|
||||||
percent_90_2_assign_material_name: percent_90_2_assign_material_name
|
|
||||||
percent_90_2_target_weigh: percent_90_2_target_weigh
|
|
||||||
percent_90_3_assign_material_name: percent_90_3_assign_material_name
|
|
||||||
percent_90_3_target_weigh: percent_90_3_target_weigh
|
|
||||||
speed: speed
|
|
||||||
temperature: temperature
|
|
||||||
goal_default:
|
|
||||||
delay_time: ''
|
|
||||||
hold_m_name: ''
|
|
||||||
order_name: ''
|
|
||||||
percent_10_1_assign_material_name: ''
|
|
||||||
percent_10_1_liquid_material_name: ''
|
|
||||||
percent_10_1_target_weigh: ''
|
|
||||||
percent_10_1_volume: ''
|
|
||||||
percent_10_2_assign_material_name: ''
|
|
||||||
percent_10_2_liquid_material_name: ''
|
|
||||||
percent_10_2_target_weigh: ''
|
|
||||||
percent_10_2_volume: ''
|
|
||||||
percent_10_3_assign_material_name: ''
|
|
||||||
percent_10_3_liquid_material_name: ''
|
|
||||||
percent_10_3_target_weigh: ''
|
|
||||||
percent_10_3_volume: ''
|
|
||||||
percent_90_1_assign_material_name: ''
|
|
||||||
percent_90_1_target_weigh: ''
|
|
||||||
percent_90_2_assign_material_name: ''
|
|
||||||
percent_90_2_target_weigh: ''
|
|
||||||
percent_90_3_assign_material_name: ''
|
|
||||||
percent_90_3_target_weigh: ''
|
|
||||||
speed: ''
|
|
||||||
temperature: ''
|
|
||||||
handles: {}
|
|
||||||
result:
|
|
||||||
return_info: return_info
|
|
||||||
schema:
|
|
||||||
description: ''
|
|
||||||
properties:
|
|
||||||
feedback:
|
|
||||||
properties: {}
|
|
||||||
required: []
|
|
||||||
title: DispenStationVialFeed_Feedback
|
|
||||||
type: object
|
|
||||||
goal:
|
|
||||||
properties:
|
|
||||||
delay_time:
|
|
||||||
type: string
|
|
||||||
hold_m_name:
|
|
||||||
type: string
|
|
||||||
order_name:
|
|
||||||
type: string
|
|
||||||
percent_10_1_assign_material_name:
|
|
||||||
type: string
|
|
||||||
percent_10_1_liquid_material_name:
|
|
||||||
type: string
|
|
||||||
percent_10_1_target_weigh:
|
|
||||||
type: string
|
|
||||||
percent_10_1_volume:
|
|
||||||
type: string
|
|
||||||
percent_10_2_assign_material_name:
|
|
||||||
type: string
|
|
||||||
percent_10_2_liquid_material_name:
|
|
||||||
type: string
|
|
||||||
percent_10_2_target_weigh:
|
|
||||||
type: string
|
|
||||||
percent_10_2_volume:
|
|
||||||
type: string
|
|
||||||
percent_10_3_assign_material_name:
|
|
||||||
type: string
|
|
||||||
percent_10_3_liquid_material_name:
|
|
||||||
type: string
|
|
||||||
percent_10_3_target_weigh:
|
|
||||||
type: string
|
|
||||||
percent_10_3_volume:
|
|
||||||
type: string
|
|
||||||
percent_90_1_assign_material_name:
|
|
||||||
type: string
|
|
||||||
percent_90_1_target_weigh:
|
|
||||||
type: string
|
|
||||||
percent_90_2_assign_material_name:
|
|
||||||
type: string
|
|
||||||
percent_90_2_target_weigh:
|
|
||||||
type: string
|
|
||||||
percent_90_3_assign_material_name:
|
|
||||||
type: string
|
|
||||||
percent_90_3_target_weigh:
|
|
||||||
type: string
|
|
||||||
speed:
|
|
||||||
type: string
|
|
||||||
temperature:
|
|
||||||
type: string
|
|
||||||
required:
|
|
||||||
- order_name
|
|
||||||
- percent_90_1_assign_material_name
|
|
||||||
- percent_90_1_target_weigh
|
|
||||||
- percent_90_2_assign_material_name
|
|
||||||
- percent_90_2_target_weigh
|
|
||||||
- percent_90_3_assign_material_name
|
|
||||||
- percent_90_3_target_weigh
|
|
||||||
- percent_10_1_assign_material_name
|
|
||||||
- percent_10_1_target_weigh
|
|
||||||
- percent_10_1_volume
|
|
||||||
- percent_10_1_liquid_material_name
|
|
||||||
- percent_10_2_assign_material_name
|
|
||||||
- percent_10_2_target_weigh
|
|
||||||
- percent_10_2_volume
|
|
||||||
- percent_10_2_liquid_material_name
|
|
||||||
- percent_10_3_assign_material_name
|
|
||||||
- percent_10_3_target_weigh
|
|
||||||
- percent_10_3_volume
|
|
||||||
- percent_10_3_liquid_material_name
|
|
||||||
- speed
|
|
||||||
- temperature
|
|
||||||
- delay_time
|
|
||||||
- hold_m_name
|
|
||||||
title: DispenStationVialFeed_Goal
|
|
||||||
type: object
|
|
||||||
result:
|
|
||||||
properties:
|
|
||||||
return_info:
|
|
||||||
type: string
|
|
||||||
required:
|
|
||||||
- return_info
|
|
||||||
title: DispenStationVialFeed_Result
|
|
||||||
type: object
|
|
||||||
required:
|
|
||||||
- goal
|
|
||||||
title: DispenStationVialFeed
|
|
||||||
type: object
|
|
||||||
type: DispenStationVialFeed
|
|
||||||
create_diamine_solution_task:
|
|
||||||
feedback: {}
|
|
||||||
goal:
|
|
||||||
delay_time: delay_time
|
|
||||||
hold_m_name: hold_m_name
|
|
||||||
liquid_material_name: liquid_material_name
|
|
||||||
material_name: material_name
|
|
||||||
order_name: order_name
|
|
||||||
speed: speed
|
|
||||||
target_weigh: target_weigh
|
|
||||||
temperature: temperature
|
|
||||||
volume: volume
|
|
||||||
goal_default:
|
|
||||||
delay_time: ''
|
|
||||||
hold_m_name: ''
|
|
||||||
liquid_material_name: ''
|
|
||||||
material_name: ''
|
|
||||||
order_name: ''
|
|
||||||
speed: ''
|
|
||||||
target_weigh: ''
|
|
||||||
temperature: ''
|
|
||||||
volume: ''
|
|
||||||
handles: {}
|
|
||||||
result:
|
|
||||||
return_info: return_info
|
|
||||||
schema:
|
|
||||||
description: ''
|
|
||||||
properties:
|
|
||||||
feedback:
|
|
||||||
properties: {}
|
|
||||||
required: []
|
|
||||||
title: DispenStationSolnPrep_Feedback
|
|
||||||
type: object
|
|
||||||
goal:
|
|
||||||
properties:
|
|
||||||
delay_time:
|
|
||||||
type: string
|
|
||||||
hold_m_name:
|
|
||||||
type: string
|
|
||||||
liquid_material_name:
|
|
||||||
type: string
|
|
||||||
material_name:
|
|
||||||
type: string
|
|
||||||
order_name:
|
|
||||||
type: string
|
|
||||||
speed:
|
|
||||||
type: string
|
|
||||||
target_weigh:
|
|
||||||
type: string
|
|
||||||
temperature:
|
|
||||||
type: string
|
|
||||||
volume:
|
|
||||||
type: string
|
|
||||||
required:
|
|
||||||
- order_name
|
|
||||||
- material_name
|
|
||||||
- target_weigh
|
|
||||||
- volume
|
|
||||||
- liquid_material_name
|
|
||||||
- speed
|
|
||||||
- temperature
|
|
||||||
- delay_time
|
|
||||||
- hold_m_name
|
|
||||||
title: DispenStationSolnPrep_Goal
|
|
||||||
type: object
|
|
||||||
result:
|
|
||||||
properties:
|
|
||||||
return_info:
|
|
||||||
type: string
|
|
||||||
required:
|
|
||||||
- return_info
|
|
||||||
title: DispenStationSolnPrep_Result
|
|
||||||
type: object
|
|
||||||
required:
|
|
||||||
- goal
|
|
||||||
title: DispenStationSolnPrep
|
|
||||||
type: object
|
|
||||||
type: DispenStationSolnPrep
|
|
||||||
module: unilabos.devices.workstation.bioyond_studio.dispensing_station:BioyondDispensingStation
|
|
||||||
status_types: {}
|
|
||||||
type: python
|
|
||||||
config_info: []
|
|
||||||
description: ''
|
|
||||||
handles: []
|
|
||||||
icon: ''
|
|
||||||
init_param_schema:
|
|
||||||
config:
|
|
||||||
properties:
|
|
||||||
config:
|
|
||||||
type: string
|
|
||||||
deck:
|
|
||||||
type: string
|
|
||||||
required:
|
|
||||||
- config
|
|
||||||
- deck
|
|
||||||
type: object
|
|
||||||
data:
|
|
||||||
properties: {}
|
|
||||||
required: []
|
|
||||||
type: object
|
|
||||||
version: 1.0.0
|
|
||||||
@@ -850,11 +850,9 @@ liquid_handler:
|
|||||||
plate: null
|
plate: null
|
||||||
volumes: null
|
volumes: null
|
||||||
well_names: null
|
well_names: null
|
||||||
wells: null
|
|
||||||
handles: {}
|
handles: {}
|
||||||
placeholder_keys:
|
placeholder_keys:
|
||||||
plate: unilabos_resources
|
plate: unilabos_resources
|
||||||
wells: unilabos_resources
|
|
||||||
result: {}
|
result: {}
|
||||||
schema:
|
schema:
|
||||||
description: ''
|
description: ''
|
||||||
@@ -954,89 +952,9 @@ liquid_handler:
|
|||||||
items:
|
items:
|
||||||
type: string
|
type: string
|
||||||
type: array
|
type: array
|
||||||
wells:
|
|
||||||
items:
|
|
||||||
additionalProperties: false
|
|
||||||
properties:
|
|
||||||
category:
|
|
||||||
type: string
|
|
||||||
children:
|
|
||||||
items:
|
|
||||||
type: string
|
|
||||||
type: array
|
|
||||||
config:
|
|
||||||
type: string
|
|
||||||
data:
|
|
||||||
type: string
|
|
||||||
id:
|
|
||||||
type: string
|
|
||||||
name:
|
|
||||||
type: string
|
|
||||||
parent:
|
|
||||||
type: string
|
|
||||||
pose:
|
|
||||||
additionalProperties: false
|
|
||||||
properties:
|
|
||||||
orientation:
|
|
||||||
additionalProperties: false
|
|
||||||
properties:
|
|
||||||
w:
|
|
||||||
maximum: 1.7976931348623157e+308
|
|
||||||
minimum: -1.7976931348623157e+308
|
|
||||||
type: number
|
|
||||||
x:
|
|
||||||
maximum: 1.7976931348623157e+308
|
|
||||||
minimum: -1.7976931348623157e+308
|
|
||||||
type: number
|
|
||||||
y:
|
|
||||||
maximum: 1.7976931348623157e+308
|
|
||||||
minimum: -1.7976931348623157e+308
|
|
||||||
type: number
|
|
||||||
z:
|
|
||||||
maximum: 1.7976931348623157e+308
|
|
||||||
minimum: -1.7976931348623157e+308
|
|
||||||
type: number
|
|
||||||
required:
|
|
||||||
- x
|
|
||||||
- y
|
|
||||||
- z
|
|
||||||
- w
|
|
||||||
title: orientation
|
|
||||||
type: object
|
|
||||||
position:
|
|
||||||
additionalProperties: false
|
|
||||||
properties:
|
|
||||||
x:
|
|
||||||
maximum: 1.7976931348623157e+308
|
|
||||||
minimum: -1.7976931348623157e+308
|
|
||||||
type: number
|
|
||||||
y:
|
|
||||||
maximum: 1.7976931348623157e+308
|
|
||||||
minimum: -1.7976931348623157e+308
|
|
||||||
type: number
|
|
||||||
z:
|
|
||||||
maximum: 1.7976931348623157e+308
|
|
||||||
minimum: -1.7976931348623157e+308
|
|
||||||
type: number
|
|
||||||
required:
|
|
||||||
- x
|
|
||||||
- y
|
|
||||||
- z
|
|
||||||
title: position
|
|
||||||
type: object
|
|
||||||
required:
|
|
||||||
- position
|
|
||||||
- orientation
|
|
||||||
title: pose
|
|
||||||
type: object
|
|
||||||
sample_id:
|
|
||||||
type: string
|
|
||||||
type:
|
|
||||||
type: string
|
|
||||||
title: well
|
|
||||||
type: object
|
|
||||||
type: array
|
|
||||||
required:
|
required:
|
||||||
|
- plate
|
||||||
|
- well_names
|
||||||
- liquid_names
|
- liquid_names
|
||||||
- volumes
|
- volumes
|
||||||
type: object
|
type: object
|
||||||
@@ -5407,13 +5325,13 @@ liquid_handler.biomek:
|
|||||||
handler_key: tip_rack
|
handler_key: tip_rack
|
||||||
label: tip_rack
|
label: tip_rack
|
||||||
output:
|
output:
|
||||||
- data_key: sources
|
- data_key: liquid
|
||||||
data_source: handle
|
data_source: handle
|
||||||
data_type: resource
|
data_type: resource
|
||||||
handler_key: sources_out
|
handler_key: sources_out
|
||||||
label: sources
|
label: sources
|
||||||
- data_key: targets
|
- data_key: liquid
|
||||||
data_source: handle
|
data_source: executor
|
||||||
data_type: resource
|
data_type: resource
|
||||||
handler_key: targets_out
|
handler_key: targets_out
|
||||||
label: targets
|
label: targets
|
||||||
@@ -7685,43 +7603,6 @@ liquid_handler.prcxi:
|
|||||||
title: iter_tips参数
|
title: iter_tips参数
|
||||||
type: object
|
type: object
|
||||||
type: UniLabJsonCommand
|
type: UniLabJsonCommand
|
||||||
auto-magnetic_action:
|
|
||||||
feedback: {}
|
|
||||||
goal: {}
|
|
||||||
goal_default:
|
|
||||||
height: null
|
|
||||||
is_wait: null
|
|
||||||
module_no: null
|
|
||||||
time: null
|
|
||||||
handles: {}
|
|
||||||
placeholder_keys: {}
|
|
||||||
result: {}
|
|
||||||
schema:
|
|
||||||
description: ''
|
|
||||||
properties:
|
|
||||||
feedback: {}
|
|
||||||
goal:
|
|
||||||
properties:
|
|
||||||
height:
|
|
||||||
type: integer
|
|
||||||
is_wait:
|
|
||||||
type: boolean
|
|
||||||
module_no:
|
|
||||||
type: integer
|
|
||||||
time:
|
|
||||||
type: integer
|
|
||||||
required:
|
|
||||||
- time
|
|
||||||
- module_no
|
|
||||||
- height
|
|
||||||
- is_wait
|
|
||||||
type: object
|
|
||||||
result: {}
|
|
||||||
required:
|
|
||||||
- goal
|
|
||||||
title: magnetic_action参数
|
|
||||||
type: object
|
|
||||||
type: UniLabJsonCommandAsync
|
|
||||||
auto-move_to:
|
auto-move_to:
|
||||||
feedback: {}
|
feedback: {}
|
||||||
goal: {}
|
goal: {}
|
||||||
@@ -7755,61 +7636,10 @@ liquid_handler.prcxi:
|
|||||||
title: move_to参数
|
title: move_to参数
|
||||||
type: object
|
type: object
|
||||||
type: UniLabJsonCommandAsync
|
type: UniLabJsonCommandAsync
|
||||||
auto-plr_pos_to_prcxi:
|
|
||||||
feedback: {}
|
|
||||||
goal: {}
|
|
||||||
goal_default:
|
|
||||||
resource: null
|
|
||||||
handles: {}
|
|
||||||
placeholder_keys: {}
|
|
||||||
result: {}
|
|
||||||
schema:
|
|
||||||
description: ''
|
|
||||||
properties:
|
|
||||||
feedback: {}
|
|
||||||
goal:
|
|
||||||
properties:
|
|
||||||
resource:
|
|
||||||
type: object
|
|
||||||
required:
|
|
||||||
- resource
|
|
||||||
type: object
|
|
||||||
result: {}
|
|
||||||
required:
|
|
||||||
- goal
|
|
||||||
title: plr_pos_to_prcxi参数
|
|
||||||
type: object
|
|
||||||
type: UniLabJsonCommand
|
|
||||||
auto-post_init:
|
|
||||||
feedback: {}
|
|
||||||
goal: {}
|
|
||||||
goal_default:
|
|
||||||
ros_node: null
|
|
||||||
handles: {}
|
|
||||||
placeholder_keys: {}
|
|
||||||
result: {}
|
|
||||||
schema:
|
|
||||||
description: ''
|
|
||||||
properties:
|
|
||||||
feedback: {}
|
|
||||||
goal:
|
|
||||||
properties:
|
|
||||||
ros_node:
|
|
||||||
type: object
|
|
||||||
required:
|
|
||||||
- ros_node
|
|
||||||
type: object
|
|
||||||
result: {}
|
|
||||||
required:
|
|
||||||
- goal
|
|
||||||
title: post_init参数
|
|
||||||
type: object
|
|
||||||
type: UniLabJsonCommand
|
|
||||||
auto-run_protocol:
|
auto-run_protocol:
|
||||||
feedback: {}
|
feedback: {}
|
||||||
goal: {}
|
goal: {}
|
||||||
goal_default:
|
goal_default: {}
|
||||||
protocol_id: null
|
|
||||||
handles: {}
|
handles: {}
|
||||||
placeholder_keys: {}
|
placeholder_keys: {}
|
||||||
result: {}
|
result: {}
|
||||||
@@ -7818,9 +7648,7 @@ liquid_handler.prcxi:
|
|||||||
properties:
|
properties:
|
||||||
feedback: {}
|
feedback: {}
|
||||||
goal:
|
goal:
|
||||||
properties:
|
properties: {}
|
||||||
protocol_id:
|
|
||||||
type: string
|
|
||||||
required: []
|
required: []
|
||||||
type: object
|
type: object
|
||||||
result: {}
|
result: {}
|
||||||
@@ -7903,47 +7731,6 @@ liquid_handler.prcxi:
|
|||||||
title: shaker_action参数
|
title: shaker_action参数
|
||||||
type: object
|
type: object
|
||||||
type: UniLabJsonCommandAsync
|
type: UniLabJsonCommandAsync
|
||||||
auto-shaking_incubation_action:
|
|
||||||
feedback: {}
|
|
||||||
goal: {}
|
|
||||||
goal_default:
|
|
||||||
amplitude: null
|
|
||||||
is_wait: null
|
|
||||||
module_no: null
|
|
||||||
temperature: null
|
|
||||||
time: null
|
|
||||||
handles: {}
|
|
||||||
placeholder_keys: {}
|
|
||||||
result: {}
|
|
||||||
schema:
|
|
||||||
description: ''
|
|
||||||
properties:
|
|
||||||
feedback: {}
|
|
||||||
goal:
|
|
||||||
properties:
|
|
||||||
amplitude:
|
|
||||||
type: integer
|
|
||||||
is_wait:
|
|
||||||
type: boolean
|
|
||||||
module_no:
|
|
||||||
type: integer
|
|
||||||
temperature:
|
|
||||||
type: integer
|
|
||||||
time:
|
|
||||||
type: integer
|
|
||||||
required:
|
|
||||||
- time
|
|
||||||
- module_no
|
|
||||||
- amplitude
|
|
||||||
- is_wait
|
|
||||||
- temperature
|
|
||||||
type: object
|
|
||||||
result: {}
|
|
||||||
required:
|
|
||||||
- goal
|
|
||||||
title: shaking_incubation_action参数
|
|
||||||
type: object
|
|
||||||
type: UniLabJsonCommandAsync
|
|
||||||
auto-touch_tip:
|
auto-touch_tip:
|
||||||
feedback: {}
|
feedback: {}
|
||||||
goal: {}
|
goal: {}
|
||||||
@@ -9455,19 +9242,13 @@ liquid_handler.prcxi:
|
|||||||
plate: null
|
plate: null
|
||||||
volumes: null
|
volumes: null
|
||||||
well_names: null
|
well_names: null
|
||||||
wells: null
|
|
||||||
handles:
|
handles:
|
||||||
input:
|
input:
|
||||||
- data_key: '@this.0@@@wells'
|
|
||||||
data_source: handle
|
|
||||||
data_type: resource
|
|
||||||
handler_key: wells_identifier
|
|
||||||
label: 待设定液体孔(框选)
|
|
||||||
- data_key: '@this.0@@@plate'
|
- data_key: '@this.0@@@plate'
|
||||||
data_source: handle
|
data_source: handle
|
||||||
data_type: resource
|
data_type: resource
|
||||||
handler_key: input_plate
|
handler_key: input_plate
|
||||||
label: 待设定液体板(兼容 fallback)
|
label: 待设定液体板
|
||||||
output:
|
output:
|
||||||
- data_key: plate.@flatten
|
- data_key: plate.@flatten
|
||||||
data_source: executor
|
data_source: executor
|
||||||
@@ -9486,7 +9267,6 @@ liquid_handler.prcxi:
|
|||||||
label: 各孔设定体积
|
label: 各孔设定体积
|
||||||
placeholder_keys:
|
placeholder_keys:
|
||||||
plate: unilabos_resources
|
plate: unilabos_resources
|
||||||
wells: unilabos_resources
|
|
||||||
result: {}
|
result: {}
|
||||||
schema:
|
schema:
|
||||||
description: ''
|
description: ''
|
||||||
@@ -9586,89 +9366,9 @@ liquid_handler.prcxi:
|
|||||||
items:
|
items:
|
||||||
type: string
|
type: string
|
||||||
type: array
|
type: array
|
||||||
wells:
|
|
||||||
items:
|
|
||||||
additionalProperties: false
|
|
||||||
properties:
|
|
||||||
category:
|
|
||||||
type: string
|
|
||||||
children:
|
|
||||||
items:
|
|
||||||
type: string
|
|
||||||
type: array
|
|
||||||
config:
|
|
||||||
type: string
|
|
||||||
data:
|
|
||||||
type: string
|
|
||||||
id:
|
|
||||||
type: string
|
|
||||||
name:
|
|
||||||
type: string
|
|
||||||
parent:
|
|
||||||
type: string
|
|
||||||
pose:
|
|
||||||
additionalProperties: false
|
|
||||||
properties:
|
|
||||||
orientation:
|
|
||||||
additionalProperties: false
|
|
||||||
properties:
|
|
||||||
w:
|
|
||||||
maximum: 1.7976931348623157e+308
|
|
||||||
minimum: -1.7976931348623157e+308
|
|
||||||
type: number
|
|
||||||
x:
|
|
||||||
maximum: 1.7976931348623157e+308
|
|
||||||
minimum: -1.7976931348623157e+308
|
|
||||||
type: number
|
|
||||||
y:
|
|
||||||
maximum: 1.7976931348623157e+308
|
|
||||||
minimum: -1.7976931348623157e+308
|
|
||||||
type: number
|
|
||||||
z:
|
|
||||||
maximum: 1.7976931348623157e+308
|
|
||||||
minimum: -1.7976931348623157e+308
|
|
||||||
type: number
|
|
||||||
required:
|
|
||||||
- x
|
|
||||||
- y
|
|
||||||
- z
|
|
||||||
- w
|
|
||||||
title: orientation
|
|
||||||
type: object
|
|
||||||
position:
|
|
||||||
additionalProperties: false
|
|
||||||
properties:
|
|
||||||
x:
|
|
||||||
maximum: 1.7976931348623157e+308
|
|
||||||
minimum: -1.7976931348623157e+308
|
|
||||||
type: number
|
|
||||||
y:
|
|
||||||
maximum: 1.7976931348623157e+308
|
|
||||||
minimum: -1.7976931348623157e+308
|
|
||||||
type: number
|
|
||||||
z:
|
|
||||||
maximum: 1.7976931348623157e+308
|
|
||||||
minimum: -1.7976931348623157e+308
|
|
||||||
type: number
|
|
||||||
required:
|
|
||||||
- x
|
|
||||||
- y
|
|
||||||
- z
|
|
||||||
title: position
|
|
||||||
type: object
|
|
||||||
required:
|
|
||||||
- position
|
|
||||||
- orientation
|
|
||||||
title: pose
|
|
||||||
type: object
|
|
||||||
sample_id:
|
|
||||||
type: string
|
|
||||||
type:
|
|
||||||
type: string
|
|
||||||
title: well
|
|
||||||
type: object
|
|
||||||
type: array
|
|
||||||
required:
|
required:
|
||||||
|
- plate
|
||||||
|
- well_names
|
||||||
- liquid_names
|
- liquid_names
|
||||||
- volumes
|
- volumes
|
||||||
type: object
|
type: object
|
||||||
@@ -10102,28 +9802,48 @@ liquid_handler.prcxi:
|
|||||||
type: Transfer
|
type: Transfer
|
||||||
transfer_liquid:
|
transfer_liquid:
|
||||||
feedback: {}
|
feedback: {}
|
||||||
goal: {}
|
goal:
|
||||||
|
asp_flow_rates: asp_flow_rates
|
||||||
|
asp_vols: asp_vols
|
||||||
|
blow_out_air_volume: blow_out_air_volume
|
||||||
|
delays: delays
|
||||||
|
dis_flow_rates: dis_flow_rates
|
||||||
|
dis_vols: dis_vols
|
||||||
|
is_96_well: is_96_well
|
||||||
|
liquid_height: liquid_height
|
||||||
|
mix_liquid_height: mix_liquid_height
|
||||||
|
mix_rate: mix_rate
|
||||||
|
mix_stage: mix_stage
|
||||||
|
mix_times: mix_times
|
||||||
|
mix_vol: mix_vol
|
||||||
|
none_keys: none_keys
|
||||||
|
offsets: offsets
|
||||||
|
sources: sources
|
||||||
|
spread: spread
|
||||||
|
targets: targets
|
||||||
|
tip_racks: tip_racks
|
||||||
|
touch_tip: touch_tip
|
||||||
|
use_channels: use_channels
|
||||||
goal_default:
|
goal_default:
|
||||||
asp_flow_rates: null
|
asp_flow_rates: []
|
||||||
asp_vols: null
|
asp_vols: []
|
||||||
blow_out_air_volume: null
|
blow_out_air_volume: []
|
||||||
blow_out_air_volume_before: null
|
delays: []
|
||||||
delays: null
|
dis_flow_rates: []
|
||||||
dis_flow_rates: null
|
dis_vols: []
|
||||||
dis_vols: null
|
|
||||||
is_96_well: false
|
is_96_well: false
|
||||||
liquid_height: null
|
liquid_height: []
|
||||||
mix_liquid_height: null
|
mix_liquid_height: 0.0
|
||||||
mix_rate: null
|
mix_rate: 0
|
||||||
mix_stage: none
|
mix_stage: ''
|
||||||
mix_times: null
|
mix_times: 0
|
||||||
mix_vol: null
|
mix_vol: 0
|
||||||
none_keys: []
|
none_keys: []
|
||||||
offsets: null
|
offsets: []
|
||||||
sources: null
|
sources: []
|
||||||
spread: wide
|
spread: ''
|
||||||
targets: null
|
targets: []
|
||||||
tip_racks: null
|
tip_racks: []
|
||||||
touch_tip: false
|
touch_tip: false
|
||||||
use_channels: []
|
use_channels: []
|
||||||
handles:
|
handles:
|
||||||
@@ -10138,7 +9858,7 @@ liquid_handler.prcxi:
|
|||||||
data_type: resource
|
data_type: resource
|
||||||
handler_key: targets_identifier
|
handler_key: targets_identifier
|
||||||
label: 转移目标
|
label: 转移目标
|
||||||
- data_key: tip_racks
|
- data_key: tip_rack
|
||||||
data_source: handle
|
data_source: handle
|
||||||
data_type: resource
|
data_type: resource
|
||||||
handler_key: tip_rack_identifier
|
handler_key: tip_rack_identifier
|
||||||
@@ -10164,7 +9884,10 @@ liquid_handler.prcxi:
|
|||||||
schema:
|
schema:
|
||||||
description: ''
|
description: ''
|
||||||
properties:
|
properties:
|
||||||
feedback: {}
|
feedback:
|
||||||
|
additionalProperties: true
|
||||||
|
title: LiquidHandlerTransfer_Feedback
|
||||||
|
type: object
|
||||||
goal:
|
goal:
|
||||||
additionalProperties: false
|
additionalProperties: false
|
||||||
properties:
|
properties:
|
||||||
@@ -10180,10 +9903,6 @@ liquid_handler.prcxi:
|
|||||||
items:
|
items:
|
||||||
type: number
|
type: number
|
||||||
type: array
|
type: array
|
||||||
blow_out_air_volume_before:
|
|
||||||
items:
|
|
||||||
type: number
|
|
||||||
type: array
|
|
||||||
delays:
|
delays:
|
||||||
items:
|
items:
|
||||||
type: integer
|
type: integer
|
||||||
@@ -10197,7 +9916,6 @@ liquid_handler.prcxi:
|
|||||||
type: number
|
type: number
|
||||||
type: array
|
type: array
|
||||||
is_96_well:
|
is_96_well:
|
||||||
default: false
|
|
||||||
type: boolean
|
type: boolean
|
||||||
liquid_height:
|
liquid_height:
|
||||||
items:
|
items:
|
||||||
@@ -10212,7 +9930,6 @@ liquid_handler.prcxi:
|
|||||||
minimum: -2147483648
|
minimum: -2147483648
|
||||||
type: integer
|
type: integer
|
||||||
mix_stage:
|
mix_stage:
|
||||||
default: none
|
|
||||||
type: string
|
type: string
|
||||||
mix_times:
|
mix_times:
|
||||||
maximum: 2147483647
|
maximum: 2147483647
|
||||||
@@ -10223,7 +9940,6 @@ liquid_handler.prcxi:
|
|||||||
minimum: -2147483648
|
minimum: -2147483648
|
||||||
type: integer
|
type: integer
|
||||||
none_keys:
|
none_keys:
|
||||||
default: []
|
|
||||||
items:
|
items:
|
||||||
type: string
|
type: string
|
||||||
type: array
|
type: array
|
||||||
@@ -10317,7 +10033,6 @@ liquid_handler.prcxi:
|
|||||||
type: object
|
type: object
|
||||||
type: array
|
type: array
|
||||||
spread:
|
spread:
|
||||||
default: wide
|
|
||||||
type: string
|
type: string
|
||||||
targets:
|
targets:
|
||||||
items:
|
items:
|
||||||
@@ -10468,228 +10183,27 @@ liquid_handler.prcxi:
|
|||||||
type: object
|
type: object
|
||||||
type: array
|
type: array
|
||||||
touch_tip:
|
touch_tip:
|
||||||
default: false
|
|
||||||
type: boolean
|
type: boolean
|
||||||
use_channels:
|
use_channels:
|
||||||
items:
|
items:
|
||||||
type: integer
|
type: integer
|
||||||
type: array
|
type: array
|
||||||
required:
|
title: LiquidHandlerTransfer_Goal
|
||||||
- sources
|
|
||||||
- targets
|
|
||||||
- tip_racks
|
|
||||||
- asp_vols
|
|
||||||
- dis_vols
|
|
||||||
type: object
|
type: object
|
||||||
result:
|
result:
|
||||||
$defs:
|
additionalProperties: false
|
||||||
ResourceDict:
|
|
||||||
properties:
|
|
||||||
class:
|
|
||||||
description: Resource class name
|
|
||||||
title: Class
|
|
||||||
type: string
|
|
||||||
config:
|
|
||||||
additionalProperties: true
|
|
||||||
description: Resource configuration
|
|
||||||
title: Config
|
|
||||||
type: object
|
|
||||||
data:
|
|
||||||
additionalProperties: true
|
|
||||||
description: 'Resource data, eg: container liquid data'
|
|
||||||
title: Data
|
|
||||||
type: object
|
|
||||||
description:
|
|
||||||
default: ''
|
|
||||||
description: Resource description
|
|
||||||
title: Description
|
|
||||||
type: string
|
|
||||||
extra:
|
|
||||||
additionalProperties: true
|
|
||||||
description: 'Extra data, eg: slot index'
|
|
||||||
title: Extra
|
|
||||||
type: object
|
|
||||||
icon:
|
|
||||||
default: ''
|
|
||||||
description: Resource icon
|
|
||||||
title: Icon
|
|
||||||
type: string
|
|
||||||
id:
|
|
||||||
description: Resource ID
|
|
||||||
title: Id
|
|
||||||
type: string
|
|
||||||
model:
|
|
||||||
additionalProperties: true
|
|
||||||
description: Resource model
|
|
||||||
title: Model
|
|
||||||
type: object
|
|
||||||
name:
|
|
||||||
description: Resource name
|
|
||||||
title: Name
|
|
||||||
type: string
|
|
||||||
parent:
|
|
||||||
anyOf:
|
|
||||||
- $ref: '#/$defs/ResourceDict'
|
|
||||||
- type: 'null'
|
|
||||||
default: null
|
|
||||||
description: Parent resource object
|
|
||||||
parent_uuid:
|
|
||||||
anyOf:
|
|
||||||
- type: string
|
|
||||||
- type: 'null'
|
|
||||||
default: null
|
|
||||||
description: Parent resource uuid
|
|
||||||
title: Parent Uuid
|
|
||||||
pose:
|
|
||||||
$ref: '#/$defs/ResourceDictPosition'
|
|
||||||
description: Resource position
|
|
||||||
schema:
|
|
||||||
additionalProperties: true
|
|
||||||
description: Resource schema
|
|
||||||
title: Schema
|
|
||||||
type: object
|
|
||||||
type:
|
|
||||||
anyOf:
|
|
||||||
- const: device
|
|
||||||
type: string
|
|
||||||
- type: string
|
|
||||||
description: Resource type
|
|
||||||
title: Type
|
|
||||||
uuid:
|
|
||||||
description: Resource UUID
|
|
||||||
title: Uuid
|
|
||||||
type: string
|
|
||||||
required:
|
|
||||||
- id
|
|
||||||
- uuid
|
|
||||||
- name
|
|
||||||
- type
|
|
||||||
- class
|
|
||||||
- config
|
|
||||||
- data
|
|
||||||
- extra
|
|
||||||
title: ResourceDict
|
|
||||||
type: object
|
|
||||||
ResourceDictPosition:
|
|
||||||
properties:
|
|
||||||
cross_section_type:
|
|
||||||
default: rectangle
|
|
||||||
description: Cross section type
|
|
||||||
enum:
|
|
||||||
- rectangle
|
|
||||||
- circle
|
|
||||||
- rounded_rectangle
|
|
||||||
title: Cross Section Type
|
|
||||||
type: string
|
|
||||||
layout:
|
|
||||||
default: x-y
|
|
||||||
description: Resource layout
|
|
||||||
enum:
|
|
||||||
- 2d
|
|
||||||
- x-y
|
|
||||||
- z-y
|
|
||||||
- x-z
|
|
||||||
title: Layout
|
|
||||||
type: string
|
|
||||||
position:
|
|
||||||
$ref: '#/$defs/ResourceDictPositionObject'
|
|
||||||
description: Resource position
|
|
||||||
position3d:
|
|
||||||
$ref: '#/$defs/ResourceDictPositionObject'
|
|
||||||
description: Resource position in 3D space
|
|
||||||
rotation:
|
|
||||||
$ref: '#/$defs/ResourceDictPositionObject'
|
|
||||||
description: Resource rotation
|
|
||||||
scale:
|
|
||||||
$ref: '#/$defs/ResourceDictPositionScale'
|
|
||||||
description: Resource scale
|
|
||||||
size:
|
|
||||||
$ref: '#/$defs/ResourceDictPositionSize'
|
|
||||||
description: Resource size
|
|
||||||
title: ResourceDictPosition
|
|
||||||
type: object
|
|
||||||
ResourceDictPositionObject:
|
|
||||||
properties:
|
|
||||||
x:
|
|
||||||
default: 0.0
|
|
||||||
description: X coordinate
|
|
||||||
title: X
|
|
||||||
type: number
|
|
||||||
y:
|
|
||||||
default: 0.0
|
|
||||||
description: Y coordinate
|
|
||||||
title: Y
|
|
||||||
type: number
|
|
||||||
z:
|
|
||||||
default: 0.0
|
|
||||||
description: Z coordinate
|
|
||||||
title: Z
|
|
||||||
type: number
|
|
||||||
title: ResourceDictPositionObject
|
|
||||||
type: object
|
|
||||||
ResourceDictPositionScale:
|
|
||||||
properties:
|
|
||||||
x:
|
|
||||||
default: 0.0
|
|
||||||
description: x scale
|
|
||||||
title: X
|
|
||||||
type: number
|
|
||||||
y:
|
|
||||||
default: 0.0
|
|
||||||
description: y scale
|
|
||||||
title: Y
|
|
||||||
type: number
|
|
||||||
z:
|
|
||||||
default: 0.0
|
|
||||||
description: z scale
|
|
||||||
title: Z
|
|
||||||
type: number
|
|
||||||
title: ResourceDictPositionScale
|
|
||||||
type: object
|
|
||||||
ResourceDictPositionSize:
|
|
||||||
properties:
|
|
||||||
depth:
|
|
||||||
default: 0.0
|
|
||||||
description: Depth
|
|
||||||
title: Depth
|
|
||||||
type: number
|
|
||||||
height:
|
|
||||||
default: 0.0
|
|
||||||
description: Height
|
|
||||||
title: Height
|
|
||||||
type: number
|
|
||||||
width:
|
|
||||||
default: 0.0
|
|
||||||
description: Width
|
|
||||||
title: Width
|
|
||||||
type: number
|
|
||||||
title: ResourceDictPositionSize
|
|
||||||
type: object
|
|
||||||
properties:
|
properties:
|
||||||
sources:
|
return_info:
|
||||||
items:
|
type: string
|
||||||
items:
|
success:
|
||||||
$ref: '#/$defs/ResourceDict'
|
type: boolean
|
||||||
type: array
|
title: LiquidHandlerTransfer_Result
|
||||||
title: Sources
|
|
||||||
type: array
|
|
||||||
targets:
|
|
||||||
items:
|
|
||||||
items:
|
|
||||||
$ref: '#/$defs/ResourceDict'
|
|
||||||
type: array
|
|
||||||
title: Targets
|
|
||||||
type: array
|
|
||||||
required:
|
|
||||||
- sources
|
|
||||||
- targets
|
|
||||||
title: TransferLiquidReturn
|
|
||||||
type: object
|
type: object
|
||||||
required:
|
required:
|
||||||
- goal
|
- goal
|
||||||
title: transfer_liquid参数
|
title: LiquidHandlerTransfer
|
||||||
type: object
|
type: object
|
||||||
type: UniLabJsonCommandAsync
|
type: LiquidHandlerTransfer
|
||||||
module: unilabos.devices.liquid_handling.prcxi.prcxi:PRCXI9300Handler
|
module: unilabos.devices.liquid_handling.prcxi.prcxi:PRCXI9300Handler
|
||||||
status_types:
|
status_types:
|
||||||
reset_ok: bool
|
reset_ok: bool
|
||||||
@@ -10712,12 +10226,6 @@ liquid_handler.prcxi:
|
|||||||
type: string
|
type: string
|
||||||
deck:
|
deck:
|
||||||
type: object
|
type: object
|
||||||
deck_y:
|
|
||||||
default: 400
|
|
||||||
type: string
|
|
||||||
deck_z:
|
|
||||||
default: 300
|
|
||||||
type: string
|
|
||||||
host:
|
host:
|
||||||
type: string
|
type: string
|
||||||
is_9320:
|
is_9320:
|
||||||
@@ -10728,44 +10236,17 @@ liquid_handler.prcxi:
|
|||||||
type: string
|
type: string
|
||||||
port:
|
port:
|
||||||
type: integer
|
type: integer
|
||||||
rail_interval:
|
|
||||||
default: 0
|
|
||||||
type: string
|
|
||||||
rail_nums:
|
|
||||||
default: 4
|
|
||||||
type: string
|
|
||||||
rail_width:
|
|
||||||
default: 27.5
|
|
||||||
type: string
|
|
||||||
setup:
|
setup:
|
||||||
default: true
|
default: true
|
||||||
type: string
|
type: string
|
||||||
simulator:
|
simulator:
|
||||||
default: false
|
default: false
|
||||||
type: string
|
type: string
|
||||||
start_rail:
|
|
||||||
default: 2
|
|
||||||
type: string
|
|
||||||
step_mode:
|
step_mode:
|
||||||
default: false
|
default: false
|
||||||
type: string
|
type: string
|
||||||
timeout:
|
timeout:
|
||||||
type: number
|
type: number
|
||||||
x_increase:
|
|
||||||
default: -0.003636
|
|
||||||
type: string
|
|
||||||
x_offset:
|
|
||||||
default: -0.8
|
|
||||||
type: string
|
|
||||||
xy_coupling:
|
|
||||||
default: -0.0045
|
|
||||||
type: string
|
|
||||||
y_increase:
|
|
||||||
default: -0.003636
|
|
||||||
type: string
|
|
||||||
y_offset:
|
|
||||||
default: -37.98
|
|
||||||
type: string
|
|
||||||
required:
|
required:
|
||||||
- deck
|
- deck
|
||||||
- host
|
- host
|
||||||
|
|||||||
@@ -173,64 +173,50 @@ robotic_arm.SCARA_with_slider.moveit.virtual:
|
|||||||
type: object
|
type: object
|
||||||
type: UniLabJsonCommand
|
type: UniLabJsonCommand
|
||||||
pick_and_place:
|
pick_and_place:
|
||||||
feedback: {}
|
feedback:
|
||||||
goal: {}
|
status: status
|
||||||
|
goal:
|
||||||
|
command: command
|
||||||
goal_default:
|
goal_default:
|
||||||
constraints: null
|
command: ''
|
||||||
lift_height: null
|
|
||||||
move_group: null
|
|
||||||
option: null
|
|
||||||
resource: null
|
|
||||||
retry: null
|
|
||||||
speed: null
|
|
||||||
status: null
|
|
||||||
target: null
|
|
||||||
x_distance: null
|
|
||||||
y_distance: null
|
|
||||||
handles: {}
|
handles: {}
|
||||||
placeholder_keys: {}
|
placeholder_keys: {}
|
||||||
result: {}
|
result:
|
||||||
|
return_info: return_info
|
||||||
|
success: success
|
||||||
schema:
|
schema:
|
||||||
description: pick_and_place 显式参数(UniLabJsonCommand)
|
description: ''
|
||||||
properties:
|
properties:
|
||||||
feedback: {}
|
feedback:
|
||||||
goal:
|
additionalProperties: false
|
||||||
properties:
|
properties:
|
||||||
constraints:
|
|
||||||
items:
|
|
||||||
type: number
|
|
||||||
type: array
|
|
||||||
lift_height:
|
|
||||||
type: string
|
|
||||||
move_group:
|
|
||||||
type: string
|
|
||||||
option:
|
|
||||||
type: string
|
|
||||||
resource:
|
|
||||||
type: string
|
|
||||||
retry:
|
|
||||||
type: string
|
|
||||||
speed:
|
|
||||||
type: string
|
|
||||||
status:
|
status:
|
||||||
type: string
|
type: string
|
||||||
target:
|
title: SendCmd_Feedback
|
||||||
type: string
|
type: object
|
||||||
x_distance:
|
goal:
|
||||||
type: string
|
additionalProperties: false
|
||||||
y_distance:
|
properties:
|
||||||
type: string
|
command:
|
||||||
required:
|
description: A JSON-formatted string that includes option, target,
|
||||||
- option
|
speed, lift_height, mt_height
|
||||||
- move_group
|
type: string
|
||||||
- status
|
title: SendCmd_Goal
|
||||||
|
type: object
|
||||||
|
result:
|
||||||
|
additionalProperties: false
|
||||||
|
properties:
|
||||||
|
return_info:
|
||||||
|
type: string
|
||||||
|
success:
|
||||||
|
type: boolean
|
||||||
|
title: SendCmd_Result
|
||||||
type: object
|
type: object
|
||||||
result: {}
|
|
||||||
required:
|
required:
|
||||||
- goal
|
- goal
|
||||||
title: pick_and_place参数
|
title: SendCmd
|
||||||
type: object
|
type: object
|
||||||
type: UniLabJsonCommand
|
type: SendCmd
|
||||||
set_position:
|
set_position:
|
||||||
feedback:
|
feedback:
|
||||||
status: status
|
status: status
|
||||||
|
|||||||
@@ -684,64 +684,50 @@ linear_motion.toyo_xyz.sim:
|
|||||||
type: object
|
type: object
|
||||||
type: UniLabJsonCommand
|
type: UniLabJsonCommand
|
||||||
pick_and_place:
|
pick_and_place:
|
||||||
feedback: {}
|
feedback:
|
||||||
goal: {}
|
status: status
|
||||||
|
goal:
|
||||||
|
command: command
|
||||||
goal_default:
|
goal_default:
|
||||||
constraints: null
|
command: ''
|
||||||
lift_height: null
|
|
||||||
move_group: null
|
|
||||||
option: null
|
|
||||||
resource: null
|
|
||||||
retry: null
|
|
||||||
speed: null
|
|
||||||
status: null
|
|
||||||
target: null
|
|
||||||
x_distance: null
|
|
||||||
y_distance: null
|
|
||||||
handles: {}
|
handles: {}
|
||||||
placeholder_keys: {}
|
placeholder_keys: {}
|
||||||
result: {}
|
result:
|
||||||
|
return_info: return_info
|
||||||
|
success: success
|
||||||
schema:
|
schema:
|
||||||
description: pick_and_place 显式参数(UniLabJsonCommand)
|
description: ''
|
||||||
properties:
|
properties:
|
||||||
feedback: {}
|
feedback:
|
||||||
goal:
|
additionalProperties: false
|
||||||
properties:
|
properties:
|
||||||
constraints:
|
|
||||||
items:
|
|
||||||
type: number
|
|
||||||
type: array
|
|
||||||
lift_height:
|
|
||||||
type: string
|
|
||||||
move_group:
|
|
||||||
type: string
|
|
||||||
option:
|
|
||||||
type: string
|
|
||||||
resource:
|
|
||||||
type: string
|
|
||||||
retry:
|
|
||||||
type: string
|
|
||||||
speed:
|
|
||||||
type: string
|
|
||||||
status:
|
status:
|
||||||
type: string
|
type: string
|
||||||
target:
|
title: SendCmd_Feedback
|
||||||
type: string
|
type: object
|
||||||
x_distance:
|
goal:
|
||||||
type: string
|
additionalProperties: false
|
||||||
y_distance:
|
properties:
|
||||||
type: string
|
command:
|
||||||
required:
|
description: A JSON-formatted string that includes option, target,
|
||||||
- option
|
speed, lift_height, mt_height
|
||||||
- move_group
|
type: string
|
||||||
- status
|
title: SendCmd_Goal
|
||||||
|
type: object
|
||||||
|
result:
|
||||||
|
additionalProperties: false
|
||||||
|
properties:
|
||||||
|
return_info:
|
||||||
|
type: string
|
||||||
|
success:
|
||||||
|
type: boolean
|
||||||
|
title: SendCmd_Result
|
||||||
type: object
|
type: object
|
||||||
result: {}
|
|
||||||
required:
|
required:
|
||||||
- goal
|
- goal
|
||||||
title: pick_and_place参数
|
title: SendCmd
|
||||||
type: object
|
type: object
|
||||||
type: UniLabJsonCommand
|
type: SendCmd
|
||||||
set_position:
|
set_position:
|
||||||
feedback:
|
feedback:
|
||||||
status: status
|
status: status
|
||||||
|
|||||||
@@ -0,0 +1,170 @@
|
|||||||
|
# UniLabOS 资源注册架构详解
|
||||||
|
|
||||||
|
> **目标受众**: 主要开发 `unilabos/registry/devices` 抽象层的开发者
|
||||||
|
> **最后更新**: 2026-01-11
|
||||||
|
> **维护者**: Uni-Lab-OS 开发团队
|
||||||
|
|
||||||
|
本文档详细说明 UniLabOS 资源注册系统的架构、资源的完整生命周期,以及如何实现动态物料位置追踪。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📚 目录
|
||||||
|
|
||||||
|
- [核心概念](#核心概念)
|
||||||
|
- [三层架构详解](#三层架构详解)
|
||||||
|
- [资源注册机制](#资源注册机制)
|
||||||
|
- [物料生命周期管理](#物料生命周期管理)
|
||||||
|
- [动态物料位置追踪](#动态物料位置追踪)
|
||||||
|
- [实战案例](#实战案例)
|
||||||
|
- [常见问题排查](#常见问题排查)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 核心概念
|
||||||
|
|
||||||
|
### 1. Resources vs Registry
|
||||||
|
|
||||||
|
UniLabOS 采用**声明式注册**模式,将资源的**定义**(Python)与**注册信息**(YAML)分离:
|
||||||
|
|
||||||
|
```
|
||||||
|
┌──────────────────────────────────────────────────────────┐
|
||||||
|
│ unilabos/resources (Python 实现) │
|
||||||
|
│ - 定义资源的物理属性、行为和创建逻辑 │
|
||||||
|
│ - 例如: 瓶子的尺寸、容量、材质 │
|
||||||
|
├──────────────────────────────────────────────────────────┤
|
||||||
|
│ unilabos/registry/resources (YAML 注册表) │
|
||||||
|
│ - 声明哪些资源可以被前端使用 │
|
||||||
|
│ - 定义资源的分类、图标、初始化参数 │
|
||||||
|
└──────────────────────────────────────────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
**为什么要分离?**
|
||||||
|
|
||||||
|
1. **解耦**: Python 代码可以定义无限多的资源类,但只有在 YAML 中注册的才能被前端识别
|
||||||
|
2. **灵活性**: 无需修改 Python 代码,只需修改 YAML 就能添加/移除可用资源
|
||||||
|
3. **可扩展性**: 第三方开发者可以通过 YAML 注册自己的资源,无需修改核心代码
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 三层架构详解
|
||||||
|
|
||||||
|
UniLabOS 资源系统采用**三层架构**,实现从前端UI到底层硬件的完整映射:
|
||||||
|
|
||||||
|
### 架构图
|
||||||
|
|
||||||
|
```
|
||||||
|
┌─────────────────────────────────────────────────────┐
|
||||||
|
│ 第1层: YAML 注册表 (registry/resources) │
|
||||||
|
│ - 告诉系统"哪些资源可用" │
|
||||||
|
│ - 前端通过此层获取可用资源列表 │
|
||||||
|
│ - 文件: YB_bottle.yaml, YB_bottle_carriers.yaml │
|
||||||
|
├─────────────────────────────────────────────────────┤
|
||||||
|
│ 第2层: Python 实现 (resources/bioyond) │
|
||||||
|
│ - 定义资源的具体属性和行为 │
|
||||||
|
│ - 创建资源实例的工厂函数 │
|
||||||
|
│ - 文件: YB_bottles.py, YB_bottle_carriers.py │
|
||||||
|
├─────────────────────────────────────────────────────┤
|
||||||
|
│ 第3层: Hardware/API 集成 (devices/workstation) │
|
||||||
|
│ - 连接 Bioyond 系统 API │
|
||||||
|
│ - 同步物料位置和状态 │
|
||||||
|
│ - 文件: station.py, bioyond_rpc.py, config.py │
|
||||||
|
└─────────────────────────────────────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
### 第1层: YAML 注册表
|
||||||
|
|
||||||
|
#### YB_bottle.yaml - 单个瓶子注册
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
YB_5ml_fenyeping:
|
||||||
|
category:
|
||||||
|
- yb3 # 系统分类
|
||||||
|
- YB_bottle # 资源类型
|
||||||
|
class:
|
||||||
|
module: unilabos.resources.bioyond.YB_bottles:YB_5ml_fenyeping # Python 函数路径
|
||||||
|
type: pylabrobot # 框架类型
|
||||||
|
description: YB_5ml_fenyeping # 前端显示名称
|
||||||
|
handles: []
|
||||||
|
icon: '' # 图标路径
|
||||||
|
init_param_schema: {} # 初始化参数 schema
|
||||||
|
registry_type: resource
|
||||||
|
version: 1.0.0
|
||||||
|
```
|
||||||
|
|
||||||
|
**作用:**
|
||||||
|
- 前端通过读取此文件知道有一个叫 "YB_5ml_fenyeping" 的资源
|
||||||
|
- 用户拖拽时,系统会调用 `YB_bottles:YB_5ml_fenyeping()` 创建实例
|
||||||
|
|
||||||
|
#### YB_bottle_carriers.yaml - 载架(容器)注册
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
YB_5ml_fenyepingban:
|
||||||
|
category:
|
||||||
|
- yb3
|
||||||
|
- YB_bottle_carriers
|
||||||
|
class:
|
||||||
|
module: unilabos.resources.bioyond.YB_bottle_carriers:YB_5ml_fenyepingban
|
||||||
|
type: pylabrobot
|
||||||
|
description: YB_5ml_fenyepingban # 5ml分液瓶板
|
||||||
|
```
|
||||||
|
|
||||||
|
**作用:**
|
||||||
|
- 载架是容器,里面可以放多个瓶子
|
||||||
|
- 例如: `YB_5ml_fenyepingban` 是一个 4x2 布局的板,可以放 8 个 5ml 瓶子
|
||||||
|
|
||||||
|
### 第2层: Python 实现
|
||||||
|
|
||||||
|
#### YB_bottles.py - 瓶子工厂函数
|
||||||
|
|
||||||
|
```python
|
||||||
|
def YB_5ml_fenyeping(
|
||||||
|
name: str,
|
||||||
|
diameter: float = 20.0, # 直径 (mm)
|
||||||
|
height: float = 50.0, # 高度 (mm)
|
||||||
|
max_volume: float = 5000.0, # 最大容量 (μL)
|
||||||
|
barcode: str = None,
|
||||||
|
) -> Bottle:
|
||||||
|
\"\"\"创建5ml分液瓶\"\"\"
|
||||||
|
return Bottle(
|
||||||
|
name=name,
|
||||||
|
diameter=diameter,
|
||||||
|
height=height,
|
||||||
|
max_volume=max_volume,
|
||||||
|
barcode=barcode,
|
||||||
|
model="YB_5ml_fenyeping", # ⭐ 与 YAML 中的名称对应
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
**关键点:**
|
||||||
|
- 函数名 `YB_5ml_fenyeping` 必须与 YAML 中的 `module` 路径末尾一致
|
||||||
|
- 返回一个 `Bottle` 对象(PyLabRobot 资源类型)
|
||||||
|
- `model` 字段用于在 Bioyond 系统中识别资源类型
|
||||||
|
|
||||||
|
**详细文档请参考完整版 README**
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 相关文件索引
|
||||||
|
|
||||||
|
### 核心文件
|
||||||
|
|
||||||
|
| 文件 | 功能 | 路径 |
|
||||||
|
|------|------|------|
|
||||||
|
| `YB_bottle.yaml` | 瓶子注册表 | `unilabos/registry/resources/bioyond/` |
|
||||||
|
| `YB_bottle_carriers.yaml` | 载架注册表 | `unilabos/registry/resources/bioyond/` |
|
||||||
|
| `deck.yaml` | Deck注册表 | `unilabos/registry/resources/bioyond/` |
|
||||||
|
| `YB_bottles.py` | 瓶子实现 | `unilabos/resources/bioyond/` |
|
||||||
|
| `YB_bottle_carriers.py` | 载架实现 | `unilabos/resources/bioyond/` |
|
||||||
|
| `YB_warehouses.py` | 仓库实现 | `unilabos/resources/bioyond/` |
|
||||||
|
| `decks.py` | Deck布局 | `unilabos/resources/bioyond/` |
|
||||||
|
| `station.py` | 物料同步 | `unilabos/devices/workstation/bioyond_studio/` |
|
||||||
|
| `config.py` | UUID映射 | `unilabos/devices/workstation/bioyond_studio/` |
|
||||||
|
|
||||||
|
### 仓库相关文档
|
||||||
|
|
||||||
|
- [README_WAREHOUSE.md](../../resources/bioyond/README_WAREHOUSE.md) - 仓库系统开发指南
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**维护者:** Uni-Lab-OS 开发团队
|
||||||
|
**最后更新:** 2026-01-11
|
||||||
@@ -20,6 +20,17 @@ BIOYOND_PolymerStation_Liquid_Vial:
|
|||||||
icon: ''
|
icon: ''
|
||||||
init_param_schema: {}
|
init_param_schema: {}
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
|
BIOYOND_PolymerStation_Measurement_Vial:
|
||||||
|
category:
|
||||||
|
- bottles
|
||||||
|
class:
|
||||||
|
module: unilabos.resources.bioyond.bottles:BIOYOND_PolymerStation_Measurement_Vial
|
||||||
|
type: pylabrobot
|
||||||
|
description: 聚合站-测量小瓶(测密度)
|
||||||
|
handles: []
|
||||||
|
icon: ''
|
||||||
|
init_param_schema: {}
|
||||||
|
version: 1.0.0
|
||||||
BIOYOND_PolymerStation_Reactor:
|
BIOYOND_PolymerStation_Reactor:
|
||||||
category:
|
category:
|
||||||
- bottles
|
- bottles
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user