From 35eb1f9ac70ea7d3c0c375a7aad658aab3344acb Mon Sep 17 00:00:00 2001 From: PH Tools Date: Tue, 15 Oct 2024 16:55:00 -0400 Subject: [PATCH] fix(read wufi): Fix read WUFI Error - handle case where there are no zones covered by Mech System (index error) --- PHX/from_WUFI_XML/phx_schemas.py | 3 +++ PHX/from_WUFI_XML/wufi_file_schema.py | 4 ++-- PHX/from_WUFI_XML/wufi_file_types.py | 6 +++--- output.txt | 5 +++++ 4 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 output.txt diff --git a/PHX/from_WUFI_XML/phx_schemas.py b/PHX/from_WUFI_XML/phx_schemas.py index aff0e79..d26d657 100644 --- a/PHX/from_WUFI_XML/phx_schemas.py +++ b/PHX/from_WUFI_XML/phx_schemas.py @@ -414,6 +414,9 @@ def _PhxVariant(_xml_variant_data: wufi_xml.WufiVariant, _phx_project_host: PhxP # -- Build the HVAC Systems, Devices, and Distribution phx_obj.clear_mechanical_collections() for xml_system_data in _xml_variant_data.HVAC.Systems: + if len(xml_system_data.ZonesCoverage) == 0: + continue + new_mechanical_collection = PhxMechanicalSystemCollection() new_mechanical_collection.display_name = xml_system_data.Name new_mechanical_collection.id_num = xml_system_data.IdentNr diff --git a/PHX/from_WUFI_XML/wufi_file_schema.py b/PHX/from_WUFI_XML/wufi_file_schema.py index ebd4bb5..1be87f3 100644 --- a/PHX/from_WUFI_XML/wufi_file_schema.py +++ b/PHX/from_WUFI_XML/wufi_file_schema.py @@ -113,8 +113,8 @@ class WufiPH_ClimateLocation(BaseModel): Longitude: wufi_unit.CardinalDegrees dUTC: int - HeightNNWeatherStation: wufi_unit.M - HeightNNBuilding: wufi_unit.M + HeightNNWeatherStation: Optional[wufi_unit.M] = wufi_unit.M(0) + HeightNNBuilding: Optional[wufi_unit.M] = wufi_unit.M(0) ClimateZone: int GroundThermalConductivity: wufi_unit.Watts_per_MK diff --git a/PHX/from_WUFI_XML/wufi_file_types.py b/PHX/from_WUFI_XML/wufi_file_types.py index 1f336fb..e45d038 100644 --- a/PHX/from_WUFI_XML/wufi_file_types.py +++ b/PHX/from_WUFI_XML/wufi_file_types.py @@ -49,9 +49,9 @@ def validate(cls, v: Union[str, Dict[str, Any]]): # -- Otherwise, pull the value out of the dict and convert the value to the right unit try: - result = convert(v["value"], v["unit_type"], cls.__unit_type__) - except Exception: - msg = f"Error converting input for '{cls.__name__}' using inputs: {v}" + result = convert(v["value"].strip(), v["unit_type"], cls.__unit_type__) + except Exception as e: + msg = f"Error converting to '{cls.__name__}' using the input of: [ {v} ]\n{e}" raise Exception(msg) # -- If the conversion was unsuccessful, raise an exception diff --git a/output.txt b/output.txt new file mode 100644 index 0000000..e7b9163 --- /dev/null +++ b/output.txt @@ -0,0 +1,5 @@ + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +> Reading in data from XML-File: /Users/em/Desktop/test/test2.xml +> Converting XML-data to a PHX-Model +> Saving the XML file to: .//Users/em/Desktop/test/test2.xml +> Successfully wrote to file.