From 93e86e41d0ec85a4e76b1dde9a525d1d355e2f41 Mon Sep 17 00:00:00 2001 From: ADERALDO Date: Sun, 29 Oct 2023 22:48:47 -0300 Subject: [PATCH 1/3] to add Line element --- bdgd2dss.json | 305 ++++++-------------------------------- bdgd_tools/__init__.py | 1 + bdgd_tools/core/Core.py | 11 +- bdgd_tools/model/Case.py | 14 +- bdgd_tools/model/Line.py | 309 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 375 insertions(+), 265 deletions(-) create mode 100644 bdgd_tools/model/Line.py diff --git a/bdgd2dss.json b/bdgd2dss.json index 3a87388..ad419f2 100644 --- a/bdgd2dss.json +++ b/bdgd2dss.json @@ -56,6 +56,9 @@ "npts": 24 }, "direct_mapping": { + "tipocc": "COD_ID", + "tipodia": "TIP_DIA", + "grupotensao": "GRU_TEN" }, "indirect_mapping": { }, @@ -119,277 +122,57 @@ "bus2": "PAC_2", "line": "COD_ID" }, - "indirect_mapping": { - "phases": [ - "FAS_CON", - "convert_tfascon_phases" - ], - "bus_nodes": [ - "FAS_CON", - "convert_tfascon_bus" - ] - }, - "calculated": { - } - }, - "SSDBT": { - "arquivo": "Trecho_BT", - "static": { - "units": "km" - }, - "direct_mapping": { - "bus1": "PAC_1", - "bus2": "PAC_2", - "line": "COD_ID", - "linecode": "TIP_CND" - }, - "indirect_mapping": { - "phases": [ - "FAS_CON", - "convert_tfascon_phases" - ], - "bus_nodes": [ - "FAS_CON", - "convert_tfascon_bus" - ], - "suffix_linecode": [ - "FAS_CON", - "convert_tfascon_quant_fios" - ] - }, - "calculated": { - "length": [ - "COMP", - "/", - 1000 - ] - } - }, - "RAMLIG": { - "arquivo": "Ramais_BT", - "static": { - "units": "km" - }, - "direct_mapping": { - "bus1": "PAC_1", - "bus2": "PAC_2", - "line": "COD_ID", - "linecode": "TIP_CND" - }, "indirect_mapping": { "phases": [ "FAS_CON", "TFASCON" - ], - "suffix_linecode": [ - "FAS_CON", - "TFASCON" - ], - "bus_nodes": [ - "FAS_CON", - "convert_tfascon_bus" ] }, "calculated": { - "length": [ - "COMP", - "/", - 1000 - ] - } - } - }, - "Transformer": { - "UNTRMT": { - "arquivo": "Transformador_MTBT", - "static": { - }, - "direct_mapping": { - "bus1": "PAC_1", - "bus2": "PAC_2", - "bus3": "PAC_3", - "transformer": "COD_ID", - "ten_lin_se": "TEN_LIN_SE", - "kvas": "POT_NOM", - "tap": "TAP" - }, - "indirect_mapping": { - "phases": [ - "TIP_TRAFO", - "convert_ttranf_phases" - ], - "bus1_nodes": [ - "FAS_CON_P", - "convert_tfascon_bus" - ], - "bus2_nodes": [ - "FAS_CON_S", - "convert_tfascon_bus" - ], - "bus3_nodes": [ - "FAS_CON_T", - "convert_tfascon_bus" - ], - "kvs": [ - "TEN_PRI", - "convert_tten" - ], - "windings": [ - "TIP_TRAFO", - "convert_ttranf_windings" - ], - "conn_p": [ - "FAS_CON_P", - "convert_tfascon_conn" - ], - "conn_s": [ - "FAS_CON_S", - "convert_tfascon_conn" - ], - "conn_t": [ - "FAS_CON_T", - "convert_tfascon_conn" - ] - }, - "calculated": { - "%loadloss": [ - "PER_TOT", - "PER_FER", - "POT_NOM", - "calc_loadloss" - ], - "%noloadloss": [ - "PER_FER", - "POT_NOM", - "calc_noloadloss" - ] - } - }, - "UNTRMT_R": { - "arquivo": "Reator_MTBT", - "static": { - "phases": 1, - "r": 15, - "x": 0, - "basefreq": 60 - }, - "direct_mapping": { - "reactor": "COD_ID", - "bus1": "PAC_2", - "bus2": "PAC_2" - }, - "indirect_mapping": { - "bus1_nodes": ".4", - "bus2_nodes": ".0" - }, - "calculated": { - } - } - }, - "Load": { - "UCMT_tab": { - "arquivo": "Cargas_MT", - "static": { - "pf": 0.92, - "vminpu": 0.93, - "Vmaxpu": 1.50, - "status": "variable" - }, - "direct_mapping": { - "bus1": "PAC", - "load": "COD_ID", - "daily": "TIP_CC" - }, - "indirect_mapping": { - "phases": [ - "FAS_CON", - "convert_tfascon_phases" - ], - "conn": [ - "FAS_CON", - "convert_tfascon_conn" - ], - "bus_nodes": [ - "FAS_CON", - "convert_tfascon_bus" - ] - }, - "calculated": { - "kv": [ - "TEN_NOM", - "convert_tten" - ], - "kW": "Processo iterativo" } }, - "UCBT_tab": { - "arquivo": "Cargas_BT", - "static": { - "pf": 0.92, - "vminpu": 0.93, - "Vmaxpu": 1.50, - "status": "variable" - }, - "direct_mapping": { - "bus1": "PAC", - "load": "COD_ID", - "daily": "TIP_CC" - }, - "indirect_mapping": { - "phases": [ - "FAS_CON", - "convert_tfascon_phases" - ], - "conn": [ - "FAS_CON", - "convert_tfascon_conn" - ], - "bus_nodes": [ - "FAS_CON", - "convert_tfascon_bus" - ] - }, - "calculated": { - "kv": [ - "TEN_NOM", - "convert_tten" - ], - "kW": "Processo iterativo" + "UNCRMT": { + "arquivo": "Capacitor_MT", + "static": + { + }, + "direct_mapping": + { + "capacitor": "COD_ID", + "bus1": "PAC_1" + }, + "indirect_mapping": + { + "kv": ["GRU_TEN", "convert_tgruten"], + "kvar": ["POT_NOM", "convert_tpotrtv"], + "phases": ["FAS_CON", "convert_tfascon_phases"], + "conn": ["FAS_CON", "convert_tfascon_conn"], + "bus_nodes": ["FAS_CON", "convert_tfascon_bus"] + }, + "calculated": + { } }, - "PIP": { - "arquivo": "Cargas_IP", - "static": { - "pf": 0.92, - "vminpu": 0.93, - "Vmaxpu": 1.50, - "status": "variable" - }, - "direct_mapping": { - "bus1": "PAC", - "load": "COD_ID", - "daily": "TIP_CC" - }, - "indirect_mapping": { - "phases": [ - "FAS_CON", - "convert_tfascon_phases" - ], - "conn": [ - "FAS_CON", - "convert_tfascon_conn" - ], - "bus_nodes": [ - "FAS_CON", - "convert_tfascon_bus" - ] - }, - "calculated": { - "kv": [ - "TEN_NOM", - "convert_tten" - ], - "kW": "Processo iterativo" + "UNCRBT": { + "arquivo": "Capacitor_BT", + "static": + { + }, + "direct_mapping": + { + "capacitor": "COD_ID", + "bus1": "PAC_1" + }, + "indirect_mapping": + { + "kv": ["GRU_TEN", "convert_tgruten"], + "kvar": ["POT_NOM", "convert_tpotrtv"], + "phases": ["FAS_CON", "convert_tfascon_phases"], + "conn": ["FAS_CON", "convert_tfascon_conn"], + "bus_nodes": ["FAS_CON", "convert_tfascon_bus"] + }, + "calculated": + { } } }, @@ -669,7 +452,7 @@ "COMP", "CTMT" ], - "type": { + "type": { "COD_ID": "category", "FAS_CON": "category", "CTMT": "category" diff --git a/bdgd_tools/__init__.py b/bdgd_tools/__init__.py index de59fa8..e4e9893 100644 --- a/bdgd_tools/__init__.py +++ b/bdgd_tools/__init__.py @@ -7,6 +7,7 @@ from bdgd_tools.model.Converter import * from bdgd_tools.model.Circuit import * from bdgd_tools.model.LineCode import * +from bdgd_tools.model.Line import * from bdgd_tools.model.Case import * from bdgd_tools.core.Core import * from bdgd_tools.gui.GUI import * diff --git a/bdgd_tools/core/Core.py b/bdgd_tools/core/Core.py index def0ef3..e8aa81b 100644 --- a/bdgd_tools/core/Core.py +++ b/bdgd_tools/core/Core.py @@ -18,7 +18,7 @@ import geopandas as gpd -from bdgd_tools import Sample, Case, Circuit, LineCode +from bdgd_tools import Sample, Case, Circuit, LineCode, Line from bdgd_tools.core.Utils import load_json from bdgd_tools.gui.GUI import GUI @@ -166,12 +166,17 @@ def run(folder: Optional[str] = None) -> None: json_data = JsonData(json_file_name) geodataframes = json_data.create_geodataframes(folder_bdgd) + case.dfs = geodataframes - case.circuitos = Circuit.create_circuit_from_json(json_data.data, case.dfs['CTMT']['gdf']) + case.circuitos = Circuit.create_circuit_from_json(json_data.data, case.dfs['CTMT']['gdf']) # parei aqui ele manda um pandas e por que o json? entender os roles for c in case.circuitos: print(c) case.line_codes = LineCode.create_linecode_from_json(json_data.data, case.dfs['SEGCON']['gdf']) - for l_ in case.line_codes: + for l_ in case.line_codes: print(l_) + + case.lines = Line.create_line_from_json(json_data.data, case.dfs['SSDMT']['gdf']) + for li_ in case.lines: + print(li_) diff --git a/bdgd_tools/model/Case.py b/bdgd_tools/model/Case.py index 6fc8488..1786170 100644 --- a/bdgd_tools/model/Case.py +++ b/bdgd_tools/model/Case.py @@ -10,13 +10,14 @@ * Time: 10:05 """ from dataclasses import dataclass, field -from bdgd_tools import Circuit, LineCode +from bdgd_tools import Circuit, LineCode, Line @dataclass class Case: _circuitos: list[Circuit] = field(init=False) _line_codes: list[LineCode] = field(init=False) + _lines: list[Line] = field(init=False) _dfs: dict = field(init=False) @property @@ -35,6 +36,14 @@ def line_codes(self): def line_codes(self, value): self._line_codes = value + @property + def lines(self): + return self._lines + + @lines.setter + def lines(self, value): + self._lines = value + @property def dfs(self): return self._dfs @@ -49,3 +58,6 @@ def circuit_names(self): def line_code_names(self): return [l.linecode for l in self.line_codes] + + def line_name(self): + return [l.line for l in self.lines] diff --git a/bdgd_tools/model/Line.py b/bdgd_tools/model/Line.py new file mode 100644 index 0000000..d58c763 --- /dev/null +++ b/bdgd_tools/model/Line.py @@ -0,0 +1,309 @@ +# -*- encoding: utf-8 -*- +""" + * Project Name: main.py + * Created by eniocc + * Date: 21/03/2023 + * Time: 23:53 + * + * Edited by: eniocc + * Date: 21/03/2023 + * Time: 23:53 +""" +# Não remover a linha de importação abaixo +import copy +import re +from typing import Any + +import geopandas as gpd +from tqdm import tqdm + +from bdgd_tools.model.Converter import convert_tfascon_phases, convert_tfascon_bus, convert_tfascon_quant_fios +#from bdgd_tools.model.Converter import convert_tten + +from dataclasses import dataclass + + +@dataclass +class Line: + + _units: str = "km" + _bus1: str = "" + _bus2: str = "" + _bus_nodes: str = "" + _line: str = "" + _linecode: str = "" + _suffix_linecode: str = "" + _phases: int = 0 + _length: float = 0.0 + + _c0: float = 0.0 + _c1: float = 0.0 + _r0: float = 0.001 + _r1: float = 0.001 + _switch: str = "T" + _x0: float = 0.0 + _x1: float = 0.0 + + @property + def units(self): + return self._units + + @units.setter + def units(self, value: str): + self._units = value + + @property + def bus1(self): + return self._bus1 + + @bus1.setter + def bus1(self, value: str): + self._bus1 = value + + @property + def bus2(self): + return self._bus2 + + @bus2.setter + def bus2(self, value: str): + self._bus2 = value + + @property + def bus_nodes(self): + return self._bus_nodes + + @bus_nodes.setter + def bus_nodes(self, value: str): + self._bus_nodes = value + + @property + def line(self): + return self._line + + @line.setter + def line(self, value: str): + self._line = value + + @property + def linecode(self): + return self._linecode + + @linecode.setter + def linecode(self, value: str): + self._linecode = value + + @property + def suffix_linecode(self): + return self._suffix_linecode + + @suffix_linecode.setter + def suffix_linecode(self, value: str): + self._suffix_linecode = value + + @property + def phases(self): + return self._phases + + @phases.setter + def phases(self, value: int): + self._phases = value + + @property + def length(self): + return self._length + + @length.setter + def length(self, value: float): + self._length = value + + @property + def c0(self): + return self._c0 + + @c0.setter + def c0(self, value: float): + self._c0 = value + + @property + def c1(self): + return self._c1 + + @c1.setter + def c1(self, value: float): + self._c1 = value + + @property + def r0(self): + return self._r0 + + @r0.setter + def r0(self, value: float): + self._r0 = value + + @property + def r1(self): + return self._r1 + + @r1.setter + def r1(self, value: float): + self._r1 = value + + @property + def switch(self): + return self._switch + + @switch.setter + def switch(self, value: str): + self._switch = value + + @property + def x0(self): + return self._x0 + + @x0.setter + def x0(self, value: float): + self._x0 = value + + @property + def x1(self): + return self._x1 + + @x1.setter + def x1(self, value: float): + self._x1 = value + + + + def full_string(self) -> str: + return f'New "Line.SMT_{self.line}" phases={self.phases} ' \ + f'bus1="{self.bus1}.{self.bus_nodes}" bus2="{self.bus2}.{self.bus_nodes}" ' \ + f'linecode="{self.linecode}_{self.suffix_linecode}" length={self.length:.5f} ' \ + f'units={self.units}' + + def __repr__(self): + return f'New "Line.SMT_{self.line}" phases={self.phases} ' \ + f'bus1="{self.bus1}.{self.bus_nodes}" bus2="{self.bus2}.{self.bus_nodes}" ' \ + f'linecode="{self.linecode}_{self.suffix_linecode}" length={self.length:.5f} ' \ + f'units={self.units}' + + + @staticmethod + def _process_static(line_, value): + """ + Static method to process the static configuration for a Circuit object. + + Args: + line_ (object): A Circuit object being updated. + value (dict): A dictionary containing the static configuration. + + This method processes the static configuration by iterating through the + key-value pairs of the 'value' dictionary and directly setting the + corresponding attribute on the Circuit object with the static value. + """ + for static_key, static_value in value.items(): + setattr(line_, f"_{static_key}", static_value) + + + @staticmethod + def _process_direct_mapping(line_, value, row): + """ + Static method to process the direct mapping configuration for a Circuit object. + + Args: + line_ (object): A Circuit object being updated. + value (dict): A dictionary containing the direct mapping configuration. + row (pd.Series): A row from the GeoDataFrame containing circuit-related data. + + This method processes the direct mapping configuration by iterating through the + key-value pairs of the 'value' dictionary and directly setting the corresponding + attribute on the Circuit object using the value from the row. + """ + for mapping_key, mapping_value in value.items(): + setattr(line_, f"_{mapping_key}", row[mapping_value]) + + @staticmethod + def _process_indirect_mapping(line_, value, row): + """ + Static method to process the indirect mapping configuration for a Circuit object. + + Args: + line_ (object): A Circuit object being updated. + value (dict): A dictionary containing the indirect mapping configuration. + row (pd.Series): A row from the GeoDataFrame containing circuit-related data. + + This method processes the indirect mapping configuration by iterating through the + key-value pairs of the 'value' dictionary. If the value is a list, it treats the + first element as a parameter name and the second element as a function name. The + method then retrieves the parameter value from the row and calls the specified + function with that parameter value. The result is then set as an attribute on the + Circuit object. + + If the value is not a list, the method directly sets the corresponding attribute on + the Circuit object using the value from the row. + """ + for mapping_key, mapping_value in value.items(): + if isinstance(mapping_value, list): + param_name, function_name = mapping_value + function_ = globals()[function_name] + param_value = row[param_name] + setattr(line_, f"_{mapping_key}", function_(str(param_value))) # corrigingo para string para encontrar valor no dicionario + else: + setattr(line_, f"_{mapping_key}", row[mapping_value]) + + @staticmethod + def _process_calculated(line_, value, row): + """ + Static method to process the calculated mapping configuration for a Line object. + + Args: + circuit_ (object): A Circuit object being updated. + value (dict): A dictionary containing the direct mapping configuration. + row (pd.Series): A row from the GeoDataFrame containing circuit-related data. + + This method processes the direct mapping configuration by iterating through the + key-value pairs of the 'value' dictionary and directly setting the corresponding + attribute on the Circuit object using the value from the row. + """ + for mapping_key, mapping_value in value.items(): + + expression = "" + for item in mapping_value: + if isinstance(item, str) and any(char.isalpha() for char in item): + + expression = f'{expression} {row[item]}' + else: + expression = f'{expression}{item}' + + param_value = eval(expression) + + setattr(line_, f"_{mapping_key}", param_value) + + + + @staticmethod + def _create_line_from_row(line_config, row): + line_ = Line() + + for key, value in line_config.items(): + if key == "static": + line_._process_static(line_, value) + elif key == "direct_mapping": + line_._process_direct_mapping(line_, value,row) + elif key == "indirect_mapping": + line_._process_indirect_mapping(line_, value,row) + elif key == "calculated": + line_._process_calculated(line_, value, row) + + return line_ + + @staticmethod + def create_line_from_json(json_data: Any, dataframe: gpd.geodataframe.GeoDataFrame): + lines = [] + line_config = json_data['elements']['Line']['SSDMT'] + progress_bar = tqdm(dataframe.iterrows(), total=len(dataframe), desc="Line", unit=" lines", ncols=100) + for _, row in progress_bar: + line_ = Line._create_line_from_row(line_config, row) + lines.append(line_) + progress_bar.set_description(f"Processing Line {_ + 1}") + + return lines \ No newline at end of file From 69a88ec8c446458f9ce41e590690caf5a5a1b2f4 Mon Sep 17 00:00:00 2001 From: ADERALDO Date: Mon, 30 Oct 2023 00:41:24 -0300 Subject: [PATCH 2/3] corrections --- bdgd2dss.json | 305 +++++++++++++++++++++++++++++++++------ bdgd_tools/core/Core.py | 2 +- bdgd_tools/model/Line.py | 44 +++--- 3 files changed, 284 insertions(+), 67 deletions(-) diff --git a/bdgd2dss.json b/bdgd2dss.json index ad419f2..3a87388 100644 --- a/bdgd2dss.json +++ b/bdgd2dss.json @@ -56,9 +56,6 @@ "npts": 24 }, "direct_mapping": { - "tipocc": "COD_ID", - "tipodia": "TIP_DIA", - "grupotensao": "GRU_TEN" }, "indirect_mapping": { }, @@ -122,57 +119,277 @@ "bus2": "PAC_2", "line": "COD_ID" }, + "indirect_mapping": { + "phases": [ + "FAS_CON", + "convert_tfascon_phases" + ], + "bus_nodes": [ + "FAS_CON", + "convert_tfascon_bus" + ] + }, + "calculated": { + } + }, + "SSDBT": { + "arquivo": "Trecho_BT", + "static": { + "units": "km" + }, + "direct_mapping": { + "bus1": "PAC_1", + "bus2": "PAC_2", + "line": "COD_ID", + "linecode": "TIP_CND" + }, + "indirect_mapping": { + "phases": [ + "FAS_CON", + "convert_tfascon_phases" + ], + "bus_nodes": [ + "FAS_CON", + "convert_tfascon_bus" + ], + "suffix_linecode": [ + "FAS_CON", + "convert_tfascon_quant_fios" + ] + }, + "calculated": { + "length": [ + "COMP", + "/", + 1000 + ] + } + }, + "RAMLIG": { + "arquivo": "Ramais_BT", + "static": { + "units": "km" + }, + "direct_mapping": { + "bus1": "PAC_1", + "bus2": "PAC_2", + "line": "COD_ID", + "linecode": "TIP_CND" + }, "indirect_mapping": { "phases": [ "FAS_CON", "TFASCON" + ], + "suffix_linecode": [ + "FAS_CON", + "TFASCON" + ], + "bus_nodes": [ + "FAS_CON", + "convert_tfascon_bus" ] }, "calculated": { + "length": [ + "COMP", + "/", + 1000 + ] + } + } + }, + "Transformer": { + "UNTRMT": { + "arquivo": "Transformador_MTBT", + "static": { + }, + "direct_mapping": { + "bus1": "PAC_1", + "bus2": "PAC_2", + "bus3": "PAC_3", + "transformer": "COD_ID", + "ten_lin_se": "TEN_LIN_SE", + "kvas": "POT_NOM", + "tap": "TAP" + }, + "indirect_mapping": { + "phases": [ + "TIP_TRAFO", + "convert_ttranf_phases" + ], + "bus1_nodes": [ + "FAS_CON_P", + "convert_tfascon_bus" + ], + "bus2_nodes": [ + "FAS_CON_S", + "convert_tfascon_bus" + ], + "bus3_nodes": [ + "FAS_CON_T", + "convert_tfascon_bus" + ], + "kvs": [ + "TEN_PRI", + "convert_tten" + ], + "windings": [ + "TIP_TRAFO", + "convert_ttranf_windings" + ], + "conn_p": [ + "FAS_CON_P", + "convert_tfascon_conn" + ], + "conn_s": [ + "FAS_CON_S", + "convert_tfascon_conn" + ], + "conn_t": [ + "FAS_CON_T", + "convert_tfascon_conn" + ] + }, + "calculated": { + "%loadloss": [ + "PER_TOT", + "PER_FER", + "POT_NOM", + "calc_loadloss" + ], + "%noloadloss": [ + "PER_FER", + "POT_NOM", + "calc_noloadloss" + ] + } + }, + "UNTRMT_R": { + "arquivo": "Reator_MTBT", + "static": { + "phases": 1, + "r": 15, + "x": 0, + "basefreq": 60 + }, + "direct_mapping": { + "reactor": "COD_ID", + "bus1": "PAC_2", + "bus2": "PAC_2" + }, + "indirect_mapping": { + "bus1_nodes": ".4", + "bus2_nodes": ".0" + }, + "calculated": { + } + } + }, + "Load": { + "UCMT_tab": { + "arquivo": "Cargas_MT", + "static": { + "pf": 0.92, + "vminpu": 0.93, + "Vmaxpu": 1.50, + "status": "variable" + }, + "direct_mapping": { + "bus1": "PAC", + "load": "COD_ID", + "daily": "TIP_CC" + }, + "indirect_mapping": { + "phases": [ + "FAS_CON", + "convert_tfascon_phases" + ], + "conn": [ + "FAS_CON", + "convert_tfascon_conn" + ], + "bus_nodes": [ + "FAS_CON", + "convert_tfascon_bus" + ] + }, + "calculated": { + "kv": [ + "TEN_NOM", + "convert_tten" + ], + "kW": "Processo iterativo" } }, - "UNCRMT": { - "arquivo": "Capacitor_MT", - "static": - { - }, - "direct_mapping": - { - "capacitor": "COD_ID", - "bus1": "PAC_1" - }, - "indirect_mapping": - { - "kv": ["GRU_TEN", "convert_tgruten"], - "kvar": ["POT_NOM", "convert_tpotrtv"], - "phases": ["FAS_CON", "convert_tfascon_phases"], - "conn": ["FAS_CON", "convert_tfascon_conn"], - "bus_nodes": ["FAS_CON", "convert_tfascon_bus"] - }, - "calculated": - { + "UCBT_tab": { + "arquivo": "Cargas_BT", + "static": { + "pf": 0.92, + "vminpu": 0.93, + "Vmaxpu": 1.50, + "status": "variable" + }, + "direct_mapping": { + "bus1": "PAC", + "load": "COD_ID", + "daily": "TIP_CC" + }, + "indirect_mapping": { + "phases": [ + "FAS_CON", + "convert_tfascon_phases" + ], + "conn": [ + "FAS_CON", + "convert_tfascon_conn" + ], + "bus_nodes": [ + "FAS_CON", + "convert_tfascon_bus" + ] + }, + "calculated": { + "kv": [ + "TEN_NOM", + "convert_tten" + ], + "kW": "Processo iterativo" } }, - "UNCRBT": { - "arquivo": "Capacitor_BT", - "static": - { - }, - "direct_mapping": - { - "capacitor": "COD_ID", - "bus1": "PAC_1" - }, - "indirect_mapping": - { - "kv": ["GRU_TEN", "convert_tgruten"], - "kvar": ["POT_NOM", "convert_tpotrtv"], - "phases": ["FAS_CON", "convert_tfascon_phases"], - "conn": ["FAS_CON", "convert_tfascon_conn"], - "bus_nodes": ["FAS_CON", "convert_tfascon_bus"] - }, - "calculated": - { + "PIP": { + "arquivo": "Cargas_IP", + "static": { + "pf": 0.92, + "vminpu": 0.93, + "Vmaxpu": 1.50, + "status": "variable" + }, + "direct_mapping": { + "bus1": "PAC", + "load": "COD_ID", + "daily": "TIP_CC" + }, + "indirect_mapping": { + "phases": [ + "FAS_CON", + "convert_tfascon_phases" + ], + "conn": [ + "FAS_CON", + "convert_tfascon_conn" + ], + "bus_nodes": [ + "FAS_CON", + "convert_tfascon_bus" + ] + }, + "calculated": { + "kv": [ + "TEN_NOM", + "convert_tten" + ], + "kW": "Processo iterativo" } } }, @@ -452,7 +669,7 @@ "COMP", "CTMT" ], - "type": { + "type": { "COD_ID": "category", "FAS_CON": "category", "CTMT": "category" diff --git a/bdgd_tools/core/Core.py b/bdgd_tools/core/Core.py index e8aa81b..64cb2cd 100644 --- a/bdgd_tools/core/Core.py +++ b/bdgd_tools/core/Core.py @@ -169,7 +169,7 @@ def run(folder: Optional[str] = None) -> None: case.dfs = geodataframes - case.circuitos = Circuit.create_circuit_from_json(json_data.data, case.dfs['CTMT']['gdf']) # parei aqui ele manda um pandas e por que o json? entender os roles + case.circuitos = Circuit.create_circuit_from_json(json_data.data, case.dfs['CTMT']['gdf']) for c in case.circuitos: print(c) diff --git a/bdgd_tools/model/Line.py b/bdgd_tools/model/Line.py index d58c763..5f766ca 100644 --- a/bdgd_tools/model/Line.py +++ b/bdgd_tools/model/Line.py @@ -1,13 +1,13 @@ # -*- encoding: utf-8 -*- """ * Project Name: main.py - * Created by eniocc - * Date: 21/03/2023 + * Created by migueldcga + * Date: 30/10/2023 * Time: 23:53 * - * Edited by: eniocc - * Date: 21/03/2023 - * Time: 23:53 + * Edited by: + * Date: + * Time: """ # Não remover a linha de importação abaixo import copy @@ -18,7 +18,7 @@ from tqdm import tqdm from bdgd_tools.model.Converter import convert_tfascon_phases, convert_tfascon_bus, convert_tfascon_quant_fios -#from bdgd_tools.model.Converter import convert_tten + from dataclasses import dataclass @@ -190,15 +190,15 @@ def __repr__(self): @staticmethod def _process_static(line_, value): """ - Static method to process the static configuration for a Circuit object. + Static method to process the static configuration for a Line object. Args: - line_ (object): A Circuit object being updated. + line_ (object): A Line object being updated. value (dict): A dictionary containing the static configuration. This method processes the static configuration by iterating through the key-value pairs of the 'value' dictionary and directly setting the - corresponding attribute on the Circuit object with the static value. + corresponding attribute on the Line object with the static value. """ for static_key, static_value in value.items(): setattr(line_, f"_{static_key}", static_value) @@ -207,16 +207,16 @@ def _process_static(line_, value): @staticmethod def _process_direct_mapping(line_, value, row): """ - Static method to process the direct mapping configuration for a Circuit object. + Static method to process the direct mapping configuration for a Line object. Args: - line_ (object): A Circuit object being updated. + line_ (object): A Line object being updated. value (dict): A dictionary containing the direct mapping configuration. - row (pd.Series): A row from the GeoDataFrame containing circuit-related data. + row (pd.Series): A row from the GeoDataFrame containing line-related data. This method processes the direct mapping configuration by iterating through the key-value pairs of the 'value' dictionary and directly setting the corresponding - attribute on the Circuit object using the value from the row. + attribute on the Line object using the value from the row. """ for mapping_key, mapping_value in value.items(): setattr(line_, f"_{mapping_key}", row[mapping_value]) @@ -224,29 +224,29 @@ def _process_direct_mapping(line_, value, row): @staticmethod def _process_indirect_mapping(line_, value, row): """ - Static method to process the indirect mapping configuration for a Circuit object. + Static method to process the indirect mapping configuration for a line object. Args: - line_ (object): A Circuit object being updated. + line_ (object): A line object being updated. value (dict): A dictionary containing the indirect mapping configuration. - row (pd.Series): A row from the GeoDataFrame containing circuit-related data. + row (pd.Series): A row from the GeoDataFrame containing line-related data. This method processes the indirect mapping configuration by iterating through the key-value pairs of the 'value' dictionary. If the value is a list, it treats the first element as a parameter name and the second element as a function name. The method then retrieves the parameter value from the row and calls the specified function with that parameter value. The result is then set as an attribute on the - Circuit object. + line object. If the value is not a list, the method directly sets the corresponding attribute on - the Circuit object using the value from the row. + the line object using the value from the row. """ for mapping_key, mapping_value in value.items(): if isinstance(mapping_value, list): param_name, function_name = mapping_value function_ = globals()[function_name] param_value = row[param_name] - setattr(line_, f"_{mapping_key}", function_(str(param_value))) # corrigingo para string para encontrar valor no dicionario + setattr(line_, f"_{mapping_key}", function_(str(param_value))) else: setattr(line_, f"_{mapping_key}", row[mapping_value]) @@ -256,13 +256,13 @@ def _process_calculated(line_, value, row): Static method to process the calculated mapping configuration for a Line object. Args: - circuit_ (object): A Circuit object being updated. + line_ (object): A Line object being updated. value (dict): A dictionary containing the direct mapping configuration. - row (pd.Series): A row from the GeoDataFrame containing circuit-related data. + row (pd.Series): A row from the GeoDataFrame containing line-related data. This method processes the direct mapping configuration by iterating through the key-value pairs of the 'value' dictionary and directly setting the corresponding - attribute on the Circuit object using the value from the row. + attribute on the Line object using the value from the row. """ for mapping_key, mapping_value in value.items(): From 81346989e6885c1800d75c50df2b3471678ddc48 Mon Sep 17 00:00:00 2001 From: Sourcery AI <> Date: Mon, 30 Oct 2023 03:47:10 +0000 Subject: [PATCH 3/3] 'Refactored by Sourcery' --- bdgd_tools/model/Line.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bdgd_tools/model/Line.py b/bdgd_tools/model/Line.py index 5f766ca..57d2db1 100644 --- a/bdgd_tools/model/Line.py +++ b/bdgd_tools/model/Line.py @@ -285,15 +285,15 @@ def _create_line_from_row(line_config, row): line_ = Line() for key, value in line_config.items(): - if key == "static": - line_._process_static(line_, value) + if key == "calculated": + line_._process_calculated(line_, value, row) + elif key == "direct_mapping": line_._process_direct_mapping(line_, value,row) elif key == "indirect_mapping": line_._process_indirect_mapping(line_, value,row) - elif key == "calculated": - line_._process_calculated(line_, value, row) - + elif key == "static": + line_._process_static(line_, value) return line_ @staticmethod