-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Funnel persons per step and dropoff (#4883)
* wip: pagination for persons on clickhouse funnels * wip: added offset support for getting a list of persons; added support for conversion window; * fixed mypy exception * helper function to insert data for local testing * moved generate code into separate class for more functionality later * corrected person_distinct_id to use the person id from postgres * minor corrections to generate local class along with addition of data cleanup via destroy() method * reduce the number of persons who make it to each step * moved funnel queries to a new folder for better organization; separated funnel_persons and funnel_trends_persons into individual classes; * funnel persons and tests * initial implementation * invoke the funnel or funnel trends class respectively * add a test * add breakdown handling and first test * add test stubs * remove repeats * mypy corrections and PR feedback * run funnel test suite on new query implementation * remove imports * corrected tests * minor test updates * correct func name * fix types * func name change * move builder functions to funnel base * add test classe for new funnel * Handle multiple same events in the funnel (#4863) * dedup + tests * deep equality. Tests to come * write test for entity equality * finish testing funnels * clean up comments * add ability to specify per step or dropoff persons * remove defaults * remove funnel_window parameter unless it's needed * add param to filters * test api * remove print * fix tests * change distribution * add none condition for funnel step * add order by * remove funnel window days Co-authored-by: Buddy Williams <buddy@posthog.com> Co-authored-by: Neil Kakkar <neilkakkar@gmail.com>
- Loading branch information
1 parent
41754f9
commit 562e3ba
Showing
13 changed files
with
195 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,34 @@ | ||
from ee.clickhouse.queries.funnels.base import ClickhouseFunnelBase | ||
from ee.clickhouse.sql.funnels.funnel import FUNNEL_PERSONS_SQL | ||
from ee.clickhouse.sql.funnels.funnel import FUNNEL_PERSONS_BY_STEP_SQL | ||
from posthog.models import Person | ||
|
||
|
||
class ClickhouseFunnelPersons(ClickhouseFunnelBase): | ||
def get_query(self, format_properties): | ||
return FUNNEL_PERSONS_SQL.format(**format_properties) | ||
steps_per_person_query = self._get_steps_per_person_query() | ||
return FUNNEL_PERSONS_BY_STEP_SQL.format( | ||
**format_properties, | ||
steps_per_person_query=steps_per_person_query, | ||
persons_steps=self._get_funnel_person_step_condition() | ||
) | ||
|
||
def _get_funnel_person_step_condition(self): | ||
step_num = self._filter.funnel_step | ||
max_steps = len(self._filter.entities) | ||
|
||
if step_num is None: | ||
raise ValueError("funnel_step should not be none") | ||
|
||
if step_num >= 0: | ||
self.params.update({"step_num": [i for i in range(step_num, max_steps + 1)]}) | ||
return "steps IN %(step_num)s" | ||
else: | ||
self.params.update({"step_num": abs(step_num) - 1}) | ||
return "steps = %(step_num)s" | ||
|
||
def _format_results(self, results): | ||
formatted_results = [] | ||
for row in results: | ||
distinct_ids, email = Person.get_distinct_ids_and_email_by_id(row[1], self._team.id) | ||
distinct_ids, email = Person.get_distinct_ids_and_email_by_id(row[0], self._team.id) | ||
formatted_results.append({"max_step": row[0], "distinct_ids": distinct_ids, "email": email}) | ||
return formatted_results |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.