def run(self, *args, **kwargs) -> List[Dict[str, Any]]: if len(self._filter.entities) == 0: return [] if self._filter.display == TRENDS_LINEAR: return ClickhouseFunnelTrends(self._filter, self._team).run() else: # Format of this is [step order, person count (that reached that step), array of person uuids] results = self._exec_query() steps = [] relevant_people = [] total_people = 0 for step in reversed(self._filter.entities): # Clickhouse step order starts at one, hence the +1 result_step = [x for x in results if step.order + 1 == x[0]] if len(result_step) > 0: total_people += result_step[0][1] relevant_people += result_step[0][2] steps.append( self._serialize_step(step, total_people, relevant_people[0:100])) return steps[::-1] # reverse
def test_month_interval(self): filter = Filter( data={ "insight": INSIGHT_FUNNELS, "display": TRENDS_LINEAR, "interval": "month", "date_from": "2021-05-01 00:00:00", "date_to": "2021-05-07 00:00:00", "funnel_window_days": 7, "events": [ { "id": "step one", "order": 0 }, { "id": "step two", "order": 1 }, { "id": "step three", "order": 2 }, ], }) results = ClickhouseFunnelTrends(filter, self.team).perform_query() self.assertEqual(len(results), 1)
def test_incomplete_status(self): today = datetime.utcnow().strftime(FORMAT_TIME) tomorrow_delta = datetime.utcnow() + timedelta(days=1) tomorrow = tomorrow_delta.strftime(FORMAT_TIME) filter = Filter( data={ "insight": INSIGHT_FUNNELS, "display": TRENDS_LINEAR, "interval": "day", "date_from": today, "date_to": tomorrow, "funnel_window_days": 1, "events": [ { "id": "step one", "order": 0 }, { "id": "step two", "order": 1 }, { "id": "step three", "order": 2 }, ], }) results = ClickhouseFunnelTrends(filter, self.team).perform_query() current = results[0] # today self.assertEqual(1, current["completed_funnels"]) self.assertEqual(1, current["total"]) self.assertEqual(100.00, current["percent_complete"]) self.assertEqual(False, current["is_complete"]) self.assertEqual(1, len(current["cohort"]))
def test_window_size_one_day(self): filter = Filter( data={ "insight": INSIGHT_FUNNELS, "display": TRENDS_LINEAR, "interval": "day", "date_from": "2021-05-01 00:00:00", "date_to": "2021-05-07 00:00:00", "funnel_window_days": 1, "events": [ { "id": "step one", "order": 0 }, { "id": "step two", "order": 1 }, { "id": "step three", "order": 2 }, ], }) results = ClickhouseFunnelTrends(filter, self.team).perform_query() saturday = results[0] # 5/1 self.assertEqual(1, saturday["completed_funnels"]) self.assertEqual(6, saturday["total"]) self.assertEqual(16.67, saturday["percent_complete"]) self.assertEqual(True, saturday["is_complete"]) self.assertEqual(1, len(saturday["cohort"])) sunday = results[1] # 5/2 self.assertEqual(0, sunday["completed_funnels"]) self.assertEqual(6, sunday["total"]) self.assertEqual(0.00, sunday["percent_complete"]) self.assertEqual(True, sunday["is_complete"]) self.assertEqual(0, len(sunday["cohort"])) monday = results[2] # 5/3 self.assertEqual(0, monday["completed_funnels"]) self.assertEqual(6, monday["total"]) self.assertEqual(0.00, monday["percent_complete"]) self.assertEqual(True, monday["is_complete"]) self.assertEqual(0, len(monday["cohort"])) tuesday = results[3] # 5/4 self.assertEqual(0, tuesday["completed_funnels"]) self.assertEqual(6, tuesday["total"]) self.assertEqual(0.00, tuesday["percent_complete"]) self.assertEqual(True, tuesday["is_complete"]) self.assertEqual(2, len(tuesday["cohort"])) wednesday = results[4] # 5/5 self.assertEqual(0, wednesday["completed_funnels"]) self.assertEqual(6, wednesday["total"]) self.assertEqual(0.00, wednesday["percent_complete"]) self.assertEqual(True, wednesday["is_complete"]) self.assertEqual(2, len(wednesday["cohort"])) thursday = results[5] # 5/6 self.assertEqual(0, thursday["completed_funnels"]) self.assertEqual(6, thursday["total"]) self.assertEqual(0.00, thursday["percent_complete"]) self.assertEqual(True, thursday["is_complete"]) self.assertEqual(1, len(thursday["cohort"])) friday = results[6] # 5/7 self.assertEqual(0, friday["completed_funnels"]) self.assertEqual(6, friday["total"]) self.assertEqual(0.00, friday["percent_complete"]) self.assertEqual(True, friday["is_complete"]) self.assertEqual(0, len(friday["cohort"]))