Skip to content

Commit

Permalink
Script optimization to mark dataframe row that it has been visited al…
Browse files Browse the repository at this point in the history
…ready, which is needed in the case of multiple parents - otherwise we traverse the tree a stupid number of times for all possible parents.
  • Loading branch information
khuck committed Jul 29, 2024
1 parent 813f2a2 commit 70f0e5a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/scripts/apex-treesummary.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,14 +336,18 @@ def graphRank2(index, df, parentNode, droplist, args):
#name = df.loc[df['node index'] == index, 'name'].iloc[0]
childNode = parentNode.addChild(name, childDF)

# If we have visited this tree before, we are done.
if childDF['visited'].item():
return

# slice out the children from the dataframe
children = df[df['parent index'] == index]
# Iterate over the children indexes and add to our node
for child in children['node index'].unique():
if child == index:
continue
graphRank2(child, df, childNode, droplist, args)

df.loc[df['node index'] == index,'visited'] = True
import ast

def main():
Expand Down Expand Up @@ -416,6 +420,7 @@ def main():
root = TreeNode('apex tree base', pd.DataFrame())
root.index = -1
#unique = df.drop_duplicates(subset=["node index", "parent index", "name"], keep='first')
df['visited'] = False
graphRank2(0, df, root, droplist, args)

roots = [root]
Expand Down

0 comments on commit 70f0e5a

Please sign in to comment.