Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Conversion Metrics Properties #209

Merged
merged 9 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 62 additions & 1 deletion dbt_semantic_interfaces/protocols/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
from dbt_semantic_interfaces.protocols.metadata import Metadata
from dbt_semantic_interfaces.protocols.where_filter import WhereFilterIntersection
from dbt_semantic_interfaces.references import MeasureReference, MetricReference
from dbt_semantic_interfaces.type_enums import MetricType, TimeGranularity
from dbt_semantic_interfaces.type_enums import (
ConversionCalculationType,
MetricType,
TimeGranularity,
)


class MetricInputMeasure(Protocol):
Expand Down Expand Up @@ -113,6 +117,52 @@ def post_aggregation_reference(self) -> MetricReference:
pass


class ConversionTypeParams(Protocol):
"""Type params to provide context for conversion metrics properties."""

@property
@abstractmethod
def base_measure(self) -> MetricInputMeasure:
"""Measure used to calculate the base event."""
pass

@property
@abstractmethod
def conversion_measure(self) -> MetricInputMeasure:
"""Measure used to calculate the conversion event."""
pass

@property
@abstractmethod
def entity(self) -> str:
"""Specified join entity."""
pass

@property
@abstractmethod
def calculation(self) -> ConversionCalculationType:
"""Type of conversion metric calculation."""
pass

@property
@abstractmethod
def window(self) -> Optional[MetricTimeWindow]:
"""Maximum time range for finding successing conversion events."""
WilliamDee marked this conversation as resolved.
Show resolved Hide resolved
pass

@property
@abstractmethod
def base_measure_reference(self) -> MeasureReference:
"""Return the measure reference associated with the base measure."""
pass

@property
@abstractmethod
def conversion_measure_reference(self) -> MeasureReference:
"""Return the measure reference associated with the conversion measure."""
pass
WilliamDee marked this conversation as resolved.
Show resolved Hide resolved


class MetricTypeParams(Protocol):
"""Type params add additional context to certain metric types (the context depends on the metric type)."""

Expand Down Expand Up @@ -157,6 +207,11 @@ def grain_to_date(self) -> Optional[TimeGranularity]: # noqa: D
def metrics(self) -> Optional[Sequence[MetricInput]]: # noqa: D
pass

@property
@abstractmethod
def conversion_type_params(self) -> Optional[ConversionTypeParams]: # noqa: D
pass


class Metric(Protocol):
"""Describes a metric."""
Expand Down Expand Up @@ -215,3 +270,9 @@ def metadata(self) -> Optional[Metadata]: # noqa: D
def label(self) -> Optional[str]:
"""Returns a string representing a human readable label for the metric."""
pass

@property
@abstractmethod
def conversion_params(self) -> ConversionTypeParams:
WilliamDee marked this conversation as resolved.
Show resolved Hide resolved
"""Accessor for conversion type params, enforces that it's set."""
pass
3 changes: 3 additions & 0 deletions dbt_semantic_interfaces/type_enums/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from dbt_semantic_interfaces.type_enums.aggregation_type import ( # noqa:F401
AggregationType,
)
from dbt_semantic_interfaces.type_enums.conversion_calculation_type import ( # noqa:F401
ConversionCalculationType,
)
from dbt_semantic_interfaces.type_enums.dimension_type import DimensionType # noqa:F401
from dbt_semantic_interfaces.type_enums.entity_type import EntityType # noqa:F401
from dbt_semantic_interfaces.type_enums.metric_type import MetricType # noqa:F401
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from dbt_semantic_interfaces.enum_extension import ExtendedEnum


class ConversionCalculationType(ExtendedEnum):
"""Types of calculations for a conversion metric."""

CONVERSIONS = "conversions"
CONVERSION_RATE = "conversion_rate"
1 change: 1 addition & 0 deletions dbt_semantic_interfaces/type_enums/metric_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ class MetricType(ExtendedEnum):
RATIO = "ratio"
CUMULATIVE = "cumulative"
DERIVED = "derived"
CONVERSION = "conversion"