nolito.training module

class nolito.training.Training(nolio_id=None, id_partner=None, name=None, date_start=None, date_end=None, hour_start=None, description=None, sport=None, sport_id=None, duration=None, distance=None, feeling=None, rpe=None, elevation_gain=None, elevation_loss=None, load_foster=None, load_coggan=None, is_competition=None, kilojoules=None, avg_watt=None, max_watt=None, athlete_id=None, structured_workout=None, planned=True)[source]

Bases: object

A training payload for the Nolio API

Full reference: https://github.com/NolioApp/NolioAPI-Documentation/wiki/Training-Object

This is a Data Class <https://docs.python.org/3/library/dataclasses.html>_ so all parameters are also attributes.

Parameters:
  • nolio_id (int | None) – ID assigned by the nolio website

  • id_partner (int | None) – ID assigned by the local “partner” app

  • name (str | None) – Name of the training

  • date_start (str | None) – Start date (YYYY-MM-DD)

  • date_end (str | None) – End date (YYYY-MM-DD)

  • hour_start (str | None) – Start time

  • description (str | None) – Training description

  • sport (str | None) – Sport name

  • sport_id (int | None) – Nolio sport ID (https://github.com/NolioApp/NolioAPI-Documentation/wiki/Training-Object#sport-map)

  • duration (int | None) – Workout duration in min

  • distance (int | float | None) – Workout distance in km

  • feeling (int | None) – Athlete feeling

  • rpe (int | None) – Athlete RPE

  • elevation_gain (int | None) – Elevation gain

  • elevation_loss (int | None) – Elevation loss

  • load_foster (float | None) – Foster load

  • load_coggan (float | None) – Coggan load

  • is_competition (bool | None) – True if the workout is a competition

  • kilojoules (int | None) – Kilojoules spent

  • avg_watt (int | None) – Average power in watts

  • max_watt (int | None) – Max power in watts

  • athlete_id (int | None) – Athlete ID (assigned by Nolio)

  • structured_workout (list | None) – Structured workout dictionary

  • planned (bool) – Whether this is a planned workout. Not sent to the Nolio API, for local use only.

property completed: bool

Is the training a completed workout?

return: Returns the opposite of Training.planned

copy()[source]

Return a deepcopy of the training

Return type:

Training

classmethod from_json(path)[source]

Load the training from a JSON file

Parameters:

path (Path | str) – Path to the JSON file

Raises:

TypeError – Raised if the JSON data is not a dictionary

Return type:

Self

Returns:

The training object read from the file

to_dict(keep_none=False)[source]

Convert the training object to a dictionary

This is useful to interact with the Nolio API or to save trainings to JSON files.

Parameters:

keep_none (bool) – Keep fields that have a none value if True (defaults to False)

Return type:

dict[str, Any]

Returns:

The training dictionary

to_edit_dict()[source]

Convert the training object to a dictioanry for POST requests

Only keys compatible with the API’s POST requests are included, when they are not None.

Return type:

dict

Returns:

The POST ready dictionary

to_json(path)[source]

Save the training to a json file

Uses Training.to_dict()

Parameters:

path (Path | str) – Path to the JSON file

class nolito.training.TrainingSet(trainings)[source]

Bases: Sequence[Training]

A set of Training objects

Useful to construct a training calendar or a training plan

Parameters:

trainings (list[dict[str, Any] | Training]) – List of training objects or dictionaries used as input If trainings contains dictionaries, they are converted to Training instances

Variables:

trainings (list [Training]) – List of training objects stored internally

classmethod from_json(path)[source]

Create a training set from a JSON file

Parameters:

path (Path | str) – Path to the JSON file

Raises:

TypeError – Raised if the JSON is not a list of dictionaries

Return type:

Self

Returns:

The newly create training set

to_dicts()[source]

Convert the objects to a list of dictionaries

Converts the trainings with Training.to_dict()

Return type:

list[dict[str, Any]]

Returns:

List of dictionaries with training info

to_json(path)[source]

Save the trainings to JSON a list of dictionaries

Parameters:

path (Path | str) – Path to the JSON file

trainings: list[Training]
nolito.training.with_step_types(steps)[source]

Ensure that each step in a structured workout has a "type" field

The default type "step".

Parameters:

steps (list[dict]) – The structured workout dictionary

Return type:

list[dict]

Returns:

The normalized structured workout dictionary