<commit_before>from __future__ import print_function
import os
import networkx as nx
import re

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt

# from networkx.readwrite.json_graph import node_link_data

# -----------------------------------------------------------------------------


class SystemTopology(object):

    orientation = "LR"          # Orientation of graph - Graphviz option
    connector_type = "spline"   # Connector appearance - Graphviz option
    clustering = False          # Cluster based on defined `node_cluster`

    out_file = "system_topology"
    graph_label = "System Component Topology"

    def __init__(self, infrastructure, scenario):

        self.infrastructure = infrastructure
        self.scenario = scenario
        self.gviz = ""  # placeholder for a pygraphviz agraph
        self.component_attr = {}  # Dict for system comp attributes
        self.out_dir = ""

        for comp_id in infrastructure.components.keys():
            self.component_attr[comp_id] = \
                vars(infrastructure.components[comp_id])

        self.graph_label = "System Component Topology"
        self.out_dir = scenario.output_path

        if infrastructure.system_class.lower() in \
                ['potablewatertreatmentplant', 'pwtp',
                 'wastewatertreatmentplant', 'wwtp',
                 'substation']:
            self.orientation = "TB"
            self.connector_type = "ortho"
            self.clustering = True
        elif infrastructure.system_class.lower() in \
                ['powerstation']:
            self.orientation = "LR"
            self.connector_type = "ortho"
            self.clustering = True
        else:
            self.orientation = "TB"
            self.connector_type = "polyline"
            self.clustering = False

        if infrastructure.system_meta['component_location_conf']['value']\
                == 'defined':
            self.drawing_prog = 'neato'
        else:
            self.drawing_prog = 'dot'
<commit_msg>Closes issue #8 `Attribute error raised`: now checks for existence of attr `system_meta` else defines a default drawing prog.<commit_after>from __future__ import print_function
import os
import networkx as nx
import re

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt

# from networkx.readwrite.json_graph import node_link_data

# -----------------------------------------------------------------------------


class SystemTopology(object):

    orientation = "LR"          # Orientation of graph - Graphviz option
    connector_type = "spline"   # Connector appearance - Graphviz option
    clustering = False          # Cluster based on defined `node_cluster`

    out_file = "system_topology"
    graph_label = "System Component Topology"

    def __init__(self, infrastructure, scenario):

        self.infrastructure = infrastructure
        self.scenario = scenario
        self.gviz = ""  # placeholder for a pygraphviz agraph
        self.component_attr = {}  # Dict for system comp attributes
        self.out_dir = ""

        for comp_id in infrastructure.components.keys():
            self.component_attr[comp_id] = \
                vars(infrastructure.components[comp_id])

        self.graph_label = "System Component Topology"
        self.out_dir = scenario.output_path

        if infrastructure.system_class.lower() in \
                ['potablewatertreatmentplant', 'pwtp',
                 'wastewatertreatmentplant', 'wwtp',
                 'substation']:
            self.orientation = "TB"
            self.connector_type = "ortho"
            self.clustering = True
        elif infrastructure.system_class.lower() in \
                ['powerstation']:
            self.orientation = "LR"
            self.connector_type = "ortho"
            self.clustering = True
        else:
            self.orientation = "TB"
            self.connector_type = "polyline"
            self.clustering = False

        # Default drawing program
        self.drawing_prog = 'dot'

        # Overwrite default if node locations are defined
        if hasattr(infrastructure, 'system_meta'):
            if infrastructure.system_meta['component_location_conf']['value']\
                    == 'defined':
                self.drawing_prog = 'neato'

{'fraction_non_alphanumeric': 0.11661267931513189, 'fraction_numerical': 0.00023137436372049977, 'mean_word_length': 2.0294323756131747, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2536570', 'n_tokens_mistral': 1160, 'n_tokens_neox': 1091, 'n_words': 276}