feat(matrix): 悬停里的每条视频显示自己的赞/评/藏/转
一格合并了多条时,并集只能说明「这天整体怎么样」,哪条是爆款要看每条自己的 数字。后端在 details 里带上各自的最近一轮指标,提示里缩进显示在该条标题下面。
This commit is contained in:
+12
-3
@@ -1549,8 +1549,11 @@ async def daily_tag_matrix(
|
|||||||
"cells": {"2026-10-21": {"<hash>": {
|
"cells": {"2026-10-21": {"<hash>": {
|
||||||
"count": 2, "tags": ["大字报", "养号"],
|
"count": 2, "tags": ["大字报", "养号"],
|
||||||
"likes": 120, "comments": 8, "collected": 30, "shares": 4,
|
"likes": 120, "comments": 8, "collected": 30, "shares": 4,
|
||||||
"details": [{"title": "…", "tags": ["大字报"]},
|
"details": [{"title": "…", "tags": ["大字报"],
|
||||||
{"title": "…", "tags": ["养号"]}], # 按发布时间正序
|
"likes": 80, "comments": 5, "collected": 20, "shares": 4},
|
||||||
|
{"title": "…", "tags": ["养号"],
|
||||||
|
"likes": 40, "comments": 3, "collected": 10, "shares": 0}],
|
||||||
|
# 按发布时间正序
|
||||||
}}}}
|
}}}}
|
||||||
|
|
||||||
``likes/comments/collected/shares`` 是当天这些作品**最近一轮**指标的和;
|
``likes/comments/collected/shares`` 是当天这些作品**最近一轮**指标的和;
|
||||||
@@ -1727,17 +1730,23 @@ async def daily_tag_matrix(
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
bucket["count"] += 1
|
bucket["count"] += 1
|
||||||
|
metric = latest_metric.get((row.task_id, row.note_id))
|
||||||
|
# 逐条明细带**各自的**指标。一格合并了多条时,并集只说明「这天整体怎么样」,
|
||||||
|
# 哪条是爆款要看每条自己的数字 —— 悬停提示里直接看得到。
|
||||||
bucket["details"].append(
|
bucket["details"].append(
|
||||||
{
|
{
|
||||||
"title": row.title or row.note_id,
|
"title": row.title or row.note_id,
|
||||||
"tags": list(tags_by_note.get(row.note_id, [])),
|
"tags": list(tags_by_note.get(row.note_id, [])),
|
||||||
|
"likes": metric.liked_count if metric is not None else None,
|
||||||
|
"comments": metric.comment_count if metric is not None else None,
|
||||||
|
"collected": metric.collected_count if metric is not None else None,
|
||||||
|
"shares": metric.share_count if metric is not None else None,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
for tag in tags_by_note.get(row.note_id, []):
|
for tag in tags_by_note.get(row.note_id, []):
|
||||||
if tag not in bucket["tags"]:
|
if tag not in bucket["tags"]:
|
||||||
bucket["tags"].append(tag)
|
bucket["tags"].append(tag)
|
||||||
|
|
||||||
metric = latest_metric.get((row.task_id, row.note_id))
|
|
||||||
if metric is not None:
|
if metric is not None:
|
||||||
for column, key in (
|
for column, key in (
|
||||||
("liked_count", "likes"),
|
("liked_count", "likes"),
|
||||||
|
|||||||
+26
-4
@@ -236,9 +236,16 @@
|
|||||||
border-top: 1px solid var(--line);
|
border-top: 1px solid var(--line);
|
||||||
white-space: normal;
|
white-space: normal;
|
||||||
}
|
}
|
||||||
#tip .tip-notes div { line-height: 1.55; }
|
#tip .tip-note { margin-bottom: 4px; line-height: 1.55; }
|
||||||
#tip .tip-note-title { color: var(--text); }
|
#tip .tip-note-title { color: var(--text); }
|
||||||
#tip .tip-note-tags { color: var(--pink); margin-left: 6px; }
|
/* 每条作品自己的指标。缩进到标题文字下面,一眼对得上是哪条。 */
|
||||||
|
#tip .tip-note-meta {
|
||||||
|
padding-left: 14px;
|
||||||
|
color: var(--muted);
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
}
|
||||||
|
#tip .tip-note-metrics { margin-right: 8px; }
|
||||||
|
#tip .tip-note-tags { color: var(--pink); }
|
||||||
#tip .tip-note-more { color: var(--muted); }
|
#tip .tip-note-more { color: var(--muted); }
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
@@ -415,15 +422,30 @@
|
|||||||
for (let index = 0; index < Math.min(details.length, limit); index += 1) {
|
for (let index = 0; index < Math.min(details.length, limit); index += 1) {
|
||||||
const item = details[index];
|
const item = details[index];
|
||||||
const row = document.createElement('div');
|
const row = document.createElement('div');
|
||||||
const title = document.createElement('span');
|
row.className = 'tip-note';
|
||||||
|
|
||||||
|
const title = document.createElement('div');
|
||||||
title.className = 'tip-note-title';
|
title.className = 'tip-note-title';
|
||||||
title.textContent = index + 1 + '. ' + item.title;
|
title.textContent = index + 1 + '. ' + item.title;
|
||||||
row.appendChild(title);
|
row.appendChild(title);
|
||||||
|
|
||||||
|
const meta = document.createElement('div');
|
||||||
|
meta.className = 'tip-note-meta';
|
||||||
|
const metrics = document.createElement('span');
|
||||||
|
metrics.className = 'tip-note-metrics';
|
||||||
|
metrics.textContent =
|
||||||
|
'赞 ' + compact(item.likes) +
|
||||||
|
' · 评 ' + compact(item.comments) +
|
||||||
|
' · 藏 ' + compact(item.collected) +
|
||||||
|
' · 转 ' + compact(item.shares);
|
||||||
|
meta.appendChild(metrics);
|
||||||
const noteTags = document.createElement('span');
|
const noteTags = document.createElement('span');
|
||||||
noteTags.className = 'tip-note-tags';
|
noteTags.className = 'tip-note-tags';
|
||||||
noteTags.textContent =
|
noteTags.textContent =
|
||||||
item.tags && item.tags.length ? item.tags.join(' / ') : '无标签';
|
item.tags && item.tags.length ? item.tags.join(' / ') : '无标签';
|
||||||
row.appendChild(noteTags);
|
meta.appendChild(noteTags);
|
||||||
|
row.appendChild(meta);
|
||||||
|
|
||||||
list.appendChild(row);
|
list.appendChild(row);
|
||||||
}
|
}
|
||||||
if (details.length > limit) {
|
if (details.length > limit) {
|
||||||
|
|||||||
@@ -76,14 +76,19 @@ async def _task(platform: str = "dy", name: str = "矩阵测试") -> int:
|
|||||||
|
|
||||||
|
|
||||||
async def _note(
|
async def _note(
|
||||||
task_id: int, note_id: str, name: str, published_at: int, creator_hash: str = "hash-a"
|
task_id: int,
|
||||||
|
note_id: str,
|
||||||
|
name: str,
|
||||||
|
published_at: int,
|
||||||
|
creator_hash: str = "hash-a",
|
||||||
|
title: str = "t",
|
||||||
) -> None:
|
) -> None:
|
||||||
async with monitor_db.get_session() as session:
|
async with monitor_db.get_session() as session:
|
||||||
session.add(
|
session.add(
|
||||||
MonitorNote(
|
MonitorNote(
|
||||||
task_id=task_id,
|
task_id=task_id,
|
||||||
note_id=note_id,
|
note_id=note_id,
|
||||||
title="t",
|
title=title,
|
||||||
note_url="",
|
note_url="",
|
||||||
cover="",
|
cover="",
|
||||||
creator_hash=creator_hash,
|
creator_hash=creator_hash,
|
||||||
@@ -360,8 +365,8 @@ async def test_empty_stat_falls_back_to_the_note_name(db):
|
|||||||
async def test_cell_sums_the_latest_metric_of_each_note(db):
|
async def test_cell_sums_the_latest_metric_of_each_note(db):
|
||||||
task_id = await _task()
|
task_id = await _task()
|
||||||
now = get_current_timestamp() - 1000
|
now = get_current_timestamp() - 1000
|
||||||
await _note(task_id, "n1", "博主A", now)
|
await _note(task_id, "n1", "博主A", now, title="作品一")
|
||||||
await _note(task_id, "n2", "博主A", now)
|
await _note(task_id, "n2", "博主A", now, title="作品二")
|
||||||
|
|
||||||
# 同一篇有两轮快照,只取 run_id 最大的那一轮
|
# 同一篇有两轮快照,只取 run_id 最大的那一轮
|
||||||
await _metric(task_id, "n1", run_id=1, liked=10, comment=1, collected=2, share=3)
|
await _metric(task_id, "n1", run_id=1, liked=10, comment=1, collected=2, share=3)
|
||||||
@@ -378,6 +383,16 @@ async def test_cell_sums_the_latest_metric_of_each_note(db):
|
|||||||
assert cell["collected"] == 5
|
assert cell["collected"] == 5
|
||||||
assert cell["shares"] == 5
|
assert cell["shares"] == 5
|
||||||
|
|
||||||
|
# 逐条明细带**各自的**指标,不是格子的合计 —— 悬停时看的就是这个。
|
||||||
|
by_title = {item["title"]: item for item in cell["details"]}
|
||||||
|
assert by_title["作品一"]["likes"] == 20 # 取最近一轮
|
||||||
|
assert by_title["作品一"]["comments"] == 2
|
||||||
|
assert by_title["作品一"]["collected"] == 4
|
||||||
|
assert by_title["作品一"]["shares"] == 5
|
||||||
|
assert by_title["作品二"]["likes"] == 5
|
||||||
|
assert by_title["作品二"]["comments"] is None # 未知不是 0
|
||||||
|
assert by_title["作品二"]["shares"] == 0
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_missing_metrics_are_none_not_zero(db):
|
async def test_missing_metrics_are_none_not_zero(db):
|
||||||
|
|||||||
Reference in New Issue
Block a user