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:
+16
-1
@@ -39,7 +39,7 @@ from dotenv import load_dotenv
|
||||
load_dotenv(PROJECT_ROOT / ".env")
|
||||
|
||||
import uvicorn
|
||||
from fastapi import Depends, FastAPI
|
||||
from fastapi import Depends, FastAPI, HTTPException
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from fastapi.responses import FileResponse
|
||||
@@ -201,6 +201,21 @@ async def serve_frontend():
|
||||
}
|
||||
|
||||
|
||||
# 独立的报表页。**刻意不放进 api/webui** —— 那个目录是 gitignore 的 Vite 产物,
|
||||
# 每次构建都会把它清掉。这里的文件是仓库里的源码,直接原样发出去。
|
||||
# 页面本身不含数据,数据走 /api/monitor/matrix(带鉴权),所以这个壳不需要再拦一道。
|
||||
REPORTS_DIR = os.path.join(os.path.dirname(__file__), "reports")
|
||||
|
||||
|
||||
@app.get("/report/matrix")
|
||||
async def serve_matrix_report():
|
||||
"""日期 × 博主 的标签矩阵。"""
|
||||
path = os.path.join(REPORTS_DIR, "matrix.html")
|
||||
if not os.path.exists(path):
|
||||
raise HTTPException(status_code=404, detail="报表页面不存在")
|
||||
return FileResponse(path)
|
||||
|
||||
|
||||
@app.get("/api/health")
|
||||
async def health_check():
|
||||
return {"status": "ok"}
|
||||
|
||||
Reference in New Issue
Block a user