From fc898f427c9e8b1b04b24714063970afd93612c4 Mon Sep 17 00:00:00 2001 From: Taha Yassine Kraiem Date: Mon, 1 Jul 2024 17:45:51 +0200 Subject: [PATCH] refactor(chalice): search for sessions that have at least 1 location event for heatmaps --- api/chalicelib/core/heatmaps.py | 13 +++++++++++++ ee/api/chalicelib/core/heatmaps.py | 26 +++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/api/chalicelib/core/heatmaps.py b/api/chalicelib/core/heatmaps.py index 1f572c62db..12a91ea912 100644 --- a/api/chalicelib/core/heatmaps.py +++ b/api/chalicelib/core/heatmaps.py @@ -147,14 +147,25 @@ 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], @@ -203,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/ee/api/chalicelib/core/heatmaps.py b/ee/api/chalicelib/core/heatmaps.py index 1fb11c68cf..c156914bc6 100644 --- a/ee/api/chalicelib/core/heatmaps.py +++ b/ee/api/chalicelib/core/heatmaps.py @@ -163,14 +163,25 @@ 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], @@ -218,7 +229,9 @@ def search_short_session(data: schemas.ClickMapSessionsSearch, project_id, user_ 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) @@ -281,14 +294,25 @@ 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],