feat(效能分析): 轨迹流转图时间轴支持工作日/自然天切换

- flow 接口加 mode 参数,workdays 模式把时间偏移换算为排除周末/节假日的工作小时
- 轨迹流转图的横轴随顶部按钮(自然天/工作日)切换,休息日被压缩
- 按钮切换自动重新请求 flow
This commit is contained in:
2026-08-28 15:34:17 +08:00
parent 7f1858387c
commit 4447a1f52d
4 changed files with 19 additions and 4 deletions

View File

@ -280,6 +280,7 @@ async def get_flow_compare(
db: AsyncSession,
product_sns: list[str] | None = None,
spec_models: list[str] | None = None,
mode: str = "natural",
) -> FlowResponse:
"""
查询每台设备上各操作人的任务时间区间,拼装为「生命周期时间轴」区间图:
@ -426,10 +427,20 @@ async def get_flow_compare(
# ── 按人分组,转为相对 T0 的小时偏移区间 ──
by_assignee: dict[str, list[list]] = {}
# 工作日模式:把时间偏移换算为「排除周末/节假日的工作小时」,压缩休息日
if mode == "workdays":
from app.core.time_utils import working_duration_hours as _wdh
from app.models.holiday import Holiday as _Holiday
hres = await db.execute(select(_Holiday.day))
_holidays = {r[0] for r in hres}
for it in intervals:
t0 = t0_by_device[it["idx"]]
start_offset = round((it["start"] - t0).total_seconds() / 3600, 1)
end_offset = round((it["end"] - t0).total_seconds() / 3600, 1)
if mode == "workdays":
start_offset = _wdh(t0, it["start"], _holidays)
end_offset = _wdh(t0, it["end"], _holidays)
else:
start_offset = round((it["start"] - t0).total_seconds() / 3600, 1)
end_offset = round((it["end"] - t0).total_seconds() / 3600, 1)
duration = round(end_offset - start_offset, 1)
by_assignee.setdefault(it["assignee_id"], []).append(
[it["idx"], start_offset, end_offset, it["task_name"], duration, it["is_main"]]