From 4a347139ba7c0d8167bba34970f04be80ecc17c9 Mon Sep 17 00:00:00 2001 From: Kraiem Taha Yassine Date: Wed, 3 May 2023 15:52:02 +0200 Subject: [PATCH] feat(chalice): reduce issues for replay (#1227) --- api/chalicelib/core/sessions_replay.py | 24 +++++++++++++++++++++++ ee/api/chalicelib/core/sessions_replay.py | 24 +++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/api/chalicelib/core/sessions_replay.py b/api/chalicelib/core/sessions_replay.py index 68991ceca..f27903a54 100644 --- a/api/chalicelib/core/sessions_replay.py +++ b/api/chalicelib/core/sessions_replay.py @@ -185,6 +185,30 @@ def get_events(project_id, session_id): start_ts=s_data["startTs"], duration=s_data["duration"]) data['issues'] = issues.get_by_session_id(session_id=session_id, project_id=project_id) + data['issues'] = reduce_issues(data['issues']) return data else: return None + + +# To reduce the number of issues in the replay; +# will be removed once we agree on how to show issues +def reduce_issues(issues_list): + if issues_list is None: + return None + i = 0 + # remove same-type issues if the time between them is <2s + while i < len(issues_list) - 1: + for j in range(i+1,len(issues_list)): + if issues_list[i]["type"] == issues_list[j]["type"]: + break + else: + i+=1 + break + + if issues_list[i]["timestamp"] - issues_list[j]["timestamp"] < 2000: + issues_list.pop(j) + else: + i += 1 + + return issues_list diff --git a/ee/api/chalicelib/core/sessions_replay.py b/ee/api/chalicelib/core/sessions_replay.py index c3ecbca9d..1ba4242ad 100644 --- a/ee/api/chalicelib/core/sessions_replay.py +++ b/ee/api/chalicelib/core/sessions_replay.py @@ -190,6 +190,30 @@ def get_events(project_id, session_id): start_ts=s_data["startTs"], duration=s_data["duration"]) data['issues'] = issues.get_by_session_id(session_id=session_id, project_id=project_id) + data['issues'] = reduce_issues(data['issues']) return data else: return None + + +# To reduce the number of issues in the replay; +# will be removed once we agree on how to show issues +def reduce_issues(issues_list): + if issues_list is None: + return None + i = 0 + # remove same-type issues if the time between them is <2s + while i < len(issues_list) - 1: + for j in range(i + 1, len(issues_list)): + if issues_list[i]["type"] == issues_list[j]["type"]: + break + else: + i += 1 + break + + if issues_list[i]["timestamp"] - issues_list[j]["timestamp"] < 2000: + issues_list.pop(j) + else: + i += 1 + + return issues_list