Skip to content

Commit

Permalink
Merge pull request #35 from corriporai/develop
Browse files Browse the repository at this point in the history
Support the removal of periods of inactivity and addition of metrics: distance, elapsed time and moving time
  • Loading branch information
marcelcaraciolo authored Mar 13, 2021
2 parents 58f34b9 + fb8d4dd commit 58e8055
Show file tree
Hide file tree
Showing 27 changed files with 47,983 additions and 34 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ CHANGELOG
The list of changes to RunPandas between each release can be found below.
For full details see the commit logs at https://github.com/corriporai/runpandas.

.. include:: docs/source/whatsnew/v0.1.0.txt
.. include:: docs/source/whatsnew/v0.1.0.txt
.. include:: docs/source/whatsnew/v0.2.0.txt
3 changes: 1 addition & 2 deletions docs/source/whatsnew/v0.2.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ Highlights include:
New features
~~~~~~~~~~~~
- Added support to fetch a single activity from an registered athlete from social network Strava. (:issue:`9`)
- Added standalone script for getting the access token for the user strava
activities. (:issue:`9`)
- Added standalone script for getting the access token for the user strava activities. (:issue:`9`)
- Added badge for Pepy metrics (pepy.tech)
- Added `runpandas.read_dir` method for iterate and read multiple tracking files located in a directory. (:issue:`10`)
- Improvements on Docs (added new sections UserGuide, API Reference, Install Guide, Changelog) (:issue:`22`)
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pandas>=0.21
fitparse
stravalib
stravalib
haversine
44 changes: 44 additions & 0 deletions runpandas/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import os
import re
from xml.etree.cElementTree import iterparse
from functools import wraps
from runpandas import exceptions
from pandas import Series


def file_exists(fname):
Expand Down Expand Up @@ -101,3 +104,44 @@ def camelcase_to_snakecase(string):
"""
string = re.sub("(.)([A-Z][a-z]+)", r"\1_\2", string)
return re.sub("([a-z0-9])([A-Z])", r"\1_\2", string).lower()


def special_column(required_columns, name=None):
"""
Decorator for certain methods of acessors that create special columns
using the ``runpandas.types.MeasureSeries`` subtypes.
Parameters
----------
required_columns: tuple
A tuple of column names.
name: str, optional.
The name for the returned Series object.
"""

def real_decorator(func):
@wraps(func)
def wrapper(self, *args, **kwargs):
for column in required_columns:
if column not in self._activity:
raise exceptions.RequiredColumnError(column)

# If it's ok so construct the new Series.
out = func(self, *args, **kwargs)
return Series(out, index=self._activity.index, name=name)

return wrapper

return real_decorator


class series_property:
"""A simple descriptor that emulates property, but returns a Series."""

def __init__(self, fget):
self.fget = fget

def __get__(self, obj, objtype=None):
return Series(self.fget(obj))
6 changes: 3 additions & 3 deletions runpandas/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ def wrapper(*args):
if request.config.getoption("--strict-data-files"):
msg = "Could not find file {} and --strict-data-files is set."
raise ValueError(msg.format(path))
else:
msg = "Could not find {}."
pytest.skip(msg.format(path))

msg = "Could not find {}."
pytest.skip(msg.format(path))
return path

return wrapper
13 changes: 11 additions & 2 deletions runpandas/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@


class InvalidFileError(Exception):
def __init__(self, format):
message = "It doesn't like a valid %s file!" % (format)
def __init__(self, msg):
message = "It doesn't like a valid %s file!" % (msg)
super().__init__(message)


class RequiredColumnError(Exception):
def __init__(self, column, cls=None):
if cls is None:
message = "{!r} column not found".format(column)
else:
message = "{!r} column should be of type {!s}".format(column, cls)
super().__init__(message)
4 changes: 2 additions & 2 deletions runpandas/io/fit/_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,5 @@ def read(file_path, to_df=False, **kwargs):

if to_df:
return data
else:
return Activity(data, cspecs=COLUMNS_SCHEMA, start=start)

return Activity(data, cspecs=COLUMNS_SCHEMA, start=start)
4 changes: 2 additions & 2 deletions runpandas/io/gpx/_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,5 @@ def read(file_path, to_df=False, **kwargs):

if to_df:
return data
else:
return Activity(data, cspecs=COLUMNS_SCHEMA, start=timestamps[0])

return Activity(data, cspecs=COLUMNS_SCHEMA, start=timestamps[0])
5 changes: 2 additions & 3 deletions runpandas/io/strava/_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ def read_strava(
activity = client.get_activity(activity_id)

start_datetime = activity.start_date_local
print(start_datetime)
streams = client.get_activity_streams(
activity_id=activity_id, types=STREAM_TYPES, series_type="time"
)
Expand All @@ -114,5 +113,5 @@ def time_to_datetime(time):

if to_df:
return data
else:
return Activity(data, cspecs=COLUMNS_SCHEMA, start=timestamps[0])

return Activity(data, cspecs=COLUMNS_SCHEMA, start=timestamps[0])
4 changes: 2 additions & 2 deletions runpandas/io/tcx/_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,5 @@ def read(file_path, to_df=False, **kwargs):

if to_df:
return data
else:
return Activity(data, cspecs=COLUMNS_SCHEMA, start=timestamps[0])

return Activity(data, cspecs=COLUMNS_SCHEMA, start=timestamps[0])
Loading

0 comments on commit 58e8055

Please sign in to comment.