Implementing depth-first preparation steps generation so tasks are in a more reasonable order.
This commit is contained in:
parent
290eea8ec2
commit
4bf120ec8d
@ -5,10 +5,10 @@ from anytree.importer import DictImporter
|
||||
from sys import argv
|
||||
|
||||
|
||||
def build_rows_depth_first(node, rows, leaf_count=0):
|
||||
def build_table_depth_first(node, rows, leaf_count=0):
|
||||
|
||||
for child in sorted(node.children, key=lambda x: x.height, reverse=True):
|
||||
leaf_count = build_rows_depth_first(child, rows, leaf_count)
|
||||
leaf_count = build_table_depth_first(child, rows, leaf_count)
|
||||
|
||||
colspan = 0
|
||||
if node.siblings:
|
||||
@ -34,6 +34,16 @@ def build_rows_depth_first(node, rows, leaf_count=0):
|
||||
return leaf_count
|
||||
|
||||
|
||||
def generate_steps_depth_first(node, steps=[]):
|
||||
for child in sorted(node.children, key=lambda x: x.height, reverse=True):
|
||||
steps = generate_steps_depth_first(child, steps)
|
||||
|
||||
if not node.is_leaf:
|
||||
steps.append(node.description if node.description else node.name)
|
||||
|
||||
return steps
|
||||
|
||||
|
||||
if len(argv) < 2:
|
||||
print(f"usage: {argv[0]} <json file>")
|
||||
exit()
|
||||
@ -61,9 +71,9 @@ print("<h2>Steps</h2>")
|
||||
print("<ol>")
|
||||
|
||||
for sub_recipe in sub_recipes:
|
||||
tasks = [node for node in LevelOrderIter(sub_recipe) if not node.is_leaf]
|
||||
for task in reversed(tasks):
|
||||
print(f" <li>{task.description if task.description else task.name}</li>")
|
||||
tasks = generate_steps_depth_first(sub_recipe, steps=[])
|
||||
for task in tasks:
|
||||
print(f" <li>{task}</li>")
|
||||
|
||||
print("</ol>")
|
||||
|
||||
@ -75,7 +85,7 @@ for sub_recipe in sub_recipes:
|
||||
for i in range(len(sub_recipe.leaves)):
|
||||
output_rows.append([])
|
||||
|
||||
build_rows_depth_first(sub_recipe, output_rows)
|
||||
build_table_depth_first(sub_recipe, output_rows)
|
||||
|
||||
for row in output_rows:
|
||||
print("<tr>")
|
||||
|
Loading…
x
Reference in New Issue
Block a user