From 11c4d9e1142f4c0708d64146bb41be1237443b03 Mon Sep 17 00:00:00 2001 From: Kraiem Taha Yassine Date: Mon, 1 Jul 2024 17:46:45 +0200 Subject: [PATCH] Dev (#2331) * refactor(chalice): upgraded dependencies * refactor(chalice): upgraded dependencies feat(chalice): support heatmaps * feat(chalice): support table-of-browsers showing user-count * feat(chalice): support table-of-devices showing user-count * feat(chalice): support table-of-URLs showing user-count * refactor(DB): update webVital UI configuration * fix(chalice): fixed Math-operators validation refactor(chalice): search for sessions that have events for heatmaps * refactor(chalice): search for sessions that have at least 1 location event for heatmaps --- api/chalicelib/core/heatmaps.py | 17 ++++++++++ api/chalicelib/core/sessions.py | 2 +- api/schemas/schemas.py | 2 +- ee/api/chalicelib/core/heatmaps.py | 34 ++++++++++++++++++- ee/api/chalicelib/core/sessions_exp.py | 2 +- .../db/init_dbs/postgresql/1.19.0/1.19.0.sql | 12 +++++++ .../db/init_dbs/postgresql/1.19.0/1.19.0.sql | 11 ++++++ 7 files changed, 76 insertions(+), 4 deletions(-) diff --git a/api/chalicelib/core/heatmaps.py b/api/chalicelib/core/heatmaps.py index 603b538a5..12a91ea91 100644 --- a/api/chalicelib/core/heatmaps.py +++ b/api/chalicelib/core/heatmaps.py @@ -147,14 +147,29 @@ def search_short_session(data: schemas.ClickMapSessionsSearch, project_id, user_ include_mobs: bool = True, exclude_sessions: list[str] = [], _depth: int = 3): no_platform = True + no_location = True for f in data.filters: if f.type == schemas.FilterType.platform: no_platform = False break + for f in data.events: + if f.type == schemas.EventType.location: + no_location = False + if len(f.value) == 0: + f.operator = schemas.SearchEventOperator._is_any + break if no_platform: data.filters.append(schemas.SessionSearchFilterSchema(type=schemas.FilterType.platform, value=[schemas.PlatformType.desktop], operator=schemas.SearchEventOperator._is)) + if no_location: + data.events.append(schemas.SessionSearchEventSchema2(type=schemas.EventType.location, + value=[], + operator=schemas.SearchEventOperator._is_any)) + + data.filters.append(schemas.SessionSearchFilterSchema(type=schemas.FilterType.events_count, + value=[0], + operator=schemas.MathOperator._greater)) full_args, query_part = sessions.search_query_parts(data=data, error_status=None, errors_only=False, favorite_only=data.bookmarked, issue=None, @@ -199,6 +214,8 @@ def search_short_session(data: schemas.ClickMapSessionsSearch, project_id, user_ logger.info("couldn't find an existing replay after 3 iterations for heatmap") session['events'] = get_page_events(session_id=session["session_id"]) + else: + logger.debug("No session found for heatmap") return helper.dict_to_camel_case(session) diff --git a/api/chalicelib/core/sessions.py b/api/chalicelib/core/sessions.py index 9fc8330ad..1621c0bb8 100644 --- a/api/chalicelib/core/sessions.py +++ b/api/chalicelib/core/sessions.py @@ -477,7 +477,7 @@ def search_query_parts(data: schemas.SessionsSearchPayloadSchema, error_status, f_k = f"f_value{i}" full_args = {**full_args, **sh.multi_values(f.value, value_key=f_k)} op = sh.get_sql_operator(f.operator) \ - if filter_type not in [schemas.FilterType.events_count] else f.operator + if filter_type not in [schemas.FilterType.events_count] else f.operator.value is_any = sh.isAny_opreator(f.operator) is_undefined = sh.isUndefined_operator(f.operator) if not is_any and not is_undefined and len(f.value) == 0: diff --git a/api/schemas/schemas.py b/api/schemas/schemas.py index 71bf46954..15b3af80f 100644 --- a/api/schemas/schemas.py +++ b/api/schemas/schemas.py @@ -700,7 +700,7 @@ class SessionSearchFilterSchema(BaseModel): else: raise ValueError(f"value should be of type PlatformType for {values.type} filter") elif values.type == FilterType.events_count: - if values.operator in MathOperator.has_value(values.operator): + if MathOperator.has_value(values.operator): values.operator = MathOperator(values.operator) else: raise ValueError(f"operator should be of type MathOperator for {values.type} filter") diff --git a/ee/api/chalicelib/core/heatmaps.py b/ee/api/chalicelib/core/heatmaps.py index 5dd0acead..c156914bc 100644 --- a/ee/api/chalicelib/core/heatmaps.py +++ b/ee/api/chalicelib/core/heatmaps.py @@ -163,14 +163,29 @@ if not config("EXP_SESSIONS_SEARCH", cast=bool, default=False): include_mobs: bool = True, exclude_sessions: list[str] = [], _depth: int = 3): no_platform = True + no_location = True for f in data.filters: if f.type == schemas.FilterType.platform: no_platform = False break + for f in data.events: + if f.type == schemas.EventType.location: + no_location = False + if len(f.value) == 0: + f.operator = schemas.SearchEventOperator._is_any + break if no_platform: data.filters.append(schemas.SessionSearchFilterSchema(type=schemas.FilterType.platform, value=[schemas.PlatformType.desktop], operator=schemas.SearchEventOperator._is)) + if no_location: + data.events.append(schemas.SessionSearchEventSchema2(type=schemas.EventType.location, + value=[], + operator=schemas.SearchEventOperator._is_any)) + + data.filters.append(schemas.SessionSearchFilterSchema(type=schemas.FilterType.events_count, + value=[0], + operator=schemas.MathOperator._greater)) full_args, query_part = sessions.search_query_parts(data=data, error_status=None, errors_only=False, favorite_only=data.bookmarked, issue=None, @@ -214,7 +229,9 @@ if not config("EXP_SESSIONS_SEARCH", cast=bool, default=False): elif _depth == 0 and len(session['domURL']) == 0 and len(session['mobsUrl']) == 0: logger.info("couldn't find an existing replay after 3 iterations for heatmap") - session['events'] = get_page_events(session_id=session["session_id"]) + session['events'] = get_page_events(session_id=session["session_id"]) + else: + logger.debug("No session found for heatmap") return helper.dict_to_camel_case(session) @@ -277,14 +294,29 @@ else: include_mobs: bool = True, exclude_sessions: list[str] = [], _depth: int = 3): no_platform = True + no_location = True for f in data.filters: if f.type == schemas.FilterType.platform: no_platform = False break + for f in data.events: + if f.type == schemas.EventType.location: + no_location = False + if len(f.value) == 0: + f.operator = schemas.SearchEventOperator._is_any + break if no_platform: data.filters.append(schemas.SessionSearchFilterSchema(type=schemas.FilterType.platform, value=[schemas.PlatformType.desktop], operator=schemas.SearchEventOperator._is)) + if no_location: + data.events.append(schemas.SessionSearchEventSchema2(type=schemas.EventType.location, + value=[], + operator=schemas.SearchEventOperator._is_any)) + + data.filters.append(schemas.SessionSearchFilterSchema(type=schemas.FilterType.events_count, + value=[0], + operator=schemas.MathOperator._greater)) full_args, query_part = sessions.search_query_parts_ch(data=data, error_status=None, errors_only=False, favorite_only=data.bookmarked, issue=None, diff --git a/ee/api/chalicelib/core/sessions_exp.py b/ee/api/chalicelib/core/sessions_exp.py index aeef72d23..4dd3f0d13 100644 --- a/ee/api/chalicelib/core/sessions_exp.py +++ b/ee/api/chalicelib/core/sessions_exp.py @@ -616,7 +616,7 @@ def search_query_parts_ch(data: schemas.SessionsSearchPayloadSchema, error_statu f_k = f"f_value{i}" full_args = {**full_args, f_k: f.value, **_multiple_values(f.value, value_key=f_k)} op = __get_sql_operator(f.operator) \ - if filter_type not in [schemas.FilterType.events_count] else f.operator + if filter_type not in [schemas.FilterType.events_count] else f.operator.value is_any = _isAny_opreator(f.operator) is_undefined = _isUndefined_operator(f.operator) if not is_any and not is_undefined and len(f.value) == 0: diff --git a/ee/scripts/schema/db/init_dbs/postgresql/1.19.0/1.19.0.sql b/ee/scripts/schema/db/init_dbs/postgresql/1.19.0/1.19.0.sql index 1b6638e67..91f852ecc 100644 --- a/ee/scripts/schema/db/init_dbs/postgresql/1.19.0/1.19.0.sql +++ b/ee/scripts/schema/db/init_dbs/postgresql/1.19.0/1.19.0.sql @@ -22,6 +22,18 @@ ALTER TABLE IF EXISTS events.clicks ADD COLUMN IF NOT EXISTS normalized_x smallint NULL, ADD COLUMN IF NOT EXISTS normalized_y smallint NULL; +UPDATE public.metrics +SET default_config=default_config || '{"col":2}' +WHERE metric_type = 'webVitals' + AND default_config ->> 'col' = '1'; + +UPDATE public.dashboard_widgets +SET config=config || '{"col":2}' +WHERE metric_id IN (SELECT metric_id + FROM public.metrics + WHERE metric_type = 'webVitals') + AND config ->> 'col' = '1'; + COMMIT; \elif :is_next diff --git a/scripts/schema/db/init_dbs/postgresql/1.19.0/1.19.0.sql b/scripts/schema/db/init_dbs/postgresql/1.19.0/1.19.0.sql index 04140e0a4..0c8f79f9c 100644 --- a/scripts/schema/db/init_dbs/postgresql/1.19.0/1.19.0.sql +++ b/scripts/schema/db/init_dbs/postgresql/1.19.0/1.19.0.sql @@ -22,6 +22,17 @@ ALTER TABLE IF EXISTS events.clicks ADD COLUMN IF NOT EXISTS normalized_x smallint NULL, ADD COLUMN IF NOT EXISTS normalized_y smallint NULL; +UPDATE public.metrics +SET default_config=default_config || '{"col":2}' +WHERE metric_type = 'webVitals' + AND default_config ->> 'col' = '1'; + +UPDATE public.dashboard_widgets +SET config=config || '{"col":2}' +WHERE metric_id IN (SELECT metric_id + FROM public.metrics + WHERE metric_type = 'webVitals') + AND config ->> 'col' = '1'; COMMIT;