refactor(chalice): hide minor paths for Path Analysis in dashboard page
This commit is contained in:
parent
a4f6a93c59
commit
dcf6fdb1c9
2 changed files with 42 additions and 29 deletions
|
|
@ -241,14 +241,13 @@ def create_card(project: schemas.ProjectContext, user_id, data: schemas.CardSche
|
||||||
params["card_info"] = json.dumps(params["card_info"])
|
params["card_info"] = json.dumps(params["card_info"])
|
||||||
|
|
||||||
query = """INSERT INTO metrics (project_id, user_id, name, is_public,
|
query = """INSERT INTO metrics (project_id, user_id, name, is_public,
|
||||||
view_type, metric_type, metric_of, metric_value,
|
view_type, metric_type, metric_of, metric_value,
|
||||||
metric_format, default_config, thumbnail, data,
|
metric_format, default_config, thumbnail, data,
|
||||||
card_info)
|
card_info)
|
||||||
VALUES (%(project_id)s, %(user_id)s, %(name)s, %(is_public)s,
|
VALUES (%(project_id)s, %(user_id)s, %(name)s, %(is_public)s,
|
||||||
%(view_type)s, %(metric_type)s, %(metric_of)s, %(metric_value)s,
|
%(view_type)s, %(metric_type)s, %(metric_of)s, %(metric_value)s,
|
||||||
%(metric_format)s, %(default_config)s, %(thumbnail)s, %(session_data)s,
|
%(metric_format)s, %(default_config)s, %(thumbnail)s, %(session_data)s,
|
||||||
%(card_info)s)
|
%(card_info)s) RETURNING metric_id"""
|
||||||
RETURNING metric_id"""
|
|
||||||
if len(data.series) > 0:
|
if len(data.series) > 0:
|
||||||
query = f"""WITH m AS ({query})
|
query = f"""WITH m AS ({query})
|
||||||
INSERT INTO metric_series(metric_id, index, name, filter)
|
INSERT INTO metric_series(metric_id, index, name, filter)
|
||||||
|
|
@ -525,13 +524,13 @@ def get_all(project_id, user_id):
|
||||||
def delete_card(project_id, metric_id, user_id):
|
def delete_card(project_id, metric_id, user_id):
|
||||||
with pg_client.PostgresClient() as cur:
|
with pg_client.PostgresClient() as cur:
|
||||||
cur.execute(
|
cur.execute(
|
||||||
cur.mogrify("""\
|
cur.mogrify(""" \
|
||||||
UPDATE public.metrics
|
UPDATE public.metrics
|
||||||
SET deleted_at = timezone('utc'::text, now()), edited_at = timezone('utc'::text, now())
|
SET deleted_at = timezone('utc'::text, now()),
|
||||||
WHERE project_id = %(project_id)s
|
edited_at = timezone('utc'::text, now())
|
||||||
AND metric_id = %(metric_id)s
|
WHERE project_id = %(project_id)s
|
||||||
AND (user_id = %(user_id)s OR is_public)
|
AND metric_id = %(metric_id)s
|
||||||
RETURNING data;""",
|
AND (user_id = %(user_id)s OR is_public) RETURNING data;""",
|
||||||
{"metric_id": metric_id, "project_id": project_id, "user_id": user_id})
|
{"metric_id": metric_id, "project_id": project_id, "user_id": user_id})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -615,13 +614,14 @@ def get_series_for_alert(project_id, user_id):
|
||||||
FALSE AS predefined,
|
FALSE AS predefined,
|
||||||
metric_id,
|
metric_id,
|
||||||
series_id
|
series_id
|
||||||
FROM metric_series
|
FROM metric_series
|
||||||
INNER JOIN metrics USING (metric_id)
|
INNER JOIN metrics USING (metric_id)
|
||||||
WHERE metrics.deleted_at ISNULL
|
WHERE metrics.deleted_at ISNULL
|
||||||
AND metrics.project_id = %(project_id)s
|
AND metrics.project_id = %(project_id)s
|
||||||
AND metrics.metric_type = 'timeseries'
|
AND metrics.metric_type = 'timeseries'
|
||||||
AND (user_id = %(user_id)s OR is_public)
|
AND (user_id = %(user_id)s
|
||||||
ORDER BY name;""",
|
OR is_public)
|
||||||
|
ORDER BY name;""",
|
||||||
{"project_id": project_id, "user_id": user_id}
|
{"project_id": project_id, "user_id": user_id}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
@ -632,11 +632,11 @@ def get_series_for_alert(project_id, user_id):
|
||||||
def change_state(project_id, metric_id, user_id, status):
|
def change_state(project_id, metric_id, user_id, status):
|
||||||
with pg_client.PostgresClient() as cur:
|
with pg_client.PostgresClient() as cur:
|
||||||
cur.execute(
|
cur.execute(
|
||||||
cur.mogrify("""\
|
cur.mogrify(""" \
|
||||||
UPDATE public.metrics
|
UPDATE public.metrics
|
||||||
SET active = %(status)s
|
SET active = %(status)s
|
||||||
WHERE metric_id = %(metric_id)s
|
WHERE metric_id = %(metric_id)s
|
||||||
AND (user_id = %(user_id)s OR is_public);""",
|
AND (user_id = %(user_id)s OR is_public);""",
|
||||||
{"metric_id": metric_id, "status": status, "user_id": user_id})
|
{"metric_id": metric_id, "status": status, "user_id": user_id})
|
||||||
)
|
)
|
||||||
return get_card(metric_id=metric_id, project_id=project_id, user_id=user_id)
|
return get_card(metric_id=metric_id, project_id=project_id, user_id=user_id)
|
||||||
|
|
@ -674,7 +674,8 @@ def get_funnel_sessions_by_issue(user_id, project_id, metric_id, issue_id,
|
||||||
"issue": issue}
|
"issue": issue}
|
||||||
|
|
||||||
|
|
||||||
def make_chart_from_card(project: schemas.ProjectContext, user_id, metric_id, data: schemas.CardSessionsSchema):
|
def make_chart_from_card(project: schemas.ProjectContext, user_id, metric_id,
|
||||||
|
data: schemas.CardSessionsSchema, for_dashboard: bool = False):
|
||||||
raw_metric: dict = get_card(metric_id=metric_id, project_id=project.project_id, user_id=user_id, include_data=True)
|
raw_metric: dict = get_card(metric_id=metric_id, project_id=project.project_id, user_id=user_id, include_data=True)
|
||||||
|
|
||||||
if raw_metric is None:
|
if raw_metric is None:
|
||||||
|
|
@ -693,7 +694,8 @@ def make_chart_from_card(project: schemas.ProjectContext, user_id, metric_id, da
|
||||||
return heatmaps.search_short_session(project_id=project.project_id,
|
return heatmaps.search_short_session(project_id=project.project_id,
|
||||||
data=schemas.HeatMapSessionsSearch(**metric.model_dump()),
|
data=schemas.HeatMapSessionsSearch(**metric.model_dump()),
|
||||||
user_id=user_id)
|
user_id=user_id)
|
||||||
|
elif metric.metric_type == schemas.MetricType.PATH_ANALYSIS and for_dashboard:
|
||||||
|
metric.hide_excess = True
|
||||||
return get_chart(project=project, data=metric, user_id=user_id)
|
return get_chart(project=project, data=metric, user_id=user_id)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -219,6 +219,17 @@ def get_card_chart(projectId: int, metric_id: int, data: schemas.CardSessionsSch
|
||||||
return {"data": data}
|
return {"data": data}
|
||||||
|
|
||||||
|
|
||||||
|
@app.post("/{projectId}/dashboards/{dashboardId}/cards/{metric_id}/chart", tags=["card"])
|
||||||
|
@app.post("/{projectId}/dashboards/{dashboardId}/cards/{metric_id}", tags=["card"])
|
||||||
|
def get_card_chart_for_dashboard(projectId: int, dashboardId: int, metric_id: int,
|
||||||
|
data: schemas.CardSessionsSchema = Body(...),
|
||||||
|
context: schemas.CurrentContext = Depends(OR_context)):
|
||||||
|
data = custom_metrics.make_chart_from_card(
|
||||||
|
project=context.project, user_id=context.user_id, metric_id=metric_id, data=data, for_dashboard=True
|
||||||
|
)
|
||||||
|
return {"data": data}
|
||||||
|
|
||||||
|
|
||||||
@app.post("/{projectId}/cards/{metric_id}", tags=["dashboard"])
|
@app.post("/{projectId}/cards/{metric_id}", tags=["dashboard"])
|
||||||
def update_card(projectId: int, metric_id: int, data: schemas.CardSchema = Body(...),
|
def update_card(projectId: int, metric_id: int, data: schemas.CardSchema = Body(...),
|
||||||
context: schemas.CurrentContext = Depends(OR_context)):
|
context: schemas.CurrentContext = Depends(OR_context)):
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue