mirror of
https://github.com/tubearchivist/tubearchivist.git
synced 2025-05-11 05:41:09 +00:00
split stats app
This commit is contained in:
parent
52ac5285b9
commit
adcd4f9245
@ -31,39 +31,4 @@ urlpatterns = [
|
|||||||
views.NotificationView.as_view(),
|
views.NotificationView.as_view(),
|
||||||
name="api-notification",
|
name="api-notification",
|
||||||
),
|
),
|
||||||
path(
|
|
||||||
"stats/video/",
|
|
||||||
views.StatVideoView.as_view(),
|
|
||||||
name="api-stats-video",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"stats/channel/",
|
|
||||||
views.StatChannelView.as_view(),
|
|
||||||
name="api-stats-channel",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"stats/playlist/",
|
|
||||||
views.StatPlaylistView.as_view(),
|
|
||||||
name="api-stats-playlist",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"stats/download/",
|
|
||||||
views.StatDownloadView.as_view(),
|
|
||||||
name="api-stats-download",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"stats/watch/",
|
|
||||||
views.StatWatchProgress.as_view(),
|
|
||||||
name="api-stats-watch",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"stats/downloadhist/",
|
|
||||||
views.StatDownloadHist.as_view(),
|
|
||||||
name="api-stats-downloadhist",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"stats/biggestchannels/",
|
|
||||||
views.StatBiggestChannel.as_view(),
|
|
||||||
name="api-stats-biggestchannels",
|
|
||||||
),
|
|
||||||
]
|
]
|
||||||
|
@ -1,14 +1,5 @@
|
|||||||
"""all API views"""
|
"""all API views"""
|
||||||
|
|
||||||
from api.src.aggs import (
|
|
||||||
BiggestChannel,
|
|
||||||
Channel,
|
|
||||||
Download,
|
|
||||||
DownloadHist,
|
|
||||||
Playlist,
|
|
||||||
Video,
|
|
||||||
WatchProgress,
|
|
||||||
)
|
|
||||||
from api.src.search_processor import SearchProcess
|
from api.src.search_processor import SearchProcess
|
||||||
from appsettings.src.reindex import ReindexProgress
|
from appsettings.src.reindex import ReindexProgress
|
||||||
from home.src.es.connect import ElasticWrap
|
from home.src.es.connect import ElasticWrap
|
||||||
@ -283,94 +274,3 @@ class NotificationView(ApiBaseView):
|
|||||||
query = f"{query}:{filter_by}"
|
query = f"{query}:{filter_by}"
|
||||||
|
|
||||||
return Response(RedisArchivist().list_items(query))
|
return Response(RedisArchivist().list_items(query))
|
||||||
|
|
||||||
|
|
||||||
class StatVideoView(ApiBaseView):
|
|
||||||
"""resolves to /api/stats/video/
|
|
||||||
GET: return video stats
|
|
||||||
"""
|
|
||||||
|
|
||||||
def get(self, request):
|
|
||||||
"""get stats"""
|
|
||||||
# pylint: disable=unused-argument
|
|
||||||
|
|
||||||
return Response(Video().process())
|
|
||||||
|
|
||||||
|
|
||||||
class StatChannelView(ApiBaseView):
|
|
||||||
"""resolves to /api/stats/channel/
|
|
||||||
GET: return channel stats
|
|
||||||
"""
|
|
||||||
|
|
||||||
def get(self, request):
|
|
||||||
"""get stats"""
|
|
||||||
# pylint: disable=unused-argument
|
|
||||||
|
|
||||||
return Response(Channel().process())
|
|
||||||
|
|
||||||
|
|
||||||
class StatPlaylistView(ApiBaseView):
|
|
||||||
"""resolves to /api/stats/playlist/
|
|
||||||
GET: return playlist stats
|
|
||||||
"""
|
|
||||||
|
|
||||||
def get(self, request):
|
|
||||||
"""get stats"""
|
|
||||||
# pylint: disable=unused-argument
|
|
||||||
|
|
||||||
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):
|
|
||||||
"""resolves to /api/stats/watchprogress/
|
|
||||||
GET: return watch/unwatch progress stats
|
|
||||||
"""
|
|
||||||
|
|
||||||
def get(self, request):
|
|
||||||
"""handle get request"""
|
|
||||||
# pylint: disable=unused-argument
|
|
||||||
|
|
||||||
return Response(WatchProgress().process())
|
|
||||||
|
|
||||||
|
|
||||||
class StatDownloadHist(ApiBaseView):
|
|
||||||
"""resolves to /api/stats/downloadhist/
|
|
||||||
GET: return download video count histogram for last days
|
|
||||||
"""
|
|
||||||
|
|
||||||
def get(self, request):
|
|
||||||
"""handle get request"""
|
|
||||||
# pylint: disable=unused-argument
|
|
||||||
|
|
||||||
return Response(DownloadHist().process())
|
|
||||||
|
|
||||||
|
|
||||||
class StatBiggestChannel(ApiBaseView):
|
|
||||||
"""resolves to /api/stats/biggestchannels/
|
|
||||||
GET: return biggest channels
|
|
||||||
param: order
|
|
||||||
"""
|
|
||||||
|
|
||||||
order_choices = ["doc_count", "duration", "media_size"]
|
|
||||||
|
|
||||||
def get(self, request):
|
|
||||||
"""handle get request"""
|
|
||||||
|
|
||||||
order = request.GET.get("order", "doc_count")
|
|
||||||
if order and order not in self.order_choices:
|
|
||||||
message = {"message": f"invalid order parameter {order}"}
|
|
||||||
return Response(message, status=400)
|
|
||||||
|
|
||||||
return Response(BiggestChannel(order).process())
|
|
||||||
|
@ -68,6 +68,7 @@ INSTALLED_APPS = [
|
|||||||
"download",
|
"download",
|
||||||
"task",
|
"task",
|
||||||
"appsettings",
|
"appsettings",
|
||||||
|
"stats",
|
||||||
"config",
|
"config",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -26,5 +26,6 @@ urlpatterns = [
|
|||||||
path("api/download/", include("download.urls")),
|
path("api/download/", include("download.urls")),
|
||||||
path("api/task/", include("task.urls")),
|
path("api/task/", include("task.urls")),
|
||||||
path("api/appsettings/", include("appsettings.urls")),
|
path("api/appsettings/", include("appsettings.urls")),
|
||||||
|
path("api/stats/", include("stats.urls")),
|
||||||
path("admin/", admin.site.urls),
|
path("admin/", admin.site.urls),
|
||||||
]
|
]
|
||||||
|
0
tubearchivist/stats/__init__.py
Normal file
0
tubearchivist/stats/__init__.py
Normal file
0
tubearchivist/stats/migrations/__init__.py
Normal file
0
tubearchivist/stats/migrations/__init__.py
Normal file
0
tubearchivist/stats/src/__init__.py
Normal file
0
tubearchivist/stats/src/__init__.py
Normal file
42
tubearchivist/stats/urls.py
Normal file
42
tubearchivist/stats/urls.py
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
"""all stats API urls"""
|
||||||
|
|
||||||
|
from django.urls import path
|
||||||
|
from stats import views
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path(
|
||||||
|
"video/",
|
||||||
|
views.StatVideoView.as_view(),
|
||||||
|
name="api-stats-video",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"channel/",
|
||||||
|
views.StatChannelView.as_view(),
|
||||||
|
name="api-stats-channel",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"playlist/",
|
||||||
|
views.StatPlaylistView.as_view(),
|
||||||
|
name="api-stats-playlist",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"download/",
|
||||||
|
views.StatDownloadView.as_view(),
|
||||||
|
name="api-stats-download",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"watch/",
|
||||||
|
views.StatWatchProgress.as_view(),
|
||||||
|
name="api-stats-watch",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"downloadhist/",
|
||||||
|
views.StatDownloadHist.as_view(),
|
||||||
|
name="api-stats-downloadhist",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"biggestchannels/",
|
||||||
|
views.StatBiggestChannel.as_view(),
|
||||||
|
name="api-stats-biggestchannels",
|
||||||
|
),
|
||||||
|
]
|
104
tubearchivist/stats/views.py
Normal file
104
tubearchivist/stats/views.py
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
"""all stats API views"""
|
||||||
|
|
||||||
|
from api.views import ApiBaseView
|
||||||
|
from rest_framework.response import Response
|
||||||
|
from stats.src.aggs import (
|
||||||
|
BiggestChannel,
|
||||||
|
Channel,
|
||||||
|
Download,
|
||||||
|
DownloadHist,
|
||||||
|
Playlist,
|
||||||
|
Video,
|
||||||
|
WatchProgress,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class StatVideoView(ApiBaseView):
|
||||||
|
"""resolves to /api/stats/video/
|
||||||
|
GET: return video stats
|
||||||
|
"""
|
||||||
|
|
||||||
|
def get(self, request):
|
||||||
|
"""get stats"""
|
||||||
|
# pylint: disable=unused-argument
|
||||||
|
|
||||||
|
return Response(Video().process())
|
||||||
|
|
||||||
|
|
||||||
|
class StatChannelView(ApiBaseView):
|
||||||
|
"""resolves to /api/stats/channel/
|
||||||
|
GET: return channel stats
|
||||||
|
"""
|
||||||
|
|
||||||
|
def get(self, request):
|
||||||
|
"""get stats"""
|
||||||
|
# pylint: disable=unused-argument
|
||||||
|
|
||||||
|
return Response(Channel().process())
|
||||||
|
|
||||||
|
|
||||||
|
class StatPlaylistView(ApiBaseView):
|
||||||
|
"""resolves to /api/stats/playlist/
|
||||||
|
GET: return playlist stats
|
||||||
|
"""
|
||||||
|
|
||||||
|
def get(self, request):
|
||||||
|
"""get stats"""
|
||||||
|
# pylint: disable=unused-argument
|
||||||
|
|
||||||
|
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):
|
||||||
|
"""resolves to /api/stats/watchprogress/
|
||||||
|
GET: return watch/unwatch progress stats
|
||||||
|
"""
|
||||||
|
|
||||||
|
def get(self, request):
|
||||||
|
"""handle get request"""
|
||||||
|
# pylint: disable=unused-argument
|
||||||
|
|
||||||
|
return Response(WatchProgress().process())
|
||||||
|
|
||||||
|
|
||||||
|
class StatDownloadHist(ApiBaseView):
|
||||||
|
"""resolves to /api/stats/downloadhist/
|
||||||
|
GET: return download video count histogram for last days
|
||||||
|
"""
|
||||||
|
|
||||||
|
def get(self, request):
|
||||||
|
"""handle get request"""
|
||||||
|
# pylint: disable=unused-argument
|
||||||
|
|
||||||
|
return Response(DownloadHist().process())
|
||||||
|
|
||||||
|
|
||||||
|
class StatBiggestChannel(ApiBaseView):
|
||||||
|
"""resolves to /api/stats/biggestchannels/
|
||||||
|
GET: return biggest channels
|
||||||
|
param: order
|
||||||
|
"""
|
||||||
|
|
||||||
|
order_choices = ["doc_count", "duration", "media_size"]
|
||||||
|
|
||||||
|
def get(self, request):
|
||||||
|
"""handle get request"""
|
||||||
|
|
||||||
|
order = request.GET.get("order", "doc_count")
|
||||||
|
if order and order not in self.order_choices:
|
||||||
|
message = {"message": f"invalid order parameter {order}"}
|
||||||
|
return Response(message, status=400)
|
||||||
|
|
||||||
|
return Response(BiggestChannel(order).process())
|
Loading…
x
Reference in New Issue
Block a user