From feb00df8c5fe90db2ee4628c89aac0546d645297 Mon Sep 17 00:00:00 2001 From: gabriel becker Date: Fri, 12 Jan 2024 19:21:28 +1100 Subject: [PATCH] Working version with repetition and tiem mode --- open_workout_coach/__main__.py | 6 +++--- .../create_open_workout_database.py | 9 +++++++-- open_workout_coach/load_exercises.py | 3 +-- open_workout_coach/map_yaml_to_database.py | 17 +++++++++-------- readme.md | 17 +++++++++-------- 5 files changed, 29 insertions(+), 23 deletions(-) diff --git a/open_workout_coach/__main__.py b/open_workout_coach/__main__.py index dcde924..b23300e 100644 --- a/open_workout_coach/__main__.py +++ b/open_workout_coach/__main__.py @@ -11,13 +11,13 @@ def cli(): @cli.command() @click.argument('input_path', type=click.Path(exists=True)) -@click.argument('output_path', type=click.Path(exists=False)) -def create_plan(input_path, output_path): +@click.argument('output_destination', type=click.Path(exists=True)) +def create_plan(input_path, output_destination): """ Creates a openworkout plan from the input yaml file. """ config = load_file_and_media_links(file_path=input_path) - process_config_into_workout_file(config=config, output_file=output_path) + process_config_into_workout_file(config=config, output_destination=output_destination) FILE = 'data/input/samples/exercises.yaml' diff --git a/open_workout_coach/create_open_workout_database.py b/open_workout_coach/create_open_workout_database.py index 237092b..dba598c 100644 --- a/open_workout_coach/create_open_workout_database.py +++ b/open_workout_coach/create_open_workout_database.py @@ -69,8 +69,12 @@ def get_item_id(): start += 1 -def create_item(name, workout_time, n_repetitions, description=None, preparation_time=5, video_path=None): +def create_item( + name, workout_time=30, n_repetitions=None, description=None, + preparation_time=5, video_path=None, break_time=5 +): is_video_mode = True if video_path else False + is_time_mode = False if n_repetitions else True new_item = dict(WOPRKOUT_ITEM) new_item_content = { @@ -79,13 +83,14 @@ def create_item(name, workout_time, n_repetitions, description=None, preparation 'elapsedTime': 0, 'imagePath': '', 'isImagePathExternal': False, - 'isTimeMode': True, + 'isTimeMode': is_time_mode, 'isVideoMode': is_video_mode, 'prepTime': preparation_time, 'repetitionCount': n_repetitions, 'videoPath': video_path, "orderNr": next(get_item_id()), "workoutItemId": 0, + "breakTime": break_time, "workoutSessionId": 1, 'workoutTime': workout_time } diff --git a/open_workout_coach/load_exercises.py b/open_workout_coach/load_exercises.py index a598be3..77deecb 100644 --- a/open_workout_coach/load_exercises.py +++ b/open_workout_coach/load_exercises.py @@ -20,7 +20,7 @@ def create_gif_from_video_and_timestamps(video_path, start, end): output_dir = tempfile.mktemp() + '.mp4' clip.without_audio().write_videofile(output_dir) return output_dir - + def load_file_and_media_links(file_path): file = open(file_path) @@ -30,7 +30,6 @@ def load_file_and_media_links(file_path): video_url = ex['video'] start = ex['start'] end = ex['end'] - video_path = get_video(video_url) gif = create_gif_from_video_and_timestamps(video_path, start, end) ex['gif_path'] = gif diff --git a/open_workout_coach/map_yaml_to_database.py b/open_workout_coach/map_yaml_to_database.py index 078eca1..a9cd5be 100644 --- a/open_workout_coach/map_yaml_to_database.py +++ b/open_workout_coach/map_yaml_to_database.py @@ -84,26 +84,27 @@ def map_config_to_workout_file(config): items = [ create_item( name=item['name'], - workout_time=30, - n_repetitions=1, - description=None, - preparation_time=5, - video_path=item['gif_path'] + workout_time=item.get('duration'), + n_repetitions=item.get('repetitions'), + description=item.get('description'), + preparation_time=item.get('preparation'), + break_time=item.get('break'), + video_path=item.get('gif_path') ) for item in config['exercises'] ] - sessions = [create_workout_session(items)] * 30 + sessions = [create_workout_session(items)] * config['n_sessions'] db = create_workout_database(config['name'], sessions) return db -def process_config_into_workout_file(config, output_file = None): +def process_config_into_workout_file(config, output_destination = None): db = map_config_to_workout_file(config) videos = get_all_media_from_db_by_type(db, media_type='video') images = get_all_media_from_db_by_type(db, media_type='image') db = refactor_media_paths_in_db(db) - output_file_name = output_file or f"{db['name']}.zip" + output_file_name = f"{output_destination or '.'}/{db['name']}.zip" save_workout_file( output_files=output_file_name, db_file=db, diff --git a/readme.md b/readme.md index 6a036b9..01417b4 100644 --- a/readme.md +++ b/readme.md @@ -3,15 +3,16 @@ Creates a workout plan form an yaml file that can be imported to