<commit_before>import pygraphviz as pgv
import pandas as pd

class Visualize(object):
    '''
    Mutate Visualization: Using PyGraphViz and Dot Syntax
    '''

    def makeGraph(self, aDataFrameToGraph):
        onlyEnabledDF = aDataFrameToGraph.loc[aDataFrameToGraph['enabled'] == True]
        removeOutputDF = onlyEnabledDF.loc[onlyEnabledDF['type'] != ("output")]

        # Node and Edge Logic
        connectionList = []
        for ix,row in removeOutputDF[['node','in','out']].iterrows():
            # Append Node and its out-bound edge to list
            connectionList.append(row[['node', 'out']].values.tolist())

        # Segregate the Sensor Nodes
        sensorDF = onlyEnabledDF.loc[onlyEnabledDF['type'] == "sensor"]
        # Create a list of sensor nodes to cluster
        sensorNodes = sensorDF['node'].values.tolist()

        # Segregate the Hidden Nodes
        hiddenDF = onlyEnabledDF.loc[onlyEnabledDF['type'] == "hidden"]
        # Create a list of hidden nodes to cluster
        hiddenNodes = hiddenDF['node'].values.tolist()

        # Segregate the Output Nodes
        outputDF = onlyEnabledDF.loc[onlyEnabledDF['type'] == "output"]
        # Create a list of output nodes to cluster
        outputNodes = outputDF['node'].values.tolist()

        # Create the dot syntax map
        graphString = ("digraph {")
        for ix,ele in enumerate(connectionList):
            graphString += (str(ele[0]) + "->" + str(ele[1]) + ";")
        graphString += ("}")

        # Create the Graph
        G = pgv.AGraph(graphString, strict=False, directed=True, rankdir='LR')
        G.node_attr['shape']='circle'
        G.add_subgraph(sensorNodes, name='cluster_sensors', label="Sensor Nodes", rank="same")
        G.add_subgraph(hiddenNodes, name='cluster_hidden', label="Hidden Nodes")
        G.add_subgraph(outputNodes, name='cluster_output', label="Output Nodes", rank="same")
        imageResult = G.draw(format='png', prog='dot')

        return imageResult<commit_msg>Bug fixed: Duplicate edges in tiny cases<commit_after>import pygraphviz as pgv
import pandas as pd

class Visualize(object):
    '''
    Mutate Visualization: Using PyGraphViz and Dot Syntax
    '''

    def create_graph(self, aDataFrameToGraph):
        onlyEnabledDF = aDataFrameToGraph.loc[aDataFrameToGraph['enabled'] == True]
        removeOutputDF = onlyEnabledDF.loc[onlyEnabledDF['type'] != ("output")]

        # Node and Edge Logic
        connectionList = []
        for ix,row in removeOutputDF[['type','node','in','out']].iterrows():
            # If a sensor node
            if row['type'] == ("sensor"):
                connectionList.append(row[['node', 'out']].values.tolist())
            # If a hidden node
            if row['type'] == ("hidden"):
                connectionList.append(row[['in', 'node']].values.tolist())
                connectionList.append(row[['node', 'out']].values.tolist())

        # Segregate the Sensor Nodes
        sensorDF = onlyEnabledDF.loc[onlyEnabledDF['type'] == "sensor"]
        # Create a list of sensor nodes to cluster
        sensorNodes = sensorDF['node'].values.tolist()

        # Segregate the Hidden Nodes
        hiddenDF = onlyEnabledDF.loc[onlyEnabledDF['type'] == "hidden"]
        # Create a list of hidden nodes to cluster
        hiddenNodes = hiddenDF['node'].values.tolist()

        # Segregate the Output Nodes
        outputDF = onlyEnabledDF.loc[onlyEnabledDF['type'] == "output"]
        # Create a list of output nodes to cluster
        outputNodes = outputDF['node'].values.tolist()

        # Remove non-unique nodes and edges
        connectionList = [tuple(ele) for ix,ele in enumerate(connectionList)]
        connectionList = set(connectionList)
        connectionList = [list(ele) for ix,ele in enumerate(connectionList)]

        # Create the dot syntax map
        graphString = ("digraph {")
        for ix,ele in enumerate(connectionList):
            graphString += (str(ele[0]) + "->" + str(ele[1]) + ";")
        graphString += ("}")

        # Create the Graph
        G = pgv.AGraph(graphString, strict=False, directed=True, rankdir='LR')
        G.node_attr['shape']='circle'
        G.add_subgraph(sensorNodes, name='cluster_sensors', label="Sensor Nodes", rank="same")
        G.add_subgraph(hiddenNodes, name='cluster_hidden', label="Hidden Nodes")
        G.add_subgraph(outputNodes, name='cluster_output', label="Output Nodes", rank="same")
        imageResult = G.draw(format='png', prog='dot')

        return imageResult
{'fraction_non_alphanumeric': 0.13305383936451898, 'fraction_numerical': 0.00088261253309797, 'mean_word_length': 2.9763157894736842, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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}}
{'dir': 'git-commits-cleaned', 'id': '1591403', 'n_tokens_mistral': 1308, 'n_tokens_neox': 1269, 'n_words': 312}