Skip to content

Commit 89452a8

Browse files
author
Daniel Svensson
committed
Add script that patches matchstats json files with extra data.
1 parent 6ef14ad commit 89452a8

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

patch-stats.py

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import json
2+
import sys
3+
4+
statsfile = sys.argv[1]
5+
6+
with open(statsfile) as fd:
7+
data = json.load(fd)
8+
9+
extrastatsfile = statsfile.replace(".json", ".extra.json")
10+
11+
with open(extrastatsfile) as fd:
12+
extra = json.load(fd)
13+
14+
15+
for player_id, team, name in extra["players"]:
16+
for i, player in enumerate(data["players"]):
17+
if player["name"] == name:
18+
player["uid"] = player_id
19+
20+
fragstats = []
21+
for timestamp, diff in extra["frags"]:
22+
fragstats.append({
23+
"timestamp": timestamp,
24+
"red": diff if diff >= 0 else 0,
25+
"blue": -diff if diff <= 0 else 0
26+
})
27+
28+
data["fragstats"] = fragstats
29+
30+
events = []
31+
for timestamp, player_id, type, count, meta in extra["events"]:
32+
y = 0
33+
for frags in fragstats:
34+
y = max(frags["red"], frags["blue"])
35+
if frags["timestamp"] > timestamp:
36+
break
37+
events.append({
38+
"timestamp": timestamp,
39+
"uid": player_id,
40+
"y": y,
41+
"type": type,
42+
"count": count,
43+
"meta": meta
44+
})
45+
46+
data["events"] = events
47+
48+
with open(statsfile, "w") as fd:
49+
json.dump(data, fd)

0 commit comments

Comments
 (0)