Skip to content

Commit

Permalink
Merge pull request #1461 from OhMaley/bugfix/storage/monitoring-tool/…
Browse files Browse the repository at this point in the history
…dates-consistency

Related to issue #1451: Send snapshot created_at instead of at_date to front for display consistency
  • Loading branch information
Didayolo authored May 31, 2024
2 parents 9b4639d + c479b12 commit 5a5a41b
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/apps/api/views/analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def storage_usage_history(request):
raise PermissionDenied(detail="Admin only")

storage_usage_history = {}
last_storage_usage_history_snapshot = StorageUsageHistory.objects.order_by("at_date").last()
last_storage_usage_history_snapshot = StorageUsageHistory.objects.order_by("-at_date").first()
if last_storage_usage_history_snapshot:
start_date = request.query_params.get("start_date", (datetime.datetime.today() - datetime.timedelta(weeks=4)).strftime("%Y-%m-%d"))
end_date = request.query_params.get("end_date", datetime.datetime.today().strftime("%Y-%m-%d"))
Expand Down Expand Up @@ -209,7 +209,7 @@ def competitions_usage(request):
raise PermissionDenied(detail="Admin only")

competitions_usage = {}
last_competition_storage_snapshot = CompetitionStorageDataPoint.objects.order_by("at_date").last()
last_competition_storage_snapshot = CompetitionStorageDataPoint.objects.order_by("-at_date").first()
if last_competition_storage_snapshot:
start_date = request.query_params.get("start_date", (datetime.datetime.today() - datetime.timedelta(weeks=4)).strftime("%Y-%m-%d"))
end_date = request.query_params.get("end_date", datetime.datetime.today().strftime("%Y-%m-%d"))
Expand Down Expand Up @@ -237,7 +237,7 @@ def competitions_usage(request):
}

response = {
"last_storage_calculation_date": last_competition_storage_snapshot.at_date.isoformat() if last_competition_storage_snapshot else None,
"last_storage_calculation_date": last_competition_storage_snapshot.created_at.isoformat() if last_competition_storage_snapshot else None,
"competitions_usage": competitions_usage
}

Expand All @@ -253,7 +253,7 @@ def users_usage(request):
raise PermissionDenied(detail="Admin only")

users_usage = {}
last_user_storage_snapshot = UserStorageDataPoint.objects.order_by("at_date").last()
last_user_storage_snapshot = UserStorageDataPoint.objects.order_by("-at_date").first()
if last_user_storage_snapshot:
start_date = request.query_params.get("start_date", (datetime.datetime.today() - datetime.timedelta(weeks=4)).strftime("%Y-%m-%d"))
end_date = request.query_params.get("end_date", datetime.datetime.today().strftime("%Y-%m-%d"))
Expand Down Expand Up @@ -281,7 +281,7 @@ def users_usage(request):
}

response = {
"last_storage_calculation_date": last_user_storage_snapshot.at_date.isoformat() if last_user_storage_snapshot else None,
"last_storage_calculation_date": last_user_storage_snapshot.created_at.isoformat() if last_user_storage_snapshot else None,
"users_usage": users_usage
}

Expand Down

0 comments on commit 5a5a41b

Please sign in to comment.