[API] add video aggregation
This commit is contained in:
parent
4a145ee7cb
commit
91bb0ed9c0
|
@ -84,6 +84,58 @@ class Primary(AggBase):
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
class Video(AggBase):
|
||||||
|
"""get video stats"""
|
||||||
|
|
||||||
|
name = "video_stats"
|
||||||
|
path = "ta_video/_search"
|
||||||
|
data = {
|
||||||
|
"size": 0,
|
||||||
|
"aggs": {
|
||||||
|
"video_type": {
|
||||||
|
"terms": {"field": "vid_type"},
|
||||||
|
"aggs": {"media_size": {"sum": {"field": "media_size"}}},
|
||||||
|
},
|
||||||
|
"video_active": {
|
||||||
|
"terms": {"field": "active"},
|
||||||
|
"aggs": {"media_size": {"sum": {"field": "media_size"}}},
|
||||||
|
},
|
||||||
|
"video_media_size": {"sum": {"field": "media_size"}},
|
||||||
|
"video_count": {"value_count": {"field": "youtube_id"}},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
def process(self):
|
||||||
|
"""process aggregation"""
|
||||||
|
aggregations = self.get()
|
||||||
|
|
||||||
|
response = {
|
||||||
|
"doc_count": aggregations["video_count"]["value"],
|
||||||
|
"media_size": int(aggregations["video_media_size"]["value"]),
|
||||||
|
}
|
||||||
|
for bucket in aggregations["video_type"]["buckets"]:
|
||||||
|
response.update(
|
||||||
|
{
|
||||||
|
f"type_{bucket['key']}": {
|
||||||
|
"doc_count": bucket.get("doc_count"),
|
||||||
|
"media_size": int(bucket["media_size"].get("value")),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
for bucket in aggregations["video_active"]["buckets"]:
|
||||||
|
response.update(
|
||||||
|
{
|
||||||
|
f"active_{bucket['key_as_string']}": {
|
||||||
|
"doc_count": bucket.get("doc_count"),
|
||||||
|
"media_size": int(bucket["media_size"].get("value")),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
class WatchProgress(AggBase):
|
class WatchProgress(AggBase):
|
||||||
"""get watch progress"""
|
"""get watch progress"""
|
||||||
|
|
||||||
|
|
|
@ -152,9 +152,9 @@ urlpatterns = [
|
||||||
name="api-notification",
|
name="api-notification",
|
||||||
),
|
),
|
||||||
path(
|
path(
|
||||||
"stats/primary/",
|
"stats/video/",
|
||||||
views.StatPrimaryView.as_view(),
|
views.StatVideoView.as_view(),
|
||||||
name="api-stats-primary",
|
name="api-stats-video",
|
||||||
),
|
),
|
||||||
path(
|
path(
|
||||||
"stats/watch/",
|
"stats/watch/",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
"""all API views"""
|
"""all API views"""
|
||||||
|
|
||||||
from api.src.aggs import BiggestChannel, DownloadHist, Primary, WatchProgress
|
from api.src.aggs import BiggestChannel, DownloadHist, Video, WatchProgress
|
||||||
from api.src.search_processor import SearchProcess
|
from api.src.search_processor import SearchProcess
|
||||||
from home.src.download.queue import PendingInteract
|
from home.src.download.queue import PendingInteract
|
||||||
from home.src.download.subscriptions import (
|
from home.src.download.subscriptions import (
|
||||||
|
@ -1141,16 +1141,16 @@ class NotificationView(ApiBaseView):
|
||||||
return Response(RedisArchivist().list_items(query))
|
return Response(RedisArchivist().list_items(query))
|
||||||
|
|
||||||
|
|
||||||
class StatPrimaryView(ApiBaseView):
|
class StatVideoView(ApiBaseView):
|
||||||
"""resolves to /api/stats/primary/
|
"""resolves to /api/stats/video/
|
||||||
GET: return document count
|
GET: return video stats
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
"""get stats"""
|
"""get stats"""
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
|
|
||||||
return Response(Primary().process())
|
return Response(Video().process())
|
||||||
|
|
||||||
|
|
||||||
class StatWatchProgress(ApiBaseView):
|
class StatWatchProgress(ApiBaseView):
|
||||||
|
|
Loading…
Reference in New Issue