|
from create_new_formularios import get_sorted_date_keys |
|
from pathlib import Path |
|
from datetime import datetime |
|
from create_new_usuarios import get_macros_from_string |
|
import statistics |
|
|
|
def query_formularios(data, query_list, debug=False, file_name=None): |
|
|
|
if file_name is not None: |
|
debug = True |
|
print(f"***************** file_name: {file_name} *****************") |
|
|
|
|
|
date_keys = get_sorted_date_keys(data) |
|
if debug: print(f"\n\n\ndate_keys: {date_keys}") |
|
|
|
|
|
date_keys_that_match = [] |
|
|
|
|
|
no_data_value = "| no data" |
|
|
|
|
|
queries_list = [] |
|
for query in query_list: |
|
queries_list.append(query) |
|
if debug: |
|
print("queries_list:") |
|
for query in queries_list: |
|
for key in query.keys(): |
|
print(f"\tkey: {key}", end=" --> ") |
|
for second_key in query[key].keys(): |
|
print(f"{key}: {query[key][second_key]}", end=", ") |
|
print("") |
|
|
|
|
|
for date_key in date_keys: |
|
if debug: print(f"\n * date_key: {date_key}") |
|
|
|
|
|
match = False |
|
if debug: print(f"\tinitial match value: {match}") |
|
|
|
|
|
data_keys = data[date_key].keys() |
|
if debug: print(f"\tkeys: {data_keys}") |
|
|
|
|
|
for query in queries_list: |
|
|
|
query_key = list(query.keys())[0] |
|
|
|
|
|
query_operator = query[query_key]['operator'] |
|
is_operator_for_numbers = query_operator == '>' or query_operator == '<' or query_operator == '>=' or query_operator == '<=' |
|
query_value = query[query_key]['value'] |
|
type_of_query_value = type(query_value) |
|
is_query_value_string = type_of_query_value == str |
|
is_query_value_number = type_of_query_value == int or type_of_query_value == float |
|
|
|
|
|
if query_key in data_keys: |
|
|
|
data_value = data[date_key][query_key] |
|
if isinstance(data_value, str): |
|
data_value = data_value.lower() |
|
data_value = data_value.replace('谩', 'a') |
|
data_value = data_value.replace('茅', 'e') |
|
data_value = data_value.replace('铆', 'i') |
|
data_value = data_value.replace('贸', 'o') |
|
data_value = data_value.replace('煤', 'u') |
|
type_of_data_value = type(data_value) |
|
is_data_value_string = type_of_data_value == str |
|
is_data_value_number = type_of_data_value == int or type_of_data_value == float |
|
is_data_value_and_query_value_number = is_data_value_number and is_query_value_number |
|
is_data_value_and_query_value_string = is_data_value_string and is_query_value_string |
|
is_data_value_or_query_value_number = is_data_value_number or is_query_value_number |
|
is_data_value_or_query_value_string = is_data_value_string or is_query_value_string |
|
if debug: print(f"\t\tchecking \"{query_key}\" in data, query operator: \"{query_operator}\", query value: \"{query_value}\", data value: \"{data_value}\"") |
|
|
|
|
|
if query_operator == '==': |
|
if query_value == data_value: |
|
match = True |
|
if debug: print(f"\t\t\t\"{query_value}\" is equal to \"{data_value}\", match: {match}") |
|
else: |
|
match = False |
|
if debug: print(f"\t\t\t\"{query_value}\" is NOT equal to \"{data_value}\", match: {match}") |
|
break |
|
|
|
elif query_operator == '!=': |
|
if query_value != data_value: |
|
match = True |
|
if debug: print(f"\t\t\t\"{query_value}\" is NOT equal to \"{data_value}\", match: {match}") |
|
else: |
|
match = False |
|
if debug: print(f"\t\t\t\"{query_value}\" is NOT equal to \"{data_value}\", match: {match}") |
|
break |
|
|
|
elif is_query_value_number and is_data_value_number and query_operator == '>': |
|
if data_value > query_value: |
|
match = True |
|
if debug: print(f"\t\t\t\"{query_value}\" is greater than \"{data_value}\", match: {match}") |
|
else: |
|
match = False |
|
if debug: print(f"\t\t\t\"{query_value}\" is NOT greater than \"{data_value}\", match: {match}") |
|
break |
|
|
|
elif is_query_value_number and is_data_value_number and query_operator == '<': |
|
if data_value < query_value: |
|
match = True |
|
if debug: print(f"\t\t\t\"{query_value}\" is less than \"{data_value}\", match: {match}") |
|
else: |
|
match = False |
|
if debug: print(f"\t\t\t\"{query_value}\" is NOT less than \"{data_value}\", match: {match}") |
|
break |
|
|
|
elif is_query_value_number and is_data_value_number and query_operator == '>=': |
|
if data_value >= query_value: |
|
match = True |
|
if debug: print(f"\t\t\t\"{query_value}\" is greater than or equal to \"{data_value}\", match: {match}") |
|
else: |
|
match = False |
|
if debug: print(f"\t\t\t\"{query_value}\" is NOT greater than or equal to \"{data_value}\", match: {match}") |
|
break |
|
|
|
elif is_query_value_number and is_data_value_number and query_operator == '<=': |
|
if data_value <= query_value: |
|
match = True |
|
if debug: print(f"\t\t\t\"{query_value}\" is less than or equal to \"{data_value}\", match: {match}") |
|
else: |
|
match = False |
|
if debug: print(f"\t\t\t\"{query_value}\" is NOT less than or equal to \"{data_value}\", match: {match}") |
|
break |
|
|
|
elif is_query_value_string and is_data_value_string and query_operator == 'in' or query_operator == 'contains': |
|
if query_value in data_value or no_data_value in data_value: |
|
match = True |
|
if debug: print(f"\t\t\t\"{query_value}\" is in \"{data_value}\", match: {match}") |
|
else: |
|
match = False |
|
if debug: print(f"\t\t\t\"{query_value}\" is NOT in \"{data_value}\", match: {match}") |
|
break |
|
|
|
elif is_query_value_string and is_data_value_string and (query_operator == 'NOT in' or query_operator == 'NOT contains'): |
|
if query_value not in data_value or no_data_value in data_value: |
|
match = True |
|
if debug: print(f"\t\t\t\"{query_value}\" is NOT in \"{data_value}\", match: {match}") |
|
else: |
|
match = False |
|
if debug: print(f"\t\t\t\"{query_value}\" is NOT in \"{data_value}\", match: {match}") |
|
break |
|
|
|
elif query_operator == 'is null': |
|
if data_value is None: |
|
match = True |
|
if debug: print(f"\t\t\t\"{query_value}\" is null, match: {match}") |
|
else: |
|
match = False |
|
if debug: print(f"\t\t\t\"{query_value}\" is NOT null, match: {match}") |
|
break |
|
|
|
elif query_operator == 'is NOT null': |
|
if data_value is not None: |
|
match = True |
|
if debug: print(f"\t\t\t\"{query_value}\" is NOT null, match: {match}") |
|
else: |
|
match = False |
|
if debug: print(f"\t\t\t\"{query_value}\" is NOT null, match: {match}") |
|
break |
|
|
|
elif is_operator_for_numbers and is_data_value_or_query_value_string: |
|
if is_data_value_string and is_query_value_string: |
|
match = False |
|
if debug: print(f"\t\t\toperator \"{query_operator}\" NOT supported, because data value is string and query value is string, match: {match}") |
|
break |
|
elif is_data_value_string and is_query_value_number: |
|
match = False |
|
if debug: print(f"\t\t\toperator \"{query_operator}\" NOT supported, because data value is string, match: {match}") |
|
break |
|
else: |
|
match = False |
|
if debug: print(f"\t\t\toperator \"{query_operator}\" NOT supported, because query value is number, match: {match}") |
|
break |
|
else: |
|
match = False |
|
if debug: print(f"\t\t\toperator \"{query_operator}\" NOT supported, match: {match}") |
|
break |
|
|
|
|
|
|
|
if match: |
|
if debug: print(f"\t***** {query_key} matches, adding date_key: {date_key} *****") |
|
date_keys_that_match.append(date_key) |
|
if debug: |
|
print("\t dates that match:") |
|
for date_key in date_keys_that_match: |
|
print(f"\t\t{date_key}") |
|
|
|
return date_keys_that_match |
|
|
|
def string_date_list_to_date_list(string_date_list): |
|
date_list = [] |
|
for string_date in string_date_list: |
|
date_list.append(datetime.strptime(string_date, '%Y-%m-%d')) |
|
return date_list |
|
|
|
def date_to_string(date): |
|
string_date = date.strftime('%Y-%m-%d') |
|
string_date = string_date.replace('-01', '-1') |
|
string_date = string_date.replace('-02', '-2') |
|
string_date = string_date.replace('-03', '-3') |
|
string_date = string_date.replace('-04', '-4') |
|
string_date = string_date.replace('-05', '-5') |
|
string_date = string_date.replace('-06', '-6') |
|
string_date = string_date.replace('-07', '-7') |
|
string_date = string_date.replace('-08', '-8') |
|
string_date = string_date.replace('-09', '-9') |
|
return string_date |
|
|
|
def get_days_between_dates(date1, date2): |
|
if isinstance(date1, str): |
|
date1 = datetime.strptime(date1, '%Y-%m-%d') |
|
if isinstance(date2, str): |
|
date2 = datetime.strptime(date2, '%Y-%m-%d') |
|
return (date1 - date2).days |
|
|
|
def query_usuarios(data, query_list, limit_days=8, debug=False): |
|
|
|
date_keys = get_sorted_date_keys(data) |
|
if debug: print(f"\tdate_keys: {date_keys}") |
|
|
|
|
|
date_keys = string_date_list_to_date_list(date_keys) |
|
|
|
|
|
if debug: print(f"\tquery_list: {query_list}") |
|
query_list = string_date_list_to_date_list(query_list) |
|
|
|
|
|
date_keys_that_match = [] |
|
|
|
|
|
macros_differences_dates = [] |
|
|
|
|
|
for query_date in query_list: |
|
|
|
for date_key in date_keys: |
|
|
|
days_between = get_days_between_dates(query_date, date_key) |
|
if days_between <= limit_days and days_between > 0: |
|
if debug: print(f"\tdays between form data {date_to_string(query_date)} and macros change data {date_to_string(date_key)}: {days_between}") |
|
|
|
|
|
date_keys_that_match.append(date_to_string(date_key)) |
|
|
|
|
|
macros_differences_dates.append(date_to_string(query_date)) |
|
|
|
break |
|
|
|
return date_keys_that_match, macros_differences_dates |
|
|
|
def get_macros_differences(data, dates_list): |
|
macros_differences_list = [] |
|
for date in dates_list: |
|
macros_differences_list.append(data[date]['diferencia_macros']) |
|
return macros_differences_list |
|
|
|
def get_min_max_mean_mode_macros_differences(macros_differences_list): |
|
|
|
train_day_protein_list = [] |
|
train_day_carbs_list = [] |
|
train_day_fat_list = [] |
|
intratrain_protein_list = [] |
|
intratrain_carbs_list = [] |
|
rest_day_protein_list = [] |
|
rest_day_carbs_list = [] |
|
rest_day_fat_list = [] |
|
|
|
|
|
for macros_difference in macros_differences_list: |
|
|
|
macros_difference_int_list = get_macros_from_string(macros_difference) |
|
|
|
|
|
train_day_protein_list.append(macros_difference_int_list[0]) |
|
train_day_carbs_list.append(macros_difference_int_list[1]) |
|
train_day_fat_list.append(macros_difference_int_list[2]) |
|
intratrain_protein_list.append(macros_difference_int_list[3]) |
|
intratrain_carbs_list.append(macros_difference_int_list[4]) |
|
rest_day_protein_list.append(macros_difference_int_list[5]) |
|
rest_day_carbs_list.append(macros_difference_int_list[6]) |
|
rest_day_fat_list.append(macros_difference_int_list[7]) |
|
|
|
|
|
min_train_day_protein = min(train_day_protein_list) |
|
max_train_day_protein = max(train_day_protein_list) |
|
mean_train_day_protein = sum(train_day_protein_list) / len(train_day_protein_list) |
|
mode_train_day_protein = statistics.mode(train_day_protein_list) |
|
train_day_protein_std = (min_train_day_protein, max_train_day_protein, mean_train_day_protein, mode_train_day_protein) |
|
|
|
min_train_day_carbs = min(train_day_carbs_list) |
|
max_train_day_carbs = max(train_day_carbs_list) |
|
mean_train_day_carbs = sum(train_day_carbs_list) / len(train_day_carbs_list) |
|
mode_train_day_carbs = statistics.mode(train_day_carbs_list) |
|
train_day_carbs_std = (min_train_day_carbs, max_train_day_carbs, mean_train_day_carbs, mode_train_day_carbs) |
|
|
|
min_train_day_fat = min(train_day_fat_list) |
|
max_train_day_fat = max(train_day_fat_list) |
|
mean_train_day_fat = sum(train_day_fat_list) / len(train_day_fat_list) |
|
mode_train_day_fat = statistics.mode(train_day_fat_list) |
|
train_day_fat_std = (min_train_day_fat, max_train_day_fat, mean_train_day_fat, mode_train_day_fat) |
|
|
|
min_intratrain_protein = min(intratrain_protein_list) |
|
max_intratrain_protein = max(intratrain_protein_list) |
|
mean_intratrain_protein = sum(intratrain_protein_list) / len(intratrain_protein_list) |
|
mode_intratrain_protein = statistics.mode(intratrain_protein_list) |
|
intratrain_protein_std = (min_intratrain_protein, max_intratrain_protein, mean_intratrain_protein, mode_intratrain_protein) |
|
|
|
min_intratrain_carbs = min(intratrain_carbs_list) |
|
max_intratrain_carbs = max(intratrain_carbs_list) |
|
mean_intratrain_carbs = sum(intratrain_carbs_list) / len(intratrain_carbs_list) |
|
mode_intratrain_carbs = statistics.mode(intratrain_carbs_list) |
|
intratrain_carbs_std = (min_intratrain_carbs, max_intratrain_carbs, mean_intratrain_carbs, mode_intratrain_carbs) |
|
|
|
min_rest_day_protein = min(rest_day_protein_list) |
|
max_rest_day_protein = max(rest_day_protein_list) |
|
mean_rest_day_protein = sum(rest_day_protein_list) / len(rest_day_protein_list) |
|
mode_rest_day_protein = statistics.mode(rest_day_protein_list) |
|
rest_day_protein_std = (min_rest_day_protein, max_rest_day_protein, mean_rest_day_protein, mode_rest_day_protein) |
|
|
|
min_rest_day_carbs = min(rest_day_carbs_list) |
|
max_rest_day_carbs = max(rest_day_carbs_list) |
|
mean_rest_day_carbs = sum(rest_day_carbs_list) / len(rest_day_carbs_list) |
|
mode_rest_day_carbs = statistics.mode(rest_day_carbs_list) |
|
rest_day_carbs_std = (min_rest_day_carbs, max_rest_day_carbs, mean_rest_day_carbs, mode_rest_day_carbs) |
|
|
|
min_rest_day_fat = min(rest_day_fat_list) |
|
max_rest_day_fat = max(rest_day_fat_list) |
|
mean_rest_day_fat = sum(rest_day_fat_list) / len(rest_day_fat_list) |
|
mode_rest_day_fat = statistics.mode(rest_day_fat_list) |
|
rest_day_fat_std = (min_rest_day_fat, max_rest_day_fat, mean_rest_day_fat, mode_rest_day_fat) |
|
|
|
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 |
|
|
|
def clustering_esfuerzo_dieta_response(response, debug=False): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if " | No data".lower() in response.lower() or 'no data'.lower() in response.lower(): |
|
if debug: print(f"\t\t{response} -> no data") |
|
return 'no data' |
|
elif " | costo subir macros".lower() in response.lower() or 'costo subir macros'.lower() in response.lower(): |
|
if debug: print(f"\t\t{response} -> costo subir macros") |
|
return 'costo subir macros' |
|
elif " | costo bajar macros".lower() in response.lower() or 'costo bajar macros'.lower() in response.lower(): |
|
if debug: print(f"\t\t{response} -> costo bajar macros") |
|
return 'costo bajar macros' |
|
elif " | costo y me adapto a nuevos ajustes".lower() in response.lower() or 'costo y me adapto a nuevos ajustes'.lower() in response.lower(): |
|
if debug: print(f"\t\t{response} -> costo y me adapto a nuevos ajustes") |
|
return 'costo y me adapto a nuevos ajustes' |
|
elif " | no costo".lower() in response.lower() or 'no costo'.lower() in response.lower(): |
|
if debug: print(f"\t\t{response} -> no costo") |
|
return 'no costo' |
|
else: |
|
if debug: print(f"\t\t{response} -> no data") |
|
return 'no data' |
|
|
|
def clustering_objetivo_response(response, debug=False): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if " | definicion".lower() in response.lower() or 'definicion'.lower() in response.lower(): |
|
if debug: print(f"\t\t{response} -> definicion") |
|
return 'definicion' |
|
elif " | volumen".lower() in response.lower() or 'volumen'.lower() in response.lower(): |
|
if debug: print(f"\t\t{response} -> volumen") |
|
return 'volumen' |
|
else: |
|
if debug: print(f"\t\t{response} -> no data") |
|
return 'no data' |
|
|
|
def clustering_entrenamiento_response(response, debug=False): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if " | bien".lower() in response.lower() or 'bien'.lower() in response.lower(): |
|
if debug: print(f"\t\t{response} -> bien") |
|
return 'bien' |
|
elif " | mal".lower() in response.lower() or 'mal'.lower() in response.lower(): |
|
if debug: print(f"\t\t{response} -> mal") |
|
return 'mal' |
|
else: |
|
if debug: print(f"\t\t{response} -> no data") |
|
return 'no data' |
|
|
|
def clustering_cumplimiento_dieta_response(response, debug=False): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if " | bien".lower() in response.lower() or 'bien'.lower() in response.lower(): |
|
if debug: print(f"\t\t{response} -> bien") |
|
return 'bien' |
|
elif " | regular".lower() in response.lower() or 'regular'.lower() in response.lower(): |
|
if debug: print(f"\t\t{response} -> regular") |
|
return 'regular' |
|
elif "nada" in response.lower() or 'mal'.lower() in response.lower(): |
|
if debug: print(f"\t\t{response} -> mal") |
|
return 'mal' |
|
else: |
|
if debug: print(f"\t\t{response} -> no data") |
|
return 'no data' |
|
|
|
def clustering_compromiso_response(response, debug=False): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if " | bueno".lower() in response.lower() or 'bueno'.lower() in response.lower(): |
|
if debug: print(f"\t\t{response} -> bueno") |
|
return 'bueno' |
|
elif " | mal".lower() in response.lower() or 'mal'.lower() in response.lower(): |
|
if debug: print(f"\t\t{response} -> mal") |
|
return 'mal' |
|
else: |
|
if debug: print(f"\t\t{response} -> no data") |
|
return 'no data' |
|
|
|
def clustering_diferencia_peso_response(diff, debug=False): |
|
diff_min = None |
|
diff_max = None |
|
if diff <= -5.0: |
|
if debug: print(f"\t\t-10 <= {diff} <= -5") |
|
diff_min = -10 |
|
diff_max = -5 |
|
elif diff <= -4.5: |
|
if debug: print(f"\t\t-5 <= {diff} <= -4.5") |
|
diff_min = -5 |
|
diff_max = -4.5 |
|
elif diff <= -4.0: |
|
if debug: print(f"\t\t-4.5 <= {diff} <= -4.0") |
|
diff_min = -4.5 |
|
diff_max = -4.0 |
|
elif diff <= -3.5: |
|
if debug: print(f"\t\t-4.0 <= {diff} <= -3.5") |
|
diff_min = -4.0 |
|
diff_max = -3.5 |
|
elif diff <= -3.0: |
|
if debug: print(f"\t\t-3.5 <= {diff} <= -3.0") |
|
diff_min = -3.5 |
|
diff_max = -3.0 |
|
elif diff <= -2.5: |
|
if debug: print(f"\t\t-3.0 <= {diff} <= -2.5") |
|
diff_min = -3.0 |
|
diff_max = -2.5 |
|
elif diff <= -2.0: |
|
if debug: print(f"\t\t-2.5 <= {diff} <= -2.0") |
|
diff_min = -2.5 |
|
diff_max = -2.0 |
|
elif diff <= -1.5: |
|
if debug: print(f"\t\t-2.0 <= {diff} <= -1.5") |
|
diff_min = -2.0 |
|
diff_max = -1.5 |
|
elif diff <= -1.0: |
|
if debug: print(f"\t\t-1.5 <= {diff} <= -1.0") |
|
diff_min = -1.5 |
|
diff_max = -1.0 |
|
elif diff <= -0.5: |
|
if debug: print(f"\t\t-1.0 <= {diff} <= -0.5") |
|
diff_min = -1.0 |
|
diff_max = -0.5 |
|
elif diff <= 0.0: |
|
if debug: print(f"\t\t-0.5 <= {diff} <= 0.0") |
|
diff_min = -0.5 |
|
diff_max = 0.0 |
|
elif diff <= 0.5: |
|
if debug: print(f"\t\t0.0 <= {diff} <= 0.5") |
|
diff_min = 0.0 |
|
diff_max = 0.5 |
|
elif diff <= 1.0: |
|
if debug: print(f"\t\t0.5 <= {diff} <= 1.0") |
|
diff_min = 0.5 |
|
diff_max = 1.0 |
|
elif diff <= 1.5: |
|
if debug: print(f"\t\t1.0 <= {diff} <= 1.5") |
|
diff_min = 1.0 |
|
diff_max = 1.5 |
|
elif diff <= 2.0: |
|
if debug: print(f"\t\t1.5 <= {diff} <= 2.0") |
|
diff_min = 1.5 |
|
diff_max = 2.0 |
|
elif diff <= 2.5: |
|
if debug: print(f"\t\t2.0 <= {diff} <= 2.5") |
|
diff_min = 2.0 |
|
diff_max = 2.5 |
|
elif diff <= 3.0: |
|
if debug: print(f"\t\t2.5 <= {diff} <= 3.0") |
|
diff_min = 2.5 |
|
diff_max = 3.0 |
|
elif diff <= 3.5: |
|
if debug: print(f"\t\t3.0 <= {diff} <= 3.5") |
|
diff_min = 3.0 |
|
diff_max = 3.5 |
|
elif diff <= 4.0: |
|
if debug: print(f"\t\t3.5 <= {diff} <= 4.0") |
|
diff_min = 3.5 |
|
diff_max = 4.0 |
|
elif diff <= 4.5: |
|
if debug: print(f"\t\t4.0 <= {diff} <= 4.5") |
|
diff_min = 4.0 |
|
diff_max = 4.5 |
|
elif diff <= 5.0: |
|
if debug: print(f"\t\t4.5 <= {diff} <= 5.0") |
|
diff_min = 4.5 |
|
diff_max = 5.0 |
|
else: |
|
if debug: print(f"\t\t{diff} -> no data") |
|
diff_min = None |
|
diff_max = None |
|
|
|
return diff_min, diff_max |
|
|
|
def dieta_response(response_esfuerzo, response_cumplimiento, debug=False): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
esfuerzo_dieta_cluster = clustering_esfuerzo_dieta_response(response_esfuerzo, debug) |
|
cumplimiento_dieta_cluster = clustering_cumplimiento_dieta_response(response_cumplimiento, debug) |
|
|
|
if esfuerzo_dieta_cluster == 0: |
|
dieta_bien = cumplimiento_dieta_cluster == 0 |
|
dieta_regular = cumplimiento_dieta_cluster == 1 |
|
dieta_mal = cumplimiento_dieta_cluster == 2 |
|
else: |
|
dieta_bien = esfuerzo_dieta_cluster == 4 and cumplimiento_dieta_cluster == 0 |
|
dieta_regular = esfuerzo_dieta_cluster == 3 and cumplimiento_dieta_cluster == 1 |
|
dieta_mal = (esfuerzo_dieta_cluster == 2 or esfuerzo_dieta_cluster == 1) and cumplimiento_dieta_cluster == 2 |
|
|
|
if dieta_bien: |
|
return 0 |
|
elif dieta_regular: |
|
return 1 |
|
elif dieta_mal: |
|
return 2 |
|
else: |
|
return 3 |
|
|
|
def make_query(cluster_esfuerzo_dieta, cluster_objetivo, cluster_entrenamiento, cluster_cumplimiento_dieta, |
|
cluster_compromiso, diff_peso_min, diff_peso_max, |
|
basic_query=False): |
|
if not basic_query: |
|
query = [ |
|
{ |
|
'esfuerzoParaCumplirDieta': |
|
{ |
|
'operator': 'in', |
|
'value': cluster_esfuerzo_dieta, |
|
} |
|
}, |
|
{ |
|
'objetivo': |
|
{ |
|
'operator': 'in', |
|
'value': cluster_objetivo, |
|
} |
|
}, |
|
{ |
|
'cumplimientoEntrenamiento': |
|
{ |
|
'operator': 'in', |
|
'value': cluster_entrenamiento, |
|
} |
|
}, |
|
{ |
|
'cumplimientoDieta': |
|
{ |
|
'operator': 'in', |
|
'value': cluster_cumplimiento_dieta, |
|
} |
|
}, |
|
{ |
|
'compromiso': |
|
{ |
|
'operator': 'in', |
|
'value': cluster_compromiso, |
|
} |
|
}, |
|
{ |
|
'diferencia_peso': |
|
{ |
|
'operator': '<=', |
|
'value': diff_peso_max, |
|
} |
|
}, |
|
{ |
|
'diferencia_peso': |
|
{ |
|
'operator': '>=', |
|
'value': diff_peso_min, |
|
} |
|
} |
|
] |
|
else: |
|
query = [ |
|
{ |
|
'objetivo': |
|
{ |
|
'operator': 'in', |
|
'value': cluster_objetivo, |
|
} |
|
}, |
|
{ |
|
'cumplimientoEntrenamiento': |
|
{ |
|
'operator': 'in', |
|
'value': cluster_entrenamiento, |
|
} |
|
}, |
|
{ |
|
'cumplimientoDieta': |
|
{ |
|
'operator': 'in', |
|
'value': cluster_cumplimiento_dieta, |
|
} |
|
}, |
|
] |
|
|
|
if cluster_esfuerzo_dieta.lower() == 'costo subir macros'.lower() or cluster_esfuerzo_dieta.lower() == 'costo bajar macros'.lower(): |
|
|
|
query.pop(6) |
|
query.pop(5) |
|
|
|
query.pop(4) |
|
|
|
query.pop(3) |
|
|
|
query.pop(2) |
|
|
|
query.pop(1) |
|
elif cluster_esfuerzo_dieta.lower() == 'no data'.lower(): |
|
|
|
query.pop(0) |
|
|
|
return query |
|
|