Filter YouTube sessions/events/stats from Douyin monitor panels

This commit is contained in:
eric 2026-08-11 03:31:23 -05:00
parent dcc4f5fca9
commit 91d8e6f65c
3 changed files with 21 additions and 12 deletions

View File

@ -1270,14 +1270,23 @@ def dedupe_active_sessions() -> int:
conn.close()
def list_active_sessions(*, dedupe: bool = True) -> list[dict[str, Any]]:
def list_active_sessions(*, dedupe: bool = True, platform: str = "") -> list[dict[str, Any]]:
if dedupe:
dedupe_active_sessions()
with _lock:
conn = _connect()
try:
plat_sql, plat_params = _platform_clause(
platform, room_col="room_id", meta_col="metadata_json"
)
where = "WHERE status = 'active' AND ended_at IS NULL"
params: list[Any] = []
if plat_sql:
where += f" AND {plat_sql}"
params.extend(plat_params)
rows = conn.execute(
"SELECT * FROM sessions WHERE status = 'active' AND ended_at IS NULL ORDER BY started_at DESC"
f"SELECT * FROM sessions {where} ORDER BY started_at DESC",
params,
).fetchall()
return [_row_to_dict(r) for r in rows] # type: ignore
finally:

View File

@ -1374,8 +1374,8 @@ async def events_export(
@app.get("/api/sessions/active")
async def sessions_active() -> dict[str, Any]:
items = await _db(db.list_active_sessions, dedupe=not _DESKTOP_LIGHT)
async def sessions_active(platform: str = "") -> dict[str, Any]:
items = await _db(db.list_active_sessions, dedupe=not _DESKTOP_LIGHT, platform=platform)
return {"sessions": items, "total": len(items)}

View File

@ -122,14 +122,14 @@ export default function HomePage() {
try {
const iso = todayBeijingISO();
const [s, ytS, m, yt, r, e, a, daySessions, up] = await Promise.all([
fetchJson("/api/sessions/stats?top_anchors=25"),
fetchJson("/api/sessions/stats?platform=douyin&top_anchors=25"),
fetchJson("/api/sessions/stats?platform=youtube&top_anchors=10").catch(() => null),
fetchJson("/api/monitor/status"),
fetchJson("/api/youtube-monitor/status").catch(() => null),
fetchJson("/api/rooms?limit=500"),
fetchJson("/api/events?limit=20"),
fetchJson("/api/sessions/active"),
fetchJson(`/api/sessions?date_from=${iso}&date_to=${iso}&limit=500`),
fetchJson("/api/events?limit=20&platform=douyin"),
fetchJson("/api/sessions/active?platform=douyin"),
fetchJson(`/api/sessions?platform=douyin&date_from=${iso}&date_to=${iso}&limit=500`),
fetchJson("/api/anchors/upcoming?limit=12"),
]);
setStats(s);
@ -196,8 +196,8 @@ export default function HomePage() {
);
const liveRooms = rooms.filter((r) => r.last_status === "live" && (!focusOnly || priorityRoomIds.has(r.room_id)));
const focusLive = active.filter((s) => {
const isYt = detectPlatform(s) === "youtube";
if (focusOnly && isYt) return false;
// 主页是抖音监控面板,始终不显示 YouTube 场次
if (detectPlatform(s) === "youtube") return false;
return !focusOnly || (s.room_id && priorityRoomIds.has(s.room_id));
});
const riskActive = !!(status?.risk_paused_until && status.risk_paused_until * 1000 > Date.now());
@ -479,7 +479,7 @@ export default function HomePage() {
hint="YouTube 历史场次合计"
accent="teal"
/>
<StatTile emoji="⏱️" label="全平台时长" value={<AnimatedNumber value={Number(stats?.overview?.total_hours || 0)} decimals={1} suffix="h" />} hint="抖音+YouTube" accent="teal" />
<StatTile emoji="⏱️" label="抖音时长" value={<AnimatedNumber value={Number(stats?.overview?.total_hours || 0)} decimals={1} suffix="h" />} hint="抖音历史累计时长" accent="teal" />
<StatTile emoji="🎯" label="检查次数" value={<AnimatedNumber value={status?.checked_total || 0} />} hint={`上次 ${fmtTs(status?.last_check_at)}`} accent="amber" />
</div>
@ -665,7 +665,7 @@ export default function HomePage() {
<div className="mb-6 grid gap-4 lg:grid-cols-[1.4fr_1fr] lg:items-stretch">
<section className="glass-panel rounded-2xl p-4">
<div className="mb-3 flex flex-wrap items-center justify-between gap-2">
<h3 className="font-display text-sm font-medium text-slate-100">📊 可视化分析(全平台)</h3>
<h3 className="font-display text-sm font-medium text-slate-100">📊 可视化分析(抖音)</h3>
<div className="flex flex-wrap gap-3 text-xs">
<Link href="/sessions" className="inline-flex items-center gap-1 text-teal-300 hover:underline">
场次明细 <ArrowRight className="h-3 w-3" />