Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update model_builder.py #1267

Merged
merged 4 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tools/abel/model/entity_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions tools/abel/model/from_spreadsheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions tools/abel/model/model_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,17 @@ 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 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
for guid in self.site.entities:
Expand All @@ -208,17 +219,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:
Expand Down
3 changes: 1 addition & 2 deletions tools/abel/tests/entity_field_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading