Skip to content

Commit

Permalink
Definindo tipagem específica para cada coluna no conjunto final
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronaldo S.A. Batista committed Nov 17, 2023
1 parent 7fec660 commit afae4c6
Show file tree
Hide file tree
Showing 17 changed files with 1,784 additions and 1,306 deletions.
2 changes: 1 addition & 1 deletion extracao/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.9.4"
__version__ = "0.9.5"
1 change: 1 addition & 0 deletions extracao/_modidx.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@
'extracao/estacoes.py'),
'extracao.estacoes.Estacoes._remove_invalid_frequencies': ( 'estacoes.html#estacoes._remove_invalid_frequencies',
'extracao/estacoes.py'),
'extracao.estacoes.Estacoes._save': ('estacoes.html#estacoes._save', 'extracao/estacoes.py'),
'extracao.estacoes.Estacoes._simplify_sources': ( 'estacoes.html#estacoes._simplify_sources',
'extracao/estacoes.py'),
'extracao.estacoes.Estacoes._update_source': ( 'estacoes.html#estacoes._update_source',
Expand Down
70 changes: 35 additions & 35 deletions extracao/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
# %% auto 0
__all__ = ['TIMEOUT', 'RELATORIO', 'ESTACAO', 'MALHA_IBGE', 'FILES', 'PATH_NAV', 'PATH_COM', 'VOR_ILS_DME', 'CHANNELS',
'IBGE_MUNICIPIOS', 'IBGE_POLIGONO', 'COLUNAS', 'COLS_SRD', 'FLOAT_COLUMNS', 'INT_COLUMNS', 'STR_COLUMNS',
'CAT_COLUMNS', 'DTYPES', 'AGG_LICENCIAMENTO', 'AGG_SMP', 'APP_ANALISE_PT', 'APP_ANALISE_EN', 'ESTADOS',
'SIGLAS', 'BW', 'BW_MAP', 'DICT_SRD', 'PROJECTION_SRD', 'DICT_LICENCIAMENTO', 'PROJECTION_LICENCIAMENTO',
'MONGO_TELECOM', 'MONGO_SRD', 'MONGO_SMP', 'SQL_RADCOM', 'SQL_STEL', 'SQL_VALIDA_COORD', 'REGEX_ESTADOS',
'RE_BW', 'MIN_LAT', 'MAX_LAT', 'MIN_LONG', 'MAX_LONG']
'CAT_COLUMNS', 'AGG_LICENCIAMENTO', 'AGG_SMP', 'APP_ANALISE_PT', 'APP_ANALISE_EN', 'ESTADOS', 'SIGLAS', 'BW',
'BW_MAP', 'DICT_SRD', 'PROJECTION_SRD', 'DICT_LICENCIAMENTO', 'PROJECTION_LICENCIAMENTO', 'MONGO_TELECOM',
'MONGO_SRD', 'MONGO_SMP', 'SQL_RADCOM', 'SQL_STEL', 'SQL_VALIDA_COORD', 'REGEX_ESTADOS', 'RE_BW', 'MIN_LAT',
'MAX_LAT', 'MIN_LONG', 'MAX_LONG']

# %% ../nbs/00_constants.ipynb 2
import re
Expand Down Expand Up @@ -92,37 +92,37 @@
"Fonte",
]

DTYPES = {
"Frequência"
"Entidade"
"Fistel"
"Serviço"
"Estação"
"Latitude"
"Longitude"
"Código_Município"
"Município"
"UF"
"Classe"
"Classe_Emissão"
"Largura_Emissão(kHz)"
"Validade_RF"
"Status"
"Fonte"
"Multiplicidade"
"Log"
"Cota_Base_Torre(m)"
"Potência_Transmissor(W)"
"Ganho_Antena(dBd)"
"Ângulo_Elevação_Antena"
"Azimute_Antena"
"Altura_Antena(m)"
"Atenuação_Linha(db/100m)"
"Perdas_Acessórias_Linha(db)"
"Padrão_Antena(dBd)"
"Comprimento_Linha(m)"
"Relatório_Canal"
}
# DTYPES = {
# 'Frequência'
# 'Entidade'
# 'Fistel'
# 'Serviço'
# 'Estação'
# 'Latitude'
# 'Longitude'
# 'Código_Município'
# 'Município'
# 'UF'
# 'Classe'
# 'Classe_Emissão'
# 'Largura_Emissão(kHz)'
# 'Validade_RF'
# 'Status'
# 'Fonte'
# 'Multiplicidade'
# 'Log'
# 'Cota_Base_Torre(m)'
# 'Potência_Transmissor(W)'
# 'Ganho_Antena(dBd)'
# 'Ângulo_Elevação_Antena'
# 'Azimute_Antena'
# 'Altura_Antena(m)'
# 'Atenuação_Linha(db/100m)'
# 'Perdas_Acessórias_Linha(db)'
# 'Padrão_Antena(dBd)'
# 'Comprimento_Linha(m)'
# 'Relatório_Canal'
# }

# COLS_LICENCIAMENTO = [
# 'Frequência',
Expand Down
2 changes: 1 addition & 1 deletion extracao/datasources/arquivos/saida/VersionFile.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"appAnalise": {"Version": "1.39", "ReleaseDate": "14/11/2023"}, "appColeta": {"Version": "1.11", "ReleaseDate": "01/12/2022"}, "appColetaV2": {"Version": "1.49", "ReleaseDate": "05/10/2023"}, "anateldb": {"ReleaseDate": "17/11/2023 05:57:31", "ANATEL": "17/11/2023 05:57:31", "AERONAUTICA": "17/11/2023 05:57:31"}, "fiscaliza": {"Version": "0.2.20", "ReleaseDate": "27/02/2023"}, "rfpye": {"Version": "0.2.3", "ReleaseDate": "03/11/2021"}}
{"appAnalise": {"Version": "1.39", "ReleaseDate": "14/11/2023"}, "appColeta": {"Version": "1.11", "ReleaseDate": "01/12/2022"}, "appColetaV2": {"Version": "1.49", "ReleaseDate": "05/10/2023"}, "anateldb": {"ReleaseDate": "17/11/2023 10:05:52", "ANATEL": "17/11/2023 10:05:52", "AERONAUTICA": "17/11/2023 10:05:52"}, "fiscaliza": {"Version": "0.2.20", "ReleaseDate": "27/02/2023"}, "rfpye": {"Version": "0.2.3", "ReleaseDate": "03/11/2021"}}
4 changes: 3 additions & 1 deletion extracao/datasources/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ def _save(
"""Format, Save and return a dataframe"""
try:
file = Path(f"{folder}/{stem}.parquet.gzip")
df.to_parquet(file, compression="gzip", index=False, engine="pyarrow")
df.astype("string[pyarrow]").to_parquet(
file, compression="gzip", index=False, engine="pyarrow"
)
except (ArrowInvalid, ArrowTypeError) as e:
raise e(f"Não foi possível salvar o arquivo parquet {file}") from e
return df
Expand Down
10 changes: 5 additions & 5 deletions extracao/datasources/sitarweb.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,13 @@ def _format(
) -> pd.DataFrame: # DataFrame formatado
"""Formata, limpa e padroniza os dados provenientes da query no banco"""
df["Entidade"] = df["Entidade"].str.strip()
df["Num_Serviço"] = "231"
df["Classe_Emissão"] = pd.NA
df["Largura_Emissão(kHz)"] = "256"
df["Validade_RF"] = pd.NA
df["Serviço"] = 231
df["Classe_Emissão"] = "-1"
df["Largura_Emissão(kHz)"] = 256
df["Validade_RF"] = "-1"
df["Status"] = "RADCOM"
df["Fonte"] = "SRD"
df["Multiplicidade"] = "1"
df["Multiplicidade"] = 1
a = df.Situação.isna()
df.loc[a, "Classe"] = df.loc[a, "Fase"].astype("string")
df.loc[~a, "Classe"] = (
Expand Down
19 changes: 16 additions & 3 deletions extracao/estacoes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# %% ../nbs/04_estacoes.ipynb 3
import urllib.request
from typing import List
from typing import List, Union
from zipfile import ZipFile

import geopandas as gpd
Expand All @@ -14,6 +14,8 @@
from fastcore.foundation import L
from fastcore.parallel import parallel
from fastcore.xtras import Path
from pyarrow import ArrowInvalid, ArrowTypeError


from extracao.constants import (
COLS_SRD,
Expand Down Expand Up @@ -76,8 +78,8 @@ def init_data_sources(self):
"telecom": Telecom(self.mongo_uri, self.limit),
"smp": SMP(self.mongo_uri, self.limit),
"srd": SRD(self.mongo_uri, self.limit),
# 'stel': Stel(self.sql_params),
# 'radcom': Radcom(self.sql_params),
"stel": Stel(self.sql_params),
"radcom": Radcom(self.sql_params),
"aero": Aero(),
}

Expand Down Expand Up @@ -285,6 +287,17 @@ def _remove_invalid_frequencies(df):
# """
# self.register_log(df, log, check_coords)

def _save(
self, df: pd.DataFrame, folder: Union[str, Path], stem: str
) -> pd.DataFrame:
"""Format, Save and return a dataframe"""
try:
file = Path(f"{folder}/{stem}.parquet.gzip")
df.to_parquet(file, compression="gzip", index=False, engine="pyarrow")
except (ArrowInvalid, ArrowTypeError) as e:
raise e(f"Não foi possível salvar o arquivo parquet {file}") from e
return df

@staticmethod
def _format_types(df):
df["Frequência"] = df["Frequência"].astype("double[pyarrow]")
Expand Down
10 changes: 4 additions & 6 deletions extracao/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,10 @@ def merge_on_frequency(
"""Mescla os dataframes baseados na frequência
É assumido que as colunas de ambos uma é subconjunto ou idêntica à outra, caso contrário os filtros não irão funcionar como esperado
"""
df_left["Frequência"] = df_left["Frequência"].astype(
"string[pyarrow]"
) # .drop_duplicates(ignore_index=True)
df_right["Frequência"] = df_right["Frequência"].astype(
"string[pyarrow]"
) # .drop_duplicates(ignore_index=True)
df_left["Frequência"] = df_left["Frequência"].astype("string[pyarrow]")
df_left.drop_duplicates(ignore_index=True, inplace=True)
df_right["Frequência"] = df_right["Frequência"].astype("string[pyarrow]")
df_right.drop_duplicates(ignore_index=True, inplace=True)
df: pd.DataFrame = pd.merge(
df_left,
df_right,
Expand Down
Loading

0 comments on commit afae4c6

Please sign in to comment.