feat(SRC): :rocket: Add all logic
Browse files- app.py +355 -54
- create_new_formularios.py +221 -0
- create_new_usuarios.py +131 -0
- find_matches.py +82 -0
- queries.py +685 -0
app.py
CHANGED
|
@@ -1,85 +1,386 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
def calcular_macros(esfuerzo_dieta, objetivo, cumplimiento_entrenamiento,
|
| 4 |
cumplimiento_dieta, compromiso, variacion_peso):
|
| 5 |
-
#
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# Definimos las opciones para cada men煤 desplegable
|
| 9 |
opciones_esfuerzo = [
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
]
|
| 17 |
|
| 18 |
opciones_objetivo = [
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
]
|
| 27 |
|
| 28 |
opciones_cumplimiento_entrenamiento = [
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
]
|
| 37 |
|
| 38 |
opciones_cumplimiento_dieta = [
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
]
|
| 46 |
|
| 47 |
opciones_compromiso = [
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
]
|
| 53 |
|
| 54 |
# Creamos la interfaz
|
| 55 |
with gr.Blocks() as demo:
|
| 56 |
-
#
|
| 57 |
-
|
| 58 |
-
objetivo = gr.Dropdown(choices=opciones_objetivo, label="Objetivo")
|
| 59 |
-
cumplimiento_entr = gr.Dropdown(choices=opciones_cumplimiento_entrenamiento,
|
| 60 |
-
label="Cumplimiento del entrenamiento")
|
| 61 |
-
cumplimiento_dieta = gr.Dropdown(choices=opciones_cumplimiento_dieta,
|
| 62 |
-
label="Cumplimiento de la dieta")
|
| 63 |
-
compromiso = gr.Dropdown(choices=opciones_compromiso, label="Compromiso")
|
| 64 |
-
variacion_peso = gr.Textbox(label="Variaci贸n de peso")
|
| 65 |
|
| 66 |
-
#
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
-
#
|
| 70 |
with gr.Row():
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
with gr.Row():
|
| 76 |
-
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
# Conectamos el bot贸n con la funci贸n
|
| 85 |
calcular_btn.click(
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from queries import (clustering_esfuerzo_dieta_response, clustering_objetivo_response, clustering_entrenamiento_response,
|
| 3 |
+
clustering_cumplimiento_dieta_response, clustering_compromiso_response, clustering_diferencia_peso_response,
|
| 4 |
+
make_query, get_min_max_mean_mode_macros_differences)
|
| 5 |
+
from find_matches import find_user_dates_matches, find_macros_that_match_dates_of_users
|
| 6 |
+
|
| 7 |
+
def clustering_responses(esfuerzo_dieta, objetivo, cumplimiento_entrenamiento,
|
| 8 |
+
cumplimiento_dieta, compromiso, variacion_peso):
|
| 9 |
+
cluster_esfuerzo_dieta = clustering_esfuerzo_dieta_response(esfuerzo_dieta)
|
| 10 |
+
cluster_objetivo = clustering_objetivo_response(objetivo)
|
| 11 |
+
cluster_entrenamiento = clustering_entrenamiento_response(cumplimiento_entrenamiento)
|
| 12 |
+
cluster_cumplimiento_dieta = clustering_cumplimiento_dieta_response(cumplimiento_dieta)
|
| 13 |
+
cluster_compromiso = clustering_compromiso_response(compromiso)
|
| 14 |
+
diff_peso_min, diff_peso_max = clustering_diferencia_peso_response(variacion_peso)
|
| 15 |
+
|
| 16 |
+
return cluster_esfuerzo_dieta, cluster_objetivo, cluster_entrenamiento, cluster_cumplimiento_dieta, cluster_compromiso, diff_peso_min, diff_peso_max
|
| 17 |
|
| 18 |
def calcular_macros(esfuerzo_dieta, objetivo, cumplimiento_entrenamiento,
|
| 19 |
cumplimiento_dieta, compromiso, variacion_peso):
|
| 20 |
+
# Obtenemos los valores correspondientes a cada selecci贸n
|
| 21 |
+
valor_esfuerzo = next(list(opcion.values())[0]["value"]
|
| 22 |
+
for opcion in opciones_esfuerzo
|
| 23 |
+
if list(opcion.values())[0]["text"] == esfuerzo_dieta)
|
| 24 |
+
|
| 25 |
+
valor_objetivo = next(list(opcion.values())[0]["value"]
|
| 26 |
+
for opcion in opciones_objetivo
|
| 27 |
+
if list(opcion.values())[0]["text"] == objetivo)
|
| 28 |
+
|
| 29 |
+
valor_cumplimiento_entr = next(list(opcion.values())[0]["value"]
|
| 30 |
+
for opcion in opciones_cumplimiento_entrenamiento
|
| 31 |
+
if list(opcion.values())[0]["text"] == cumplimiento_entrenamiento)
|
| 32 |
+
|
| 33 |
+
valor_cumplimiento_dieta = next(list(opcion.values())[0]["value"]
|
| 34 |
+
for opcion in opciones_cumplimiento_dieta
|
| 35 |
+
if list(opcion.values())[0]["text"] == cumplimiento_dieta)
|
| 36 |
+
|
| 37 |
+
valor_compromiso = next(list(opcion.values())[0]["value"]
|
| 38 |
+
for opcion in opciones_compromiso
|
| 39 |
+
if list(opcion.values())[0]["text"] == compromiso)
|
| 40 |
+
|
| 41 |
+
# Clustering
|
| 42 |
+
(cluster_esfuerzo_dieta, cluster_objetivo, cluster_entrenamiento, cluster_cumplimiento_dieta,
|
| 43 |
+
cluster_compromiso, diff_peso_min, diff_peso_max) = clustering_responses(valor_esfuerzo, valor_objetivo,
|
| 44 |
+
valor_cumplimiento_entr,
|
| 45 |
+
valor_cumplimiento_dieta, valor_compromiso,
|
| 46 |
+
variacion_peso)
|
| 47 |
+
|
| 48 |
+
# Imprimimos los resultados
|
| 49 |
+
print(f"Consulta:")
|
| 50 |
+
print(f"\tEsfuerzo para cumplir dieta: {cluster_esfuerzo_dieta}")
|
| 51 |
+
print(f"\tObjetivo: {cluster_objetivo}")
|
| 52 |
+
print(f"\tEntrenamiento: {cluster_entrenamiento}")
|
| 53 |
+
print(f"\tCumplimiento dieta: {cluster_cumplimiento_dieta}")
|
| 54 |
+
print(f"\tCompromiso: {cluster_compromiso}")
|
| 55 |
+
print(f"\tVariaci贸n de peso: {variacion_peso}")
|
| 56 |
+
print(f"\t{diff_peso_min} <= Diferencia peso <= {diff_peso_max}")
|
| 57 |
+
|
| 58 |
+
# Crear query
|
| 59 |
+
query = make_query(cluster_esfuerzo_dieta, cluster_objetivo, cluster_entrenamiento, cluster_cumplimiento_dieta, cluster_compromiso, diff_peso_min, diff_peso_max)
|
| 60 |
+
|
| 61 |
+
# Print query
|
| 62 |
+
print(f"Query: {query}")
|
| 63 |
+
|
| 64 |
+
# Crear diccionario de matches
|
| 65 |
+
matches_dict = find_user_dates_matches(query)
|
| 66 |
+
|
| 67 |
+
# Print matches
|
| 68 |
+
print(f"Matches:\n{matches_dict}")
|
| 69 |
+
|
| 70 |
+
# Find macros that match dates of users
|
| 71 |
+
macros_differences_list = find_macros_that_match_dates_of_users(matches_dict)
|
| 72 |
+
|
| 73 |
+
# Print macros
|
| 74 |
+
print(f"Macros:\n{macros_differences_list}")
|
| 75 |
+
|
| 76 |
+
# Calculate macros min, max and mean
|
| 77 |
+
(train_day_protein_std, train_day_carbs_std, train_day_fat_std, intratrain_protein_std, intratrain_carbs_std,
|
| 78 |
+
rest_day_protein_std, rest_day_carbs_std, rest_day_fat_std) = get_min_max_mean_mode_macros_differences(macros_differences_list)
|
| 79 |
+
|
| 80 |
+
# Print macros min, max and mean
|
| 81 |
+
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}")
|
| 82 |
+
|
| 83 |
+
# Create strings for the outputs
|
| 84 |
+
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]}"
|
| 85 |
+
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]}"
|
| 86 |
+
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]}"
|
| 87 |
+
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]}"
|
| 88 |
+
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]}"
|
| 89 |
+
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]}"
|
| 90 |
+
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]}"
|
| 91 |
+
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]}"
|
| 92 |
+
|
| 93 |
+
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
|
| 94 |
|
| 95 |
# Definimos las opciones para cada men煤 desplegable
|
| 96 |
opciones_esfuerzo = [
|
| 97 |
+
{
|
| 98 |
+
"No entiendo la calculadora, quiero men煤s tipo": {
|
| 99 |
+
"text": "No entiendo la calculadora, quiero men煤s tipo",
|
| 100 |
+
"value": " | no data"
|
| 101 |
+
}
|
| 102 |
+
},
|
| 103 |
+
{
|
| 104 |
+
"No cost贸 nada": {
|
| 105 |
+
"text": "No cost贸 nada",
|
| 106 |
+
"value": " | no costo"
|
| 107 |
+
}
|
| 108 |
+
},
|
| 109 |
+
{
|
| 110 |
+
"Cost贸 demasiado, s煤beme macros": {
|
| 111 |
+
"text": "Cost贸 demasiado, s煤beme macros",
|
| 112 |
+
"value": " | costo subir macros"
|
| 113 |
+
}
|
| 114 |
+
},
|
| 115 |
+
{
|
| 116 |
+
"Cost贸 demasiado, b谩jame macros": {
|
| 117 |
+
"text": "Cost贸 demasiado, b谩jame macros",
|
| 118 |
+
"value": " | costo bajar macros"
|
| 119 |
+
}
|
| 120 |
+
},
|
| 121 |
+
{
|
| 122 |
+
"Cost贸, pero me adapto a nuevos ajustes": {
|
| 123 |
+
"text": "Cost贸, pero me adapto a nuevos ajustes",
|
| 124 |
+
"value": " | costo y me adapto a nuevos ajustes"
|
| 125 |
+
}
|
| 126 |
+
},
|
| 127 |
+
{
|
| 128 |
+
"Iba a coger men煤s tipo, pero al final por precio no": {
|
| 129 |
+
"text": "Iba a coger men煤s tipo, pero al final por precio no",
|
| 130 |
+
"value": " | no data"
|
| 131 |
+
}
|
| 132 |
+
}
|
| 133 |
]
|
| 134 |
|
| 135 |
opciones_objetivo = [
|
| 136 |
+
{
|
| 137 |
+
"definici贸n (nada cambia)": {
|
| 138 |
+
"text": "definici贸n (nada cambia)",
|
| 139 |
+
"value": " | definicion"
|
| 140 |
+
}
|
| 141 |
+
},
|
| 142 |
+
{
|
| 143 |
+
"empezamos a definir (cambia)": {
|
| 144 |
+
"text": "empezamos a definir (cambia)",
|
| 145 |
+
"value": " | definicion"
|
| 146 |
+
}
|
| 147 |
+
},
|
| 148 |
+
{
|
| 149 |
+
"perder peso (nada cambia)": {
|
| 150 |
+
"text": "perder peso (nada cambia)",
|
| 151 |
+
"value": " | definicion"
|
| 152 |
+
}
|
| 153 |
+
},
|
| 154 |
+
{
|
| 155 |
+
"volumen (nada cambia)": {
|
| 156 |
+
"text": "volumen (nada cambia)",
|
| 157 |
+
"value": " | volumen"
|
| 158 |
+
}
|
| 159 |
+
},
|
| 160 |
+
{
|
| 161 |
+
"empezamos a coger volumen (cambia)": {
|
| 162 |
+
"text": "empezamos a coger volumen (cambia)",
|
| 163 |
+
"value": " | volumen"
|
| 164 |
+
}
|
| 165 |
+
},
|
| 166 |
+
{
|
| 167 |
+
"empezamos a coger volumen, sobre todo tren inferior (cambia)": {
|
| 168 |
+
"text": "empezamos a coger volumen, sobre todo tren inferior (cambia)",
|
| 169 |
+
"value": " | volumen"
|
| 170 |
+
}
|
| 171 |
+
},
|
| 172 |
+
{
|
| 173 |
+
"empezamos a coger volumen, en todo el cuerpo (cambia)": {
|
| 174 |
+
"text": "empezamos a coger volumen, en todo el cuerpo (cambia)",
|
| 175 |
+
"value": " | volumen"
|
| 176 |
+
}
|
| 177 |
+
}
|
| 178 |
]
|
| 179 |
|
| 180 |
opciones_cumplimiento_entrenamiento = [
|
| 181 |
+
{
|
| 182 |
+
"Lo hice perfecto": {
|
| 183 |
+
"text": "Lo hice perfecto",
|
| 184 |
+
"value": " | bien"
|
| 185 |
+
}
|
| 186 |
+
},
|
| 187 |
+
{
|
| 188 |
+
"He fallado algunos d铆as, pero s铆": {
|
| 189 |
+
"text": "He fallado algunos d铆as, pero s铆",
|
| 190 |
+
"value": " | bien"
|
| 191 |
+
}
|
| 192 |
+
},
|
| 193 |
+
{
|
| 194 |
+
"Lesi贸n importante": {
|
| 195 |
+
"text": "Lesi贸n importante",
|
| 196 |
+
"value": " | mal"
|
| 197 |
+
}
|
| 198 |
+
},
|
| 199 |
+
{
|
| 200 |
+
"Lo hice pr谩cticamente perfecto": {
|
| 201 |
+
"text": "Lo hice pr谩cticamente perfecto",
|
| 202 |
+
"value": " | bien"
|
| 203 |
+
}
|
| 204 |
+
},
|
| 205 |
+
{
|
| 206 |
+
"Peque帽a lesi贸n": {
|
| 207 |
+
"text": "Peque帽a lesi贸n",
|
| 208 |
+
"value": " | mal"
|
| 209 |
+
}
|
| 210 |
+
},
|
| 211 |
+
{
|
| 212 |
+
"No hice nada, mantenemos la rutina un mes m谩s": {
|
| 213 |
+
"text": "No hice nada, mantenemos la rutina un mes m谩s",
|
| 214 |
+
"value": " | mal"
|
| 215 |
+
}
|
| 216 |
+
},
|
| 217 |
+
{
|
| 218 |
+
"Al谩rgame la rutina una semana m谩s": {
|
| 219 |
+
"text": "Al谩rgame la rutina una semana m谩s",
|
| 220 |
+
"value": " | mal"
|
| 221 |
+
}
|
| 222 |
+
}
|
| 223 |
]
|
| 224 |
|
| 225 |
opciones_cumplimiento_dieta = [
|
| 226 |
+
{
|
| 227 |
+
"al 70%": {
|
| 228 |
+
"text": "al 70%",
|
| 229 |
+
"value": " | bien"
|
| 230 |
+
}
|
| 231 |
+
},
|
| 232 |
+
{
|
| 233 |
+
"regular, me cuesta llegar": {
|
| 234 |
+
"text": "regular, me cuesta llegar",
|
| 235 |
+
"value": " | regular"
|
| 236 |
+
}
|
| 237 |
+
},
|
| 238 |
+
{
|
| 239 |
+
"Nada, mant茅n mis macros": {
|
| 240 |
+
"text": "Nada, mant茅n mis macros",
|
| 241 |
+
"value": " | mal"
|
| 242 |
+
}
|
| 243 |
+
},
|
| 244 |
+
{
|
| 245 |
+
"casi perfecta": {
|
| 246 |
+
"text": "casi perfecta",
|
| 247 |
+
"value": " | bien"
|
| 248 |
+
}
|
| 249 |
+
},
|
| 250 |
+
{
|
| 251 |
+
"regular, me salto la dieta": {
|
| 252 |
+
"text": "regular, me salto la dieta",
|
| 253 |
+
"value": " | regular"
|
| 254 |
+
}
|
| 255 |
+
},
|
| 256 |
+
{
|
| 257 |
+
"Perfecta": {
|
| 258 |
+
"text": "Perfecta",
|
| 259 |
+
"value": " | bien"
|
| 260 |
+
}
|
| 261 |
+
}
|
| 262 |
]
|
| 263 |
|
| 264 |
opciones_compromiso = [
|
| 265 |
+
{
|
| 266 |
+
"Bueno, pero mejorable": {
|
| 267 |
+
"text": "Bueno, pero mejorable",
|
| 268 |
+
"value": " | bueno"
|
| 269 |
+
}
|
| 270 |
+
},
|
| 271 |
+
{
|
| 272 |
+
"Mal, pero a partir de ahora voy a por todas": {
|
| 273 |
+
"text": "Mal, pero a partir de ahora voy a por todas",
|
| 274 |
+
"value": " | mal"
|
| 275 |
+
}
|
| 276 |
+
},
|
| 277 |
+
{
|
| 278 |
+
"Mal, demasiado exigente": {
|
| 279 |
+
"text": "Mal, demasiado exigente",
|
| 280 |
+
"value": " | mal"
|
| 281 |
+
}
|
| 282 |
+
},
|
| 283 |
+
{
|
| 284 |
+
"M谩ximo": {
|
| 285 |
+
"text": "M谩ximo",
|
| 286 |
+
"value": " | bueno"
|
| 287 |
+
}
|
| 288 |
+
}
|
| 289 |
]
|
| 290 |
|
| 291 |
# Creamos la interfaz
|
| 292 |
with gr.Blocks() as demo:
|
| 293 |
+
# Definimos el color naranja
|
| 294 |
+
naranja = "#FF9300"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 295 |
|
| 296 |
+
# Procesamos las opciones para obtener solo los textos
|
| 297 |
+
textos_esfuerzo = [list(opcion.values())[0]["text"] for opcion in opciones_esfuerzo]
|
| 298 |
+
textos_objetivo = [list(opcion.values())[0]["text"] for opcion in opciones_objetivo]
|
| 299 |
+
textos_cumplimiento_entr = [list(opcion.values())[0]["text"] for opcion in opciones_cumplimiento_entrenamiento]
|
| 300 |
+
textos_cumplimiento_dieta = [list(opcion.values())[0]["text"] for opcion in opciones_cumplimiento_dieta]
|
| 301 |
+
textos_compromiso = [list(opcion.values())[0]["text"] for opcion in opciones_compromiso]
|
| 302 |
|
| 303 |
+
# Entradas
|
| 304 |
with gr.Row():
|
| 305 |
+
esfuerzo = gr.Dropdown(
|
| 306 |
+
choices=textos_esfuerzo,
|
| 307 |
+
label="Esfuerzo dieta",
|
| 308 |
+
value="No cost贸 nada"
|
| 309 |
+
)
|
| 310 |
+
cumplimiento_dieta = gr.Dropdown(
|
| 311 |
+
choices=textos_cumplimiento_dieta,
|
| 312 |
+
label="Cumplimiento de la dieta",
|
| 313 |
+
value="Perfecta"
|
| 314 |
+
)
|
| 315 |
+
objetivo = gr.Dropdown(
|
| 316 |
+
choices=textos_objetivo,
|
| 317 |
+
label="Objetivo",
|
| 318 |
+
value="volumen (nada cambia)"
|
| 319 |
+
)
|
| 320 |
with gr.Row():
|
| 321 |
+
cumplimiento_entr = gr.Dropdown(
|
| 322 |
+
choices=textos_cumplimiento_entr,
|
| 323 |
+
label="Cumplimiento del entrenamiento",
|
| 324 |
+
value="Lo hice perfecto"
|
| 325 |
+
)
|
| 326 |
+
compromiso = gr.Dropdown(
|
| 327 |
+
choices=textos_compromiso,
|
| 328 |
+
label="Compromiso",
|
| 329 |
+
value="M谩ximo"
|
| 330 |
+
)
|
| 331 |
+
variacion_peso = gr.Number(
|
| 332 |
+
label="Variaci贸n de peso",
|
| 333 |
+
precision=2,
|
| 334 |
+
value=0.7
|
| 335 |
+
)
|
| 336 |
|
| 337 |
+
# Versi贸n simple del bot贸n
|
| 338 |
+
calcular_btn = gr.Button(
|
| 339 |
+
"Calcular",
|
| 340 |
+
variant="primary",
|
| 341 |
+
size="lg"
|
| 342 |
+
)
|
| 343 |
+
|
| 344 |
+
# A帽adimos el estilo CSS personalizado
|
| 345 |
+
css = f"""
|
| 346 |
+
<style>
|
| 347 |
+
#boton-naranja {{
|
| 348 |
+
background-color: {naranja} !important;
|
| 349 |
+
border: 1px solid {naranja} !important;
|
| 350 |
+
}}
|
| 351 |
+
#boton-naranja:hover {{
|
| 352 |
+
background-color: {naranja}DD !important;
|
| 353 |
+
border: 1px solid {naranja}DD !important;
|
| 354 |
+
}}
|
| 355 |
+
</style>
|
| 356 |
+
"""
|
| 357 |
+
|
| 358 |
+
css_outputs = """
|
| 359 |
+
<style>
|
| 360 |
+
.output-row {
|
| 361 |
+
align-items: flex-end !important;
|
| 362 |
+
display: flex !important;
|
| 363 |
+
gap: 1rem !important;
|
| 364 |
+
}
|
| 365 |
+
.output-row > * {
|
| 366 |
+
flex: 1;
|
| 367 |
+
min-width: 0;
|
| 368 |
+
}
|
| 369 |
+
</style>
|
| 370 |
+
"""
|
| 371 |
+
|
| 372 |
+
gr.Markdown(css + css_outputs)
|
| 373 |
+
|
| 374 |
+
# Salidas
|
| 375 |
+
with gr.Row(elem_classes="output-row"):
|
| 376 |
+
proteina_entreno = gr.Textbox(label="Prote铆na d铆a de entreno (g)")
|
| 377 |
+
carbs_entreno = gr.Textbox(label="Carbohidratos d铆a de entreno (g)")
|
| 378 |
+
grasas_entreno = gr.Textbox(label="Grasas d铆a de entreno (g)")
|
| 379 |
+
proteina_intra = gr.Textbox(label="Prote铆na intraentreno (g)")
|
| 380 |
+
carbs_intra = gr.Textbox(label="Carbohidratos intraentreno (g)")
|
| 381 |
+
proteina_descanso = gr.Textbox(label="Prote铆na d铆a de descanso (g)")
|
| 382 |
+
carbs_descanso = gr.Textbox(label="Carbohidratos d铆a de descanso (g)")
|
| 383 |
+
grasas_descanso = gr.Textbox(label="Grasas d铆a de descanso (g)")
|
| 384 |
|
| 385 |
# Conectamos el bot贸n con la funci贸n
|
| 386 |
calcular_btn.click(
|
create_new_formularios.py
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pathlib import Path
|
| 2 |
+
import json
|
| 3 |
+
from datetime import datetime
|
| 4 |
+
from tqdm import tqdm
|
| 5 |
+
|
| 6 |
+
# Paths
|
| 7 |
+
formularios_path = 'formularios'
|
| 8 |
+
formularios_weight_difference_path = 'formularios_weight_difference'
|
| 9 |
+
|
| 10 |
+
# Get sorted date keys
|
| 11 |
+
def get_sorted_date_keys(data):
|
| 12 |
+
keys = list(data.keys())
|
| 13 |
+
keys_dates = []
|
| 14 |
+
for key in keys:
|
| 15 |
+
try:
|
| 16 |
+
keys_dates.append(datetime.strptime(key, '%Y-%m-%d'))
|
| 17 |
+
except ValueError:
|
| 18 |
+
pass
|
| 19 |
+
keys_sorted = sorted(keys_dates)
|
| 20 |
+
keys_sorted = [key.strftime('%Y-%m-%d') for key in keys_sorted]
|
| 21 |
+
keys_sorted = [key.replace('-01', '-1') for key in keys_sorted]
|
| 22 |
+
keys_sorted = [key.replace('-02', '-2') for key in keys_sorted]
|
| 23 |
+
keys_sorted = [key.replace('-03', '-3') for key in keys_sorted]
|
| 24 |
+
keys_sorted = [key.replace('-04', '-4') for key in keys_sorted]
|
| 25 |
+
keys_sorted = [key.replace('-05', '-5') for key in keys_sorted]
|
| 26 |
+
keys_sorted = [key.replace('-06', '-6') for key in keys_sorted]
|
| 27 |
+
keys_sorted = [key.replace('-07', '-7') for key in keys_sorted]
|
| 28 |
+
keys_sorted = [key.replace('-08', '-8') for key in keys_sorted]
|
| 29 |
+
keys_sorted = [key.replace('-09', '-9') for key in keys_sorted]
|
| 30 |
+
return keys_sorted
|
| 31 |
+
|
| 32 |
+
# Get non date keys
|
| 33 |
+
def get_non_date_keys(data):
|
| 34 |
+
keys = list(data.keys())
|
| 35 |
+
keys_non_dates = []
|
| 36 |
+
for key in keys:
|
| 37 |
+
try:
|
| 38 |
+
datetime.strptime(key, '%Y-%m-%d')
|
| 39 |
+
except ValueError:
|
| 40 |
+
keys_non_dates.append(key)
|
| 41 |
+
return keys_non_dates
|
| 42 |
+
|
| 43 |
+
# Add empty weight difference to all the dates
|
| 44 |
+
def add_empty_weight_difference(data):
|
| 45 |
+
data['diferencia_peso'] = 'None'
|
| 46 |
+
return data
|
| 47 |
+
|
| 48 |
+
# Change esfuerzo para cumplir dieta
|
| 49 |
+
def change_esfuerzo_para_cumplir_dieta(data):
|
| 50 |
+
# Get the date keys
|
| 51 |
+
data_date_keys = list(get_sorted_date_keys(data))
|
| 52 |
+
|
| 53 |
+
# Iterate over the date keys
|
| 54 |
+
for key in data_date_keys:
|
| 55 |
+
# If data hasn't 'esfuerzoParaCumplirDieta' key, create it
|
| 56 |
+
if 'esfuerzoParaCumplirDieta' not in data[key]:
|
| 57 |
+
data[key]['esfuerzoParaCumplirDieta'] = 'None | no data'
|
| 58 |
+
|
| 59 |
+
# If data has 'esfuerzoParaCumplirDieta' key, change it
|
| 60 |
+
if 'esfuerzoParaCumplirDieta' in data[key]:
|
| 61 |
+
if 'No entiendo la calculadora' in data[key]['esfuerzoParaCumplirDieta'] or 'Iba a coger men煤s tipo' in data[key]['esfuerzoParaCumplirDieta']:
|
| 62 |
+
data[key]['esfuerzoParaCumplirDieta'] += ' | No data'
|
| 63 |
+
elif 'Cost贸 demasiado, s煤beme macros' in data[key]['esfuerzoParaCumplirDieta']:
|
| 64 |
+
data[key]['esfuerzoParaCumplirDieta'] += ' | costo subir macros'
|
| 65 |
+
elif 'Cost贸 demasiado, b谩jame macros' in data[key]['esfuerzoParaCumplirDieta']:
|
| 66 |
+
data[key]['esfuerzoParaCumplirDieta'] += ' | costo bajar macros'
|
| 67 |
+
elif 'Cost贸, pero me adapto a nuevos ajustes' in data[key]['esfuerzoParaCumplirDieta']:
|
| 68 |
+
data[key]['esfuerzoParaCumplirDieta'] += ' | costo y me adapto a nuevos ajustes'
|
| 69 |
+
elif 'No cost贸 nada' in data[key]['esfuerzoParaCumplirDieta']:
|
| 70 |
+
data[key]['esfuerzoParaCumplirDieta'] += ' | no costo'
|
| 71 |
+
else:
|
| 72 |
+
data[key]['esfuerzoParaCumplirDieta'] += ' | no data'
|
| 73 |
+
return data
|
| 74 |
+
|
| 75 |
+
# Change cumplimiento dieta
|
| 76 |
+
def change_cumplimiento_dieta(data):
|
| 77 |
+
# Get the date keys
|
| 78 |
+
data_date_keys = list(get_sorted_date_keys(data))
|
| 79 |
+
|
| 80 |
+
# Iterate over the date keys
|
| 81 |
+
for key in data_date_keys:
|
| 82 |
+
# If data hasn't 'cumplimientoDieta' key, create it
|
| 83 |
+
if 'cumplimientoDieta' not in data[key]:
|
| 84 |
+
data[key]['cumplimientoDieta'] = 'None | no data'
|
| 85 |
+
|
| 86 |
+
# If data has 'cumplimientoDieta' key, change it
|
| 87 |
+
if 'cumplimientoDieta' in data[key]:
|
| 88 |
+
if 'al 70%' in data[key]['cumplimientoDieta'] or 'casi perfecta' in data[key]['cumplimientoDieta'] or 'Perfecta' in data[key]['cumplimientoDieta']:
|
| 89 |
+
data[key]['cumplimientoDieta'] += ' | bien'
|
| 90 |
+
elif 'regular, me cuesta llegar' in data[key]['cumplimientoDieta'] or 'regular, me salto la dieta' in data[key]['cumplimientoDieta']:
|
| 91 |
+
data[key]['cumplimientoDieta'] += ' | regular'
|
| 92 |
+
elif 'Nada, mant茅n mis macros' in data[key]['cumplimientoDieta']:
|
| 93 |
+
data[key]['cumplimientoDieta'] += ' | mal'
|
| 94 |
+
else:
|
| 95 |
+
data[key]['cumplimientoDieta'] += ' | no data'
|
| 96 |
+
return data
|
| 97 |
+
|
| 98 |
+
# Change objetivo
|
| 99 |
+
def change_objetivo(data):
|
| 100 |
+
# Get the date keys
|
| 101 |
+
data_date_keys = list(get_sorted_date_keys(data))
|
| 102 |
+
|
| 103 |
+
# Iterate over the date keys
|
| 104 |
+
for key in data_date_keys:
|
| 105 |
+
# If data hasn't 'objetivo' key, create it
|
| 106 |
+
if 'objetivo' not in data[key]:
|
| 107 |
+
data[key]['objetivo'] = 'None | no data'
|
| 108 |
+
|
| 109 |
+
# If data has 'objetivo' key, change it
|
| 110 |
+
if 'objetivo' in data[key]:
|
| 111 |
+
if 'definici贸n (nada cambia)' in data[key]['objetivo'] or 'empezamos a definir (cambia)' in data[key]['objetivo'] or 'perder peso (nada cambia)' in data[key]['objetivo']:
|
| 112 |
+
data[key]['objetivo'] += ' | definicion'
|
| 113 |
+
elif 'volumen (nada cambia)' in data[key]['objetivo'] or 'empezamos a coger volumen (cambia)' in data[key]['objetivo'] or 'empezamos a coger volumen, sobre todo tren inferior (cambia)' in data[key]['objetivo'] or 'empezamos a coger volumen, en todo el cuerpo (cambia)' in data[key]['objetivo']:
|
| 114 |
+
data[key]['objetivo'] += ' | volumen'
|
| 115 |
+
else:
|
| 116 |
+
data[key]['objetivo'] += ' | no data'
|
| 117 |
+
return data
|
| 118 |
+
|
| 119 |
+
# Change cumplimientoEntrenamiento
|
| 120 |
+
def change_cumplimiento_entrenamiento(data):
|
| 121 |
+
# Get the date keys
|
| 122 |
+
data_date_keys = list(get_sorted_date_keys(data))
|
| 123 |
+
|
| 124 |
+
# Iterate over the date keys
|
| 125 |
+
for key in data_date_keys:
|
| 126 |
+
# If data hasn't 'cumplimientoEntrenamiento' key, create it
|
| 127 |
+
if 'cumplimientoEntrenamiento' not in data[key]:
|
| 128 |
+
data[key]['cumplimientoEntrenamiento'] = 'None | no data'
|
| 129 |
+
|
| 130 |
+
# If data has 'cumplimientoEntrenamiento' key, change it
|
| 131 |
+
if 'cumplimientoEntrenamiento' in data[key]:
|
| 132 |
+
if 'Lo hice perfecto' in data[key]['cumplimientoEntrenamiento'] or 'He fallado algunos d铆as, pero s铆' in data[key]['cumplimientoEntrenamiento'] or 'Lo hice pr谩cticamente perfecto' in data[key]['cumplimientoEntrenamiento']:
|
| 133 |
+
data[key]['cumplimientoEntrenamiento'] += ' | bien'
|
| 134 |
+
elif 'Lesi贸n importante' in data[key]['cumplimientoEntrenamiento'] or 'Peque帽a lesi贸n' in data[key]['cumplimientoEntrenamiento'] or 'No hice nada, mantenemos la rutina un mes m谩s' in data[key]['cumplimientoEntrenamiento'] or 'Al谩rgame la rutina una semana m谩s' in data[key]['cumplimientoEntrenamiento']:
|
| 135 |
+
data[key]['cumplimientoEntrenamiento'] += ' | mal'
|
| 136 |
+
else:
|
| 137 |
+
data[key]['cumplimientoEntrenamiento'] += ' | no data'
|
| 138 |
+
return data
|
| 139 |
+
|
| 140 |
+
# Change compromiso
|
| 141 |
+
def change_compromiso(data):
|
| 142 |
+
# Get the date keys
|
| 143 |
+
data_date_keys = list(get_sorted_date_keys(data))
|
| 144 |
+
|
| 145 |
+
# Iterate over the date keys
|
| 146 |
+
for key in data_date_keys:
|
| 147 |
+
# If data hasn't 'compromiso' key, create it
|
| 148 |
+
if 'compromiso' not in data[key]:
|
| 149 |
+
data[key]['compromiso'] = 'None | no data'
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
# If data has 'compromiso' key, change it
|
| 153 |
+
if 'compromiso' in data[key]:
|
| 154 |
+
if 'Bueno, pero mejorable' in data[key]['compromiso'] or 'M谩ximo' in data[key]['compromiso']:
|
| 155 |
+
data[key]['compromiso'] += ' | bueno'
|
| 156 |
+
elif 'Mal, pero a partir de ahora voy a por todas' in data[key]['compromiso'] or 'Mal, demasiado exigente' in data[key]['compromiso']:
|
| 157 |
+
data[key]['compromiso'] += ' | mal'
|
| 158 |
+
else:
|
| 159 |
+
data[key]['compromiso'] += ' | no data'
|
| 160 |
+
return data
|
| 161 |
+
|
| 162 |
+
# Add real weight difference to all the dates
|
| 163 |
+
def add_real_weight_difference(data, keys_dates):
|
| 164 |
+
number_of_keys_dates = len(keys_dates)
|
| 165 |
+
for i in range(1,number_of_keys_dates):
|
| 166 |
+
data[keys_dates[i]]['diferencia_peso'] = data[keys_dates[i]]['peso'] - data[keys_dates[i-1]]['peso']
|
| 167 |
+
return data
|
| 168 |
+
|
| 169 |
+
if __name__ == '__main__':
|
| 170 |
+
# Get all the files in the formularios_path
|
| 171 |
+
files = Path(formularios_path).glob('*.json')
|
| 172 |
+
|
| 173 |
+
# Sort the files by name
|
| 174 |
+
# files = sorted(files, key=lambda x: x.name)
|
| 175 |
+
|
| 176 |
+
# Load all the files
|
| 177 |
+
for file in tqdm(files):
|
| 178 |
+
# Get data from the file
|
| 179 |
+
with open(file, 'r') as f:
|
| 180 |
+
data = json.load(f)
|
| 181 |
+
|
| 182 |
+
# Create new empty dictionary
|
| 183 |
+
data_sorted = {}
|
| 184 |
+
|
| 185 |
+
# Get the date and non date keys
|
| 186 |
+
keys_dates = get_sorted_date_keys(data)
|
| 187 |
+
keys_non_dates = get_non_date_keys(data)
|
| 188 |
+
|
| 189 |
+
# Add empty weight difference to all the dates
|
| 190 |
+
for key_date in keys_dates:
|
| 191 |
+
data[key_date] = add_empty_weight_difference(data[key_date])
|
| 192 |
+
|
| 193 |
+
# Add real weight difference to all the dates
|
| 194 |
+
data = add_real_weight_difference(data, keys_dates)
|
| 195 |
+
|
| 196 |
+
# Change esfuerzo para cumplir dieta
|
| 197 |
+
data = change_esfuerzo_para_cumplir_dieta(data)
|
| 198 |
+
|
| 199 |
+
# Change cumplimiebto dieta
|
| 200 |
+
data = change_cumplimiento_dieta(data)
|
| 201 |
+
|
| 202 |
+
# Change objetivo
|
| 203 |
+
data = change_objetivo(data)
|
| 204 |
+
|
| 205 |
+
# Change cumplimientoEntrenamiento
|
| 206 |
+
data = change_cumplimiento_entrenamiento(data)
|
| 207 |
+
|
| 208 |
+
# Change compromiso
|
| 209 |
+
data = change_compromiso(data)
|
| 210 |
+
|
| 211 |
+
# Sort the keys
|
| 212 |
+
sorted_keys = keys_non_dates + keys_dates
|
| 213 |
+
|
| 214 |
+
# Add the sorted keys to the new dictionary
|
| 215 |
+
for key in sorted_keys:
|
| 216 |
+
data_sorted[key] = data[key]
|
| 217 |
+
|
| 218 |
+
# Save the data to the file
|
| 219 |
+
file_path = Path(formularios_weight_difference_path) / file.name
|
| 220 |
+
with open(file_path, 'w') as f:
|
| 221 |
+
json.dump(data_sorted, f, indent=4)
|
create_new_usuarios.py
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pathlib import Path
|
| 2 |
+
import json
|
| 3 |
+
from datetime import datetime
|
| 4 |
+
from tqdm import tqdm
|
| 5 |
+
|
| 6 |
+
# Paths
|
| 7 |
+
usuarios_path = 'usuarios'
|
| 8 |
+
usuarios_macros_difference_path = 'usuarios_macros_difference'
|
| 9 |
+
|
| 10 |
+
# Get sorted date keys
|
| 11 |
+
def get_sorted_date_keys(data):
|
| 12 |
+
keys = list(data.keys())
|
| 13 |
+
keys_dates = []
|
| 14 |
+
for key in keys:
|
| 15 |
+
try:
|
| 16 |
+
keys_dates.append(datetime.strptime(key, '%Y-%m-%d'))
|
| 17 |
+
except ValueError:
|
| 18 |
+
pass
|
| 19 |
+
keys_sorted = sorted(keys_dates)
|
| 20 |
+
keys_sorted = [key.strftime('%Y-%m-%d') for key in keys_sorted]
|
| 21 |
+
keys_sorted = [key.replace('-01', '-1') for key in keys_sorted]
|
| 22 |
+
keys_sorted = [key.replace('-02', '-2') for key in keys_sorted]
|
| 23 |
+
keys_sorted = [key.replace('-03', '-3') for key in keys_sorted]
|
| 24 |
+
keys_sorted = [key.replace('-04', '-4') for key in keys_sorted]
|
| 25 |
+
keys_sorted = [key.replace('-05', '-5') for key in keys_sorted]
|
| 26 |
+
keys_sorted = [key.replace('-06', '-6') for key in keys_sorted]
|
| 27 |
+
keys_sorted = [key.replace('-07', '-7') for key in keys_sorted]
|
| 28 |
+
keys_sorted = [key.replace('-08', '-8') for key in keys_sorted]
|
| 29 |
+
keys_sorted = [key.replace('-09', '-9') for key in keys_sorted]
|
| 30 |
+
return keys_sorted
|
| 31 |
+
|
| 32 |
+
# Get non date keys
|
| 33 |
+
def get_non_date_keys(data):
|
| 34 |
+
keys = list(data.keys())
|
| 35 |
+
keys_non_dates = []
|
| 36 |
+
for key in keys:
|
| 37 |
+
try:
|
| 38 |
+
datetime.strptime(key, '%Y-%m-%d')
|
| 39 |
+
except ValueError:
|
| 40 |
+
keys_non_dates.append(key)
|
| 41 |
+
return keys_non_dates
|
| 42 |
+
|
| 43 |
+
# Get macros from string data
|
| 44 |
+
def get_macros_from_string(data):
|
| 45 |
+
macros = data.split(' ')
|
| 46 |
+
if len(macros) != 8:
|
| 47 |
+
return None
|
| 48 |
+
for i, macro in enumerate(macros):
|
| 49 |
+
if '.' in macro:
|
| 50 |
+
macro = macro.split('.')[0]
|
| 51 |
+
macros[i] = macro
|
| 52 |
+
if macro == '':
|
| 53 |
+
return None
|
| 54 |
+
macros = [int(macro) for macro in macros]
|
| 55 |
+
is_all_numbers = all((type(macro)==int or type(macro)==float) for macro in macros)
|
| 56 |
+
if not is_all_numbers:
|
| 57 |
+
return None
|
| 58 |
+
return macros
|
| 59 |
+
|
| 60 |
+
# Add empty weight difference to all the dates
|
| 61 |
+
def add_empty_macros_difference(data):
|
| 62 |
+
new_data = {}
|
| 63 |
+
new_data['macros'] = data
|
| 64 |
+
new_data['diferencia_macros'] = '0 0 0 0 0 0 0 0'
|
| 65 |
+
return new_data
|
| 66 |
+
|
| 67 |
+
# Add real macros difference to all the dates
|
| 68 |
+
def add_real_macros_difference(data, keys_dates):
|
| 69 |
+
# Get the number of keys dates
|
| 70 |
+
number_of_keys_dates = len(keys_dates)
|
| 71 |
+
|
| 72 |
+
# Iterate over the keys dates
|
| 73 |
+
for i in range(1,number_of_keys_dates):
|
| 74 |
+
# Get the previous macros
|
| 75 |
+
previous_macros = data[keys_dates[i-1]]['macros']
|
| 76 |
+
previous_macros = get_macros_from_string(previous_macros)
|
| 77 |
+
if previous_macros is None:
|
| 78 |
+
return data
|
| 79 |
+
|
| 80 |
+
# Get the current macros
|
| 81 |
+
current_macros = data[keys_dates[i]]['macros']
|
| 82 |
+
current_macros = get_macros_from_string(current_macros)
|
| 83 |
+
if current_macros is None:
|
| 84 |
+
return data
|
| 85 |
+
|
| 86 |
+
# Calculate the difference
|
| 87 |
+
diferencia_macros = [current_macros[i] - previous_macros[i] for i in range(8)]
|
| 88 |
+
diferencia_macros = ' '.join(str(diferencia) for diferencia in diferencia_macros)
|
| 89 |
+
|
| 90 |
+
# Add the difference to the data
|
| 91 |
+
data[keys_dates[i]]['diferencia_macros'] = diferencia_macros
|
| 92 |
+
return data
|
| 93 |
+
|
| 94 |
+
if __name__ == '__main__':
|
| 95 |
+
# Get all the files in the formularios_path
|
| 96 |
+
files = Path(usuarios_path).glob('*.json')
|
| 97 |
+
|
| 98 |
+
# Sort the files by name
|
| 99 |
+
files = sorted(files, key=lambda x: x.name)
|
| 100 |
+
|
| 101 |
+
# Load all the files
|
| 102 |
+
for file in tqdm(files):
|
| 103 |
+
# Get data from the file
|
| 104 |
+
with open(file, 'r') as f:
|
| 105 |
+
data = json.load(f)
|
| 106 |
+
|
| 107 |
+
# Create new empty dictionary
|
| 108 |
+
data_sorted = {}
|
| 109 |
+
|
| 110 |
+
# Get the date and non date keys
|
| 111 |
+
keys_dates = get_sorted_date_keys(data)
|
| 112 |
+
keys_non_dates = get_non_date_keys(data)
|
| 113 |
+
|
| 114 |
+
# Add empty weight difference to all the dates
|
| 115 |
+
for key_date in keys_dates:
|
| 116 |
+
data[key_date] = add_empty_macros_difference(data[key_date])
|
| 117 |
+
|
| 118 |
+
# Add real weight difference to all the dates
|
| 119 |
+
data = add_real_macros_difference(data, keys_dates)
|
| 120 |
+
|
| 121 |
+
# Concatenate the non date keys and the date keys
|
| 122 |
+
sorted_keys = keys_non_dates + keys_dates
|
| 123 |
+
|
| 124 |
+
# Add the sorted keys to the new dictionary
|
| 125 |
+
for key in sorted_keys:
|
| 126 |
+
data_sorted[key] = data[key]
|
| 127 |
+
|
| 128 |
+
# Save the data to the file
|
| 129 |
+
file_path = Path(usuarios_macros_difference_path) / file.name
|
| 130 |
+
with open(file_path, 'w') as f:
|
| 131 |
+
json.dump(data_sorted, f, indent=4)
|
find_matches.py
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pathlib import Path
|
| 2 |
+
import json
|
| 3 |
+
from queries import query_formularios, query_usuarios, get_macros_differences
|
| 4 |
+
|
| 5 |
+
formularios_weight_difference_path = 'anonymized_formularios_weight_difference'
|
| 6 |
+
usuarios_macros_difference_path = 'usuarios_macros_difference'
|
| 7 |
+
|
| 8 |
+
# Find users dates that match the query
|
| 9 |
+
def find_user_dates_matches(query, debug=False):
|
| 10 |
+
# Create a dictionary to store the matches
|
| 11 |
+
matches_dict = {}
|
| 12 |
+
|
| 13 |
+
# Get all the files in the formularios_path
|
| 14 |
+
files = Path(formularios_weight_difference_path).glob('*.json')
|
| 15 |
+
files = list(files)
|
| 16 |
+
files.sort()
|
| 17 |
+
|
| 18 |
+
# Iterate over the user data
|
| 19 |
+
for i, file in enumerate(files):
|
| 20 |
+
with open(file, 'r') as f:
|
| 21 |
+
data = json.load(f)
|
| 22 |
+
|
| 23 |
+
if file.name == '_albertino_06@hotmail.com.json':
|
| 24 |
+
dates = query_formularios(data, query, debug=False, file_name=file.name)
|
| 25 |
+
else:
|
| 26 |
+
dates = query_formularios(data, query, debug=debug)
|
| 27 |
+
if len(dates) > 0:
|
| 28 |
+
file_name = file.name
|
| 29 |
+
matches_dict[file_name] = dates
|
| 30 |
+
if debug:
|
| 31 |
+
if i > 0:
|
| 32 |
+
print("")
|
| 33 |
+
print(f"{file_name} has {len(dates)} dates that match the query:")
|
| 34 |
+
for date in dates:
|
| 35 |
+
print(f"\t{date}")
|
| 36 |
+
for query_item in query:
|
| 37 |
+
key = list(query_item.keys())[0]
|
| 38 |
+
data_value = data[date][key]
|
| 39 |
+
query_value = query_item[key]['value']
|
| 40 |
+
operator = query_item[key]['operator']
|
| 41 |
+
if type(data_value) == int or type(data_value) == float:
|
| 42 |
+
data_value = f"{data_value:.2f}"
|
| 43 |
+
if operator == 'in' or operator == 'contains':
|
| 44 |
+
print(f"\t\t{key} data: \"{data_value}\", query: \"{query_value}\"")
|
| 45 |
+
else:
|
| 46 |
+
print(f"\t\t{key} data: \"{data_value}\" \"{operator}\" query: \"{query_value}\"")
|
| 47 |
+
|
| 48 |
+
return matches_dict
|
| 49 |
+
|
| 50 |
+
def find_macros_that_match_dates_of_users(matches_dict, debug=False):
|
| 51 |
+
# Create a list to store the macros differences
|
| 52 |
+
macros_differences_list = []
|
| 53 |
+
|
| 54 |
+
# Iterate over the matches dictionary
|
| 55 |
+
for match_user in matches_dict:
|
| 56 |
+
if debug: print(f"match_user: {match_user}")
|
| 57 |
+
|
| 58 |
+
# Get dates list
|
| 59 |
+
dates_list_from_user = matches_dict[match_user]
|
| 60 |
+
|
| 61 |
+
# Get user data
|
| 62 |
+
user_data = usuarios_macros_difference_path + '/' + match_user
|
| 63 |
+
user_data = json.load(open(user_data, 'r'))
|
| 64 |
+
|
| 65 |
+
# Query usuarios
|
| 66 |
+
dates_that_match = query_usuarios(user_data, dates_list_from_user, debug=False, limit_days=31)
|
| 67 |
+
if len(dates_that_match) > 0:
|
| 68 |
+
if debug: print(f"\tdates that match: {dates_that_match}")
|
| 69 |
+
|
| 70 |
+
# Get macros differences
|
| 71 |
+
macros_differences = get_macros_differences(user_data, dates_that_match)
|
| 72 |
+
if type(macros_differences) == list:
|
| 73 |
+
if len(macros_differences) > 0:
|
| 74 |
+
for macros_difference in macros_differences:
|
| 75 |
+
macros_differences_list.append(macros_difference)
|
| 76 |
+
if debug: print(f"\tmacros_differences: {macros_difference}")
|
| 77 |
+
if debug: print("")
|
| 78 |
+
else:
|
| 79 |
+
macros_differences_list.append(macros_differences)
|
| 80 |
+
if debug: print(f"\tmacros_differences: {macros_differences}\n")
|
| 81 |
+
|
| 82 |
+
return macros_differences_list
|
queries.py
ADDED
|
@@ -0,0 +1,685 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from create_new_formularios import get_sorted_date_keys
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
from datetime import datetime
|
| 4 |
+
from create_new_usuarios import get_macros_from_string
|
| 5 |
+
import statistics
|
| 6 |
+
|
| 7 |
+
def query_formularios(data, query_list, debug=False, file_name=None):
|
| 8 |
+
|
| 9 |
+
if file_name is not None:
|
| 10 |
+
debug = True
|
| 11 |
+
print(f"***************** file_name: {file_name} *****************")
|
| 12 |
+
|
| 13 |
+
# Get date keys
|
| 14 |
+
date_keys = get_sorted_date_keys(data)
|
| 15 |
+
if debug: print(f"\n\n\ndate_keys: {date_keys}")
|
| 16 |
+
|
| 17 |
+
# List of date keys that match the query
|
| 18 |
+
date_keys_that_match = []
|
| 19 |
+
|
| 20 |
+
# No data value
|
| 21 |
+
no_data_value = "| no data"
|
| 22 |
+
|
| 23 |
+
# Get all the keys in the query_list
|
| 24 |
+
queries_list = []
|
| 25 |
+
for query in query_list:
|
| 26 |
+
queries_list.append(query)
|
| 27 |
+
if debug:
|
| 28 |
+
print("queries_list:")
|
| 29 |
+
for query in queries_list:
|
| 30 |
+
for key in query.keys():
|
| 31 |
+
print(f"\tkey: {key}", end=" --> ")
|
| 32 |
+
for second_key in query[key].keys():
|
| 33 |
+
print(f"{key}: {query[key][second_key]}", end=", ")
|
| 34 |
+
print("")
|
| 35 |
+
|
| 36 |
+
# For each date key get all the keys
|
| 37 |
+
for date_key in date_keys:
|
| 38 |
+
if debug: print(f"\n * date_key: {date_key}")
|
| 39 |
+
|
| 40 |
+
# match is a boolean that will be true if the key is in query_dict
|
| 41 |
+
match = False
|
| 42 |
+
if debug: print(f"\tinitial match value: {match}")
|
| 43 |
+
|
| 44 |
+
# Get all the keys in the data
|
| 45 |
+
data_keys = data[date_key].keys()
|
| 46 |
+
if debug: print(f"\tkeys: {data_keys}")
|
| 47 |
+
|
| 48 |
+
# Find for each key if it is in query_dict
|
| 49 |
+
for query in queries_list:
|
| 50 |
+
# Get the query key
|
| 51 |
+
query_key = list(query.keys())[0]
|
| 52 |
+
|
| 53 |
+
# Get the query operator and value
|
| 54 |
+
query_operator = query[query_key]['operator']
|
| 55 |
+
is_operator_for_numbers = query_operator == '>' or query_operator == '<' or query_operator == '>=' or query_operator == '<='
|
| 56 |
+
query_value = query[query_key]['value']
|
| 57 |
+
type_of_query_value = type(query_value)
|
| 58 |
+
is_query_value_string = type_of_query_value == str
|
| 59 |
+
is_query_value_number = type_of_query_value == int or type_of_query_value == float
|
| 60 |
+
|
| 61 |
+
# Check if the query key is in the data
|
| 62 |
+
if query_key in data_keys:
|
| 63 |
+
# Get the data value
|
| 64 |
+
data_value = data[date_key][query_key]
|
| 65 |
+
type_of_data_value = type(data_value)
|
| 66 |
+
is_data_value_string = type_of_data_value == str
|
| 67 |
+
is_data_value_number = type_of_data_value == int or type_of_data_value == float
|
| 68 |
+
is_data_value_and_query_value_number = is_data_value_number and is_query_value_number
|
| 69 |
+
is_data_value_and_query_value_string = is_data_value_string and is_query_value_string
|
| 70 |
+
is_data_value_or_query_value_number = is_data_value_number or is_query_value_number
|
| 71 |
+
is_data_value_or_query_value_string = is_data_value_string or is_query_value_string
|
| 72 |
+
if debug: print(f"\t\tchecking \"{query_key}\" in data, query operator: \"{query_operator}\", query value: \"{query_value}\", data value: \"{data_value}\"")
|
| 73 |
+
|
| 74 |
+
# Check if the data value matches the query value
|
| 75 |
+
if query_operator == '==':
|
| 76 |
+
if query_value == data_value:
|
| 77 |
+
match = True
|
| 78 |
+
if debug: print(f"\t\t\t\"{query_value}\" is equal to \"{data_value}\", match: {match}")
|
| 79 |
+
else:
|
| 80 |
+
match = False
|
| 81 |
+
if debug: print(f"\t\t\t\"{query_value}\" is NOT equal to \"{data_value}\", match: {match}")
|
| 82 |
+
break
|
| 83 |
+
# continue
|
| 84 |
+
elif query_operator == '!=':
|
| 85 |
+
if query_value != data_value:
|
| 86 |
+
match = True
|
| 87 |
+
if debug: print(f"\t\t\t\"{query_value}\" is NOT equal to \"{data_value}\", match: {match}")
|
| 88 |
+
else:
|
| 89 |
+
match = False
|
| 90 |
+
if debug: print(f"\t\t\t\"{query_value}\" is NOT equal to \"{data_value}\", match: {match}")
|
| 91 |
+
break
|
| 92 |
+
# continue
|
| 93 |
+
elif is_query_value_number and is_data_value_number and query_operator == '>':
|
| 94 |
+
if data_value > query_value:
|
| 95 |
+
match = True
|
| 96 |
+
if debug: print(f"\t\t\t\"{query_value}\" is greater than \"{data_value}\", match: {match}")
|
| 97 |
+
else:
|
| 98 |
+
match = False
|
| 99 |
+
if debug: print(f"\t\t\t\"{query_value}\" is NOT greater than \"{data_value}\", match: {match}")
|
| 100 |
+
break
|
| 101 |
+
# continue
|
| 102 |
+
elif is_query_value_number and is_data_value_number and query_operator == '<':
|
| 103 |
+
if data_value < query_value:
|
| 104 |
+
match = True
|
| 105 |
+
if debug: print(f"\t\t\t\"{query_value}\" is less than \"{data_value}\", match: {match}")
|
| 106 |
+
else:
|
| 107 |
+
match = False
|
| 108 |
+
if debug: print(f"\t\t\t\"{query_value}\" is NOT less than \"{data_value}\", match: {match}")
|
| 109 |
+
break
|
| 110 |
+
# continue
|
| 111 |
+
elif is_query_value_number and is_data_value_number and query_operator == '>=':
|
| 112 |
+
if data_value >= query_value:
|
| 113 |
+
match = True
|
| 114 |
+
if debug: print(f"\t\t\t\"{query_value}\" is greater than or equal to \"{data_value}\", match: {match}")
|
| 115 |
+
else:
|
| 116 |
+
match = False
|
| 117 |
+
if debug: print(f"\t\t\t\"{query_value}\" is NOT greater than or equal to \"{data_value}\", match: {match}")
|
| 118 |
+
break
|
| 119 |
+
# continue
|
| 120 |
+
elif is_query_value_number and is_data_value_number and query_operator == '<=':
|
| 121 |
+
if data_value <= query_value:
|
| 122 |
+
match = True
|
| 123 |
+
if debug: print(f"\t\t\t\"{query_value}\" is less than or equal to \"{data_value}\", match: {match}")
|
| 124 |
+
else:
|
| 125 |
+
match = False
|
| 126 |
+
if debug: print(f"\t\t\t\"{query_value}\" is NOT less than or equal to \"{data_value}\", match: {match}")
|
| 127 |
+
break
|
| 128 |
+
# continue
|
| 129 |
+
elif is_query_value_string and is_data_value_string and query_operator == 'in' or query_operator == 'contains':
|
| 130 |
+
if query_value in data_value or no_data_value in data_value:
|
| 131 |
+
match = True
|
| 132 |
+
if debug: print(f"\t\t\t\"{query_value}\" is in \"{data_value}\", match: {match}")
|
| 133 |
+
else:
|
| 134 |
+
match = False
|
| 135 |
+
if debug: print(f"\t\t\t\"{query_value}\" is NOT in \"{data_value}\", match: {match}")
|
| 136 |
+
break
|
| 137 |
+
# continue
|
| 138 |
+
elif is_query_value_string and is_data_value_string and (query_operator == 'NOT in' or query_operator == 'NOT contains'):
|
| 139 |
+
if query_value not in data_value or no_data_value in data_value:
|
| 140 |
+
match = True
|
| 141 |
+
if debug: print(f"\t\t\t\"{query_value}\" is NOT in \"{data_value}\", match: {match}")
|
| 142 |
+
else:
|
| 143 |
+
match = False
|
| 144 |
+
if debug: print(f"\t\t\t\"{query_value}\" is NOT in \"{data_value}\", match: {match}")
|
| 145 |
+
break
|
| 146 |
+
# continue
|
| 147 |
+
elif query_operator == 'is null':
|
| 148 |
+
if data_value is None:
|
| 149 |
+
match = True
|
| 150 |
+
if debug: print(f"\t\t\t\"{query_value}\" is null, match: {match}")
|
| 151 |
+
else:
|
| 152 |
+
match = False
|
| 153 |
+
if debug: print(f"\t\t\t\"{query_value}\" is NOT null, match: {match}")
|
| 154 |
+
break
|
| 155 |
+
# continue
|
| 156 |
+
elif query_operator == 'is NOT null':
|
| 157 |
+
if data_value is not None:
|
| 158 |
+
match = True
|
| 159 |
+
if debug: print(f"\t\t\t\"{query_value}\" is NOT null, match: {match}")
|
| 160 |
+
else:
|
| 161 |
+
match = False
|
| 162 |
+
if debug: print(f"\t\t\t\"{query_value}\" is NOT null, match: {match}")
|
| 163 |
+
break
|
| 164 |
+
# continue
|
| 165 |
+
elif is_operator_for_numbers and is_data_value_or_query_value_string:
|
| 166 |
+
if is_data_value_string and is_query_value_string:
|
| 167 |
+
match = False
|
| 168 |
+
if debug: print(f"\t\t\toperator \"{query_operator}\" NOT supported, because data value is string and query value is string, match: {match}")
|
| 169 |
+
break
|
| 170 |
+
elif is_data_value_string and is_query_value_number:
|
| 171 |
+
match = False
|
| 172 |
+
if debug: print(f"\t\t\toperator \"{query_operator}\" NOT supported, because data value is string, match: {match}")
|
| 173 |
+
break
|
| 174 |
+
else:
|
| 175 |
+
match = False
|
| 176 |
+
if debug: print(f"\t\t\toperator \"{query_operator}\" NOT supported, because query value is number, match: {match}")
|
| 177 |
+
break
|
| 178 |
+
else:
|
| 179 |
+
match = False
|
| 180 |
+
if debug: print(f"\t\t\toperator \"{query_operator}\" NOT supported, match: {match}")
|
| 181 |
+
break
|
| 182 |
+
# continue
|
| 183 |
+
|
| 184 |
+
# If the match is true, add the date_key to the list
|
| 185 |
+
if match:
|
| 186 |
+
if debug: print(f"\t***** {query_key} matches, adding date_key: {date_key} *****")
|
| 187 |
+
date_keys_that_match.append(date_key)
|
| 188 |
+
if debug:
|
| 189 |
+
print("\t dates that match:")
|
| 190 |
+
for date_key in date_keys_that_match:
|
| 191 |
+
print(f"\t\t{date_key}")
|
| 192 |
+
|
| 193 |
+
return date_keys_that_match
|
| 194 |
+
|
| 195 |
+
def string_date_list_to_date_list(string_date_list):
|
| 196 |
+
date_list = []
|
| 197 |
+
for string_date in string_date_list:
|
| 198 |
+
date_list.append(datetime.strptime(string_date, '%Y-%m-%d'))
|
| 199 |
+
return date_list
|
| 200 |
+
|
| 201 |
+
def date_to_string(date):
|
| 202 |
+
string_date = date.strftime('%Y-%m-%d')
|
| 203 |
+
string_date = string_date.replace('-01', '-1')
|
| 204 |
+
string_date = string_date.replace('-02', '-2')
|
| 205 |
+
string_date = string_date.replace('-03', '-3')
|
| 206 |
+
string_date = string_date.replace('-04', '-4')
|
| 207 |
+
string_date = string_date.replace('-05', '-5')
|
| 208 |
+
string_date = string_date.replace('-06', '-6')
|
| 209 |
+
string_date = string_date.replace('-07', '-7')
|
| 210 |
+
string_date = string_date.replace('-08', '-8')
|
| 211 |
+
string_date = string_date.replace('-09', '-9')
|
| 212 |
+
return string_date
|
| 213 |
+
|
| 214 |
+
def get_days_between_dates(date1, date2):
|
| 215 |
+
return (date1 - date2).days
|
| 216 |
+
|
| 217 |
+
def query_usuarios(data, query_list, limit_days=8, debug=False):
|
| 218 |
+
# Get date keys
|
| 219 |
+
date_keys = get_sorted_date_keys(data)
|
| 220 |
+
if debug: print(f"\tdate_keys: {date_keys}")
|
| 221 |
+
|
| 222 |
+
# Format date_keys to date objects
|
| 223 |
+
date_keys = string_date_list_to_date_list(date_keys)
|
| 224 |
+
|
| 225 |
+
# Format query_list to date objects
|
| 226 |
+
if debug: print(f"\tquery_list: {query_list}")
|
| 227 |
+
query_list = string_date_list_to_date_list(query_list)
|
| 228 |
+
|
| 229 |
+
# Create empty list to store the date_keys that match
|
| 230 |
+
date_keys_that_match = []
|
| 231 |
+
|
| 232 |
+
# Iterate for each query_list date
|
| 233 |
+
for query_date in query_list:
|
| 234 |
+
# Iterate for each date_key
|
| 235 |
+
for date_key in date_keys:
|
| 236 |
+
# Get the days between the query_date and the date_key
|
| 237 |
+
days_between = get_days_between_dates(query_date, date_key)
|
| 238 |
+
if days_between <= limit_days and days_between > 0:
|
| 239 |
+
if debug: print(f"\tdays between form data {date_to_string(query_date)} and macros change data {date_to_string(date_key)}: {days_between}")
|
| 240 |
+
|
| 241 |
+
# Add the date_key to the list and break the loop, because is first mach so is match with less days between dates
|
| 242 |
+
date_keys_that_match.append(date_to_string(date_key))
|
| 243 |
+
break
|
| 244 |
+
|
| 245 |
+
return date_keys_that_match
|
| 246 |
+
|
| 247 |
+
def get_macros_differences(data, dates_list):
|
| 248 |
+
macros_differences_list = []
|
| 249 |
+
for date in dates_list:
|
| 250 |
+
macros_differences_list.append(data[date]['diferencia_macros'])
|
| 251 |
+
return macros_differences_list
|
| 252 |
+
|
| 253 |
+
def get_min_max_mean_mode_macros_differences(macros_differences_list):
|
| 254 |
+
# Create list for each macro
|
| 255 |
+
train_day_protein_list = []
|
| 256 |
+
train_day_carbs_list = []
|
| 257 |
+
train_day_fat_list = []
|
| 258 |
+
intratrain_protein_list = []
|
| 259 |
+
intratrain_carbs_list = []
|
| 260 |
+
rest_day_protein_list = []
|
| 261 |
+
rest_day_carbs_list = []
|
| 262 |
+
rest_day_fat_list = []
|
| 263 |
+
|
| 264 |
+
# Iterate over the macros differences list
|
| 265 |
+
for macros_difference in macros_differences_list:
|
| 266 |
+
# Get the macros difference as a list of integers
|
| 267 |
+
macros_difference_int_list = get_macros_from_string(macros_difference)
|
| 268 |
+
|
| 269 |
+
# Append the macros difference to the list
|
| 270 |
+
train_day_protein_list.append(macros_difference_int_list[0])
|
| 271 |
+
train_day_carbs_list.append(macros_difference_int_list[1])
|
| 272 |
+
train_day_fat_list.append(macros_difference_int_list[2])
|
| 273 |
+
intratrain_protein_list.append(macros_difference_int_list[3])
|
| 274 |
+
intratrain_carbs_list.append(macros_difference_int_list[4])
|
| 275 |
+
rest_day_protein_list.append(macros_difference_int_list[5])
|
| 276 |
+
rest_day_carbs_list.append(macros_difference_int_list[6])
|
| 277 |
+
rest_day_fat_list.append(macros_difference_int_list[7])
|
| 278 |
+
|
| 279 |
+
# Get the min, max, mean and mode of the macros differences
|
| 280 |
+
min_train_day_protein = min(train_day_protein_list)
|
| 281 |
+
max_train_day_protein = max(train_day_protein_list)
|
| 282 |
+
mean_train_day_protein = sum(train_day_protein_list) / len(train_day_protein_list)
|
| 283 |
+
mode_train_day_protein = statistics.mode(train_day_protein_list)
|
| 284 |
+
train_day_protein_std = (min_train_day_protein, max_train_day_protein, mean_train_day_protein, mode_train_day_protein)
|
| 285 |
+
|
| 286 |
+
min_train_day_carbs = min(train_day_carbs_list)
|
| 287 |
+
max_train_day_carbs = max(train_day_carbs_list)
|
| 288 |
+
mean_train_day_carbs = sum(train_day_carbs_list) / len(train_day_carbs_list)
|
| 289 |
+
mode_train_day_carbs = statistics.mode(train_day_carbs_list)
|
| 290 |
+
train_day_carbs_std = (min_train_day_carbs, max_train_day_carbs, mean_train_day_carbs, mode_train_day_carbs)
|
| 291 |
+
|
| 292 |
+
min_train_day_fat = min(train_day_fat_list)
|
| 293 |
+
max_train_day_fat = max(train_day_fat_list)
|
| 294 |
+
mean_train_day_fat = sum(train_day_fat_list) / len(train_day_fat_list)
|
| 295 |
+
mode_train_day_fat = statistics.mode(train_day_fat_list)
|
| 296 |
+
train_day_fat_std = (min_train_day_fat, max_train_day_fat, mean_train_day_fat, mode_train_day_fat)
|
| 297 |
+
|
| 298 |
+
min_intratrain_protein = min(intratrain_protein_list)
|
| 299 |
+
max_intratrain_protein = max(intratrain_protein_list)
|
| 300 |
+
mean_intratrain_protein = sum(intratrain_protein_list) / len(intratrain_protein_list)
|
| 301 |
+
mode_intratrain_protein = statistics.mode(intratrain_protein_list)
|
| 302 |
+
intratrain_protein_std = (min_intratrain_protein, max_intratrain_protein, mean_intratrain_protein, mode_intratrain_protein)
|
| 303 |
+
|
| 304 |
+
min_intratrain_carbs = min(intratrain_carbs_list)
|
| 305 |
+
max_intratrain_carbs = max(intratrain_carbs_list)
|
| 306 |
+
mean_intratrain_carbs = sum(intratrain_carbs_list) / len(intratrain_carbs_list)
|
| 307 |
+
mode_intratrain_carbs = statistics.mode(intratrain_carbs_list)
|
| 308 |
+
intratrain_carbs_std = (min_intratrain_carbs, max_intratrain_carbs, mean_intratrain_carbs, mode_intratrain_carbs)
|
| 309 |
+
|
| 310 |
+
min_rest_day_protein = min(rest_day_protein_list)
|
| 311 |
+
max_rest_day_protein = max(rest_day_protein_list)
|
| 312 |
+
mean_rest_day_protein = sum(rest_day_protein_list) / len(rest_day_protein_list)
|
| 313 |
+
mode_rest_day_protein = statistics.mode(rest_day_protein_list)
|
| 314 |
+
rest_day_protein_std = (min_rest_day_protein, max_rest_day_protein, mean_rest_day_protein, mode_rest_day_protein)
|
| 315 |
+
|
| 316 |
+
min_rest_day_carbs = min(rest_day_carbs_list)
|
| 317 |
+
max_rest_day_carbs = max(rest_day_carbs_list)
|
| 318 |
+
mean_rest_day_carbs = sum(rest_day_carbs_list) / len(rest_day_carbs_list)
|
| 319 |
+
mode_rest_day_carbs = statistics.mode(rest_day_carbs_list)
|
| 320 |
+
rest_day_carbs_std = (min_rest_day_carbs, max_rest_day_carbs, mean_rest_day_carbs, mode_rest_day_carbs)
|
| 321 |
+
|
| 322 |
+
min_rest_day_fat = min(rest_day_fat_list)
|
| 323 |
+
max_rest_day_fat = max(rest_day_fat_list)
|
| 324 |
+
mean_rest_day_fat = sum(rest_day_fat_list) / len(rest_day_fat_list)
|
| 325 |
+
mode_rest_day_fat = statistics.mode(rest_day_fat_list)
|
| 326 |
+
rest_day_fat_std = (min_rest_day_fat, max_rest_day_fat, mean_rest_day_fat, mode_rest_day_fat)
|
| 327 |
+
|
| 328 |
+
return 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
|
| 329 |
+
|
| 330 |
+
def clustering_esfuerzo_dieta_response(response, debug=False):
|
| 331 |
+
# Options:
|
| 332 |
+
# No entiendo la calculadora, quiero men煤s tipo, c谩rgame 4|I: 2
|
| 333 |
+
# No cost贸 nada|A: 1504
|
| 334 |
+
# Cost贸 demasiado, s煤beme macros|D: 28
|
| 335 |
+
# Cost贸, pero me adapto a nuevos ajustes|C: 331
|
| 336 |
+
# Iba a coger men煤s tipo, pero al final por precio no|D: 13
|
| 337 |
+
# Cost贸 demasiado, b谩jame macros|D: 42
|
| 338 |
+
# No entiendo la calculadora, quiero men煤s tipo, c谩rgame 2|I: 3
|
| 339 |
+
#
|
| 340 |
+
# Clustering:
|
| 341 |
+
# 0 (No data):
|
| 342 |
+
# No entiendo la calculadora, quiero men煤s tipo, c谩rgame 4|I: 2 | No data
|
| 343 |
+
# Iba a coger men煤s tipo, pero al final por precio no|D: 13 | No data
|
| 344 |
+
# No entiendo la calculadora, quiero men煤s tipo, c谩rgame 2|I: 3 | No data
|
| 345 |
+
# 1 (cost贸 subir macros):
|
| 346 |
+
# Cost贸 demasiado, s煤beme macros|D: 28 | costo subir macros
|
| 347 |
+
# 2 (cost贸 bajar macros):
|
| 348 |
+
# Cost贸 demasiado, b谩jame macros|D: 42 | costo bajar macros
|
| 349 |
+
# 3 (cost贸 y me adapto a nuevos ajustes):
|
| 350 |
+
# Cost贸, pero me adapto a nuevos ajustes|C: 331 | costo y me adapto a nuevos ajustes
|
| 351 |
+
# 4 (no cost贸):
|
| 352 |
+
# No cost贸 nada|A: 1504 | no costo
|
| 353 |
+
|
| 354 |
+
if " | No data".lower() in response.lower():
|
| 355 |
+
if debug: print(f"\t\t{response} -> no data")
|
| 356 |
+
return 'no data'
|
| 357 |
+
elif " | costo subir macros".lower() in response.lower():
|
| 358 |
+
if debug: print(f"\t\t{response} -> costo subir macros")
|
| 359 |
+
return 'costo subir macros'
|
| 360 |
+
elif " | costo bajar macros".lower() in response.lower():
|
| 361 |
+
if debug: print(f"\t\t{response} -> costo bajar macros")
|
| 362 |
+
return 'costo bajar macros'
|
| 363 |
+
elif " | costo y me adapto a nuevos ajustes".lower() in response.lower():
|
| 364 |
+
if debug: print(f"\t\t{response} -> costo y me adapto a nuevos ajustes")
|
| 365 |
+
return 'costo y me adapto a nuevos ajustes'
|
| 366 |
+
elif " | no costo".lower() in response.lower():
|
| 367 |
+
if debug: print(f"\t\t{response} -> no costo")
|
| 368 |
+
return 'no costo'
|
| 369 |
+
else:
|
| 370 |
+
if debug: print(f"\t\t{response} -> no data")
|
| 371 |
+
return 'no data'
|
| 372 |
+
|
| 373 |
+
def clustering_objetivo_response(response, debug=False):
|
| 374 |
+
# Options:
|
| 375 |
+
# definici贸n (nada cambia)|A: 1031
|
| 376 |
+
# empezamos a definir (cambia)|C: 92
|
| 377 |
+
# perder peso (nada cambia)|A: 21
|
| 378 |
+
# volumen (nada cambia)|A: 688
|
| 379 |
+
# empezamos a coger volumen (cambia)|C: 78
|
| 380 |
+
# empezamos a coger volumen, sobre todo tren inferior (cambia)|C: 7
|
| 381 |
+
# empezamos a coger volumen, en todo el cuerpo (cambia)|C: 6
|
| 382 |
+
#
|
| 383 |
+
# Clustering:
|
| 384 |
+
# 0 (definici贸n):
|
| 385 |
+
# definici贸n (nada cambia)|A: 1031 | definici贸n
|
| 386 |
+
# empezamos a definir (cambia)|C: 92 | definici贸n
|
| 387 |
+
# perder peso (nada cambia)|A: 21 | definici贸n
|
| 388 |
+
# 1 (volumen):
|
| 389 |
+
# volumen (nada cambia)|A: 688 | volumen
|
| 390 |
+
# empezamos a coger volumen (cambia)|C: 78 | volumen
|
| 391 |
+
# empezamos a coger volumen, sobre todo tren inferior (cambia)|C: 7 | volumen
|
| 392 |
+
# empezamos a coger volumen, en todo el cuerpo (cambia)|C: 6 | volumen
|
| 393 |
+
|
| 394 |
+
if " | definicion".lower() in response.lower():
|
| 395 |
+
if debug: print(f"\t\t{response} -> definicion")
|
| 396 |
+
return 'definicion'
|
| 397 |
+
elif " | volumen".lower() in response.lower():
|
| 398 |
+
if debug: print(f"\t\t{response} -> volumen")
|
| 399 |
+
return 'volumen'
|
| 400 |
+
else:
|
| 401 |
+
if debug: print(f"\t\t{response} -> no data")
|
| 402 |
+
return 'no data'
|
| 403 |
+
|
| 404 |
+
def clustering_entrenamiento_response(response, debug=False):
|
| 405 |
+
# Options:
|
| 406 |
+
# Lo hice perfecto|A|10: 838
|
| 407 |
+
# He fallado algunos d铆as, pero s铆|B|5: 98
|
| 408 |
+
# Lesi贸n importante: 16
|
| 409 |
+
# Lo hice pr谩cticamente perfecto|A|8: 416
|
| 410 |
+
# Peque帽a lesi贸n: 63
|
| 411 |
+
# No hice nada, mantenemos la rutina un mes m谩s|I|0: 64
|
| 412 |
+
# Al谩rgame la rutina una semana m谩s|I|6: 32
|
| 413 |
+
#
|
| 414 |
+
# Clustering:
|
| 415 |
+
# 0 (bien):
|
| 416 |
+
# Lo hice perfecto|A|10: 838 | bien
|
| 417 |
+
# He fallado algunos d铆as, pero s铆|B|5: 98 | bien
|
| 418 |
+
# Lo hice pr谩cticamente perfecto|A|8: 416 | bien
|
| 419 |
+
# 1 (mal):
|
| 420 |
+
# Lesi贸n importante: 16 | mal
|
| 421 |
+
# Peque帽a lesi贸n: 63 | mal
|
| 422 |
+
# No hice nada, mantenemos la rutina un mes m谩s|I|0: 64 | mal
|
| 423 |
+
# Al谩rgame la rutina una semana m谩s|I|6: 32 | mal
|
| 424 |
+
|
| 425 |
+
if " | bien".lower() in response.lower():
|
| 426 |
+
if debug: print(f"\t\t{response} -> bien")
|
| 427 |
+
return 'bien'
|
| 428 |
+
elif " | mal".lower() in response.lower():
|
| 429 |
+
if debug: print(f"\t\t{response} -> mal")
|
| 430 |
+
return 'mal'
|
| 431 |
+
else:
|
| 432 |
+
if debug: print(f"\t\t{response} -> no data")
|
| 433 |
+
return 'no data'
|
| 434 |
+
|
| 435 |
+
def clustering_cumplimiento_dieta_response(response, debug=False):
|
| 436 |
+
# Options:
|
| 437 |
+
# al 70%|B|6: 564
|
| 438 |
+
# regular, me cuesta llegar|C|5: 57
|
| 439 |
+
# Nada, mant茅n mis macros|I|0: 123
|
| 440 |
+
# casi perfecta|A|9: 610
|
| 441 |
+
# regular, me salto la dieta|C|4: 6
|
| 442 |
+
# Perfecta|A|10: 563
|
| 443 |
+
#
|
| 444 |
+
# Clustering:
|
| 445 |
+
# 0 (bien):
|
| 446 |
+
# al 70%|B|6: 564 | bien
|
| 447 |
+
# casi perfecta|A|9: 610 | bien
|
| 448 |
+
# Perfecta|A|10: 563 | bien
|
| 449 |
+
# 1 (regular):
|
| 450 |
+
# regular, me cuesta llegar|C|5: 57 | regular
|
| 451 |
+
# regular, me salto la dieta|C|4: 6 | regular
|
| 452 |
+
# 2 (mal):
|
| 453 |
+
# Nada, mant茅n mis macros|I|0: 123 | mal
|
| 454 |
+
|
| 455 |
+
if " | bien".lower() in response.lower():
|
| 456 |
+
if debug: print(f"\t\t{response} -> bien")
|
| 457 |
+
return 'bien'
|
| 458 |
+
elif " | regular".lower() in response.lower():
|
| 459 |
+
if debug: print(f"\t\t{response} -> regular")
|
| 460 |
+
return 'regular'
|
| 461 |
+
elif "nada" in response.lower():
|
| 462 |
+
if debug: print(f"\t\t{response} -> mal")
|
| 463 |
+
return 'mal'
|
| 464 |
+
else:
|
| 465 |
+
if debug: print(f"\t\t{response} -> no data")
|
| 466 |
+
return 'no data'
|
| 467 |
+
|
| 468 |
+
def clustering_compromiso_response(response, debug=False):
|
| 469 |
+
# Options:
|
| 470 |
+
# Bueno, pero mejorable|B|7: 604
|
| 471 |
+
# Mal, pero a partir de ahora voy a por todas|C|0: 319
|
| 472 |
+
# Mal, demasiado exigente|D|0: 15
|
| 473 |
+
# M谩ximo|A|10: 985
|
| 474 |
+
#
|
| 475 |
+
# Clustering:
|
| 476 |
+
# 0 (bueno):
|
| 477 |
+
# Bueno, pero mejorable|B|7: 604 | bueno
|
| 478 |
+
# M谩ximo|A|10: 985 | bueno
|
| 479 |
+
# 1 (mal):
|
| 480 |
+
# Mal, pero a partir de ahora voy a por todas|C|0: 319 | mal
|
| 481 |
+
# Mal, demasiado exigente|D|0: 15 | mal
|
| 482 |
+
|
| 483 |
+
if " | bueno".lower() in response.lower():
|
| 484 |
+
if debug: print(f"\t\t{response} -> bueno")
|
| 485 |
+
return 'bueno'
|
| 486 |
+
elif " | mal".lower() in response.lower():
|
| 487 |
+
if debug: print(f"\t\t{response} -> mal")
|
| 488 |
+
return 'mal'
|
| 489 |
+
else:
|
| 490 |
+
if debug: print(f"\t\t{response} -> no data")
|
| 491 |
+
return 'no data'
|
| 492 |
+
|
| 493 |
+
def clustering_diferencia_peso_response(diff, debug=False):
|
| 494 |
+
diff_min = None
|
| 495 |
+
diff_max = None
|
| 496 |
+
if diff <= -5.0:
|
| 497 |
+
if debug: print(f"\t\t-10 <= {diff} <= -5")
|
| 498 |
+
diff_min = -10
|
| 499 |
+
diff_max = -5
|
| 500 |
+
elif diff <= -4.5:
|
| 501 |
+
if debug: print(f"\t\t-5 <= {diff} <= -4.5")
|
| 502 |
+
diff_min = -5
|
| 503 |
+
diff_max = -4.5
|
| 504 |
+
elif diff <= -4.0:
|
| 505 |
+
if debug: print(f"\t\t-4.5 <= {diff} <= -4.0")
|
| 506 |
+
diff_min = -4.5
|
| 507 |
+
diff_max = -4.0
|
| 508 |
+
elif diff <= -3.5:
|
| 509 |
+
if debug: print(f"\t\t-4.0 <= {diff} <= -3.5")
|
| 510 |
+
diff_min = -4.0
|
| 511 |
+
diff_max = -3.5
|
| 512 |
+
elif diff <= -3.0:
|
| 513 |
+
if debug: print(f"\t\t-3.5 <= {diff} <= -3.0")
|
| 514 |
+
diff_min = -3.5
|
| 515 |
+
diff_max = -3.0
|
| 516 |
+
elif diff <= -2.5:
|
| 517 |
+
if debug: print(f"\t\t-3.0 <= {diff} <= -2.5")
|
| 518 |
+
diff_min = -3.0
|
| 519 |
+
diff_max = -2.5
|
| 520 |
+
elif diff <= -2.0:
|
| 521 |
+
if debug: print(f"\t\t-2.5 <= {diff} <= -2.0")
|
| 522 |
+
diff_min = -2.5
|
| 523 |
+
diff_max = -2.0
|
| 524 |
+
elif diff <= -1.5:
|
| 525 |
+
if debug: print(f"\t\t-2.0 <= {diff} <= -1.5")
|
| 526 |
+
diff_min = -2.0
|
| 527 |
+
diff_max = -1.5
|
| 528 |
+
elif diff <= -1.0:
|
| 529 |
+
if debug: print(f"\t\t-1.5 <= {diff} <= -1.0")
|
| 530 |
+
diff_min = -1.5
|
| 531 |
+
diff_max = -1.0
|
| 532 |
+
elif diff <= -0.5:
|
| 533 |
+
if debug: print(f"\t\t-1.0 <= {diff} <= -0.5")
|
| 534 |
+
diff_min = -1.0
|
| 535 |
+
diff_max = -0.5
|
| 536 |
+
elif diff <= 0.0:
|
| 537 |
+
if debug: print(f"\t\t-0.5 <= {diff} <= 0.0")
|
| 538 |
+
diff_min = -0.5
|
| 539 |
+
diff_max = 0.0
|
| 540 |
+
elif diff <= 0.5:
|
| 541 |
+
if debug: print(f"\t\t0.0 <= {diff} <= 0.5")
|
| 542 |
+
diff_min = 0.0
|
| 543 |
+
diff_max = 0.5
|
| 544 |
+
elif diff <= 1.0:
|
| 545 |
+
if debug: print(f"\t\t0.5 <= {diff} <= 1.0")
|
| 546 |
+
diff_min = 0.5
|
| 547 |
+
diff_max = 1.0
|
| 548 |
+
elif diff <= 1.5:
|
| 549 |
+
if debug: print(f"\t\t1.0 <= {diff} <= 1.5")
|
| 550 |
+
diff_min = 1.0
|
| 551 |
+
diff_max = 1.5
|
| 552 |
+
elif diff <= 2.0:
|
| 553 |
+
if debug: print(f"\t\t1.5 <= {diff} <= 2.0")
|
| 554 |
+
diff_min = 1.5
|
| 555 |
+
diff_max = 2.0
|
| 556 |
+
elif diff <= 2.5:
|
| 557 |
+
if debug: print(f"\t\t2.0 <= {diff} <= 2.5")
|
| 558 |
+
diff_min = 2.0
|
| 559 |
+
diff_max = 2.5
|
| 560 |
+
elif diff <= 3.0:
|
| 561 |
+
if debug: print(f"\t\t2.5 <= {diff} <= 3.0")
|
| 562 |
+
diff_min = 2.5
|
| 563 |
+
diff_max = 3.0
|
| 564 |
+
elif diff <= 3.5:
|
| 565 |
+
if debug: print(f"\t\t3.0 <= {diff} <= 3.5")
|
| 566 |
+
diff_min = 3.0
|
| 567 |
+
diff_max = 3.5
|
| 568 |
+
elif diff <= 4.0:
|
| 569 |
+
if debug: print(f"\t\t3.5 <= {diff} <= 4.0")
|
| 570 |
+
diff_min = 3.5
|
| 571 |
+
diff_max = 4.0
|
| 572 |
+
elif diff <= 4.5:
|
| 573 |
+
if debug: print(f"\t\t4.0 <= {diff} <= 4.5")
|
| 574 |
+
diff_min = 4.0
|
| 575 |
+
diff_max = 4.5
|
| 576 |
+
elif diff <= 5.0:
|
| 577 |
+
if debug: print(f"\t\t4.5 <= {diff} <= 5.0")
|
| 578 |
+
diff_min = 4.5
|
| 579 |
+
diff_max = 5.0
|
| 580 |
+
else:
|
| 581 |
+
if debug: print(f"\t\t{diff} -> no data")
|
| 582 |
+
diff_min = None
|
| 583 |
+
diff_max = None
|
| 584 |
+
|
| 585 |
+
return diff_min, diff_max
|
| 586 |
+
|
| 587 |
+
def dieta_response(response_esfuerzo, response_cumplimiento, debug=False):
|
| 588 |
+
# esfuerzo dieta:
|
| 589 |
+
# 0 (No data):
|
| 590 |
+
# No entiendo la calculadora, quiero men煤s tipo, c谩rgame 4|I: 2
|
| 591 |
+
# Iba a coger men煤s tipo, pero al final por precio no|D: 13
|
| 592 |
+
# No entiendo la calculadora, quiero men煤s tipo, c谩rgame 2|I: 3
|
| 593 |
+
# 1 (cost贸 subir macros):
|
| 594 |
+
# Cost贸 demasiado, s煤beme macros|D: 28
|
| 595 |
+
# 2 (cost贸 bajar macros):
|
| 596 |
+
# Cost贸 demasiado, b谩jame macros|D: 42
|
| 597 |
+
# 3 (cost贸 y me adapto a nuevos ajustes):
|
| 598 |
+
# Cost贸, pero me adapto a nuevos ajustes|C: 331
|
| 599 |
+
# 4 (no cost贸):
|
| 600 |
+
# No cost贸 nada|A: 1504
|
| 601 |
+
# compromiso dieta:
|
| 602 |
+
# 0 (bien):
|
| 603 |
+
# al 70%|B|6: 564
|
| 604 |
+
# casi 漏|A|9: 610
|
| 605 |
+
# Perfecta|A|10: 563
|
| 606 |
+
# 1 (regular):
|
| 607 |
+
# regular, me cuesta llegar|C|5: 57
|
| 608 |
+
# regular, me salto la dieta|C|4: 6
|
| 609 |
+
# 2 (mal):
|
| 610 |
+
# Nada, mant茅n mis macros|I|0: 123
|
| 611 |
+
|
| 612 |
+
esfuerzo_dieta_cluster = clustering_esfuerzo_dieta_response(response_esfuerzo, debug)
|
| 613 |
+
cumplimiento_dieta_cluster = clustering_cumplimiento_dieta_response(response_cumplimiento, debug)
|
| 614 |
+
|
| 615 |
+
if esfuerzo_dieta_cluster == 0:
|
| 616 |
+
dieta_bien = cumplimiento_dieta_cluster == 0
|
| 617 |
+
dieta_regular = cumplimiento_dieta_cluster == 1
|
| 618 |
+
dieta_mal = cumplimiento_dieta_cluster == 2
|
| 619 |
+
else:
|
| 620 |
+
dieta_bien = esfuerzo_dieta_cluster == 4 and cumplimiento_dieta_cluster == 0
|
| 621 |
+
dieta_regular = esfuerzo_dieta_cluster == 3 and cumplimiento_dieta_cluster == 1
|
| 622 |
+
dieta_mal = (esfuerzo_dieta_cluster == 2 or esfuerzo_dieta_cluster == 1) and cumplimiento_dieta_cluster == 2
|
| 623 |
+
|
| 624 |
+
if dieta_bien:
|
| 625 |
+
return 0
|
| 626 |
+
elif dieta_regular:
|
| 627 |
+
return 1
|
| 628 |
+
elif dieta_mal:
|
| 629 |
+
return 2
|
| 630 |
+
else:
|
| 631 |
+
return 3
|
| 632 |
+
|
| 633 |
+
def make_query(cluster_esfuerzo_dieta, cluster_objetivo, cluster_entrenamiento, cluster_cumplimiento_dieta, cluster_compromiso, diff_peso_min, diff_peso_max):
|
| 634 |
+
query = [
|
| 635 |
+
{
|
| 636 |
+
'esfuerzoParaCumplirDieta':
|
| 637 |
+
{
|
| 638 |
+
'operator': 'in',
|
| 639 |
+
'value': cluster_esfuerzo_dieta,
|
| 640 |
+
}
|
| 641 |
+
},
|
| 642 |
+
{
|
| 643 |
+
'objetivo':
|
| 644 |
+
{
|
| 645 |
+
'operator': 'in',
|
| 646 |
+
'value': cluster_objetivo,
|
| 647 |
+
}
|
| 648 |
+
},
|
| 649 |
+
{
|
| 650 |
+
'cumplimientoEntrenamiento':
|
| 651 |
+
{
|
| 652 |
+
'operator': 'in',
|
| 653 |
+
'value': cluster_entrenamiento,
|
| 654 |
+
}
|
| 655 |
+
},
|
| 656 |
+
{
|
| 657 |
+
'cumplimientoDieta':
|
| 658 |
+
{
|
| 659 |
+
'operator': 'in',
|
| 660 |
+
'value': cluster_cumplimiento_dieta,
|
| 661 |
+
}
|
| 662 |
+
},
|
| 663 |
+
{
|
| 664 |
+
'compromiso':
|
| 665 |
+
{
|
| 666 |
+
'operator': 'in',
|
| 667 |
+
'value': cluster_compromiso,
|
| 668 |
+
}
|
| 669 |
+
},
|
| 670 |
+
{
|
| 671 |
+
'diferencia_peso':
|
| 672 |
+
{
|
| 673 |
+
'operator': '<=',
|
| 674 |
+
'value': diff_peso_max,
|
| 675 |
+
}
|
| 676 |
+
},
|
| 677 |
+
{
|
| 678 |
+
'diferencia_peso':
|
| 679 |
+
{
|
| 680 |
+
'operator': '>=',
|
| 681 |
+
'value': diff_peso_min,
|
| 682 |
+
}
|
| 683 |
+
}
|
| 684 |
+
]
|
| 685 |
+
return query
|