| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- import logging
- import pandas as pd
- from common.data import APPDIRS
- logger = logging.getLogger('simsdt.validacion')
- def load_results(filename):
- flujos_mct = pd.read_pickle(
- f'{APPDIRS["DATA"]}/flujos_inter_{filename}.dat')
- flujos_paises = pd.read_pickle(
- f'{APPDIRS["DATA"]}/flujos_paises_{filename}.dat')
- return flujos_mct[1:2], flujos_paises[1:2]
- def validar_flujos(filename, mctp, mes):
- finter, fnetos = load_results(filename)
- # Para Guatemala
- GU = {'FLUJOS':
- {'EXP NS': 0,
- 'IMP NS': 0,
- 'EXP SN': 0,
- 'IMP SN': 0,
- 'POR NS': 0,
- 'POR SN': 0},
- 'CASO': 0}
- if fnetos['GUA'][1] > 0:
- GU['FLUJOS']['EXP SN'] = finter['GUAELS'][1] + finter['GUAHON'][1]
- GU['FLUJOS']['IMP SN'] = 0
- else:
- GU['FLUJOS']['EXP SN'] = 0
- GU['FLUJOS']['IMP SN'] = finter['GUAELS'][1] + finter['GUAHON'][1]
- # Para El Salvador
- ES = {'FLUJOS':
- {'EXP NS': 0,
- 'IMP NS': 0,
- 'EXP SN': 0,
- 'IMP SN': 0,
- 'POR NS': 0,
- 'POR SN': 0},
- 'CASO': 0}
- if finter['GUAELS'][1] > 0 and finter['ELSHON'][1] > 0:
- ES['FLUJOS']['IMP NS'] = fnetos['ES'][1]
- ES['FLUJOS']['POR NS'] = finter['ELSHON'][1]
- ES['CASO'] = 1
- elif finter['GUAELS'][1] > 0 and finter['ELSHON'][1] < 0:
- ES['FLUJOS']['IMP NS'] = -1*finter['GUAELS'][1]
- ES['FLUJOS']['IMP SN'] = finter['ELSHON'][1]
- ES['CASO'] = 2
- elif finter['GUAELS'][1] < 0 and finter['ELSHON'][1] < 0:
- ES['FLUJOS']['EXP SN'] = fnetos['ES'][1]
- ES['FLUJOS']['POR SN'] = -1*finter['ELSHON'][1]
- ES['CASO'] = 3
- # Para Honduras
- HO = {'FLUJOS':
- {'EXP NS': 0,
- 'IMP NS': 0,
- 'EXP SN': 0,
- 'IMP SN': 0,
- 'POR NS': 0,
- 'POR SN': 0},
- 'CASO': 0}
- if finter['GUAHON'][1] > 0 and finter['ELSHON'][1] > 0 and finter['HONNIC'][1] > 0:
- HO['FLUJOS']['IMP NS'] = fnetos['HON'][1]
- HO['FLUJOS']['POR NS'] = finter['HONNIC'][1]
- HO['CASO'] = 1
- elif finter['GUAHON'][1] > 0 and finter['ELSHON'][1] > 0 and finter['HONNIC'][1] < 0:
- HO['FLUJOS']['IMP NS'] = -1*(finter['GUAHON'][1]+finter['ELSHON'])
- HO['FLUJOS']['IMP SN'] = finter['HONNIC'][1]
- HO['CASO'] = 2
- elif finter['GUAHON'][1] < 0 and finter['ELSHON'][1] < 0 and finter['HONNIC'][1] < 0:
- HO['FLUJOS']['EXP SN'] = fnetos['HON'][1]
- HO['FLUJOS']['POR SN'] = -1*finter['HONNIC'][1]
- HO['CASO'] = 3
- # Para NICARAGUA
- NI = {'FLUJOS':
- {'EXP NS': 0,
- 'IMP NS': 0,
- 'EXP SN': 0,
- 'IMP SN': 0,
- 'POR NS': 0,
- 'POR SN': 0},
- 'CASO': 0}
- if finter['HONNIC'][1] > 0 and finter['NICCRI'][1] > 0:
- NI['FLUJOS']['IMP NS'] = fnetos['NIC'][1]
- NI['FLUJOS']['POR NS'] = finter['NICRI'][1]
- NI['CASO'] = 1
- elif finter['HONNIC'][1] > 0 and finter['NICCRI'][1] < 0:
- NI['FLUJOS']['IMP NS'] = -1*finter['HONNIC'][1]
- NI['FLUJOS']['IMP SN'] = finter['NICCRI'][1]
- NI['CASO'] = 2
- elif finter['HONNIC'][1] < 0 and finter['NICCRI'][1] < 0:
- NI['FLUJOS']['EXP SN'] = fnetos['NIC'][1]
- NI['FLUJOS']['POR SN'] = -1*finter['NICCRI'][1]
- NI['CASO'] = 3
- # Para COSTA RICA
- CR = {'FLUJOS':
- {'EXP NS': 0,
- 'IMP NS': 0,
- 'EXP SN': 0,
- 'IMP SN': 0,
- 'POR NS': 0,
- 'POR SN': 0},
- 'CASO': 0}
- if finter['NICCRI'][1] > 0 and finter['CRIPAN'][1] >= 0:
- CR['FLUJOS']['IMP NS'] = fnetos['CR'][1]
- CR['FLUJOS']['POR NS'] = finter['CRIPAN'][1]
- CR['CASO'] = 1
- elif finter['NICCRI'][1] > 0 and finter['CRIPAN'][1] < 0:
- CR['FLUJOS']['IMP NS'] = -1*finter['NICCRI'][1]
- CR['FLUJOS']['IMP SN'] = finter['CRIPAN'][1]
- CR['CASO'] = 2
- elif finter['NICCRI'][1] < 0 and finter['CRIPAN'][1] < 0:
- CR['FLUJOS']['EXP SN'] = fnetos['CR'][1]
- CR['FLUJOS']['POR SN'] = -1*finter['CRIPAN'][1]
- CR['CASO'] = 3
- # Para Panama
- PA = {'FLUJOS':
- {'EXP NS': 0,
- 'IMP NS': 0,
- 'EXP SN': 0,
- 'IMP SN': 0,
- 'POR NS': 0,
- 'POR SN': 0},
- 'CASO': 0}
- if fnetos['PAN'][1] >= 0:
- PA['FLUJOS']['EXP SN'] = -1*finter['CRIPAN'][1]
- PA['FLUJOS']['IMP SN'] = 0
- else:
- PA['FLUJOS']['EXP SN'] = 0
- PA['FLUJOS']['IMP SN'] = -1*finter['CRIPAN'][1]
- res = {
- 'GU': GU,
- 'ES': ES,
- 'HO': HO,
- 'NI': NI,
- 'CR': CR,
- 'PA': PA
- }
- for (k, v) in res.items():
- for (kf, w) in v.items():
- if kf == 'FLUJOS':
- for (f, mw) in w.items():
- if round(abs(mw), 2) > mctp.loc[(1, k)][f]:
- if v['CASO'] == 1:
- logger.error(
- f"La restriccion de importacion total {k}debe cambiar a {mctp.loc[mes, k][f]}")
- elif v['CASO'] == 2:
- logger.error(
- f"La restriccion de mct ns {k} debe cambiar a {mctp.loc[mes, k][f]}")
- if v['CASO'] == 3:
- logger.error(
- f"La restriccion de exportacion total {k} debe cambiar a {mctp.loc[mes, k][f]}")
- else:
- pass
- # mctp = pd.read_excel('subasta_A2101_enero.xlsx', 'mctp', index_col=[0, 1])
|