feat(report): 自带「标签矩阵」报表页,侧边栏一键跳转
不再依赖外部报表工具。`/report/matrix` 是后端直接发的一份静态 HTML(不走 Vite
构建,所以不会被 `api/webui` 的产物清理覆盖),数据来自 `/api/monitor/matrix`
(同一套鉴权,靠同源 cookie)。
形状正是用户要的:行=日期(新到旧),列=博主,格子里是当天发出去的标签。
三种格子语义分开:空白=当天没发、无标签=发了没打标签、标签=实际打上的。
**为什么转置放在前端。** MySQL 5.7 没有 PIVOT,而列数随博主变化;写死昵称的
SQL 一改名就废(上一轮的教训)。所以接口只返回长表结构
`{dates, creators, cells}`,前端按 creator_hash 转置 —— 改名、加博主都不用动
任何 SQL。分组/去重放在 `service.daily_tag_matrix` 里做(Python 侧),这样测试
能跑在 SQLite 上,不用 MySQL 的日期函数。
去重特意处理了两件事:
* 同一天同一个号的多条作品合成一格,计数相加、标签取并集并按词表顺序;
* 同一个作品挂在两个任务下(唯一键是 (task_id, note_id))只算一次,否则计数翻倍。
侧边栏加「标签矩阵」入口,新标签页打开(宽表要占满整屏)。
测试:6 条,覆盖分组/排序/窗口/跨任务去重/空结果/接口形状。
This commit is contained in:
@@ -749,6 +749,20 @@ def _to_xlsx(rows: List[Dict[str, Any]], columns: List[tuple[str, str]], sheet:
|
||||
return output.getvalue()
|
||||
|
||||
|
||||
@router.get("/matrix")
|
||||
async def get_tag_matrix(
|
||||
platform: str = Query(default=PLATFORM_XHS, description="dy / xhs"),
|
||||
days: int = Query(default=14, ge=1, le=90, description="回看多少天"),
|
||||
):
|
||||
"""日期 × 博主 → 当天发出去的作品标签。
|
||||
|
||||
返回**长表结构**(dates / creators / cells),转置交给前端的报表页
|
||||
(``/report/matrix``)。理由见 ``service.daily_tag_matrix`` 的说明。
|
||||
"""
|
||||
async with get_session() as session:
|
||||
return await service.daily_tag_matrix(session, platform, days)
|
||||
|
||||
|
||||
@router.get("/report")
|
||||
async def get_report(
|
||||
task_id: Optional[List[int]] = Query(
|
||||
|
||||
Reference in New Issue
Block a user