mirror of
https://github.com/PostHog/posthog.git
synced 2024-11-28 18:26:15 +01:00
fix(sampling): ensure funnel correlation results get corrected for sampling (#14382)
* fix(sampling): ensure funnel correlation results get corrected for sampling * adapt signature to round return * update
This commit is contained in:
parent
0682422d8e
commit
95670dc70b
@ -29,6 +29,7 @@ from posthog.queries.funnels.utils import get_funnel_order_actor_class
|
||||
from posthog.queries.insight import insight_sync_execute
|
||||
from posthog.queries.person_distinct_id_query import get_team_distinct_ids_query
|
||||
from posthog.queries.person_query import PersonQuery
|
||||
from posthog.queries.util import correct_result_for_sampling
|
||||
|
||||
|
||||
class EventDefinition(TypedDict):
|
||||
@ -639,6 +640,9 @@ class FunnelCorrelation:
|
||||
|
||||
event_contingency_tables, success_total, failure_total = self.get_partial_event_contingency_tables()
|
||||
|
||||
success_total = correct_result_for_sampling(success_total, self._filter.sampling_factor)
|
||||
failure_total = correct_result_for_sampling(failure_total, self._filter.sampling_factor)
|
||||
|
||||
if not success_total or not failure_total:
|
||||
return [], True
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import json
|
||||
from datetime import datetime, timedelta
|
||||
from typing import Any, Dict, Optional, Union
|
||||
from typing import Any, Dict, Optional
|
||||
|
||||
import pytz
|
||||
from django.utils import timezone
|
||||
@ -103,8 +103,9 @@ def convert_to_datetime_aware(date_obj):
|
||||
return date_obj
|
||||
|
||||
|
||||
def correct_result_for_sampling(result: Union[int, float], sampling_factor: Optional[float]) -> float:
|
||||
def correct_result_for_sampling(value: int, sampling_factor: Optional[float]) -> int:
|
||||
if not sampling_factor:
|
||||
return result
|
||||
return value
|
||||
|
||||
return result * (1 / sampling_factor)
|
||||
result: int = round(value * (1 / sampling_factor))
|
||||
return result
|
||||
|
Loading…
Reference in New Issue
Block a user