Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
I
inventario
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jose Luis Gordillo Ruiz
inventario
Commits
0d1d0a0e
Commit
0d1d0a0e
authored
Feb 13, 2025
by
Jose Luis Gordillo Ruiz
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'nutVsIAUC'
parents
1082515d
bb552813
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
69 additions
and
26 deletions
+69
-26
estadisticas.py
+69
-26
No files found.
estadisticas.py
View file @
0d1d0a0e
...
...
@@ -14,6 +14,40 @@ import flask
server
=
flask
.
Flask
(
__name__
)
def
update_correlacion_macro_iauc
():
datos
=
comidas
.
sort_values
(
by
=
"iAUC"
,
ascending
=
True
)
datos
=
datos
[
np
.
abs
(
stats
.
zscore
(
datos
[
"iAUC"
],
nan_policy
=
'omit'
))
<
3
]
datos
.
reset_index
(
inplace
=
True
)
metricas
=
[
"hc_total"
,
"lipids_total"
,
"protein_total"
,
"fiber_total"
]
pcts
=
[
metrica
+
"_pct"
for
metrica
in
metricas
]
datos
[
"total"
]
=
datos
[
metricas
]
.
sum
(
axis
=
1
)
datos
=
datos
[
datos
[
"total"
]
>
0
]
datos
[
pcts
]
=
datos
[
metricas
]
.
div
(
datos
[
"total"
],
axis
=
0
)
fig
=
make_subplots
(
rows
=
2
,
cols
=
4
,
vertical_spacing
=
0.25
)
lcol
=
1
seq
=
1
for
metrica
in
metricas
:
datosfil
=
datos
[
np
.
abs
(
stats
.
zscore
(
datos
[
metrica
],
nan_policy
=
'omit'
))
<
3
]
fig
.
add_trace
(
go
.
Scatter
(
x
=
datosfil
[
"iAUC"
],
y
=
datosfil
[
metrica
],
name
=
metrica
,
mode
=
'markers'
),
row
=
1
,
col
=
lcol
)
fig
.
add_trace
(
go
.
Scatter
(
x
=
datosfil
[
"iAUC"
],
y
=
datosfil
[
metrica
+
"_pct"
],
name
=
metrica
,
mode
=
'markers'
),
row
=
2
,
col
=
lcol
)
fig
[
"layout"
][
'xaxis'
+
str
(
seq
)][
'title'
]
=
"iAUC"
fig
[
"layout"
][
'yaxis'
+
str
(
seq
)][
'title'
]
=
metrica
fig
[
"layout"
][
'xaxis'
+
str
(
seq
+
4
)][
'title'
]
=
"iAUC"
fig
[
"layout"
][
'yaxis'
+
str
(
seq
+
4
)][
'title'
]
=
"pct de "
+
metrica
lcol
=
lcol
+
1
seq
=
seq
+
1
return
fig
def
datavis
(
datos
):
medidas
=
[
"imc"
,
"age"
,
"glucose"
,
"hba1c"
,
"ct"
,
"hdl"
]
fig
=
make_subplots
(
rows
=
2
,
cols
=
3
,
vertical_spacing
=
0.25
)
...
...
@@ -316,46 +350,48 @@ def comidas_porcentajes(datos):
return
figura
def
comidas_principales
(
datos
):
dominantes
=
datos
.
groupby
(
"dominante"
)
categorias
=
datos
.
groupby
(
"dominante_category"
)
figura
=
make_subplots
(
cols
=
1
,
rows
=
1
)
dominantes
=
datos
.
groupby
(
"dominante"
)
.
count
()
dominantes
.
sort_values
(
by
=
"patient"
,
ascending
=
False
,
inplace
=
True
)
dominantes
=
dominantes
[
dominantes
[
"patient"
]
>
9
]
figura
=
make_subplots
(
cols
=
1
,
rows
=
1
,
subplot_titles
=
[
"Alimentos"
])
figura
.
add_trace
(
go
.
Scatter
(
x
=
list
(
dominantes
.
groups
.
keys
()),
y
=
dominantes
.
count
()[
"patient"
],
mode
=
'markers'
),
go
.
Scatter
(
x
=
dominantes
.
index
,
y
=
dominantes
[
"patient"
],
mode
=
'markers'
,
name
=
"# de comidas"
),
col
=
1
,
row
=
1
)
figura
[
"layout"
][
'yaxis'
][
'title'
]
=
"# de comidas"
# figura.update_layout(height=2000, width=800)
return
figura
def
comidas_principales_categorias
(
datos
):
categorias
=
datos
.
groupby
(
"dominante_category"
)
figura
=
make_subplots
(
cols
=
1
,
rows
=
1
)
categorias
=
datos
.
groupby
(
"dominante_category"
)
.
count
()
categorias
.
sort_values
(
by
=
"patient"
,
ascending
=
False
,
inplace
=
True
)
categorias
=
categorias
[
categorias
[
"patient"
]
>
9
]
figura
=
make_subplots
(
cols
=
1
,
rows
=
1
,
subplot_titles
=
[
"Categorías de alimentos"
])
figura
.
add_trace
(
go
.
Scatter
(
x
=
list
(
categorias
.
groups
.
keys
()),
y
=
categorias
.
count
()
[
"patient"
],
mode
=
'markers'
),
go
.
Scatter
(
x
=
categorias
.
index
,
y
=
categorias
[
"patient"
],
mode
=
'markers'
),
col
=
1
,
row
=
1
)
figura
[
"layout"
][
'yaxis'
][
'title'
]
=
"# de comidas"
return
figura
def
comidas_principales_hists
(
datos
):
dominantes
=
datos
.
groupby
(
"dominante"
)
categorias
=
datos
.
groupby
(
"dominante_category"
)
figura
=
make_subplots
(
cols
=
1
,
rows
=
2
)
figura
.
add_trace
(
go
.
Histogram
(
x
=
dominantes
.
count
()[
"patient"
]),
col
=
1
,
row
=
1
)
figura
.
add_trace
(
go
.
Histogram
(
x
=
categorias
.
count
()[
"patient"
]),
col
=
1
,
row
=
2
)
figura
.
update_layout
(
bargap
=
0.05
,
# gap between bars of adjacent location coordinates
bargroupgap
=
0.05
,
# gap between bars of the same location coordinates
showlegend
=
False
)
def
categorias_promedio_aucs
():
categorias
=
comidas
.
groupby
(
"dominante_category"
)[[
"iAUC"
,
"hc_total"
]]
.
mean
()
print
(
categorias
)
categorias
[
"tamaño"
]
=
comidas
.
groupby
(
"dominante_category"
)[
"iAUC"
]
.
count
()
categorias
.
sort_values
(
ascending
=
False
,
inplace
=
True
,
by
=
"iAUC"
)
# figura = make_subplots(cols=1, rows=1, subplot_titles=["Categorías de alimentos"])
# figura.add_trace(
# go.Scatter(x=categorias.index, y=categorias["iAUC"], mode="markers")
# )
figura
=
px
.
scatter
(
categorias
[
"iAUC"
],
size
=
categorias
[
"tamaño"
])
return
figura
def
categorias_aucs
(
datos
):
figura
=
px
.
box
(
datos
,
x
=
"dominante_category"
,
y
=
"iAUC"
)
datos_fil
=
datos
[
np
.
abs
(
stats
.
zscore
(
datos
[
"iAUC"
],
nan_policy
=
'omit'
))
<
3
]
figura
=
px
.
box
(
datos_fil
,
x
=
"dominante_category"
,
y
=
"iAUC"
)
return
figura
...
...
@@ -474,6 +510,7 @@ comidas = pd.read_csv("todos-foods.csv", usecols=["hc_total", "kcal_total", "fib
comidas
[
"foods"
]
=
comidas
[
"foods"
]
.
apply
(
literal_eval
)
comidas
=
comidas
[
comidas
[
"visita"
]
==
"e1"
]
comidas
=
comidas
[
comidas
[
"hc_total"
]
>
0
]
comidas
.
rename
(
columns
=
{
"glucosa_basal_area"
:
"pre-AUC"
,
"glucosa_estimulo_area"
:
"post-AUC"
,
"glucosa_area_efectiva"
:
"iAUC"
},
inplace
=
True
)
comidas
[
"iAUC"
]
=
comidas
[
"post-AUC"
]
-
comidas
[
"pre-AUC"
]
*
2
print
(
comidas
.
columns
)
...
...
@@ -632,12 +669,18 @@ app.layout = html.Div(children=[
html
.
Div
(
children
=
[
html
.
H1
(
"Distribución de
%
s de Macronutrientes de comidas"
,
className
=
"header-title2"
)]),
dcc
.
Graph
(
figure
=
comidas_porcentajes
(
comidas
))
,]),
# relación de macronutrientes de comidas con sus iAUC
html
.
Div
(
children
=
[
html
.
Div
(
children
=
[
html
.
H1
(
"Relación de macros / iAUCs de las comidas "
,
className
=
"header-title2"
)]),
dcc
.
Graph
(
figure
=
update_correlacion_macro_iauc
())
,]),
# # de comidas por componente dominante
html
.
Div
(
children
=
[
html
.
Div
(
children
=
[
html
.
H1
(
"Distribución de num. de comidas por componente principal"
,
className
=
"header-title2"
)]),
dcc
.
Graph
(
figure
=
comidas_principales
(
comidas
)),
dcc
.
Graph
(
figure
=
comidas_principales_categorias
(
comidas
)),
dcc
.
Graph
(
figure
=
c
omidas_principales_hists
(
comidas
)),
dcc
.
Graph
(
figure
=
c
ategorias_promedio_aucs
(
)),
dcc
.
Graph
(
figure
=
categorias_aucs
(
comidas
))
,]),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment