Skip to content

Commit

Permalink
fix: recursion in AhbReader that lead to super large AHB models (#59)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Konstantin <konstantin.klein+github@hochfrequenz.de>
  • Loading branch information
hf-kklein and Konstantin authored Dec 5, 2024
1 parent 20c5d98 commit ecc612d
Show file tree
Hide file tree
Showing 5 changed files with 2,240 additions and 109,019 deletions.
11 changes: 7 additions & 4 deletions src/fundamend/reader/ahbreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ def get_anwendungsfaelle(self) -> list[Anwendungsfall]:
def _iter_segments_and_segment_groups(self, element: ET.Element) -> list[SegmentGroup | Segment]:
"""recursive function that builds a list of all segments and segment groups"""
result: list[Segment | SegmentGroup] = []
if _is_anwendungsfall(element) or _is_format(element) or _is_uebertragungsdatei(element):
should_go_deeper = _is_anwendungsfall(element) or _is_format(element) or _is_uebertragungsdatei(element)
if should_go_deeper:
for sub_element in element:
result.extend(self._iter_segments_and_segment_groups(sub_element))
if _is_segment_group(element):
Expand All @@ -235,14 +236,16 @@ def _iter_segments_and_segment_groups(self, element: ET.Element) -> list[Segment

def _read_anwendungsfall(self, original_element: ET.Element) -> Anwendungsfall:
segments_and_groups = []
root = self._element_tree.getroot()
for element in root:
for element in original_element:
segments_and_groups.extend(self._iter_segments_and_segment_groups(element))
format_element = original_element[0]
if _is_uebertragungsdatei(format_element):
format_element = original_element[0][0]
return Anwendungsfall(
pruefidentifikator=original_element.attrib["Pruefidentifikator"],
beschreibung=original_element.attrib["Beschreibung"],
kommunikation_von=original_element.attrib["Kommunikation_von"],
format=original_element[0].tag.lstrip("M_"),
format=format_element.tag.lstrip("M_"),
segments=[s for s in segments_and_groups if isinstance(s, Segment)],
segment_groups=[s for s in segments_and_groups if isinstance(s, SegmentGroup)],
)
Expand Down
Loading

0 comments on commit ecc612d

Please sign in to comment.