def test_aggregate_by_groups(self): self._create_multiple_people( period=timedelta(weeks=1), event_properties=lambda i: {"$group_0": f"org:{i // 2}"}, ) create_group(team_id=self.team.pk, group_type_index=0, group_key=f"org:0", properties={"industry": "technology"}) create_group(team_id=self.team.pk, group_type_index=0, group_key=f"org:1", properties={"industry": "agriculture"}) create_group(team_id=self.team.pk, group_type_index=0, group_key=f"org:2", properties={"industry": "technology"}) with freeze_time("2020-02-15T13:01:01Z"): data = get_stickiness_time_series_ok( client=self.client, team=self.team, request={ "shown_as": "Stickiness", "date_from": "2020-01-01", "date_to": "2020-02-15", "events": [{ "id": "watched movie", "math": "unique_group", "math_group_type_index": 0 }], "interval": "week", }, ) assert data["watched movie"][1].value == 2 assert data["watched movie"][2].value == 0 assert data["watched movie"][3].value == 1 with freeze_time("2020-02-15T13:01:01Z"): week1_actors = get_people_from_url_ok( self.client, data["watched movie"][1].person_url) week2_actors = get_people_from_url_ok( self.client, data["watched movie"][2].person_url) week3_actors = get_people_from_url_ok( self.client, data["watched movie"][3].person_url) assert sorted([p["id"] for p in week1_actors]) == sorted(["org:0", "org:2"]) assert sorted([p["id"] for p in week2_actors]) == sorted([]) assert sorted([p["id"] for p in week3_actors]) == sorted(["org:1"])
def test_aggregating_by_group(self): self._create_groups() events_by_person = { "person1": [ { "event": "$pageview", "timestamp": datetime(2020, 1, 2, 12), "properties": { "$group_0": "org:5" } }, { "event": "$pageview", "timestamp": datetime(2020, 1, 2, 12), "properties": { "$group_0": "org:6" } }, { "event": "$pageview", "timestamp": datetime(2020, 1, 2, 12), "properties": { "$group_0": "org:6", "$group_1": "company:10" }, }, ], } journeys_for(events_by_person, self.team) request = TrendsRequest( date_from="2020-01-01 00:00:00", date_to="2020-01-12 00:00:00", events=[{ "id": "$pageview", "type": "events", "order": 0, "math": "unique_group", "math_group_type_index": 0, }], ) data_response = get_trends_time_series_ok(self.client, request, self.team) assert data_response["$pageview"]["2020-01-01"].value == 0 assert data_response["$pageview"]["2020-01-02"].value == 2 curr_people = get_people_from_url_ok( self.client, data_response["$pageview"]["2020-01-02"].person_url) assert sorted([p["group_key"] for p in curr_people]) == sorted(["org:5", "org:6"])
def test_insight_trends_clean_arg(self): events_by_actor = { "1": [ { "event": "$pageview", "timestamp": datetime(2012, 1, 14, 3), "properties": { "key": "val" } }, ], "2": [ { "event": "$pageview", "timestamp": datetime(2012, 1, 14, 3) }, ], } created_actors = journeys_for(events_by_actor, self.team) with freeze_time("2012-01-15T04:01:34.000Z"): request = TrendsRequest( date_from="-14d", display="ActionsLineGraph", events=[{ "id": "$pageview", "math": None, # this argument will now be removed from the request instead of becoming a string "name": "$pageview", "custom_name": None, "type": "events", "order": 0, "properties": [{ "key": "key", "value": "val" }], "math_property": None, }], ) data = get_trends_time_series_ok(self.client, request, self.team) actors = get_people_from_url_ok( self.client, data["$pageview"]["2012-01-14"].person_url) # this would return 2 people prior to #8103 fix # 'None' values have to be purged before formatting into the actor url assert sorted([p["id"] for p in actors ]) == sorted([str(created_actors["1"].uuid)])
def test_insight_trends_basic(self): events_by_person = { "1": [ { "event": "$pageview", "timestamp": datetime(2012, 1, 14, 3) }, ], "2": [ { "event": "$pageview", "timestamp": datetime(2012, 1, 14, 3) }, ], } created_people = journeys_for(events_by_person, self.team) with freeze_time("2012-01-15T04:01:34.000Z"): request = TrendsRequest( date_from="-14d", display="ActionsLineGraph", events=[{ "id": "$pageview", "math": "dau", "name": "$pageview", "custom_name": None, "type": "events", "order": 0, "properties": [], "math_property": None, }], ) data = get_trends_time_series_ok(self.client, request, self.team) assert data["$pageview"]["2012-01-13"].value == 0 assert data["$pageview"]["2012-01-14"].value == 2 assert data["$pageview"]["2012-01-14"].label == "14-Jan-2012" assert data["$pageview"]["2012-01-15"].value == 0 with freeze_time("2012-01-15T04:01:34.000Z"): people = get_people_from_url_ok( self.client, data["$pageview"]["2012-01-14"].person_url) assert sorted([p["id"] for p in people]) == sorted( [str(created_people["1"].uuid), str(created_people["2"].uuid)])
def test_insight_trends_compare(self): events_by_person = { "p1": [ { "event": "$pageview", "timestamp": datetime(2012, 1, 5, 3), "properties": { "key": "val" } }, { "event": "$pageview", "timestamp": datetime(2012, 1, 14, 3), "properties": { "key": "val" } }, ], "p2": [ { "event": "$pageview", "timestamp": datetime(2012, 1, 5, 3), "properties": { "key": "notval" } }, { "event": "$pageview", "timestamp": datetime(2012, 1, 14, 3), "properties": { "key": "notval" } }, ], } created_people = journeys_for(events_by_person, self.team) with freeze_time("2012-01-15T04:01:34.000Z"): request = TrendsRequest( date_from="-7d", compare=True, events=[{ "id": "$pageview", "name": "$pageview", "type": "events", "order": 0, }], ) data_response = get_trends_time_series_ok(self.client, request, self.team) assert data_response["$pageview - current"]["2012-01-13"].value == 0 assert data_response["$pageview - current"]["2012-01-14"].value == 2 assert data_response["$pageview - previous"]["2012-01-04"].value == 0 assert data_response["$pageview - previous"]["2012-01-05"].value == 2 with freeze_time("2012-01-15T04:01:34.000Z"): curr_people = get_people_from_url_ok( self.client, data_response["$pageview - current"]["2012-01-14"].person_url) prev_people = get_people_from_url_ok( self.client, data_response["$pageview - previous"]["2012-01-05"].person_url) assert sorted([p["id"] for p in curr_people]) == sorted( [str(created_people["p1"].uuid), str(created_people["p2"].uuid)]) assert sorted([p["id"] for p in prev_people]) == sorted( [str(created_people["p1"].uuid), str(created_people["p2"].uuid)])
def test_breakdown_with_filter(self): events_by_person = { "person1": [ { "event": "sign up", "timestamp": datetime(2012, 1, 13, 3), "properties": { "key": "val" } }, ], "person2": [ { "event": "sign up", "timestamp": datetime(2012, 1, 13, 3), "properties": { "key": "oh" } }, ], } created_people = journeys_for(events_by_person, self.team) with freeze_time("2012-01-15T04:01:34.000Z"): params = TrendsRequestBreakdown( date_from="-14d", breakdown="key", events=[{ "id": "sign up", "name": "sign up", "type": "events", "order": 0, }], properties=[{ "key": "key", "value": "oh", "operator": "not_icontains" }], ) data_response = get_trends_time_series_ok(self.client, params, self.team) person_response = get_people_from_url_ok( self.client, data_response["sign up - val"]["2012-01-13"].person_url) assert data_response["sign up - val"]["2012-01-13"].value == 1 assert data_response["sign up - val"][ "2012-01-13"].breakdown_value == "val" assert sorted([p["id"] for p in person_response ]) == sorted([str(created_people["person1"].uuid)]) with freeze_time("2012-01-15T04:01:34.000Z"): params = TrendsRequestBreakdown( date_from="-14d", breakdown="key", display="ActionsPie", events=[{ "id": "sign up", "name": "sign up", "type": "events", "order": 0, }], ) aggregate_response = get_trends_aggregate_ok( self.client, params, self.team) aggregate_person_response = get_people_from_url_ok( self.client, aggregate_response["sign up - val"].person_url) assert aggregate_response["sign up - val"].value == 1 assert sorted([p["id"] for p in aggregate_person_response ]) == sorted([str(created_people["person1"].uuid)])
def test_insight_trends_cumulative(self): events_by_person = { "p1": [ { "event": "$pageview", "timestamp": datetime(2012, 1, 13, 3), "properties": { "key": "val" } }, { "event": "$pageview", "timestamp": datetime(2012, 1, 14, 3), "properties": { "key": "val" } }, ], "p2": [ { "event": "$pageview", "timestamp": datetime(2012, 1, 13, 3), "properties": { "key": "notval" } }, ], "p3": [ { "event": "$pageview", "timestamp": datetime(2012, 1, 14, 3), "properties": { "key": "val" } }, ], } created_people = journeys_for(events_by_person, self.team) # Total Volume with freeze_time("2012-01-15T04:01:34.000Z"): request = TrendsRequest( date_from="-14d", display="ActionsLineGraphCumulative", events=[{ "id": "$pageview", "math": None, "name": "$pageview", "custom_name": None, "type": "events", "order": 0, "properties": [], "math_property": None, }], ) data_response = get_trends_time_series_ok(self.client, request, self.team) person_response = get_people_from_url_ok( self.client, data_response["$pageview"]["2012-01-14"].person_url) assert data_response["$pageview"]["2012-01-13"].value == 2 assert data_response["$pageview"]["2012-01-14"].value == 4 assert data_response["$pageview"]["2012-01-15"].value == 4 assert data_response["$pageview"]["2012-01-14"].label == "14-Jan-2012" assert sorted([p["id"] for p in person_response]) == sorted([ str(created_people["p1"].uuid), str(created_people["p2"].uuid), str(created_people["p3"].uuid) ]) # DAU with freeze_time("2012-01-15T04:01:34.000Z"): request = TrendsRequest( date_from="-14d", display="ActionsLineGraphCumulative", events=[{ "id": "$pageview", "math": "dau", "name": "$pageview", "custom_name": None, "type": "events", "order": 0, "properties": [], "math_property": None, }], ) data_response = get_trends_time_series_ok(self.client, request, self.team) person_response = get_people_from_url_ok( self.client, data_response["$pageview"]["2012-01-14"].person_url) assert data_response["$pageview"]["2012-01-13"].value == 2 assert data_response["$pageview"]["2012-01-14"].value == 3 assert data_response["$pageview"]["2012-01-15"].value == 3 assert data_response["$pageview"]["2012-01-14"].label == "14-Jan-2012" assert sorted([p["id"] for p in person_response]) == sorted([ str(created_people["p1"].uuid), str(created_people["p2"].uuid), str(created_people["p3"].uuid) ]) # breakdown with freeze_time("2012-01-15T04:01:34.000Z"): request = TrendsRequestBreakdown( date_from="-14d", display="ActionsLineGraphCumulative", breakdown="key", breakdown_type="event", events=[{ "id": "$pageview", "math": None, "name": "$pageview", "custom_name": None, "type": "events", "order": 0, "properties": [], "math_property": None, }], ) data_response = get_trends_time_series_ok(self.client, request, self.team) person_response = get_people_from_url_ok( self.client, data_response["$pageview - val"]["2012-01-14"].person_url) assert data_response["$pageview - val"]["2012-01-13"].value == 1 assert data_response["$pageview - val"][ "2012-01-13"].breakdown_value == "val" assert data_response["$pageview - val"]["2012-01-14"].value == 3 assert data_response["$pageview - val"][ "2012-01-14"].label == "14-Jan-2012" assert sorted([p["id"] for p in person_response]) == sorted( [str(created_people["p1"].uuid), str(created_people["p3"].uuid)]) # breakdown dau with freeze_time("2012-01-15T04:01:34.000Z"): request = TrendsRequestBreakdown( date_from="-14d", display="ActionsLineGraphCumulative", breakdown="key", breakdown_type="event", events=[{ "id": "$pageview", "math": "dau", "name": "$pageview", "custom_name": None, "type": "events", "order": 0, "properties": [], "math_property": None, }], ) data_response = get_trends_time_series_ok(self.client, request, self.team) people = get_people_from_url_ok( self.client, data_response["$pageview - val"]["2012-01-14"].person_url) assert data_response["$pageview - val"]["2012-01-13"].value == 1 assert data_response["$pageview - val"][ "2012-01-13"].breakdown_value == "val" assert data_response["$pageview - val"]["2012-01-14"].value == 2 assert data_response["$pageview - val"][ "2012-01-14"].label == "14-Jan-2012" assert sorted([p["id"] for p in people]) == sorted( [str(created_people["p1"].uuid), str(created_people["p3"].uuid)])
def test_filter_by_group_properties(self): p1, p2, p3, p4 = self._create_multiple_people( period=timedelta(weeks=1), event_properties=lambda i: { "$group_0": f"org:{i}", "$group_1": "instance:1" }, ) create_group(team_id=self.team.pk, group_type_index=0, group_key=f"org:1", properties={"industry": "technology"}) create_group(team_id=self.team.pk, group_type_index=0, group_key=f"org:2", properties={"industry": "agriculture"}) create_group(team_id=self.team.pk, group_type_index=0, group_key=f"org:3", properties={"industry": "technology"}) create_group(team_id=self.team.pk, group_type_index=1, group_key=f"company:1", properties={"industry": "technology"}) with freeze_time("2020-02-15T13:01:01Z"): data = get_stickiness_time_series_ok( client=self.client, team=self.team, request={ "shown_as": "Stickiness", "date_from": "2020-01-01", "date_to": "2020-02-15", "events": [{ "id": "watched movie" }], "properties": [{ "key": "industry", "value": "technology", "type": "group", "group_type_index": 0 }], "interval": "week", }, ) assert data["watched movie"][1].value == 1 assert data["watched movie"][2].value == 0 assert data["watched movie"][3].value == 1 with freeze_time("2020-02-15T13:01:01Z"): week1_actors = get_people_from_url_ok( self.client, data["watched movie"][1].person_url) week2_actors = get_people_from_url_ok( self.client, data["watched movie"][2].person_url) week3_actors = get_people_from_url_ok( self.client, data["watched movie"][3].person_url) assert sorted([p["id"] for p in week1_actors]) == sorted([str(p1.pk)]) assert sorted([p["id"] for p in week2_actors]) == sorted([]) assert sorted([p["id"] for p in week3_actors]) == sorted([str(p3.pk)])