<commit_before>import numpy as np
import time
from datetime import timedelta
from modelling.component_graph import ComponentGraph

# these are required for defining the data model
from sifra.modelling.structural import (
    Element,
    Info,
    Base)

from sifra.modelling.component import Component


class IFSystem(Base):
    name = Element('str', "The model's name", 'model')
    description = Info('Represents a model (e.g. a "model of a powerstation")')

    components = Element('IODict', 'The components that make up the infrastructure system', {},
        [lambda x: [isinstance(y, Component) for y in x.itervalues()]])

    supply_nodes = Element('dict', 'The components that make up the infrastructure system', {})
    output_nodes = Element('dict', 'The components that make up the infrastructure system', {})

    supply_total = None
    component_graph = None
    if_nominal_output = None
    system_class = None

    sys_dmg_states = ['DS0 None',
                      'DS1 Slight',
                      'DS2 Moderate',
                      'DS3 Extensive',
                      'DS4 Complete']

    def __init__(self, **kwargs):
        super(IFSystem, self).__init__(**kwargs)
        if self.system_class == 'Substation':
            self.uncosted_classes = ['JUNCTION POINT',
                                     'SYSTEM INPUT', 'SYSTEM OUTPUT',
                                     'Generator', 'Bus', 'Lightning Arrester']
            self.ds_lims_compclasses = {
                'Disconnect Switch': [0.05, 0.40, 0.70, 0.99, 1.00],
                'Circuit Breaker': [0.05, 0.40, 0.70, 0.99, 1.00],
                'Current Transformer': [0.05, 0.40, 0.70, 0.99, 1.00],
                'Voltage Transformer': [0.05, 0.40, 0.70, 0.99, 1.00],
                'Power Transformer': [0.05, 0.40, 0.70, 0.99, 1.00],
                'Control Building': [0.06, 0.30, 0.75, 0.99, 1.00]
            }
        elif self.system_class == 'PowerStation':
            self.uncosted_classes = ['JUNCTION POINT', 'SYSTEM INPUT', 'SYSTEM OUTPUT']
            self.ds_lims_compclasses = {
                'Boiler': [0.0, 0.05, 0.40, 0.70, 1.00],
                'Control Building': [0.0, 0.05, 0.40, 0.70, 1.00],
                'Emission Management': [0.0, 0.05, 0.40, 0.70, 1.00],
                'Fuel Delivery and Storage': [0.0, 0.05, 0.40, 0.70, 1.00],
                'Fuel Movement': [0.0, 0.05, 0.40, 0.70, 1.00],
                'Generator': [0.0, 0.05, 0.40, 0.70, 1.00],
                'SYSTEM OUTPUT': [0.0, 0.05, 0.40, 0.70, 1.00],
                'Stepup Transformer': [0.0, 0.05, 0.40, 0.70, 1.00],
                'Turbine': [0.0, 0.05, 0.40, 0.70, 1.00],
                'Water System': [0.0, 0.05, 0.40, 0.70, 1.00]
            }

    def add_component(self, name, component):
        self.components[name] = component

    def expose_to(self, hazard_level, scenario):
        code_start_time = time.time()

        # calculate the damage state
        component_damage_state_ind = self.probable_ds_hazard_level(hazard_level, scenario)

        # calculate the output loss and economic loss
        component_sample_loss, \
        if_sample_output, \
        if_sample_economic_loss, \
        if_output_given_recovery = self.calc_output_loss(scenario, component_damage_state_ind)

        component_response = self.calc_response(component_sample_loss,
                                                component_damage_state_ind)

        # determine average output for the output components
        if_output = {}
        for output_index, (output_comp_id, output_comp) in enumerate(self.output_nodes.iteritems()):
            if_output[output_comp_id] = np.mean(if_sample_output[:, output_index])

        print("[ Hazard {} run time: {} ]\n".format(hazard_level.hazard_intensity,
                                                    str(timedelta(seconds=(time.time() - code_start_time)))))
<commit_msg>Minor changes to make system_class checks case-insensitive, Cleaner message printouts to console during model run.<commit_after>import numpy as np
import time
from datetime import timedelta
from modelling.component_graph import ComponentGraph

# these are required for defining the data model
from sifra.modelling.structural import (
    Element,
    Info,
    Base)

from sifra.modelling.component import Component


class IFSystem(Base):
    name = Element('str', "The model's name", 'model')
    description = Info('Represents a model (e.g. a "model of a powerstation")')

    components = Element('IODict', 'The components that make up the infrastructure system', {},
        [lambda x: [isinstance(y, Component) for y in x.itervalues()]])

    supply_nodes = Element('dict', 'The components that make up the infrastructure system', {})
    output_nodes = Element('dict', 'The components that make up the infrastructure system', {})

    supply_total = None
    component_graph = None
    if_nominal_output = None
    system_class = None

    sys_dmg_states = ['DS0 None',
                      'DS1 Slight',
                      'DS2 Moderate',
                      'DS3 Extensive',
                      'DS4 Complete']

    def __init__(self, **kwargs):
        super(IFSystem, self).__init__(**kwargs)
        if self.system_class.lower() == 'substation':
            self.uncosted_classes = ['JUNCTION POINT',
                                     'SYSTEM INPUT', 'SYSTEM OUTPUT',
                                     'Generator', 'Bus', 'Lightning Arrester']
            self.ds_lims_compclasses = {
                'Disconnect Switch': [0.05, 0.40, 0.70, 0.99, 1.00],
                'Circuit Breaker': [0.05, 0.40, 0.70, 0.99, 1.00],
                'Current Transformer': [0.05, 0.40, 0.70, 0.99, 1.00],
                'Voltage Transformer': [0.05, 0.40, 0.70, 0.99, 1.00],
                'Power Transformer': [0.05, 0.40, 0.70, 0.99, 1.00],
                'Control Building': [0.06, 0.30, 0.75, 0.99, 1.00]
            }
        elif self.system_class.lower() == 'powerstation':
            self.uncosted_classes = ['JUNCTION POINT', 'SYSTEM INPUT', 'SYSTEM OUTPUT']
            self.ds_lims_compclasses = {
                'Boiler': [0.0, 0.05, 0.40, 0.70, 1.00],
                'Control Building': [0.0, 0.05, 0.40, 0.70, 1.00],
                'Emission Management': [0.0, 0.05, 0.40, 0.70, 1.00],
                'Fuel Delivery and Storage': [0.0, 0.05, 0.40, 0.70, 1.00],
                'Fuel Movement': [0.0, 0.05, 0.40, 0.70, 1.00],
                'Generator': [0.0, 0.05, 0.40, 0.70, 1.00],
                'SYSTEM OUTPUT': [0.0, 0.05, 0.40, 0.70, 1.00],
                'Stepup Transformer': [0.0, 0.05, 0.40, 0.70, 1.00],
                'Turbine': [0.0, 0.05, 0.40, 0.70, 1.00],
                'Water System': [0.0, 0.05, 0.40, 0.70, 1.00]
            }

    def add_component(self, name, component):
        self.components[name] = component

    def expose_to(self, hazard_level, scenario):
        code_start_time = time.time()

        # calculate the damage state
        component_damage_state_ind = self.probable_ds_hazard_level(hazard_level, scenario)

        # calculate the output loss and economic loss
        component_sample_loss, \
        if_sample_output, \
        if_sample_economic_loss, \
        if_output_given_recovery = self.calc_output_loss(scenario, component_damage_state_ind)

        component_response = self.calc_response(component_sample_loss,
                                                component_damage_state_ind)

        # determine average output for the output components
        if_output = {}
        for output_index, (output_comp_id, output_comp) in enumerate(self.output_nodes.iteritems()):
            if_output[output_comp_id] = np.mean(if_sample_output[:, output_index])

        print("> Hazard intensity: {} {} | Run time: {}".
              format(hazard_level.hazard_intensity,
                     scenario.intensity_measure_unit,
                     str(timedelta(seconds=(time.time() - code_start_time)))))

{'fraction_non_alphanumeric': 0.12710070957301134, 'fraction_numerical': 0.05850865181127848, 'mean_word_length': 2.08881199538639, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5615997', 'n_tokens_mistral': 2830, 'n_tokens_neox': 2470, 'n_words': 632}