From ef8de83337ea224fd105818dcc27fb126a5ed1c2 Mon Sep 17 00:00:00 2001 From: AlanJaeger Date: Thu, 27 Jun 2024 09:13:13 -0300 Subject: [PATCH 01/15] feature: adding timezone and live filters --- .../dashboards/usecases/dashboard_creation.py | 6 ++- insights/widgets/usecases/get_source_data.py | 41 ++++++++++++++++--- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/insights/dashboards/usecases/dashboard_creation.py b/insights/dashboards/usecases/dashboard_creation.py index 5a423e4..674ebe6 100644 --- a/insights/dashboards/usecases/dashboard_creation.py +++ b/insights/dashboards/usecases/dashboard_creation.py @@ -37,6 +37,7 @@ def create_widgets(self, dashboard_atendimento_humano): config={ "limit": 12, "operation": "timeseries_hour_group_count", + "filter": {"created_on__gte": "now"}, }, dashboard=dashboard_atendimento_humano, position={"rows": [1, 1], "columns": [1, 12]}, @@ -61,6 +62,7 @@ def create_widgets(self, dashboard_atendimento_humano): "operation": "avg", "type_result": "executions", "op_field": "waiting_time", + "filter": {"created_on__gte": "now"}, }, dashboard=dashboard_atendimento_humano, position={"rows": [3, 3], "columns": [5, 8]}, @@ -72,7 +74,7 @@ def create_widgets(self, dashboard_atendimento_humano): config={ "operation": "count", "type_result": "executions", - "filter": {"is_active": False}, + "filter": {"is_active": False, "created_on__gte": "now"}, }, dashboard=dashboard_atendimento_humano, position={"rows": [2, 2], "columns": [9, 12]}, @@ -85,6 +87,7 @@ def create_widgets(self, dashboard_atendimento_humano): "operation": "avg", "type_result": "executions", "op_field": "message_response_time", + "filter": {"created_on__gte": "now"}, }, dashboard=dashboard_atendimento_humano, position={"rows": [3, 3], "columns": [1, 4]}, @@ -112,6 +115,7 @@ def create_widgets(self, dashboard_atendimento_humano): "operation": "avg", "type_result": "executions", "op_field": "interaction_time", + "filter": {"created_on__gte": "now"}, }, dashboard=dashboard_atendimento_humano, position={"rows": [3, 3], "columns": [9, 12]}, diff --git a/insights/widgets/usecases/get_source_data.py b/insights/widgets/usecases/get_source_data.py index 9a9ad4b..5cce626 100644 --- a/insights/widgets/usecases/get_source_data.py +++ b/insights/widgets/usecases/get_source_data.py @@ -2,6 +2,33 @@ from insights.shared.viewsets import get_source from insights.widgets.models import Widget +from datetime import datetime, time +import pytz +from django.utils.timezone import now, make_aware + + +def set_live_day(default_filters: dict, tz): + start_of_day = make_aware( + datetime.combine(now().date(), datetime.min.time()), timezone=tz + ) + default_filters["created_on__gte"] = start_of_day + + +def apply_timezone_to_date_filters(default_filters: dict, timezone: str): + tz = pytz.timezone(timezone) + date_suffixes = ["__gte", "__lte"] + + if default_filters.get("created_on__gte") == "now": + set_live_day(default_filters, tz) + + for key, value in default_filters.items(): + if any(key.endswith(suffix) for suffix in date_suffixes): + if isinstance(value, str): + date_value = datetime.strptime(value, "%Y-%m-%d") + default_filters[key] = tz.localize(date_value) + elif isinstance(value, datetime): + default_filters[key] = tz.localize(value) + def get_source_data_from_widget( widget: Widget, is_report: bool = False, filters: dict = {}, user_email: str = "" @@ -19,13 +46,17 @@ def get_source_data_from_widget( default_filters, operation, op_field, limit = widget.source_config( sub_widget=filters.pop("slug", [None])[0] - ) # implement a dynamic handler for each widget + ) + + default_filters.update(filters) + + project_timezone = widget.project.timezone + apply_timezone_to_date_filters(default_filters, project_timezone) - filters.update(default_filters) if operation == "list": - tags = filters.pop("tags", [None])[0] + tags = default_filters.pop("tags", [None])[0] if tags: - filters["tags"] = tags.split(",") + default_filters["tags"] = tags.split(",") if op_field: query_kwargs["field_name"] = op_field @@ -33,7 +64,7 @@ def get_source_data_from_widget( query_kwargs["limit"] = limit serialized_source = SourceQuery.execute( - filters=filters, + filters=default_filters, operation=operation, parser=parse_dict_to_json, project=widget.project, From 1a23034ee3a58643efdbf3527fcfddc09f7d3d2e Mon Sep 17 00:00:00 2001 From: AlanJaeger Date: Thu, 27 Jun 2024 09:45:23 -0300 Subject: [PATCH 02/15] feat: adding pytz package --- poetry.lock | 15 +++++++++++++-- pyproject.toml | 1 + 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/poetry.lock b/poetry.lock index 2c323aa..b2fcbb7 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.7.1 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.2 and should not be changed by hand. [[package]] name = "amqp" @@ -1371,6 +1371,17 @@ files = [ [package.dependencies] six = ">=1.5" +[[package]] +name = "pytz" +version = "2024.1" +description = "World timezone definitions, modern and historical" +optional = false +python-versions = "*" +files = [ + {file = "pytz-2024.1-py2.py3-none-any.whl", hash = "sha256:328171f4e3623139da4983451950b28e95ac706e13f3f2630a879749e7a8b319"}, + {file = "pytz-2024.1.tar.gz", hash = "sha256:2a29735ea9c18baf14b448846bde5a48030ed267578472d8955cd0e7443a9812"}, +] + [[package]] name = "pyyaml" version = "6.0.1" @@ -1890,4 +1901,4 @@ testing = ["coverage (>=5.0.3)", "zope.event", "zope.testing"] [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "1827011f504a8f612340ca5356f2eebedfe368687281347473ea8fc15cb58257" +content-hash = "dcaa38fcc01159992d7c6525a830c15f18b89876de38de19d4ff6d0885674d4a" diff --git a/pyproject.toml b/pyproject.toml index b0b0344..7086ba4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,6 +24,7 @@ sentry-sdk = "^1.44.0" gunicorn = "^22.0.0" drf-spectacular = "^0.27.2" django-filter = "^24.2" +pytz = "^2024.1" [tool.poetry.group.dev.dependencies] ipython = "^8.22.2" From e9d2b69ec3a1014ae378c08a7cf7f92bc30dc58b Mon Sep 17 00:00:00 2001 From: AlanJaeger Date: Thu, 27 Jun 2024 10:04:14 -0300 Subject: [PATCH 03/15] feat: removing redundance when setting timezone --- insights/widgets/usecases/get_source_data.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/insights/widgets/usecases/get_source_data.py b/insights/widgets/usecases/get_source_data.py index 5cce626..f4bb8f9 100644 --- a/insights/widgets/usecases/get_source_data.py +++ b/insights/widgets/usecases/get_source_data.py @@ -7,10 +7,8 @@ from django.utils.timezone import now, make_aware -def set_live_day(default_filters: dict, tz): - start_of_day = make_aware( - datetime.combine(now().date(), datetime.min.time()), timezone=tz - ) +def set_live_day(default_filters: dict): + start_of_day = datetime.combine(now().date(), time.min) default_filters["created_on__gte"] = start_of_day @@ -19,7 +17,7 @@ def apply_timezone_to_date_filters(default_filters: dict, timezone: str): date_suffixes = ["__gte", "__lte"] if default_filters.get("created_on__gte") == "now": - set_live_day(default_filters, tz) + set_live_day(default_filters) for key, value in default_filters.items(): if any(key.endswith(suffix) for suffix in date_suffixes): From 2884563e05175971d52ee6f137fa92b2882ec42b Mon Sep 17 00:00:00 2001 From: AlanJaeger Date: Thu, 27 Jun 2024 11:39:49 -0300 Subject: [PATCH 04/15] feat:updating in subvalue key of default_filters dict --- insights/widgets/usecases/get_source_data.py | 21 +++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/insights/widgets/usecases/get_source_data.py b/insights/widgets/usecases/get_source_data.py index f4bb8f9..48de200 100644 --- a/insights/widgets/usecases/get_source_data.py +++ b/insights/widgets/usecases/get_source_data.py @@ -8,24 +8,27 @@ def set_live_day(default_filters: dict): - start_of_day = datetime.combine(now().date(), time.min) - default_filters["created_on__gte"] = start_of_day + start_of_day = datetime.combine(datetime.now().date(), datetime.min.time()) + default_filters.setdefault("filter", {})["created_on__gte"] = start_of_day def apply_timezone_to_date_filters(default_filters: dict, timezone: str): tz = pytz.timezone(timezone) date_suffixes = ["__gte", "__lte"] - if default_filters.get("created_on__gte") == "now": + if default_filters["filter"].get("created_on__gte") == "now": set_live_day(default_filters) for key, value in default_filters.items(): - if any(key.endswith(suffix) for suffix in date_suffixes): - if isinstance(value, str): - date_value = datetime.strptime(value, "%Y-%m-%d") - default_filters[key] = tz.localize(date_value) - elif isinstance(value, datetime): - default_filters[key] = tz.localize(value) + if isinstance(value, dict): + for subkey, subvalue in value.items(): + if subkey.endswith(tuple(date_suffixes)): + if isinstance(subvalue, str): + date_value = datetime.strptime(subvalue, "%Y-%m-%d") + elif isinstance(subvalue, datetime): + date_value = subvalue + + default_filters[key][subkey] = tz.localize(date_value) def get_source_data_from_widget( From 796f0da77e6218b29d9413cb82125754cc741f61 Mon Sep 17 00:00:00 2001 From: AlanJaeger Date: Thu, 27 Jun 2024 16:02:23 -0300 Subject: [PATCH 05/15] feat: changing now to today --- .../dashboards/usecases/dashboard_creation.py | 10 ++--- insights/widgets/usecases/get_source_data.py | 38 +++++++++---------- 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/insights/dashboards/usecases/dashboard_creation.py b/insights/dashboards/usecases/dashboard_creation.py index 674ebe6..2d20108 100644 --- a/insights/dashboards/usecases/dashboard_creation.py +++ b/insights/dashboards/usecases/dashboard_creation.py @@ -37,7 +37,7 @@ def create_widgets(self, dashboard_atendimento_humano): config={ "limit": 12, "operation": "timeseries_hour_group_count", - "filter": {"created_on__gte": "now"}, + "filter": {"created_on__gte": "today"}, }, dashboard=dashboard_atendimento_humano, position={"rows": [1, 1], "columns": [1, 12]}, @@ -62,7 +62,7 @@ def create_widgets(self, dashboard_atendimento_humano): "operation": "avg", "type_result": "executions", "op_field": "waiting_time", - "filter": {"created_on__gte": "now"}, + "filter": {"created_on__gte": "today"}, }, dashboard=dashboard_atendimento_humano, position={"rows": [3, 3], "columns": [5, 8]}, @@ -74,7 +74,7 @@ def create_widgets(self, dashboard_atendimento_humano): config={ "operation": "count", "type_result": "executions", - "filter": {"is_active": False, "created_on__gte": "now"}, + "filter": {"is_active": False, "ended_at__gte": "today"}, }, dashboard=dashboard_atendimento_humano, position={"rows": [2, 2], "columns": [9, 12]}, @@ -87,7 +87,7 @@ def create_widgets(self, dashboard_atendimento_humano): "operation": "avg", "type_result": "executions", "op_field": "message_response_time", - "filter": {"created_on__gte": "now"}, + "filter": {"created_on__gte": "today"}, }, dashboard=dashboard_atendimento_humano, position={"rows": [3, 3], "columns": [1, 4]}, @@ -115,7 +115,7 @@ def create_widgets(self, dashboard_atendimento_humano): "operation": "avg", "type_result": "executions", "op_field": "interaction_time", - "filter": {"created_on__gte": "now"}, + "filter": {"created_on__gte": "today"}, }, dashboard=dashboard_atendimento_humano, position={"rows": [3, 3], "columns": [9, 12]}, diff --git a/insights/widgets/usecases/get_source_data.py b/insights/widgets/usecases/get_source_data.py index 48de200..7892cac 100644 --- a/insights/widgets/usecases/get_source_data.py +++ b/insights/widgets/usecases/get_source_data.py @@ -1,34 +1,32 @@ +from datetime import datetime, time + +import pytz + from insights.projects.parsers import parse_dict_to_json from insights.shared.viewsets import get_source from insights.widgets.models import Widget -from datetime import datetime, time -import pytz -from django.utils.timezone import now, make_aware - -def set_live_day(default_filters: dict): - start_of_day = datetime.combine(datetime.now().date(), datetime.min.time()) - default_filters.setdefault("filter", {})["created_on__gte"] = start_of_day +def set_live_day(default_filters: dict, key: str): + start_of_day = datetime.combine(datetime.now().date(), time.min) + default_filters[key] = start_of_day def apply_timezone_to_date_filters(default_filters: dict, timezone: str): tz = pytz.timezone(timezone) date_suffixes = ["__gte", "__lte"] - if default_filters["filter"].get("created_on__gte") == "now": - set_live_day(default_filters) - - for key, value in default_filters.items(): - if isinstance(value, dict): - for subkey, subvalue in value.items(): - if subkey.endswith(tuple(date_suffixes)): - if isinstance(subvalue, str): - date_value = datetime.strptime(subvalue, "%Y-%m-%d") - elif isinstance(subvalue, datetime): - date_value = subvalue - - default_filters[key][subkey] = tz.localize(date_value) + for key, value in list(default_filters.items()): + if any(key.endswith(suffix) for suffix in date_suffixes): + if value == "today": + set_live_day(default_filters, key) + value = default_filters[key] + + if isinstance(value, str): + date_value = datetime.strptime(value, "%Y-%m-%d") + default_filters[key] = tz.localize(date_value) + elif isinstance(value, datetime): + default_filters[key] = tz.localize(value) def get_source_data_from_widget( From d5cc24273f190ee5fae64f7b0b47cb2f9dafdd9d Mon Sep 17 00:00:00 2001 From: AlanJaeger Date: Thu, 27 Jun 2024 23:08:43 -0300 Subject: [PATCH 06/15] feature: verify filters --- insights/widgets/usecases/get_source_data.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/insights/widgets/usecases/get_source_data.py b/insights/widgets/usecases/get_source_data.py index 7892cac..da088ce 100644 --- a/insights/widgets/usecases/get_source_data.py +++ b/insights/widgets/usecases/get_source_data.py @@ -7,6 +7,14 @@ from insights.widgets.models import Widget +def verify_filters(filters: dict): + if "created_on__gte" in filters.get( + "filter", {} + ) and "created_on__lte" in filters.get("filter", {}): + if "ended_at__gte" in filters.get("filter", {}): + del filters["filter"]["ended_at__gte"] + + def set_live_day(default_filters: dict, key: str): start_of_day = datetime.combine(datetime.now().date(), time.min) default_filters[key] = start_of_day @@ -47,6 +55,7 @@ def get_source_data_from_widget( sub_widget=filters.pop("slug", [None])[0] ) + verify_filters(filters) default_filters.update(filters) project_timezone = widget.project.timezone From a7b67b2b8678a804415f7873e3746b7d6e626d08 Mon Sep 17 00:00:00 2001 From: AlanJaeger Date: Thu, 27 Jun 2024 23:09:40 -0300 Subject: [PATCH 07/15] feature: print to debug --- insights/widgets/usecases/get_source_data.py | 1 + 1 file changed, 1 insertion(+) diff --git a/insights/widgets/usecases/get_source_data.py b/insights/widgets/usecases/get_source_data.py index da088ce..ace9e54 100644 --- a/insights/widgets/usecases/get_source_data.py +++ b/insights/widgets/usecases/get_source_data.py @@ -8,6 +8,7 @@ def verify_filters(filters: dict): + print("filtros", filters) if "created_on__gte" in filters.get( "filter", {} ) and "created_on__lte" in filters.get("filter", {}): From 0ab06bfcc285e422bfd7c3be3128976d244f973b Mon Sep 17 00:00:00 2001 From: AlanJaeger Date: Thu, 27 Jun 2024 23:29:53 -0300 Subject: [PATCH 08/15] feature: print to debug --- insights/widgets/usecases/get_source_data.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/insights/widgets/usecases/get_source_data.py b/insights/widgets/usecases/get_source_data.py index ace9e54..37f5337 100644 --- a/insights/widgets/usecases/get_source_data.py +++ b/insights/widgets/usecases/get_source_data.py @@ -7,13 +7,13 @@ from insights.widgets.models import Widget -def verify_filters(filters: dict): - print("filtros", filters) - if "created_on__gte" in filters.get( +def verify_filters(default_filters: dict): + print("filtros", default_filters) + if "created_on__gte" in default_filters.get( "filter", {} - ) and "created_on__lte" in filters.get("filter", {}): - if "ended_at__gte" in filters.get("filter", {}): - del filters["filter"]["ended_at__gte"] + ) and "created_on__lte" in default_filters.get("filter", {}): + if "ended_at__gte" in default_filters.get("filter", {}): + del default_filters["ended_at__gte"] def set_live_day(default_filters: dict, key: str): @@ -56,11 +56,11 @@ def get_source_data_from_widget( sub_widget=filters.pop("slug", [None])[0] ) - verify_filters(filters) default_filters.update(filters) project_timezone = widget.project.timezone apply_timezone_to_date_filters(default_filters, project_timezone) + verify_filters(default_filters) if operation == "list": tags = default_filters.pop("tags", [None])[0] From bf7cfaa94b312b78e28da97662fa79438a5e41e9 Mon Sep 17 00:00:00 2001 From: AlanJaeger Date: Thu, 27 Jun 2024 23:46:46 -0300 Subject: [PATCH 09/15] feature: print to debug --- insights/widgets/usecases/get_source_data.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/insights/widgets/usecases/get_source_data.py b/insights/widgets/usecases/get_source_data.py index 37f5337..d3d7a59 100644 --- a/insights/widgets/usecases/get_source_data.py +++ b/insights/widgets/usecases/get_source_data.py @@ -9,12 +9,12 @@ def verify_filters(default_filters: dict): print("filtros", default_filters) - if "created_on__gte" in default_filters.get( - "filter", {} - ) and "created_on__lte" in default_filters.get("filter", {}): + if "created_on__gte" in default_filters and "created_on__lte" in default_filters: if "ended_at__gte" in default_filters.get("filter", {}): del default_filters["ended_at__gte"] + print("apos", default_filters) + def set_live_day(default_filters: dict, key: str): start_of_day = datetime.combine(datetime.now().date(), time.min) @@ -62,6 +62,7 @@ def get_source_data_from_widget( apply_timezone_to_date_filters(default_filters, project_timezone) verify_filters(default_filters) + print("funcao final", default_filters) if operation == "list": tags = default_filters.pop("tags", [None])[0] if tags: From 11c3bff257b5030bd9e8e7bb8d2242a884f97a22 Mon Sep 17 00:00:00 2001 From: AlanJaeger Date: Fri, 28 Jun 2024 00:00:57 -0300 Subject: [PATCH 10/15] feature: print to debug --- insights/widgets/usecases/get_source_data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/insights/widgets/usecases/get_source_data.py b/insights/widgets/usecases/get_source_data.py index d3d7a59..b4aa5c4 100644 --- a/insights/widgets/usecases/get_source_data.py +++ b/insights/widgets/usecases/get_source_data.py @@ -10,7 +10,7 @@ def verify_filters(default_filters: dict): print("filtros", default_filters) if "created_on__gte" in default_filters and "created_on__lte" in default_filters: - if "ended_at__gte" in default_filters.get("filter", {}): + if "ended_at__gte" in default_filters: del default_filters["ended_at__gte"] print("apos", default_filters) From 3c459190e7bb216fdcddd973724806a5ef97871e Mon Sep 17 00:00:00 2001 From: AlanJaeger Date: Fri, 28 Jun 2024 00:18:01 -0300 Subject: [PATCH 11/15] feat: removing ended_at__gte when date filter is passed --- insights/widgets/usecases/get_source_data.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/insights/widgets/usecases/get_source_data.py b/insights/widgets/usecases/get_source_data.py index b4aa5c4..4d263f2 100644 --- a/insights/widgets/usecases/get_source_data.py +++ b/insights/widgets/usecases/get_source_data.py @@ -8,13 +8,10 @@ def verify_filters(default_filters: dict): - print("filtros", default_filters) if "created_on__gte" in default_filters and "created_on__lte" in default_filters: if "ended_at__gte" in default_filters: del default_filters["ended_at__gte"] - print("apos", default_filters) - def set_live_day(default_filters: dict, key: str): start_of_day = datetime.combine(datetime.now().date(), time.min) @@ -62,7 +59,6 @@ def get_source_data_from_widget( apply_timezone_to_date_filters(default_filters, project_timezone) verify_filters(default_filters) - print("funcao final", default_filters) if operation == "list": tags = default_filters.pop("tags", [None])[0] if tags: From 40039cabed9a36bd6255c07ff84be16c50fee0d5 Mon Sep 17 00:00:00 2001 From: AlanJaeger Date: Mon, 1 Jul 2024 16:21:41 -0300 Subject: [PATCH 12/15] feature: apply timezone function --- insights/widgets/usecases/get_source_data.py | 37 ++++++-------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/insights/widgets/usecases/get_source_data.py b/insights/widgets/usecases/get_source_data.py index 4d263f2..d747873 100644 --- a/insights/widgets/usecases/get_source_data.py +++ b/insights/widgets/usecases/get_source_data.py @@ -7,32 +7,16 @@ from insights.widgets.models import Widget -def verify_filters(default_filters: dict): - if "created_on__gte" in default_filters and "created_on__lte" in default_filters: - if "ended_at__gte" in default_filters: - del default_filters["ended_at__gte"] +def apply_timezone_to_filters(default_filters, project_timezone_str): + project_timezone = pytz.timezone(project_timezone_str) + for key in default_filters.keys(): + if key.endswith("__gte") or key.endswith("__lte"): + date_str = default_filters[key][0] + date_obj = datetime.strptime(date_str, "%Y-%m-%d") + date_obj_with_tz = project_timezone.localize(date_obj) + default_filters[key] = [date_obj_with_tz] - -def set_live_day(default_filters: dict, key: str): - start_of_day = datetime.combine(datetime.now().date(), time.min) - default_filters[key] = start_of_day - - -def apply_timezone_to_date_filters(default_filters: dict, timezone: str): - tz = pytz.timezone(timezone) - date_suffixes = ["__gte", "__lte"] - - for key, value in list(default_filters.items()): - if any(key.endswith(suffix) for suffix in date_suffixes): - if value == "today": - set_live_day(default_filters, key) - value = default_filters[key] - - if isinstance(value, str): - date_value = datetime.strptime(value, "%Y-%m-%d") - default_filters[key] = tz.localize(date_value) - elif isinstance(value, datetime): - default_filters[key] = tz.localize(value) + return default_filters def get_source_data_from_widget( @@ -56,8 +40,7 @@ def get_source_data_from_widget( default_filters.update(filters) project_timezone = widget.project.timezone - apply_timezone_to_date_filters(default_filters, project_timezone) - verify_filters(default_filters) + apply_timezone_to_filters(default_filters, project_timezone) if operation == "list": tags = default_filters.pop("tags", [None])[0] From c0122cd03c4106b4d41544edb853945a61a174d4 Mon Sep 17 00:00:00 2001 From: AlanJaeger Date: Mon, 1 Jul 2024 16:23:52 -0300 Subject: [PATCH 13/15] feature: print to debug --- insights/widgets/usecases/get_source_data.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/insights/widgets/usecases/get_source_data.py b/insights/widgets/usecases/get_source_data.py index d747873..e9e4e2a 100644 --- a/insights/widgets/usecases/get_source_data.py +++ b/insights/widgets/usecases/get_source_data.py @@ -16,8 +16,6 @@ def apply_timezone_to_filters(default_filters, project_timezone_str): date_obj_with_tz = project_timezone.localize(date_obj) default_filters[key] = [date_obj_with_tz] - return default_filters - def get_source_data_from_widget( widget: Widget, is_report: bool = False, filters: dict = {}, user_email: str = "" @@ -39,8 +37,10 @@ def get_source_data_from_widget( default_filters.update(filters) + print("filtro antes", default_filters) project_timezone = widget.project.timezone apply_timezone_to_filters(default_filters, project_timezone) + print("filtro depois", default_filters) if operation == "list": tags = default_filters.pop("tags", [None])[0] From baabdc5b0ed9cdf241d8416394067b704ee8fb95 Mon Sep 17 00:00:00 2001 From: AlanJaeger Date: Tue, 2 Jul 2024 17:12:29 -0300 Subject: [PATCH 14/15] feature: adding isoformat to date with timezone --- insights/sources/agents/clients.py | 4 ++-- insights/widgets/usecases/get_source_data.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/insights/sources/agents/clients.py b/insights/sources/agents/clients.py index be66fd3..50ff9e7 100644 --- a/insights/sources/agents/clients.py +++ b/insights/sources/agents/clients.py @@ -15,9 +15,9 @@ def __init__(self, project) -> None: def list(self, query_filters: dict): if query_filters.get("created_on__gte", None): - query_filters["start_date"] = query_filters.pop("created_on__gte")[0] + query_filters["start_date"] = query_filters.pop("created_on__gte") if query_filters.get("created_on__lte", None): - query_filters["end_date"] = query_filters.pop("created_on__lte")[0] + query_filters["end_date"] = query_filters.pop("created_on__lte") response = requests.get( url=self.url, headers=self.headers, params=query_filters diff --git a/insights/widgets/usecases/get_source_data.py b/insights/widgets/usecases/get_source_data.py index e9e4e2a..57c60a9 100644 --- a/insights/widgets/usecases/get_source_data.py +++ b/insights/widgets/usecases/get_source_data.py @@ -14,7 +14,7 @@ def apply_timezone_to_filters(default_filters, project_timezone_str): date_str = default_filters[key][0] date_obj = datetime.strptime(date_str, "%Y-%m-%d") date_obj_with_tz = project_timezone.localize(date_obj) - default_filters[key] = [date_obj_with_tz] + default_filters[key] = date_obj_with_tz.isoformat() def get_source_data_from_widget( From 6afb0038360ff89af1cbd3ccef87d2f1c3c22176 Mon Sep 17 00:00:00 2001 From: AlanJaeger Date: Tue, 2 Jul 2024 17:23:56 -0300 Subject: [PATCH 15/15] feat: removing comments --- insights/dashboards/usecases/dashboard_creation.py | 6 +----- insights/widgets/usecases/get_source_data.py | 2 -- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/insights/dashboards/usecases/dashboard_creation.py b/insights/dashboards/usecases/dashboard_creation.py index 2d20108..5a423e4 100644 --- a/insights/dashboards/usecases/dashboard_creation.py +++ b/insights/dashboards/usecases/dashboard_creation.py @@ -37,7 +37,6 @@ def create_widgets(self, dashboard_atendimento_humano): config={ "limit": 12, "operation": "timeseries_hour_group_count", - "filter": {"created_on__gte": "today"}, }, dashboard=dashboard_atendimento_humano, position={"rows": [1, 1], "columns": [1, 12]}, @@ -62,7 +61,6 @@ def create_widgets(self, dashboard_atendimento_humano): "operation": "avg", "type_result": "executions", "op_field": "waiting_time", - "filter": {"created_on__gte": "today"}, }, dashboard=dashboard_atendimento_humano, position={"rows": [3, 3], "columns": [5, 8]}, @@ -74,7 +72,7 @@ def create_widgets(self, dashboard_atendimento_humano): config={ "operation": "count", "type_result": "executions", - "filter": {"is_active": False, "ended_at__gte": "today"}, + "filter": {"is_active": False}, }, dashboard=dashboard_atendimento_humano, position={"rows": [2, 2], "columns": [9, 12]}, @@ -87,7 +85,6 @@ def create_widgets(self, dashboard_atendimento_humano): "operation": "avg", "type_result": "executions", "op_field": "message_response_time", - "filter": {"created_on__gte": "today"}, }, dashboard=dashboard_atendimento_humano, position={"rows": [3, 3], "columns": [1, 4]}, @@ -115,7 +112,6 @@ def create_widgets(self, dashboard_atendimento_humano): "operation": "avg", "type_result": "executions", "op_field": "interaction_time", - "filter": {"created_on__gte": "today"}, }, dashboard=dashboard_atendimento_humano, position={"rows": [3, 3], "columns": [9, 12]}, diff --git a/insights/widgets/usecases/get_source_data.py b/insights/widgets/usecases/get_source_data.py index 57c60a9..d0ed9ef 100644 --- a/insights/widgets/usecases/get_source_data.py +++ b/insights/widgets/usecases/get_source_data.py @@ -37,10 +37,8 @@ def get_source_data_from_widget( default_filters.update(filters) - print("filtro antes", default_filters) project_timezone = widget.project.timezone apply_timezone_to_filters(default_filters, project_timezone) - print("filtro depois", default_filters) if operation == "list": tags = default_filters.pop("tags", [None])[0]