Skip to content

Commit

Permalink
IMPROVEMENT: prepare validation of derived parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
amilcarlucas committed Apr 29, 2024
1 parent c33e6aa commit 7e8d853
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions MethodicConfigurator/backend_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ class LocalFilesystem: # pylint: disable=too-many-instance-attributes, too-many
"""
def __init__(self, vehicle_dir: str, vehicle_type: str):
self.file_documentation_filename = "file_documentation.json"
self.file_documentation = {}
self.vehicle_components_json_filename = "vehicle_components.json"
self.vehicle_components = {}
if vehicle_dir is not None:
self.re_init(vehicle_dir, vehicle_type)

Expand All @@ -97,6 +99,7 @@ def re_init(self, vehicle_dir: str, vehicle_type: str):
self.file_documentation = {}
self.param_default_dict = {}
self.doc_dict = {}
self.vehicle_components = {}

# Read intermediate parameters from files
self.file_parameters = self.read_params_from_files()
Expand All @@ -121,6 +124,7 @@ def re_init(self, vehicle_dir: str, vehicle_type: str):
pass
if file_found:
self.validate_forced_parameters_in_file_documentation()
self.validate_derived_parameters_in_file_documentation()
else:
logging_warning("No file documentation will be available.")

Expand All @@ -130,6 +134,7 @@ def re_init(self, vehicle_dir: str, vehicle_type: str):
self.doc_dict = create_doc_dict(xml_root, vehicle_type, TOOLTIP_MAX_LENGTH)

self.extend_and_reformat_parameter_documentation_metadata()
self.load_vehicle_components_json_data()

def validate_forced_parameters_in_file_documentation(self):
for filename, file_info in self.file_documentation.items():
Expand All @@ -148,6 +153,23 @@ def validate_forced_parameters_in_file_documentation(self):
" 'Change Reason' attribute not found.",
self.file_documentation_filename, filename, parameter)

def validate_derived_parameters_in_file_documentation(self):
for filename, file_info in self.file_documentation.items():
if 'derived_parameters' in file_info and filename in self.file_parameters:
if not isinstance(file_info['derived_parameters'], dict):
logging_error("Error in file '%s': '%s' derived parameter is not a dictionary",
self.file_documentation_filename, filename)
continue
for parameter, parameter_info in file_info['derived_parameters'].items():
if "New Value" not in parameter_info:
logging_error("Error in file '%s': '%s' derived parameter '%s'"
" 'New Value' attribute not found.",
self.file_documentation_filename, filename, parameter)
if "Change Reason" not in parameter_info:
logging_error("Error in file '%s': '%s' derived parameter '%s'"
" 'Change Reason' attribute not found.",
self.file_documentation_filename, filename, parameter)

def extend_and_reformat_parameter_documentation_metadata(self):
for param_name, param_info in self.doc_dict.items():
if 'fields' in param_info:
Expand Down Expand Up @@ -413,6 +435,7 @@ def load_vehicle_components_json_data(self):
logging_warning("File '%s' not found in %s.", self.vehicle_components_json_filename, self.vehicle_dir)
except JSONDecodeError:
logging_error("Error decoding JSON data from file '%s'.", filepath)
self.vehicle_components = data
return data

def save_vehicle_components_json_data(self, data) -> bool:
Expand Down

0 comments on commit 7e8d853

Please sign in to comment.