def test_rider_add_activities_update(): rider = Rider.from_csv(load_rider()) rider.delete_activities('07 May 2014') rider.add_activities(load_fit()[0]) assert rider.power_profile_.shape == (35771, 3) with pytest.raises(ValueError, message='activity was already added'): rider.add_activities(load_fit()[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)
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_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)
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)
def test_dump_load_rider(): filenames = load_fit()[:1] rider = Rider() rider.add_activities(filenames) tmpdir = mkdtemp() csv_filename = os.path.join(tmpdir, 'rider.csv') try: rider.to_csv(csv_filename) rider2 = Rider.from_csv(csv_filename) assert_frame_equal(rider.power_profile_, rider2.power_profile_) finally: shutil.rmtree(tmpdir)
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_check_filename_fit(): filename = load_fit()[0] my_filename = check_filename_fit(filename) assert my_filename == filename
from sksports.datasets import load_rider def test_rider_add_activities_update(): rider = Rider.from_csv(load_rider()) rider.delete_activities('07 May 2014') rider.add_activities(load_fit()[0]) assert rider.power_profile_.shape == (35771, 3) with pytest.raises(ValueError, message='activity was already added'): rider.add_activities(load_fit()[0]) @pytest.mark.parametrize( "rider, filename, expected_shape", [(Rider(), load_fit(), (40218, 3)), (Rider(), load_fit()[0], (13536, 1))]) def test_rider_add_activities(rider, filename, expected_shape): rider.add_activities(filename) assert rider.power_profile_.shape == expected_shape @pytest.mark.parametrize( "dates, time_comparison, expected_shape", [('07 May 2014', False, (33515, 2)), ('07 May 2014', True, (33515, 3)), ('07 May 2014 12:26:22', True, (33515, 2)), (['07 May 2014'], False, (33515, 2)), (tuple(['07 May 2014', '11 May 2014']), False, (33515, 1))]) def test_rider_delete_activities(dates, time_comparison, expected_shape): rider = Rider.from_csv(load_rider())
""" # Authors: Guillaume Lemaitre <*****@*****.**> # License: MIT print(__doc__) ############################################################################### # First, we will load an activity from the toy data set available in # scikit-sports. from sksports.datasets import load_fit from sksports.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 sksports.extraction import activity_power_profile power_profile = activity_power_profile(ride, '00:08:00') print('The power-profile is:\n {}'.format(power_profile))
""" print(__doc__) # Authors: Guillaume Lemaitre <*****@*****.**> # License: MIT ############################################################################### # We will use the :class:`sksports.Rider` class to compute power-profile for # the toy data sets. from sksports.datasets import load_fit from sksports 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
cyclist during a cycling ride. """ print(__doc__) # Authors: Guillaume Lemaitre <*****@*****.**> # License: MIT ############################################################################### # We can first read a toy ride from the library from sksports.datasets import load_fit from sksports.io import bikeread ride = bikeread(load_fit()[0]) ############################################################################### # Different scores are available in ``scikit-sports``. 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 sksports.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
:func:`sksports.io.bikeread` using pandas. """ # Authors: Guillaume Lemaitre <*****@*****.**> # License: MIT print(__doc__) ############################################################################### # `scikit-sports` has couple of `fit` files stored which can be used as toy # data. from sksports.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:`sksports.io.bikeread` allows to read the file without # any extra information regarding the format. from sksports.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