readabilite: simplify scoring loop
For perfomance
This commit is contained in:
		@@ -93,33 +93,19 @@ def score_node(node):
 | 
				
			|||||||
    return score
 | 
					    return score
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def score_all(root):
 | 
					def score_all(node, grades=None):
 | 
				
			||||||
    grades = {}
 | 
					    " Fairly dumb loop to score all worthwhile nodes. Tries to be fast "
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for node in list(root.iter()):
 | 
					    if grades is None:
 | 
				
			||||||
        score = score_node(node)
 | 
					        grades = {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        parent = node.getparent()
 | 
					    for child in node:
 | 
				
			||||||
        clean_node(node)
 | 
					        score = score_node(child)
 | 
				
			||||||
 | 
					        child.attrib['seen'] = 'yes, ' + str(int(score))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if parent is not None and node.getparent() is None:
 | 
					        if score > 0:
 | 
				
			||||||
            # if the node got deleted/dropped (else, nothing to do)
 | 
					            spread_score(child, score, grades)
 | 
				
			||||||
            # maybe now the parent only contains 1 item and needs to be flattened?
 | 
					            score_all(child, grades)
 | 
				
			||||||
 | 
					 | 
				
			||||||
            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
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user