parent
a6befad136
commit
f044c242ef
|
@ -93,33 +93,19 @@ def score_node(node):
|
||||||
return score
|
return score
|
||||||
|
|
||||||
|
|
||||||
def score_all(root):
|
def score_all(node, grades=None):
|
||||||
|
" Fairly dumb loop to score all worthwhile nodes. Tries to be fast "
|
||||||
|
|
||||||
|
if grades is None:
|
||||||
grades = {}
|
grades = {}
|
||||||
|
|
||||||
for node in list(root.iter()):
|
for child in node:
|
||||||
score = score_node(node)
|
score = score_node(child)
|
||||||
|
child.attrib['seen'] = 'yes, ' + str(int(score))
|
||||||
|
|
||||||
parent = node.getparent()
|
if score > 0:
|
||||||
clean_node(node)
|
spread_score(child, score, grades)
|
||||||
|
score_all(child, grades)
|
||||||
if parent is not None and node.getparent() is None:
|
|
||||||
# if the node got deleted/dropped (else, nothing to do)
|
|
||||||
# maybe now the parent only contains 1 item and needs to be flattened?
|
|
||||||
|
|
||||||
gdparent = parent.getparent()
|
|
||||||
clean_node(parent)
|
|
||||||
|
|
||||||
if gdparent is not None and parent.getparent() is None:
|
|
||||||
# if the parent got deleted/dropped
|
|
||||||
spread_score(gdparent, score + grades[parent], grades)
|
|
||||||
|
|
||||||
else:
|
|
||||||
# if the parent was kept
|
|
||||||
spread_score(parent, score, grades)
|
|
||||||
|
|
||||||
else:
|
|
||||||
# if the node was kept
|
|
||||||
spread_score(node, score, grades)
|
|
||||||
|
|
||||||
return grades
|
return grades
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue