From 4016e81f9aa73f9a8c8bff89fc70226c508cdb9a Mon Sep 17 00:00:00 2001 From: Simon Date: Sat, 2 Sep 2023 11:22:03 +0700 Subject: [PATCH] add download history stats --- tubearchivist/api/src/aggs.py | 12 +++++++++-- .../home/templates/home/settings.html | 10 +++++++--- tubearchivist/static/stats.js | 20 +++++++++++++++++++ 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/tubearchivist/api/src/aggs.py b/tubearchivist/api/src/aggs.py index b8db502..aa35c39 100644 --- a/tubearchivist/api/src/aggs.py +++ b/tubearchivist/api/src/aggs.py @@ -174,7 +174,7 @@ class DownloadHist(AggBase): }, } }, - "query": {"range": {"date_downloaded": {"gte": "now-6d/d"}}}, + "query": {"range": {"date_downloaded": {"gte": "now-7d/d"}}}, } def process(self): @@ -182,7 +182,15 @@ class DownloadHist(AggBase): aggregations = self.get() buckets = aggregations[self.name]["buckets"] - return {i.get("key_as_string"): i.get("doc_count") for i in buckets} + response = [ + { + "date": i.get("key_as_string"), + "count": i.get("doc_count"), + } + for i in buckets + ] + + return response class BiggestChannel(AggBase): diff --git a/tubearchivist/home/templates/home/settings.html b/tubearchivist/home/templates/home/settings.html index edaaeaf..3d2bafd 100644 --- a/tubearchivist/home/templates/home/settings.html +++ b/tubearchivist/home/templates/home/settings.html @@ -4,15 +4,19 @@

Your Archive

-
+

Main overview

-
+

Watch Progress

-
+
+

Download History

+
+
+

Biggest Channels

diff --git a/tubearchivist/static/stats.js b/tubearchivist/static/stats.js index 0bdba34..8a2616c 100644 --- a/tubearchivist/static/stats.js +++ b/tubearchivist/static/stats.js @@ -96,6 +96,25 @@ function buildWatchTile(title, watchDetail) { return tile; } +function downloadHist() { + let apiEndpoint = '/api/stats/downloadhist/'; + let responseData = apiRequest(apiEndpoint, 'GET'); + let histBox = document.getElementById('downHistBox'); + for (let i = 0; i < responseData.length; i++) { + const dailyStat = responseData[i]; + let tile = buildDailyStat(dailyStat); + histBox.appendChild(tile); + } +} + +function buildDailyStat(dailyStat) { + let tile = buildTile(dailyStat.date); + let message = document.createElement('p'); + message.innerText = `new videos: ${dailyStat.count}`; + tile.appendChild(message); + return tile; +} + function biggestChannel() { let apiEndpoint = '/api/stats/biggestchannels/'; let responseData = apiRequest(apiEndpoint, 'GET'); @@ -126,6 +145,7 @@ function humanFileSize(size) { function buildStats() { primaryStats(); watchStats(); + downloadHist(); biggestChannel(); }