def generate_new_workouts(user, move_to_next_week=True): user.workout_logger = WorkoutLogger.for_user(user) user.workout_logger.log_start() old_framework = DayFrameworkCollection.get_for_user(user) if move_to_next_week: # added the option to backfill workouts in case of a bug user.move_to_next_week() day_framework_collection = _generate_day_frameworks(user) user.workout_logger.log_initial_day_framework_collection(day_framework_collection) new_workouts = _generate_workouts(user, day_framework_collection) workout_collection = WorkoutCollection(new_workouts, day_framework_collection) _swap_empty_workouts(workout_collection) _swap_one_cardio_day(workout_collection) for workout in workout_collection.workout_list: _trim_to_time(workout, user) old_framework.delete() user.workout_logger.log_end() user.workout_logger.commit() return workout_collection
def _generate_day_frameworks(user): isoweekday_to_components = _fill_isoweekdays_with_workout_components(user) isoweekday_to_cardio_intensity = _fill_isoweekdays_with_cardio_intensity(user, isoweekday_to_components) _mandate_cardio_or_resistance(isoweekday_to_components, isoweekday_to_cardio_intensity) _evenly_distribute_cardio_lifting_days(isoweekday_to_components, isoweekday_to_cardio_intensity) return DayFrameworkCollection.create(user, isoweekday_to_components, isoweekday_to_cardio_intensity)