#5 Latest views are now displayed on the stats page
This commit is contained in:
@@ -49,30 +49,32 @@ class StatsController(DatabaseController):
|
||||
WHERE userID = ?
|
||||
"""
|
||||
|
||||
self.get_many(query, params)
|
||||
return self.get_many(query, params)
|
||||
|
||||
def read_days(self, product_id: int, prev_days: int = 7
|
||||
) -> list[Stats] | None:
|
||||
) -> dict[int, list[Stats]] | None:
|
||||
""" Returns data from within the given number of days """
|
||||
data = self.read_product(product_id)
|
||||
|
||||
filtered_data = list(filter(
|
||||
lambda d: is_within_x_days(d.viewDate, prev_days),
|
||||
data
|
||||
))
|
||||
# Filter the values to only be within X prev days
|
||||
filtered_data = list()
|
||||
if data is not None:
|
||||
filtered_data = list(filter(
|
||||
lambda d: is_within_x_days(d.viewDate, prev_days),
|
||||
data
|
||||
))
|
||||
|
||||
day_views: dict[int, list[Stats]] = dict()
|
||||
|
||||
for i in range(0, prev_days):
|
||||
day_views[i] = list()
|
||||
|
||||
# Organise data into distinct
|
||||
for view in filtered_data:
|
||||
diff = datetime.now()-view.viewDate
|
||||
|
||||
if diff.days not in day_views:
|
||||
day_views[diff.days] = []
|
||||
|
||||
day_views[diff.days].append(view)
|
||||
|
||||
for days in day_views.values():
|
||||
print(len(days))
|
||||
return day_views
|
||||
|
||||
def update(self):
|
||||
print("Doing work")
|
||||
|
Reference in New Issue
Block a user