mirror of
https://github.com/tubearchivist/tubearchivist.git
synced 2024-12-23 02:10:14 +00:00
add biggest chanel aggs
This commit is contained in:
parent
4650963cc7
commit
5ee37eb0cb
@ -211,11 +211,8 @@ class BiggestChannel(AggBase):
|
|||||||
}
|
}
|
||||||
order_choices = ["doc_count", "duration", "media_size"]
|
order_choices = ["doc_count", "duration", "media_size"]
|
||||||
|
|
||||||
def process(self, order_by=False):
|
def process(self):
|
||||||
"""process aggregation"""
|
"""process aggregation, order_by validated in the view"""
|
||||||
|
|
||||||
if order_by and order_by in self.order_choices:
|
|
||||||
self.data["aggs"][self.name]["multi_terms"]["order"] = order_by
|
|
||||||
|
|
||||||
aggregations = self.get()
|
aggregations = self.get()
|
||||||
buckets = aggregations[self.name]["buckets"]
|
buckets = aggregations[self.name]["buckets"]
|
||||||
@ -226,6 +223,9 @@ class BiggestChannel(AggBase):
|
|||||||
"name": i["key"][0].title(),
|
"name": i["key"][0].title(),
|
||||||
"doc_count": i["doc_count"]["value"],
|
"doc_count": i["doc_count"]["value"],
|
||||||
"duration": i["duration"]["value"],
|
"duration": i["duration"]["value"],
|
||||||
|
"duration_str": DurationConverter().get_str(
|
||||||
|
i["duration"]["value"]
|
||||||
|
),
|
||||||
"media_size": i["media_size"]["value"],
|
"media_size": i["media_size"]["value"],
|
||||||
}
|
}
|
||||||
for i in buckets
|
for i in buckets
|
||||||
|
@ -1025,7 +1025,7 @@ class StatBiggestChannel(ApiBaseView):
|
|||||||
def get(self, request):
|
def get(self, request):
|
||||||
"""handle get request"""
|
"""handle get request"""
|
||||||
|
|
||||||
order = request.GET.get("order")
|
order = request.GET.get("order", False)
|
||||||
if order and order not in self.order_choices:
|
if order and order not in self.order_choices:
|
||||||
message = {"message": f"invalid order parameter {order}"}
|
message = {"message": f"invalid order parameter {order}"}
|
||||||
return Response(message, status=400)
|
return Response(message, status=400)
|
||||||
|
@ -12,5 +12,21 @@
|
|||||||
<h2>Watch Progress</h2>
|
<h2>Watch Progress</h2>
|
||||||
<div id="watchBox" class="info-box info-box-3"></div>
|
<div id="watchBox" class="info-box info-box-3"></div>
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
<h2>Biggest Channels</h2>
|
||||||
|
<div class="info-box description-box">
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Videos</th>
|
||||||
|
<th>Duration</th>
|
||||||
|
<th>Media Size</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody id="biggestChannelTable"></tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<script type="text/javascript" src="{% static 'stats.js' %}"></script>
|
<script type="text/javascript" src="{% static 'stats.js' %}"></script>
|
||||||
{% endblock settings_content %}
|
{% endblock settings_content %}
|
||||||
|
@ -82,6 +82,7 @@ ul {
|
|||||||
td, th, span, label {
|
td, th, span, label {
|
||||||
font-family: Sen-Regular, sans-serif;
|
font-family: Sen-Regular, sans-serif;
|
||||||
color: var(--main-font);
|
color: var(--main-font);
|
||||||
|
text-align: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
select, input {
|
select, input {
|
||||||
@ -655,6 +656,10 @@ video:-webkit-full-screen {
|
|||||||
grid-template-columns: 1fr 1fr;
|
grid-template-columns: 1fr 1fr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.info-box-1 {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
|
||||||
.info-box img {
|
.info-box img {
|
||||||
width: 80px;
|
width: 80px;
|
||||||
margin: 0 15px;
|
margin: 0 15px;
|
||||||
|
@ -96,9 +96,37 @@ function buildWatchTile(title, watchDetail) {
|
|||||||
return tile;
|
return tile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function biggestChannel() {
|
||||||
|
let apiEndpoint = '/api/stats/biggestchannels/';
|
||||||
|
let responseData = apiRequest(apiEndpoint, 'GET');
|
||||||
|
let tBody = document.getElementById('biggestChannelTable');
|
||||||
|
for (let i = 0; i < responseData.length; i++) {
|
||||||
|
const channelData = responseData[i];
|
||||||
|
let tableRow = buildChannelRow(channelData);
|
||||||
|
tBody.appendChild(tableRow);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildChannelRow(channelData) {
|
||||||
|
let tableRow = document.createElement('tr');
|
||||||
|
tableRow.innerHTML = `
|
||||||
|
<td><a href="/channel/${channelData.id}/">${channelData.name}</a></td>
|
||||||
|
<td>${channelData.doc_count}</td>
|
||||||
|
<td>${channelData.duration_str}</td>
|
||||||
|
<td>${humanFileSize(channelData.media_size)}</td>
|
||||||
|
`;
|
||||||
|
return tableRow;
|
||||||
|
}
|
||||||
|
|
||||||
|
function humanFileSize(size) {
|
||||||
|
let i = size === 0 ? 0 : Math.floor(Math.log(size) / Math.log(1024));
|
||||||
|
return (size / Math.pow(1024, i)).toFixed(1) * 1 + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i];
|
||||||
|
}
|
||||||
|
|
||||||
function buildStats() {
|
function buildStats() {
|
||||||
primaryStats();
|
primaryStats();
|
||||||
watchStats();
|
watchStats();
|
||||||
|
biggestChannel();
|
||||||
}
|
}
|
||||||
|
|
||||||
buildStats();
|
buildStats();
|
||||||
|
Loading…
Reference in New Issue
Block a user