droboticflow/scripts/local/wire-local-capture.sh

97 lines
5.4 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# 把本地下载的 Capture 接进快照库的标注任务(本地 27018 容器操作,与线上无关)。
#
# 用法: scripts/local/wire-local-capture.sh [Capture目录名] [runId]
# Capture 目录名: ~/Desktop/fanyu/droboticflow/local-data/captures/ 下的目录(默认 FYLX_B01_AZER764007R_19700101_001838)
# runId: 要接线的 run(默认挑第一条 claimed 的 annotation-qa 任务对应的 run)
#
# 做三件事:
# 1. 把该 run 的 nodeExecutions 中所有双目视频/PTS/IMU artifact 的 path 改为本地文件路径
# ——注意:artifacts 输出数组和 inputBindings 端口绑定两处都要改
# (frame-timeline 接口从 inputBindings 的 leftTimestamps/fullLeftVideos 端口解析 PTS,
# 视频播放从 artifacts/subject 解析,缺一处对应功能就报错)
# 2. 工作台视频接口要求 API 以 WORKSPACE_MOUNT_PATH 指向本地 workspace 目录启动:
# 文件先拷到 ~/Desktop/fanyu/droboticflow/local-data/workspace/,API 启动时设
# WORKSPACE_MOUNT_PATH=~/Desktop/fanyu/droboticflow/local-data/workspace
# (safeMaterializationSourcePath 只接受挂载根下的路径,这是平台安全设计)
# 3. 把 claimed 任务 assignedUserId 改为标注员、补 rightArtifactId
#
# 前提: download-capture.sh 已下载;API 已用 WORKSPACE_MOUNT_PATH 启动(见 env-local-snapshot.sh 尾注)
set -euo pipefail
CAPTURE="${1:-FYLX_B01_AZER764007R_19700101_001838}"
RUNID="${2:-}"
WS="$HOME/Desktop/fanyu/droboticflow/local-data/workspace"
LOCAL_DIR="$HOME/Desktop/fanyu/droboticflow/local-data/captures/$CAPTURE"
MONGO="docker exec fanyu-mongo-restore mongosh --quiet 127.0.0.1:27017/drobodata-fanyu"
LEFT=$(ls "$LOCAL_DIR"/part*/${CAPTURE}_camera_left_part*.mp4 2>/dev/null | head -1 || true)
RIGHT=$(ls "$LOCAL_DIR"/part*/${CAPTURE}_camera_right_part*.mp4 2>/dev/null | head -1 || true)
[ -n "$LEFT" ] && [ -n "$RIGHT" ] || { echo "错误: $LOCAL_DIR 下找不到左右目视频(先跑 download-capture.sh)"; exit 1; }
# 1. 拷进 workspace(materialization 安全约束:必须在挂载根下)
mkdir -p "$WS"
[ -d "$WS/$CAPTURE" ] || cp -R "$LOCAL_DIR" "$WS/"
WS_LEFT=$(ls "$WS/$CAPTURE"/part*/${CAPTURE}_camera_left_part*.mp4 | head -1)
WS_RIGHT=$(ls "$WS/$CAPTURE"/part*/${CAPTURE}_camera_right_part*.mp4 | head -1)
WS_LEFT_PTS=$(ls "$WS/$CAPTURE"/part*/${CAPTURE}_camera_left_part*pts.csv | head -1)
WS_RIGHT_PTS=$(ls "$WS/$CAPTURE"/part*/${CAPTURE}_camera_right_part*pts.csv | head -1)
WS_IMU=$(ls "$WS/$CAPTURE"/part*/${CAPTURE}_imu_part*.csv | head -1)
# 2. 选目标 run
if [ -z "$RUNID" ]; then
ITEM_JSON=$($MONGO --eval '
const it = db.humanItems.findOne({status: "claimed", pluginId: "annotation-qa"});
print(JSON.stringify({id: it.id, runId: it.runId, assigned: it.assignedUserId}));')
else
ITEM_JSON=$($MONGO --eval "
const it = db.humanItems.findOne({runId: '$RUNID', status: 'claimed'}) || db.humanItems.findOne({runId: '$RUNID'});
print(JSON.stringify({id: it.id, runId: it.runId, assigned: it.assignedUserId}));")
fi
ITEM=$(echo "$ITEM_JSON" | python3 -c "import json,sys; print(json.load(sys.stdin)['id'])")
RUNID=$(echo "$ITEM_JSON" | python3 -c "import json,sys; print(json.load(sys.stdin)['runId'])")
ANNOTATOR=$($MONGO --eval '
const u = db.users.findOne({email: "fanyu-full-annotator@droboticflow.local"});
print(u ? u.id : "");')
echo "接线: $CAPTURE → run=$RUNID task=$ITEM → 标注员=$ANNOTATOR"
# 3. 双路改写(artifacts 数组 + inputBindings 端口)+ 任务归属 + rightArtifactId
$MONGO --eval "
const runId = '$RUNID';
const left = '$WS_LEFT', right = '$WS_RIGHT', leftPts = '$WS_LEFT_PTS', rightPts = '$WS_RIGHT_PTS', imu = '$WS_IMU';
const run = db.runs.findOne({id: runId});
let video=0, pts=0, imuN=0;
const fix = (a) => {
const name = a.name || '';
if (name.endsWith('.mp4') && name.includes('camera_left_part0001')) { a.path = left; return 'video'; }
if (name.endsWith('.mp4') && name.includes('camera_right_part0001')) { a.path = right; return 'video'; }
if (name.endsWith('_pts.csv') && name.includes('camera_left')) { a.path = leftPts; return 'pts'; }
if (name.endsWith('_pts.csv') && name.includes('camera_right')) { a.path = rightPts; return 'pts'; }
if (name.toLowerCase().includes('imu') && name.endsWith('.csv')) { a.path = imu; return 'imu'; }
return null;
};
let rightArt = null;
for (const ne of (run.nodeExecutions||[])) {
for (const a of (ne.artifacts||[])) { const k=fix(a); if(k==='video'){video++; if(!rightArt && (a.name||'').includes('camera_right')) rightArt=a.id;} if(k==='pts')pts++; if(k==='imu')imuN++; }
for (const ib of (ne.inputBindings||[])) {
for (const a of (ib.artifacts||[])) {
const k=fix(a);
if(k==='video'){video++; if(!rightArt && (a.name||'').includes('camera_right')) rightArt=a.id;}
if(k==='pts')pts++; if(k==='imu')imuN++;
}
}
}
db.runs.updateOne({id: runId}, {\$set: {nodeExecutions: run.nodeExecutions}});
db.humanItems.updateOne({id: '$ITEM'}, {\$set: {
assignedUserId: '$ANNOTATOR',
latestAuthorUserId: '$ANNOTATOR',
'subject.payload.rightArtifactId': rightArt || ''
}});
print('改写统计: video=' + video + ' pts=' + pts + ' imu=' + imuN + ' | rightArtifactId: ' + (rightArt||'无'));
"
echo
echo "完成。API 启动务必带: WORKSPACE_MOUNT_PATH=$WS"
echo "浏览器用 fanyu-full-annotator@droboticflow.local 登录 http://127.0.0.1:5173,"
echo "进入任务 $ITEM 的标注工作台:双目视频可播、统一帧范围可加载。"