add download history stats

This commit is contained in:
Simon 2023-09-02 11:22:03 +07:00
parent 5ee37eb0cb
commit 4016e81f9a
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
3 changed files with 37 additions and 5 deletions

View File

@ -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):

View File

@ -4,15 +4,19 @@
<div class="title-bar">
<h1>Your Archive</h1>
</div>
<div>
<div class="settings-item">
<h2>Main overview</h2>
<div id="primaryBox" class="info-box info-box-4"></div>
</div>
<div>
<div class="settings-item">
<h2>Watch Progress</h2>
<div id="watchBox" class="info-box info-box-3"></div>
</div>
<div>
<div class="settings-item">
<h2>Download History</h2>
<div id="downHistBox" class="info-box info-box-4"></div>
</div>
<div class="settings-item">
<h2>Biggest Channels</h2>
<div class="info-box description-box">
<table>

View File

@ -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();
}