fix(analytics): anomaly回退同人多账号累加+今日无环比断言修正

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
浅念
2026-09-04 17:17:24 +08:00
parent 49f2ffe8ea
commit 02e100849b
2 changed files with 34 additions and 3 deletions
+4 -2
View File
@@ -186,10 +186,12 @@ async def anomaly(session: AsyncSession, channel: str) -> dict | None:
).all()
rows = [(d, amap.get(o, o), v) for d, o, v in raw]
# 逐 user 显式算(yesterday 量 + prev7 均值),不猜 rows 顺序
# 逐 user 显式算(yesterday 量 + prev7 均值),不猜 rows 顺序。
# 累加而非覆盖:回退路径同人(多账号映射到同一 user_id)会有多行/日。
day_rows: dict[str, dict[int, int]] = {}
for day, uid, v in rows:
day_rows.setdefault(uid, {})[day] = int(v)
by_day = day_rows.setdefault(uid, {})
by_day[day] = by_day.get(day, 0) + int(v)
staff_out = []
totals_y, totals_p = 0, 0.0