From e42af7257a46286fb466a0f923d8355846a7f1ce Mon Sep 17 00:00:00 2001 From: travis Date: Thu, 8 Feb 2024 11:01:55 -0800 Subject: [PATCH 1/3] update model_builer.py --- tools/abel/model/from_spreadsheet.py | 6 +++--- tools/abel/model/model_builder.py | 21 ++++++++++----------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/tools/abel/model/from_spreadsheet.py b/tools/abel/model/from_spreadsheet.py index de25018bb..95cbb6e48 100644 --- a/tools/abel/model/from_spreadsheet.py +++ b/tools/abel/model/from_spreadsheet.py @@ -75,11 +75,11 @@ def LoadFieldsFromSpreadsheet( entity_field_entries: List[Dict[str, str]], guid_to_entity_map: GuidToEntityMap, ) -> List[FieldTranslation]: - """Loads list of entity field maps into FieldTranslation instances. + """Loads list of entity fields from a spreadsheet into FieldTranslation + instances. Once the entity field mapping is loaded into an FieldTranslation instance, - it - is then added to the ABEL internal model. + it is then added to the ABEL internal model. Args: entity_field_entries: A list of python dictionaries mapping entity field diff --git a/tools/abel/model/model_builder.py b/tools/abel/model/model_builder.py index f22925333..7c6d88815 100644 --- a/tools/abel/model/model_builder.py +++ b/tools/abel/model/model_builder.py @@ -199,6 +199,16 @@ def Build(self) -> ...: Returns: built Model instance """ + # First add states to fields + for field in self.fields: + # For each state in the model + if isinstance(field, MultistateValueField): + for state in self.states: + # Create edges between states and their corresponding Multi-state + # value field in stances. + if state.reporting_entity_guid == field.reporting_entity_guid: + if state.std_field_name == field.std_field_name: + field.AddState(state) self.site.entities = self.entities # For each entity, Add connections where entity is the source for guid in self.site.entities: @@ -208,17 +218,6 @@ def Build(self) -> ...: entity.AddConnection(connection) # For each field in the model for field in self.fields: - # For each state in the model - for state in self.states: - # Create edges between states and their corresponding Multi-state - # value field in stances. - if state.reporting_entity_guid == guid: - if state.std_field_name in ( - field.reporting_entity_field_name, - field.std_field_name, - ): - if isinstance(field, MultistateValueField): - field.AddState(state) # Link field to entity if entity is virtual if isinstance(entity, VirtualEntity): if field.entity_guid == guid: From 923ff57771158875406a25c94042a1f6627961de Mon Sep 17 00:00:00 2001 From: travis Date: Thu, 8 Feb 2024 11:17:50 -0800 Subject: [PATCH 2/3] update model_builder.py --- tools/abel/model/model_builder.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/abel/model/model_builder.py b/tools/abel/model/model_builder.py index 7c6d88815..2b55d55fe 100644 --- a/tools/abel/model/model_builder.py +++ b/tools/abel/model/model_builder.py @@ -207,7 +207,8 @@ def Build(self) -> ...: # Create edges between states and their corresponding Multi-state # value field in stances. if state.reporting_entity_guid == field.reporting_entity_guid: - if state.std_field_name == field.std_field_name: + if state.std_field_name in (field.reporting_entity_field_name, + field.std_field_name): field.AddState(state) self.site.entities = self.entities # For each entity, Add connections where entity is the source From 6bbfc747369425f6c2859caa7e9cb9684d8347ca Mon Sep 17 00:00:00 2001 From: travis Date: Thu, 8 Feb 2024 11:29:35 -0800 Subject: [PATCH 3/3] update entity_field.py and tests --- tools/abel/model/entity_field.py | 4 ++-- tools/abel/tests/entity_field_test.py | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/tools/abel/model/entity_field.py b/tools/abel/model/entity_field.py index 52a4f5cec..720b19fdc 100644 --- a/tools/abel/model/entity_field.py +++ b/tools/abel/model/entity_field.py @@ -86,7 +86,7 @@ def __init__( def __eq__(self, other): if not isinstance(other, MissingField): - raise TypeError(f'{str(other)} must be a MissingField instance') + return False standard_field_name_eq = self.std_field_name == other.std_field_name entity_guid_eq = self.entity_guid == other.entity_guid reporting_field_eq = ( @@ -396,7 +396,7 @@ def __init__( def __eq__(self, other: ...) -> bool: if not isinstance(other, DimensionalValueField): - raise TypeError(f'{str(other)} must be an DimensionalValueField instance') + return False standard_field_name_eq = self.std_field_name == other.std_field_name raw_field_name_eq = self.raw_field_name == other.raw_field_name entity_guid_eq = self.entity_guid == other.entity_guid diff --git a/tools/abel/tests/entity_field_test.py b/tools/abel/tests/entity_field_test.py index 62234581e..f1bab4c37 100644 --- a/tools/abel/tests/entity_field_test.py +++ b/tools/abel/tests/entity_field_test.py @@ -94,8 +94,7 @@ def testMissingFieldEqualityRaisesTypeError(self): test_missing_field = MissingField.FromDict(TEST_MISSING_FIELD_DICT) # pylint: disable=unnecessary-dunder-call - with self.assertRaises(TypeError): - test_missing_field.__eq__('not a field') + self.assertFalse(test_missing_field.__eq__('not a field')) @mock.patch.object(GuidToEntityMap, 'GetEntityCodeByGuid') def testMissingFieldGetSpreadsheetRowMapping(self, test_get_code):