|
from pathlib import Path |
|
import json |
|
from datetime import datetime |
|
from tqdm import tqdm |
|
|
|
|
|
formularios_path = 'formularios' |
|
formularios_weight_difference_path = 'formularios_weight_difference' |
|
|
|
|
|
def get_sorted_date_keys(data): |
|
keys = list(data.keys()) |
|
keys_dates = [] |
|
for key in keys: |
|
try: |
|
keys_dates.append(datetime.strptime(key, '%Y-%m-%d')) |
|
except ValueError: |
|
pass |
|
keys_sorted = sorted(keys_dates) |
|
keys_sorted = [key.strftime('%Y-%m-%d') for key in keys_sorted] |
|
keys_sorted = [key.replace('-01', '-1') for key in keys_sorted] |
|
keys_sorted = [key.replace('-02', '-2') for key in keys_sorted] |
|
keys_sorted = [key.replace('-03', '-3') for key in keys_sorted] |
|
keys_sorted = [key.replace('-04', '-4') for key in keys_sorted] |
|
keys_sorted = [key.replace('-05', '-5') for key in keys_sorted] |
|
keys_sorted = [key.replace('-06', '-6') for key in keys_sorted] |
|
keys_sorted = [key.replace('-07', '-7') for key in keys_sorted] |
|
keys_sorted = [key.replace('-08', '-8') for key in keys_sorted] |
|
keys_sorted = [key.replace('-09', '-9') for key in keys_sorted] |
|
return keys_sorted |
|
|
|
|
|
def get_non_date_keys(data): |
|
keys = list(data.keys()) |
|
keys_non_dates = [] |
|
for key in keys: |
|
try: |
|
datetime.strptime(key, '%Y-%m-%d') |
|
except ValueError: |
|
keys_non_dates.append(key) |
|
return keys_non_dates |
|
|
|
|
|
def add_empty_weight_difference(data): |
|
data['diferencia_peso'] = 'None' |
|
return data |
|
|
|
|
|
def change_esfuerzo_para_cumplir_dieta(data): |
|
|
|
data_date_keys = list(get_sorted_date_keys(data)) |
|
|
|
|
|
for key in data_date_keys: |
|
|
|
if 'esfuerzoParaCumplirDieta' not in data[key]: |
|
data[key]['esfuerzoParaCumplirDieta'] = 'None | no data' |
|
|
|
|
|
if 'esfuerzoParaCumplirDieta' in data[key]: |
|
if 'No entiendo la calculadora' in data[key]['esfuerzoParaCumplirDieta'] or 'Iba a coger menús tipo' in data[key]['esfuerzoParaCumplirDieta']: |
|
data[key]['esfuerzoParaCumplirDieta'] += ' | No data' |
|
elif 'Costó demasiado, súbeme macros' in data[key]['esfuerzoParaCumplirDieta']: |
|
data[key]['esfuerzoParaCumplirDieta'] += ' | costo subir macros' |
|
elif 'Costó demasiado, bájame macros' in data[key]['esfuerzoParaCumplirDieta']: |
|
data[key]['esfuerzoParaCumplirDieta'] += ' | costo bajar macros' |
|
elif 'Costó, pero me adapto a nuevos ajustes' in data[key]['esfuerzoParaCumplirDieta']: |
|
data[key]['esfuerzoParaCumplirDieta'] += ' | costo y me adapto a nuevos ajustes' |
|
elif 'No costó nada' in data[key]['esfuerzoParaCumplirDieta']: |
|
data[key]['esfuerzoParaCumplirDieta'] += ' | no costo' |
|
else: |
|
data[key]['esfuerzoParaCumplirDieta'] += ' | no data' |
|
return data |
|
|
|
|
|
def change_cumplimiento_dieta(data): |
|
|
|
data_date_keys = list(get_sorted_date_keys(data)) |
|
|
|
|
|
for key in data_date_keys: |
|
|
|
if 'cumplimientoDieta' not in data[key]: |
|
data[key]['cumplimientoDieta'] = 'None | no data' |
|
|
|
|
|
if 'cumplimientoDieta' in data[key]: |
|
if 'al 70%' in data[key]['cumplimientoDieta'] or 'casi perfecta' in data[key]['cumplimientoDieta'] or 'Perfecta' in data[key]['cumplimientoDieta']: |
|
data[key]['cumplimientoDieta'] += ' | bien' |
|
elif 'regular, me cuesta llegar' in data[key]['cumplimientoDieta'] or 'regular, me salto la dieta' in data[key]['cumplimientoDieta']: |
|
data[key]['cumplimientoDieta'] += ' | regular' |
|
elif 'Nada, mantén mis macros' in data[key]['cumplimientoDieta']: |
|
data[key]['cumplimientoDieta'] += ' | mal' |
|
else: |
|
data[key]['cumplimientoDieta'] += ' | no data' |
|
return data |
|
|
|
|
|
def change_objetivo(data): |
|
|
|
data_date_keys = list(get_sorted_date_keys(data)) |
|
|
|
|
|
for key in data_date_keys: |
|
|
|
if 'objetivo' not in data[key]: |
|
data[key]['objetivo'] = 'None | no data' |
|
|
|
|
|
if 'objetivo' in data[key]: |
|
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']: |
|
data[key]['objetivo'] += ' | definicion' |
|
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']: |
|
data[key]['objetivo'] += ' | volumen' |
|
else: |
|
data[key]['objetivo'] += ' | no data' |
|
return data |
|
|
|
|
|
def change_cumplimiento_entrenamiento(data): |
|
|
|
data_date_keys = list(get_sorted_date_keys(data)) |
|
|
|
|
|
for key in data_date_keys: |
|
|
|
if 'cumplimientoEntrenamiento' not in data[key]: |
|
data[key]['cumplimientoEntrenamiento'] = 'None | no data' |
|
|
|
|
|
if 'cumplimientoEntrenamiento' in data[key]: |
|
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']: |
|
data[key]['cumplimientoEntrenamiento'] += ' | bien' |
|
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']: |
|
data[key]['cumplimientoEntrenamiento'] += ' | mal' |
|
else: |
|
data[key]['cumplimientoEntrenamiento'] += ' | no data' |
|
return data |
|
|
|
|
|
def change_compromiso(data): |
|
|
|
data_date_keys = list(get_sorted_date_keys(data)) |
|
|
|
|
|
for key in data_date_keys: |
|
|
|
if 'compromiso' not in data[key]: |
|
data[key]['compromiso'] = 'None | no data' |
|
|
|
|
|
|
|
if 'compromiso' in data[key]: |
|
if 'Bueno, pero mejorable' in data[key]['compromiso'] or 'Máximo' in data[key]['compromiso']: |
|
data[key]['compromiso'] += ' | bueno' |
|
elif 'Mal, pero a partir de ahora voy a por todas' in data[key]['compromiso'] or 'Mal, demasiado exigente' in data[key]['compromiso']: |
|
data[key]['compromiso'] += ' | mal' |
|
else: |
|
data[key]['compromiso'] += ' | no data' |
|
return data |
|
|
|
|
|
def add_real_weight_difference(data, keys_dates): |
|
number_of_keys_dates = len(keys_dates) |
|
for i in range(1,number_of_keys_dates): |
|
data[keys_dates[i]]['diferencia_peso'] = data[keys_dates[i]]['peso'] - data[keys_dates[i-1]]['peso'] |
|
return data |
|
|
|
if __name__ == '__main__': |
|
|
|
files = Path(formularios_path).glob('*.json') |
|
|
|
|
|
|
|
|
|
|
|
for file in tqdm(files): |
|
|
|
with open(file, 'r') as f: |
|
data = json.load(f) |
|
|
|
|
|
data_sorted = {} |
|
|
|
|
|
keys_dates = get_sorted_date_keys(data) |
|
keys_non_dates = get_non_date_keys(data) |
|
|
|
|
|
for key_date in keys_dates: |
|
data[key_date] = add_empty_weight_difference(data[key_date]) |
|
|
|
|
|
data = add_real_weight_difference(data, keys_dates) |
|
|
|
|
|
data = change_esfuerzo_para_cumplir_dieta(data) |
|
|
|
|
|
data = change_cumplimiento_dieta(data) |
|
|
|
|
|
data = change_objetivo(data) |
|
|
|
|
|
data = change_cumplimiento_entrenamiento(data) |
|
|
|
|
|
data = change_compromiso(data) |
|
|
|
|
|
sorted_keys = keys_non_dates + keys_dates |
|
|
|
|
|
for key in sorted_keys: |
|
data_sorted[key] = data[key] |
|
|
|
|
|
file_path = Path(formularios_weight_difference_path) / file.name |
|
with open(file_path, 'w') as f: |
|
json.dump(data_sorted, f, indent=4) |