diff --git a/qc_openscenario/checks/data_type_checker/non_negative_transition_time_in_light_state_action.py b/qc_openscenario/checks/data_type_checker/non_negative_transition_time_in_light_state_action.py index 7eb2f57..dce5958 100644 --- a/qc_openscenario/checks/data_type_checker/non_negative_transition_time_in_light_state_action.py +++ b/qc_openscenario/checks/data_type_checker/non_negative_transition_time_in_light_state_action.py @@ -87,7 +87,11 @@ def check_rule(checker_data: models.CheckerData) -> None: return - current_numeric_value = float(current_transition_time) + current_numeric_value = utils.to_float(current_transition_time) + + if current_numeric_value is None: + continue + has_issue = current_numeric_value < 0 if has_issue: diff --git a/qc_openscenario/checks/data_type_checker/positive_duration_in_phase.py b/qc_openscenario/checks/data_type_checker/positive_duration_in_phase.py index c3aabaf..8fb66f8 100644 --- a/qc_openscenario/checks/data_type_checker/positive_duration_in_phase.py +++ b/qc_openscenario/checks/data_type_checker/positive_duration_in_phase.py @@ -74,7 +74,11 @@ def check_rule(checker_data: models.CheckerData) -> None: return - current_numeric_value = float(current_duration) + current_numeric_value = utils.to_float(current_duration) + + if current_numeric_value is None: + continue + has_issue = current_numeric_value < 0 if has_issue: diff --git a/qc_openscenario/checks/utils.py b/qc_openscenario/checks/utils.py index f9ba550..1bdb6e1 100644 --- a/qc_openscenario/checks/utils.py +++ b/qc_openscenario/checks/utils.py @@ -10,6 +10,13 @@ PARAMETER_PATTERN = re.compile(r"[$][A-Za-z_][A-Za-z0-9_]*") +def to_float(s): + try: + return float(s) + except (ValueError, TypeError): + return None + + def get_root_without_default_namespace(path: str) -> etree._ElementTree: with open(path, "rb") as raw_file: xml_string = raw_file.read().decode()