<jupyter_start><jupyter_text>Initialize Tree first<jupyter_code>tree = Tree()<jupyter_output><empty_output><jupyter_text>Initialize all nodes<jupyter_code>node_labels = ["Analyze", "Design", "Build", "Test", "Package", "Accept", "Deploy", "End"]
def _init_nodes(node_labels: list = None):
    nodes = OrderedDict()
    for label in node_labels:
        nodes[label] = Node({"label": label, "time": 0})
    return nodes
nodes = _init_nodes(node_labels)<jupyter_output><empty_output><jupyter_text>Add all nodes to the tree<jupyter_code>for node in nodes.values():
    tree.add_node(node)<jupyter_output><empty_output><jupyter_text>Initialize all edges<jupyter_code>def _init_edges(node_labels, nodes):
    edges = []
    for i in range(len(node_labels)-1):
        from_node = nodes[node_labels[i]]
        to_node = nodes[node_labels[i+1]]
        edge1 = Edge(data={"weight": 0}, from_node=from_node, to_node=to_node)
        edges.append(edge1)
        if node_labels[len(node_labels)-1] not in edge1.prints():
            end_node = nodes[node_labels[len(node_labels)-1]]
            edge2 = Edge(data={"weight": 0}, from_node=from_node, to_node=end_node)
            edges.append(edge2)
    return edges
edges = _init_edges(node_labels, nodes)<jupyter_output><empty_output><jupyter_text>Add all edges to the tree<jupyter_code>for edge in edges:
    tree.add_edge(edge)<jupyter_output><empty_output><jupyter_text>Print tree to see if this was succesful<jupyter_code>process2 = [(str(x.prints()[0]).replace(":","="), str(x.prints()[1]).replace(":","=")) for x in tree.edges]
g = plot_process(process=process2, name="Init_Tree", path="../plots/")
g<jupyter_output><empty_output><jupyter_text>Looks good. Tree should get a function .plot() for easier plotting. Edges should have their weights as labels Nice! Let's structure that and put it into functions. We now want to fill the tree with real data from our dataset<jupyter_code>filename = Path("../data/gdsc2_public.csv")
data = load_table(filename)
times = time_for_phase(data, end_date=None)
work_time = work_times(times, time_col="duration_in_days")
work_freq = work_times(times)
merged = pd.merge(work_time, work_freq)
merged.set_index("work_item", inplace=True)
wi1 = merged.loc["WI_000165"].to_dict()<jupyter_output><empty_output><jupyter_text>Initialize Tree with all nodes<jupyter_code>tree = Tree()
tree, nodes = init_nodes(tree, data=wi1)<jupyter_output><empty_output><jupyter_text>Initialize edges<jupyter_code>data = add_phase(data, col_name="phase", cols=["from_phase", "to_phase"])
phases = data.groupby("work_item")["phase"].unique().to_dict()
wi1 = phases["WI_000165"]
tree, edges = init_edges(tree, nodes, path=wi1)
g = tree.plot(name="Init_Tree", path="../plots/")<jupyter_output><empty_output><jupyter_text>Looks good. Now we are able to convert every work item into a tree object. We should write a function for this.<jupyter_code>tree2 = get_tree(data, merged, "WI_000165")
tree2.plot(name="Init_Tree", path="../plots/")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14257360238174, 'fraction_numerical': 0.013562686073436983, 'mean_word_length': 6.393643031784841, 'pattern_counts': {'":': 6, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '79460', 'license': 'MIT', 'n_tokens_mistral': 1082, 'n_tokens_neox': 1059, 'n_words': 215, 'path': 'notebooks/08_tree_model.ipynb', 'repo_name': 'Ijusttyped/it_support_tickets', 'size': '3023'}