@@ -31,7 +31,9 @@ class ConditionMatchTypes(object):
31
31
EXACT = 'exact'
32
32
EXISTS = 'exists'
33
33
GREATER_THAN = 'gt'
34
+ GREATER_THAN_OR_EQUAL = 'ge'
34
35
LESS_THAN = 'lt'
36
+ LESS_THAN_OR_EQUAL = 'le'
35
37
SEMVER_EQ = 'semver_eq'
36
38
SEMVER_GE = 'semver_ge'
37
39
SEMVER_GT = 'semver_gt'
@@ -177,6 +179,40 @@ def greater_than_evaluator(self, index):
177
179
178
180
return user_value > condition_value
179
181
182
+ def greater_than_or_equal_evaluator (self , index ):
183
+ """ Evaluate the given greater than or equal to match condition for the user attributes.
184
+
185
+ Args:
186
+ index: Index of the condition to be evaluated.
187
+
188
+ Returns:
189
+ Boolean:
190
+ - True if the user attribute value is greater than or equal to the condition value.
191
+ - False if the user attribute value is less than the condition value.
192
+ None: if the condition value isn't finite or the user attribute value isn't finite.
193
+ """
194
+ condition_name = self .condition_data [index ][0 ]
195
+ condition_value = self .condition_data [index ][1 ]
196
+ user_value = self .attributes .get (condition_name )
197
+
198
+ if not validator .is_finite_number (condition_value ):
199
+ self .logger .warning (audience_logs .UNKNOWN_CONDITION_VALUE .format (self ._get_condition_json (index )))
200
+ return None
201
+
202
+ if not self .is_value_a_number (user_value ):
203
+ self .logger .warning (
204
+ audience_logs .UNEXPECTED_TYPE .format (self ._get_condition_json (index ), type (user_value ), condition_name )
205
+ )
206
+ return None
207
+
208
+ if not validator .is_finite_number (user_value ):
209
+ self .logger .warning (
210
+ audience_logs .INFINITE_ATTRIBUTE_VALUE .format (self ._get_condition_json (index ), condition_name )
211
+ )
212
+ return None
213
+
214
+ return user_value >= condition_value
215
+
180
216
def less_than_evaluator (self , index ):
181
217
""" Evaluate the given less than match condition for the user attributes.
182
218
@@ -211,6 +247,40 @@ def less_than_evaluator(self, index):
211
247
212
248
return user_value < condition_value
213
249
250
+ def less_than_or_equal_evaluator (self , index ):
251
+ """ Evaluate the given less than or equal to match condition for the user attributes.
252
+
253
+ Args:
254
+ index: Index of the condition to be evaluated.
255
+
256
+ Returns:
257
+ Boolean:
258
+ - True if the user attribute value is less than or equal to the condition value.
259
+ - False if the user attribute value is greater than the condition value.
260
+ None: if the condition value isn't finite or the user attribute value isn't finite.
261
+ """
262
+ condition_name = self .condition_data [index ][0 ]
263
+ condition_value = self .condition_data [index ][1 ]
264
+ user_value = self .attributes .get (condition_name )
265
+
266
+ if not validator .is_finite_number (condition_value ):
267
+ self .logger .warning (audience_logs .UNKNOWN_CONDITION_VALUE .format (self ._get_condition_json (index )))
268
+ return None
269
+
270
+ if not self .is_value_a_number (user_value ):
271
+ self .logger .warning (
272
+ audience_logs .UNEXPECTED_TYPE .format (self ._get_condition_json (index ), type (user_value ), condition_name )
273
+ )
274
+ return None
275
+
276
+ if not validator .is_finite_number (user_value ):
277
+ self .logger .warning (
278
+ audience_logs .INFINITE_ATTRIBUTE_VALUE .format (self ._get_condition_json (index ), condition_name )
279
+ )
280
+ return None
281
+
282
+ return user_value <= condition_value
283
+
214
284
def substring_evaluator (self , index ):
215
285
""" Evaluate the given substring match condition for the given user attributes.
216
286
@@ -331,7 +401,8 @@ def split_semantic_version(self, target):
331
401
target_parts = []
332
402
333
403
if self .has_white_space (target ):
334
- raise Exception (Errors .INVALID_ATTRIBUTE_FORMAT )
404
+ self .logger .warning (Errors .INVALID_ATTRIBUTE_FORMAT )
405
+ return None
335
406
336
407
if self .is_pre_release (target ):
337
408
target_parts = target .split (SemverType .IS_PRE_RELEASE )
@@ -340,20 +411,24 @@ def split_semantic_version(self, target):
340
411
341
412
if target_parts :
342
413
if len (target_parts ) < 1 :
343
- raise Exception (Errors .INVALID_ATTRIBUTE_FORMAT )
414
+ self .logger .warning (Errors .INVALID_ATTRIBUTE_FORMAT )
415
+ return None
344
416
target_prefix = str (target_parts [0 ])
345
417
target_suffix = target_parts [1 :]
346
418
347
419
dot_count = target_prefix .count ("." )
348
420
if dot_count > 2 :
349
- raise Exception (Errors .INVALID_ATTRIBUTE_FORMAT )
421
+ self .logger .warning (Errors .INVALID_ATTRIBUTE_FORMAT )
422
+ return None
350
423
351
424
target_version_parts = target_prefix .split ("." )
352
425
if len (target_version_parts ) != dot_count + 1 :
353
- raise Exception (Errors .INVALID_ATTRIBUTE_FORMAT )
426
+ self .logger .warning (Errors .INVALID_ATTRIBUTE_FORMAT )
427
+ return None
354
428
for part in target_version_parts :
355
429
if not part .isdigit ():
356
- raise Exception (Errors .INVALID_ATTRIBUTE_FORMAT )
430
+ self .logger .warning (Errors .INVALID_ATTRIBUTE_FORMAT )
431
+ return None
357
432
358
433
if target_suffix :
359
434
target_version_parts .extend (target_suffix )
@@ -453,7 +528,9 @@ def compare_user_version_with_target_version(self, index):
453
528
ConditionMatchTypes .SEMVER_GT : semver_greater_than_evaluator ,
454
529
ConditionMatchTypes .SEMVER_LE : semver_less_than_or_equal_evaluator ,
455
530
ConditionMatchTypes .SEMVER_LT : semver_less_than_evaluator ,
456
- ConditionMatchTypes .SUBSTRING : substring_evaluator
531
+ ConditionMatchTypes .SUBSTRING : substring_evaluator ,
532
+ ConditionMatchTypes .LESS_THAN_OR_EQUAL : less_than_or_equal_evaluator ,
533
+ ConditionMatchTypes .GREATER_THAN_OR_EQUAL : greater_than_or_equal_evaluator ,
457
534
}
458
535
459
536
def evaluate (self , index ):
0 commit comments