Skip to content

Commit

Permalink
Type casting on date filter fix (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
dogversioning authored Oct 29, 2024
1 parent a3b4977 commit 042c129
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 42 deletions.
4 changes: 2 additions & 2 deletions scripts/credential_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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]}")
Expand Down
63 changes: 43 additions & 20 deletions src/dashboard/get_chart_data/filter_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
64 changes: 44 additions & 20 deletions tests/dashboard/test_filter_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
(
Expand Down

0 comments on commit 042c129

Please sign in to comment.