#5 Changed styling and added product ranking in category to the stats page

This commit is contained in:
2024-02-11 15:52:12 +00:00
parent 9943a1492c
commit 83829af06f
5 changed files with 66 additions and 22 deletions

View File

@ -90,6 +90,34 @@ class StatsController(DatabaseController):
return self.get_one(query, params, int)
def read_ranking(self, id: int):
params = [
id
]
query = """
SELECT
ranking
FROM
(
SELECT
p.id as id,
RANK() OVER (
PARTITION BY p.categoryID
ORDER BY COUNT(v.productID) DESC
)AS ranking
FROM
Products p
LEFT JOIN
Views v ON p.id = v.productID
GROUP BY
p.id, p.categoryID
)
WHERE id = ?
"""
return self.get_one(query, params, int)
def update(self):
print("Doing work")

View File

@ -42,18 +42,12 @@ def view_product_stats(id: int):
# Total Views
total_views = db.read_product_views(id)
# Ranking in category
ranking = db.read_ranking(id)
db = ProductController()
product = db.read_id(id)
# Ranking in category
query = """
SELECT id, count(id) FROM stats WHERE id = (
SELECT id FROM Products WEHRE id = (
SELECT categoryID FROM Products WHERE id = ?
)
)
"""
# Stock Level
product.quantityAvailable
@ -62,7 +56,7 @@ def view_product_stats(id: int):
data = {
"age": time_since_posted,
"ranking": 0,
"ranking": ranking,
"views": {
"total": total_views,
"headings": list(reversed(product_view_frequency_data.keys())),