* refactor(chalice): refactored code

* refactor(DB): changed delta

* refactor(chalice): product analytics log refactoring
This commit is contained in:
Kraiem Taha Yassine 2025-02-18 16:37:37 +01:00 committed by GitHub
parent e996600dc8
commit 3ed8b3c27d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 19 additions and 17 deletions

View file

@ -487,10 +487,12 @@ WITH {initial_sessions_cte}
SELECT * SELECT *
FROM pre_ranked_events;""" FROM pre_ranked_events;"""
logger.debug("---------Q1-----------") logger.debug("---------Q1-----------")
ch.execute(query=ch_query1, parameters=params) ch_query1 = ch.format(query=ch_query1, parameters=params)
logger.debug(ch_query1)
ch.execute(query=ch_query1)
if time() - _now > 2: if time() - _now > 2:
logger.warning(f">>>>>>>>>PathAnalysis long query EE ({int(time() - _now)}s)<<<<<<<<<") logger.warning(f">>>>>>>>>PathAnalysis long query EE ({int(time() - _now)}s)<<<<<<<<<")
logger.warning(ch.format(query=ch_query1, parameters=params)) logger.warning(ch_query1)
logger.warning("----------------------") logger.warning("----------------------")
_now = time() _now = time()
@ -512,10 +514,11 @@ SELECT *
FROM ranked_events FROM ranked_events
{q2_extra_condition if q2_extra_condition else ""};""" {q2_extra_condition if q2_extra_condition else ""};"""
logger.debug("---------Q2-----------") logger.debug("---------Q2-----------")
ch.execute(query=ch_query2, parameters=params) ch_query2 = ch.format(query=ch_query2, parameters=params)
ch.execute(query=ch_query2)
if time() - _now > 2: if time() - _now > 2:
logger.warning(f">>>>>>>>>PathAnalysis long query EE ({int(time() - _now)}s)<<<<<<<<<") logger.warning(f">>>>>>>>>PathAnalysis long query EE ({int(time() - _now)}s)<<<<<<<<<")
logger.warning(ch.format(query=ch_query2, parameters=params)) logger.warning(ch_query2)
logger.warning("----------------------") logger.warning("----------------------")
_now = time() _now = time()
@ -625,10 +628,12 @@ FROM ranked_events
) AS chart_steps ) AS chart_steps
ORDER BY event_number_in_session, sessions_count DESC;""" ORDER BY event_number_in_session, sessions_count DESC;"""
logger.debug("---------Q3-----------") logger.debug("---------Q3-----------")
rows = ch.execute(query=ch_query3, parameters=params) ch_query3 = ch.format(query=ch_query3, parameters=params)
logger.debug(ch_query3)
rows = ch.execute(query=ch_query3)
if time() - _now > 2: if time() - _now > 2:
logger.warning(f">>>>>>>>>PathAnalysis long query EE ({int(time() - _now)}s)<<<<<<<<<") logger.warning(f">>>>>>>>>PathAnalysis long query EE ({int(time() - _now)}s)<<<<<<<<<")
logger.warning(ch.format(query=ch_query3, parameters=params)) logger.warning(ch_query3)
logger.warning("----------------------") logger.warning("----------------------")
return __transform_journey(rows=rows, reverse_path=reverse) return __transform_journey(rows=rows, reverse_path=reverse)

View file

@ -2,8 +2,6 @@ from typing import List
def get_step_size(startTimestamp, endTimestamp, density, decimal=False, factor=1000): def get_step_size(startTimestamp, endTimestamp, density, decimal=False, factor=1000):
print("-------density:")
print(density)
step_size = (endTimestamp // factor - startTimestamp // factor) step_size = (endTimestamp // factor - startTimestamp // factor)
if density <= 1: if density <= 1:
return step_size return step_size
@ -17,7 +15,6 @@ def complete_missing_steps(rows: List[dict], start_timestamp: int, end_timestamp
result = [] result = []
i = 0 i = 0
for t in range(start_timestamp, end_timestamp, step): for t in range(start_timestamp, end_timestamp, step):
print(t)
if i >= len(rows) or rows[i][time_key] > t: if i >= len(rows) or rows[i][time_key] > t:
neutral[time_key] = t neutral[time_key] = t
result.append(neutral.copy()) result.append(neutral.copy())

View file

@ -27,10 +27,10 @@ DROP TABLE IF EXISTS public.user_favorite_errors;
DROP TABLE IF EXISTS public.user_viewed_errors; DROP TABLE IF EXISTS public.user_viewed_errors;
ALTER TABLE IF EXISTS public.sessions_notes ALTER TABLE IF EXISTS public.sessions_notes
ADD COLUMN start_at integer, ADD COLUMN IF NOT EXISTS start_at integer,
ADD COLUMN end_at integer, ADD COLUMN IF NOT EXISTS end_at integer,
ADD COLUMN thumbnail text, ADD COLUMN IF NOT EXISTS thumbnail text,
ADD COLUMN updated_at timestamp DEFAULT NULL, ADD COLUMN IF NOT EXISTS updated_at timestamp DEFAULT NULL,
ALTER COLUMN message DROP NOT NULL; ALTER COLUMN message DROP NOT NULL;
DELETE DELETE

View file

@ -27,10 +27,10 @@ DROP TABLE IF EXISTS public.user_favorite_errors;
DROP TABLE IF EXISTS public.user_viewed_errors; DROP TABLE IF EXISTS public.user_viewed_errors;
ALTER TABLE IF EXISTS public.sessions_notes ALTER TABLE IF EXISTS public.sessions_notes
ADD COLUMN start_at integer, ADD COLUMN IF NOT EXISTS start_at integer,
ADD COLUMN end_at integer, ADD COLUMN IF NOT EXISTS end_at integer,
ADD COLUMN thumbnail text, ADD COLUMN IF NOT EXISTS thumbnail text,
ADD COLUMN updated_at timestamp DEFAULT NULL, ADD COLUMN IF NOT EXISTS updated_at timestamp DEFAULT NULL,
ALTER COLUMN message DROP NOT NULL; ALTER COLUMN message DROP NOT NULL;
DELETE DELETE