From 4b3ee78acda326fe76dc60772fea2e8849bdec50 Mon Sep 17 00:00:00 2001 From: Paige Gulley Date: Tue, 10 Sep 2024 15:18:01 -0400 Subject: [PATCH 1/2] hotfix for the date formatting issue --- client.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/client.py b/client.py index 433c90c..304a055 100644 --- a/client.py +++ b/client.py @@ -278,9 +278,22 @@ def aggregator_query( # Add the results of each aggregator to the return value for agg in aggs: agg_name = list(agg.value.keys())[0] - return_dict.update( - {agg_name: self.format_counts(res["aggregations"][agg_name]["buckets"])} - ) + if agg_name == "dailycounts": + return_dict.update( + { + agg_name: self.format_day_counts( + res["aggregations"][agg_name]["buckets"] + ) + } + ) + else: + return_dict.update( + { + agg_name: self.format_counts( + res["aggregations"][agg_name]["buckets"] + ) + } + ) # Only return the total and matches if explicitly requested if "overview" in options: From d32f1d2bb6a856b1da78951bf6a9027c90b79263 Mon Sep 17 00:00:00 2001 From: Paige Gulley Date: Tue, 10 Sep 2024 16:23:47 -0400 Subject: [PATCH 2/2] readability per phil --- client.py | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/client.py b/client.py index 304a055..a095abe 100644 --- a/client.py +++ b/client.py @@ -251,11 +251,11 @@ def format_match(self, hit: dict, collection: str, expanded: bool = False): res["text_extraction"] = src.get("text_extraction") return res - def format_day_counts(self, bucket: list): - return {item["key_as_string"][:10]: item["doc_count"] for item in bucket} - - def format_counts(self, bucket: list): - return {item["key"]: item["doc_count"] for item in bucket} + def format_counts(self, bucket: list, day_counts=False): + if day_counts: + return {item["key_as_string"][:10]: item["doc_count"] for item in bucket} + else: + return {item["key"]: item["doc_count"] for item in bucket} def aggregator_query( self, collection: str, q: str, *aggs: QueryBuilder.Aggregators, **options @@ -278,22 +278,10 @@ def aggregator_query( # Add the results of each aggregator to the return value for agg in aggs: agg_name = list(agg.value.keys())[0] - if agg_name == "dailycounts": - return_dict.update( - { - agg_name: self.format_day_counts( - res["aggregations"][agg_name]["buckets"] - ) - } - ) - else: - return_dict.update( - { - agg_name: self.format_counts( - res["aggregations"][agg_name]["buckets"] - ) - } - ) + return_dict[agg_name] = self.format_counts( + res["aggregations"][agg_name]["buckets"], + day_counts=(agg_name == "dailycounts"), + ) # Only return the total and matches if explicitly requested if "overview" in options: