WMGZON/controllers/web/stats.py

51 lines
1.5 KiB
Python
Raw Normal View History

""" The user controller to manage all of the stats related endpoints
in the web app
"""
from flask import Blueprint
from flask import render_template, request
from controllers.database.stats import StatsController
# Blueprint to append user endpoints to
blueprint = Blueprint("stats", __name__, url_prefix='/stats')
@blueprint.route('/')
def index():
""" Main page to view all of the statistics for the site """
db = StatsController()
data = db.read()
test = list(map(lambda d: d.productID, data))
return render_template("index.html", content="stats.html", data=test)
2024-02-06 20:11:04 +00:00
@blueprint.route('/products/<int:id>')
def view_product_stats(id: int):
""" Page to view statistics for a given product """
db = StatsController()
prev_days: int = request.args.get('prev_days', 7, int)
data = db.read_days(id, prev_days)
product_frequency_data = dict(map(
# lambda k, v: (k, random.randint(0, 100)),
lambda k, v: (k, len(v)),
data.keys(),
data.values()
))
return render_template(
"index.html",
content="stats.html",
headings=list(reversed(product_frequency_data.keys())),
data=list(reversed(product_frequency_data.values()))
)
2024-02-01 01:45:39 +00:00
2024-02-06 20:11:04 +00:00
@blueprint.route('/users/<int:id>')
def view_user_stats(id: int):
""" Page to view statistics for a given user """
db = StatsController()
data = db.read_user(id)
return render_template("index.html", content="stats.html", data=data)