From 77fef5de57b213cf57b6f09ed7a774bbbb0dc9cc Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 25 Sep 2023 14:53:12 +0700 Subject: [PATCH] fix standard duration str agg --- tubearchivist/api/src/search_processor.py | 14 +++++++++++++- tubearchivist/home/views.py | 3 ++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/tubearchivist/api/src/search_processor.py b/tubearchivist/api/src/search_processor.py index 7c9d28e..232474d 100644 --- a/tubearchivist/api/src/search_processor.py +++ b/tubearchivist/api/src/search_processor.py @@ -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)} + ) diff --git a/tubearchivist/home/views.py b/tubearchivist/home/views.py index f5c771d..c9227c4 100644 --- a/tubearchivist/home/views.py +++ b/tubearchivist/home/views.py @@ -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)