Skip to content

Commit

Permalink
Merge pull request #619 from gisce/compare-8-2021
Browse files Browse the repository at this point in the history
Comparación con ficheros de la Circular 8/2021
  • Loading branch information
ecarreras authored Mar 6, 2024
2 parents c24e042 + 0876ff7 commit fa6f520
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 35 deletions.
44 changes: 36 additions & 8 deletions libcnmc/cir_8_2021/FB1.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def __init__(self, **kwargs):
self.forced_ids = {}
self.prefix_AT = kwargs.pop('prefix_at', 'A') or 'A'
self.prefix_BT = kwargs.pop('prefix_bt', 'B') or 'B'
self.compare_field = '4666_entregada'
self.dividir = kwargs.pop('div', False)

O = self.connection
Expand Down Expand Up @@ -127,7 +126,7 @@ def consumer(self):
'baixa', 'data_pm', 'data_industria', 'coeficient', 'cini', 'propietari', 'tensio_max_disseny_id', 'name',
'origen', 'final', 'perc_financament', 'longitud_cad', 'cable', 'linia', 'model', 'model', 'punt_frontera',
'tipus_instalacio_cnmc_id', 'data_baixa', 'baixa', 'longitud_cad', 'data_pm', 'circuits',
'id_regulatori', self.compare_field, 'municipi',
'id_regulatori', 'municipi',
]
data_pm_limit = '{0}-01-01'.format(self.year + 1)

Expand Down Expand Up @@ -459,9 +458,24 @@ def get_inst_name(element_id):
operacion = 0
else:
# Estado
if tram[self.compare_field]:
data_entregada = tram[self.compare_field]
entregada = F1Res4666(**data_entregada)
# Busquem a l'historic
hist_obj = O.model('circular.82021.historics.b1')
hist_ids = hist_obj.search([
('identificador_tramo', '=', o_tram),
('year', '=', self.year - 1)
])
if hist_ids:
hist = hist_obj.read(hist_ids[0], [
'cini', 'codigo_ccuu', 'longitud',
'tension_explotacion', 'fecha_aps'
])
entregada = F1Res4666(
cini=hist['cini'],
longitud=hist['longitud'],
codigo_ccuu=hist['codigo_ccuu'],
nivel_tension=hist['tension_explotacion'],
fecha_aps=hist['fecha_aps']
)
actual = F1Res4666(
o_tram,
tram['cini'],
Expand Down Expand Up @@ -843,9 +857,23 @@ def get_inst_name(element_id):
operacion = 0
else:
# Estado
if linia[self.compare_field]:
data_entregada = linia[self.compare_field]
entregada = F2Res4666(**data_entregada)
hist_obj = O.model('circular.82021.historics.b1')
hist_ids = hist_obj.search([
('identificador_tramo', '=', identificador_tramo),
('year', '=', self.year - 1)
])
if hist_ids:
hist = hist_obj.read(hist_ids[0], [
'cini', 'codigo_ccuu', 'longitud',
'tension_explotacion', 'fecha_aps'
])
entregada = F1Res4666(
cini=hist['cini'],
longitud=hist['longitud'],
codigo_ccuu=hist['codigo_ccuu'],
nivel_tension=hist['tension_explotacion'],
fecha_aps=hist['fecha_aps']
)
actual = F2Res4666(
identificador_tramo,
linia['cini'],
Expand Down
20 changes: 15 additions & 5 deletions libcnmc/cir_8_2021/FB2.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def __init__(self, **kwargs):
self.codi_r1 = kwargs.pop('codi_r1')
self.base_object = 'CTS'
self.report_name = 'Formulario B2: Centros de Transformación'
self.compare_field = "4666_entregada"
self.extended = kwargs.get("extended", False)

def get_sequence(self):
Expand Down Expand Up @@ -126,7 +125,7 @@ def get_inst_name(element_id):
fields_to_read = [
'id', 'name', 'cini', 'data_pm', 'tipus_instalacio_cnmc_id', 'tensio_p',
'id_municipi', 'perc_financament', 'descripcio', 'data_baixa', 'tensio_const',
self.compare_field, 'node_baixa', 'zona_id', 'node_id', 'potencia',
'node_baixa', 'zona_id', 'node_id', 'potencia',
'model', 'punt_frontera', 'id_regulatori', 'perc_financament',
]

Expand Down Expand Up @@ -361,9 +360,20 @@ def get_inst_name(element_id):
modelo = ct['model']

# Estado
if ct[self.compare_field]:
last_data = ct[self.compare_field]
entregada = F8Res4666(**last_data)
hist_obj = O.model('circular.82021.historics.b2')
hist_ids = hist_obj.search([
('identificador_ct', '=', o_identificador_ct),
('year', '=', self.year - 1)
])
if hist_ids:
hist = hist_obj.read(hist_ids[0], [
'cini', 'codigo_ccuu', 'fecha_aps'
])
entregada = F8Res4666(
cini=hist['cini'],
codigo_ccuu=hist['codigo_ccuu'],
fecha_aps=hist['fecha_aps']
)

id_ti = ct['tipus_instalacio_cnmc_id'][0]
ti = O.GiscedataTipusInstallacio.read(
Expand Down
20 changes: 15 additions & 5 deletions libcnmc/cir_8_2021/FB4.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def __init__(self, **kwargs):
"""

self.year = kwargs.pop('year', datetime.now().year - 1)
self.compare_field = '4666_entregada'

super(FB4, self).__init__(**kwargs)
self.include_obres = False
Expand Down Expand Up @@ -118,7 +117,7 @@ def consumer(self):

fields_to_read = [
'name', 'cini', 'node_id', 'propietari', 'subestacio_id', 'data_pm', 'tensio', 'model',
'parc_id', 'data_baixa', 'interruptor', 'tipus_instalacio_cnmc_id', 'punt_frontera', self.compare_field,
'parc_id', 'data_baixa', 'interruptor', 'tipus_instalacio_cnmc_id', 'punt_frontera',
'tipus_interruptor',
]
fields_to_read_obra = [
Expand Down Expand Up @@ -292,9 +291,20 @@ def get_inst_name(element_id):
else:
equipada = interruptor

if pos[self.compare_field]:
last_data = pos[self.compare_field]
entregada = F4Res4666(**last_data)
hist_obj = O.model('circular.82021.historics.b4')
hist_ids = hist_obj.search([
('identificador_posicion', '=', pos['name']),
('year', '=', self.year - 1)
])
if hist_ids:
hist = hist_obj.read(hist_ids[0], [
'cini', 'codigo_ccuu', 'fecha_aps'
])
entregada = F4Res4666(
cini=hist['cini'],
codigo_ccuu=hist['codigo_ccuu'],
fecha_aps=hist['fecha_aps']
)
actual = F4Res4666(
pos['name'],
pos['cini'],
Expand Down
20 changes: 15 additions & 5 deletions libcnmc/cir_8_2021/FB5.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def __init__(self, **kwargs):
self.year = kwargs.pop('year', datetime.now().year - 1)
self.report_name = 'FB5 - TRAFOS-SE'
self.base_object = 'TRAFOS'
self.compare_field = '4666_entregada'

def get_sequence(self):
search_params = [
Expand Down Expand Up @@ -65,7 +64,7 @@ def consumer(self):
o = self.connection
fields_to_read = [
'ct', 'name', 'cini', 'potencia_nominal', 'id_estat', 'node_id', 'data_pm', 'data_baixa', 'id_regulatori',
'tipus_instalacio_cnmc_id', 'node_baixa', 'model', self.compare_field
'tipus_instalacio_cnmc_id', 'node_baixa', 'model'
]
fields_to_read_obra = [
'subvenciones_europeas', 'subvenciones_nacionales', 'subvenciones_prtr', 'financiado',
Expand Down Expand Up @@ -223,9 +222,20 @@ def get_inst_name(element_id):
['name'])['name']

# ESTADO
if trafo[self.compare_field]:
last_data = trafo[self.compare_field]
entregada = F5Res4666(**last_data)
hist_obj = self.connection.model('circular.82021.historics.b5')
hist_ids = hist_obj.search([
('identificador_maquina', '=', o_maquina),
('year', '=', self.year - 1)
])
if hist_ids:
hist = hist_obj.read(hist_ids[0], [
'cini', 'codigo_ccuu', 'fecha_aps'
])
entregada = F5Res4666(
cini=hist['cini'],
codigo_ccuu=hist['codigo_ccuu'],
fecha_aps=hist['fecha_aps']
)
actual = F5Res4666(
trafo['name'],
trafo['cini'],
Expand Down
21 changes: 15 additions & 6 deletions libcnmc/cir_8_2021/FB6.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ def __init__(self, **kwargs):
self.report_name = 'FB6 - Elements de millora de fiabilitat'
self.base_object = 'Elements de millora de fiabilitat'
self.cod_dis = 'R1-{}'.format(self.codi_r1[-3:])
self.compare_field = "4666_entregada"
self.prefix_AT = kwargs.pop('prefix_at', 'A') or 'A'
self.compare_field = '4666_entregada'

def get_sequence(self):
"""
Expand Down Expand Up @@ -203,7 +201,7 @@ def get_inst_name(element_id):
fields_to_read = [
'installacio', 'cini', 'propietari', 'name', 'tensio', 'node_id', 'perc_financament',
'tipus_instalacio_cnmc_id', 'punt_frontera', 'tensio_const', 'model',
'geom', 'tram_id', 'id', 'data_pm', 'data_baixa', self.compare_field,
'geom', 'tram_id', 'id', 'data_pm', 'data_baixa',
]
fields_to_read_obra = [
'name', 'cini', 'tipo_inversion', 'ccuu', 'codigo_ccaa', 'nivel_tension_explotacion', 'elemento_act',
Expand Down Expand Up @@ -420,9 +418,20 @@ def get_inst_name(element_id):
y = format_f(res_srid[1], decimals=3)

# ESTADO
if cella[self.compare_field] and str(self.year + 1) not in str(data_pm):
last_data = cella[self.compare_field]
entregada = F7Res4666(**last_data)
hist_obj = O.model('circular.82021.historics.b6')
hist_ids = hist_obj.search([
('identificador_em', '=', o_fiabilitat),
('year', '=', self.year - 1)
])
if hist_ids:
hist = hist_obj.read(hist_ids[0], [
'cini', 'codigo_ccuu', 'fecha_aps'
])
entregada = F7Res4666(
cini=hist['cini'],
codigo_ccuu=hist['codigo_ccuu'],
fecha_aps=hist['fecha_aps']
)
actual = F7Res4666(
cella['name'],
cella['cini'],
Expand Down
19 changes: 14 additions & 5 deletions libcnmc/cir_8_2021/FB8.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ def __init__(self, **kwargs):
self.year = kwargs.pop('year', datetime.now().year - 1)
self.report_name = 'FB8 - Otros activos'
self.base_object = 'Despatxos'
self.compare_field = '4666_entregada'

def get_sequence(self):
data_pm = '{0}-01-01'.format(self.year + 1)
Expand All @@ -52,7 +51,7 @@ def consumer(self):
data_baixa_limit = '{0}-01-01'.format(self.year)
fields_to_read = [
'id', 'cini', 'name', 'geom', 'vertex', 'data_apm', 'data_baixa', 'municipi', 'data_baixa_parcial',
'valor_baixa_parcial', 'motivacion', self.compare_field, 'coco',
'valor_baixa_parcial', 'motivacion', 'coco',
]
fields_to_read_obra = [
'subvenciones_europeas', 'subvenciones_nacionales', 'subvenciones_prtr', 'financiado', 'fecha_baja',
Expand Down Expand Up @@ -173,9 +172,19 @@ def consumer(self):
if comunitat_vals:
comunitat_codi = comunitat_vals['codi']

if despatx[self.compare_field]:
data_entregada = despatx[self.compare_field]
entregada = F6Res4666(**data_entregada)
hist_obj = O.model('circular.82021.historics.b8')
hist_ids = hist_obj.search([
('identificador_posicion', '=', despatx['name']),
('year', '=', self.year - 1)
])
if hist_ids:
hist = hist_obj.read(hist_ids[0], [
'cini', 'codigo_ccuu', 'fecha_aps'
])
entregada = F6Res4666(
cini=hist['cini'],
fecha_aps=hist['fecha_aps']
)
actual = F6Res4666(
despatx['name'],
despatx['cini'],
Expand Down
7 changes: 6 additions & 1 deletion libcnmc/models/cnmcmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ def __init__(self, *values, **kwvalues):
"""
self.validator = CNMCValidator(self.schema)
stored = namedtuple('{0}_store'.format(self.__class__.__name__), self.fields)
self.store = stored(*values, **kwvalues)
for idx, k in enumerate(self.fields):
if idx < len(values):
kwvalues[k] = values[idx]
elif k not in kwvalues:
kwvalues[k] = None
self.store = stored(**kwvalues)
self.validator.validate(self.store._asdict())
self.store = stored(**self.validator.document)

Expand Down

0 comments on commit fa6f520

Please sign in to comment.