Skip to content

Commit c871add

Browse files
authored
Add first_value and last_value aggregations and allow winsorization.
2 parents 55f32b6 + 6c5680c commit c871add

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

eppo_metrics_sync/schema/eppo_metric_schema.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@
156156
},
157157
"operation": {
158158
"description": "Which aggregation to apply to the fact",
159-
"enum": ["sum", "count", "distinct_entity", "threshold", "conversion", "retention", "count_distinct"]
159+
"enum": ["sum", "count", "distinct_entity", "threshold", "conversion", "retention", "count_distinct", "last_value", "first_value"]
160160
},
161161
"filters": {
162162
"description": "Optional fact property filters to apply",
@@ -254,7 +254,7 @@
254254
},
255255
"operation": {
256256
"description": "How to aggregate fact",
257-
"enum": ["sum", "count", "distinct_entity", "count_distinct"]
257+
"enum": ["sum", "count", "distinct_entity", "count_distinct", "last_value", "first_value"]
258258
},
259259
"filters": {
260260
"description": "Optional fact property filters to apply",

eppo_metrics_sync/validation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,13 @@ def aggregation_is_valid(aggregation):
112112
error_message = []
113113

114114
if aggregation['operation'] not in ['sum', 'count', 'count_distinct', 'distinct_entity', 'threshold', 'retention',
115-
'conversion']:
115+
'conversion', 'last_value', 'first_value']:
116116
error_message.append(
117117
'Invalid aggregation operation: ' + aggregation['operation']
118118
)
119119

120120
# can only winsorize sum or count metrics
121-
if aggregation['operation'] not in ['sum', 'count']:
121+
if aggregation['operation'] not in ['sum', 'count', 'last_value', 'first_value']:
122122
if [name for name in winsorization_parameters if name in aggregation]:
123123
error_message.append(
124124
'Cannot winsorize a metric with operation ' + aggregation['operation']

tests/test_validation.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,16 @@ def test_count_distinct():
129129

130130
res = aggregation_is_valid(test_agg)
131131
assert res == None
132+
133+
def test_last_value():
134+
res = aggregation_is_valid({'operation': 'last_value'})
135+
assert res == None
136+
137+
def test_first_value():
138+
res = aggregation_is_valid({'operation': 'first_value'})
139+
assert res == None
140+
141+
def test_valid_yaml():
142+
eppo_metrics_sync = EppoMetricsSync(directory=None)
143+
eppo_metrics_sync.load_eppo_yaml(path='tests/yaml/valid/purchases.yaml')
144+
eppo_metrics_sync.validate()

tests/yaml/valid/purchases.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,11 @@ metrics:
5252
operation: equals
5353
values:
5454
- "UNITED STATES"
55-
55+
- name: Last Purchase Amount
56+
entity: User
57+
description: The last purchase amount with winsorization
58+
numerator:
59+
fact_name: Purchase
60+
operation: last_value
61+
winsorization_lower_percentile: 0.05
62+
winsorization_upper_percentile: 0.95

0 commit comments

Comments
 (0)