fix(tools): backfill fan counts in chronological order
This commit is contained in:
1 parent
94ee9aefd1
commit
e7cae035e0
2 files changed
+14
-3
No files matched your search
@@ -203,6 +203,13 @@ def test_seed_preview_end_to_end():
|
||||
assert conn.execute(
|
||||
"SELECT 1 FROM up_blacklist WHERE mid=?", (FAKE_BLACKLIST_MID,)
|
||||
).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:
|
||||
conn.close()
|
||||
|
||||
|
||||
@@ -327,10 +327,14 @@ def _seed_up_stats(
|
||||
follower = int(data.get("follower") or 0)
|
||||
following = data.get("following")
|
||||
current = follower
|
||||
for offset in range(days, 0, -1):
|
||||
stat_date = (latest_day - timedelta(days=offset)).isoformat()
|
||||
# values[0] 对应 latest-1,values[-1] 对应 latest-days。
|
||||
values: list[int] = []
|
||||
for _ in range(days):
|
||||
decrement = max(1, int(round(current * rng.uniform(0.00015, 0.0006))))
|
||||
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(
|
||||
"""
|
||||
INSERT OR REPLACE INTO up_stat(
|
||||
@@ -340,7 +344,7 @@ def _seed_up_stats(
|
||||
(
|
||||
stat_date,
|
||||
int(mid),
|
||||
current,
|
||||
values[offset - 1],
|
||||
following,
|
||||
int(_day_start(latest_day - timedelta(days=offset)) + 60),
|
||||
),
|
||||
|
||||
Reference in new issue
Block a user