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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
from multiapp import ViewPortal, Auth
|
3 |
+
import pandas as pd
|
4 |
+
from sqlalchemy import create_engine
|
5 |
+
from Data import credentials
|
6 |
+
import streamlit as st
|
7 |
+
from streamlit_multipage import MultiPage
|
8 |
+
import extra_streamlit_components as stx
|
9 |
+
import datetime
|
10 |
+
|
11 |
+
def button_style():
|
12 |
+
style_button = """
|
13 |
+
<style>
|
14 |
+
.button {
|
15 |
+
display: inline-block;
|
16 |
+
background-color: #e8e8e8;
|
17 |
+
border-radius: 20px;
|
18 |
+
border: 4px #cccccc;
|
19 |
+
color: #4a4a4a;
|
20 |
+
text-align: center;
|
21 |
+
font-size: 12px;
|
22 |
+
padding: 2px;
|
23 |
+
width: 550px;
|
24 |
+
height:70px;
|
25 |
+
transition: all 0.5s;
|
26 |
+
cursor: pointer;
|
27 |
+
margin: 5px;
|
28 |
+
}
|
29 |
+
.button span {
|
30 |
+
cursor: pointer;
|
31 |
+
display: inline-block;
|
32 |
+
position: relative;
|
33 |
+
transition: 0.5s;
|
34 |
+
}
|
35 |
+
.button span:after {
|
36 |
+
content: '\00bb';
|
37 |
+
position: absolute;
|
38 |
+
opacity: 0;
|
39 |
+
top: 0;
|
40 |
+
right: -20px;
|
41 |
+
transition: 0.5s;
|
42 |
+
}
|
43 |
+
.button:hover {
|
44 |
+
background-color: #bb1114;
|
45 |
+
color:white;
|
46 |
+
}
|
47 |
+
button:hover span {
|
48 |
+
padding-right: 25px;
|
49 |
+
}
|
50 |
+
button:hover span:after {
|
51 |
+
opacity: 1;
|
52 |
+
right: 0;
|
53 |
+
}
|
54 |
+
.stMarkdown{
|
55 |
+
margin-bottom:0px;}
|
56 |
+
</style>
|
57 |
+
"""
|
58 |
+
st.markdown(style_button, unsafe_allow_html=True)
|
59 |
+
|
60 |
+
|
61 |
+
def style_title():
|
62 |
+
style = """
|
63 |
+
<style>
|
64 |
+
h1, h3{
|
65 |
+
color: "white";
|
66 |
+
font-family: Optima, sans-serif;
|
67 |
+
}
|
68 |
+
h1{
|
69 |
+
font-size:40px;
|
70 |
+
}
|
71 |
+
.st-ae {
|
72 |
+
font-family: Optima, sans-serif;
|
73 |
+
}
|
74 |
+
*
|
75 |
+
{
|
76 |
+
font-family: Optima, sans-serif;
|
77 |
+
}
|
78 |
+
.css-1y0tadsbody
|
79 |
+
{
|
80 |
+
padding:40px;
|
81 |
+
}
|
82 |
+
</style>
|
83 |
+
"""
|
84 |
+
st.markdown(style, unsafe_allow_html=True)
|
85 |
+
|
86 |
+
def get_user():
|
87 |
+
user = st.session_state.key
|
88 |
+
return user
|
89 |
+
|
90 |
+
def get_password():
|
91 |
+
password = st.session_state['pass']
|
92 |
+
return password
|
93 |
+
|
94 |
+
# @st.experimental_memo
|
95 |
+
def get_session_state():
|
96 |
+
return st.session_state
|
97 |
+
|
98 |
+
|
99 |
+
@st.experimental_memo
|
100 |
+
def read_cred():
|
101 |
+
url = credentials.credentials_postgresql["POSTGRESQL"]
|
102 |
+
engine = create_engine(url, echo=False)
|
103 |
+
credenciales = pd.read_sql_query("""select * from credenciales""",
|
104 |
+
con=engine)
|
105 |
+
credenciales.columns = ['Usuario', 'Password', 'Area', 'Cargo',
|
106 |
+
'Mail', 'Nombre']
|
107 |
+
engine.dispose()
|
108 |
+
return credenciales
|
109 |
+
|
110 |
+
|
111 |
+
def input_page(st, **state):
|
112 |
+
MultiPage.save({"user": "", "passw": ""})
|
113 |
+
user = st.sidebar.text_input('User', key="1")
|
114 |
+
passw = st.sidebar.text_input('Password', key="2")
|
115 |
+
if user and passw:
|
116 |
+
MultiPage.save({"user": user, "passw": passw})
|
117 |
+
|
118 |
+
|
119 |
+
|
120 |
+
|
121 |
+
|
122 |
+
def login_cookies(cookie_manager):
|
123 |
+
c1, c2, c3 = st.columns(3)
|
124 |
+
with c2:
|
125 |
+
user = st.text_input("User")
|
126 |
+
passw = st.text_input("Password")
|
127 |
+
if st.button("Login"):
|
128 |
+
cookie_manager.set("user", user, key="user", expires_at=datetime.datetime(year=2023, month=2, day=2))
|
129 |
+
cookie_manager.set("passw", passw, key="password", expires_at=datetime.datetime(year=2023, month=2, day=2))
|
130 |
+
return user, passw
|
131 |
+
|
132 |
+
|
133 |
+
def compute_page():
|
134 |
+
def get_manager():
|
135 |
+
return stx.CookieManager()
|
136 |
+
cookie_manager = get_manager()
|
137 |
+
cookies = cookie_manager.get_all()
|
138 |
+
st.write(cookies)
|
139 |
+
credenciales = read_cred()
|
140 |
+
|
141 |
+
|
142 |
+
try:
|
143 |
+
user = cookies["user"]
|
144 |
+
password = cookies["passw"]
|
145 |
+
mail = st.session_state['mail']
|
146 |
+
cargo = st.session_state['cargo']
|
147 |
+
password = st.session_state['pass']
|
148 |
+
area = st.session_state['area']
|
149 |
+
name = st.session_state["name"]
|
150 |
+
# st.write(get_session_state())
|
151 |
+
Portal = ViewPortal()
|
152 |
+
Portal.set_user(user, area, mail, cargo)
|
153 |
+
Portal.run_views()
|
154 |
+
except Exception as exc:
|
155 |
+
|
156 |
+
try:
|
157 |
+
auth = Auth()
|
158 |
+
user = cookies["user"]
|
159 |
+
password = cookies["passw"]
|
160 |
+
auth.log_in(user, password)
|
161 |
+
if auth.state:
|
162 |
+
user = auth.user
|
163 |
+
st.session_state.key = user
|
164 |
+
name = credenciales[credenciales["Usuario"]==user].iloc[0]["Nombre"]
|
165 |
+
st.session_state["name"] = name
|
166 |
+
area = auth.area
|
167 |
+
mail = auth.mail
|
168 |
+
cargo = auth.cargo
|
169 |
+
st.session_state['mail'] = mail
|
170 |
+
st.session_state['cargo'] = cargo
|
171 |
+
st.session_state['pass'] = password
|
172 |
+
st.session_state['area'] = area
|
173 |
+
Portal = ViewPortal()
|
174 |
+
Portal.set_user(user, area, mail, cargo)
|
175 |
+
Portal.run_views()
|
176 |
+
except:
|
177 |
+
auth = Auth()
|
178 |
+
if auth.state == "":
|
179 |
+
user, passw = login_cookies(cookie_manager)
|
180 |
+
auth.log_in(user, passw)
|
181 |
+
if auth.state:
|
182 |
+
user = auth.user
|
183 |
+
st.session_state.key = user
|
184 |
+
name = credenciales[credenciales["Usuario"] == user].iloc[0]["Nombre"]
|
185 |
+
st.session_state["name"] = name
|
186 |
+
area = auth.area
|
187 |
+
mail = auth.mail
|
188 |
+
cargo = auth.cargo
|
189 |
+
st.session_state['mail'] = mail
|
190 |
+
st.session_state['cargo'] = cargo
|
191 |
+
st.session_state['pass'] = passw
|
192 |
+
st.session_state['area'] = area
|
193 |
+
Portal = ViewPortal()
|
194 |
+
Portal.set_user(user, area, mail, cargo)
|
195 |
+
Portal.run_views()
|
196 |
+
else:
|
197 |
+
st.sidebar.error("Clave incorrecta")
|
198 |
+
|
199 |
+
|
200 |
+
def set_page_container_style(
|
201 |
+
max_width: int = 1100, max_width_100_percent: bool = False,
|
202 |
+
padding_top: int = 1, padding_right: int = 10, padding_left: int = 1, padding_bottom: int = 10,
|
203 |
+
color: str = 'black', background_color: str = 'white',
|
204 |
+
):
|
205 |
+
if max_width_100_percent:
|
206 |
+
max_width_str = f'max-width: 100%;'
|
207 |
+
else:
|
208 |
+
max_width_str = f'max-width: {max_width}px;'
|
209 |
+
st.markdown(
|
210 |
+
f'''
|
211 |
+
<style>
|
212 |
+
.css-189x3qo {{
|
213 |
+
padding-top: {padding_top}rem;
|
214 |
+
}}
|
215 |
+
.reportview-container .main .block-container {{
|
216 |
+
{max_width_str}
|
217 |
+
padding-top: {padding_top}rem;
|
218 |
+
padding-right: {padding_right}rem;
|
219 |
+
padding-left: {padding_left}rem;
|
220 |
+
padding-bottom: {padding_bottom}rem;
|
221 |
+
}}
|
222 |
+
.reportview-container .main {{
|
223 |
+
color: {color};
|
224 |
+
background-color: {background_color};
|
225 |
+
}}
|
226 |
+
</style>
|
227 |
+
''',
|
228 |
+
unsafe_allow_html=True,
|
229 |
+
)
|
230 |
+
|
231 |
+
if __name__ == '__main__':
|
232 |
+
import streamlit_authenticator as stauth
|
233 |
+
import yaml
|
234 |
+
st.set_page_config(layout="wide", page_title="Portal LVAM",
|
235 |
+
page_icon="img/icono.png")
|
236 |
+
|
237 |
+
hashed_passwords = stauth.Hasher(["hola", "hola"]).generate()
|
238 |
+
|
239 |
+
with open('config.yaml') as file:
|
240 |
+
config = yaml.load(file, Loader=yaml.SafeLoader)
|
241 |
+
authenticator = stauth.Authenticate(
|
242 |
+
config['credentials']['names'],
|
243 |
+
config['credentials']['usernames'],
|
244 |
+
hashed_passwords,
|
245 |
+
config['cookie']['name'],
|
246 |
+
config['cookie']['key'],
|
247 |
+
config['cookie']['expiry_days']
|
248 |
+
)
|
249 |
+
name, authentication_status, username = authenticator.login('Login', 'main')
|
250 |
+
if st.session_state["authentication_status"]:
|
251 |
+
authenticator.logout('Logout', 'main')
|
252 |
+
st.write(f'Welcome *{st.session_state["name"]}*')
|
253 |
+
st.title('Some content')
|
254 |
+
elif st.session_state["authentication_status"] == False:
|
255 |
+
st.error('Username/password is incorrect')
|
256 |
+
elif st.session_state["authentication_status"] == None:
|
257 |
+
st.warning('Please enter your username and password')
|
258 |
+
|
259 |
+
|
260 |
+
|
261 |
+
|
262 |
+
|
263 |
+
# if __name__ == '__main__':
|
264 |
+
# st.set_page_config(layout="wide", page_title="Portal LVAM",
|
265 |
+
# page_icon="img/icono.png")
|
266 |
+
# place_0 = st.empty()
|
267 |
+
# col1, col2 = st.columns((2, 1))
|
268 |
+
# place_image = st.sidebar.empty()
|
269 |
+
# place_form = st.sidebar.empty()
|
270 |
+
|
271 |
+
# form1 = place_form.form("Ingresar")
|
272 |
+
# logged = False
|
273 |
+
# try:
|
274 |
+
# user = st.session_state.key
|
275 |
+
# password = st.session_state['pass']
|
276 |
+
# mail = st.session_state['mail']
|
277 |
+
# cargo = st.session_state['cargo']
|
278 |
+
# password = st.session_state['pass']
|
279 |
+
# area = st.session_state['area']
|
280 |
+
# name = st.session_state["name"]
|
281 |
+
# # st.write(get_session_state())
|
282 |
+
# Portal = ViewPortal()
|
283 |
+
# Portal.set_user(user, area, mail, cargo)
|
284 |
+
# Portal.run_views()
|
285 |
+
# except Exception as exc:
|
286 |
+
# st.write(exc)
|
287 |
+
# url = credentials.credentials_postgresql["POSTGRESQL"]
|
288 |
+
# engine = create_engine(url, echo=False)
|
289 |
+
# credenciales = pd.read_sql_query(
|
290 |
+
# """select * from credenciales""", con=engine)
|
291 |
+
# credenciales.columns = ['Usuario', 'Password',
|
292 |
+
# 'Area', 'Cargo', 'Mail', 'Nombre']
|
293 |
+
# try:
|
294 |
+
# usuario = get_user()
|
295 |
+
# except:
|
296 |
+
# usuario = ""
|
297 |
+
# user = form1.text_input("Enter a username", value=usuario)
|
298 |
+
# password = form1.text_input("Enter a password",
|
299 |
+
# type="password")
|
300 |
+
# submitted = form1.form_submit_button("Ingresar")
|
301 |
+
# auth = Auth()
|
302 |
+
# auth.log_in(user, password)
|
303 |
+
# if auth.state:
|
304 |
+
# user = auth.user
|
305 |
+
# st.session_state.key = user
|
306 |
+
# name = credenciales[credenciales["Usuario"]==user].iloc[0]["Nombre"]
|
307 |
+
# st.session_state["name"] = name
|
308 |
+
# area = auth.area
|
309 |
+
# mail = auth.mail
|
310 |
+
# cargo = auth.cargo
|
311 |
+
# st.session_state['mail'] = mail
|
312 |
+
# st.session_state['cargo'] = cargo
|
313 |
+
# st.session_state['pass'] = password
|
314 |
+
# st.session_state['area'] = area
|
315 |
+
# place_form.empty()
|
316 |
+
# place_image.empty()
|
317 |
+
# Portal = ViewPortal()
|
318 |
+
# Portal.set_user(user, area, mail, cargo)
|
319 |
+
# Portal.run_views()
|
320 |
+
# elif auth.state == "":
|
321 |
+
# st.write("")
|
322 |
+
# else:
|
323 |
+
# st.sidebar.error("Clave incorrecta")
|
config.yaml
CHANGED
@@ -1,3 +1,8 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
credentials:
|
2 |
+
names: ['Benjamin Ull', 'Alejandro Lehmann']
|
3 |
+
usernames: ['bull', 'alehmann']
|
4 |
+
passwords: ['hola', 'hola']
|
5 |
+
cookie:
|
6 |
+
name: 'some_cookie_name'
|
7 |
+
key: 'some_signature_key'
|
8 |
+
expiry_days: 30
|
logs_portal.py
CHANGED
@@ -1,3 +1,75 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
"""
|
3 |
+
Created on Thu Dec 16 16:29:25 2021
|
4 |
+
|
5 |
+
@author: bullm
|
6 |
+
"""
|
7 |
+
import streamlit as st
|
8 |
+
from datetime import datetime
|
9 |
+
from datetime import timedelta
|
10 |
+
import pandas as pd
|
11 |
+
import os
|
12 |
+
import boto3
|
13 |
+
import json
|
14 |
+
import io
|
15 |
+
import xlsxwriter
|
16 |
+
|
17 |
+
|
18 |
+
|
19 |
+
|
20 |
+
def save_s3(key, secret_key, bucket, df, path):
|
21 |
+
with io.BytesIO() as output:
|
22 |
+
with pd.ExcelWriter(output, engine='xlsxwriter') as writer:
|
23 |
+
df.to_excel(writer, 'sheet_name')
|
24 |
+
data = output.getvalue()
|
25 |
+
s3 = boto3.resource('s3', aws_access_key_id = key, aws_secret_access_key= secret_key)
|
26 |
+
s3.Bucket(bucket).put_object(Key=path, Body=data)
|
27 |
+
|
28 |
+
|
29 |
+
|
30 |
+
def read_excel_s3(key, secret_key, bucket, path):
|
31 |
+
s3_client = boto3.client('s3', aws_access_key_id = key, aws_secret_access_key= secret_key)
|
32 |
+
response = s3_client.get_object(Bucket=bucket, Key=path)
|
33 |
+
data = response["Body"].read()
|
34 |
+
df = pd.read_excel(io.BytesIO(data))
|
35 |
+
return df
|
36 |
+
|
37 |
+
|
38 |
+
def log(func):
|
39 |
+
"""
|
40 |
+
Log portal permite almacenar las visitas que tienen tanto
|
41 |
+
las vistas como las subvistas, esta funcion se utiliza como decorador
|
42 |
+
"""
|
43 |
+
def visita_vista(*args, **kwargs):
|
44 |
+
key ='AKIARYMZ4J2YQDB66VX4'
|
45 |
+
secret_key = 'Jr5kvwPBF6XfUBnBOEjGaOirqOAIqo771mXIoRUy'
|
46 |
+
bucket='portallvam'
|
47 |
+
path ='Logs.xlsx'
|
48 |
+
analista = st.session_state.key
|
49 |
+
fecha = datetime.today()
|
50 |
+
data = read_excel_s3(key, secret_key, bucket, 'Logs.xlsx')[['Analista', 'Fecha', 'Vista',
|
51 |
+
'Subvista']]
|
52 |
+
vista = st.session_state['Funcion']
|
53 |
+
subvista = st.session_state['Subvista']
|
54 |
+
last_view = data.iloc[-1]
|
55 |
+
last_analista = last_view["Analista"]
|
56 |
+
last_vista = last_view["Vista"]
|
57 |
+
last_subvista = last_view["Subvista"]
|
58 |
+
last_fecha = last_view["Fecha"]
|
59 |
+
delta_t = fecha - last_fecha
|
60 |
+
if analista == last_analista and vista == last_vista:
|
61 |
+
if last_subvista == subvista and delta_t < timedelta(minutes=10):
|
62 |
+
pass
|
63 |
+
else:
|
64 |
+
data = data.append({"Analista": analista, "Fecha": fecha,
|
65 |
+
"Vista": vista, "Subvista": subvista},
|
66 |
+
ignore_index=True)
|
67 |
+
save_s3(key, secret_key, bucket, data, path)
|
68 |
+
else:
|
69 |
+
data = data.append({"Analista": analista, "Fecha": fecha,
|
70 |
+
"Vista": vista, "Subvista": subvista},
|
71 |
+
ignore_index=True)
|
72 |
+
save_s3(key, secret_key, bucket, data, path)
|
73 |
+
# data.to_excel('Data/Logs.xlsx', engine='openpyxl')
|
74 |
+
func(*args, **kwargs)
|
75 |
+
return visita_vista
|
metodos.py
CHANGED
@@ -1,3 +1,29 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
"""
|
3 |
+
Created on Wed Jul 29 15:28:55 2020
|
4 |
+
|
5 |
+
@author: ASUS
|
6 |
+
"""
|
7 |
+
|
8 |
+
def colores_corporativos(colors=None):
|
9 |
+
|
10 |
+
diccionario = {'red': (204, 0, 51),
|
11 |
+
'light_blue': (110, 162, 201),
|
12 |
+
'gray': (66, 74, 82),
|
13 |
+
'light_green': (122, 178, 153),
|
14 |
+
'yellow': (195, 195, 9),
|
15 |
+
'dark_purple': (119, 28, 95),
|
16 |
+
'blue': (42, 83, 113),
|
17 |
+
'purple': (159, 37, 127),
|
18 |
+
'light_yellow': (252, 252, 196),
|
19 |
+
'green': (55, 95, 77),
|
20 |
+
'light_gray': (135, 146, 158)}
|
21 |
+
|
22 |
+
for key in diccionario:
|
23 |
+
diccionario[key] = tuple(v/255 for v in diccionario[key])
|
24 |
+
|
25 |
+
if colors is None:
|
26 |
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import hashlib
|
4 |
+
from sqlalchemy import create_engine
|
5 |
+
from Data import credentials
|
6 |
+
from streamlit_option_menu import option_menu
|
7 |
+
import os
|
8 |
+
from apps import Covid19, Scoring, Comentarios, Tasas, analisis_inmob,\
|
9 |
+
Comandos_utiles, simulacion_vc, Mails_Analistas, Panel_de_control,\
|
10 |
+
Mom_industrias, admin_portal, Clustering, companies
|
11 |
+
|
12 |
+
class MultiApp:
|
13 |
+
"""Framework for combining multiple streamlit applications.
|
14 |
+
Usage:
|
15 |
+
def foo():
|
16 |
+
st.title("Hello Foo")
|
17 |
+
def bar():
|
18 |
+
st.title("Hello Bar")
|
19 |
+
app = MultiApp()
|
20 |
+
app.add_app("Foo", foo)
|
21 |
+
app.add_app("Bar", bar)
|
22 |
+
app.run()
|
23 |
+
It is also possible keep each application in a separate file.
|
24 |
+
import foo
|
25 |
+
import bar
|
26 |
+
app = MultiApp()
|
27 |
+
app.add_app("Foo", foo.app)
|
28 |
+
app.add_app("Bar", bar.app)
|
29 |
+
app.run()
|
30 |
+
"""
|
31 |
+
|
32 |
+
def __init__(self):
|
33 |
+
self.apps = []
|
34 |
+
|
35 |
+
def add_app(self, title, func):
|
36 |
+
"""Adds a new application.
|
37 |
+
Parameters
|
38 |
+
----------
|
39 |
+
func:
|
40 |
+
the python function to render this app.
|
41 |
+
title:
|
42 |
+
title of the app. Appears in the dropdown in the sidebar.
|
43 |
+
"""
|
44 |
+
self.apps.append({
|
45 |
+
"title": title,
|
46 |
+
"function": func
|
47 |
+
})
|
48 |
+
|
49 |
+
def run(self):
|
50 |
+
if len(self.apps) > 1:
|
51 |
+
app = st.selectbox(
|
52 |
+
'',
|
53 |
+
self.apps,
|
54 |
+
format_func=lambda app: app['title'])
|
55 |
+
st.session_state['Subvista'] = app['title']
|
56 |
+
app['function']()
|
57 |
+
else:
|
58 |
+
self.apps[0]['function']()
|
59 |
+
|
60 |
+
|
61 |
+
class Auth:
|
62 |
+
'''
|
63 |
+
Clase generada para el proceso de autenticación
|
64 |
+
esta clase permite el acceso a las distintas vistas del portal a través de
|
65 |
+
la contraseña y el usuario
|
66 |
+
'''
|
67 |
+
|
68 |
+
def __init__(self):
|
69 |
+
self.user = ""
|
70 |
+
self.password = ""
|
71 |
+
self.state = ""
|
72 |
+
self.cargo = ""
|
73 |
+
self.mail = ""
|
74 |
+
|
75 |
+
def log_in(self, user, password):
|
76 |
+
url = credentials.credentials_postgresql["POSTGRESQL"]
|
77 |
+
engine = create_engine(url, echo=False)
|
78 |
+
credenciales = pd.read_sql_query("""select * from credenciales""",
|
79 |
+
con=engine)
|
80 |
+
credenciales.columns = ['Usuario', 'Password', 'Area', 'Cargo',
|
81 |
+
'Mail', 'Nombre']
|
82 |
+
|
83 |
+
credenciales = credenciales[credenciales["Usuario"] == user]
|
84 |
+
if len(credenciales) > 0:
|
85 |
+
password_enc = hashlib.sha256(password.encode()).hexdigest()
|
86 |
+
passw = credenciales.iloc[0]["Password"]
|
87 |
+
if password_enc == passw:
|
88 |
+
self.area = credenciales.iloc[0]["Area"]
|
89 |
+
self.user = credenciales.iloc[0]["Usuario"]
|
90 |
+
self.mail = credenciales.iloc[0]["Mail"]
|
91 |
+
self.cargo = credenciales.iloc[0]["Cargo"]
|
92 |
+
self.state = password_enc == passw
|
93 |
+
elif password == "":
|
94 |
+
self.state=""
|
95 |
+
else:
|
96 |
+
self.state = False
|
97 |
+
|
98 |
+
|
99 |
+
class ViewPortal:
|
100 |
+
'''
|
101 |
+
Esta clase permite asignar vistas a las distintas areas de LV las vistas
|
102 |
+
distintas vistas desarrolladas y asginar distinas funciones a las vistas
|
103 |
+
correspondientes
|
104 |
+
Para añadir una vista se debe agregar una nueva key en dict_app con el
|
105 |
+
nombre respectivo a esa vista
|
106 |
+
Para agregar una subvista, se debe añadir en el value de la key
|
107 |
+
correspondiente a la vista a la cual se quiere asignar
|
108 |
+
'''
|
109 |
+
|
110 |
+
def __init__(self):
|
111 |
+
self.user = ""
|
112 |
+
self.area = ""
|
113 |
+
self.mail= ""
|
114 |
+
dict_area = {"Data Science": ["Home"] +
|
115 |
+
sorted(["Análisis Inmobiliario",
|
116 |
+
"Notas Analistas",
|
117 |
+
"Covid-19", "Macro",
|
118 |
+
"Scoring",
|
119 |
+
"Noticias Equity LATAM",
|
120 |
+
"LarrAI",
|
121 |
+
"Comandos Utiles",
|
122 |
+
"Panel de Control",
|
123 |
+
"Momentum de Industrias",
|
124 |
+
"Admin Portal",
|
125 |
+
"Clustering",
|
126 |
+
"Index Constructor"]),
|
127 |
+
"Equity Latam": ["Home"] +
|
128 |
+
sorted(["Macro",
|
129 |
+
"Noticias Equity LATAM",
|
130 |
+
"Notas Analistas",
|
131 |
+
"Scoring",
|
132 |
+
"Momentum de Industrias",
|
133 |
+
"Clustering",
|
134 |
+
"Index Constructor"]),
|
135 |
+
"Inmobiliario": ["Análisis Inmobiliario"],
|
136 |
+
"Proyectos": ["LarrAI", "Análisis Inmobiliario"],
|
137 |
+
"Covid": ["Covid-19"],
|
138 |
+
"Directorio": ["Home"] + sorted(["Momentum de Industrias",
|
139 |
+
"Clustering",
|
140 |
+
"Notas Analistas",
|
141 |
+
"Covid-19",
|
142 |
+
"Macro",
|
143 |
+
"Scoring"])
|
144 |
+
}
|
145 |
+
dict_app = {
|
146 |
+
"Análisis Inmobiliario": {
|
147 |
+
"Análisis General":
|
148 |
+
analisis_inmob.run_scrapping,
|
149 |
+
"Análisis Focalizado":
|
150 |
+
analisis_inmob.scraping_localizado
|
151 |
+
},
|
152 |
+
"Notas Analistas": {
|
153 |
+
"Ver Notas": Comentarios.ver_nota,
|
154 |
+
"Estadisticas": Comentarios.estadisticas,
|
155 |
+
},
|
156 |
+
"Admin Equity LATAM": {
|
157 |
+
"Asignar analistas a empresas":
|
158 |
+
Comentarios.asignar_analista,
|
159 |
+
'Claves':
|
160 |
+
Comentarios.save_password
|
161 |
+
},
|
162 |
+
"Covid-19": {
|
163 |
+
"Movilidad": Covid19.Movilidad,
|
164 |
+
"Correlacion_GT": Covid19.Correlacion_GT,
|
165 |
+
"Vacunacion": Covid19.vacunas
|
166 |
+
},
|
167 |
+
"Macro": {
|
168 |
+
"View Macro": Tasas.view_macro,
|
169 |
+
"Tasas": Tasas.bonos,
|
170 |
+
"Pendiente": Tasas.tasa10y_2y,
|
171 |
+
"Commodities": Tasas.Commodities,
|
172 |
+
"Indices": Tasas.Indices,
|
173 |
+
"Divisas": Tasas.Divisas,
|
174 |
+
"Curva Yield": Tasas.curva_yield
|
175 |
+
},
|
176 |
+
"Scoring": {
|
177 |
+
"General": Scoring.general,
|
178 |
+
"Diagrama": Scoring.diagrama
|
179 |
+
},
|
180 |
+
"LarrAI": {
|
181 |
+
"Explorar data":
|
182 |
+
simulacion_vc.explorar_data,
|
183 |
+
"Prototipo simulación":
|
184 |
+
simulacion_vc.prototipo_simulacion,
|
185 |
+
"Simulación volatilidad en 3 periodos":
|
186 |
+
simulacion_vc.sim_norm,
|
187 |
+
"Simulacion volatilidad dinamica":
|
188 |
+
simulacion_vc.sim_2,
|
189 |
+
"Simulacion proyectos inmobiliarios":
|
190 |
+
simulacion_vc.sim_inmob,
|
191 |
+
"Simulacion ingreso clientes":
|
192 |
+
simulacion_vc.sim_ingreso_clientes,
|
193 |
+
"Candidatos":
|
194 |
+
simulacion_vc.candidatos
|
195 |
+
},
|
196 |
+
"Noticias Equity LATAM": {
|
197 |
+
"Escribir mail":
|
198 |
+
Mails_Analistas.escribir_mails2,
|
199 |
+
"Ver mails":
|
200 |
+
Mails_Analistas.ver_mails
|
201 |
+
},
|
202 |
+
"Comandos Utiles": {
|
203 |
+
"Comandos Utiles": Comandos_utiles.comandos_utiles
|
204 |
+
},
|
205 |
+
"Panel de Control": {
|
206 |
+
"Panel de Control": Panel_de_control.panel_de_control
|
207 |
+
},
|
208 |
+
"Momentum de Industrias": {
|
209 |
+
"Medias Móviles": Mom_industrias.medias_moviles,
|
210 |
+
"StN": Mom_industrias.signal_to_noise,
|
211 |
+
"Difusión": Mom_industrias.difusion
|
212 |
+
},
|
213 |
+
"Admin Portal": {
|
214 |
+
"Admin Portal": admin_portal.logs_portal,
|
215 |
+
"Editar credenciales": admin_portal.edit_credentials
|
216 |
+
},
|
217 |
+
"Clustering": {
|
218 |
+
"Correlaciones": Clustering.clustering_basado_en_correlacion,
|
219 |
+
"DTW": Clustering.clustering_con_dtw
|
220 |
+
},
|
221 |
+
"Index Constructor":{
|
222 |
+
"Index Constructor": companies.index_constructor
|
223 |
+
}
|
224 |
+
}
|
225 |
+
self.dict_apps = dict_app
|
226 |
+
self.dict_area = dict_area
|
227 |
+
|
228 |
+
def set_user(self, user, area, mail, cargo):
|
229 |
+
self.user = user
|
230 |
+
self.area = area
|
231 |
+
self.mail = mail
|
232 |
+
self.cargo = cargo
|
233 |
+
|
234 |
+
def set_app(self, dict_apps):
|
235 |
+
self.dict_apps = dict_apps
|
236 |
+
|
237 |
+
def set_area(self, dict_area):
|
238 |
+
self.dict_area = dict_area
|
239 |
+
|
240 |
+
def run_views(self):
|
241 |
+
'''
|
242 |
+
Con la función run_views se corren las vistas asginadas al
|
243 |
+
usuario respectivo, generando las vistas en la sidebar y las subivistas
|
244 |
+
'''
|
245 |
+
app = MultiApp()
|
246 |
+
menu = self.dict_area[self.area]
|
247 |
+
if self.user == "alehmann":
|
248 |
+
menu.append("Análisis Inmobiliario")
|
249 |
+
if self.cargo == "PM" or self.user == 'bull':
|
250 |
+
menu.insert(1, "Admin Equity LATAM",)
|
251 |
+
|
252 |
+
with st.sidebar:
|
253 |
+
rad = option_menu("Navegación",menu,
|
254 |
+
menu_icon="app-indicator",
|
255 |
+
default_index=0, styles={
|
256 |
+
"container": {"margin": "0px",
|
257 |
+
"background-color": "#fafafa"},
|
258 |
+
"icon": { "font-size": "10px"},
|
259 |
+
"nav-link": {"font-size": "15px",
|
260 |
+
"text-align": "left",
|
261 |
+
"margin":"0px",
|
262 |
+
"--hover-color": "#eee"},
|
263 |
+
}
|
264 |
+
)
|
265 |
+
# rad = st.sidebar.radio("", menu)
|
266 |
+
if rad == "Home":
|
267 |
+
col1, col2 = st.columns((7, 2))
|
268 |
+
col1.subheader("Hola " + self.user + ",")
|
269 |
+
col1.title("Bienvenido al Portal LVAM")
|
270 |
+
for name in self.dict_area[self.area]:
|
271 |
+
if rad == name and rad != "Home":
|
272 |
+
st.session_state['Funcion'] = name
|
273 |
+
col1, col2 = st.columns((7, 2))
|
274 |
+
col1.markdown("""
|
275 |
+
# {Name}
|
276 |
+
""".format(Name=name))
|
277 |
+
if rad == "Notas Analistas" and self.cargo == "Investment Analyst":
|
278 |
+
app.add_app("Ingresar nota", Comentarios.ingresar_nota)
|
279 |
+
for aplicacion in list(self.dict_apps[name].keys()):
|
280 |
+
dic = self.dict_apps[name]
|
281 |
+
app.add_app(aplicacion, dic[aplicacion])
|
282 |
+
# st.write('Para dejar tu feedback accede al siguiente [formulario](https://forms.office.com/Pages/ResponsePage.aspx?id=mpR0wfr-_kmELD83ivOlRhEm1JCbNapEi4UG-t7FamlUM0VNTUU4TFpXNzBQTFM2NEo4RzhWVFk3Si4u)')
|
283 |
+
app.run()
|
284 |
+
# col2.image("img/logoDSTD.png")
|