sksports.Rider

class sksports.Rider(n_jobs=1)[source][source]

User interface for a rider.

User interface to easily add, remove, compute information related to power.

Read more in the User Guide.

Parameters:
n_jobs : int, (default=1)

The number of workers to use for the different processing.

Attributes:
power_profile_ : DataFrame

DataFrame containing all information regarding the power-profile of a rider for each ride.

__init__(n_jobs=1)[source][source]

x.__init__(…) initializes x; see help(type(x)) for signature

Methods

__init__([n_jobs]) x.__init__(…) initializes x; see help(type(x)) for signature
add_activities(filenames) Compute the power-profile for each activity and add it to the current power-profile.
delete_activities(dates[, time_comparison]) Delete the activities power-profile from some specific dates.
from_csv(filename[, n_jobs]) Load rider information from a CSV file.
record_power_profile([range_dates, columns]) Compute the record power-profile.
to_csv(filename) Drop the rider information into a CSV file.
add_activities(filenames)[source][source]

Compute the power-profile for each activity and add it to the current power-profile.

Parameters:
filenames : str or list of str

A string a list of string to the file to read. You can use wildcards to automatically check several files.

Returns:
None

Examples

>>> from sksports.datasets import load_fit
>>> from sksports.base import Rider
>>> rider = Rider()
>>> rider.add_activities(load_fit()[0])
>>> rider.power_profile_.head() 
                  2014-05-07 12:26:22
cadence 00:00:01            78.000000
        00:00:02            64.000000
        00:00:03            62.666667
        00:00:04            62.500000
        00:00:05            64.400000
delete_activities(dates, time_comparison=False)[source][source]

Delete the activities power-profile from some specific dates.

Parameters:
dates : list/tuple of datetime-like or str

The dates of the activities to be removed. The format expected is:

  • datetime-like or str: a single activity will be deleted.
  • a list of datetime-like or str: each activity for which the date is contained in the list will be deleted.
  • a tuple of datetime-like or str (start_date, end_date): the activities for which the dates are included in the range will be deleted.
time_comparison : bool, optional

Whether to make a strict comparison using time or to relax to constraints with only the date.

Returns:
None

Examples

>>> from sksports.datasets import load_rider
>>> from sksports import Rider
>>> rider = Rider.from_csv(load_rider())
>>> rider.delete_activities('07 May 2014')
>>> print(rider) 
RIDER INFORMATION:
 power-profile:
                   2014-05-11 09:39:38  2014-07-26 16:50:56
cadence 00:00:01           100.000000            60.000000
        00:00:02            89.000000            58.000000
        00:00:03            68.333333            56.333333
        00:00:04            59.500000            59.250000
        00:00:05            63.200000            61.000000
classmethod from_csv(filename, n_jobs=1)[source][source]

Load rider information from a CSV file.

Parameters:
filename : str

The path to the CSV file.

n_jobs : int, (default=1)

The number of workers to use for the different processing.

Returns:
rider : sksports.Rider

The sksports.Rider instance.

Examples

>>> from sksports.datasets import load_rider
>>> from sksports import Rider
>>> rider = Rider.from_csv(load_rider())
>>> print(rider) 
RIDER INFORMATION:
 power-profile:
                   2014-05-07 12:26:22  2014-05-11 09:39:38  \
cadence 00:00:01            78.000000           100.000000
        00:00:02            64.000000            89.000000
        00:00:03            62.666667            68.333333
        00:00:04            62.500000            59.500000
        00:00:05            64.400000            63.200000

                  2014-07-26 16:50:56
cadence 00:00:01            60.000000
        00:00:02            58.000000
        00:00:03            56.333333
        00:00:04            59.250000
        00:00:05            61.000000
record_power_profile(range_dates=None, columns=None)[source][source]

Compute the record power-profile.

Parameters:
range_dates : tuple of datetime-like or str, optional

The start and end date to consider when computing the record power-profile. By default, all data will be used.

columns : array-like or None, optional

Name of data field to return. By default, all available data will be returned.

Returns:
record_power_profile : DataFrame

Record power-profile taken between the range of dates.

Examples

>>> from sksports import Rider
>>> from sksports.datasets import load_rider
>>> rider = Rider.from_csv(load_rider())
>>> record_power_profile = rider.record_power_profile()
>>> record_power_profile.head() 
            cadence      distance  elevation  heart-rate       power
00:00:01  60.000000  27162.600000        NaN         NaN  750.000000
00:00:02  58.000000  27163.750000        NaN         NaN  741.000000
00:00:03  56.333333  27164.586667        NaN         NaN  731.666667
00:00:04  59.250000  27163.402500        NaN         NaN  719.500000
00:00:05  61.000000  27162.142000        NaN         NaN  712.200000

This is also possible to give a range of dates to compute the record power-profile. We can also select some specific information.

>>> record_power_profile = rider.record_power_profile(
...     range_dates=('07 May 2014', '11 May 2014'),
...     columns=['power', 'cadence'])
>>> record_power_profile.head() 
             cadence   power
00:00:01  100.000000  717.00
00:00:02   89.000000  717.00
00:00:03   68.333333  590.00
00:00:04   59.500000  552.25
00:00:05   63.200000  552.60
to_csv(filename)[source][source]

Drop the rider information into a CSV file.

Parameters:
filename : str

The path to the CSV file.

Returns:
None

Examples

>>> from sksports.datasets import load_fit
>>> from sksports import Rider
>>> rider = Rider(n_jobs=-1)
>>> rider.add_activities(load_fit()[:1])
>>> print(rider)
RIDER INFORMATION:
 power-profile:
                   2014-05-07 12:26:22
cadence 00:00:01            78.000000
        00:00:02            64.000000
        00:00:03            62.666667
        00:00:04            62.500000
        00:00:05            64.400000