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_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)
예제 #3
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
예제 #4
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
              '2018-05-18-11-46-19',
              '2018-05-18-13-55-23',
              '2018-05-18-14-37-07',
              '2018-05-18-15-00-26',
              '2018-05-18-15-06-46']

    exten = '.fit'

    f_crop = 'check_std_cedric.csv'
    df = pd.read_csv(f_path_data + f_path_user + f_crop)

    for f in range(len(f_name)):

        filename_fit = f_path_data + f_path_user + f_name[f] + exten
        print('Nom du fichier traité : ', filename_fit)
        ride = bikeread(filename_fit, drop_nan='columns')
        ride['speed'] = ride['speed'] * 3.6
        # print('The ride is the following:\n {}'.format(ride.head()))
        # print('The available data are {}'.format(ride.columns))

        all_time = pd.to_datetime(df[f_name[f]]).tolist()
        all_time_15s = []

        for t in all_time:
            t_15s = t + datetime.timedelta(seconds=15)
            all_time_15s.append(t_15s)

        for i in range(len(all_time)):
            print('Index du crop : ', i)
            debut = str(all_time[i])
            fin = str(all_time_15s[i])
예제 #6
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
예제 #7
0
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)
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)
예제 #9
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))
예제 #10
0
# `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)
print('The ride is the following:\n {}'.format(ride.head()))

###############################################################################
# :func:`skcycling.io.bikeread` returns a pandas DataFrame. Thus, this is
# possible to export it in different format. We will use CSV format in this
# case.

filename_export = 'ride_exported.csv'
ride.to_csv(filename_export)

###############################################################################
# Then, it is always possible to read the file exported using pandas

import pandas as pd
예제 #11
0
# `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

print('The available data are {}'.format(ride.columns))

###############################################################################
# Plotting a specific column (e.g. power) is easy using the pandas ``plot``
# function.

import matplotlib.pyplot as plt

ride['power'].plot(legend=True)
plt.xlabel('Time')