Filter YouTube sessions/events/stats from Douyin monitor panels
This commit is contained in:
parent
dcc4f5fca9
commit
91d8e6f65c
@ -1270,14 +1270,23 @@ def dedupe_active_sessions() -> int:
|
|||||||
conn.close()
|
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:
|
if dedupe:
|
||||||
dedupe_active_sessions()
|
dedupe_active_sessions()
|
||||||
with _lock:
|
with _lock:
|
||||||
conn = _connect()
|
conn = _connect()
|
||||||
try:
|
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(
|
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()
|
).fetchall()
|
||||||
return [_row_to_dict(r) for r in rows] # type: ignore
|
return [_row_to_dict(r) for r in rows] # type: ignore
|
||||||
finally:
|
finally:
|
||||||
|
|||||||
@ -1374,8 +1374,8 @@ async def events_export(
|
|||||||
|
|
||||||
|
|
||||||
@app.get("/api/sessions/active")
|
@app.get("/api/sessions/active")
|
||||||
async def sessions_active() -> dict[str, Any]:
|
async def sessions_active(platform: str = "") -> dict[str, Any]:
|
||||||
items = await _db(db.list_active_sessions, dedupe=not _DESKTOP_LIGHT)
|
items = await _db(db.list_active_sessions, dedupe=not _DESKTOP_LIGHT, platform=platform)
|
||||||
return {"sessions": items, "total": len(items)}
|
return {"sessions": items, "total": len(items)}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -122,14 +122,14 @@ export default function HomePage() {
|
|||||||
try {
|
try {
|
||||||
const iso = todayBeijingISO();
|
const iso = todayBeijingISO();
|
||||||
const [s, ytS, m, yt, r, e, a, daySessions, up] = await Promise.all([
|
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/sessions/stats?platform=youtube&top_anchors=10").catch(() => null),
|
||||||
fetchJson("/api/monitor/status"),
|
fetchJson("/api/monitor/status"),
|
||||||
fetchJson("/api/youtube-monitor/status").catch(() => null),
|
fetchJson("/api/youtube-monitor/status").catch(() => null),
|
||||||
fetchJson("/api/rooms?limit=500"),
|
fetchJson("/api/rooms?limit=500"),
|
||||||
fetchJson("/api/events?limit=20"),
|
fetchJson("/api/events?limit=20&platform=douyin"),
|
||||||
fetchJson("/api/sessions/active"),
|
fetchJson("/api/sessions/active?platform=douyin"),
|
||||||
fetchJson(`/api/sessions?date_from=${iso}&date_to=${iso}&limit=500`),
|
fetchJson(`/api/sessions?platform=douyin&date_from=${iso}&date_to=${iso}&limit=500`),
|
||||||
fetchJson("/api/anchors/upcoming?limit=12"),
|
fetchJson("/api/anchors/upcoming?limit=12"),
|
||||||
]);
|
]);
|
||||||
setStats(s);
|
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 liveRooms = rooms.filter((r) => r.last_status === "live" && (!focusOnly || priorityRoomIds.has(r.room_id)));
|
||||||
const focusLive = active.filter((s) => {
|
const focusLive = active.filter((s) => {
|
||||||
const isYt = detectPlatform(s) === "youtube";
|
// 主页是抖音监控面板,始终不显示 YouTube 场次
|
||||||
if (focusOnly && isYt) return false;
|
if (detectPlatform(s) === "youtube") return false;
|
||||||
return !focusOnly || (s.room_id && priorityRoomIds.has(s.room_id));
|
return !focusOnly || (s.room_id && priorityRoomIds.has(s.room_id));
|
||||||
});
|
});
|
||||||
const riskActive = !!(status?.risk_paused_until && status.risk_paused_until * 1000 > Date.now());
|
const riskActive = !!(status?.risk_paused_until && status.risk_paused_until * 1000 > Date.now());
|
||||||
@ -479,7 +479,7 @@ export default function HomePage() {
|
|||||||
hint="YouTube 历史场次合计"
|
hint="YouTube 历史场次合计"
|
||||||
accent="teal"
|
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" />
|
<StatTile emoji="🎯" label="检查次数" value={<AnimatedNumber value={status?.checked_total || 0} />} hint={`上次 ${fmtTs(status?.last_check_at)}`} accent="amber" />
|
||||||
</div>
|
</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">
|
<div className="mb-6 grid gap-4 lg:grid-cols-[1.4fr_1fr] lg:items-stretch">
|
||||||
<section className="glass-panel rounded-2xl p-4">
|
<section className="glass-panel rounded-2xl p-4">
|
||||||
<div className="mb-3 flex flex-wrap items-center justify-between gap-2">
|
<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">
|
<div className="flex flex-wrap gap-3 text-xs">
|
||||||
<Link href="/sessions" className="inline-flex items-center gap-1 text-teal-300 hover:underline">
|
<Link href="/sessions" className="inline-flex items-center gap-1 text-teal-300 hover:underline">
|
||||||
场次明细 <ArrowRight className="h-3 w-3" />
|
场次明细 <ArrowRight className="h-3 w-3" />
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user