Spaces:
Configuration error
Configuration error
import streamlit as st | |
import pandas as pd | |
import hashlib | |
from sqlalchemy import create_engine | |
from Data import credentials | |
from streamlit_option_menu import option_menu | |
import os | |
from apps import Covid19, Scoring, Comentarios, Tasas, analisis_inmob,\ | |
Comandos_utiles, simulacion_vc, Mails_Analistas, Panel_de_control,\ | |
Mom_industrias, admin_portal, Clustering, companies | |
class MultiApp: | |
"""Framework for combining multiple streamlit applications. | |
Usage: | |
def foo(): | |
st.title("Hello Foo") | |
def bar(): | |
st.title("Hello Bar") | |
app = MultiApp() | |
app.add_app("Foo", foo) | |
app.add_app("Bar", bar) | |
app.run() | |
It is also possible keep each application in a separate file. | |
import foo | |
import bar | |
app = MultiApp() | |
app.add_app("Foo", foo.app) | |
app.add_app("Bar", bar.app) | |
app.run() | |
""" | |
def __init__(self): | |
self.apps = [] | |
def add_app(self, title, func): | |
"""Adds a new application. | |
Parameters | |
---------- | |
func: | |
the python function to render this app. | |
title: | |
title of the app. Appears in the dropdown in the sidebar. | |
""" | |
self.apps.append({ | |
"title": title, | |
"function": func | |
}) | |
def run(self): | |
if len(self.apps) > 1: | |
app = st.selectbox( | |
'', | |
self.apps, | |
format_func=lambda app: app['title']) | |
st.session_state['Subvista'] = app['title'] | |
app['function']() | |
else: | |
self.apps[0]['function']() | |
class Auth: | |
''' | |
Clase generada para el proceso de autenticación | |
esta clase permite el acceso a las distintas vistas del portal a través de | |
la contraseña y el usuario | |
''' | |
def __init__(self): | |
self.user = "" | |
self.password = "" | |
self.state = "" | |
self.cargo = "" | |
self.mail = "" | |
def log_in(self, user, password): | |
url = credentials.credentials_postgresql["POSTGRESQL"] | |
engine = create_engine(url, echo=False) | |
credenciales = pd.read_sql_query("""select * from credenciales""", | |
con=engine) | |
credenciales.columns = ['Usuario', 'Password', 'Area', 'Cargo', | |
'Mail', 'Nombre'] | |
credenciales = credenciales[credenciales["Usuario"] == user] | |
if len(credenciales) > 0: | |
password_enc = hashlib.sha256(password.encode()).hexdigest() | |
passw = credenciales.iloc[0]["Password"] | |
if password_enc == passw: | |
self.area = credenciales.iloc[0]["Area"] | |
self.user = credenciales.iloc[0]["Usuario"] | |
self.mail = credenciales.iloc[0]["Mail"] | |
self.cargo = credenciales.iloc[0]["Cargo"] | |
self.state = password_enc == passw | |
elif password == "": | |
self.state="" | |
else: | |
self.state = False | |
class ViewPortal: | |
''' | |
Esta clase permite asignar vistas a las distintas areas de LV las vistas | |
distintas vistas desarrolladas y asginar distinas funciones a las vistas | |
correspondientes | |
Para añadir una vista se debe agregar una nueva key en dict_app con el | |
nombre respectivo a esa vista | |
Para agregar una subvista, se debe añadir en el value de la key | |
correspondiente a la vista a la cual se quiere asignar | |
''' | |
def __init__(self): | |
self.user = "" | |
self.area = "" | |
self.mail= "" | |
dict_area = {"Data Science": ["Home"] + | |
sorted(["Análisis Inmobiliario", | |
"Notas Analistas", | |
"Covid-19", "Macro", | |
"Scoring", | |
"Noticias Equity LATAM", | |
"LarrAI", | |
"Comandos Utiles", | |
"Panel de Control", | |
"Momentum de Industrias", | |
"Admin Portal", | |
"Clustering", | |
"Index Constructor"]), | |
"Equity Latam": ["Home"] + | |
sorted(["Macro", | |
"Noticias Equity LATAM", | |
"Notas Analistas", | |
"Scoring", | |
"Momentum de Industrias", | |
"Clustering", | |
"Index Constructor"]), | |
"Inmobiliario": ["Análisis Inmobiliario"], | |
"Proyectos": ["LarrAI", "Análisis Inmobiliario"], | |
"Covid": ["Covid-19"], | |
"Directorio": ["Home"] + sorted(["Momentum de Industrias", | |
"Clustering", | |
"Notas Analistas", | |
"Covid-19", | |
"Macro", | |
"Scoring"]) | |
} | |
dict_app = { | |
"Análisis Inmobiliario": { | |
"Análisis General": | |
analisis_inmob.run_scrapping, | |
"Análisis Focalizado": | |
analisis_inmob.scraping_localizado | |
}, | |
"Notas Analistas": { | |
"Ver Notas": Comentarios.ver_nota, | |
"Estadisticas": Comentarios.estadisticas, | |
}, | |
"Admin Equity LATAM": { | |
"Asignar analistas a empresas": | |
Comentarios.asignar_analista, | |
'Claves': | |
Comentarios.save_password | |
}, | |
"Covid-19": { | |
"Movilidad": Covid19.Movilidad, | |
"Correlacion_GT": Covid19.Correlacion_GT, | |
"Vacunacion": Covid19.vacunas | |
}, | |
"Macro": { | |
"View Macro": Tasas.view_macro, | |
"Tasas": Tasas.bonos, | |
"Pendiente": Tasas.tasa10y_2y, | |
"Commodities": Tasas.Commodities, | |
"Indices": Tasas.Indices, | |
"Divisas": Tasas.Divisas, | |
"Curva Yield": Tasas.curva_yield | |
}, | |
"Scoring": { | |
"General": Scoring.general, | |
"Diagrama": Scoring.diagrama | |
}, | |
"LarrAI": { | |
"Explorar data": | |
simulacion_vc.explorar_data, | |
"Prototipo simulación": | |
simulacion_vc.prototipo_simulacion, | |
"Simulación volatilidad en 3 periodos": | |
simulacion_vc.sim_norm, | |
"Simulacion volatilidad dinamica": | |
simulacion_vc.sim_2, | |
"Simulacion proyectos inmobiliarios": | |
simulacion_vc.sim_inmob, | |
"Simulacion ingreso clientes": | |
simulacion_vc.sim_ingreso_clientes, | |
"Candidatos": | |
simulacion_vc.candidatos | |
}, | |
"Noticias Equity LATAM": { | |
"Escribir mail": | |
Mails_Analistas.escribir_mails2, | |
"Ver mails": | |
Mails_Analistas.ver_mails | |
}, | |
"Comandos Utiles": { | |
"Comandos Utiles": Comandos_utiles.comandos_utiles | |
}, | |
"Panel de Control": { | |
"Panel de Control": Panel_de_control.panel_de_control | |
}, | |
"Momentum de Industrias": { | |
"Medias Móviles": Mom_industrias.medias_moviles, | |
"StN": Mom_industrias.signal_to_noise, | |
"Difusión": Mom_industrias.difusion | |
}, | |
"Admin Portal": { | |
"Admin Portal": admin_portal.logs_portal, | |
"Editar credenciales": admin_portal.edit_credentials | |
}, | |
"Clustering": { | |
"Correlaciones": Clustering.clustering_basado_en_correlacion, | |
"DTW": Clustering.clustering_con_dtw | |
}, | |
"Index Constructor":{ | |
"Index Constructor": companies.index_constructor | |
} | |
} | |
self.dict_apps = dict_app | |
self.dict_area = dict_area | |
def set_user(self, user, area, mail, cargo): | |
self.user = user | |
self.area = area | |
self.mail = mail | |
self.cargo = cargo | |
def set_app(self, dict_apps): | |
self.dict_apps = dict_apps | |
def set_area(self, dict_area): | |
self.dict_area = dict_area | |
def run_views(self): | |
''' | |
Con la función run_views se corren las vistas asginadas al | |
usuario respectivo, generando las vistas en la sidebar y las subivistas | |
''' | |
app = MultiApp() | |
menu = self.dict_area[self.area] | |
if self.user == "alehmann": | |
menu.append("Análisis Inmobiliario") | |
if self.cargo == "PM" or self.user == 'bull': | |
menu.insert(1, "Admin Equity LATAM",) | |
with st.sidebar: | |
rad = option_menu("Navegación",menu, | |
menu_icon="app-indicator", | |
default_index=0, styles={ | |
"container": {"margin": "0px", | |
"background-color": "#fafafa"}, | |
"icon": { "font-size": "10px"}, | |
"nav-link": {"font-size": "15px", | |
"text-align": "left", | |
"margin":"0px", | |
"--hover-color": "#eee"}, | |
} | |
) | |
# rad = st.sidebar.radio("", menu) | |
if rad == "Home": | |
col1, col2 = st.columns((7, 2)) | |
col1.subheader("Hola " + self.user + ",") | |
col1.title("Bienvenido al Portal LVAM") | |
for name in self.dict_area[self.area]: | |
if rad == name and rad != "Home": | |
st.session_state['Funcion'] = name | |
col1, col2 = st.columns((7, 2)) | |
col1.markdown(""" | |
# {Name} | |
""".format(Name=name)) | |
if rad == "Notas Analistas" and self.cargo == "Investment Analyst": | |
app.add_app("Ingresar nota", Comentarios.ingresar_nota) | |
for aplicacion in list(self.dict_apps[name].keys()): | |
dic = self.dict_apps[name] | |
app.add_app(aplicacion, dic[aplicacion]) | |
# st.write('Para dejar tu feedback accede al siguiente [formulario](https://forms.office.com/Pages/ResponsePage.aspx?id=mpR0wfr-_kmELD83ivOlRhEm1JCbNapEi4UG-t7FamlUM0VNTUU4TFpXNzBQTFM2NEo4RzhWVFk3Si4u)') | |
app.run() | |
# col2.image("img/logoDSTD.png") | |