File size: 2,644 Bytes
2cd1f13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# /// script
# dependencies = ["duckdb"]
# ///
"""Recompute the quick-hop rate from this dataset, the simplest headline number (METHODS.md, M1).

A "quick hop" is one account following two different profiles within 5 minutes. The claim is that
there are far more quick hops per follow since the attack than the same profiles had before it. This
rebuilds that from data/followers.parquet alone, so it can be checked without the site's database.

    uv run replicate.py                 # from Hugging Face
    uv run replicate.py data/followers.parquet   # from a downloaded copy

The network classification and username features need the full pipeline (the code is open; usernames
are private), so they are not reproduced here.
"""

import sys

import duckdb

SRC = sys.argv[1] if len(sys.argv) > 1 else "hf://datasets/gavrilo/botijada/data/followers.parquet"
CUTOFF = "2026-09-01 00:00:00+00"

# one follow per account+profile (earliest), then each account's consecutive follows in time order;
# a hop is a move to a different profile, quick if within 5 minutes, counted on its second follow.
sql = f"""
with f as (
  select account, target_id, min(followed_at) as t
  from read_parquet('{SRC}')
  group by 1, 2
),
seq as (
  select account, target_id, t,
         lag(target_id) over w as prev_target,
         lag(t) over w as prev_t
  from f
  window w as (partition by account order by t)
),
hops as (
  select t, (t - prev_t) as gap
  from seq
  where prev_target is not null and prev_target <> target_id
    and t - prev_t <= interval 1 hour
)
select
  case when t < timestamptz '{CUTOFF}' then 'before 1 Sep' else 'since 1 Sep' end as period,
  count(*) as hops,
  round(100.0 * count(*) filter (where gap <= interval 5 minute) / count(*), 1) as pct_within_5min
from hops group by 1 order by 1;
"""

# follows per period, to express hops per 1000 follows
follows_sql = f"""
with f as (select account, target_id, min(followed_at) as t from read_parquet('{SRC}') group by 1, 2)
select case when t < timestamptz '{CUTOFF}' then 'before 1 Sep' else 'since 1 Sep' end as period,
       count(*) as follows
from f group by 1 order by 1;
"""

con = duckdb.connect()
hops = {r[0]: (r[1], r[2]) for r in con.execute(sql).fetchall()}
follows = {r[0]: r[1] for r in con.execute(follows_sql).fetchall()}

print(f"{'period':14}{'follows':>10}{'quick hops':>12}{'per 1000 follows':>18}")
for period in ("before 1 Sep", "since 1 Sep"):
    n = follows.get(period, 0)
    h = hops.get(period)
    quick = round(h[0] * h[1] / 100) if h else 0
    per1000 = round(1000 * quick / n, 1) if n else 0
    print(f"{period:14}{n:>10}{quick:>12}{per1000:>18}")