Skip to content

Commit

Permalink
Add matched recordings to trends actors query
Browse files Browse the repository at this point in the history
  • Loading branch information
webjunkie committed Mar 20, 2024
1 parent 0c5b8cb commit 3e52fb1
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 3 deletions.
8 changes: 8 additions & 0 deletions frontend/src/scenes/insights/views/BoldNumber/BoldNumber.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ export function BoldNumber({ showPersonsModal = true }: ChartParams): JSX.Elemen
kind: NodeKind.InsightActorsQuery,
source: query.source,
},
additionalSelect: {
value_at_data_point: 'event_count',
matched_recordings: 'matched_recordings',
},
})
} else if (resultSeries.persons?.url) {
openPersonsModal({
Expand Down Expand Up @@ -213,6 +217,10 @@ function BoldNumberComparison({ showPersonsModal }: Pick<ChartParams, 'showPerso
kind: NodeKind.InsightActorsQuery,
source: query.source,
},
additionalSelect: {
value_at_data_point: 'event_count',
matched_recordings: 'matched_recordings',
},
})
} else if (previousPeriodSeries.persons?.url) {
openPersonsModal({
Expand Down
1 change: 1 addition & 0 deletions frontend/src/scenes/trends/persons-modal/PersonsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ export function ActorRow({ actor, onOpenRecording, propertiesTimelineFilter }: A
onClick={onOpenRecordingClick}
sideIcon={matchedRecordings.length === 1 ? <IconPlayCircle /> : null}
type="secondary"
status={matchedRecordings.length > 1 ? 'alt' : undefined}
size="small"
>
{matchedRecordings.length > 1 ? `${matchedRecordings.length} recordings` : 'View recording'}
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/scenes/trends/viz/ActionsHorizontalBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ export function ActionsHorizontalBar({ showPersonsModal = true }: ChartParams):
kind: NodeKind.InsightActorsQuery,
source: query.source,
},
additionalSelect: {
value_at_data_point: 'event_count',
matched_recordings: 'matched_recordings',
},
})
} else if (selectedUrl) {
openPersonsModal({
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/scenes/trends/viz/ActionsLineGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ export function ActionsLineGraph({
breakdown: dataset.breakdown_value,
compare: dataset.compare_label,
},
additionalSelect: {
value_at_data_point: 'event_count',
matched_recordings: 'matched_recordings',
},
})
} else {
const datasetUrls = urlsForDatasets(
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/scenes/trends/viz/ActionsPie.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ export function ActionsPie({
kind: NodeKind.InsightActorsQuery,
source: query.source,
},
additionalSelect: {
value_at_data_point: 'event_count',
matched_recordings: 'matched_recordings',
},
})
} else if (selectedUrl) {
openPersonsModal({
Expand Down
15 changes: 12 additions & 3 deletions posthog/hogql_queries/insights/trends/trends_query_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,12 @@ def build_actors_query(

return parse_select(
"""
SELECT DISTINCT actor_id
SELECT
actor_id,
count() as event_count,
groupUniqArray(100)((timestamp, uuid, $session_id, $window_id)) as matching_events
FROM {subquery}
GROUP BY actor_id
""",
placeholders={
"subquery": self._get_events_subquery(
Expand Down Expand Up @@ -225,8 +229,13 @@ def _get_events_subquery(

# TODO: Move this logic into the below branches when working on adding breakdown support for the person modal
if is_actors_query:
default_query.select = [ast.Alias(alias="actor_id", expr=self._aggregation_operation.actor_id())]
default_query.distinct = True
default_query.select = [
ast.Alias(alias="actor_id", expr=self._aggregation_operation.actor_id()),
ast.Field(chain=["e", "timestamp"]),
ast.Field(chain=["e", "uuid"]),
ast.Field(chain=["e", "$session_id"]),
ast.Field(chain=["e", "$window_id"]),
]
default_query.group_by = []

# No breakdowns and no complex series aggregation
Expand Down

0 comments on commit 3e52fb1

Please sign in to comment.