fix(tools): backfill fan counts in chronological order

This commit is contained in:
kairee committed 2026-10-31 23:10:54 +08:00
1 parent 94ee9aefd1
commit e7cae035e0
2 files changed
+14 -3

No files matched your search

+7
View File
@@ -203,6 +203,13 @@ def test_seed_preview_end_to_end():
assert conn.execute( assert conn.execute(
"SELECT 1 FROM up_blacklist WHERE mid=?", (FAKE_BLACKLIST_MID,) "SELECT 1 FROM up_blacklist WHERE mid=?", (FAKE_BLACKLIST_MID,)
).fetchone() is not None ).fetchone() is not None
up_rows = conn.execute(
"SELECT stat_date, follower FROM up_stat WHERE mid=37754047 "
"ORDER BY stat_date"
).fetchall()
followers = [int(row["follower"]) for row in up_rows]
assert followers == sorted(followers), followers
assert len(followers) == 8
finally: finally:
conn.close() conn.close()
+7 -3
View File
@@ -327,10 +327,14 @@ def _seed_up_stats(
follower = int(data.get("follower") or 0) follower = int(data.get("follower") or 0)
following = data.get("following") following = data.get("following")
current = follower current = follower
for offset in range(days, 0, -1): # values[0] 对应 latest-1,values[-1] 对应 latest-days。
stat_date = (latest_day - timedelta(days=offset)).isoformat() values: list[int] = []
for _ in range(days):
decrement = max(1, int(round(current * rng.uniform(0.00015, 0.0006)))) decrement = max(1, int(round(current * rng.uniform(0.00015, 0.0006))))
current = max(0, current - decrement) current = max(0, current - decrement)
values.append(current)
for offset in range(days, 0, -1):
stat_date = (latest_day - timedelta(days=offset)).isoformat()
conn.execute( conn.execute(
""" """
INSERT OR REPLACE INTO up_stat( INSERT OR REPLACE INTO up_stat(
@@ -340,7 +344,7 @@ def _seed_up_stats(
( (
stat_date, stat_date,
int(mid), int(mid),
current, values[offset - 1],
following, following,
int(_day_start(latest_day - timedelta(days=offset)) + 60), int(_day_start(latest_day - timedelta(days=offset)) + 60),
), ),