Aggregation daily stats improvements, #build

Changed:
- [API] make daily stats TZ aware
- [API] add daily download media size
This commit is contained in:
Simon 2023-11-09 10:42:02 +07:00
commit 1657c55cbe
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
2 changed files with 16 additions and 3 deletions

View File

@ -2,6 +2,7 @@
from home.src.es.connect import ElasticWrap
from home.src.ta.helper import get_duration_str
from home.src.ta.settings import EnvironmentSettings
class AggBase:
@ -168,13 +169,22 @@ class DownloadHist(AggBase):
"calendar_interval": "day",
"format": "yyyy-MM-dd",
"order": {"_key": "desc"},
"time_zone": EnvironmentSettings.TZ,
},
"aggs": {
"total_videos": {"value_count": {"field": "youtube_id"}}
"total_videos": {"value_count": {"field": "youtube_id"}},
"media_size": {"sum": {"field": "media_size"}},
},
}
},
"query": {"range": {"date_downloaded": {"gte": "now-7d/d"}}},
"query": {
"range": {
"date_downloaded": {
"gte": "now-7d/d",
"time_zone": EnvironmentSettings.TZ,
}
}
},
}
def process(self):
@ -186,6 +196,7 @@ class DownloadHist(AggBase):
{
"date": i.get("key_as_string"),
"count": i.get("doc_count"),
"media_size": i["media_size"].get("value"),
}
for i in buckets
]

View File

@ -241,7 +241,9 @@ function buildDailyStat(dailyStat) {
text = 'Video';
}
message.innerText = `+${dailyStat.count} ${text}`;
message.innerText =
`+${dailyStat.count} ${text}
${humanFileSize(dailyStat.media_size)}`;
tile.appendChild(message);
return tile;