Skip to content

Commit

Permalink
Merge pull request #3 from elpablete/main
Browse files Browse the repository at this point in the history
Add support for file 'fronteras'
  • Loading branch information
elpablete authored Oct 31, 2023
2 parents 2783144 + db58f5c commit 2261af6
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/asic/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.0
0.2.0
4 changes: 2 additions & 2 deletions src/asic/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import pathlib
from ssl import SSLZeroReturnError
from typing import Optional
import pydantic

import pydantic
import typer
from rich.progress import track

Expand Down Expand Up @@ -92,7 +92,7 @@ def get_ftps(
ftps.connect(
port=ftps_port,
)

logger.info(f"Login to FTP '{ftps_host}' as '{ftps_user}'")
ftps.login(user=ftps_user, passwd=ftps_password.get_secret_value())

ftps.prot_p()
Expand Down
3 changes: 2 additions & 1 deletion src/asic/data/ASIC_FILE_CONFIG.jsonl
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
{"code":"cliq", "visibility": "public","name_pattern":"(?P<code>cliq)(?P<name_month>[0-9]{2}).(?P<ext>[a-zA-Z0-9]+)","location_pattern":"/INFORMACION_XM/PUBLICOK/SIC/COMERCIA/{location_year:04}-{location_month:02}/","description":"Liquidación diaria de los agentes comercializadores"}
{"code":"desbm", "visibility": "agent","name_pattern":"(?P<code>desbm)(?P<name_month>[0-9]{2})(?P<name_day>[0-9]{2}).(?P<ext>[a-zA-Z0-9]+)","location_pattern":"/INFORMACION_XM/USUARIOSK/{agent}/SIC/COMERCIA/{location_year:04}-{location_month:02}/","description":""}
{"code":"desbmex", "visibility": "agent","name_pattern":"(?P<code>desbmex)(?P<name_month>[0-9]{2})(?P<name_day>[0-9]{2}).(?P<ext>[a-zA-Z0-9]+)","location_pattern":"/INFORMACION_XM/USUARIOSK/{agent}/SIC/COMERCIA/{location_year:04}-{location_month:02}/","description":""}
{"code":"oefagnch", "visibility": "agent","name_pattern":"(?P<code>oefagnch)(?P<name_month>[0-9]{2})(?P<name_day>[0-9]{2}).(?P<ext>[a-zA-Z0-9]+)","location_pattern":"/INFORMACION_XM/USUARIOSK/{agent}/SIC/COMERCIA/{location_year:04}-{location_month:02}/","description":""}
{"code":"oefagnch", "visibility": "agent","name_pattern":"(?P<code>oefagnch)(?P<name_month>[0-9]{2})(?P<name_day>[0-9]{2}).(?P<ext>[a-zA-Z0-9]+)","location_pattern":"/INFORMACION_XM/USUARIOSK/{agent}/SIC/COMERCIA/{location_year:04}-{location_month:02}/","description":""}
{"code":"fronteras", "visibility": "agent","name_pattern":"(?P<agent>[a-zA-Z]{4})_(?P<code>FronterasComerciales)_(?P<name_day>[0-9]{2})-(?P<name_month>[0-9]{2})-(?P<name_year>[0-9]{4}).(?P<ext>xlsx)","location_pattern":"/INFORMACION_XM/USUARIOSK/{agent}/SIC/FRONTERAS/{location_year:04}-{location_month:02}/","description":"Formato con universo de fronteras de un agente, no parece tener un cronograma de publicación"}
14 changes: 8 additions & 6 deletions src/asic/files/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,22 @@
from .adem import adem_preprocess
from .aenc import aenc_preprocess
from .afac import afac_preprocess
from .balcttos import balcttos_preprocess
from .cliq import cliq_preprocess
from .desbm import desbm_preprocess
from .desbmex import desbmex_preprocess
from .dspcttos import dspcttos_preprocess
from .fronteras import fronteras_preprocess
from .ldcbmr import ldcbmr_preprocess
from .oefagnch import oefagnch_preprocess
from .pep import pep_preprocess
from .pubfc import pubfc_preprocess
from .pubfc_falla_hurto import pubfc_falla_hurto_preprocess
from .sntie import sntie_preprocess
from .tfroc import tfroc_preprocess
from .tgrl import tgrl_preprocess
from .trsd import trsd_preprocess
from .trsm import trsm_preprocess
from .tfroc import tfroc_preprocess
from .cliq import cliq_preprocess
from .balcttos import balcttos_preprocess
from .desbm import desbm_preprocess
from .desbmex import desbmex_preprocess
from .oefagnch import oefagnch_preprocess

# from .undefined import undefined_preprocess

Expand All @@ -43,6 +44,7 @@ class SupportedFiles(str, enum.Enum):
DESBM = "desbm", desbm_preprocess
DESBMEX = "desbmex", desbmex_preprocess
OEFAGNCH = "oefagnch", oefagnch_preprocess
FRONTERAS = "fronteras", fronteras_preprocess

def __new__(cls, code, preprocessor):
obj = str.__new__(cls, [code])
Expand Down
104 changes: 104 additions & 0 deletions src/asic/files/fronteras.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import logging
import pathlib

# Third party imports
import pandas as pd

# Local application imports
from asic.reader import FileReader

from ..metadata import FileItemInfo

logger = logging.getLogger(__name__)

fronteras_format = {
"type": "xlsx",
"sheet_name": "Fronteras Comerciales",
"encoding": "cp1252",
"dt_fields": {
"Registrada por primera vez el": {"format": "%d-%m-%Y"},
"Inicio Representación Frontera": {"format": "%d-%m-%Y"},
"Último Cambio en Medidor Ppal o Transformadores": {"format": "%d-%m-%Y"},
"Fecha de Calibración Med. Ppal": {"format": "%d-%m-%Y"},
"Actualizada por última vez el": {"format": "%Y-%m-%d %H:%M:%S"},
"Último Cambio en Medidor Resp.": {"format": "%d-%m-%Y"},
"Fecha de Calibración Med. Resp.": {"format": "%d-%m-%Y"},
},
"dtype": {
"Código SIC": str,
"Nombre de la Frontera": str,
"Registrada en el Mercado por": str,
"Registrada por primera vez el": str,
"Factor de Pérdidas": float,
"NIU": str,
"NIT": str,
"Voltaje (kV)": str,
"Nivel de Tensión": str,
"Tipo Punto Medicion": str,
"Representante Frontera": str,
"Inicio Representación Frontera": str,
"Representante Anterior": str,
"Operador de Red": str,
"Operador de Red de la Zona": str,
"Agente Exportador": str,
"Agente Importador": str,
"Tipo de Frontera": str,
"Nombre del CGM": str,
"Código SIC DDV": str,
"Predio ID": str,
"Nombre del Predio": str,
"Representante de la DDV": str,
"Número de Serie Med. Ppal": str,
"Marca Med. Ppal": str,
"Clase del Medidor": str,
"Clase del CT": str,
"Clase del PT": str,
"Último Cambio en Medidor Ppal o Transformadores": str,
"Entidad Calibradora Med. Ppal.": str,
"Fecha de Calibración Med. Ppal": str,
"Actualizada por última vez el": str,
"Número de Serie Med. Resp.": str,
"Marca Med. Resp.": str,
"Último Cambio en Medidor Resp.": str,
"Entidad Calibradora Med. Resp.": str,
"Fecha de Calibración Med. Resp.": str,
"Actualizada por última vez el.1": str, # Added the ".1" since the column name is repeated
"Es Agrupadora": str,
"Factor PSF (Para agrupadoras)": float,
"Agrupada bajo la": str,
"Es Principal de Modelo Embebido": str,
"Embebida bajo la": str,
"Factor Acordado": float,
"Factor Ajuste": float,
"Factor de Pérdidas Frontera Principal (para embebidas)": float,
"Código CIIU": str,
"Clasificación Industral General": str,
"Clasificación Industrial Específica": str,
"NIT.1": str, # Added the ".1" since the column name is repeated
"Departamento": str,
"Municipio": str,
"Centro Poblado": str,
"Dirección": str,
"Latitud (°)": float,
"Longitud (°)": float,
"Altitud (msnm)": int,
"Código SIC Submercado": str,
},
}


class Fronteras(FileReader):
def __init__(self):
return super().__init__(fronteras_format.copy())


def fronteras_preprocess(filepath: pathlib.Path, item: FileItemInfo) -> pd.DataFrame:
"""
fronteras: se publica un archivo por dia.
versiones: No aplica
"""
fronteras_reader = Fronteras()
total = fronteras_reader.read(filepath)

return_col = ["Código SIC", "Nombre de la Frontera"]
return total[return_col]

0 comments on commit 2261af6

Please sign in to comment.