feat(report): 日期列补满区间、博主补上「只有资料没有作品」的号、加条件格式
三个问题一起修: 1. **日期列按完整区间生成**。原先只取「有作品的那几天」,某天断更那一列就消失了 —— 看图的人会以为漏采,而空白本身也是信息。现在固定输出最近 N 个自然日(含今天)。 2. **博主名单改成「账号快照 ∪ 作品」**,和界面一致。线上有 3 个号(昵称是纯数字 uid、作品数 0)只存在于快照表里,一条作品都没有;名单只从作品里取的话它们整行 消失。现在它们会占一行,格子里是空的。 3. **条件格式**:头部加「高亮 [指标] ≥ [数值]」。命中的格子换底色 + 粉色描边, 只在本地重画,不重新请求数据;条件写进地址栏(`cf=likes:1000`)可直接收藏。 细节: * 计数/指标的去重口径不变(同一作品挂两个任务只算一次); * 指标未知仍是 None,参与不了条件格式 —— 不会被当成 0 高亮。 测试 11 条(新增:只有资料没有作品的号仍占一行、日期列是完整区间)。
This commit is contained in:
@@ -21,6 +21,7 @@ from api.monitor import db as monitor_db
|
||||
from api.monitor import service
|
||||
from api.monitor.models import (
|
||||
MODE_CREATOR,
|
||||
MonitorCreatorStat,
|
||||
MonitorNote,
|
||||
MonitorNoteMetric,
|
||||
MonitorNoteTag,
|
||||
@@ -150,7 +151,9 @@ async def test_same_day_notes_collapse_with_tags_union(db):
|
||||
async with monitor_db.get_session() as session:
|
||||
data = await service.daily_tag_matrix(session, "dy", days=7)
|
||||
|
||||
assert data["dates"] == [_day(today)]
|
||||
# 日期列是**完整区间**(7 天),不是只有有作品的那天
|
||||
assert len(data["dates"]) == 7
|
||||
assert data["dates"][0] == _day(today)
|
||||
assert [c["name"] for c in data["creators"]] == ["博主A"]
|
||||
|
||||
cell = data["cells"][_day(today)]["hash-a"]
|
||||
@@ -183,8 +186,11 @@ async def test_notes_outside_the_window_are_excluded(db):
|
||||
async with monitor_db.get_session() as session:
|
||||
data = await service.daily_tag_matrix(session, "dy", days=7)
|
||||
|
||||
assert data["dates"] == [_day(now - 1000)]
|
||||
assert data["cells"][_day(now - 1000)]["hash-a"]["count"] == 1
|
||||
assert len(data["dates"]) == 7
|
||||
assert data["dates"][0] == _day(now)
|
||||
assert data["cells"][_day(now)]["hash-a"]["count"] == 1
|
||||
# 40 天前那天不该出现在 cells 里
|
||||
assert _day(now - 40 * DAY_MS) not in data["cells"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -217,6 +223,39 @@ async def test_no_tasks_returns_an_empty_shape(db):
|
||||
}
|
||||
|
||||
|
||||
async def _stat(task_id: int, creator_hash: str, nickname: str) -> None:
|
||||
async with monitor_db.get_session() as session:
|
||||
session.add(
|
||||
MonitorCreatorStat(
|
||||
task_id=task_id,
|
||||
run_id=1,
|
||||
creator_hash=creator_hash,
|
||||
nickname=nickname,
|
||||
creator_id="",
|
||||
works_count=0,
|
||||
captured_at=get_current_timestamp(),
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_creators_without_notes_still_get_a_row(db):
|
||||
"""只在账号快照里出现的号不能消失。
|
||||
|
||||
典型是资料读成纯数字昵称、作品数为 0 的那几个 —— 它们一条作品都没有,如果博主
|
||||
名单只从作品里取,整行就不见了。日期列也一样:一行数据都没有时,7 个日期还在。
|
||||
"""
|
||||
task_id = await _task()
|
||||
await _stat(task_id, "hash-num", "26828346705")
|
||||
|
||||
async with monitor_db.get_session() as session:
|
||||
data = await service.daily_tag_matrix(session, "dy", days=7)
|
||||
|
||||
assert [c["name"] for c in data["creators"]] == ["26828346705"]
|
||||
assert data["cells"] == {}
|
||||
assert len(data["dates"]) == 7
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_cell_sums_the_latest_metric_of_each_note(db):
|
||||
task_id = await _task()
|
||||
@@ -292,7 +331,7 @@ async def test_endpoint_returns_the_long_shape(client):
|
||||
|
||||
assert response.status_code == 200
|
||||
body = response.json()
|
||||
assert body["dates"] == [_day(now)]
|
||||
assert _day(now) in body["dates"]
|
||||
assert body["creators"][0]["name"] == "博主A"
|
||||
cell = body["cells"][_day(now)]["hash-a"]
|
||||
assert cell["count"] == 1
|
||||
|
||||
Reference in New Issue
Block a user