예제 #1
0
    def test_retention_period(self):
        Person.objects.create(
            team=self.team, distinct_ids=["person1", "alias1"], properties={"email": "*****@*****.**"},
        )
        Person.objects.create(
            team=self.team, distinct_ids=["person2"], properties={"email": "*****@*****.**"},
        )

        self._create_pageviews(
            [
                ("person1", self._date(0)),
                ("person1", self._date(1)),
                ("person1", self._date(2, month=1)),
                ("person1", self._date(10, month=1)),
                ("person1", self._date(15)),
                ("person1", self._date(18)),
                ("alias1", self._date(5, 9)),
                ("person1", self._date(6)),
                ("person2", self._date(1)),
                ("person2", self._date(2)),
                ("person2", self._date(3)),
                ("person2", self._date(6)),
                ("person2", self._date(13)),
            ]
        )

        result = Retention().run(
            Filter(data={"date_from": self._date(0, hour=0), "period": "Week"}), self.team, total_intervals=7,
        )

        self.assertEqual(
            self.pluck(result, "label"), ["Week 0", "Week 1", "Week 2", "Week 3", "Week 4", "Week 5", "Week 6"],
        )

        self.assertEqual(
            self.pluck(result, "values", "count"),
            [[2, 2, 0, 1, 0, 1, 0], [2, 0, 1, 0, 1, 0], [0, 0, 0, 0, 0], [1, 0, 1, 0], [0, 0, 0], [1, 0], [0],],
        )

        self.assertEqual(
            self.pluck(result, "date"),
            [
                "Wed. 10 June",
                "Wed. 17 June",
                "Wed. 24 June",
                "Wed. 1 July",
                "Wed. 8 July",
                "Wed. 15 July",
                "Wed. 22 July",
            ],
        )
예제 #2
0
    def test_retention_action_start_point(self):
        person1 = Person.objects.create(team=self.team,
                                        distinct_ids=["person1", "alias1"])
        person2 = Person.objects.create(team=self.team,
                                        distinct_ids=["person2"])

        action = self._create_signup_actions([
            ("person1", self._date(0)),
            ("person1", self._date(1)),
            ("person1", self._date(2)),
            ("person1", self._date(5)),
            ("alias1", self._date(5, 9)),
            ("person1", self._date(6)),
            ("person2", self._date(1)),
            ("person2", self._date(2)),
            ("person2", self._date(3)),
            ("person2", self._date(6)),
        ])

        start_entity = Entity({
            "id": action.pk,
            "type": TREND_FILTER_TYPE_ACTIONS
        })
        result = Retention().run(
            Filter(data={
                "date_from": self._date(0, hour=0),
                "entities": [start_entity]
            }),
            self.team,
            total_days=7)

        self.assertEqual(len(result), 7)
        self.assertEqual(
            self.pluck(result, "label"),
            ["Day 0", "Day 1", "Day 2", "Day 3", "Day 4", "Day 5", "Day 6"],
        )
        self.assertEqual(result[0]["date"], "Wed. 10 June")

        self.assertEqual(
            self.pluck(result, "values", "count"),
            [
                [1, 1, 1, 0, 0, 1, 1],
                [2, 2, 1, 0, 1, 2],
                [2, 1, 0, 1, 2],
                [1, 0, 0, 1],
                [0, 0, 0],
                [1, 1],
                [2],
            ],
        )
예제 #3
0
    def test_retention_with_properties(self):
        person1 = Person.objects.create(
            team=self.team,
            distinct_ids=["person1", "alias1"],
            properties={"email": "*****@*****.**"})
        person2 = Person.objects.create(
            team=self.team,
            distinct_ids=["person2"],
            properties={"email": "*****@*****.**"})

        self._create_pageviews([
            ("person1", self._date(0)),
            ("person1", self._date(1)),
            ("person1", self._date(2)),
            ("person1", self._date(5)),
            ("alias1", self._date(5, 9)),
            ("person1", self._date(6)),
            ("person2", self._date(1)),
            ("person2", self._date(2)),
            ("person2", self._date(3)),
            ("person2", self._date(6)),
        ])

        result = Retention().run(
            Filter(
                data={
                    "properties": [{
                        "key": "email",
                        "value": "*****@*****.**",
                        "type": "person"
                    }],
                    "date_from":
                    self._date(0, hour=0),
                }),
            self.team,
            total_days=7,
        )

        self.assertEqual(len(result), 7)
        self.assertEqual(
            self.pluck(result, "label"),
            ["Day 0", "Day 1", "Day 2", "Day 3", "Day 4", "Day 5", "Day 6"],
        )
        self.assertEqual(result[0]["date"], "Wed. 10 June")
        self.assertEqual(
            self.pluck(result, "values", "count"),
            [[1, 1, 1, 0, 0, 1, 1], [1, 1, 0, 0, 1, 1], [1, 0, 0, 1, 1],
             [0, 0, 0, 0], [0, 0, 0], [1, 1], [1]],
        )
예제 #4
0
    def test_retention(self):
        person1 = Person.objects.create(team=self.team,
                                        distinct_ids=["person1", "alias1"])
        person2 = Person.objects.create(team=self.team,
                                        distinct_ids=["person2"])

        self._create_pageviews([
            ("person1", self._date(0)),
            ("person1", self._date(1)),
            ("person1", self._date(2)),
            ("person1", self._date(5)),
            ("alias1", self._date(5, 9)),
            ("person1", self._date(6)),
            ("person2", self._date(1)),
            ("person2", self._date(2)),
            ("person2", self._date(3)),
            ("person2", self._date(6)),
        ])

        result = Retention().run(
            Filter(data={"date_from": self._date(0, hour=0)}), self.team)

        self.assertEqual(len(result), 11)
        self.assertEqual(
            self.pluck(result, "label"),
            [
                "Day 0", "Day 1", "Day 2", "Day 3", "Day 4", "Day 5", "Day 6",
                "Day 7", "Day 8", "Day 9", "Day 10"
            ],
        )
        self.assertEqual(result[0]["date"], "Wed. 10 June")

        self.assertEqual(
            self.pluck(result, "values", "count"),
            [
                [1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0],
                [2, 2, 1, 0, 1, 2, 0, 0, 0, 0],
                [2, 1, 0, 1, 2, 0, 0, 0, 0],
                [1, 0, 0, 1, 0, 0, 0, 0],
                [0, 0, 0, 0, 0, 0, 0],
                [1, 1, 0, 0, 0, 0],
                [2, 0, 0, 0, 0],
                [0, 0, 0, 0],
                [0, 0, 0],
                [0, 0],
                [0],
            ],
        )
예제 #5
0
    def test_retention_period_weekly(self):
        Person.objects.create(
            team=self.team,
            distinct_ids=["person1", "alias1"],
            properties={"email": "*****@*****.**"},
        )
        Person.objects.create(
            team=self.team,
            distinct_ids=["person2"],
            properties={"email": "*****@*****.**"},
        )

        self._create_pageviews([
            ("person1", self._date(0)),
            ("person1", self._date(1)),
            ("person1", self._date(2, month=1)),
            ("person1", self._date(10, month=1)),
            ("person1", self._date(15)),
            ("person1", self._date(18)),
            ("alias1", self._date(5, 9)),
            ("person1", self._date(6)),
            ("person2", self._date(1)),
            ("person2", self._date(2)),
            ("person2", self._date(3)),
            ("person2", self._date(6)),
            ("person2", self._date(13)),
        ])

        result = Retention().run(
            Filter(data={
                "date_to": self._date(15, month=1, hour=0),
                "period": "Week"
            }),
            self.team,
            total_intervals=7,
        )

        self.assertEqual(
            self.pluck(result, "label"),
            [
                "Week 0", "Week 1", "Week 2", "Week 3", "Week 4", "Week 5",
                "Week 6"
            ],
        )

        self.assertEqual(
            self.pluck(result, "values", "count"),
            [
                [2, 2, 0, 1, 0, 1, 0],
                [2, 0, 1, 0, 1, 0],
                [0, 0, 0, 0, 0],
                [1, 0, 1, 0],
                [0, 0, 0],
                [1, 0],
                [0],
            ],
        )

        self.assertEqual(
            self.pluck(result, "date"),
            [
                datetime(2020, 6, 13, 0, tzinfo=pytz.UTC),
                datetime(2020, 6, 20, 0, tzinfo=pytz.UTC),
                datetime(2020, 6, 27, 0, tzinfo=pytz.UTC),
                datetime(2020, 7, 4, 0, tzinfo=pytz.UTC),
                datetime(2020, 7, 11, 0, tzinfo=pytz.UTC),
                datetime(2020, 7, 18, 0, tzinfo=pytz.UTC),
                datetime(2020, 7, 25, 0, tzinfo=pytz.UTC),
            ],
        )