refactor(chalice): changed filters response
This commit is contained in:
parent
c8f7a2e453
commit
ca16a90f52
4 changed files with 169 additions and 28 deletions
|
|
@ -16,20 +16,19 @@ PREDEFINED_EVENTS = [
|
|||
]
|
||||
|
||||
|
||||
def get_events(project_id: int, page: schemas.PaginatedSchema):
|
||||
def get_events(project_id: int):
|
||||
with ClickHouseClient() as ch_client:
|
||||
r = ch_client.format(
|
||||
"""SELECT DISTINCT
|
||||
""" \
|
||||
SELECT DISTINCT
|
||||
ON(event_name,auto_captured)
|
||||
COUNT (1) OVER () AS total,
|
||||
event_name AS name, display_name, description,
|
||||
auto_captured
|
||||
FROM product_analytics.all_events
|
||||
WHERE project_id=%(project_id)s
|
||||
ORDER BY auto_captured, display_name
|
||||
LIMIT %(limit)s
|
||||
OFFSET %(offset)s;""",
|
||||
parameters={"project_id": project_id, "limit": page.limit, "offset": (page.page - 1) * page.limit})
|
||||
ORDER BY auto_captured, display_name, event_name;""",
|
||||
parameters={"project_id": project_id})
|
||||
rows = ch_client.execute(r)
|
||||
if len(rows) == 0:
|
||||
return {"total": len(PREDEFINED_EVENTS), "list": [{
|
||||
|
|
|
|||
148
api/chalicelib/core/product_analytics/filters.py
Normal file
148
api/chalicelib/core/product_analytics/filters.py
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
import schemas
|
||||
|
||||
|
||||
def get_sessions_filters(project_id: int):
|
||||
return {"total": 13,
|
||||
"list": [
|
||||
{
|
||||
"id": "sf_1",
|
||||
"name": schemas.FilterType.REFERRER,
|
||||
"displayName": "Referrer",
|
||||
"possibleTypes": [
|
||||
"String"
|
||||
],
|
||||
"autoCaptured": True
|
||||
},
|
||||
{
|
||||
"id": "sf_2",
|
||||
"name": schemas.FilterType.DURATION,
|
||||
"displayName": "Duration",
|
||||
"possibleTypes": [
|
||||
"int"
|
||||
],
|
||||
"autoCaptured": True
|
||||
},
|
||||
{
|
||||
"id": "sf_3",
|
||||
"name": schemas.FilterType.UTM_SOURCE,
|
||||
"displayName": "UTM Source",
|
||||
"possibleTypes": [
|
||||
"string"
|
||||
],
|
||||
"autoCaptured": True
|
||||
},
|
||||
{
|
||||
"id": "sf_4",
|
||||
"name": schemas.FilterType.UTM_MEDIUM,
|
||||
"displayName": "UTM Medium",
|
||||
"possibleTypes": [
|
||||
"string"
|
||||
],
|
||||
"autoCaptured": True
|
||||
},
|
||||
{
|
||||
"id": "sf_5",
|
||||
"name": schemas.FilterType.UTM_CAMPAIGN,
|
||||
"displayName": "UTM Campaign",
|
||||
"possibleTypes": [
|
||||
"string"
|
||||
],
|
||||
"autoCaptured": True
|
||||
},
|
||||
{
|
||||
"id": "sf_6",
|
||||
"name": schemas.FilterType.USER_COUNTRY,
|
||||
"displayName": "Country",
|
||||
"possibleTypes": [
|
||||
"string"
|
||||
],
|
||||
"autoCaptured": True
|
||||
},
|
||||
{
|
||||
"id": "sf_7",
|
||||
"name": schemas.FilterType.USER_CITY,
|
||||
"displayName": "City",
|
||||
"possibleTypes": [
|
||||
"string"
|
||||
],
|
||||
"autoCaptured": True
|
||||
},
|
||||
{
|
||||
"id": "sf_8",
|
||||
"name": schemas.FilterType.USER_STATE,
|
||||
"displayName": "State / Province",
|
||||
"possibleTypes": [
|
||||
"string"
|
||||
],
|
||||
"autoCaptured": True
|
||||
},
|
||||
{
|
||||
"id": "sf_9",
|
||||
"name": schemas.FilterType.USER_OS,
|
||||
"displayName": "OS",
|
||||
"possibleTypes": [
|
||||
"string"
|
||||
],
|
||||
"autoCaptured": True
|
||||
},
|
||||
{
|
||||
"id": "sf_10",
|
||||
"name": schemas.FilterType.USER_BROWSER,
|
||||
"displayName": "Browser",
|
||||
"possibleTypes": [
|
||||
"string"
|
||||
],
|
||||
"autoCaptured": True
|
||||
},
|
||||
{
|
||||
"id": "sf_11",
|
||||
"name": schemas.FilterType.USER_DEVICE,
|
||||
"displayName": "Device",
|
||||
"possibleTypes": [
|
||||
"string"
|
||||
],
|
||||
"autoCaptured": True
|
||||
},
|
||||
{
|
||||
"id": "sf_12",
|
||||
"name": schemas.FilterType.PLATFORM,
|
||||
"displayName": "Platform",
|
||||
"possibleTypes": [
|
||||
"string"
|
||||
],
|
||||
"autoCaptured": True
|
||||
},
|
||||
{
|
||||
"id": "sf_13",
|
||||
"name": schemas.FilterType.REV_ID,
|
||||
"displayName": "Version ID",
|
||||
"possibleTypes": [
|
||||
"string"
|
||||
],
|
||||
"autoCaptured": True
|
||||
}
|
||||
]}
|
||||
|
||||
|
||||
def get_users_filters(project_id: int):
|
||||
return {"total": 2,
|
||||
"list": [
|
||||
{
|
||||
"id": "uf_1",
|
||||
"name": schemas.FilterType.USER_ID,
|
||||
"displayName": "User ID",
|
||||
"possibleTypes": [
|
||||
"string"
|
||||
],
|
||||
"autoCaptured": False
|
||||
},
|
||||
{
|
||||
"id": "uf_2",
|
||||
"name": schemas.FilterType.USER_ANONYMOUS_ID,
|
||||
"displayName": "User Anonymous ID",
|
||||
"possibleTypes": [
|
||||
"string"
|
||||
],
|
||||
"autoCaptured": False
|
||||
}
|
||||
]}
|
||||
|
|
@ -67,7 +67,7 @@ EVENT_DEFAULT_PROPERTIES = {
|
|||
}
|
||||
|
||||
|
||||
def get_all_properties(project_id: int, page: schemas.PaginatedSchema):
|
||||
def get_all_properties(project_id: int):
|
||||
with ClickHouseClient() as ch_client:
|
||||
r = ch_client.format(
|
||||
"""SELECT COUNT(1) OVER () AS total, property_name AS name,
|
||||
|
|
@ -77,12 +77,8 @@ def get_all_properties(project_id: int, page: schemas.PaginatedSchema):
|
|||
LEFT JOIN product_analytics.event_properties USING (project_id, property_name)
|
||||
WHERE all_properties.project_id = %(project_id)s
|
||||
GROUP BY property_name, display_name
|
||||
ORDER BY display_name
|
||||
LIMIT %(limit)s
|
||||
OFFSET %(offset)s;""",
|
||||
parameters={"project_id": project_id,
|
||||
"limit": page.limit,
|
||||
"offset": (page.page - 1) * page.limit})
|
||||
ORDER BY display_name, property_name;""",
|
||||
parameters={"project_id": project_id})
|
||||
properties = ch_client.execute(r)
|
||||
if len(properties) == 0:
|
||||
return {"total": 0, "list": []}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ from fastapi import Body, Depends, Query
|
|||
|
||||
import schemas
|
||||
from chalicelib.core import metadata
|
||||
from chalicelib.core.product_analytics import events, properties, autocomplete
|
||||
from chalicelib.core.product_analytics import events, properties, autocomplete, filters
|
||||
from or_dependencies import OR_context
|
||||
from routers.base import get_routers
|
||||
from typing import Optional
|
||||
|
|
@ -13,15 +13,13 @@ public_app, app, app_apikey = get_routers()
|
|||
|
||||
|
||||
@app.get('/{projectId}/filters', tags=["product_analytics"])
|
||||
def get_all_filters(projectId: int, filter_query: Annotated[schemas.PaginatedSchema, Query()],
|
||||
context: schemas.CurrentContext = Depends(OR_context)):
|
||||
# TODO: fix total attribute to return the total count instead of the total number of pages
|
||||
# TODO: no pagination, return everything
|
||||
# TODO: remove icon
|
||||
def get_all_filters(projectId: int, context: schemas.CurrentContext = Depends(OR_context)):
|
||||
return {
|
||||
"data": {
|
||||
"events": events.get_events(project_id=projectId, page=filter_query),
|
||||
"filters": properties.get_all_properties(project_id=projectId, page=filter_query),
|
||||
"events": events.get_events(project_id=projectId),
|
||||
"eventProperties": properties.get_all_properties(project_id=projectId),
|
||||
"sessionFilters": filters.get_sessions_filters(project_id=projectId),
|
||||
"userFilters": filters.get_users_filters(project_id=projectId),
|
||||
"metadata": metadata.get_for_filters(project_id=projectId)
|
||||
}
|
||||
}
|
||||
|
|
@ -30,7 +28,7 @@ def get_all_filters(projectId: int, filter_query: Annotated[schemas.PaginatedSch
|
|||
@app.get('/{projectId}/events/names', tags=["product_analytics"])
|
||||
def get_all_events(projectId: int, filter_query: Annotated[schemas.PaginatedSchema, Query()],
|
||||
context: schemas.CurrentContext = Depends(OR_context)):
|
||||
return {"data": events.get_events(project_id=projectId, page=filter_query)}
|
||||
return {"data": events.get_events(project_id=projectId)}
|
||||
|
||||
|
||||
@app.get('/{projectId}/properties/search', tags=["product_analytics"])
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue