-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moving risk_data function to a new file and moving Escribir_Datos_Osi…
…ris to a new file to avoid circular import between risk_data file and subida.py
- Loading branch information
Showing
4 changed files
with
103 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import pandas as pd | ||
from .constants.constants import NUMBER_OF_COLUMNS | ||
from .write_data_osiris import Escribir_Datos_Osiris | ||
|
||
|
||
def get_phone_risk(df_risk: pd.DataFrame) -> pd.DataFrame: | ||
frames = list() | ||
num_tel = len([col_name for col_name in list(df_risk.columns) if 'tel_riesgo' in col_name]) | ||
for i in range(1, num_tel + 1): | ||
col_riesgo = f'tel_riesgo_{i}' | ||
df = df_risk.loc[df_risk[col_riesgo].notnull(), ['Cuenta', col_riesgo]]\ | ||
.rename(columns={col_riesgo: 'TEL'}).copy() | ||
df['OBS'] = f'RIESGO {i}' | ||
df['ID_FONO'] = '8' | ||
frames.append(df) | ||
df_phone_risk = pd.concat(frames) | ||
return df_phone_risk | ||
|
||
|
||
def read_osiris_accounts() -> pd.DataFrame: | ||
try: | ||
uploaded_accounts = pd.read_csv('cuentas.csv', encoding='latin_1', sep=';', dtype=str) | ||
except Exception: | ||
uploaded_accounts = pd.read_csv('cuentas.csv', encoding='ANSI', sep=';', dtype=str) | ||
uploaded_accounts = uploaded_accounts[['Cuenta', 'Mat. Unica']].rename( | ||
columns={ | ||
'Mat. Unica': 'DNI' | ||
}, | ||
inplace=False | ||
) | ||
return uploaded_accounts | ||
|
||
|
||
def risk_data(): | ||
'NECESARIOS: tener el archivos.csv de riesgo y el archivo de las cuentas de osiris como cuentas.csv' | ||
col_numbers = { | ||
'Número.1': 'tel_riesgo_1', | ||
'Número.2': 'tel_riesgo_2', | ||
'Número.3': 'tel_riesgo_3', | ||
'Número.4': 'tel_riesgo_4' | ||
} | ||
|
||
col_list = [x for x in range(NUMBER_OF_COLUMNS)] | ||
try: | ||
risk = pd.read_csv('riesgo.csv', sep=';', encoding='latin_1', dtype=str, index_col=False, usecols=col_list) | ||
except Exception: | ||
risk = pd.read_csv('riesgo.csv', sep=';', encoding='ANSI', dtype=str, index_col=False, usecols=col_list) | ||
df_risk = risk[['DNI'] + list(col_numbers.keys()) + ['NSE']] | ||
|
||
df_risk = df_risk.rename(columns=col_numbers, inplace=False) | ||
|
||
uploaded_accounts = read_osiris_accounts() | ||
|
||
df_risk = pd.merge(uploaded_accounts, df_risk, how="inner", on="DNI") | ||
|
||
df_phone_risk = get_phone_risk(df_risk=df_risk) | ||
|
||
Escribir_Datos_Osiris( | ||
df_phone_risk, | ||
'RIESGO_telefonos.csv', | ||
['Cuenta', 'ID_FONO', 'TEL', 'OBS'], | ||
["ID Cuenta o Nro. de Asig. (0)", "ID Tipo de Teléfono (17)", "Nro. de Teléfono (18)", "Obs. de Teléfono (19)"] | ||
) | ||
print('Planilla de Teléfonos de RIESGO escrita') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
|
||
import pandas as pd | ||
import time | ||
from .constants.constants import DATA_UPLOADER_HEADER | ||
|
||
|
||
def Escribir_Datos_Osiris(df, filename, cols_df, cols_osiris): | ||
|
||
Control_Carpeta_Subida() | ||
|
||
df_subida = pd.DataFrame(columns=DATA_UPLOADER_HEADER) | ||
df_subida[cols_osiris] = df[cols_df] | ||
try: | ||
df_subida.to_csv( | ||
f'Subida Osiris/{time.strftime("(%H.%M hs) -")} {filename}', | ||
sep=';', | ||
index=False, | ||
encoding='latin_1' | ||
) | ||
except Exception: | ||
df_subida.to_csv( | ||
f'Subida Osiris/{time.strftime("(%H.%M hs) -")} {filename}', | ||
sep=';', | ||
index=False, | ||
encoding='ANSI' | ||
) | ||
|
||
|
||
def Control_Carpeta_Subida(): | ||
'COntrola que exista una carpeta llamada Subida Osiris y sino la crea' | ||
pass | ||
# no la estoy usando |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters