Skip to content

Commit

Permalink
feat(chalice): table of referrers
Browse files Browse the repository at this point in the history
  • Loading branch information
tahayk committed Aug 9, 2024
1 parent 5c5ff70 commit d757356
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions api/chalicelib/core/custom_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ def __get_table_of_urls(project_id: int, data: schemas.CardTable, user_id: int =
return __get_table_of_series(project_id=project_id, data=data)


def __get_table_of_referrers(project_id: int, data: schemas.CardTable, user_id: int = None):
return __get_table_of_series(project_id=project_id, data=data)


def __get_table_chart(project_id: int, data: schemas.CardTable, user_id: int):
supported = {
schemas.MetricOfTable.SESSIONS: __get_table_of_sessions,
Expand All @@ -147,6 +151,7 @@ def __get_table_chart(project_id: int, data: schemas.CardTable, user_id: int):
schemas.MetricOfTable.USER_DEVICE: __get_table_of_devises,
schemas.MetricOfTable.USER_COUNTRY: __get_table_of_countries,
schemas.MetricOfTable.VISITED_URL: __get_table_of_urls,
schemas.MetricOfTable.REFERRER: __get_table_of_referrers,
}
return supported.get(data.metric_of, not_supported)(project_id=project_id, data=data, user_id=user_id)

Expand Down
8 changes: 6 additions & 2 deletions api/chalicelib/core/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,13 @@ def search2_table(data: schemas.SessionsSearchPayloadSchema, project_id: int, de
main_col = "path"
extra_col = ", path"
distinct_on += ",path"
elif metric_of == schemas.MetricOfTable.REFERRER:
main_col = "referrer"
extra_col = ", referrer"

if metric_format == schemas.MetricExtendedFormatType.SESSION_COUNT:
main_query = f"""SELECT COUNT(*) AS count,
COALESCE(SUM(users_sessions.session_count),0) AS count,
COALESCE(SUM(users_sessions.total),0) AS total,
COALESCE(JSONB_AGG(users_sessions)
FILTER ( WHERE rn > %(limit_s)s
AND rn <= %(limit_e)s ), '[]'::JSONB) AS values
Expand All @@ -376,7 +380,7 @@ def search2_table(data: schemas.SessionsSearchPayloadSchema, project_id: int, de
) AS full_sessions
{extra_where}
GROUP BY {main_col}
ORDER BY session_count DESC) AS users_sessions;"""
ORDER BY total DESC) AS users_sessions;"""
else:
main_query = f"""SELECT COUNT(*) AS count,
COALESCE(SUM(users_sessions.user_count),0) AS count,
Expand Down
1 change: 1 addition & 0 deletions api/schemas/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,7 @@ class MetricOfTable(str, Enum):
VISITED_URL = "location"
SESSIONS = "sessions"
ERRORS = "jsException"
REFERRER = "referrer"


class MetricOfTimeseries(str, Enum):
Expand Down

0 comments on commit d757356

Please sign in to comment.