def get_descendant_levels(graph, tablename): #import networkx as nx import utool as ut parent_to_children = ut.edges_to_adjacency_list(graph.edges()) to_leafs = ut.path_to_leafs(tablename, parent_to_children) descendant_levels_ = ut.get_levels(to_leafs) descendant_levels = ut.longest_levels(descendant_levels_) return descendant_levels
def get_dependants(depc, tablename): """ gets level dependences table to the leaves Example: >>> # ENABLE_DOCTEST >>> from ibeis.depends_cache import * # NOQA >>> depc = testdata_depc() >>> tablename = 'chip' >>> result = ut.repr3(depc.get_dependants(tablename), nl=1) >>> print(result) [ ['chip'], ['keypoint'], ['fgweight', 'descriptor'], ['spam'], ] Example: >>> # ENABLE_DOCTEST >>> from ibeis.depends_cache import * # NOQA >>> depc = testdata_depc() >>> tablename = 'spam' >>> result = ut.repr3(depc.get_dependants(tablename), nl=1) >>> print(result) [ ['spam'], ] """ children_, parents_ = list(zip(*depc.get_edges())) parent_to_children = ut.group_items(parents_, children_) to_leafs = {tablename: ut.path_to_leafs(tablename, parent_to_children)} dependency_levels_ = ut.get_levels(to_leafs) dependency_levels = ut.longest_levels(dependency_levels_) return dependency_levels