예제 #1
0
def test_activity_power_profile_max_duration_too_large():
    # test that there is no segmentation fault when max_duration is set too
    # large and that we fall back to the largest possible interval.
    activity = bikeread(load_fit()[0])
    power_profile = activity_power_profile(activity, max_duration=1000000)
    assert power_profile.shape == (13536, )
    assert power_profile.iloc[-1] == pytest.approx(8.2117765957446736)
예제 #2
0
def test_load_fit(returned_type, set_data, expected_filenames):
    filenames = load_fit(returned_type=returned_type,
                         set_data=set_data)
    if not isinstance(filenames, list):
        filenames = [filenames]
    for f, e in zip(filenames, expected_filenames):
        assert e in f
def test_activity_power_profile_max_duration_too_large():
    # test that there is no segmentation fault when max_duration is set too
    # large and that we fall back to the largest possible interval.
    activity = bikeread(load_fit()[0])
    power_profile = activity_power_profile(activity, max_duration=1000000)
    assert power_profile.shape == (13536,)
    assert power_profile.iloc[-1] == pytest.approx(8.2117765957446736)
예제 #4
0
def test_load_power_normal_file():
    filenames = load_fit(set_data='corrupted')
    pattern = '2013-04-24-22-22-25.fit'
    for f in filenames:
        if pattern in f:
            filename = f
    df = load_power_from_fit(filename)
    assert_allclose(df['power'], ride)
    assert df.index[0].date() == date(2013, 4, 24)
예제 #5
0
def test_load_power_if_no_record():
    filenames = load_fit(set_data='corrupted')
    pattern = '2015-11-27-18-54-57.fit'
    for f in filenames:
        if pattern in f:
            filename = f
    msg = "does not contain any data."
    with pytest.raises(IOError, message=msg):
        load_power_from_fit(filename)
예제 #6
0
def test_load_power_normal_file():
    filenames = load_fit(set_data='corrupted')
    pattern = '2013-04-24-22-22-25.fit'
    for f in filenames:
        if pattern in f:
            filename = f
    df = load_power_from_fit(filename)
    assert_allclose(df['power'], ride)
    assert df.index[0].date() == date(2013, 4, 24)
예제 #7
0
def test_load_power_if_no_record():
    filenames = load_fit(set_data='corrupted')
    pattern = '2015-11-27-18-54-57.fit'
    for f in filenames:
        if pattern in f:
            filename = f
    msg = "does not contain any data."
    with pytest.raises(IOError, message=msg):
        load_power_from_fit(filename)
"""

print(__doc__)

# Authors: Guillaume Lemaitre <*****@*****.**>
# License: BSD 3 clause

###############################################################################
# We will use the :class:`skcycling.Rider` class to compute power-profile for
# the toy data sets.

from skcycling.datasets import load_fit
from skcycling import Rider

rider = Rider()
rider.add_activities(load_fit())

print('The computed activities are:\n {}'.format(rider.power_profile_))

###############################################################################
# We can store and load the information using the `to_csv` and `from_csv`
# methods.

filename_rider = 'rider.csv'
rider.to_csv(filename_rider)

rider_reloaded = Rider.from_csv(filename_rider)

###############################################################################
# Clean the temporary csv file
import os
예제 #9
0
cyclist during a cycling ride.

"""

print(__doc__)

# Authors: Guillaume Lemaitre <*****@*****.**>
# License: BSD 3 clause

###############################################################################
# We can first read a toy ride from the library

from skcycling.datasets import load_fit
from skcycling.io import bikeread

ride = bikeread(load_fit()[0])

###############################################################################
# Different scores are available in ``scikit-cycling``. We can first compute
# the normalized power® which corresponds to an average power during the ride
# with an additional smoothing. To compute this score, we need to know the
# maximum power aerobic (or the functional threshold power).

from skcycling.metrics import normalized_power_score

mpa = 400
np_score = normalized_power_score(ride['power'], mpa)
print('Normalized power {:.2f}'.format(np_score))

###############################################################################
# The intensity factor® normalize the normalized power using the functional
예제 #10
0
to a cyclist to infer power produced by a cyclist.

"""

print(__doc__)

# Authors: Guillaume Lemaitre <*****@*****.**>
# License: BSD 3 clause

###############################################################################
# We can first grab a file and read all data available

from skcycling.datasets import load_fit
from skcycling.io import bikeread

ride = bikeread(load_fit()[0], drop_nan='columns')

###############################################################################
# We can use a physical model to infer the power.

from skcycling.model import strava_power_model

power = strava_power_model(ride, cyclist_weight=72)

###############################################################################
# We can plot the measured and estimated power to observe the difference. We
# can also compute the median absolute error to asses the quality of the
# estimation. To ease the interpretation, we will first resample the data.

import matplotlib.pyplot as plt
from sklearn.metrics import median_absolute_error
예제 #11
0
def test_check_filename_fit():
    filename = load_fit()[0]
    my_filename = check_filename_fit(filename)
    assert my_filename == filename
def test_activity_power_profile(max_duration, power_profile_shape,
                                first_element):
    activity = bikeread(load_fit()[0])
    power_profile = activity_power_profile(activity, max_duration=max_duration)
    assert power_profile.shape == power_profile_shape
    assert power_profile.iloc[-1] == pytest.approx(first_element)
예제 #13
0
"""

# Authors: Guillaume Lemaitre <*****@*****.**>
# License: BSD 3 clause

print(__doc__)

###############################################################################
# First, we will load an activity from the toy data set available in
# scikit-cycling.

from skcycling.datasets import load_fit
from skcycling.io import bikeread

ride = bikeread(load_fit()[0], drop_nan='columns')

###############################################################################
# We will only select some of interesting information
columns_selected = ['power', 'speed', 'cadence']
ride = ride[columns_selected]

###############################################################################
# The power-profile is extracted from the ride. By default, the maximum
# duration corresponds to the duration of the ride. However, to limit the
# processing, we limit the extraction to 8 minutes.

from skcycling.extraction import activity_power_profile

power_profile = activity_power_profile(ride, '00:08:00')
print('The power-profile is:\n {}'.format(power_profile))
예제 #14
0
# Authors: Guillaume Lemaitre <*****@*****.**>
#          Cedric Lemaitre
# License: BSD 3 clause

from os.path import dirname, join

import pytest

from skcycling.datasets import load_fit
from skcycling.utils import validate_filenames

filenames = load_fit()


@pytest.mark.parametrize("filenames, expected_filenames",
                         [(filenames, filenames),
                          (join(dirname(filenames[0]), '*.fit'), filenames)])
def test_validate_filenames(filenames, expected_filenames):
    assert list(validate_filenames(filenames)) == expected_filenames
예제 #15
0
:func:`skcycling.io.bikeread` using pandas.

"""

# Authors: Guillaume Lemaitre <*****@*****.**>
# License: BSD 3 clause

print(__doc__)

###############################################################################
# `scikit-cycling` has couple of `fit` files stored which can be used as toy
# data.

from skcycling.datasets import load_fit

filename_fit = load_fit()[0]  # catch the first toy file
print('The fit file which will be used is stored at: \n {}'
      .format(filename_fit))

###############################################################################
# The function :func:`skcycling.io.bikeread` allows to read the file without
# any extra information regarding the format.

from skcycling.io import bikeread

ride = bikeread(filename_fit, drop_nan='columns')
print('The ride is the following:\n {}'.format(ride.head()))

###############################################################################
# First, we can list the type of data available in the DataFrame
예제 #16
0
def test_check_filename_fit():
    filename = load_fit()[0]
    my_filename = check_filename_fit(filename)
    assert my_filename == filename