def test_groups_aggregating(self): self._create_groups_and_events() filter = RetentionFilter( data={ "date_to": self._date(10, month=1, hour=0), "period": "Week", "total_intervals": 7, "aggregation_group_type_index": 0, }, team=self.team, ) result = ClickhouseRetention().run(filter, self.team) self.assertEqual( self.pluck(result, "values", "count"), [ [2, 2, 1, 2, 2, 0, 1], [2, 1, 2, 2, 0, 1], [1, 1, 1, 0, 0], [2, 2, 0, 1], [2, 0, 1], [0, 0], [1], ], ) actor_result = ClickhouseRetention().actors( filter.with_data({"selected_interval": 0}), self.team) assert [actor["id"] for actor in actor_result] == ["org:5", "org:6"] filter = RetentionFilter( data={ "date_to": self._date(10, month=1, hour=0), "period": "Week", "total_intervals": 7, "aggregation_group_type_index": 1, }, team=self.team, ) result = ClickhouseRetention().run(filter, self.team) self.assertEqual( self.pluck(result, "values", "count"), [ [1, 0, 0, 1, 0, 0, 1], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [1, 0, 0, 1], [0, 0, 0], [0, 0], [1], ], )
def track_retention_filter_by_person_property_materialized(self): filter = RetentionFilter( data={ "insight": "RETENTION", "target_event": { "id": "$pageview" }, "returning_event": { "id": "$pageview" }, "total_intervals": 14, "retention_type": "retention_first_time", "period": "Week", "properties": [{ "key": "email", "operator": "icontains", "value": ".com", "type": "person" }], **DATE_RANGE, }, team=self.team, ) ClickhouseRetention().run(filter, self.team)
def calculate_retention(self, request: request.Request) -> Dict[str, Any]: team = self.team data = {} if not request.GET.get("date_from"): data.update({"date_from": "-11d"}) filter = RetentionFilter(data=data, request=request, team=self.team) base_uri = request.build_absolute_uri("/") result = ClickhouseRetention(base_uri=base_uri).run(filter, team) return {"result": result}
def track_retention(self): filter = RetentionFilter( data={ "insight": "RETENTION", "target_event": { "id": "$pageview" }, "returning_event": { "id": "$pageview" }, "total_intervals": 14, "retention_type": "retention_first_time", "period": "Week", **DATE_RANGE, }, team=self.team, ) ClickhouseRetention().run(filter, self.team)
def test_groups_in_period(self): self._create_groups_and_events() filter = RetentionFilter( data={ "date_to": self._date(10, month=1, hour=0), "period": "Week", "total_intervals": 7, "aggregation_group_type_index": 0, }, team=self.team, ) actor_result = ClickhouseRetention().actors_in_period( filter.with_data({"selected_interval": 0}), self.team) self.assertTrue(actor_result[0]["person"]["id"] == "org:6") self.assertEqual(actor_result[0]["appearances"], [1, 1, 0, 1, 1, 0, 1]) self.assertTrue(actor_result[1]["person"]["id"] == "org:5") self.assertEqual(actor_result[1]["appearances"], [1, 1, 1, 1, 1, 0, 0])
def track_retention_with_person_breakdown(self): filter = RetentionFilter( data={ "insight": "RETENTION", "target_event": { "id": "$pageview" }, "returning_event": { "id": "$pageview" }, "total_intervals": 14, "retention_type": "retention_first_time", "breakdown_type": "person", "breakdowns": [ { "type": "person", "property": "$browser" }, { "type": "person", "property": "$browser_version" }, ], "period": "Week", **DATE_RANGE, }, team=self.team, ) with no_materialized_columns(): ClickhouseRetention().run(filter, self.team)
def test_groups_filtering(self): self._create_groups_and_events() result = ClickhouseRetention().run( RetentionFilter( data={ "date_to": self._date(10, month=1, hour=0), "period": "Week", "total_intervals": 7, "properties": [{ "key": "industry", "value": "technology", "type": "group", "group_type_index": 0 }], }, team=self.team, ), self.team, ) self.assertEqual( self.pluck(result, "values", "count"), [ [1, 1, 0, 1, 1, 0, 1], [1, 0, 1, 1, 0, 1], [0, 0, 0, 0, 0], [1, 1, 0, 1], [1, 0, 1], [0, 0], [1], ], ) result = ClickhouseRetention().run( RetentionFilter( data={ "date_to": self._date(10, month=1, hour=0), "period": "Week", "total_intervals": 7, "properties": [{ "key": "industry", "value": "", "type": "group", "group_type_index": 0, "operator": "is_set" }], }, team=self.team, ), self.team, ) self.assertEqual( self.pluck(result, "values", "count"), [ [2, 2, 1, 2, 2, 0, 1], [2, 1, 2, 2, 0, 1], [1, 1, 1, 0, 0], [2, 2, 0, 1], [2, 0, 1], [0, 0], [1], ], )