src.utils package

Submodules

src.utils.cleanup module

Empty specified folder or file.

src.utils.cleanup.main() None[source]

Empty specified folder or file.

src.utils.config_loader module

src.utils.custom_storage module

Extend TinyDB to use YAML as storage.

class src.utils.custom_storage.YAMLStorage(filename, **kwargs)[source]

Bases: Storage

YAML storage for TinyDB.

close()[source]

Optional: Close open file handles, etc.

read()[source]

Read the current state.

Any kind of deserialization should go here.

Return None here to indicate that the storage is empty.

write(data)[source]

Write the current state of the database to the storage.

Any kind of serialization should go here.

Parameters:

data – The current state of the database.

src.utils.custom_storage.main() None[source]

Load a TinyDB database using YAML storage.

src.utils.get_bodyweight module

Get the bodyweight from the google sheet.

src.utils.get_bodyweight.get_bw() float[source]

Get the bodyweight from the google sheet.

Returns:

Bodyweight in kg

Return type:

float

src.utils.get_bodyweight.main() None[source]

Get the bodyweight from the google sheet.

src.utils.get_breath_holding module

Get breath holding data from Google Sheet and plot min, max, and mean duration.

src.utils.get_breath_holding.get_breath_holding(sheet_title: str) DataFrame[source]

Get the breath holding data from the Google Sheet.

Parameters:

sheet_title (str) – Title of the Google Sheet

Returns:

Breath holding data

Return type:

pd.DataFrame

src.utils.get_breath_holding.get_sheet_title(year: int, month: int) str[source]

Get the title of the Google Sheet.

Parameters:
  • year (int) – Year

  • month (int) – Month

Returns:

Title of the Google Sheet

Return type:

str

src.utils.get_breath_holding.main() None[source]

Get the breath holding data from the Google Sheet and make a figure.

src.utils.get_breath_holding.make_figure(df, year, sheet_title) None[source]

Make a figure of min, max, and mean breath holding duration.

Parameters:

df (pd.DataFrame) – Breath holding data

src.utils.get_exercises module

Get all exercises available for a given musclegroup.

src.utils.get_exercises.get_available_exercises(training_catalogue: str, split: str) list[str][source]

Fetch musclegroup-exercises catalogue.

Parameters:
  • training_catalogue (str) – Exercises available for each musclegroup

  • split (str) – Name of musclegroup

Returns:

A list of available exercises for a given split / musclegroup

Return type:

list

src.utils.get_exercises.main() None[source]

Get all exercises available for a given musclegroup.

src.utils.get_program module

Get the workout program based on the workout date.

src.utils.get_program.get_pgm_from_date(workout_date: str) str | None[source]

Get the workout program based on the workout date.

Parameters:

workout_date (str) – date in the format ‘YYYY-MM-DD’

Returns:

name of the workout program

Return type:

str

src.utils.get_program.main() None[source]

Get the workout program based on the workout date.

src.utils.get_program.parse_date(date_str: str) datetime | None[source]

Parse the date string.

Parameters:

date_str (str) – date in the format ‘YYYY-MM-DD’

Returns:

date object

Return type:

dt | None

src.utils.get_split module

Get the split of the workout.

class src.utils.get_split.Split(value)[source]

Bases: Enum

BACK = 2
CHEST = 1
LEGS = 3

src.utils.get_volume module

Get the total workout volume of each date in the table. In the case of multiple workouts on the same day, the volume is the sum of the volumes of the workouts.

src.utils.get_volume.get_total_volume(table) list[tuple[str, int]][source]

Get the total volume of all workouts, summing volumes for the same date.

Parameters:

table (tinydb.table.Table) – TinyDB table

Returns:

List of tuples containing the date and total volume of each workout

Return type:

list[tuple[str, int]]

src.utils.get_volume.get_weight(s: dict, bodyweight: str, Sidea_9012_Olympic_Hex_Bar: str) int[source]

Get the weight of the exercise.

Parameters:
  • s (dict) – Dictionary containing the exercise details

  • bodyweight (str) – Bodyweight of the person in kg

  • Sidea_9012_Olympic_Hex_Bar (str) – Weight of the barbell

Returns:

Weight of the exercise

Return type:

float

src.utils.get_volume.main() None[source]

Get the total volume of each workout in the table.

src.utils.get_workout_duration module

Get the workout duration on each date in a given year. In the case of multiple workouts on the same day, the duration is the sum of the durations of the workouts.

src.utils.get_workout_duration.get_all_durations(year: str) dict[source]

Get the total duration of all workouts in a given year, summing durations for the same date.

Parameters:

year (str) – Year to get the duration of each workout for.

Returns:

Dictionary with the date as the key and the duration of the workout as the value.

Return type:

dict

src.utils.get_workout_duration.main() None[source]

Display the duration of each workout in a given year.

src.utils.google_sheet module

Google Sheets API.

src.utils.google_sheet.get_sheet(sheet_id: str, sheet_title: str) Worksheet[source]

Get a Google Sheet by its ID and title.

Parameters:
  • sheet_id (str) – ID of the Google Sheet.

  • sheet_title (str) – Title of the Google Sheet.

Returns:

Google Sheet.

Return type:

gspread.Worksheet

src.utils.google_sheet.main() None[source]

Display a Google Sheet.

src.utils.google_sheet.update_sheet() None[source]

Update a Google Sheet.

src.utils.logger_config module

Logging configuration for the project.

src.utils.logger_config.log_running_file(file_path: str) None[source]

Optional utility for logging the running file.

src.utils.logger_config.setup_logger(log_file: str = 'insert.log', log_dir: str = 'logs/') None[source]

Set up the logger for the project.

Parameters:
  • log_file (str, optional) – Name of the log file, defaults to “insert.log”

  • log_dir (str, optional) – Name of the log directory, defaults to “logs/”

src.utils.set_db_and_table module

Set db and table depending on datatype (real/simulated).

class src.utils.set_db_and_table.TinyDBSingleton(db_path: str, storage=<class 'src.utils.custom_storage.YAMLStorage'>)[source]

Bases: object

Singleton class for TinyDB.

close()[source]
get_db()[source]
src.utils.set_db_and_table.main() None[source]

Main function.

src.utils.set_db_and_table.set_db_and_table(datatype, athlete=None, year=None, env='prd')[source]

Set up database and table based on datatype (real/simulated).

Parameters:
  • datatype (str) – Type of data to be used, either “real” or “simulated”

  • athlete (str, optional) – Athlete name, defaults to None

  • year (int, optional) – Year of the data, defaults to None

  • env (str, optional) – Environment, defaults to “prd”

Returns:

Database, table and training catalogue

Return type:

tuple

src.utils.validate module

Validates workout data from a JSON or YAML file.

exception src.utils.validate.ExercisesFormatError(value: str, message: str)[source]

Bases: Exception

Custom error that is raised when Exercises doesn’t have the right format.

class src.utils.validate.Workout(*, date: str, start_time: str, end_time: str, split: str, exercises: dict, warmup: str | None = None, cooldown: str | None = None, gym: str | None = None, notes: str | None = None)[source]

Bases: BaseModel

Represents a Workout from a JSON or YAML file.

cooldown: str | None
date: str
end_time: str
classmethod exercise_valid(value) dict[source]

Validate exercises using the WorkoutValidator.

exercises: dict
gym: str | None
model_config = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

notes: str | None
split: str
start_time: str
warmup: str | None
class src.utils.validate.WorkoutFactory[source]

Bases: object

Factory for creating Workout instances.

static create_workout(data: dict) Workout[source]

Create a Workout instance from the given data.

static create_workouts_from_json(file_path: str) list[Workout][source]

Creates a list of Workout instances from a JSON file.

static create_workouts_from_yaml(file_path: str) list[Workout][source]

Creates a list of Workout instances from a YAML file.

class src.utils.validate.WorkoutValidator[source]

Bases: object

Handles validation of workout data.

static validate_exercises(value: dict) None[source]

Validator to check whether exercises are valid.

src.utils.validate.main() None[source]

Main function.

Module contents