From 6609f436aef94689e44b5e7d249d38dd191855fd Mon Sep 17 00:00:00 2001 From: Ed Date: Fri, 12 May 2023 00:19:08 +0200 Subject: [PATCH] Removed superficial code from stats --- stats.py | 35 ----------------------------------- 1 file changed, 35 deletions(-) diff --git a/stats.py b/stats.py index c90b3f5..ae37d1f 100644 --- a/stats.py +++ b/stats.py @@ -7,41 +7,6 @@ import asyncio bp = Blueprint("stats", url_prefix="/manage") -def by_count(d): - return {k:v for k,v in sorted(d.items(), key=lambda x: x[1], reverse=True)} - -async def gen_stats(app): - orders = app.ctx.om.cache.values() - - countries = {} - sponsors = {} - - for o in orders: - countries[o.country] = countries.get(o.country, 0) +1 - sponsors[o.sponsorship or 'no'] = sponsors.get(o.sponsorship or 'no', 0) +1 - - app.ctx.stats = { - 'countries': by_count(countries), - 'sponsors': by_count(sponsors), - 'time': time() - } - - return app.ctx.stats - -@bp.route("/stats") -async def stats(request, order: Order): - - stats = getattr(request.app.ctx, 'stats', None) - '''if not stats: - await gen_stats(request.app) - elif time() - stats['time'] > 1800: - asyncio.create_task(gen_stats(request.app))''' - - request.app.ctx.stats = await gen_stats(request.app) - - tpl = request.app.ctx.tpl.get_template('stats.html') - return html(tpl.render(order=order, stats=request.app.ctx.stats)) - @bp.route("/nosecount") async def nose_count(request, order: Order): orders = {key:value for key,value in sorted(request.app.ctx.om.cache.items(), key=lambda x: len(x[1].room_members), reverse=True) if value.status not in ['c', 'e']}