#NEWLINE# def get_priority( root , root_priority , target_index ) : #NEWLINE# #INDENT# def count_max_serial_children( task ) : #NEWLINE# #INDENT# result = None #NEWLINE# if ( 'Action' in task ) : #NEWLINE# #INDENT# result = 0 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if task [ 'Task' ] . get ( 'parallel' , False ) : #NEWLINE# #INDENT# result = max ( [ ( count_max_serial_children ( c ) + 1 ) for c in task [ 'Task' ] [ 'children' ] ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# result = reduce ( ( lambda x , y : ( x + y ) ) , [ ( count_max_serial_children ( c ) + 1 ) for c in task [ 'Task' ] [ 'children' ] ] ) #NEWLINE# #UNINDENT# #UNINDENT# return result #NEWLINE# #UNINDENT# type_ = [ k for k in root . keys ( ) ] [ 0 ] #NEWLINE# is_parallel = root [ type_ ] . get ( 'parallel' , False ) #NEWLINE# priority = None #NEWLINE# brothers = root [ type_ ] [ 'children' ] [ : target_index ] #NEWLINE# if is_parallel : #NEWLINE# #INDENT# priority = ( root_priority + 1 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not brothers ) : #NEWLINE# #INDENT# priority = ( root_priority + 1 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# priority = ( ( reduce ( ( lambda x , y : ( x + y ) ) , [ ( count_max_serial_children ( b ) + 1 ) for b in brothers ] ) + root_priority ) + 1 ) #NEWLINE# #UNINDENT# #UNINDENT# return priority