[API] add download stats
This commit is contained in:
parent
a466c02304
commit
02ac590caa
|
@ -195,6 +195,36 @@ class Playlist(AggBase):
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
class Download(AggBase):
|
||||||
|
"""get downloads queue stats"""
|
||||||
|
|
||||||
|
name = "download_queue_stats"
|
||||||
|
path = "ta_download/_search"
|
||||||
|
data = {
|
||||||
|
"size": 0,
|
||||||
|
"aggs": {
|
||||||
|
"status": {"terms": {"field": "status"}},
|
||||||
|
"video_type": {
|
||||||
|
"filter": {"term": {"status": "pending"}},
|
||||||
|
"aggs": {"type_pending": {"terms": {"field": "vid_type"}}},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
def process(self):
|
||||||
|
"""process aggregation"""
|
||||||
|
aggregations = self.get()
|
||||||
|
response = {}
|
||||||
|
for bucket in aggregations["status"]["buckets"]:
|
||||||
|
response.update({bucket["key"]: bucket.get("doc_count")})
|
||||||
|
|
||||||
|
for bucket in aggregations["video_type"]["type_pending"]["buckets"]:
|
||||||
|
key = f"pending_{bucket['key']}"
|
||||||
|
response.update({key: bucket.get("doc_count")})
|
||||||
|
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
class WatchProgress(AggBase):
|
class WatchProgress(AggBase):
|
||||||
"""get watch progress"""
|
"""get watch progress"""
|
||||||
|
|
||||||
|
|
|
@ -166,6 +166,11 @@ urlpatterns = [
|
||||||
views.StatPlaylistView.as_view(),
|
views.StatPlaylistView.as_view(),
|
||||||
name="api-stats-playlist",
|
name="api-stats-playlist",
|
||||||
),
|
),
|
||||||
|
path(
|
||||||
|
"stats/download/",
|
||||||
|
views.StatDownloadView.as_view(),
|
||||||
|
name="api-stats-download",
|
||||||
|
),
|
||||||
path(
|
path(
|
||||||
"stats/watch/",
|
"stats/watch/",
|
||||||
views.StatWatchProgress.as_view(),
|
views.StatWatchProgress.as_view(),
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
from api.src.aggs import (
|
from api.src.aggs import (
|
||||||
BiggestChannel,
|
BiggestChannel,
|
||||||
Channel,
|
Channel,
|
||||||
|
Download,
|
||||||
DownloadHist,
|
DownloadHist,
|
||||||
Playlist,
|
Playlist,
|
||||||
Video,
|
Video,
|
||||||
|
@ -1184,6 +1185,18 @@ class StatPlaylistView(ApiBaseView):
|
||||||
return Response(Playlist().process())
|
return Response(Playlist().process())
|
||||||
|
|
||||||
|
|
||||||
|
class StatDownloadView(ApiBaseView):
|
||||||
|
"""resolves to /api/stats/download/
|
||||||
|
GET: return download stats
|
||||||
|
"""
|
||||||
|
|
||||||
|
def get(self, request):
|
||||||
|
"""get stats"""
|
||||||
|
# pylint: disable=unused-argument
|
||||||
|
|
||||||
|
return Response(Download().process())
|
||||||
|
|
||||||
|
|
||||||
class StatWatchProgress(ApiBaseView):
|
class StatWatchProgress(ApiBaseView):
|
||||||
"""resolves to /api/stats/watchprogress/
|
"""resolves to /api/stats/watchprogress/
|
||||||
GET: return watch/unwatch progress stats
|
GET: return watch/unwatch progress stats
|
||||||
|
|
Loading…
Reference in New Issue