:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
"""Which reports count as inbox inventory.
The dataset dag's daily spine and the scoring sweep share this definition. The sweep must score
the population the dag trains on, or the model trains on one inventory and serves another.
"""
import datetime
from django.db.models import Q
from products.signals.backend.models import SignalReport
# Statuses a report can be authored straight into and still be in the inbox (`create_scout_report`,
# `create_custom_agent_ready_report` and `create_layer_reports`), which is how a report reaches the spine without a
# promotion. Suppressed and deleted are absent on purpose: authored-then-hidden is not inventory.
BORN_VISIBLE_STATUSES = (
SignalReport.Status.READY,
SignalReport.Status.PENDING_INPUT,
SignalReport.Status.IN_PROGRESS,
SignalReport.Status.RESOLVED,
SignalReport.Status.CLOSED,
SignalReport.Status.MONITORING,
)
# Inventory a user can still act on, which the sweep scores. A resolved report stays in the spine
# because its history matters for labels, but there is nothing left to rank.
SCORABLE_STATUSES = (
SignalReport.Status.READY,
SignalReport.Status.PENDING_INPUT,
SignalReport.Status.IN_PROGRESS,
)
def spine_report_filter(snapshot_end: datetime.datetime) -> Q:
"""Reports that were in the inbox before the cutoff.
Two ways in, because not every visible report was promoted: the pipeline promotes a `potential`
report and stamps promoted_at, but the scout, custom-agent and stack-layer paths create a report
already in a visible status and never stamp it. Keying only on promotion dropped every
directly-authored report until a user happened to interact with it, biasing the inventory toward
reports that already had engagement — the wrong bias for a ranking model. A never-promoted report
is only eligible while it is still visible, so a promotion after the cutoff (promoted_at set, not
null) still cannot leak in through the second branch."""
return Q(promoted_at__isnull=False, promoted_at__lt=snapshot_end) | Q(
promoted_at__isnull=True, status__in=BORN_VISIBLE_STATUSES, created_at__lt=snapshot_end
)