12
12
]
13
13
14
14
timeframe_parameters = [
15
- 'aggregation_timeframe_value' ,
15
+ 'aggregation_timeframe_start_value' ,
16
+ 'aggregation_timeframe_end_value' ,
16
17
'aggregation_timeframe_unit'
17
18
]
18
19
@@ -27,15 +28,14 @@ def check_for_duplicated_names(payload, names, object_name):
27
28
28
29
29
30
def unique_names (payload ):
30
-
31
31
fact_source_names = []
32
32
fact_names = []
33
33
fact_property_names = []
34
34
35
35
for fact_source in payload .fact_sources :
36
36
fact_source_names .append (fact_source ['name' ])
37
37
fact_names .extend ([f ['name' ] for f in fact_source ['facts' ]])
38
- if ('properties' in fact_source ):
38
+ if ('properties' in fact_source ):
39
39
fact_property_names .extend (
40
40
[f ['name' ] for f in fact_source ['properties' ]]
41
41
)
@@ -45,14 +45,13 @@ def unique_names(payload):
45
45
check_for_duplicated_names (payload , fact_source_names , 'Fact source' )
46
46
check_for_duplicated_names (payload , fact_names , 'Fact' )
47
47
# TODO: check for distinct names within a given fact source
48
- #check_for_duplicated_names(payload, fact_property_names, 'Fact property')
48
+ # check_for_duplicated_names(payload, fact_property_names, 'Fact property')
49
49
check_for_duplicated_names (payload , metric_names , 'Metric' )
50
-
50
+
51
51
return True
52
52
53
53
54
54
def valid_fact_references (payload ):
55
-
56
55
fact_references = set ()
57
56
for metric in payload .metrics :
58
57
fact_references .add (metric ['numerator' ]['fact_name' ])
@@ -66,7 +65,7 @@ def valid_fact_references(payload):
66
65
67
66
if fact_references .issubset (set (fact_names )) == False :
68
67
payload .validation_errors .append (
69
- "Invalid fact reference(s): " +
68
+ "Invalid fact reference(s): " +
70
69
str (', ' .join (fact_references .difference (fact_names )))
71
70
)
72
71
@@ -79,7 +78,7 @@ def metric_aggregation_is_valid(payload):
79
78
payload .validation_errors .append (
80
79
f"{ m ['name' ]} has invalid numerator: { numerator_error } "
81
80
)
82
-
81
+
83
82
if 'denominator' in m :
84
83
denominator_error = aggregation_is_valid (m ['denominator' ])
85
84
if denominator_error :
@@ -89,11 +88,11 @@ def metric_aggregation_is_valid(payload):
89
88
90
89
91
90
def distinct_advanced_aggregation_parameter_set (
92
- aggregation ,
93
- operation ,
91
+ aggregation ,
92
+ operation ,
94
93
aggregation_parameter ,
95
- error_message
96
- ):
94
+ error_message
95
+ ):
97
96
if aggregation ['operation' ] == operation :
98
97
matched = [p for p in advanced_aggregation_parameters if p in aggregation ]
99
98
if len (matched ) == 0 :
@@ -110,10 +109,10 @@ def distinct_advanced_aggregation_parameter_set(
110
109
111
110
112
111
def aggregation_is_valid (aggregation ):
113
-
114
112
error_message = []
115
113
116
- if aggregation ['operation' ] not in ['sum' , 'count' , 'count_distinct' , 'distinct_entity' , 'threshold' , 'retention' , 'conversion' ]:
114
+ if aggregation ['operation' ] not in ['sum' , 'count' , 'count_distinct' , 'distinct_entity' , 'threshold' , 'retention' ,
115
+ 'conversion' ]:
117
116
error_message .append (
118
117
'Invalid aggregation operation: ' + aggregation ['operation' ]
119
118
)
@@ -124,12 +123,19 @@ def aggregation_is_valid(aggregation):
124
123
error_message .append (
125
124
'Cannot winsorize a metric with operation ' + aggregation ['operation' ]
126
125
)
127
-
128
- # either 0 or 2 of timeframe_parameters must be set
129
- if len ([name for name in timeframe_parameters if name in aggregation ]) == 1 :
126
+
127
+ # The aggregation_timeframe_unit must be specified if timeframe parameters are set
128
+ included_timeframe_parameters = [name for name in timeframe_parameters if name in aggregation ]
129
+
130
+ if 'aggregation_timeframe_value' in aggregation :
131
+ error_message .append (
132
+ 'The aggregation_timeframe_value parameter has been deprecated. Please use aggregation_timeframe_end instead.'
133
+ )
134
+
135
+ timeframe_unit_specified = 'aggregation_timeframe_unit' in included_timeframe_parameters
136
+ if len (included_timeframe_parameters ) > 0 and not timeframe_unit_specified :
130
137
error_message .append (
131
- 'Either both or neither aggregation_timeframe_value and ' +
132
- 'aggregation_timeframe_unit must be set'
138
+ 'The aggregation_timeframe_unit must be set to use timeframe parameters.'
133
139
)
134
140
135
141
# only set timeframe_parameters on a some operation types
@@ -154,20 +160,20 @@ def aggregation_is_valid(aggregation):
154
160
pass
155
161
156
162
distinct_advanced_aggregation_parameter_set (
157
- aggregation ,
158
- 'retention' ,
163
+ aggregation ,
164
+ 'retention' ,
159
165
'retention_threshold_days' ,
160
166
error_message
161
167
)
162
168
distinct_advanced_aggregation_parameter_set (
163
- aggregation ,
164
- 'conversion' ,
169
+ aggregation ,
170
+ 'conversion' ,
165
171
'conversion_threshold_days' ,
166
172
error_message
167
173
)
168
174
distinct_advanced_aggregation_parameter_set (
169
- aggregation ,
170
- 'threshold' ,
175
+ aggregation ,
176
+ 'threshold' ,
171
177
'threshold_metric_settings' ,
172
178
error_message
173
179
)
@@ -176,4 +182,3 @@ def aggregation_is_valid(aggregation):
176
182
return '\n ' .join (error_message )
177
183
else :
178
184
return None
179
-
0 commit comments