add panoramax token
This commit is contained in:
parent
f66e5e3f7b
commit
1a3df2ed75
12 changed files with 1132 additions and 61 deletions
53
oedb/resources/demo/demo_stats.py
Normal file
53
oedb/resources/demo/demo_stats.py
Normal file
|
@ -0,0 +1,53 @@
|
|||
"""
|
||||
Stats page for demo: list counts per what, and optional map per selected type.
|
||||
"""
|
||||
|
||||
import os
|
||||
import falcon
|
||||
from collections import Counter
|
||||
from oedb.utils.logging import logger
|
||||
from oedb.utils.db import db_connect
|
||||
import jinja2
|
||||
|
||||
|
||||
class DemoStatsResource:
|
||||
def __init__(self):
|
||||
template_dir = os.path.join(os.path.dirname(__file__), 'templates')
|
||||
self.jinja_env = jinja2.Environment(
|
||||
loader=jinja2.FileSystemLoader(template_dir),
|
||||
autoescape=jinja2.select_autoescape(['html', 'xml'])
|
||||
)
|
||||
|
||||
def on_get(self, req, resp):
|
||||
logger.info("Processing GET request to /demo/stats")
|
||||
resp.content_type = 'text/html'
|
||||
|
||||
selected_what = req.get_param('what')
|
||||
|
||||
try:
|
||||
db = db_connect()
|
||||
cur = db.cursor()
|
||||
# Compter par what
|
||||
cur.execute("""
|
||||
SELECT events_what, COUNT(*)
|
||||
FROM events
|
||||
GROUP BY events_what
|
||||
ORDER BY COUNT(*) DESC
|
||||
""")
|
||||
rows = cur.fetchall()
|
||||
counts = [(r[0], r[1]) for r in rows]
|
||||
total_events = sum(c for _, c in counts)
|
||||
template = self.jinja_env.get_template('stats.html')
|
||||
html = template.render(counts=counts, total_events=total_events, selected_what=selected_what)
|
||||
resp.text = html
|
||||
resp.status = falcon.HTTP_200
|
||||
logger.success("Successfully processed GET request to /demo/stats")
|
||||
except Exception as e:
|
||||
logger.error(f"Error processing GET request to /demo/stats: {e}")
|
||||
resp.status = falcon.HTTP_500
|
||||
resp.text = f"Error: {str(e)}"
|
||||
|
||||
|
||||
demo_stats = DemoStatsResource()
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue