#5 Changed styling and added product ranking in category to the stats page
This commit is contained in:
parent
9943a1492c
commit
83829af06f
@ -90,6 +90,34 @@ class StatsController(DatabaseController):
|
|||||||
|
|
||||||
return self.get_one(query, params, int)
|
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):
|
def update(self):
|
||||||
print("Doing work")
|
print("Doing work")
|
||||||
|
|
||||||
|
@ -42,18 +42,12 @@ def view_product_stats(id: int):
|
|||||||
# Total Views
|
# Total Views
|
||||||
total_views = db.read_product_views(id)
|
total_views = db.read_product_views(id)
|
||||||
|
|
||||||
|
# Ranking in category
|
||||||
|
ranking = db.read_ranking(id)
|
||||||
|
|
||||||
db = ProductController()
|
db = ProductController()
|
||||||
product = db.read_id(id)
|
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
|
# Stock Level
|
||||||
product.quantityAvailable
|
product.quantityAvailable
|
||||||
|
|
||||||
@ -62,7 +56,7 @@ def view_product_stats(id: int):
|
|||||||
|
|
||||||
data = {
|
data = {
|
||||||
"age": time_since_posted,
|
"age": time_since_posted,
|
||||||
"ranking": 0,
|
"ranking": ranking,
|
||||||
"views": {
|
"views": {
|
||||||
"total": total_views,
|
"total": total_views,
|
||||||
"headings": list(reversed(product_view_frequency_data.keys())),
|
"headings": list(reversed(product_view_frequency_data.keys())),
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
.stats {
|
.stats {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 1rem;
|
gap: 1rem;
|
||||||
|
@ -182,3 +182,10 @@ a:active {
|
|||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
height: 1%;
|
height: 1%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.hidden {
|
||||||
|
display: none;
|
||||||
|
visibility: hidden;
|
||||||
|
width: 0;
|
||||||
|
height: 0;
|
||||||
|
}
|
@ -1,25 +1,27 @@
|
|||||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/products.css') }}">
|
<link rel="stylesheet" href="{{ url_for('static', filename='css/products.css') }}">
|
||||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/stats.css') }}">
|
<link rel="stylesheet" href="{{ url_for('static', filename='css/stats.css') }}">
|
||||||
|
<link rel="stylesheet" href="{{ url_for('static', filename='css/loginform.css') }}">
|
||||||
|
|
||||||
<div class="stats">
|
<div class="stats">
|
||||||
<div>
|
<div>
|
||||||
<canvas id="myChart" width="800px" height="500px"></canvas>
|
<canvas id="myChart" width="800px" height="500px"></canvas>
|
||||||
<br >
|
<br >
|
||||||
<form method="GET">
|
<form method="GET" action='' id="timeframe_form">
|
||||||
<input type="radio" id="7days" name="prev_days" value=7>
|
<div class="input-form-row">
|
||||||
<label for="7days">7 Days</label><br>
|
<input type="radio" class="hidden" id="7days" name='prev_days' value=7>
|
||||||
<input type="radio" id="31days" name="prev_days" value=31>
|
<label for="7days">1 Week</label><br>
|
||||||
<label for="31days">31 Days</label><br>
|
<input type="radio" class="hidden" id="14days" name="prev_days" value=14>
|
||||||
<input type="radio" id="1year" name="prev_days" value=365>
|
<label for="14days">2 Weeks</label><br>
|
||||||
<label for="1year">1 Year</label>
|
<input type="radio" class="hidden" id="1month" name="prev_days" value=31>
|
||||||
<input type="submit">
|
<label for="1month">1 Month</label>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<p>Age: {{data['age']}}</p>
|
<p><b>Age:</b> {{data['age']}}</p>
|
||||||
<p>Ranking: {{data['ranking']}}</p>
|
<p><b>Ranking:</b> {{data['ranking']}}</p>
|
||||||
<p>Stock Level: {{data['stocklevel']}}</p>
|
<p><b>Stock Level:</b> {{data['stocklevel']}}</p>
|
||||||
<p>Total Views: {{data['views']['total']}}</p>
|
<p><b>Total Views:</b> {{data['views']['total']}}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -58,4 +60,16 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// Remove the need for a submit button on the graph buttons
|
||||||
|
const form = document.getElementById("timeframe_form");
|
||||||
|
const rbs = form.querySelectorAll("input[type='radio']");
|
||||||
|
console.log(rbs)
|
||||||
|
console.log(form)
|
||||||
|
rbs.forEach((input) => {
|
||||||
|
input.addEventListener("change", () => {
|
||||||
|
form.submit();
|
||||||
|
});
|
||||||
|
});
|
||||||
</script>
|
</script>
|
Loading…
Reference in New Issue
Block a user