Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
thmsobrmlr committed Feb 14, 2024
1 parent 25f6dd7 commit 4febba9
Show file tree
Hide file tree
Showing 4 changed files with 1,603 additions and 104 deletions.
17 changes: 6 additions & 11 deletions posthog/hogql_queries/insights/funnels/funnel_time_to_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ def get_query(self) -> ast.SelectQuery:
time_to_convert_query = parse_select(
f"""
WITH
-- step_runs AS (SELECT 1),
step_runs AS (
{{steps_per_person_query}}
),
Expand Down Expand Up @@ -95,7 +94,7 @@ def get_query(self) -> ast.SelectQuery:
( SELECT to_seconds FROM histogram_params ) AS histogram_to_seconds,
( SELECT average_conversion_time FROM histogram_params ) AS histogram_average_conversion_time
SELECT
bin_from_seconds,
fill.bin_from_seconds,
person_count,
histogram_average_conversion_time AS average_conversion_time
FROM (
Expand All @@ -109,18 +108,14 @@ def get_query(self) -> ast.SelectQuery:
RIGHT OUTER JOIN (
/* Making sure bin_count bins are returned */
/* Those not present in the results query due to lack of data simply get person_count 0 */
SELECT histogram_from_seconds + number * bin_width_seconds AS bin_from_seconds FROM system.numbers LIMIT ifNull({bin_count_identifier}, 0) + 1
SELECT histogram_from_seconds + number * bin_width_seconds AS bin_from_seconds FROM numbers(ifNull({bin_count_identifier}, 0) + 1)
) fill
ORDER BY bin_from_seconds
-- USING (bin_from_seconds)
ON results.bin_from_seconds = fill.bin_from_seconds
-- ORDER BY bin_from_seconds
ORDER BY fill.bin_from_seconds
""",
placeholders={"steps_per_person_query": steps_per_person_query},
# placeholders={
# "step_runs_cte": ast.CTE(
# name="step_runs",
# expr=steps_per_person_query,
# cte_type="subquery",
# )
# },
)

assert isinstance(time_to_convert_query, ast.SelectQuery)
Expand Down
24 changes: 14 additions & 10 deletions posthog/hogql_queries/insights/funnels/funnels_query_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,7 @@ def _refresh_frequency(self):
return refresh_frequency

def to_query(self) -> ast.SelectQuery:
funnelVizType = self.context.funnelsFilter.funnelVizType

if funnelVizType == FunnelVizType.trends:
# return FunnelTrends(context=self.context).get_query()
return self.funnel_order_class.get_query()
elif funnelVizType == FunnelVizType.time_to_convert:
return FunnelTimeToConvert(context=self.context).get_query()
else:
return self.funnel_order_class.get_query()
return self.funnel_class.get_query()

def calculate(self):
query = self.to_query()
Expand All @@ -96,7 +88,7 @@ def calculate(self):
modifiers=self.modifiers,
)

results = self.funnel_order_class._format_results(response.results)
results = self.funnel_class._format_results(response.results)

if response.timings is not None:
timings.extend(response.timings)
Expand All @@ -107,6 +99,18 @@ def calculate(self):
def funnel_order_class(self):
return get_funnel_order_class(self.context.funnelsFilter)(context=self.context)

@cached_property
def funnel_class(self):
funnelVizType = self.context.funnelsFilter.funnelVizType

if funnelVizType == FunnelVizType.trends:
# return FunnelTrends(context=self.context)
return self.funnel_order_class
elif funnelVizType == FunnelVizType.time_to_convert:
return FunnelTimeToConvert(context=self.context)
else:
return self.funnel_order_class

@cached_property
def query_date_range(self):
return QueryDateRange(
Expand Down
Loading

0 comments on commit 4febba9

Please sign in to comment.