Skip to content

Commit

Permalink
added protocols for ConversionMetric properties
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamDee committed Nov 16, 2023
1 parent b4c0a82 commit 3ea5fc2
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 1 deletion.
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."""
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


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:
"""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"

0 comments on commit 3ea5fc2

Please sign in to comment.