Exemplo n.º 1
0
    def test_breakdown_by_person_property(self):
        person1, person2, person3, person4 = self._create_multiple_people()
        action = _create_action(name="watched movie", team=self.team)

        with freeze_time("2020-01-04T13:01:01Z"):
            action_response = ClickhouseTrends().run(
                Filter(
                    data={
                        "date_from":
                        "-14d",
                        "breakdown":
                        "name",
                        "breakdown_type":
                        "person",
                        "actions": [{
                            "id": action.pk,
                            "type": "actions",
                            "order": 0
                        }],
                    }),
                self.team,
            )
            event_response = ClickhouseTrends().run(
                Filter(
                    data={
                        "date_from":
                        "-14d",
                        "breakdown":
                        "name",
                        "breakdown_type":
                        "person",
                        "events": [{
                            "id": "watched movie",
                            "name": "watched movie",
                            "type": "events",
                            "order": 0,
                        }],
                    }),
                self.team,
            )

        self.assertListEqual(
            [res["breakdown_value"] for res in event_response],
            ["person1", "person2", "person3"])

        for response in event_response:
            if response["breakdown_value"] == "person1":
                self.assertEqual(response["count"], 1)
                self.assertEqual(response["label"], "watched movie - person1")
            if response["breakdown_value"] == "person2":
                self.assertEqual(response["count"], 3)
            if response["breakdown_value"] == "person3":
                self.assertEqual(response["count"], 3)

        self.assertTrue(
            self._compare_entity_response(
                event_response,
                action_response,
            ))
Exemplo n.º 2
0
    def test_breakdown_filtering(self):
        self._create_events()
        # test breakdown filtering
        with freeze_time("2020-01-04T13:01:01Z"):
            response = ClickhouseTrends().run(
                Filter(
                    data={
                        "date_from": "-14d",
                        "breakdown": "$some_property",
                        "events": [
                            {"id": "sign up", "name": "sign up", "type": "events", "order": 0,},
                            {"id": "no events"},
                        ],
                    }
                ),
                self.team,
            )

        self.assertEqual(response[0]["label"], 'sign up - "value"')
        self.assertEqual(response[1]["label"], 'sign up - "other_value"')
        self.assertEqual(response[2]["label"], 'no events - "value"')
        self.assertEqual(response[3]["label"], 'no events - "other_value"')

        self.assertEqual(sum(response[0]["data"]), 2)
        self.assertEqual(response[0]["breakdown_value"], '"value"')

        self.assertEqual(sum(response[1]["data"]), 1)
        self.assertEqual(response[1]["breakdown_value"], '"other_value"')
Exemplo n.º 3
0
    def test_dau_with_breakdown_filtering(self):
        sign_up_action, _ = self._create_events()
        with freeze_time("2020-01-02T13:01:01Z"):
            _create_event(
                team=self.team,
                event="sign up",
                distinct_id="blabla",
                properties={"$some_property": "other_value"},
            )
        with freeze_time("2020-01-04T13:01:01Z"):
            action_response = ClickhouseTrends().run(
                Filter(
                    data={
                        "breakdown": "$some_property",
                        "actions": [{
                            "id": sign_up_action.id,
                            "math": "dau"
                        }]
                    }),
                self.team,
            )
            event_response = ClickhouseTrends().run(
                Filter(
                    data={
                        "breakdown": "$some_property",
                        "events": [{
                            "id": "sign up",
                            "math": "dau"
                        }]
                    }),
                self.team,
            )

        self.assertEqual(event_response[0]["label"], "sign up - value")
        self.assertEqual(event_response[1]["label"], "sign up - other_value")

        self.assertEqual(sum(event_response[0]["data"]), 1)
        self.assertEqual(event_response[0]["data"][4],
                         1)  # property not defined

        self.assertEqual(sum(event_response[1]["data"]), 1)
        self.assertEqual(event_response[1]["data"][5], 1)
        self.assertTrue(
            self._compare_entity_response(action_response, event_response))
Exemplo n.º 4
0
    def trend(self, request: Request, *args: Any, **kwargs: Any) -> Response:

        team = request.user.team
        filter = Filter(request=request)

        if filter.shown_as == TRENDS_STICKINESS:
            result = ClickhouseStickiness().run(filter, team)
        else:
            result = ClickhouseTrends().run(filter, team)

        self._refresh_dashboard(request=request)

        return Response(result)
Exemplo n.º 5
0
    def trend(self, request: Request, *args: Any, **kwargs: Any) -> Response:
        if not endpoint_enabled(CH_TREND_ENDPOINT, request.user.distinct_id):
            result = super().calculate_trends(request)
            return Response(result)

        team = request.user.team
        filter = Filter(request=request)

        if filter.shown_as == TRENDS_STICKINESS:
            result = ClickhouseStickiness().run(filter, team)
        else:
            result = ClickhouseTrends().run(filter, team)

        self._refresh_dashboard(request=request)

        return Response(result)