-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(insights): support cohort filters in lifecycle insight
- Loading branch information
1 parent
409a5b9
commit 0ac72e9
Showing
9 changed files
with
162 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
posthog/hogql_queries/insights/test/__snapshots__/test_lifecycle_query_runner.ambr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
PropertyOperator, | ||
PersonPropertyFilter, | ||
ActionsNode, | ||
CohortPropertyFilter, | ||
) | ||
from posthog.test.base import ( | ||
APIBaseTest, | ||
|
@@ -22,7 +23,7 @@ | |
flush_persons_and_events, | ||
snapshot_clickhouse_queries, | ||
) | ||
from posthog.models import Action, ActionStep | ||
from posthog.models import Action, ActionStep, Cohort | ||
from posthog.models.instance_setting import get_instance_setting | ||
|
||
|
||
|
@@ -1252,6 +1253,55 @@ def test_sampling(self): | |
), | ||
).calculate() | ||
|
||
@snapshot_clickhouse_queries | ||
def test_cohort_filter(self): | ||
self._create_events( | ||
data=[ | ||
( | ||
"p1", | ||
[ | ||
"2020-01-11T12:00:00Z", | ||
"2020-01-12T12:00:00Z", | ||
"2020-01-13T12:00:00Z", | ||
"2020-01-15T12:00:00Z", | ||
"2020-01-17T12:00:00Z", | ||
"2020-01-19T12:00:00Z", | ||
], | ||
), | ||
("p2", ["2020-01-09T12:00:00Z", "2020-01-12T12:00:00Z"]), | ||
("p3", ["2020-01-12T12:00:00Z"]), | ||
("p4", ["2020-01-15T12:00:00Z"]), | ||
] | ||
) | ||
flush_persons_and_events() | ||
cohort = Cohort.objects.create( | ||
team=self.team, | ||
groups=[ | ||
{ | ||
"properties": [ | ||
{ | ||
"key": "email", | ||
"value": ["[email protected]"], | ||
"type": "person", | ||
"operator": "exact", | ||
} | ||
] | ||
} | ||
], | ||
) | ||
cohort.calculate_people_ch(pending_version=0) | ||
response = LifecycleQueryRunner( | ||
team=self.team, | ||
query=LifecycleQuery( | ||
dateRange=DateRange(date_from="2020-01-12T00:00:00Z", date_to="2020-01-19T00:00:00Z"), | ||
interval=IntervalType.day, | ||
series=[EventsNode(event="$pageview")], | ||
properties=[CohortPropertyFilter(value=cohort.pk)], | ||
), | ||
).calculate() | ||
counts = [r["count"] for r in response.results] | ||
assert counts == [0, 2, 3, -3] | ||
|
||
|
||
def assertLifecycleResults(results, expected): | ||
sorted_results = [{"status": r["status"], "data": r["data"]} for r in sorted(results, key=lambda r: r["status"])] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters