Update app.py
Browse files
app.py
CHANGED
@@ -10,6 +10,7 @@ def __():
|
|
10 |
import marimo as mo
|
11 |
import pandas as pd
|
12 |
import gspread
|
|
|
13 |
|
14 |
class Criterio:
|
15 |
def __init__(self, criteriol, criterior, tooltipl, tooltipr):
|
@@ -223,6 +224,21 @@ def __():
|
|
223 |
region = 'LIMA NORTE'
|
224 |
return region
|
225 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
226 |
@mo.cache
|
227 |
def LoadData(credentials):
|
228 |
gs = gspread.service_account(filename = credentials)
|
@@ -253,6 +269,7 @@ def __():
|
|
253 |
CreateSheet,
|
254 |
Criterio,
|
255 |
Direccion,
|
|
|
256 |
LoadData,
|
257 |
MeanMatrix,
|
258 |
ShowMatrix,
|
@@ -265,6 +282,7 @@ def __():
|
|
265 |
np,
|
266 |
pd,
|
267 |
poa,
|
|
|
268 |
sheets,
|
269 |
unidades,
|
270 |
valores,
|
@@ -295,14 +313,14 @@ def __(factores, mo):
|
|
295 |
full_width=True,
|
296 |
label="Establesca el n煤mero de factores de riesgo a comparar: ",
|
297 |
)
|
298 |
-
criterios
|
299 |
return (criterios,)
|
300 |
|
301 |
|
302 |
@app.cell(hide_code=True)
|
303 |
-
def __(CompareLayoutValues, criterios):
|
304 |
compares, vstack = CompareLayoutValues(criterios.value)
|
305 |
-
vstack
|
306 |
return compares, vstack
|
307 |
|
308 |
|
@@ -365,14 +383,20 @@ def __(meanmatrix, mo):
|
|
365 |
|
366 |
|
367 |
@app.cell(hide_code=True)
|
368 |
-
def __(Titles, meanmatrix, mo, pd):
|
369 |
try:
|
370 |
regiones = pd.DataFrame(meanmatrix.value[1]["Regi贸n"].value_counts())
|
371 |
oficina = mo.ui.dropdown(options=sorted(regiones.index.to_list()), label="Seleccione la regi贸n que desea analizar: ", value= 'AMAZONAS', full_width=True)
|
372 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
373 |
except:
|
374 |
pass
|
375 |
-
return oficina, regiones
|
376 |
|
377 |
|
378 |
@app.cell(hide_code=True)
|
|
|
10 |
import marimo as mo
|
11 |
import pandas as pd
|
12 |
import gspread
|
13 |
+
import random
|
14 |
|
15 |
class Criterio:
|
16 |
def __init__(self, criteriol, criterior, tooltipl, tooltipr):
|
|
|
224 |
region = 'LIMA NORTE'
|
225 |
return region
|
226 |
|
227 |
+
def Distribucion(valor):
|
228 |
+
incremento = 0
|
229 |
+
while True:
|
230 |
+
distribucion = [incremento] * 12
|
231 |
+
for i in range(12):
|
232 |
+
if sum(distribucion) == valor:
|
233 |
+
break
|
234 |
+
distribucion[i] = incremento + 1
|
235 |
+
if sum(distribucion) == valor:
|
236 |
+
break
|
237 |
+
incremento += 1
|
238 |
+
random.shuffle(distribucion)
|
239 |
+
distribucion = distribucion + [sum(distribucion)]
|
240 |
+
return distribucion
|
241 |
+
|
242 |
@mo.cache
|
243 |
def LoadData(credentials):
|
244 |
gs = gspread.service_account(filename = credentials)
|
|
|
269 |
CreateSheet,
|
270 |
Criterio,
|
271 |
Direccion,
|
272 |
+
Distribucion,
|
273 |
LoadData,
|
274 |
MeanMatrix,
|
275 |
ShowMatrix,
|
|
|
282 |
np,
|
283 |
pd,
|
284 |
poa,
|
285 |
+
random,
|
286 |
sheets,
|
287 |
unidades,
|
288 |
valores,
|
|
|
313 |
full_width=True,
|
314 |
label="Establesca el n煤mero de factores de riesgo a comparar: ",
|
315 |
)
|
316 |
+
mo.output.replace(criterios)
|
317 |
return (criterios,)
|
318 |
|
319 |
|
320 |
@app.cell(hide_code=True)
|
321 |
+
def __(CompareLayoutValues, criterios, mo):
|
322 |
compares, vstack = CompareLayoutValues(criterios.value)
|
323 |
+
mo.output.replace(vstack)
|
324 |
return compares, vstack
|
325 |
|
326 |
|
|
|
383 |
|
384 |
|
385 |
@app.cell(hide_code=True)
|
386 |
+
def __(Distribucion, Titles, meanmatrix, mo, pd, poa):
|
387 |
try:
|
388 |
regiones = pd.DataFrame(meanmatrix.value[1]["Regi贸n"].value_counts())
|
389 |
oficina = mo.ui.dropdown(options=sorted(regiones.index.to_list()), label="Seleccione la regi贸n que desea analizar: ", value= 'AMAZONAS', full_width=True)
|
390 |
+
departamentos = pd.DataFrame(sorted(regiones.index.to_list()), columns = ['Regiones'])
|
391 |
+
distribucion = []
|
392 |
+
for i in departamentos['Regiones']:
|
393 |
+
acciones = int(poa[poa['REGIONES'] == i]['CRITICIDAD DE INSTALACIONES'].iat[0] * 0.7)
|
394 |
+
distribucion.append(Distribucion(acciones))
|
395 |
+
distribucion = pd.DataFrame(distribucion, columns= ["Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre", "Total"])
|
396 |
+
mo.output.replace(mo.vstack([Titles('Matriz de fiscalizaci贸n nacional', 1).show(), pd.concat([departamentos, distribucion], ignore_index=False, axis = 1), Titles("Matriz de fiscalizaci贸n regional", 1).show(), oficina]))
|
397 |
except:
|
398 |
pass
|
399 |
+
return acciones, departamentos, distribucion, i, oficina, regiones
|
400 |
|
401 |
|
402 |
@app.cell(hide_code=True)
|