Ejemplo n.º 1
0
 def test_errors(self):  # Verifica los levantamientos de errores
     # ElectricalOverload ------------------------------------------------
     overloading_node = Consumer(0, "a", "b", "c", 29)
     with self.assertRaises(ElectricalOverload):
         self.consumers_1[0].value.add_connection(overloading_node, 18)
         for i in self.centrals_1:
             i.value._demanded_power = 0
         for i in self.centrals_1:
             i.value.demanded_power
     overloading_node = Consumer(0, "a", "b2", "c", 29)
     with self.assertRaises(ElectricalOverload):
         self.consumers_2[3].value.add_connection(overloading_node, 18)
         for i in self.centrals_2:
             i.value._demanded_power = 0
         for i in self.centrals_2:
             i.value.demanded_power
     # Forbbiden Action Agregar Conexion ------------------------
     different_node = DistributionSubstation(4, "a", "b", "cx", "d", 10)
     lifting_node = LiftingStation(4, "a", "b", "c", "d", 12)
     with self.assertRaises(ForbbidenAction):  # Union no valida
         self.centrals_1[0].value.add_connection(different_node, 5)
     with self.assertRaises(ForbbidenAction):  # Distinta comuna
         different_node.add_connection(self.consumers_1[0].value, 12)
     with self.assertRaises(ForbbidenAction):  # Se añade un padre extra
         # no valido
         lifting_node.add_connection(self.transmisions_1[0].value, 12)
     # Forbbiden Action Remover conexion
     with self.assertRaises(ForbbidenAction):  # Remover un camino no
         # existente
         self.centrals_2[0].value.remove_connection(
             self.consumers_2[0].value)
     with self.assertRaises(InvalidQuery):  # Comprueba ints
         check_input(5, List(1, 2, 3))
     with self.assertRaises(InvalidQuery):
         check_input("2", List("22", "1", "3"))  # Comprueba strl
Ejemplo n.º 2
0
def user_add_new_node(centrals, liftings, transmisions, distributions,
                      consumers):
    print("AÑADIR NODO  ------------------------------------------------")
    node_type = select_type()
    if node_type == "0":
        return decide_system_modification(centrals, liftings, transmisions,
                                          distributions, consumers)
    system_copy = mod.get_copy_of_system(centrals, liftings, transmisions,
                                         distributions, consumers)
    centrals_copy = system_copy[0].value
    liftings_copy = system_copy[1].value
    transmisions_copy = system_copy[2].value
    distributions_copy = system_copy[3].value
    consumers_copy = system_copy[4].value
    list_types = List(ElectricalGeneratingCentral, LiftingStation,
                      TransmisionSubstation, DistributionSubstation, Consumer)
    new_node = create_node(list_types[int(node_type)].value, centrals_copy,
                           liftings_copy, transmisions_copy,
                           distributions_copy, consumers_copy)
    instances = List(centrals_copy, liftings_copy, transmisions_copy,
                     distributions_copy, consumers_copy)
    result = mod.add_node(new_node, instances[int(node_type)].value,
                          centrals_copy, liftings_copy, transmisions_copy,
                          distributions_copy, consumers_copy)
    if result:
        if ask_for_permanent_change():
            print("Cambios aplicados ....................")
            return user_add_new_node(centrals_copy, liftings_copy,
                                     transmisions_copy, distributions_copy,
                                     consumers_copy)
    return user_add_new_node(centrals, liftings, transmisions, distributions,
                             consumers)
Ejemplo n.º 3
0
def decide_querie(centrals, liftings, transmision, distributions, consumers):
    list_functions = show_queries()
    action = decide_action("Seleccione la consulta deseada",
                           List("0", "1", "2", "3", "4", "5"))
    arguments_funtions = List(distributions, consumers, consumers)
    if int(action) == 0:
        return main_menu(centrals, liftings, transmision, distributions,
                         consumers)
    elif action == "1":
        argument = get_commune_name()
        get_querie_result(list_functions[int(action)].value, argument,
                          consumers, centrals,
                          arguments_funtions[int(action) - 1].value)
    elif int(action) in List(2, 3, 4):
        if int(action) == 4:
            argument = get_numeric_id()
        else:
            argument = select_electrical_system()
        get_querie_result(list_functions[int(action)].value, argument, None,
                          None, consumers)
    else:
        argument = get_numeric_id()
        get_querie_result(list_functions[5].value, argument, None, None,
                          distributions)
    return decide_querie(centrals, liftings, transmision, distributions,
                         consumers)
Ejemplo n.º 4
0
def read_database(filename, default_order):
    file_list = List()
    with open(PATH + filename, encoding="utf-8") as file:
        header = List(*file.readline().strip().split(","))
        for i in unpack_reader(*csv.reader(file)):
            file_list.append(
                get_pair_elements(default_order, header, List(*i.value)))
    return file_list
Ejemplo n.º 5
0
def select_type_energy():
    print("Seleccione el tipo de energia")
    print("1) Solar")
    print("2) Termoeléctrica")
    print("3) Biomasa")
    list_of_types = List("Solar", "Termoelectrica", "Biomasa")
    return list_of_types[int(decide_action("Seleccione:", List("1", "2", "3")))
                         - 1].value
Ejemplo n.º 6
0
def select_electrical_system():
    print("Seleccione un sistema")
    print("1) SIC")
    print("2) SING")
    print("3) AYSEN")
    print("4) MAGALLANES")
    systems = List("SIC", "SING", "AYSEN", "MAGALLANES")
    action = decide_action("Seleccione", List("1", "2", "3", "4"))
    return systems[int(action) - 1].value
Ejemplo n.º 7
0
def get_instance_to_modify(centrals, liftings, transmisions, distributions,
                           consumers):
    list_of_instances = List(centrals, liftings, transmisions, distributions,
                             consumers)
    print("Seleccione la instancia deseada, 0 para cancelar")
    print("0) Cancelar")
    print("1) Centrales")
    print("2) Elevadoras")
    print("3) Transmisiones")
    print("4) Distribuciones")
    print("5) Casas")
    action = decide_action("Seleccione:", List("0", "1", "2", "3", "4", "5"))
    if action == "0":
        return "0"
    return list_of_instances[int(action) - 1].value
    def test_data_structure(self):
        ds = DataStructure()
        ds.add(5)
        ds.add(1)
        ds.add(0)
        ds.add(2)
        ds.add(2)
        ds.add(4)

        self.assertEqual(ds.get_min(), 0)
        self.assertEqual(ds.get_min(), 1)
        self.assertEqual(ds.get_min(), 2)
        self.assertEqual(ds.get_min(), 2)
        self.assertEqual(ds.get_min(), 4)
        self.assertEqual(ds.get_min(), 5)
Ejemplo n.º 9
0
def create_node(node_type, centrals, liftings, transmisions, distributions,
                consumers):
    if node_type == ElectricalGeneratingCentral:
        return create_new_central(centrals)
    elif node_type != Consumer:
        list_type = List(LiftingStation, TransmisionSubstation,
                         DistributionSubstation)
        list_entities = List(liftings, transmisions, distributions)
        c = 0
        for i in list_type:
            if i.value == node_type:
                break
            c += 1
        return create_substation(list_entities[c].value, node_type)
    else:
        return create_consumer(consumers)
Ejemplo n.º 10
0
def decide_system_modification(centrals, liftings, transmisions, distributions,
                               consumers):
    list_of_modifications = List(add_user_connection, remove_user_connection,
                                 user_add_new_node, user_remove_node)
    show_modification_options()
    action = decide_action(
        "Pulse el numero asociado a la acción a "
        "realizar", List("0", "1", "2", "3", "4"))
    if action == "0":
        return main_menu(centrals, liftings, transmisions, distributions,
                         consumers)
    list_of_modifications[int(action) - 1].value(centrals, liftings,
                                                 transmisions, distributions,
                                                 consumers)
    return decide_system_modification(centrals, liftings, transmisions,
                                      distributions, consumers)
Ejemplo n.º 11
0
def user_remove_node(centrals, liftings, transmisions, distributions,
                     consumers):
    print("REMOVER NODO -------------------------------------------------")
    system_copy = mod.get_copy_of_system(centrals, liftings, transmisions,
                                         distributions, consumers)
    centrals_copy = system_copy[0].value
    liftings_copy = system_copy[1].value
    transmisions_copy = system_copy[2].value
    distributions_copy = system_copy[3].value
    consumers_copy = system_copy[4].value
    instances = List(centrals_copy, liftings_copy, transmisions_copy,
                     distributions_copy, consumers_copy)
    node_type = select_type()
    if node_type == "0":
        return decide_system_modification(centrals, liftings, transmisions,
                                          distributions, consumers)
    print("Seleccione la instancia a borrar")
    removed_node = get_entity(instances[int(node_type)].value)
    result = mod.remove_node(removed_node, centrals_copy, liftings_copy,
                             transmisions_copy, distributions_copy,
                             consumers_copy)
    if result:
        if ask_for_permanent_change():
            return remove_user_connection(centrals_copy, liftings_copy,
                                          transmisions_copy,
                                          distributions_copy, consumers_copy)
    return remove_user_connection(centrals, liftings, transmisions,
                                  distributions, consumers)
Ejemplo n.º 12
0
def ask_for_permanent_change():
    print("Es factible aplicar los cambios")
    print("¿Desea aplicar los cambios de forma permanente? Pulse 1 para si, "
          "2 no")
    result = decide_action("Seleccione", List("1", "2"))
    if result == "1":
        return True
    return False
Ejemplo n.º 13
0
 def find_direct_connection(self):  # Busca la conexion directa a una
     # elevadora
     if isinstance(self, LiftingStation):  # Caso base: Llegamos a la
         # estacion elevadora
         return List(self)
     for i in self.parents_data:  # De lo contrario buscamos en los padres
         result = i.value[0].value.find_direct_connection()
         if result is not None:
             result.append(self)  # Se agrega a si mismo y se retorna
             return result
Ejemplo n.º 14
0
def create_stations(filename, type_substation):
    station_list = IdList()
    for j in read_database(
            filename,
            List("id", "nombre", "sistema_electrico", "provincia", "comuna",
                 "consumo_mw")):
        i = j.value
        station = type_substation(int(i[0].value), i[1].value, i[2].value,
                                  i[3].value, i[4].value, float(i[5].value))
        station_list.append(int(i[0].value), station)
    return station_list
Ejemplo n.º 15
0
def select_type():
    print("Seleccione la instancia, 0 para cancelar")
    print("0) Cancelar")
    print("1) Central Generadora de energia")
    print("2) Central Elevadora")
    print("3) Subestación de Transmisión")
    print("4) Subestación de Distribución")
    print("5) Casas")
    action = decide_action("Seleccione", List("0", "1", "2", "3", "4", "5"))
    if action == "0":
        return action
    return int(action) - 1
Ejemplo n.º 16
0
def create_consumers():
    consumer_list = IdList()
    for j in read_database(
            "casas.csv",
            List("id", "sistema_electrico", "provincia", "comuna",
                 "consumo_kw")):
        i = j.value
        consumer = Consumer(int(i[0].value), i[1].value, i[2].value,
                            i[3].value,
                            float(i[4].value) / 1000)
        consumer_list.append(int(i[0].value), consumer)
    return consumer_list
Ejemplo n.º 17
0
def main_menu(centrals, liftings, transmisions, distributions, consumers):
    action = decide_action(
        "Pulse 1 para realizar un consulta, 2 para "
        "modificar la red, 0 para salir", List("0", "1", "2"))
    if action == "0":
        exit()
    elif action == "1":
        decide_querie(centrals, liftings, transmisions, distributions,
                      consumers)
    else:
        decide_system_modification(centrals, liftings, transmisions,
                                   distributions, consumers)
Ejemplo n.º 18
0
def create_generating_centrals():
    centrals_list = IdList()
    for j in read_database(
            "centrales.csv",
            List("id", "nombre", "sistema_electrico", "provincia", "comuna",
                 "tipo", "potencia")):
        i = j.value
        central = ElectricalGeneratingCentral(int(i[0].value), i[1].value,
                                              i[2].value, i[3].value,
                                              i[4].value, i[5].value,
                                              float(i[6].value))
        centrals_list.append(int(i[0].value), central)
    return centrals_list
Ejemplo n.º 19
0
 def __init__(self, id_, name, electrical_system, province, commune,
              cross_sectional_area, receptor):
     self.id_structure = id_
     self.name = name
     self.electrical_system = electrical_system
     self.province = province
     self.commune = commune
     self.cross_sectional_area = cross_sectional_area
     self.connected_to = Graph(id_, self)
     self.receptor = receptor
     self.max_of_parents = inf
     self.power_consumed = 0.0  # potencia que se necesita para funcionar
     self.parents_data = List()
     self.received_power = 0.0
     self._demanded_power = 0.0  # Guarda el valor de la demanda,
     # así este solo se calcula una vez
     self.received = False
     self.extra_energy = 0
def get_copy_of_system(centrals, liftings, transmisions, distributions,
                       consumers):
    # Se hacen las copias
    centrals_copy = copy_list_entities(centrals)
    liftings_copy = copy_list_entities(liftings)
    transmisions_copy = copy_list_entities(transmisions)
    distributions_copy = copy_list_entities(distributions)
    consumers_copy = copy_list_entities(consumers)
    # Se hacen las conexiones
    for i in liftings:
        connect_copy(i.value, liftings_copy[i.value.id_structure].value,
                     transmisions_copy, centrals_copy)
    for i in distributions:
        connect_copy(i.value, distributions_copy[i.value.id_structure].value,
                     consumers_copy, transmisions_copy)
    for i in consumers:
        connect_consumers(i.value, consumers_copy)
    return List(centrals_copy, liftings_copy, transmisions_copy,
                distributions_copy, consumers_copy)
Ejemplo n.º 21
0
def load_total_graph():
    centrals = create_generating_centrals()
    liftings = create_stations("elevadoras.csv", LiftingStation)
    transmisions = create_stations("transmision.csv", TransmisionSubstation)
    distributions = create_stations("distribucion.csv", DistributionSubstation)
    consumers = create_consumers()
    make_connections(centrals, liftings, "centrales_elevadoras.csv",
                     List("id_central", "id_elevadora", "distancia"))
    make_connections(liftings, transmisions, "transmision_elevadoras.csv",
                     List("id_elevadora", "id_transmision", "distancia"))
    make_connections(transmisions, distributions,
                     "distribucion_transmision.csv",
                     List("id_transmision", "id_distribucion", "distancia"))
    make_connections(distributions, consumers, "casas_distribucion.csv",
                     List("id_distribucion", "id_casa", "distancia"))
    make_connections(consumers, consumers, "casas_casas.csv",
                     List("id_desde", "id_hasta", "distancia"))
    calculate_ideal_demanded_power(centrals)
    distribute_the_power(consumers)
    return List(centrals, liftings, transmisions, distributions, consumers)
Ejemplo n.º 22
0
def unpack_reader(*args):
    return List(*args)
Ejemplo n.º 23
0
def get_pair_elements(default_order, order_line, line):
    ordered_list = List()
    for i in default_order:
        ordered_list.append(line[get_index_of_header_element(
            i.value, order_line)].value)
    return ordered_list
Ejemplo n.º 24
0
 def setUp(self):
     self.structure = List()
Ejemplo n.º 25
0
 def set_parent_data(self, element, distance):
     """
     Envia la informacion del padre a parents_data de element
     """
     data = List(self, distance, self.cross_sectional_area)
     element.parents_data.append(data)