diff --git a/config.yml b/config.yml index c69e0ed5..bec82d52 100644 --- a/config.yml +++ b/config.yml @@ -2,9 +2,9 @@ google_drive_data_path: "/Users//Google Drive/My Drive/DATA/fitness-tracker-data" # google_drive_data_path: "/Users//Library/CloudStorage/GoogleDrive-/My Drive/DATA/fitness-tracker-data" -real_workout_database: "//db.json" +real_workout_database: "//db.yml" # "//db.json" real_disciplines_database: "//real_disciplines.json" -simulated_workout_database: "/sim_db.json" +simulated_workout_database: "/sim_db.yml" # "/sim_db.json" real_weight_table: "weight_training_log" real_disciplines_table: "disciplines_log" simulated_weight_table: "weight_training_log" diff --git a/src/helpers/custom_storage.py b/src/helpers/custom_storage.py new file mode 100644 index 00000000..9bb50b79 --- /dev/null +++ b/src/helpers/custom_storage.py @@ -0,0 +1,27 @@ +import yaml # type: ignore + +from tinydb import TinyDB # type: ignore + + +class YAMLStorage(Storage): + def __init__(self, filename): + self.filename = filename + + def read(self): + with open(self.filename) as handle: + try: + data = yaml.safe_load(handle.read()) + return data + except yaml.YAMLError: + return None + + def write(self, data): + with open(self.filename, 'w+') as handle: + yaml.dump(data, handle) + + def close(self): + pass + + +if __name__ == "__main__": + db = TinyDB('db.yml', storage=YAMLStorage) diff --git a/src/helpers/json_to_yaml.py b/src/helpers/json_to_yaml.py new file mode 100644 index 00000000..bf3ac59f --- /dev/null +++ b/src/helpers/json_to_yaml.py @@ -0,0 +1,18 @@ +import json +import yaml + + +def json_to_yaml(in_file: str) -> None: + """Create YAML file from JSON file, without sorting keys alphabetically. + + :param in_file: absolute path to JSON file + :type in_file: str + """ + + with open(in_file, 'r') as rf, open(in_file.replace('json', 'yml'), "w") as wf: + yaml.dump(json.load(rf), wf, sort_keys=False) + + +if __name__ == "__main__": + in_file = "/Users/gustavcollinrasmussen/Library/CloudStorage/GoogleDrive-gcr84@hotmail.com/My Drive/DATA/fitness-tracker-data/gustav_rasmussen/log_archive/JSON/2023/June/test.json" + json_to_yaml(in_file) diff --git a/src/helpers/set_db_and_table.py b/src/helpers/set_db_and_table.py index f1a432c6..30a5f204 100644 --- a/src/helpers/set_db_and_table.py +++ b/src/helpers/set_db_and_table.py @@ -12,6 +12,8 @@ from tinydb import TinyDB # type: ignore +from custom_storage import YAMLStorage + def set_db_and_table( datatype, @@ -56,14 +58,16 @@ def set_db_and_table( DATA["real_workout_database"] .replace("", athlete) .replace("", user) - .replace("", email) + .replace("", email), + storage=YAMLStorage ) if datatype == "real" else TinyDB( DATA["simulated_workout_database"], - sort_keys=True, - indent=4, - separators=(",", ": "), + storage=YAMLStorage + # sort_keys=True, + # indent=4, + # separators=(",", ": "), ) ) table = ( diff --git a/src/orchestration/real_flow.sh b/src/orchestration/real_flow.sh index e4d4ed5f..31f3ed3a 100755 --- a/src/orchestration/real_flow.sh +++ b/src/orchestration/real_flow.sh @@ -5,7 +5,7 @@ # Author: Gustav Collin Rasmussen # Purpose: BASH workflow that inserts data in database. -WORKOUT_DATE=$(date +%F) # '2023-01-19' # 2022-03-02,2022-03-03 +WORKOUT_DATE='2023-06-23' # $(date +%F) # '2023-01-19' # 2022-03-02,2022-03-03 # TRAINING_PROGRAM='nfp' # 'gvt' # --workout_number 2 @@ -14,27 +14,27 @@ if ! python3 ./src/CRUD/insert.py --datatype real --dates "$WORKOUT_DATE"; then exit 1 fi -echo "Data inserted in database. Preparing figures..." +# echo "Data inserted in database. Preparing figures..." -if ! python3 ./src/combined_metrics/combined_metrics.py; then - echo "Error: Failed to prepare figures." - exit 1 -fi +# if ! python3 ./src/combined_metrics/combined_metrics.py; then +# echo "Error: Failed to prepare figures." +# exit 1 +# fi # python3 src/model/plot_model.py --datatype real --pgm $TRAINING_PROGRAM -open_images() { - open ./img/workout_frequency.png - open ./img/workout_duration.png +# open_images() { +# open ./img/workout_frequency.png +# open ./img/workout_duration.png # open img/real_fitted_data_squat_${TRAINING_PROGRAM}.png # open img/real_fitted_data_barbell_bench_press_${TRAINING_PROGRAM}.png # open img/real_fitted_data_squat_splines.png # open img/real_fitted_data_deadlift_splines.png # open img/real_fitted_data_seated_row_splines.png # open img/real_fitted_data_barbell_bench_press_splines.png -} +# } -if ! open_images; then - echo "Error: Failed to open images." - exit 1 -fi +# if ! open_images; then +# echo "Error: Failed to open images." +# exit 1 +# fi