diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d5fd3aa --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +public/*html diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..14964e5 --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +html: + cd scripts && uv run gen_web_views.py diff --git a/public/css/style.css b/public/css/style.css new file mode 100644 index 0000000..e69de29 diff --git a/scripts/gen_web_views.py b/scripts/gen_web_views.py new file mode 100644 index 0000000..2e20504 --- /dev/null +++ b/scripts/gen_web_views.py @@ -0,0 +1,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)) diff --git a/scripts/requirements.txt b/scripts/requirements.txt index 8dee024..8cd545d 100644 --- a/scripts/requirements.txt +++ b/scripts/requirements.txt @@ -1,2 +1,5 @@ requests types-requests +jinja2 +numpy +pandas diff --git a/scripts/templates/base.html b/scripts/templates/base.html new file mode 100644 index 0000000..e83e31b --- /dev/null +++ b/scripts/templates/base.html @@ -0,0 +1,110 @@ + + + + + + + + + + + +
+ +
+ + +
+
+
+

+ {{ title }} +

+
+ +
+

{{ description }}

+
+ +
+ {% block content %} + {% endblock %} +
+ +
+
+ + + + + + + diff --git a/scripts/templates/base_sponsors.html b/scripts/templates/base_sponsors.html new file mode 100644 index 0000000..50cf38e --- /dev/null +++ b/scripts/templates/base_sponsors.html @@ -0,0 +1,43 @@ +{% extends "templates/base.html" %} +{% block content %} +{% set sort_icon = '' %} +

+ Ranking by amount +

+ + + + + + {% for idx, sponsor in grouped.iterrows() %} + {% if sponsor['name'] and ( sponsors['level'] is defined )%} + + + + + {% endif %} + {% endfor %} +
Company {{ sort_icon }}Total amount (EUR) {{ sort_icon }}
{{ sponsor['name'] }}{{ sponsor['level'] }}
+ +

+ All data +

+ + + + + + + + {% for idx, sponsor in sponsors.iterrows() %} + {% if sponsor['name'] and ( sponsors['level'] is defined )%} + + + + + + + {% endif %} + {% endfor %} +
Year {{ sort_icon }}Conference {{ sort_icon }}Company {{ sort_icon }}Amount (EUR) {{ sort_icon }}
{{ sponsor['year'] }}{{ sponsor['conference'] }}{{ sponsor['name'] }}{{ sponsor['level'] }}
+{% endblock %}