Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/InovaFiscaliza/rfdatahub int…
Browse files Browse the repository at this point in the history
…o dev
  • Loading branch information
ronaldokun committed Feb 20, 2024
2 parents 59f8d63 + f0e8450 commit 91061ae
Show file tree
Hide file tree
Showing 4 changed files with 17,420 additions and 74 deletions.
2 changes: 1 addition & 1 deletion extracao/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
# %% ../nbs/00_constants.ipynb 4
TIMEOUT = 5
RELATORIO_SRD = (
'http://sistemas.anatel.gov.br/se/eApp/reports/b/srd/resumo_sistema.php?id={id}&state={state}'
'http://sistemas.anatel.gov.br/se/eApp/reports/b/srd/resumo_sistema.php?id={}&state={}'
)
ESTACAO = 'http://sistemas.anatel.gov.br/se/public/view/b/srd.php?wfid=estacoes&id={}'
MALHA_IBGE = 'https://geoftp.ibge.gov.br/organizacao_do_territorio/malhas_territoriais/malhas_municipais/municipio_2022/Brasil/BR/BR_Municipios_2022.zip'
Expand Down
7 changes: 4 additions & 3 deletions extracao/datasources/mosaico.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ def _extract(self, collection: str, pipeline: list):
client = self.connect()
database = client[self.database]
db_collection = database[collection]
df = pd.DataFrame(list(db_collection.aggregate(pipeline)), copy=False, dtype='string')
df = pd.DataFrame(list(db_collection.aggregate(pipeline)), copy=False).astype(
'string', copy=False
)
# Substitui strings vazias e somente com espaços por nulo
return df.replace(r'^\s*|\[\]', pd.NA, regex=True)
return df.replace(r'^\s*$|^\[\]$', pd.NA, regex=True)

def split_designacao(
self,
Expand All @@ -58,7 +60,6 @@ def split_designacao(
"""Parse a bandwidth string
It returns the numerical component and a character class
"""
df['Designação_Emissão'] = df['Designação_Emissão'].astype('string', copy=False)
df['Designação_Emissão'] = (
df['Designação_Emissão'].str.replace(',', ' ').str.strip().str.upper().str.split(' ')
)
Expand Down
5 changes: 2 additions & 3 deletions extracao/datasources/srd.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def _format(
df['Validade_RF'] = df.Validade_RF.astype('string', copy=False).str.slice(0, 10)
df['Fonte'] = 'MOSAICO-SRD'
df['Serviço'] = df['Serviço'].fillna('')
df['Designação_Emissão'] = df.Serviço.astype('string', copy=False).fillna('').map(BW_MAP)
df['Designação_Emissão'] = df.Serviço.map(BW_MAP)
df = self.split_designacao(df)
df['Multiplicidade'] = 1
df['Padrão_Antena(dBd)'] = df['Padrão_Antena(dBd)'].str.replace('None', '0')
Expand All @@ -104,9 +104,8 @@ def _format(
.apply(lambda x: float(Decimal(1000) * Decimal(x)))
.astype('float')
).fillna(-1.0)
df.loc[:, ['Id', 'Status']] = df.loc[:, ['Id', 'Status']].astype('string', copy=False)
df['Relatório_Canal'] = df.apply(
lambda row: RELATORIO_SRD.format(row['Id'], row['Status']), axis=1
lambda row: RELATORIO_SRD.format(row.loc['Id'], row.loc['Status']), axis=1
)
# self.append2discarded([self.discarded, discarded, discarded_with_na])
return df.loc[:, self.columns]
Loading

0 comments on commit 91061ae

Please sign in to comment.