mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-10 23:17:37 +01:00
Fix all package stats API returning 0s
This commit is contained in:
parent
8cde0cd852
commit
996d46cad7
@ -78,13 +78,14 @@ def get_package_overview_for_user(user: Optional[User], start_date: datetime.dat
|
|||||||
if user:
|
if user:
|
||||||
query = query.filter(PackageDailyStats.package.has(author_id=user.id))
|
query = query.filter(PackageDailyStats.package.has(author_id=user.id))
|
||||||
|
|
||||||
stats = query \
|
all_stats = query \
|
||||||
.filter(PackageDailyStats.package.has(state=PackageState.APPROVED)) \
|
.filter(PackageDailyStats.package.has(state=PackageState.APPROVED),
|
||||||
|
PackageDailyStats.date >= start_date, PackageDailyStats.date <= end_date) \
|
||||||
.order_by(db.asc(PackageDailyStats.package_id), db.asc(PackageDailyStats.date)) \
|
.order_by(db.asc(PackageDailyStats.package_id), db.asc(PackageDailyStats.date)) \
|
||||||
.all()
|
.all()
|
||||||
|
|
||||||
stats_by_package = {}
|
stats_by_package = {}
|
||||||
for stat in stats:
|
for stat in all_stats:
|
||||||
bucket = stats_by_package.get(stat.package_id, [])
|
bucket = stats_by_package.get(stat.package_id, [])
|
||||||
stats_by_package[stat.package_id] = bucket
|
stats_by_package[stat.package_id] = bucket
|
||||||
|
|
||||||
@ -113,8 +114,10 @@ def get_package_overview_for_user(user: Optional[User], start_date: datetime.dat
|
|||||||
if stat.date == date:
|
if stat.date == date:
|
||||||
row.append(stat.downloads)
|
row.append(stat.downloads)
|
||||||
i += 1
|
i += 1
|
||||||
else:
|
elif stat.date > date:
|
||||||
row.append(0)
|
row.append(0)
|
||||||
|
else:
|
||||||
|
raise Exception(f"Invalid logic, expected stat {stat.date} to be later than {date}")
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user