in violation_detection.py [0:0]
def passing_atomic_value(atomic, value):
# ['=', '>', '<', '>=', '<=', '!=', 'BETWEEN', 'REGEXP', 'IN', 'NOTNULL']
OP_MAPPING = {'=': op.eq, '>': op.gt, '<': op.lt, '>=': op.ge, '<=': op.le, '!=': op.ne}
operator, ref = atomic['operator'], atomic['values']
if operator == 'NOTNULL':
return True
elif operator == 'IN':
return (value is not None) and (value in ref)
elif operator == 'BETWEEN':
# TODO: Check how to compare times
return (value >= ref[0]) and (value <= ref[1])
elif operator == 'REGEXP':
# TODO: Match or Search is more suitable?
return bool(re.match(ref, value))
elif operator in OP_MAPPING:
return OP_MAPPING[operator](value, ref)
else:
raise Exception(f'Invalid operator {operator}')