def pbar(age, weight, performance, sex, hideprogram): """ Makes recommendation based on performance before the training program. """ if sex == 'MAN': converted_sex = 0 elif sex == 'WOMAN': converted_sex = 1 else: converted_sex = 2 data = np.array([age, weight, converted_sex, performance]).reshape(1, -1) recengine = RecommendationEngine("pbar") best_pred, _ = recengine.recommend_training(data) click.secho("\nTraining program: " + best_pred["model"].name, fg="green") click.secho("Predicted performance: " + str(best_pred["predicted_performance"]) + "\n", fg="green") hide_program_output = hideprogram if hide_program_output is False: program = fetch_program_from_model(best_pred["model"]) click.secho("Program structure: ", fg="green") for day, sets in program.items(): click.secho("Day: " + str(day), fg="green") for i, p_set in enumerate(sets): calculated_weight = (p_set.percent_1rm / 100 * performance) click.secho(" (Set " + str(i) + ") Weight: " + str(calculated_weight) + " Reps: " + str(p_set.repetitions))
def formttr(): name = request.form.get("fname") file = request.files["ffile"] stream = io.StringIO(file.stream.read().decode("UTF8"), newline=None) # TODO Let user input format. ttrdata = ttrdata_from_csv_bytes(stream, "%m/%d/%Y %H:%M") four_weeks_ttrdata = ttrdata[-8:] data = np.array(four_weeks_ttrdata).reshape(1, -1) recengine = RecommendationEngine("ttr") best_pred, _ = recengine.recommend_training(data) program = fetch_program_from_model(best_pred["model"]) return render_template( "ttr.html", best_pred=best_pred["model"].name, predicted_performance=best_pred["predicted_performance"], program=program, performance=four_weeks_ttrdata[-1], name=name)
def formpbar(): recengine = RecommendationEngine("pbar") name = request.form.get("fname") age = int(request.form.get("fage")) sex = int(request.form.get("fsex")) weight = float(request.form.get("fweight")) performance = float(request.form.get("fperformance")) data = np.array([age, weight, sex, performance]).reshape(1, -1) best_pred, _ = recengine.recommend_training(data) program = fetch_program_from_model(best_pred["model"]) return render_template( "index.html", age=age, sex=sex, weight=weight, performance=performance, best_pred=best_pred["model"].name, predicted_performance=best_pred["predicted_performance"], program=program, name=name)
def pbar(age, weight, performance, sex, hideprogram): """ Makes recommendation based on performance before the training program. """ if sex == 'MAN': converted_sex = 0 elif sex == 'WOMAN': converted_sex = 1 else: converted_sex = 2 data = np.array([age, weight, converted_sex, performance]).reshape(1, -1) recengine = RecommendationEngine("pbar") best_pred, _ = recengine.recommend_training(data) click.secho("\nTraining program: " + best_pred["model"].name, fg="green") click.secho("Predicted performance: " + str(best_pred["predicted_performance"]) + "\n", fg="green") if hideprogram is False: print_training_program_from_model(best_pred["model"], performance)
def ttr(): sets = request.json.get('sets', []) time_format = request.json.get('timeformat', '') weeks = split_into_weeks(sets, time_format) if len(weeks.keys()) < 4: return jsonify(error=400, text="Sets spanning atleast four weeks is required.") ttr_d = calculate_ttrdata_from_week_dict(weeks) four_weeks_ttrdata = ttr_d[-8:] data = np.array(four_weeks_ttrdata).reshape(1, -1) recengine = RecommendationEngine("ttr") best_pred, _ = recengine.recommend_training(data) program = fetch_program_from_model(best_pred["model"]) res = { "predicted_performance": best_pred["predicted_performance"], "training_program": best_pred["model"].name, "program_structure": program, "calculated_current_1rm": four_weeks_ttrdata[-1] } return jsonify(res)
def ttr(file, timeformat, weeks, hideprogram): """ Using previous training data makes an recommendation. Format of the CSV file should be the following with '|' delimiters: Exercice | Weight | Reps | Timestamp """ if weeks != 4: click.secho( "\nINFO: Only 4 weeks is supported currently. Changing to 4.", fg="yellow") weeks = 4 full_path = os.path.join(os.getcwd(), file) ttrdata = ttrdata_from_csv(full_path, timeformat) if len(ttrdata) < weeks * 2: click.secho("The inputted data has to span atleast " + str(weeks) + " weeks", fg="red") return elif len(ttrdata) >= weeks * 2: correct_length_ttr = ttrdata[-(weeks * 2):] data = np.array(correct_length_ttr).reshape(1, -1) recengine = RecommendationEngine("ttr") best_pred, _ = recengine.recommend_training(data) click.secho("\nTraining program: " + best_pred["model"].name, fg="green") click.secho("Predicted performance: " + str(best_pred["predicted_performance"]) + "\n", fg="green") if hideprogram is False: print_training_program_from_model(best_pred["model"], ttrdata[-1])
def pbar(): recengine = RecommendationEngine("pbar") age = int(request.json.get('age', '')) weight = float(request.json.get('weight', '')) sex = request.json.get('sex', '') performance = float(request.json.get('performance', '')) if sex == 'MAN': converted_sex = 0 elif sex == 'WOMAN': converted_sex = 1 else: converted_sex = 2 data = np.array([age, weight, converted_sex, performance]).reshape(1, -1) best_pred, all_predictions = recengine.recommend_training(data) program = fetch_program_from_model(best_pred["model"]) res = { "predicted_performance": best_pred["predicted_performance"], "training_program": best_pred["model"].name, "program_structure": program } return jsonify(res)