Add .gitignore Add Screenshot 2025-05-08 at 21-15-26 Popepedia abi abi.png Add collect.py Add index.html Add tabulate.py
63 lines
No EOL
1.8 KiB
Python
63 lines
No EOL
1.8 KiB
Python
import json
|
|
from collections import defaultdict
|
|
|
|
points = defaultdict(list)
|
|
|
|
with open("pope.jsonl") as f:
|
|
for line in f:
|
|
data = json.loads(line.strip())
|
|
|
|
# 2025-05-08T18:17:09Z
|
|
ts = data["timestamp"]
|
|
key = ts[:17] + "00" + ts[19:]
|
|
points[key].append(data)
|
|
|
|
totals = []
|
|
|
|
for minute in points:
|
|
n = 0
|
|
bs = 0
|
|
for thing in points[minute]:
|
|
n += 1
|
|
bs += abs(thing["delta"])
|
|
totals.append({"time": minute, "edits": n, "bytes": bs})
|
|
|
|
running_edits = 0
|
|
running_bytes = 0
|
|
|
|
for i in range(len(totals)):
|
|
running_edits += totals[i]["edits"]
|
|
running_bytes += totals[i]["bytes"]
|
|
|
|
totals[i]["running_edits"] = running_edits
|
|
totals[i]["running_bytes"] = running_bytes
|
|
|
|
ns = totals[max(0, i-5):i]
|
|
if len(ns) == 0:
|
|
totals[i]["avg_bytes"] = totals[i]["bytes"]
|
|
else:
|
|
totals[i]["avg_bytes"] = sum(map(lambda x: x["bytes"], ns)) / len(ns)
|
|
|
|
if len(ns) == 0:
|
|
totals[i]["avg_edits"] = totals[i]["edits"]
|
|
else:
|
|
totals[i]["avg_edits"] = sum(map(lambda x: x["edits"], ns)) / len(ns)
|
|
|
|
# result = {
|
|
# "total_edits": sum(totals[k]["number"] for k in totals),
|
|
# "total_bytes_changed": sum(totals[k]["bytes"] for k in totals),
|
|
# "time_series": totals,
|
|
# }
|
|
|
|
result = []
|
|
for minute in range(len(totals)):
|
|
result.append([totals[minute]["time"], totals[minute]["edits"], totals[minute]["avg_edits"], totals[minute]["running_edits"]/100, totals[minute]["bytes"], totals[minute]["avg_bytes"], totals[minute]["running_bytes"]/100])
|
|
|
|
import datetime
|
|
|
|
print(json.dumps({
|
|
"total_edits": sum(k["edits"] for k in totals),
|
|
"total_bytes_changed": sum(k["bytes"] for k in totals),
|
|
"updated_at": datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M"),
|
|
"data": result,
|
|
})) |