Skip to content

Commit

Permalink
refactor(chalice): search for sessions that have at least 1 location …
Browse files Browse the repository at this point in the history
…event for heatmaps
  • Loading branch information
tahayk committed Jul 1, 2024
1 parent 5fedf1b commit fc898f4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
13 changes: 13 additions & 0 deletions api/chalicelib/core/heatmaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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)

Expand Down
26 changes: 25 additions & 1 deletion ee/api/chalicelib/core/heatmaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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],
Expand Down

0 comments on commit fc898f4

Please sign in to comment.