feat(web): add fan date range modes and delta column
This commit is contained in:
1 parent
998d0fd0c0
commit
274eccba93
6 files changed
+253
-22
No files matched your search
@@ -197,6 +197,52 @@ def test_up_queries():
|
||||
db.close()
|
||||
|
||||
|
||||
def test_fans_custom_range_modes():
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
db, q = setup(tmp)
|
||||
try:
|
||||
daily = q.fans(start="2026-10-29", end="2026-10-31")
|
||||
assert daily["mode"] == "daily"
|
||||
assert daily["range_start"] == "2026-10-29"
|
||||
assert daily["range_end"] == "2026-10-31"
|
||||
assert daily["dates"] == list(DATES)
|
||||
assert daily["series"] == [1000, 1010, 1020]
|
||||
|
||||
# 超过一年触发按月峰值模式
|
||||
db.write(lambda conn: conn.execute(
|
||||
"INSERT OR REPLACE INTO up_stat"
|
||||
"(stat_date, mid, follower, following, captured_at, ok) "
|
||||
"VALUES ('2025-01-01', 37754047, 500, NULL, 1, 1)"
|
||||
))
|
||||
monthly = q.fans(start="2025-01-01", end="2026-10-31")
|
||||
assert monthly["mode"] == "monthly"
|
||||
assert monthly["span_days"] == 669
|
||||
assert monthly["dates"][0] == "2025-01-01"
|
||||
assert monthly["series"][0] == 500
|
||||
assert monthly["dates"][-1] == "2026-10-31"
|
||||
assert monthly["series"][-1] == 1020
|
||||
|
||||
# 同月多条时取峰值日期,并优先较晚日期
|
||||
db.write(lambda conn: conn.execute(
|
||||
"INSERT OR REPLACE INTO up_stat"
|
||||
"(stat_date, mid, follower, following, captured_at, ok) "
|
||||
"VALUES ('2026-10-15', 37754047, 5000, NULL, 1, 1), "
|
||||
"('2026-10-16', 37754047, 5000, NULL, 1, 1)"
|
||||
))
|
||||
monthly = q.fans(start="2025-01-01", end="2026-10-31")
|
||||
assert monthly["dates"][-1] == "2026-10-16"
|
||||
assert monthly["series"][-1] == 5000
|
||||
|
||||
try:
|
||||
q.fans(start="2026-11-01", end="2026-10-01")
|
||||
except ValueError:
|
||||
pass
|
||||
else:
|
||||
raise AssertionError("start 晚于 end 应报错")
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
def test_fans_candidates_system_and_export():
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
db, q = setup(tmp)
|
||||
@@ -223,6 +269,10 @@ def test_fans_candidates_system_and_export():
|
||||
recent = q.fans(days=90)
|
||||
assert recent["recent_days"] == 14
|
||||
assert [point["stat_date"] for point in recent["recent_points"]] == list(DATES)
|
||||
deltas = {point["stat_date"]: point["delta"] for point in recent["recent_points"]}
|
||||
assert deltas["2026-10-29"] == 100 # 对比 2026-10-01 的 900
|
||||
assert deltas["2026-10-30"] == 10
|
||||
assert deltas["2026-10-31"] == 10
|
||||
one_day = q.fans(days=90, recent_days=1)
|
||||
assert [point["stat_date"] for point in one_day["recent_points"]] == [DATES[-1]]
|
||||
|
||||
@@ -262,6 +312,7 @@ def main_test():
|
||||
test_growth_and_cold_start()
|
||||
test_video_detail_and_trend()
|
||||
test_up_queries()
|
||||
test_fans_custom_range_modes()
|
||||
test_fans_candidates_system_and_export()
|
||||
print("OK: Web 查询层总览/榜单/详情/UP/粉丝/候选/系统测试全部通过")
|
||||
|
||||
|
||||
Reference in new issue
Block a user