Skip to content

Commit

Permalink
Merge pull request #87 from AartGoossens/feature/ag_less_strict_user_…
Browse files Browse the repository at this point in the history
…info

Less strict athlete info validation
  • Loading branch information
AartGoossens authored Oct 19, 2021
2 parents 3cf3c86 + d7e23fe commit 596634a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
4 changes: 4 additions & 0 deletions docs/docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ Types of changes:
- `Fixed` for any bug fixes.
- `Security` in case of vulnerabilities.

## [unreleased] - {date}
### Fixed
- Relax Athlete model validation because it raised errors for some FIT files.

## [0.22.0] - 2021-10-19
### Added
- When `metadata=True` is passed to `sweat.read_fit()` the response now includes an "athlete" key that contains an Athlete model with information about the athlete.
Expand Down
16 changes: 8 additions & 8 deletions sweat/io/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import Enum
from typing import Dict, Optional

from pydantic import BaseModel, conint, PositiveFloat, PositiveInt
from pydantic import BaseModel


class Gender(Enum):
Expand All @@ -20,20 +20,20 @@ class UnitSystem(Enum):
class ThresholdSetting(BaseModel):
sport: str
sub_sport: str
power: Optional[PositiveInt]
speed: Optional[PositiveFloat]
heartrate: Optional[PositiveInt]
power: Optional[int]
speed: Optional[float]
heartrate: Optional[int]


class Athlete(BaseModel):
name: Optional[str]
gender: Optional[Gender]
age: Optional[PositiveInt]
weight: Optional[PositiveFloat]
max_heartrate: Optional[PositiveInt]
age: Optional[int]
weight: Optional[float]
max_heartrate: Optional[int]
unit_system: Optional[UnitSystem]
threshold: Optional[ThresholdSetting]
activity_class: Optional[conint(ge=0, le=100)]
activity_class: Optional[int]

@classmethod
def from_fit_file(cls, user_profile, zones_target, sport):
Expand Down
23 changes: 23 additions & 0 deletions tests/io/test_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,29 @@ def test_read_fit(example):
assert activity["session"].max() == example.sessions - 1


@pytest.mark.parametrize(
"example", [(i) for i in sweat.examples(file_type=FileTypeEnum.fit)]
)
def test_read_fit_metadata(example):
fit_data = fit.read_fit(example.path, metadata=True, hrv=True)
activity = fit_data["data"]

assert isinstance(activity, pd.DataFrame)
assert isinstance(activity.index, pd.DatetimeIndex)
included_data = set(i.value for i in example.included_data)
assert included_data <= set(activity.columns.to_list())

assert "lap" in activity.columns
assert activity["lap"].max() == example.laps - 1

assert "session" in activity.columns
assert activity["session"].max() == example.sessions - 1

assert "hrv" in fit_data
assert "devices" in fit_data
assert "athlete" in fit_data


def test_read_fit_no_fit():
example_tcx = sweat.examples(path="activity_4078723797.tcx")
with pytest.raises(exceptions.InvalidFitFile):
Expand Down

0 comments on commit 596634a

Please sign in to comment.