add stats
This commit is contained in:
1 parent
55778039fb
commit
067f23cc19
3 files changed
+51
No files matched your search
@@ -1 +1,2 @@
|
|||||||
*.db
|
*.db
|
||||||
|
__pycache__
|
||||||
@@ -1,2 +1,5 @@
|
|||||||
|
stats:
|
||||||
|
python stats.py
|
||||||
|
|
||||||
fetch:
|
fetch:
|
||||||
python fetch.py
|
python fetch.py
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import json
|
||||||
|
import sqlite3
|
||||||
|
from collections import Counter
|
||||||
|
from datetime import date
|
||||||
|
|
||||||
|
db = sqlite3.connect("mensa.db")
|
||||||
|
|
||||||
|
rows = db.execute("""
|
||||||
|
SELECT date, title, category, type
|
||||||
|
FROM dishes
|
||||||
|
WHERE title != ''
|
||||||
|
""").fetchall()
|
||||||
|
|
||||||
|
meals = [title for _, title, _, _ in rows]
|
||||||
|
vegan = [title for _, title, category, _ in rows if "vegan" in json.loads(category)]
|
||||||
|
nds = [title for _, title, category, _ in rows if "NDS" in json.loads(category)]
|
||||||
|
|
||||||
|
counts = Counter(meals)
|
||||||
|
vegan_counts = Counter(vegan)
|
||||||
|
nds_counts = Counter(nds)
|
||||||
|
|
||||||
|
dates = [date.fromisoformat(d) for d, _, _, _ in rows]
|
||||||
|
|
||||||
|
print(f"date range: {min(dates)} → {max(dates)}")
|
||||||
|
print(f"meals: {len(meals)}")
|
||||||
|
print(f"vegan meals: {len(vegan)}")
|
||||||
|
print(f"unique meals: {len(counts)}")
|
||||||
|
|
||||||
|
print("\ntop 5 most served:")
|
||||||
|
for meal, count in counts.most_common(5):
|
||||||
|
print(f" {count:3}x {meal}")
|
||||||
|
|
||||||
|
print("\ntop 5 vegan meals:")
|
||||||
|
for meal, count in vegan_counts.most_common(5):
|
||||||
|
print(f" {count:3}x {meal}")
|
||||||
|
|
||||||
|
print("\ntop 5 NDS menus:")
|
||||||
|
for meal, count in nds_counts.most_common(5):
|
||||||
|
print(f" {count:3}x {meal}")
|
||||||
|
|
||||||
|
print("\nmeals served only once:")
|
||||||
|
for date_, meal, _, _ in rows:
|
||||||
|
if counts[meal] == 1:
|
||||||
|
days = (date.today() - date.fromisoformat(date_)).days
|
||||||
|
print(f" {days:3} days ago {date_} {meal}")
|
||||||
|
|
||||||
|
db.close()
|
||||||
Reference in new issue
Block a user