Skip to content

Commit

Permalink
Create global Participant Order
Browse files Browse the repository at this point in the history
  • Loading branch information
Toddelismyname committed Feb 7, 2025
1 parent 121a047 commit 0d04396
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions format.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
'coupling-scheme:': 5
}

PARTICIPANT_ORDER = {
'provide-mesh': 1,
'receive-mesh': 2,
'write-data': 3,
'read-data': 4,
'mapping:': 5
}

def custom_sort_key(elem, order):
"""
Custom sorting key for XML elements like top-level-order.
Expand Down Expand Up @@ -159,20 +167,12 @@ def printChildren(self, element, level):
for i, group in enumerate(sorted_children, start=1):
# Special handling for participants to reorder child elements
if 'participant' in str(group.tag):
# Define order for participant child elements with more generalized matching
participant_order = {
'provide-mesh': 1,
'receive-mesh': 2,
'write-data': 3,
'read-data': 4,
'mapping:': 5 # Matches mapping:nearest-neighbor, mapping:rbf, etc.
}

# Sort participant's children based on the defined order
sorted_participant_children = sorted(
group.getchildren(),
key=lambda child: next(
(rank for prefix, rank in participant_order.items()
(rank for prefix, rank in PARTICIPANT_ORDER.items()
if str(child.tag).startswith(prefix)),
6 # Unknown elements appear last
)
Expand Down

0 comments on commit 0d04396

Please sign in to comment.