コード例 #1
0
ファイル: update_cache.py プロジェクト: satheesh1997/posthog
def _calculate_funnel(filter: Filter, team_id: int) -> List[Dict[str, Any]]:
    dashboard_items = DashboardItem.objects.filter(team_id=team_id,
                                                   filters=filter.to_dict())
    dashboard_items.update(refreshing=True)
    result = Funnel(filter=filter, team=Team(pk=team_id)).run()
    dashboard_items.update(last_refresh=timezone.now(), refreshing=False)
    return result
コード例 #2
0
ファイル: update_cache.py プロジェクト: copyit/posthog
def _calculate_funnel(filter: Filter, key: str,
                      team_id: int) -> List[Dict[str, Any]]:
    dashboard_items = DashboardItem.objects.filter(team_id=team_id,
                                                   filters_hash=key)
    dashboard_items.update(refreshing=True)

    team = Team(pk=team_id)

    if is_clickhouse_enabled():
        funnel_order_class: Type[ClickhouseFunnelBase] = ClickhouseFunnel
        if filter.funnel_order_type == FunnelOrderType.UNORDERED:
            funnel_order_class = ClickhouseFunnelUnordered
        elif filter.funnel_order_type == FunnelOrderType.STRICT:
            funnel_order_class = ClickhouseFunnelStrict

        if filter.funnel_viz_type == FunnelVizType.TRENDS:
            result = ClickhouseFunnelTrends(
                team=team,
                filter=filter,
                funnel_order_class=funnel_order_class).run()
        elif filter.funnel_viz_type == FunnelVizType.TIME_TO_CONVERT:
            result = ClickhouseFunnelTimeToConvert(
                team=team,
                filter=filter,
                funnel_order_class=funnel_order_class).run()
        else:
            result = funnel_order_class(team=team, filter=filter).run()
    else:
        result = Funnel(filter=filter, team=team).run()

    dashboard_items.update(last_refresh=timezone.now(), refreshing=False)
    return result
コード例 #3
0
 def _run(self, date_from=None, date_to=None, interval=None):
     self._create_events()
     return Funnel(
         team=self.team,
         filter=Filter(
             data={
                 "insight":
                 INSIGHT_FUNNELS,
                 "display":
                 TRENDS_LINEAR,
                 "interval":
                 interval if interval else "day",
                 "date_from":
                 date_from,
                 **({
                     "date_to": date_to
                 } if date_to else {}),
                 "events": [
                     {
                         "id": "sign up",
                         "order": 0
                     },
                     {
                         "id": "pay",
                         "order": 1
                     },
                 ],
             }),
     ).run()
コード例 #4
0
def _calculate_funnel(filter: Filter, key: str,
                      team_id: int) -> List[Dict[str, Any]]:
    team = Team(pk=team_id)

    if is_clickhouse_enabled():
        funnel_order_class: Type[ClickhouseFunnelBase] = ClickhouseFunnel
        if filter.funnel_order_type == FunnelOrderType.UNORDERED:
            funnel_order_class = ClickhouseFunnelUnordered
        elif filter.funnel_order_type == FunnelOrderType.STRICT:
            funnel_order_class = ClickhouseFunnelStrict

        if filter.funnel_viz_type == FunnelVizType.TRENDS:
            result = ClickhouseFunnelTrends(
                team=team,
                filter=filter,
                funnel_order_class=funnel_order_class).run()
        elif filter.funnel_viz_type == FunnelVizType.TIME_TO_CONVERT:
            result = ClickhouseFunnelTimeToConvert(
                team=team,
                filter=filter,
                funnel_order_class=funnel_order_class).run()
        else:
            result = funnel_order_class(team=team, filter=filter).run()
    else:
        result = Funnel(filter=filter, team=team).run()

    return result
コード例 #5
0
        def test_funnel_multiple_actions(self):
            # we had an issue on clickhouse where multiple actions with different property filters would incorrectly grab only the last
            # properties.
            # This test prevents a regression
            person_factory(distinct_ids=["person1"], team_id=self.team.pk)
            event_factory(distinct_id="person1", event="event1", team=self.team)
            event_factory(distinct_id="person1", event="event2", properties={"test_prop": "a"}, team=self.team)

            action1 = Action.objects.create(team_id=self.team.pk, name="event2")
            ActionStep.objects.create(action=action1, event="event2", properties=[{"key": "test_prop", "value": "a"}])
            action1.calculate_events()
            action2 = Action.objects.create(team_id=self.team.pk, name="event2")
            ActionStep.objects.create(action=action2, event="event2", properties=[{"key": "test_prop", "value": "c"}])
            action2.calculate_events()

            result = Funnel(
                filter=Filter(
                    data={
                        "events": [{"id": "event1", "order": 0}],
                        "actions": [{"id": action1.pk, "order": 1,}, {"id": action2.pk, "order": 2,},],
                        "insight": INSIGHT_FUNNELS,
                        "funnel_window_days": 14,
                    }
                ),
                team=self.team,
            ).run()
            self.assertEqual(result[0]["count"], 1)
            self.assertEqual(result[1]["count"], 1)
            self.assertEqual(result[2]["count"], 0)
コード例 #6
0
        def _single_step_funnel(self, properties=None, filters=None):
            if filters is None:
                filters = {
                    "events": [{"id": "user signed up", "type": "events", "order": 0},],
                }

            if properties is not None:
                filters.update({"properties": properties})

            filter = Filter(data=filters)
            return Funnel(filter=filter, team=self.team)
コード例 #7
0
        def _single_step_funnel(self, properties=None, filters=None):
            if filters is None:
                filters = {
                    "events": [{"id": "user signed up", "type": "events", "order": 0},],
                    "insight": INSIGHT_FUNNELS,
                    "funnel_window_days": 14,
                }

            if properties is not None:
                filters.update({"properties": properties})

            filter = Filter(data=filters)
            return Funnel(filter=filter, team=self.team)
コード例 #8
0
 def test_one_step(self):
     self._create_events()
     with freeze_time("2021-01-02T04:00:00.000Z"):
         result = Funnel(
             team=self.team,
             filter=Filter(
                 data={
                     "insight": INSIGHT_FUNNELS,
                     "display": TRENDS_LINEAR,
                     "interval": "day",
                     "events": [{
                         "id": "sign up",
                         "order": 0
                     }],
                 }),
         ).run()
     self.assertEqual(result[0]["data"], [0, 0, 0, 0, 0, 0, 0, 0])
コード例 #9
0
 def test_funnel_filter_test_accounts(self):
     person_factory(distinct_ids=["person1"], team_id=self.team.pk, properties={"email": "*****@*****.**"})
     person_factory(distinct_ids=["person2"], team_id=self.team.pk)
     event_factory(distinct_id="person1", event="event1", team=self.team)
     event_factory(distinct_id="person2", event="event1", team=self.team)
     result = Funnel(
         filter=Filter(
             data={
                 "events": [{"id": "event1", "order": 0}],
                 "insight": INSIGHT_FUNNELS,
                 FILTER_TEST_ACCOUNTS: True,
                 "funnel_window_days": 14,
             }
         ),
         team=self.team,
     ).run()
     self.assertEqual(result[0]["count"], 1)
コード例 #10
0
        def _basic_funnel(self, properties=None, filters=None):
            action_credit_card = Action.objects.create(team=self.team,
                                                       name="paid")
            ActionStep.objects.create(action=action_credit_card,
                                      event="$autocapture",
                                      tag_name="button",
                                      text="Pay $10")
            action_play_movie = Action.objects.create(team=self.team,
                                                      name="watched movie")
            ActionStep.objects.create(action=action_play_movie,
                                      event="$autocapture",
                                      tag_name="a",
                                      href="/movie")

            if filters is None:
                filters = {
                    "events": [
                        {
                            "id": "user signed up",
                            "type": "events",
                            "order": 0
                        },
                    ],
                    "actions": [
                        {
                            "id": action_credit_card.pk,
                            "type": "actions",
                            "order": 1
                        },
                        {
                            "id": action_play_movie.pk,
                            "type": "actions",
                            "order": 2
                        },
                    ],
                }

            if properties is not None:
                filters.update({"properties": properties})

            filters["insight"] = INSIGHT_FUNNELS
            filter = Filter(data=filters)
            return Funnel(filter=filter, team=self.team)
コード例 #11
0
 def test_funnel_no_events(self):
     funnel = Funnel(filter=Filter(data={"some": "prop"}),
                     team=self.team)
     self.assertEqual(funnel.run(), [])