Skip to content

Commit

Permalink
Corrigido tratamento de erro para #Estação não numérico
Browse files Browse the repository at this point in the history
Adicionado também tratamento de erros genérico caso haja erro na atualização dos dados aeronáuticos. A chamada fillna com o argumento inplace=True no pandas não parece estar funcionando
  • Loading branch information
ronaldokun committed Sep 6, 2023
1 parent b28a373 commit fa06b0d
Show file tree
Hide file tree
Showing 27 changed files with 75,946 additions and 75,790 deletions.
28 changes: 1 addition & 27 deletions dados/VersionFile.json
Original file line number Diff line number Diff line change
@@ -1,27 +1 @@
{
"appAnalise": {
"Version": "1.35",
"ReleaseDate": "28/06/2023"
},
"appColeta": {
"Version": "1.11",
"ReleaseDate": "01/12/2022"
},
"appColetaV2": {
"Version": "1.41",
"ReleaseDate": "25/08/2023"
},
"anateldb": {
"ReleaseDate": "25/08/2023 08:56:21",
"ANATEL": "25/08/2023 08:53:59",
"AERONAUTICA": "25/08/2023 08:55:26"
},
"fiscaliza": {
"Version": "0.2.20",
"ReleaseDate": "27/02/2023"
},
"rfpye": {
"Version": "0.2.3",
"ReleaseDate": "03/11/2021"
}
}
{"appAnalise": {"Version": "1.35", "ReleaseDate": "28/06/2023"}, "appColeta": {"Version": "1.11", "ReleaseDate": "01/12/2022"}, "appColetaV2": {"Version": "1.42", "ReleaseDate": "30/08/2023"}, "anateldb": {"ReleaseDate": "06/09/2023 09:42:20", "ANATEL": "06/09/2023 09:41:52", "AERONAUTICA": "06/09/2023 09:41:52"}, "fiscaliza": {"Version": "0.2.20", "ReleaseDate": "27/02/2023"}, "rfpye": {"Version": "0.2.3", "ReleaseDate": "03/11/2021"}}
2 changes: 1 addition & 1 deletion extracao/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.8.0"
__version__ = "0.8.1"
29 changes: 17 additions & 12 deletions extracao/_modidx.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,24 @@
'extracao.aero.aisgeo.get_aisg': ('aisgeo.html#get_aisg', 'extracao/aero/aisgeo.py'),
'extracao.aero.aisgeo.get_geodf': ('aisgeo.html#get_geodf', 'extracao/aero/aisgeo.py')},
'extracao.aero.aisweb': { 'extracao.aero.aisweb.AisWeb': ('aisweb.html#aisweb', 'extracao/aero/aisweb.py'),
'extracao.aero.aisweb.AisWeb.__init__': ('aisweb.html#__init__', 'extracao/aero/aisweb.py'),
'extracao.aero.aisweb.AisWeb._check_ils_dme': ( 'aisweb.html#_check_ils_dme',
'extracao.aero.aisweb.AisWeb.__init__': ('aisweb.html#aisweb.__init__', 'extracao/aero/aisweb.py'),
'extracao.aero.aisweb.AisWeb._check_ils_dme': ( 'aisweb.html#aisweb._check_ils_dme',
'extracao/aero/aisweb.py'),
'extracao.aero.aisweb.AisWeb._filter_freq': ('aisweb.html#_filter_freq', 'extracao/aero/aisweb.py'),
'extracao.aero.aisweb.AisWeb._get_request': ('aisweb.html#_get_request', 'extracao/aero/aisweb.py'),
'extracao.aero.aisweb.AisWeb._parse_type': ('aisweb.html#_parse_type', 'extracao/aero/aisweb.py'),
'extracao.aero.aisweb.AisWeb._process_coords': ( 'aisweb.html#_process_coords',
'extracao.aero.aisweb.AisWeb._filter_freq': ( 'aisweb.html#aisweb._filter_freq',
'extracao/aero/aisweb.py'),
'extracao.aero.aisweb.AisWeb._get_request': ( 'aisweb.html#aisweb._get_request',
'extracao/aero/aisweb.py'),
'extracao.aero.aisweb.AisWeb._parse_type': ( 'aisweb.html#aisweb._parse_type',
'extracao/aero/aisweb.py'),
'extracao.aero.aisweb.AisWeb._process_coords': ( 'aisweb.html#aisweb._process_coords',
'extracao/aero/aisweb.py'),
'extracao.aero.aisweb.AisWeb._process_data': ('aisweb.html#_process_data', 'extracao/aero/aisweb.py'),
'extracao.aero.aisweb.AisWeb.airports': ('aisweb.html#airports', 'extracao/aero/aisweb.py'),
'extracao.aero.aisweb.AisWeb.records': ('aisweb.html#records', 'extracao/aero/aisweb.py'),
'extracao.aero.aisweb.AisWeb.request_aero': ('aisweb.html#request_aero', 'extracao/aero/aisweb.py'),
'extracao.aero.aisweb.AisWeb.request_stations': ( 'aisweb.html#request_stations',
'extracao.aero.aisweb.AisWeb._process_data': ( 'aisweb.html#aisweb._process_data',
'extracao/aero/aisweb.py'),
'extracao.aero.aisweb.AisWeb.airports': ('aisweb.html#aisweb.airports', 'extracao/aero/aisweb.py'),
'extracao.aero.aisweb.AisWeb.records': ('aisweb.html#aisweb.records', 'extracao/aero/aisweb.py'),
'extracao.aero.aisweb.AisWeb.request_aero': ( 'aisweb.html#aisweb.request_aero',
'extracao/aero/aisweb.py'),
'extracao.aero.aisweb.AisWeb.request_stations': ( 'aisweb.html#aisweb.request_stations',
'extracao/aero/aisweb.py'),
'extracao.aero.aisweb.convert_latitude': ('aisweb.html#convert_latitude', 'extracao/aero/aisweb.py'),
'extracao.aero.aisweb.convert_longitude': ( 'aisweb.html#convert_longitude',
Expand Down Expand Up @@ -71,4 +76,4 @@
'extracao.updates.update_srd': ('updates.html#update_srd', 'extracao/updates.py'),
'extracao.updates.update_stel': ('updates.html#update_stel', 'extracao/updates.py'),
'extracao.updates.update_telecom': ('updates.html#update_telecom', 'extracao/updates.py'),
'extracao.updates.validar_coords': ('updates.html#validar_coords', 'extracao/updates.py')}}}
'extracao.updates.validar_coords': ('updates.html#validar_coords', 'extracao/updates.py')}}}
5 changes: 0 additions & 5 deletions extracao/aero/aisgeo.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@

UNIQUE_COLS = ["Frequency", "Latitude", "Longitude"]


# %% ../../nbs/08_aisgeo.ipynb 6
def convert_frequency(
freq: float, # Frequência Central da emissão
Expand All @@ -71,7 +70,6 @@ def convert_frequency(
result = -1
return result


# %% ../../nbs/08_aisgeo.ipynb 7
def _process_frequency(
df: pd.DataFrame, # Dataframe com os dados
Expand Down Expand Up @@ -100,7 +98,6 @@ def _process_frequency(
)
return df


# %% ../../nbs/08_aisgeo.ipynb 8
def _filter_df(df, cols): # sourcery skip: use-fstring-for-concatenation
df.fillna("", inplace=True)
Expand All @@ -117,7 +114,6 @@ def _filter_df(df, cols): # sourcery skip: use-fstring-for-concatenation
}
)


# %% ../../nbs/08_aisgeo.ipynb 9
def get_geodf(
link: str, # Link para a requisição das estações VOR do GEOAISWEB
Expand All @@ -142,7 +138,6 @@ def get_geodf(
df = _process_frequency(df, cols)
return _filter_df(df, cols)


# %% ../../nbs/08_aisgeo.ipynb 13
def get_aisg() -> pd.DataFrame: # DataFrame com todos os dados do GEOAISWEB
"""Lê e processa os dataframes individuais da API GEOAISWEB e retorna o conjunto concatenado"""
Expand Down
3 changes: 0 additions & 3 deletions extracao/aero/aisweb.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
COLUMNS = ["Frequency", "Latitude", "Longitude", "Description"]
UNIQUE_COLS = ["Frequency", "Latitude", "Longitude"]


# %% ../../nbs/07_aisweb.ipynb 6
def convert_latitude(
lat: str, # Latitude
Expand All @@ -50,7 +49,6 @@ def convert_longitude(
float(lon[:3]) + float(lon[3:5]) / 60 + float(lon[6:8]) / 3600.0
)


# %% ../../nbs/07_aisweb.ipynb 7
class AisWeb:
"""Classe para encapsular requisições REST à API do AISWEB"""
Expand Down Expand Up @@ -211,7 +209,6 @@ def records(
df = pd.concat(records).astype("string")
return map_channels(df, "AISW").drop_duplicates(UNIQUE_COLS, ignore_index=True)


# %% ../../nbs/07_aisweb.ipynb 8
def get_aisw() -> pd.DataFrame: # DataFrame com todos os dados do GEOAISWEB
"""Lê e processa os dataframes individuais da API AISWEB e retorna o conjunto concatenado"""
Expand Down
4 changes: 0 additions & 4 deletions extracao/aero/icao.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
COLS_COM = ["Frequency", "CoordLat", "CoordLong", "DOC", "Location", "NS", "WE"]
UNIQUE_COLS = ["Frequency", "Latitude", "Longitude"]


# %% ../../nbs/06_icao.ipynb 6
def convert_latitude(
lat: str, # Latitude
Expand All @@ -42,7 +41,6 @@ def convert_longitude(
float(lon[1:3]) + float(lon[4:6]) / 60 + float(lon[7:9]) / 3600.0
)


# %% ../../nbs/06_icao.ipynb 8
def _read_df(
path: str, # Caminho do arquivo
Expand All @@ -61,7 +59,6 @@ def _read_df(
df["Description"] = "[ICAO] " + df.Facility + ", " + df.Location
return df[["Frequency", "Latitude", "Longitude", "Description"]]


# %% ../../nbs/06_icao.ipynb 9
def map_channels(
df: pd.DataFrame, # DataFrame dos dados de origem
Expand Down Expand Up @@ -89,7 +86,6 @@ def map_channels(
df.loc[len(df)] = [c, row.Latitude, row.Longitude, description]
return df


# %% ../../nbs/06_icao.ipynb 10
def get_icao() -> (
pd.DataFrame
Expand Down
1 change: 0 additions & 1 deletion extracao/aero/redemet.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
URL = "https://api-redemet.decea.mil.br/produtos/radar/maxcappi?api_key={}&{}"
UNIQUE_COLS = ["Frequency", "Latitude", "Longitude"]


# %% ../../nbs/09_redemet.ipynb 6
def get_redemet() -> (
pd.DataFrame
Expand Down
2 changes: 1 addition & 1 deletion extracao/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'BW_pattern', 'REGEX_ESTADOS', 'MIN_LAT', 'MAX_LAT', 'MIN_LONG', 'MAX_LONG']

# %% ../nbs/01_constants.ipynb 2
import re
import re

# %% ../nbs/01_constants.ipynb 4
TIMEOUT = 5
Expand Down
50 changes: 30 additions & 20 deletions extracao/format.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/03_format.ipynb.

# %% auto 0
__all__ = ['RE_BW', 'MAX_DIST', 'LIMIT_FREQ', 'parse_bw', 'get_km_distance', 'merge_on_frequency']
__all__ = [
"RE_BW",
"MAX_DIST",
"LIMIT_FREQ",
"parse_bw",
"get_km_distance",
"merge_on_frequency",
]

# %% ../nbs/03_format.ipynb 2
import re
Expand Down Expand Up @@ -70,12 +77,12 @@ def _filter_matlab(
"Município_IBGE",
"UF",
]
df.loc[:, cols_desc].fillna("NI", inplace=True)
df.loc[:, cols_desc] = df.loc[:, cols_desc].fillna("NI")

df["Descrição"] = (
"["
+ df.Fonte
+ "] "
+ "] "rsilva
+ df.Status
+ ", "
+ df.Classe
Expand Down Expand Up @@ -110,25 +117,28 @@ def _format_matlab(
) -> pd.DataFrame: # Arquivo de Dados formatado para leitura no Matlab
"""Formata o arquivo final de dados para o formato esperado pela aplicação em Matlab"""
df = df.astype("string")
# df.loc[len(df), :] = [
# "-1",
# "-15.7801",
# "-47.9292",
# "[TEMP] L, FX, Estação do SMP licenciada (cadastro temporário)",
# "10",
# "999999999",
# "NI",
# "-1",
# ] # Paliativo...
df.loc[len(df), :] = [
"-1",
"-15.7801",
"-47.9292",
"[TEMP] L, FX, Estação do SMP licenciada (cadastro temporário)",
"10",
"999999999",
"NI",
"-1",
] # Paliativo...
for c in df.columns:
if c not in ["Description", "Class"]:
df[c] = pd.to_numeric(df[c], errors="coerce")
for c in ["Latitude", "Longitude"]:
df[c] = df[c].fillna("-1").astype("float32")
df[c] = df[c].fillna(-1).astype("float32")
df["Frequency"] = df["Frequency"].astype("float64")
df.loc[df.Service.isin(["", "-1"]), "Service"] = pd.NA
df["Service"] = df.Service.fillna("-1").astype("int16")
df.loc[df.Station.isin(["", "-1"]), "Station"] = pd.NA
df["Station"] = df.Station.fillna("-1").astype("int32")
df.loc[df.BW.isin(["", "-1"]), "BW"] = pd.NA
df["BW"] = df["BW"].astype("float32").fillna(-1)
# df.loc[df.Service.isin(["", "-1"]), "Service"] = pd.NA
df["Service"] = df.Service.fillna(-1).astype("int16")
# df.loc[df.Station.isin(["", "-1"]), "Station"] = pd.NA
df["Station"] = df.Station.fillna(-1).astype("int32")
# df.loc[df.BW.isin(["", "-1"]), "BW"] = pd.NA
df["BW"] = df["BW"].fillna(-1).astype("float32")
df.loc[df["Class"].isin(["", "-1"]), "Class"] = pd.NA
df["Class"] = df.Class.fillna("NI").astype("category")
df = df[df.Frequency <= LIMIT_FREQ]
Expand Down
6 changes: 4 additions & 2 deletions extracao/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

load_dotenv(find_dotenv(), override=True)


# %% ../nbs/05_main.ipynb 3
def get_db(
path: Union[str, Path], # Pasta onde salvar os arquivos",
Expand All @@ -39,7 +38,10 @@ def get_db(
mod_times = {"ANATEL": datetime.now().strftime("%d/%m/%Y %H:%M:%S")}
print(":airplane:[blue]Requisitando os dados da Aeronáutica.")
update = all([connSQL, clientMongoDB])
aero = read_aero(path, update=update)
try:
aero = read_aero(path, update=update)
except Exception:
aero = read_aero(path)
mod_times["AERONAUTICA"] = datetime.now().strftime("%d/%m/%Y %H:%M:%S")
print(":spoon:[yellow]Mesclando os dados da Aeronáutica.")
df = _format_matlab(merge_on_frequency(df, aero))
Expand Down
10 changes: 0 additions & 10 deletions extracao/reading.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

load_dotenv(find_dotenv())


# %% ../nbs/04_reading.ipynb 4
def read_srd(
folder: Union[str, Path], # Pasta onde ler/salvar os dados
Expand All @@ -39,7 +38,6 @@ def read_srd(
"""Lê o banco de dados salvo localmente do MOSAICO e opcionalmente o atualiza."""
return update_srd(conn, folder) if conn else _read_df(folder, "srd")


# %% ../nbs/04_reading.ipynb 10
def read_telecom(
folder: Union[str, Path], # Pasta onde ler/salvar os dados
Expand All @@ -48,7 +46,6 @@ def read_telecom(
"""Lê o banco de dados salvo localmente do LICENCIAMENTO e opcionalmente o atualiza."""
return update_telecom(conn, folder) if conn else _read_df(folder, "telecom")


# %% ../nbs/04_reading.ipynb 14
def read_radcom(
folder: Union[str, Path], # Pasta onde ler/salvar os dados
Expand All @@ -57,7 +54,6 @@ def read_radcom(
"""Lê o banco de dados salvo localmente de RADCOM. Opcionalmente o atualiza pelo Banco de Dados ANATELBDRO05 caso `update = True` ou não exista o arquivo local"""
return update_radcom(conn, folder) if conn else _read_df(folder, "radcom")


# %% ../nbs/04_reading.ipynb 18
def read_stel(
folder: Union[str, Path], # Pasta onde ler/salvar os dados
Expand All @@ -68,7 +64,6 @@ def read_stel(
caso `update = True` ou não exista o arquivo local"""
return update_stel(conn, folder) if conn else _read_df(folder, "stel")


# %% ../nbs/04_reading.ipynb 22
def read_icao(
folder: Union[str, Path], # Pasta onde ler/salvar os dados
Expand All @@ -77,7 +72,6 @@ def read_icao(
"""Lê a base de dados do Frequency Finder e Canalização VOR/ILS/DME"""
return get_icao if update else _read_df(folder, "icao")


# %% ../nbs/04_reading.ipynb 23
def read_aisw(
folder: Union[str, Path], # Pasta onde ler/salvar os dados
Expand All @@ -86,7 +80,6 @@ def read_aisw(
"""Fontes da informação: AISWEB, REDEMET, Ofício nº 2/SSARP/14410 e Canalização VOR/ILS/DME."""
return get_aisw() if update else _read_df(folder, "aisw")


# %% ../nbs/04_reading.ipynb 24
def read_aisg(
folder: Union[str, Path], # Pasta onde ler/salvar os dados
Expand All @@ -95,7 +88,6 @@ def read_aisg(
"""Fontes da informação: GEOAISWEB, REDEMET, Ofício nº 2/SSARP/14410 e Canalização VOR/ILS/DME."""
return get_aisg() if update else _read_df(folder, "aisg")


# %% ../nbs/04_reading.ipynb 25
def read_redemet(
folder: Union[str, Path], # Pasta onde ler/salvar os dados
Expand All @@ -104,7 +96,6 @@ def read_redemet(
"""Fontes da informação: AISWEB, REDEMET, Ofício nº 2/SSARP/14410 e Canalização VOR/ILS/DME."""
return get_redemet() if update else _read_df(folder, "redemet")


# %% ../nbs/04_reading.ipynb 26
def read_aero(
folder: Union[str, Path], # Pasta onde ler/salvar os dados
Expand All @@ -115,7 +106,6 @@ def read_aero(
"""Lê os arquivos de dados da aeronáutica e retorna os registros comuns e únicos"""
return update_aero(folder) if update else _read_df(folder, "aero")


# %% ../nbs/04_reading.ipynb 30
def read_base(
folder: Union[str, Path],
Expand Down
Loading

0 comments on commit fa06b0d

Please sign in to comment.