ajustes en las gráficas de iaucs y distr. de comidas reportadas

parent 8e2c3fc6
......@@ -220,49 +220,91 @@ def triareas(pacientes):
)
return figura
def comidas_datos(datos):
columnas = ["hc_total", "kcal_total", "fiber_total", "protein_total", "pre-AUC", "post-AUC", "iAUC", "N-alimentos"]
def comidas_iaucs(datos):
columnas = ["pre-AUC", "post-AUC", "iAUC"]
datos["N-alimentos"] = datos["foods"].apply(lambda x: len(x))
figura = make_subplots(cols=4, rows=2, shared_xaxes=True, vertical_spacing=0.1,
subplot_titles=columnas)
lrow = 1
fig = make_subplots(cols=3, rows=1, vertical_spacing=0.25)
lcol = 1
seq = 1
for columna in columnas:
datosfil = datos[np.abs(stats.zscore(datos[columna], nan_policy='omit')) < 3]
fig.add_trace(
go.Scatter(y=datosfil[columna], name=columna, mode="markers"),
row=1, col=lcol
)
fig['layout']['yaxis' + str(seq)]['title']=columna
fig['layout']['xaxis' + str(seq)]['title']="Comida ID"
seq = seq + 1
lcol = lcol + 1
fig.update_layout(showlegend=False)
return fig
def comidas_iauc_describe(datos):
columnas = ["pre-AUC", "post-AUC", "iAUC"]
fig = make_subplots(cols=3, rows=1, vertical_spacing=0.25)
seq = 1
lcol = 1
for columna in columnas:
datosfil = datos[np.abs(stats.zscore(datos[columna], nan_policy='omit')) < 3]
fig.add_trace(
go.Histogram(x=datosfil[columna], name=columna),
row=1, col=lcol
)
fig['layout']['yaxis' + str(seq)]['title']=columna
seq = seq + 1
lcol = lcol + 1
fig.update_layout(
showlegend = False,
bargap=0.05, # gap between bars of adjacent location coordinates
bargroupgap=0.05 # gap between bars of the same location coordinates
)
return fig
def comidas_macro_contenido(datos):
columnas = ["hc_total", "lipids_total", "fiber_total", "protein_total"]
datos["N-alimentos"] = datos["foods"].apply(lambda x: len(x))
figura = make_subplots(cols=4, rows=1, vertical_spacing=0.24)
lcol = 1
seq = 1
for columna in columnas:
datosfil = datos[np.abs(stats.zscore(datos[columna], nan_policy='omit')) < 3]
figura.add_trace(
go.Scatter(y=datosfil[columna], name=columna, mode="markers"),
row=lrow, col=lcol
row=1, col=lcol
)
lrow = lrow + (lcol // 4)
figura['layout']['yaxis' + str(seq)]['title']=columna
figura['layout']['xaxis' + str(seq)]['title']="Comida ID"
seq = seq + 1
lcol = lcol + 1 if lcol < 4 else 1
figura.update_layout(showlegend=False)
return figura
def comidas_describe(datos):
columnas = ["hc_total", "kcal_total", "fiber_total", "protein_total", "pre-AUC", "post-AUC", "iAUC", "N-alimentos"]
datos["N-alimentos"] = datos["foods"].apply(lambda x: len(x))
print(datos.columns)
figura = make_subplots(cols=4, rows=2, shared_yaxes=True,
subplot_titles=columnas)
lrow = 1
def comidas_macro_describe(datos):
columnas = ["hc_total", "lipids_total", "fiber_total", "protein_total"]
fig = make_subplots(cols=4, rows=1, vertical_spacing=0.25)
seq = 1
lcol = 1
for columna in columnas:
datosfil = datos[np.abs(stats.zscore(datos[columna], nan_policy='omit')) < 3]
figura.add_trace(
fig.add_trace(
go.Histogram(x=datosfil[columna], name=columna),
row=lrow, col=lcol
row=1, col=lcol
)
lrow = lrow + (lcol // 4)
fig['layout']['yaxis' + str(seq)]['title']=columna
seq = seq + 1
lcol = lcol + 1 if lcol < 4 else 1
figura.update_layout(
fig.update_layout(
showlegend = False,
bargap=0.05, # gap between bars of adjacent location coordinates
bargroupgap=0.05 # gap between bars of the same location coordinates
)
return figura
return fig
def comidas_porcentajes(datos):
columnas = ["hc_total", "fiber_total", "protein_total", "lipids_total"]
......@@ -551,30 +593,37 @@ app.layout = html.Div(children=[
dcc.Graph(id="figCorrelaciones")
]),
# correlaciones transpuesta
html.Div(children= [
html.Div(children= [html.H1("Relación de iAUC/Controlados con diversos índices (traspuesta)", className = "header-title2")]),
dcc.Graph(figure=correlaciones_v2(visitas_incluidos, "Glucosa"))
]),
# html.Div(children= [
# html.Div(children= [html.H1("Relación de iAUC/Controlados con diversos índices (traspuesta)", className = "header-title2")]),
# dcc.Graph(figure=correlaciones_v2(visitas_incluidos, "Glucosa"))
# ]),
# areas de tres pacientes
html.Div(children= [
html.Div(children= [html.H1("Ejemplos de iAUC de Glucosa", className = "header-title2")]),
dcc.Graph(figure=triareas([85,148,177]))
]),
# heatmap
# # heatmap
# html.Div(children= [
# html.Div(children= [html.H1("Mapa de calor de iAUC/alimentos controlados", className = "header-title2")]),
# dcc.Graph(figure=heatmap(visitas_incluidos))
# ,]),
# datos de comidas
html.Div(children= [
html.Div(children= [html.H1("Mapa de calor de iAUC/alimentos controlados", className = "header-title2")]),
dcc.Graph(figure=heatmap(visitas_incluidos))
html.Div(children= [html.H1("iAUCs de las comidas reportadas", className = "header-title2")]),
dcc.Graph(figure=comidas_iaucs(comidas)),
dcc.Graph(figure=comidas_iauc_describe(comidas))
,]),
# datos de comidas
html.Div(children= [
html.Div(children= [html.H1("Macronutrientes / AUCs de comidas", className = "header-title2")]),
dcc.Graph(figure=comidas_datos(comidas))
html.Div(children= [html.H1("Contenido de macronutrientes de las comidas", className = "header-title2")]),
dcc.Graph(figure=comidas_macro_contenido(comidas))
,]),
# descripcion de comidas
html.Div(children= [
html.Div(children= [html.H1("Distribución de Macronutrientes de comidas", className = "header-title2")]),
dcc.Graph(figure=comidas_describe(comidas))
dcc.Graph(figure=comidas_macro_describe(comidas))
,]),
# descripcion de componentes de macronutrientes de comidas
html.Div(children= [
......@@ -626,7 +675,7 @@ def update_correlacion(controlado):
datos_sorted = datos_fil.sort_values(by=controlado, ascending=True)
datos_sorted.reset_index(inplace=True)
metricas = ["imc", "age", "glucose", "hba1c"]
figura = make_subplots(rows=2, cols=2, vertical_spacing=0.25)
figura = make_subplots(rows=1, cols=4, vertical_spacing=0.25)
lrow = 1
lcol = 1
seq = 1
......@@ -635,18 +684,17 @@ def update_correlacion(controlado):
figura.add_trace(
go.Scatter(x=datos_sorted.index, y=datos_sorted[metrica], name=metrica, mode='markers'),
row=lrow, col=lcol
row=1, col=lcol
)
figura.add_trace(
go.Scatter(x=datos_sorted.index, y=datos_sorted[metrica].rolling(5).mean(), name="PM(5)"),
row=lrow, col=lcol
row=1, col=lcol
)
corr = datos_sorted[[metrica]].corrwith(datos_sorted[controlado]).values[0]
figura.add_annotation(row=lrow, col=lcol, text="R = " + "{:.2f}".format(corr))
figura["layout"]['xaxis' + str(seq)]['title']="Ranqueo de pacientes por su iAUC de" + controlado
figura.add_annotation(row=1, col=lcol, text="R = " + "{:.2f}".format(corr))
figura["layout"]['xaxis' + str(seq)]['title']="Ranqueo de pacientes por iAUC: " + controlado
figura["layout"]['yaxis' + str(seq)]['title']= metrica
lcol = lcol + 1 if lcol < 2 else 1
lrow = lrow + (lcol % 2)
lcol = lcol + 1
seq = seq + 1
figura["layout"]["yaxis1"]["range"] = [15,45]
figura["layout"]["yaxis2"]["range"] = [17,80]
......@@ -654,7 +702,7 @@ def update_correlacion(controlado):
figura["layout"]["yaxis4"]["range"] = [5,7]
figura.update_layout(showlegend=False)
figura.update_layout(height=600, width=800)
#figura.update_layout(height=600, width=800)
return figura
if __name__ == "__main__":
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment