-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport_csv.py
More file actions
35 lines (28 loc) · 1.26 KB
/
Copy pathexport_csv.py
File metadata and controls
35 lines (28 loc) · 1.26 KB
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
#!/usr/bin/env python
"""
Dump the BWF cache to plain CSVs, one per discipline -- the shareable version
of the dataset for people who just want the matches and not this codebase.
python export_csv.py # writes data/csv/{ms,ws,md,wd,xd}.csv
"""
from pathlib import Path
from badminton import bwf
OUT = Path(__file__).resolve().parent / "data" / "csv"
def main():
OUT.mkdir(parents=True, exist_ok=True)
frames = bwf.load()
for code, df in frames.items():
out = df.copy()
# tuples don't belong in a CSV; join pairs with ' / '
out["team1"] = out["s1_players"].map(" / ".join)
out["team2"] = out["s2_players"].map(" / ".join)
out = out[["date", "discipline", "tournament", "tier", "round",
"host", "team1", "team2", "winner", "score",
"s1_home", "s2_home"]]
out.columns = ["date", "discipline", "tournament", "tier", "round",
"host_location", "team1", "team2", "winner", "score",
"team1_at_home", "team2_at_home"]
path = OUT / f"{code.lower()}.csv"
out.to_csv(path, index=False, encoding="utf-8")
print(f"{path.name}: {len(out):,} matches, {path.stat().st_size // 1024} KB")
if __name__ == "__main__":
main()