Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chart data cleanup #141

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/dashboard/get_chart_data/get_chart_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"strContainsCI",
"strStartsWithCI",
"strEndsWithCI",
"strMatchesCI",
"matchesCI",
"strNotEq",
"strNotContains",
"strNotStartsWith",
Expand Down Expand Up @@ -89,7 +89,7 @@
"strContainsCI",
"strStartsWithCI",
"strEndsWithCI",
"strMatchesCI",
"matchesCI",
"strNotEq",
"strNotContains",
"strNotStartsWith",
Expand Down Expand Up @@ -165,9 +165,10 @@ def _build_query(query_params: dict, filter_groups: list, path_params: dict) ->
raise errors.AggregatorFilterError(
f"Invalid filter type {filter_config[1]} requested."
)

inline_configs.append(config_params)
none_configs.append(none_params)
if config_params != []:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if config_params: might be more natural, unless there's a reason you want to append a None value.

inline_configs.append(config_params)
if none_params != []:
none_configs.append(none_params)
count_col = next(c for c in columns if c.startswith("cnt"))
columns.remove(count_col)
# these 'if in' checks is meant to handle the case where the selected column is also
Expand Down
70 changes: 35 additions & 35 deletions src/dashboard/get_chart_data/templates/filter_inline.sql.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -8,86 +8,86 @@
{#- TODO: replace all LIKE filters with regexp() calls -#}
{#- Sting filters -#}
{%- if filter_type == 'strEq' -%}
"{{ data }}" LIKE '{{ bound }}'
CAST("{{ data }}" AS VARCHAR) LIKE '{{ bound }}'
{%- elif filter_type == 'strContains' -%}
"{{ data }}" LIKE '%{{ bound }}%'
CAST("{{ data }}" AS VARCHAR) LIKE '%{{ bound }}%'
{%- elif filter_type == 'strStartsWith' -%}
"{{ data }}" LIKE '{{ bound }}%'
CAST("{{ data }}" AS VARCHAR) LIKE '{{ bound }}%'
{%- elif filter_type == 'strEndsWith' -%}
"{{ data }}" LIKE '%{{ bound }}'
CAST("{{ data }}" AS VARCHAR) LIKE '%{{ bound }}'
{%- elif filter_type == 'matches' -%}
regexp_like("{{ data }}", '{{ bound }}')
regexp_like(CAST("{{ data }}" AS VARCHAR), '{{ bound }}')
{%- elif filter_type == 'strEqCI' -%}
"{{ data }}" ILIKE '{{ bound }}'
regexp_like(CAST("{{ data }}" AS VARCHAR), '(?i)^{{ bound }}$')
{%- elif filter_type == 'strContainsCI' -%}
"{{ data }}" ILIKE '%{{ bound }}%'
regexp_like(CAST("{{ data }}" AS VARCHAR), '(?i){{ bound }}')
{%- elif filter_type == 'strStartsWithCI' -%}
"{{ data }}" ILIKE '{{ bound }}%'
regexp_like(CAST("{{ data }}" AS VARCHAR), '(?i)^{{ bound }}')
{%- elif filter_type == 'strEndsWithCI' -%}
"{{ data }}" ILIKE '%{{ bound }}'
regexp_like(CAST("{{ data }}" AS VARCHAR), '(?i){{ bound }}$')
{%- elif filter_type == 'matchesCI' -%}
regexp_like("{{ data }}", '(?i){{ bound }}')
regexp_like(CAST("{{ data }}" AS VARCHAR), '(?i){{ bound }}')
{%- elif filter_type == 'strNotEq' -%}
"{{ data }}" NOT LIKE '{{ bound }}'
CAST("{{ data }}" AS VARCHAR) NOT LIKE '{{ bound }}'
{%- elif filter_type == 'strNotContains' -%}
"{{ data }}" NOT LIKE '%{{ bound }}%'
CAST("{{ data }}" AS VARCHAR) NOT LIKE '%{{ bound }}%'
{%- elif filter_type == 'strNotStartsWith' -%}
"{{ data }}" NOT LIKE '{{ bound }}%'
CAST("{{ data }}" AS VARCHAR) NOT LIKE '{{ bound }}%'
{%- elif filter_type == 'strNotEndsWith' -%}
"{{ data }}" NOT LIKE '%{{ bound }}'
CAST("{{ data }}" AS VARCHAR) NOT LIKE '%{{ bound }}'
{%- elif filter_type == 'notMatches' -%}
NOT regexp_like("{{ data }}", '{{ bound }}')
NOT regexp_like(CAST("{{ data }}" AS VARCHAR), '{{ bound }}')
{%- elif filter_type == 'strNotEqCI' -%}
"{{ data }}" NOT ILIKE '{{ bound }}'
NOT regexp_like(CAST("{{ data }}" AS VARCHAR), '(?i)^{{ bound }}$')
{%- elif filter_type == 'strNotContainsCI' -%}
"{{ data }}" NOT ILIKE '%{{ bound }}%'
NOT regexp_like(CAST("{{ data }}" AS VARCHAR), '(?i){{ bound }}')
{%- elif filter_type == 'strNotStartsWithCI' -%}
"{{ data }}" NOT ILIKE '{{ bound }}%'
NOT regexp_like(CAST("{{ data }}" AS VARCHAR), '(?i)^{{ bound }}')
{%- elif filter_type == 'strNotEndsWithCI' -%}
"{{ data }}" NOT ILIKE '%{{ bound }}'
NOT regexp_like(CAST("{{ data }}" AS VARCHAR), '(?i){{ bound }}$')
{%- elif filter_type == 'notMatchesCI' -%}
NOT regexp_like("{{ data }}", '(?i){{ bound }}')
NOT regexp_like(CAST("{{ data }}" AS VARCHAR), '(?i){{ bound }}')
{#- Date filters -#}
{%- elif filter_type == 'sameDay' -%}
from_iso8601_timestamp("{{ data }}") = date_trunc('day',from_iso8601_timestamp('{{ bound }}'))
{%- elif filter_type == 'sameWeek' -%}
date_trunc('week',from_iso8601_timestamp('{{ data }}')) = date_trunc('week',from_iso8601_timestamp('{{ bound }}'))
date_trunc('week',from_iso8601_timestamp("{{ data }}")) = date_trunc('week',from_iso8601_timestamp('{{ bound }}'))
{%- elif filter_type == 'sameMonth' -%}
date_trunc('month',from_iso8601_timestamp('{{ data }}')) = date_trunc('month',from_iso8601_timestamp('{{ bound }}'))
date_trunc('month',from_iso8601_timestamp("{{ data }}")) = date_trunc('month',from_iso8601_timestamp('{{ bound }}'))
{%- elif filter_type == 'sameYear' -%}
date_trunc('year',from_iso8601_timestamp('{{ data }}')) = date_trunc('year',from_iso8601_timestamp('{{ bound }}'))
date_trunc('year',from_iso8601_timestamp("{{ data }}")) = date_trunc('year',from_iso8601_timestamp('{{ bound }}'))
{%- elif filter_type == 'sameDayOrBefore' -%}
from_iso8601_timestamp("{{ data }}") <= date_trunc('day',from_iso8601_timestamp('{{ bound }}'))
{%- elif filter_type == 'sameWeekOrBefore' -%}
date_trunc('week',from_iso8601_timestamp('{{ data }}')) <= date_trunc('week',from_iso8601_timestamp('{{ bound }}'))
date_trunc('week',from_iso8601_timestamp("{{ data }}")) <= date_trunc('week',from_iso8601_timestamp('{{ bound }}'))
{%- elif filter_type == 'sameMonthOrBefore' -%}
date_trunc('month',from_iso8601_timestamp('{{ data }}')) <= date_trunc('month',from_iso8601_timestamp('{{ bound }}'))
date_trunc('month',from_iso8601_timestamp("{{ data }}")) <= date_trunc('month',from_iso8601_timestamp('{{ bound }}'))
{%- elif filter_type == 'sameYearOrBefore' -%}
date_trunc('year',from_iso8601_timestamp('{{ data }}')) <= date_trunc('year',from_iso8601_timestamp('{{ bound }}'))
date_trunc('year',from_iso8601_timestamp("{{ data }}")) <= date_trunc('year',from_iso8601_timestamp('{{ bound }}'))
{%- elif filter_type == 'sameDayOrAfter' -%}
from_iso8601_timestamp("{{ data }}") >= date_trunc('day',from_iso8601_timestamp('{{ bound }}'))
{%- elif filter_type == 'sameWeekOrAfter' -%}
date_trunc('week',from_iso8601_timestamp('{{ data }}')) >= date_trunc('week',from_iso8601_timestamp('{{ bound }}'))
date_trunc('week',from_iso8601_timestamp("{{ data }}")) >= date_trunc('week',from_iso8601_timestamp('{{ bound }}'))
{%- elif filter_type == 'sameMonthOrAfter' -%}
date_trunc('month',from_iso8601_timestamp('{{ data }}')) >= date_trunc('month',from_iso8601_timestamp('{{ bound }}'))
date_trunc('month',from_iso8601_timestamp("{{ data }}")) >= date_trunc('month',from_iso8601_timestamp('{{ bound }}'))
{%- elif filter_type == 'sameYearOrAfter' -%}
date_trunc('year',from_iso8601_timestamp('{{ data }}')) >= date_trunc('year',from_iso8601_timestamp('{{ bound }}'))
date_trunc('year',from_iso8601_timestamp("{{ data }}")) >= date_trunc('year',from_iso8601_timestamp('{{ bound }}'))
{%- elif filter_type == 'beforeDay' -%}
from_iso8601_timestamp("{{ data }}") < date_trunc('day',from_iso8601_timestamp('{{ bound }}'))
{%- elif filter_type == 'beforeWeek' -%}
date_trunc('week',from_iso8601_timestamp('{{ data }}')) < date_trunc('week',from_iso8601_timestamp('{{ bound }}'))
date_trunc('week',from_iso8601_timestamp("{{ data }}")) < date_trunc('week',from_iso8601_timestamp('{{ bound }}'))
{%- elif filter_type == 'beforeMonth' -%}
date_trunc('month',from_iso8601_timestamp('{{ data }}')) < date_trunc('month',from_iso8601_timestamp('{{ bound }}'))
date_trunc('month',from_iso8601_timestamp("{{ data }}")) < date_trunc('month',from_iso8601_timestamp('{{ bound }}'))
{%- elif filter_type == 'beforeYear' -%}
date_trunc('year',from_iso8601_timestamp('{{ data }}')) < date_trunc('year',from_iso8601_timestamp('{{ bound }}'))
date_trunc('year',from_iso8601_timestamp("{{ data }}")) < date_trunc('year',from_iso8601_timestamp('{{ bound }}'))
{%- elif filter_type == 'afterDay' -%}
from_iso8601_timestamp("{{ data }}") > date_trunc('day',from_iso8601_timestamp('{{ bound }}'))
{%- elif filter_type == 'afterWeek' -%}
date_trunc('week',from_iso8601_timestamp('{{ data }}')) > date_trunc('week',from_iso8601_timestamp('{{ bound }}'))
date_trunc('week',from_iso8601_timestamp("{{ data }}")) > date_trunc('week',from_iso8601_timestamp('{{ bound }}'))
{%- elif filter_type == 'afterMonth' -%}
date_trunc('month',from_iso8601_timestamp('{{ data }}')) > date_trunc('month',from_iso8601_timestamp('{{ bound }}'))
date_trunc('month',from_iso8601_timestamp("{{ data }}")) > date_trunc('month',from_iso8601_timestamp('{{ bound }}'))
{%- elif filter_type == 'afterYear' -%}
date_trunc('year',from_iso8601_timestamp('{{ data }}')) > date_trunc('year',from_iso8601_timestamp('{{ bound }}'))
date_trunc('year',from_iso8601_timestamp("{{ data }}")) > date_trunc('year',from_iso8601_timestamp('{{ bound }}'))
{#- Boolean filters -#}
{%- elif filter_type == 'isTrue' -%}
"{{ data }}" IS TRUE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ WHERE
AND (
(
{{ data_column }} != 'cumulus__none'
{%- if inline_configs %}
{%- if inline_configs|length > 0 %}
AND
(
{{ inline.get_filters(inline_configs) }}
Expand All @@ -30,7 +30,7 @@ WHERE
)
OR (
{{ data_column }} = 'cumulus__none'
{%- if none_configs %}
{%- if none_configs|length > 0 %}
AND
(
{{ inline.get_filters(none_configs) }}
Expand Down
Loading
Loading