From 042c129b25cd0cd526d9241e62dd1fddb6bf989b Mon Sep 17 00:00:00 2001 From: matt garber Date: Tue, 29 Oct 2024 16:00:38 -0400 Subject: [PATCH] Type casting on date filter fix (#138) --- scripts/credential_management.py | 4 +- src/dashboard/get_chart_data/filter_config.py | 63 ++++++++++++------ tests/dashboard/test_filter_config.py | 64 +++++++++++++------ 3 files changed, 89 insertions(+), 42 deletions(-) diff --git a/scripts/credential_management.py b/scripts/credential_management.py index bb66bde..9a17003 100755 --- a/scripts/credential_management.py +++ b/scripts/credential_management.py @@ -29,7 +29,7 @@ def _put_s3_data(name: str, bucket_name: str, client, data: dict, path: str = "a def create_auth(client, user: str, auth: str, site: str) -> str: """Adds a new entry to the auth dict used to issue pre-signed URLs""" site_id = _basic_auth_str(user, auth).split(" ")[1] - return f'"{site_id}"": {{"site":{site}}}' + return f'"{site_id}"": {{"user": {user}, "site":{site}}}' def create_meta(client, bucket_name: str, site: str, folder: str) -> None: @@ -98,7 +98,7 @@ def delete_meta(client, bucket_name: str, site: str) -> bool: args.create_auth[1], args.create_auth[2], ) - print(f"Add the following key/valye to secrets manager: \n {id_str}") + print(f"Add the following key/value to secrets manager: \n {id_str}") elif args.create_meta: create_meta(s3_client, bucket, args.create_meta[0], args.create_meta[1]) print(f"{args.create_meta[0]} mapped to S3 folder {args.create_meta[1]}") diff --git a/src/dashboard/get_chart_data/filter_config.py b/src/dashboard/get_chart_data/filter_config.py index 66b16f2..44c0127 100644 --- a/src/dashboard/get_chart_data/filter_config.py +++ b/src/dashboard/get_chart_data/filter_config.py @@ -30,26 +30,49 @@ "lt": "%s < %s", "lte": "%s <= %s", # dates - "sameDay": "DATE(%s) = date_trunc('day',DATE('%s'))", - "sameWeek": "date_trunc('week',DATE(%s)) = date_trunc('week',DATE('%s'))", - "sameMonth": "date_trunc('month',DATE(%s)) = date_trunc('month',DATE('%s'))", - "sameYear": "date_trunc('year',DATE(%s)) = date_trunc('year',DATE('%s'))", - "sameDayOrBefore": "DATE(%s) <= date_trunc('day',DATE('%s'))", - "sameWeekOrBefore": "date_trunc('week',DATE(%s)) <= date_trunc('week',DATE('%s'))", - "sameMonthOrBefore": ("date_trunc('month',DATE(%s)) <= date_trunc('month',DATE('%s'))"), - "sameYearOrBefore": "date_trunc('year',DATE(%s)) <= date_trunc('year',DATE('%s'))", - "sameDayOrAfter": "DATE(%s) >= date_trunc('day',DATE('%s'))", - "sameWeekOrAfter": ("date_trunc('week',DATE(%s)) " ">= date_trunc('week',DATE('%s'))"), - "sameMonthOrAfter": ("date_trunc('month',DATE(%s)) >= date_trunc('month',DATE('%s'))"), - "sameYearOrAfter": "date_trunc('year',DATE(%s)) >= date_trunc('year',DATE('%s'))", - "beforeDay": "DATE(%s) < date_trunc('day',DATE('%s'))", - "beforeWeek": "date_trunc('week',DATE(%s)) < date_trunc('week',DATE('%s'))", - "beforeMonth": "date_trunc('month',DATE(%s)) < date_trunc('month',DATE('%s'))", - "beforeYear": "date_trunc('year',DATE(%s)) < date_trunc('year',DATE('%s'))", - "afterDay": "DATE(%s) > date_trunc('day',DATE('%s'))", - "afterWeek": "date_trunc('week',DATE(%s)) > date_trunc('week',DATE('%s'))", - "afterMonth": "date_trunc('month',DATE(%s)) > date_trunc('month',DATE('%s'))", - "afterYear": "date_trunc('year',DATE(%s)) > date_trunc('year',DATE('%s'))", + "sameDay": "from_iso8601_timestamp(%s) = date_trunc('day',from_iso8601_timestamp('%s'))", + "sameWeek": "date_trunc('week',from_iso8601_timestamp(%s)) = " + "date_trunc('week',from_iso8601_timestamp('%s'))", + "sameMonth": "date_trunc('month',from_iso8601_timestamp(%s)) = " + "date_trunc('month',from_iso8601_timestamp('%s'))", + "sameYear": "date_trunc('year',from_iso8601_timestamp(%s)) = " + "date_trunc('year',from_iso8601_timestamp('%s'))", + "sameDayOrBefore": "from_iso8601_timestamp(%s) <= " + "date_trunc('day',from_iso8601_timestamp('%s'))", + "sameWeekOrBefore": "date_trunc('week',from_iso8601_timestamp(%s)) <= " + "date_trunc('week',from_iso8601_timestamp('%s'))", + "sameMonthOrBefore": ( + "date_trunc('month',from_iso8601_timestamp(%s)) <= " + "date_trunc('month',from_iso8601_timestamp('%s'))" + ), + "sameYearOrBefore": "date_trunc('year',from_iso8601_timestamp(%s)) <= " + "date_trunc('year',from_iso8601_timestamp('%s'))", + "sameDayOrAfter": "from_iso8601_timestamp(%s) >= " + "date_trunc('day',from_iso8601_timestamp('%s'))", + "sameWeekOrAfter": ( + "date_trunc('week',from_iso8601_timestamp(%s)) " + ">= date_trunc('week',from_iso8601_timestamp('%s'))" + ), + "sameMonthOrAfter": ( + "date_trunc('month',from_iso8601_timestamp(%s)) >= " + "date_trunc('month',from_iso8601_timestamp('%s'))" + ), + "sameYearOrAfter": "date_trunc('year',from_iso8601_timestamp(%s)) >= " + "date_trunc('year',from_iso8601_timestamp('%s'))", + "beforeDay": "from_iso8601_timestamp(%s) < " "date_trunc('day',from_iso8601_timestamp('%s'))", + "beforeWeek": "date_trunc('week',from_iso8601_timestamp(%s)) < " + "date_trunc('week',from_iso8601_timestamp('%s'))", + "beforeMonth": "date_trunc('month',from_iso8601_timestamp(%s)) < " + "date_trunc('month',from_iso8601_timestamp('%s'))", + "beforeYear": "date_trunc('year',from_iso8601_timestamp(%s)) < " + "date_trunc('year',from_iso8601_timestamp('%s'))", + "afterDay": "from_iso8601_timestamp(%s) > " "date_trunc('day',from_iso8601_timestamp('%s'))", + "afterWeek": "date_trunc('week',from_iso8601_timestamp(%s)) > " + "date_trunc('week',from_iso8601_timestamp('%s'))", + "afterMonth": "date_trunc('month',from_iso8601_timestamp(%s)) > " + "date_trunc('month',from_iso8601_timestamp('%s'))", + "afterYear": "date_trunc('year',from_iso8601_timestamp(%s)) > " + "date_trunc('year',from_iso8601_timestamp('%s'))", } _FILTER_MAP_ONE_PARAM = { diff --git a/tests/dashboard/test_filter_config.py b/tests/dashboard/test_filter_config.py index e4e3dd9..39685ad 100644 --- a/tests/dashboard/test_filter_config.py +++ b/tests/dashboard/test_filter_config.py @@ -42,83 +42,107 @@ (["col:strEq:str"], "col LIKE 'str'"), ( ["column:sameDay:1900-01-01"], - "DATE(column) = date_trunc('day',DATE('1900-01-01'))", + "from_iso8601_timestamp(column) = " + "date_trunc('day',from_iso8601_timestamp('1900-01-01'))", ), ( ["column:sameWeek:1900-01-01"], - "date_trunc('week',DATE(column)) = date_trunc('week',DATE('1900-01-01'))", + "date_trunc('week',from_iso8601_timestamp(column)) = " + "date_trunc('week',from_iso8601_timestamp('1900-01-01'))", ), ( ["column:sameMonth:1900-01-01"], - "date_trunc('month',DATE(column)) = date_trunc('month',DATE('1900-01-01'))", + "date_trunc('month',from_iso8601_timestamp(column)) = " + "date_trunc('month',from_iso8601_timestamp('1900-01-01'))", ), ( ["column:sameYear:1900-01-01"], - "date_trunc('year',DATE(column)) = date_trunc('year',DATE('1900-01-01'))", + "date_trunc('year',from_iso8601_timestamp(column)) = " + "date_trunc('year',from_iso8601_timestamp('1900-01-01'))", ), ( ["column:sameDayOrBefore:1900-01-01"], - "DATE(column) <= date_trunc('day',DATE('1900-01-01'))", + "from_iso8601_timestamp(column) <= " + "date_trunc('day',from_iso8601_timestamp('1900-01-01'))", ), ( ["column:sameWeekOrBefore:1900-01-01"], - "date_trunc('week',DATE(column)) <= date_trunc('week',DATE('1900-01-01'))", + "date_trunc('week',from_iso8601_timestamp(column)) <= " + "date_trunc('week',from_iso8601_timestamp('1900-01-01'))", ), ( ["column:sameMonthOrBefore:1900-01-01"], - ("date_trunc('month',DATE(column)) <= " "date_trunc('month',DATE('1900-01-01'))"), + ( + "date_trunc('month',from_iso8601_timestamp(column)) <= " + "date_trunc('month',from_iso8601_timestamp('1900-01-01'))" + ), ), ( ["column:sameYearOrBefore:1900-01-01"], - "date_trunc('year',DATE(column)) <= date_trunc('year',DATE('1900-01-01'))", + "date_trunc('year',from_iso8601_timestamp(column)) <= " + "date_trunc('year',from_iso8601_timestamp('1900-01-01'))", ), ( ["column:sameDayOrAfter:1900-01-01"], - "DATE(column) >= date_trunc('day',DATE('1900-01-01'))", + "from_iso8601_timestamp(column) >= " + "date_trunc('day',from_iso8601_timestamp('1900-01-01'))", ), ( ["column:sameWeekOrAfter:1900-01-01"], - "date_trunc('week',DATE(column)) >= date_trunc('week',DATE('1900-01-01'))", + "date_trunc('week',from_iso8601_timestamp(column)) >= " + "date_trunc('week',from_iso8601_timestamp('1900-01-01'))", ), ( ["column:sameMonthOrAfter:1900-01-01"], - ("date_trunc('month',DATE(column)) >= " "date_trunc('month',DATE('1900-01-01'))"), + ( + "date_trunc('month',from_iso8601_timestamp(column)) >= " + "date_trunc('month',from_iso8601_timestamp('1900-01-01'))" + ), ), ( ["column:sameYearOrAfter:1900-01-01"], - "date_trunc('year',DATE(column)) >= date_trunc('year',DATE('1900-01-01'))", + "date_trunc('year',from_iso8601_timestamp(column)) >= " + "date_trunc('year',from_iso8601_timestamp('1900-01-01'))", ), ( ["column:beforeDay:1900-01-01"], - "DATE(column) < date_trunc('day',DATE('1900-01-01'))", + "from_iso8601_timestamp(column) < " + "date_trunc('day',from_iso8601_timestamp('1900-01-01'))", ), ( ["column:beforeWeek:1900-01-01"], - "date_trunc('week',DATE(column)) < date_trunc('week',DATE('1900-01-01'))", + "date_trunc('week',from_iso8601_timestamp(column)) < " + "date_trunc('week',from_iso8601_timestamp('1900-01-01'))", ), ( ["column:beforeMonth:1900-01-01"], - "date_trunc('month',DATE(column)) < date_trunc('month',DATE('1900-01-01'))", + "date_trunc('month',from_iso8601_timestamp(column)) < " + "date_trunc('month',from_iso8601_timestamp('1900-01-01'))", ), ( ["column:beforeYear:1900-01-01"], - "date_trunc('year',DATE(column)) < date_trunc('year',DATE('1900-01-01'))", + "date_trunc('year',from_iso8601_timestamp(column)) < " + "date_trunc('year',from_iso8601_timestamp('1900-01-01'))", ), ( ["column:afterDay:1900-01-01"], - "DATE(column) > date_trunc('day',DATE('1900-01-01'))", + "from_iso8601_timestamp(column) > " + "date_trunc('day',from_iso8601_timestamp('1900-01-01'))", ), ( ["column:afterWeek:1900-01-01"], - "date_trunc('week',DATE(column)) > date_trunc('week',DATE('1900-01-01'))", + "date_trunc('week',from_iso8601_timestamp(column)) > " + "date_trunc('week',from_iso8601_timestamp('1900-01-01'))", ), ( ["column:afterMonth:1900-01-01"], - "date_trunc('month',DATE(column)) > date_trunc('month',DATE('1900-01-01'))", + "date_trunc('month',from_iso8601_timestamp(column)) > " + "date_trunc('month',from_iso8601_timestamp('1900-01-01'))", ), ( ["column:afterYear:1900-01-01"], - "date_trunc('year',DATE(column)) > date_trunc('year',DATE('1900-01-01'))", + "date_trunc('year',from_iso8601_timestamp(column)) > " + "date_trunc('year',from_iso8601_timestamp('1900-01-01'))", ), # Checking compound statements (