From 98c49ecccbb672c5e167a927fe3a4e2df495b32e Mon Sep 17 00:00:00 2001 From: Kraiem Taha Yassine Date: Fri, 8 Dec 2023 14:28:19 +0100 Subject: [PATCH] fix(chalice): fixed Path Analysis support of contains/not-contains for exclude points (#1753) --- api/chalicelib/core/product_analytics.py | 9 +++++++-- ee/api/chalicelib/core/product_analytics.py | 5 ++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/api/chalicelib/core/product_analytics.py b/api/chalicelib/core/product_analytics.py index 3d70e28c6..c93bd34e3 100644 --- a/api/chalicelib/core/product_analytics.py +++ b/api/chalicelib/core/product_analytics.py @@ -126,11 +126,14 @@ def path_analysis(project_id: int, data: schemas.CardPathAnalysis): for i, ef in enumerate(data.excludes): if len(ef.value) == 0: continue + ef.value = helper.values_for_operator(value=ef.value, op=ef.operator) + op = sh.get_sql_operator(ef.operator) + op = sh.reverse_sql_operator(op) if ef.type in data.metric_value: f_k = f"exclude_{i}" extra_values = {**extra_values, **sh.multi_values(ef.value, value_key=f_k)} exclusions[ef.type] = [ - sh.multi_conditions(f'{JOURNEY_TYPES[ef.type]["column"]} != %({f_k})s', ef.value, is_not=True, + sh.multi_conditions(f'{JOURNEY_TYPES[ef.type]["column"]} {op} %({f_k})s', ef.value, is_not=True, value_key=f_k)] meta_keys = None @@ -407,7 +410,9 @@ WITH sub_sessions AS (SELECT session_id {sub_sessions_extra_projection} **extra_values} query = cur.mogrify(pg_query, params) _now = time() - + logger.debug("----------------------") + logger.debug(query) + logger.debug("----------------------") cur.execute(query) if time() - _now > 2: logger.warning(f">>>>>>>>>PathAnalysis long query ({int(time() - _now)}s)<<<<<<<<<") diff --git a/ee/api/chalicelib/core/product_analytics.py b/ee/api/chalicelib/core/product_analytics.py index 7b51de26c..6847aa4aa 100644 --- a/ee/api/chalicelib/core/product_analytics.py +++ b/ee/api/chalicelib/core/product_analytics.py @@ -139,9 +139,12 @@ def path_analysis(project_id: int, data: schemas.CardPathAnalysis): continue if ef.type in data.metric_value: f_k = f"exclude_{i}" + ef.value = helper.values_for_operator(value=ef.value, op=ef.operator) + op = sh.get_sql_operator(ef.operator) + op = sh.reverse_sql_operator(op) extra_values = {**extra_values, **sh.multi_values(ef.value, value_key=f_k)} exclusions[ef.type] = [ - sh.multi_conditions(f'{JOURNEY_TYPES[ef.type]["column"]} != %({f_k})s', ef.value, is_not=True, + sh.multi_conditions(f'{JOURNEY_TYPES[ef.type]["column"]} {op} %({f_k})s', ef.value, is_not=True, value_key=f_k)] sessions_conditions = []