-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgen_web_views.py
More file actions
59 lines (49 loc) · 1.43 KB
/
gen_web_views.py
File metadata and controls
59 lines (49 loc) · 1.43 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# /// script
# dependencies = [
# "jinja2",
# "numpy",
# "pandas",
# ]
# ///
import sys
import jinja2
import json
import numpy as np
import pandas as pd
from jinja2 import Environment, FileSystemLoader
from pathlib import Path
BASE = Path(__file__).parents[0]
DEST = BASE / ".." / "public"
DATA = BASE / ".." / "data"
environment = Environment(
loader=FileSystemLoader(str(BASE))
)
out = DEST / "sponsors.html"
base_html = environment.get_template(str(Path("templates") / "base_sponsors.html"))
# Read data
dfs = []
sponsor_dir = DATA / "sponsors"
for datafile in sponsor_dir.glob("**/*.json"):
data = None
with open(datafile) as f:
try:
data = json.load(f)
except json.decoder.JSONDecodeError:
print("[ERROR] Failed to parse", datafile)
sys.exit(1)
df = pd.DataFrame(data["sponsors"])
df["level"] = df["level"].apply(lambda x : data["levels"][x] if x in data["levels"] else np.nan)
df["conference"] = datafile.parents[0].stem
df["year"] = data["year"]
dfs.append(df)
sponsors = pd.concat(dfs)
grouped = sponsors.drop(["conference", "year"], axis=1).groupby("name").sum().sort_values("level", ascending=False)
# End read data
context = {
"title": "Sponsors",
"description": "Historical data from European Conferences",
"sponsors": sponsors,
"grouped": grouped,
}
with open(out, mode="w", encoding="utf-8") as f:
f.write(base_html.render(context))