Skip to main content

Intervals.icu to InfluxDB

Intervalsicu-to-influxdb is a personal project to extract data from Intervals.icu to InfluxDB (oh, really?). But if Intervals.icu already shows a lot of graphics, statistics and more, why I need to extract it?

Full documentation can be found in here

Why

Well, as a sportsman and techie, it's just a personal project, but the main reason is because I want to create my own dashboards (using Grafana in this case).

So, for example, I can combine activity data with sleep time or quality, compare the evolution between pace/bpm for the similar activities or whatever.

Grafana Dashboard example Grafana Dashboard example2

How it works

This project exports some data from intervals.icu to influxDB. To retrieve the information the official intervals.icu API is used.

Exported data

Not all information is exported. This project has been created to extract data from activities and wellness. Besides, information about data account (like email, location, preferences, etc.), calendar or workouts are not retrieved neither (for now).

Currently the following data is exported:

  • Wellness*: this data contains information like sleep time and quality, atl/ctl or VO2Max
  • Activities*: general information about every activity, like elapsed time, time in zones (hr or pace), distance, average pace/hr, etc.
  • Streams**: streams contains detailed information about activities, like hr/pace for every second.

* There are som extra fields generated, just to facilitate the use for the dashboards (see Entities)

** Currently working on it.

How to use

There are 2 ways (3 if you count 'from source code') to use the project: with Docker or directly with Python (or from source code), but in both cases you need to create a .env file to save your credentials for Intervals.icu and InfluxDB as follow:

INFLUXDB_TOKEN=
INFLUXDB_ORG=
INFLUXDB_URL=
INFLUXDB_BUCKET=
INFLUXDB_TIMEOUT=10000
INTERVALS_ATHLETE_ID=
INTERVALS_API_KEY=

With Python

If you want to run it directly with Python, first install the dependency:

pip install intervalsicu-to-influxdb

Then, the minimum code to run it is (remember to put the .env file on the same folder):

from intervalsicu_to_influxdb.extractor import IntervalsToInflux

extractor = IntervalsToInflux()
extractor.all_data()

To run it, just save as app.py and run it:

python app.py

Arguments

All the arguments are optional, but take in consideration the following variations when run it:

  • No arguments: retrieve the wellness and activities data for today (this is the basic use to run with a cronjob)
  • date: retrieve data for the defined date (in format YYYY-MM-DD)
  • start-date: retrieve data from the starting date (in format YYYY-MM-DD) until today
  • end-date: retrieve data until specified date (in format YYYY-MM-DD). Use it with start-date
  • streams: retrieve the streams for the activities
  • reset: delete the current bucket and recreate again

NOTE: on the first run, the bucket is created automatically if not exists on InfluxDB

extractor = IntervalsToInflux(start_date="2023-01-01")
extractor = IntervalsToInflux(streams=True)
extractor = IntervalsToInflux(start_date="2023-01-01", end_date="2023-05-01")

Dynamic script

If you want to create a more dynamic script, here is a more complete example:

import argparse

from intervalsicu_to_influxdb.extractor import IntervalsToInflux

parser = argparse.ArgumentParser()

parser.add_argument("--date", type=str, help="Date in format YYYY-MM-DD")
parser.add_argument("--start-date", type=str, help="Start date in format YYYY-MM-DD")
parser.add_argument("--end-date", type=str, help="End date in format YYYY-MM-DD")
parser.add_argument(
    "--streams",
    action="store_true",
    help="Export streams for the activities",
)
parser.add_argument(
    "--reset", action="store_true", help="Reset influx bucket (delete and create)"
)

args = parser.parse_args()

if args.date:
    date = args.date
else:
    date = None
if args.start_date:
    start_date = args.start_date
else:
    start_date = None
if args.end_date:
    end_date = args.end_date
else:
    end_date = None
if args.streams:
    streams = True
else:
    streams = False
if args.reset:
    reset = True
else:
    reset = False

extractor = IntervalsToInflux(date, start_date, end_date, reset, streams)
extractor.all_data()

Then, just run the script as before, but you will can use arguments (same as the Docker section):

python app.py [-h] [--date DATE] [--start-date START_DATE] [--end-date END_DATE] [--streams] [--reset]

From source code

If you want to run it from source code, just clone the project, and the follow the next steps (remember to create the .env file):

Run with Docker

First, compile the image

docker build --tag intervals-to-influxdb .

And then, just run it like the Docker section above (but with the image name)

docker run --env-file PATH/TO/FILE -it --rm intervals-to-influxdb app.py [-h] [--date DATE] [--start-date START_DATE] [--end-date END_DATE] [--streams] [--reset]

Run with Python

First, install dependencies from source

pip install .

And then, run the script

python app.py [-h] [--date DATE] [--start-date START_DATE] [--end-date END_DATE] [--streams] [--reset]

Metadata

Release files for intervalsicu-to-influxdb 0.2.50

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for intervalsicu-to-influxdb 0.2.50
File Size Uploaded
intervalsicu_to_influxdb-0.2.50.tar.gz 336.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for intervalsicu-to-influxdb 0.2.50
File Interpreter ABI Platform
intervalsicu_to_influxdb-0.2.50-py3-none-any.whl Python 3 none any Details

Total release size: 352.6 kB

Release files / intervalsicu_to_influxdb-0.2.50.tar.gz

Download URL intervalsicu_to_influxdb-0.2.50.tar.gz
Size 336.7 kB
Tags Source
SHA-256 checksum
How to use checksums
c93c8fd32e22eaabb64b0430cbc0b42151bff344e42d3752e2ae3a81bb8ab3fc
BLAKE2b-256 checksum
How to use checksums
bf4554fe81e4f92c538b24bc1db6728398cc4020f6ac2ac37312303fff2acd05
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.13

Release files / intervalsicu_to_influxdb-0.2.50-py3-none-any.whl

Download URL intervalsicu_to_influxdb-0.2.50-py3-none-any.whl
Size 15.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3b36e28136675f80c3eadf28be9ee0abcdc9236568750f2ec7ec02fe955645b6
BLAKE2b-256 checksum
How to use checksums
65eadb24f8da596c3767408ce1c868ba143ac64d102d7e5e7df596239c9804c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.13

Release history Release notifications | RSS feed

This release

0.2.50 This release

2 release files

0.2.43

2 release files

0.2.42

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page