From 2b0391528c48420e84b5ba0f67d969f4a4b4ee07 Mon Sep 17 00:00:00 2001 From: OhMaley Date: Mon, 18 Dec 2023 15:38:41 -0500 Subject: [PATCH] add analytics snapshot date in API response + display it --- src/apps/api/views/analytics.py | 21 +++++++++-- .../riot/analytics/_competitions_usage.tag | 37 ++++++++++++------- src/static/riot/analytics/_usage_history.tag | 22 ++++++++--- src/static/riot/analytics/_users_usage.tag | 37 ++++++++++++------- src/static/riot/analytics/analytics.tag | 8 ++++ 5 files changed, 91 insertions(+), 34 deletions(-) diff --git a/src/apps/api/views/analytics.py b/src/apps/api/views/analytics.py index 47282c97b..238002a9d 100644 --- a/src/apps/api/views/analytics.py +++ b/src/apps/api/views/analytics.py @@ -190,8 +190,13 @@ def storage_usage_history(request): 'admin_usage': su['admin_usage'], 'orphaned_file_usage': su['orphaned_file_usage'] } + + response = { + "last_storage_calculation_date": last_storage_usage_history_snapshot.at_date.isoformat() if last_storage_usage_history_snapshot else None, + "storage_usage_history": storage_usage_history + } - return Response(storage_usage_history, status=status.HTTP_200_OK) + return Response(response, status=status.HTTP_200_OK) @api_view(["GET"]) @@ -230,7 +235,12 @@ def competitions_usage(request): 'datasets': su['datasets_total'], } - return Response(competitions_usage, status=status.HTTP_200_OK) + response = { + "last_storage_calculation_date": last_competition_storage_snapshot.at_date.isoformat() if last_competition_storage_snapshot else None, + "competitions_usage": competitions_usage + } + + return Response(response, status=status.HTTP_200_OK) @api_view(["GET"]) @@ -269,4 +279,9 @@ def users_usage(request): 'submissions': su['submissions_total'], } - return Response(users_usage, status=status.HTTP_200_OK) \ No newline at end of file + response = { + "last_storage_calculation_date": last_user_storage_snapshot.at_date.isoformat() if last_user_storage_snapshot else None, + "users_usage": users_usage + } + + return Response(response, status=status.HTTP_200_OK) \ No newline at end of file diff --git a/src/static/riot/analytics/_competitions_usage.tag b/src/static/riot/analytics/_competitions_usage.tag index b9568313e..353fb0684 100644 --- a/src/static/riot/analytics/_competitions_usage.tag +++ b/src/static/riot/analytics/_competitions_usage.tag @@ -1,15 +1,18 @@ - - - +
+ + + +

{lastSnapshotDate ? "Last snaphost date: " + pretty_date(lastSnapshotDate) : "No snapshot has been taken yet"}

+
@@ -55,6 +58,7 @@ let datetime = luxon.DateTime; + self.lastSnapshotDate = null; self.competitionsUsageData = null; self.competitionsDropdownOptions = []; self.tableSelectedDate = null; @@ -221,9 +225,11 @@ }; CODALAB.api.get_competitions_usage(parameters) .done(function(data) { - self.competitionsUsageData = data; + self.competitionsUsageData = data["competitions_usage"]; + self.lastSnapshotDate = data["last_storage_calculation_date"]; + self.update({lastSnapshotDate: data["last_storage_calculation_date"]}); self.updateCompetitionsSelectionDropdown(); - self.updateCompetitionTableCalendar(data); + self.updateCompetitionTableCalendar(data["competitions_usage"]); self.updateCompetitionsChart(); self.updateCompetitionsPieChart(); self.updateCompetitionsTable(); @@ -559,5 +565,10 @@ .chart-container { min-height: 450px; } + + .flex-row { + display: flex; + flex-direction: row; + }
\ No newline at end of file diff --git a/src/static/riot/analytics/_usage_history.tag b/src/static/riot/analytics/_usage_history.tag index 50535d8a6..6a75a5e53 100644 --- a/src/static/riot/analytics/_usage_history.tag +++ b/src/static/riot/analytics/_usage_history.tag @@ -1,7 +1,11 @@ - +
+ + +

{lastSnapshotDate ? "Last snaphost date: " + pretty_date(lastSnapshotDate) : "No snapshot has been taken yet"}

+
@@ -17,6 +21,7 @@ }; self.storageUsageHistoryData = null; self.storageUsageChart = null; + self.lastSnapshotDate = null; self.one("mount", function () { self.state.startDate = opts.start_date; @@ -121,8 +126,10 @@ }; CODALAB.api.get_storage_usage_history(parameters) .done(function(data) { - self.storageUsageHistoryData = data; - self.update_storage_usage_history_chart(data); + self.storageUsageHistoryData = data["storage_usage_history"]; + self.lastSnapshotDate = data["last_storage_calculation_date"]; + self.update({lastSnapshotDate: data["last_storage_calculation_date"]}); + self.update_storage_usage_history_chart(data["storage_usage_history"]); }) .fail(function(error) { toastr.error("Could not load storage analytics data"); @@ -177,5 +184,10 @@ .chart-container { min-height: 450px; } + + .flex-row { + display: flex; + flex-direction: row; + } \ No newline at end of file diff --git a/src/static/riot/analytics/_users_usage.tag b/src/static/riot/analytics/_users_usage.tag index 5aff49e28..b83a8a52c 100644 --- a/src/static/riot/analytics/_users_usage.tag +++ b/src/static/riot/analytics/_users_usage.tag @@ -1,15 +1,18 @@ - - - +
+ + + +

{lastSnapshotDate ? "Last snaphost date: " + pretty_date(lastSnapshotDate) : "No snapshot has been taken yet"}

+
@@ -62,6 +65,7 @@ let datetime = luxon.DateTime; + self.lastSnapshotDate = null; self.usersUsageData = null; self.usersDropdownOptions = []; self.usersTableSelectedDate = null; @@ -269,9 +273,11 @@ }; CODALAB.api.get_users_usage(parameters) .done(function(data) { - self.usersUsageData = data; + self.usersUsageData = data["users_usage"]; + self.lastSnapshotDate = data["last_storage_calculation_date"]; + self.update({lastSnapshotDate: data["last_storage_calculation_date"]}); self.updateUsersSelectionDropdown(); - self.updateUsersTableCalendar(data); + self.updateUsersTableCalendar(data["users_usage"]); self.updateUsersChart(); self.updateUsersPieChart(); self.updateUsersTable(); @@ -640,5 +646,10 @@ .chart-container { min-height: 450px; } + + .flex-row { + display: flex; + flex-direction: row; + }
\ No newline at end of file diff --git a/src/static/riot/analytics/analytics.tag b/src/static/riot/analytics/analytics.tag index e6ecbeb26..f0a8d99b4 100644 --- a/src/static/riot/analytics/analytics.tag +++ b/src/static/riot/analytics/analytics.tag @@ -474,6 +474,14 @@ self.update(); } + self.pretty_date = function (date_string) { + if (!!date_string) { + return luxon.DateTime.fromISO(date_string).toLocaleString(luxon.DateTime.DATE_FULL) + } else { + return '' + } + } +