Skip to content

Commit

Permalink
Chart data cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dogversioning committed Nov 11, 2024
1 parent 7e72e89 commit 52cc704
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 101 deletions.
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 != []:
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

0 comments on commit 52cc704

Please sign in to comment.