File size: 14,568 Bytes
cbdbd1c
478fd8c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cbdbd1c
e4f587a
 
478fd8c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e4f587a
 
 
478fd8c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e4f587a
 
 
478fd8c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e4f587a
 
 
478fd8c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e4f587a
 
 
478fd8c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e4f587a
 
 
478fd8c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e4f587a
 
 
 
478fd8c
 
e4f587a
478fd8c
 
 
 
 
 
e4f587a
478fd8c
e4f587a
478fd8c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e4f587a
478fd8c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e4f587a
478fd8c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e4f587a
 
 
 
 
 
 
 
 
 
cbdbd1c
 
e4f587a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
import gradio as gr
from queries import (clustering_esfuerzo_dieta_response, clustering_objetivo_response, clustering_entrenamiento_response, 
                     clustering_cumplimiento_dieta_response, clustering_compromiso_response, clustering_diferencia_peso_response,
                     make_query, get_min_max_mean_mode_macros_differences)
from find_matches import find_user_dates_matches, find_macros_that_match_dates_of_users

def clustering_responses(esfuerzo_dieta, objetivo, cumplimiento_entrenamiento, 
                    cumplimiento_dieta, compromiso, variacion_peso):
    cluster_esfuerzo_dieta = clustering_esfuerzo_dieta_response(esfuerzo_dieta)
    cluster_objetivo = clustering_objetivo_response(objetivo)
    cluster_entrenamiento = clustering_entrenamiento_response(cumplimiento_entrenamiento)
    cluster_cumplimiento_dieta = clustering_cumplimiento_dieta_response(cumplimiento_dieta)
    cluster_compromiso = clustering_compromiso_response(compromiso)
    diff_peso_min, diff_peso_max = clustering_diferencia_peso_response(variacion_peso)

    return cluster_esfuerzo_dieta, cluster_objetivo, cluster_entrenamiento, cluster_cumplimiento_dieta, cluster_compromiso, diff_peso_min, diff_peso_max

def calcular_macros(esfuerzo_dieta, objetivo, cumplimiento_entrenamiento, 
                    cumplimiento_dieta, compromiso, variacion_peso):
    # Obtenemos los valores correspondientes a cada selección
    valor_esfuerzo = next(list(opcion.values())[0]["value"] 
                         for opcion in opciones_esfuerzo 
                         if list(opcion.values())[0]["text"] == esfuerzo_dieta)
    
    valor_objetivo = next(list(opcion.values())[0]["value"] 
                         for opcion in opciones_objetivo 
                         if list(opcion.values())[0]["text"] == objetivo)
    
    valor_cumplimiento_entr = next(list(opcion.values())[0]["value"] 
                                  for opcion in opciones_cumplimiento_entrenamiento 
                                  if list(opcion.values())[0]["text"] == cumplimiento_entrenamiento)
    
    valor_cumplimiento_dieta = next(list(opcion.values())[0]["value"] 
                                   for opcion in opciones_cumplimiento_dieta 
                                   if list(opcion.values())[0]["text"] == cumplimiento_dieta)
    
    valor_compromiso = next(list(opcion.values())[0]["value"] 
                          for opcion in opciones_compromiso 
                          if list(opcion.values())[0]["text"] == compromiso)
    
    # Clustering
    (cluster_esfuerzo_dieta, cluster_objetivo, cluster_entrenamiento, cluster_cumplimiento_dieta, 
     cluster_compromiso, diff_peso_min, diff_peso_max) = clustering_responses(valor_esfuerzo, valor_objetivo, 
                                                                           valor_cumplimiento_entr, 
                                                                           valor_cumplimiento_dieta, valor_compromiso, 
                                                                           variacion_peso)
    
    # Imprimimos los resultados
    print(f"Consulta:")
    print(f"\tEsfuerzo para cumplir dieta: {cluster_esfuerzo_dieta}")
    print(f"\tObjetivo: {cluster_objetivo}")
    print(f"\tEntrenamiento: {cluster_entrenamiento}")
    print(f"\tCumplimiento dieta: {cluster_cumplimiento_dieta}")
    print(f"\tCompromiso: {cluster_compromiso}")
    print(f"\tVariación de peso: {variacion_peso}")
    print(f"\t{diff_peso_min} <= Diferencia peso <= {diff_peso_max}")

    # Crear query
    query = make_query(cluster_esfuerzo_dieta, cluster_objetivo, cluster_entrenamiento, cluster_cumplimiento_dieta, cluster_compromiso, diff_peso_min, diff_peso_max)

    # Print query
    print(f"Query: {query}")

    # Crear diccionario de matches
    matches_dict = find_user_dates_matches(query)

    # Print matches
    print(f"Matches:\n{matches_dict}")

    # Find macros that match dates of users
    macros_differences_list = find_macros_that_match_dates_of_users(matches_dict)

    # Print macros
    print(f"Macros:\n{macros_differences_list}")

    # Calculate macros min, max and mean
    (train_day_protein_std, train_day_carbs_std, train_day_fat_std, intratrain_protein_std, intratrain_carbs_std, 
     rest_day_protein_std, rest_day_carbs_std, rest_day_fat_std) = get_min_max_mean_mode_macros_differences(macros_differences_list)

    # Print macros min, max and mean
    print(f"Macros min, max and mean:\n{train_day_protein_std}, {train_day_carbs_std}, {train_day_fat_std}, {intratrain_protein_std}, {intratrain_carbs_std}, {rest_day_protein_std}, {rest_day_carbs_std}, {rest_day_fat_std}")

    # Create strings for the outputs
    train_day_protein_str = f"min: {train_day_protein_std[0]}, max: {train_day_protein_std[1]}, mean: {train_day_protein_std[2]:.2f}, mode: {train_day_protein_std[3]}"
    train_day_carbs_str = f"min: {train_day_carbs_std[0]}, max: {train_day_carbs_std[1]}, mean: {train_day_carbs_std[2]:.2f}, mode: {train_day_carbs_std[3]}"
    train_day_fat_str = f"min: {train_day_fat_std[0]}, max: {train_day_fat_std[1]}, mean: {train_day_fat_std[2]:.2f}, mode: {train_day_fat_std[3]}"
    intratrain_protein_str = f"min: {intratrain_protein_std[0]}, max: {intratrain_protein_std[1]}, mean: {intratrain_protein_std[2]:.2f}, mode: {intratrain_protein_std[3]}"
    intratrain_carbs_str = f"min: {intratrain_carbs_std[0]}, max: {intratrain_carbs_std[1]}, mean: {intratrain_carbs_std[2]:.2f}, mode: {intratrain_carbs_std[3]}"
    rest_day_protein_str = f"min: {rest_day_protein_std[0]}, max: {rest_day_protein_std[1]}, mean: {rest_day_protein_std[2]:.2f}, mode: {rest_day_protein_std[3]}"
    rest_day_carbs_str = f"min: {rest_day_carbs_std[0]}, max: {rest_day_carbs_std[1]}, mean: {rest_day_carbs_std[2]:.2f}, mode: {rest_day_carbs_std[3]}"
    rest_day_fat_str = f"min: {rest_day_fat_std[0]}, max: {rest_day_fat_std[1]}, mean: {rest_day_fat_std[2]:.2f}, mode: {rest_day_fat_std[3]}"

    return train_day_protein_str, train_day_carbs_str, train_day_fat_str, intratrain_protein_str, intratrain_carbs_str, rest_day_protein_str, rest_day_carbs_str, rest_day_fat_str

# Definimos las opciones para cada menú desplegable
opciones_esfuerzo = [
    {
        "No entiendo la calculadora, quiero menús tipo": {
            "text": "No entiendo la calculadora, quiero menús tipo",
            "value": " | no data"
        }
    },
    {
        "No costó nada": {
            "text": "No costó nada",
            "value": " | no costo"
        }
    },
    {
        "Costó demasiado, súbeme macros": {
            "text": "Costó demasiado, súbeme macros",
            "value": " | costo subir macros"
        }
    },
    {
        "Costó demasiado, bájame macros": {
            "text": "Costó demasiado, bájame macros",
            "value": " | costo bajar macros"
        }
    },
    {
        "Costó, pero me adapto a nuevos ajustes": {
            "text": "Costó, pero me adapto a nuevos ajustes",
            "value": " | costo y me adapto a nuevos ajustes"
        }
    },
    {
        "Iba a coger menús tipo, pero al final por precio no": {
            "text": "Iba a coger menús tipo, pero al final por precio no",
            "value": " | no data"
        }
    }
]

opciones_objetivo = [
    {
        "definición (nada cambia)": {
            "text": "definición (nada cambia)",
            "value": " | definicion"
        }
    },
    {
        "empezamos a definir (cambia)": {
            "text": "empezamos a definir (cambia)",
            "value": " | definicion"
        }
    },
    {
        "perder peso (nada cambia)": {
            "text": "perder peso (nada cambia)",
            "value": " | definicion"
        }
    },
    {
        "volumen (nada cambia)": {
            "text": "volumen (nada cambia)",
            "value": " | volumen"
        }
    },
    {
        "empezamos a coger volumen (cambia)": {
            "text": "empezamos a coger volumen (cambia)",
            "value": " | volumen"
        }
    },
    {
        "empezamos a coger volumen, sobre todo tren inferior (cambia)": {
            "text": "empezamos a coger volumen, sobre todo tren inferior (cambia)",
            "value": " | volumen"
        }
    },
    {
        "empezamos a coger volumen, en todo el cuerpo (cambia)": {
            "text": "empezamos a coger volumen, en todo el cuerpo (cambia)",
            "value": " | volumen"
        }
    }
]

opciones_cumplimiento_entrenamiento = [
    {
        "Lo hice perfecto": {
            "text": "Lo hice perfecto",
            "value": " | bien"
        }
    },
    {
        "He fallado algunos días, pero sí": {
            "text": "He fallado algunos días, pero sí",
            "value": " | bien"
        }
    },
    {
        "Lesión importante": {
            "text": "Lesión importante",
            "value": " | mal"
        }
    },
    {
        "Lo hice prácticamente perfecto": {
            "text": "Lo hice prácticamente perfecto",
            "value": " | bien"
        }
    },
    {
        "Pequeña lesión": {
            "text": "Pequeña lesión",
            "value": " | mal"
        }
    },
    {
        "No hice nada, mantenemos la rutina un mes más": {
            "text": "No hice nada, mantenemos la rutina un mes más",
            "value": " | mal"
        }
    },
    {
        "Alárgame la rutina una semana más": {
            "text": "Alárgame la rutina una semana más",
            "value": " | mal"
        }
    }
]

opciones_cumplimiento_dieta = [
    {
        "al 70%": {
            "text": "al 70%",
            "value": " | bien"
        }
    },
    {
        "regular, me cuesta llegar": {
            "text": "regular, me cuesta llegar",
            "value": " | regular"
        }
    },
    {
        "Nada, mantén mis macros": {
            "text": "Nada, mantén mis macros",
            "value": " | mal"
        }
    },
    {
        "casi perfecta": {
            "text": "casi perfecta",
            "value": " | bien"
        }
    },
    {
        "regular, me salto la dieta": {
            "text": "regular, me salto la dieta",
            "value": " | regular"
        }
    },
    {
        "Perfecta": {
            "text": "Perfecta",
            "value": " | bien"
        }
    }
]

opciones_compromiso = [
    {
        "Bueno, pero mejorable": {
            "text": "Bueno, pero mejorable",
            "value": " | bueno"
        }
    },
    {
        "Mal, pero a partir de ahora voy a por todas": {
            "text": "Mal, pero a partir de ahora voy a por todas",
            "value": " | mal"
        }
    },
    {
        "Mal, demasiado exigente": {
            "text": "Mal, demasiado exigente",
            "value": " | mal"
        }
    },
    {
        "Máximo": {
            "text": "Máximo",
            "value": " | bueno"
        }
    }
]

# Creamos la interfaz
with gr.Blocks() as demo:
    # Definimos el color naranja
    naranja = "#FF9300"
    
    # Procesamos las opciones para obtener solo los textos
    textos_esfuerzo = [list(opcion.values())[0]["text"] for opcion in opciones_esfuerzo]
    textos_objetivo = [list(opcion.values())[0]["text"] for opcion in opciones_objetivo]
    textos_cumplimiento_entr = [list(opcion.values())[0]["text"] for opcion in opciones_cumplimiento_entrenamiento]
    textos_cumplimiento_dieta = [list(opcion.values())[0]["text"] for opcion in opciones_cumplimiento_dieta]
    textos_compromiso = [list(opcion.values())[0]["text"] for opcion in opciones_compromiso]
    
    # Entradas
    with gr.Row():
        esfuerzo = gr.Dropdown(
            choices=textos_esfuerzo, 
            label="Esfuerzo dieta",
            value="No costó nada"
        )
        cumplimiento_dieta = gr.Dropdown(
            choices=textos_cumplimiento_dieta, 
            label="Cumplimiento de la dieta",
            value="Perfecta"
        )
        objetivo = gr.Dropdown(
            choices=textos_objetivo, 
            label="Objetivo",
            value="volumen (nada cambia)"
        )
    with gr.Row():
        cumplimiento_entr = gr.Dropdown(
            choices=textos_cumplimiento_entr, 
            label="Cumplimiento del entrenamiento",
            value="Lo hice perfecto"
        )
        compromiso = gr.Dropdown(
            choices=textos_compromiso, 
            label="Compromiso",
            value="Máximo"
        )
        variacion_peso = gr.Number(
            label="Variación de peso", 
            precision=2,
            value=0.7
        )
    
    # Versión simple del botón
    calcular_btn = gr.Button(
        "Calcular",
        variant="primary",
        size="lg"
    )
    
    # Añadimos el estilo CSS personalizado
    css = f"""
        <style>
        #boton-naranja {{
            background-color: {naranja} !important;
            border: 1px solid {naranja} !important;
        }}
        #boton-naranja:hover {{
            background-color: {naranja}DD !important;
            border: 1px solid {naranja}DD !important;
        }}
        </style>
    """
    
    css_outputs = """
        <style>
        .output-row {
            align-items: flex-end !important;
            display: flex !important;
            gap: 1rem !important;
        }
        .output-row > * {
            flex: 1;
            min-width: 0;
        }
        </style>
    """
    
    gr.Markdown(css + css_outputs)
    
    # Salidas
    with gr.Row(elem_classes="output-row"):
        proteina_entreno = gr.Textbox(label="Proteína día de entreno (g)")
        carbs_entreno = gr.Textbox(label="Carbohidratos día de entreno (g)")
        grasas_entreno = gr.Textbox(label="Grasas día de entreno (g)")
        proteina_intra = gr.Textbox(label="Proteína intraentreno (g)")
        carbs_intra = gr.Textbox(label="Carbohidratos intraentreno (g)")
        proteina_descanso = gr.Textbox(label="Proteína día de descanso (g)")
        carbs_descanso = gr.Textbox(label="Carbohidratos día de descanso (g)")
        grasas_descanso = gr.Textbox(label="Grasas día de descanso (g)")
    
    # Conectamos el botón con la función
    calcular_btn.click(
        fn=calcular_macros,
        inputs=[esfuerzo, objetivo, cumplimiento_entr, cumplimiento_dieta, 
                compromiso, variacion_peso],
        outputs=[proteina_entreno, carbs_entreno, grasas_entreno,
                proteina_intra, carbs_intra,
                proteina_descanso, carbs_descanso, grasas_descanso]
    )

demo.launch()