hatchet/graphframe.py
def from_literal(graph_dict):
        """Create a GraphFrame from a list of dictionaries.

        TODO: calculate inclusive metrics automatically.

        Example:

        .. code-block:: console

            dag_ldict = [
                {
                    "name": "A",
                    "metrics": {"time (inc)": 130.0, "time": 0.0},
                    "children": [
                        {
                            "name": "B",
                            "metrics": {"time (inc)": 20.0, "time": 5.0},
                            "children": [
                                {
                                    "name": "C",
                                    "metrics": {"time (inc)": 5.0, "time": 5.0},
                                    "children": [
                                        {
                                            "name": "D",
                                            "metrics": {"time (inc)": 8.0, "time": 1.0},
                                        }
                                    ],
                                }
                            ],
                        },
                        {
                            "name": "E",
                            "metrics": {"time (inc)": 55.0, "time": 10.0},
                            "children": [
                                {"name": "H", "metrics": {"time (inc)": 1.0, "time": 9.0}}
                            ],
                        },
                    ],
                }
            ]

        Return:
            (GraphFrame): graphframe containing data from dictionaries
        """

        def parse_node_literal(child_dict, hparent):
            """Create node_dict for one node and then call the function
            recursively on all children.
            """

            hnode = Node(Frame({"name": child_dict["name"]}), hparent)

            node_dicts.append(
                dict(
                    {"node": hnode, "name": child_dict["name"]}, **child_dict["metrics"]
                )
            )
            hparent.add_child(hnode)

            if "children" in child_dict:
                for child in child_dict["children"]:
                    parse_node_literal(child, hnode)

        list_roots = []
        node_dicts = []

        # start with creating a node_dict for each root
        for i in range(len(graph_dict)):
            graph_root = Node(Frame({"name": graph_dict[i]["name"]}), None)

            node_dict = {"node": graph_root, "name": graph_dict[i]["name"]}
            node_dict.update(**graph_dict[i]["metrics"])
            node_dicts.append(node_dict)

            list_roots.append(graph_root)

            # call recursively on all children of root
            if "children" in graph_dict[i]:
                for child in graph_dict[i]["children"]:
                    parse_node_literal(child, graph_root)

        graph = Graph(list_roots)
        graph.enumerate_traverse()

        exc_metrics = []
        inc_metrics = []
        for key in graph_dict[i]["metrics"].keys():
            if "(inc)" in key:
                inc_metrics.append(key)
            else:
                exc_metrics.append(key)

        dataframe = pd.DataFrame(data=node_dicts)
        dataframe.set_index(["node"], inplace=True)
        dataframe.sort_index(inplace=True)

        return GraphFrame(graph, dataframe, exc_metrics, inc_metrics)
Create a GraphFrame from a list of dictionaries.

        TODO: calculate inclusive metrics automatically.

        Example:

        .. code-block:: console

            dag_ldict = [
                {
                    "name": "A",
                    "metrics": {"time (inc)": 130.0, "time": 0.0},
                    "children": [
                        {
                            "name": "B",
                            "metrics": {"time (inc)": 20.0, "time": 5.0},
                            "children": [
                                {
                                    "name": "C",
                                    "metrics": {"time (inc)": 5.0, "time": 5.0},
                                    "children": [
                                        {
                                            "name": "D",
                                            "metrics": {"time (inc)": 8.0, "time": 1.0},
                                        }
                                    ],
                                }
                            ],
                        },
                        {
                            "name": "E",
                            "metrics": {"time (inc)": 55.0, "time": 10.0},
                            "children": [
                                {"name": "H", "metrics": {"time (inc)": 1.0, "time": 9.0}}
                            ],
                        },
                    ],
                }
            ]

        Return:
            (GraphFrame): graphframe containing data from dictionaries
        
Create a GraphFrame from a list of dictionaries.
TODO: calculate inclusive metrics automatically.
Create a GraphFrame from a list of dictionaries . TODO : calculate inclusive metrics automatically .
def from_literal(graph_dict):
        def parse_node_literal(child_dict, hparent):
            hnode = Node(Frame({"name": child_dict["name"]}), hparent)
            node_dicts.append(
                dict(
                    {"node": hnode, "name": child_dict["name"]}, **child_dict["metrics"]
                )
            )
            hparent.add_child(hnode)
            if "children" in child_dict:
                for child in child_dict["children"]:
                    parse_node_literal(child, hnode)
        list_roots = []
        node_dicts = []
        for i in range(len(graph_dict)):
            graph_root = Node(Frame({"name": graph_dict[i]["name"]}), None)
            node_dict = {"node": graph_root, "name": graph_dict[i]["name"]}
            node_dict.update(**graph_dict[i]["metrics"])
            node_dicts.append(node_dict)
            list_roots.append(graph_root)
            if "children" in graph_dict[i]:
                for child in graph_dict[i]["children"]:
                    parse_node_literal(child, graph_root)
        graph = Graph(list_roots)
        graph.enumerate_traverse()
        exc_metrics = []
        inc_metrics = []
        for key in graph_dict[i]["metrics"].keys():
            if "(inc)" in key:
                inc_metrics.append(key)
            else:
                exc_metrics.append(key)
        dataframe = pd.DataFrame(data=node_dicts)
        dataframe.set_index(["node"], inplace=True)
        dataframe.sort_index(inplace=True)
        return GraphFrame(graph, dataframe, exc_metrics, inc_metrics)
def from_literal ( graph_dict ) : def parse_node_literal ( child_dict , hparent ) : """Create node_dict for one node and then call the function
            recursively on all children.
            """ hnode = Node ( Frame ( { "name" : child_dict [ "name" ] } ) , hparent ) node_dicts . append ( dict ( { "node" : hnode , "name" : child_dict [ "name" ] } , ** child_dict [ "metrics" ] ) ) hparent . add_child ( hnode ) if "children" in child_dict : for child in child_dict [ "children" ] : parse_node_literal ( child , hnode ) list_roots = [ ] node_dicts = [ ] for i in range ( len ( graph_dict ) ) : graph_root = Node ( Frame ( { "name" : graph_dict [ i ] [ "name" ] } ) , None ) node_dict = { "node" : graph_root , "name" : graph_dict [ i ] [ "name" ] } node_dict . update ( ** graph_dict [ i ] [ "metrics" ] ) node_dicts . append ( node_dict ) list_roots . append ( graph_root ) if "children" in graph_dict [ i ] : for child in graph_dict [ i ] [ "children" ] : parse_node_literal ( child , graph_root ) graph = Graph ( list_roots ) graph . enumerate_traverse ( ) exc_metrics = [ ] inc_metrics = [ ] for key in graph_dict [ i ] [ "metrics" ] . keys ( ) : if "(inc)" in key : inc_metrics . append ( key ) else : exc_metrics . append ( key ) dataframe = pd . DataFrame ( data = node_dicts ) dataframe . set_index ( [ "node" ] , inplace = True ) dataframe . sort_index ( inplace = True ) return GraphFrame ( graph , dataframe , exc_metrics , inc_metrics )
Create a GraphFrame from a list of dictionaries.
Create a GraphFrame from a list of dictionaries .
"""Create a GraphFrame from a list of dictionaries.

        TODO: calculate inclusive metrics automatically.

        Example:

        .. code-block:: console

            dag_ldict = [
                {
                    "name": "A",
                    "metrics": {"time (inc)": 130.0, "time": 0.0},
                    "children": [
                        {
                            "name": "B",
                            "metrics": {"time (inc)": 20.0, "time": 5.0},
                            "children": [
                                {
                                    "name": "C",
                                    "metrics": {"time (inc)": 5.0, "time": 5.0},
                                    "children": [
                                        {
                                            "name": "D",
                                            "metrics": {"time (inc)": 8.0, "time": 1.0},
                                        }
                                    ],
                                }
                            ],
                        },
                        {
                            "name": "E",
                            "metrics": {"time (inc)": 55.0, "time": 10.0},
                            "children": [
                                {"name": "H", "metrics": {"time (inc)": 1.0, "time": 9.0}}
                            ],
                        },
                    ],
                }
            ]

        Return:
            (GraphFrame): graphframe containing data from dictionaries
        """ """Create node_dict for one node and then call the function
            recursively on all children.
            """ # start with creating a node_dict for each root # call recursively on all children of root
graph_dict
examples
None