Refactor parameter value checks to use float conversion (#49)
build and deploy Speckle functions / publish-automate-function-version (push) Has been cancelled
build and deploy Speckle functions / publish-automate-function-version (push) Has been cancelled
- Updated methods to convert parameter values to float. - Removed type checks and exceptions for non-numeric types. - Simplified return logic for invalid conversions.
This commit is contained in:
committed by
GitHub
parent
90c5051fc6
commit
a704aded80
+1
-1
@@ -11,7 +11,7 @@ dependencies = [
|
||||
"pydantic==2.10.6",
|
||||
"python-dotenv>=1.0.1",
|
||||
"python-levenshtein>=0.26.1",
|
||||
"specklepy>=2.21.2",
|
||||
"specklepy>=2.21.3",
|
||||
]
|
||||
|
||||
|
||||
|
||||
+15
-8
@@ -253,9 +253,11 @@ class PropertyRules:
|
||||
parameter_value = PropertyRules.get_parameter_value(speckle_object, parameter_name)
|
||||
if parameter_value is None:
|
||||
return False
|
||||
if not isinstance(parameter_value, int | float):
|
||||
raise ValueError(f"Parameter value must be a number, got {type(parameter_value)}")
|
||||
return parameter_value <= PropertyRules.parse_number_from_string(threshold)
|
||||
try:
|
||||
parameter_value = float(parameter_value)
|
||||
except (ValueError, TypeError):
|
||||
return False # Return False if the value cannot be converted to a number
|
||||
return parameter_value > PropertyRules.parse_number_from_string(threshold)
|
||||
|
||||
@staticmethod
|
||||
def is_parameter_value_less_than(speckle_object: Base, parameter_name: str, threshold: str) -> bool:
|
||||
@@ -267,9 +269,12 @@ class PropertyRules:
|
||||
parameter_value = PropertyRules.get_parameter_value(speckle_object, parameter_name)
|
||||
if parameter_value is None:
|
||||
return False
|
||||
if not isinstance(parameter_value, int | float):
|
||||
raise ValueError(f"Parameter value must be a number, got {type(parameter_value)}")
|
||||
return parameter_value >= PropertyRules.parse_number_from_string(threshold)
|
||||
try:
|
||||
parameter_value = float(parameter_value)
|
||||
except (ValueError, TypeError):
|
||||
return False # Return False if the value cannot be converted to a number
|
||||
|
||||
return parameter_value < PropertyRules.parse_number_from_string(threshold)
|
||||
|
||||
@staticmethod
|
||||
def is_parameter_value_in_range(speckle_object: Base, parameter_name: str, value_range: str) -> bool:
|
||||
@@ -285,8 +290,10 @@ class PropertyRules:
|
||||
parameter_value = PropertyRules.get_parameter_value(speckle_object, parameter_name)
|
||||
if parameter_value is None:
|
||||
return False
|
||||
if not isinstance(parameter_value, int | float):
|
||||
raise ValueError(f"Parameter value must be a number, got {type(parameter_value)}")
|
||||
try:
|
||||
parameter_value = float(parameter_value)
|
||||
except (ValueError, TypeError):
|
||||
return False # Return False if the value cannot be converted to a number
|
||||
|
||||
return min_value <= parameter_value <= max_value
|
||||
|
||||
|
||||
Reference in New Issue
Block a user