fix standard duration str agg

This commit is contained in:
Simon 2023-09-25 14:53:12 +07:00
parent 9d09d27fba
commit 77fef5de57
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
2 changed files with 15 additions and 2 deletions

View File

@ -8,7 +8,7 @@ import urllib.parse
from home.src.download.thumbnails import ThumbManager
from home.src.ta.config import AppConfig
from home.src.ta.helper import date_praser
from home.src.ta.helper import date_praser, get_duration_str
class SearchProcess:
@ -163,3 +163,15 @@ class SearchProcess:
subtitle_dict.update({"vid_thumb_url": f"/cache/{thumb_path}"})
return subtitle_dict
def process_aggs(response):
"""convert aggs duration to str"""
if response.get("aggregations"):
aggs = response["aggregations"]
if "total_duration" in aggs:
duration_sec = int(aggs["total_duration"]["value"])
aggs["total_duration"].update(
{"value_str": get_duration_str(duration_sec)}
)

View File

@ -8,7 +8,7 @@ import json
import urllib.parse
from time import sleep
from api.src.search_processor import SearchProcess
from api.src.search_processor import SearchProcess, process_aggs
from django.conf import settings
from django.contrib.auth import login
from django.contrib.auth.forms import AuthenticationForm
@ -200,6 +200,7 @@ class ArchivistResultsView(ArchivistViewConfig):
def find_results(self):
"""add results and pagination to context"""
response, _ = ElasticWrap(self.es_search).get(self.data)
process_aggs(response)
results = SearchProcess(response).process()
max_hits = response["hits"]["total"]["value"]
self.pagination_handler.validate(max_hits)