2023-01-19 16:02:57 +00:00
|
|
|
from sanic.response import html
|
2024-02-19 06:55:23 +00:00
|
|
|
from sanic import Blueprint, Request
|
|
|
|
from messages import NOSECOUNT
|
2023-01-19 16:02:57 +00:00
|
|
|
from ext import *
|
|
|
|
|
|
|
|
bp = Blueprint("stats", url_prefix="/manage")
|
|
|
|
|
2024-01-04 11:14:43 +00:00
|
|
|
@bp.route("/sponsorcount")
|
|
|
|
async def sponsor_count(request, order: Order):
|
2024-01-21 23:35:44 +00:00
|
|
|
await request.app.ctx.om.update_cache()
|
2024-01-04 20:40:06 +00:00
|
|
|
orders = {key:value for key,value in sorted(request.app.ctx.om.cache.items(), key=lambda x: x[1].ans('fursona_name')) if value.status not in ['c', 'e']}
|
2024-01-04 11:14:43 +00:00
|
|
|
|
|
|
|
tpl = request.app.ctx.tpl.get_template('sponsorcount.html')
|
|
|
|
return html(tpl.render(orders=orders, order=order))
|
|
|
|
|
2024-02-19 06:55:23 +00:00
|
|
|
def calc_filter(orders: dict, filter_cmd: str, order: Order) -> tuple[dict, str]:
|
|
|
|
if not filter_cmd or len(filter_cmd) == 0 or not orders or len(orders.keys()) == 0: return
|
|
|
|
if filter_cmd.lower() == "capacity":
|
|
|
|
return {key:value for key,value in orders.items() if (not value.room_confirmed and value.bed_in_room == order.bed_in_room)}, NOSECOUNT['filters'][filter_cmd.lower()]
|
|
|
|
else:
|
|
|
|
return None, None
|
|
|
|
|
2023-01-19 16:02:57 +00:00
|
|
|
@bp.route("/nosecount")
|
2024-02-19 06:55:23 +00:00
|
|
|
async def nose_count(request: Request, order: Order):
|
2024-01-21 23:35:44 +00:00
|
|
|
await request.app.ctx.om.update_cache()
|
2023-01-19 16:02:57 +00:00
|
|
|
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']}
|
2024-02-19 06:55:23 +00:00
|
|
|
filtered: dict = None
|
|
|
|
filter_message: str = None
|
|
|
|
for query in request.query_args:
|
|
|
|
if query[0] == "filter" and order:
|
|
|
|
filtered, filter_message = calc_filter(orders, query[1], order) if filter else None
|
2023-01-19 16:02:57 +00:00
|
|
|
tpl = request.app.ctx.tpl.get_template('nosecount.html')
|
2024-02-19 06:55:23 +00:00
|
|
|
return html(tpl.render(orders=orders, order=order, filtered=filtered, filter_header=filter_message))
|
2023-12-30 10:27:42 +00:00
|
|
|
|
|
|
|
@bp.route("/fursuitcount")
|
|
|
|
async def fursuit_count(request, order: Order):
|
2024-01-21 23:35:44 +00:00
|
|
|
await request.app.ctx.om.update_cache()
|
2024-01-04 20:40:06 +00:00
|
|
|
orders = {key:value for key,value in sorted(request.app.ctx.om.cache.items(), key=lambda x: x[1].ans('fursona_name')) if value.status not in ['c', 'e']}
|
2023-12-30 10:27:42 +00:00
|
|
|
|
|
|
|
tpl = request.app.ctx.tpl.get_template('fursuitcount.html')
|
|
|
|
return html(tpl.render(orders=orders, order=order))
|