Skip to content

Commit 6a163fb

Browse files
committed
relax data types on PerformanceMetric, remove all custom logic, was doing nothing valuable
1 parent ad81b1f commit 6a163fb

File tree

1 file changed

+10
-31
lines changed

1 file changed

+10
-31
lines changed

src/otf_api/models/workouts/performance_summary.py

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
from datetime import time
1+
from logging import getLogger
2+
from typing import Any
23

3-
from pydantic import AliasPath, Field, field_validator
4+
from pydantic import AliasPath, Field
45

56
from otf_api.models.base import OtfItemBase
67

8+
LOGGER = getLogger(__name__)
9+
710

811
class ZoneTimeMinutes(OtfItemBase):
912
gray: int
@@ -22,41 +25,17 @@ class HeartRate(OtfItemBase):
2225

2326

2427
class PerformanceMetric(OtfItemBase):
25-
display_value: time | float | None
28+
display_value: Any
2629
display_unit: str
27-
metric_value: float
30+
metric_value: float | int = Field(
31+
coerce_numbers_to_str=True,
32+
description="The raw value of the metric, as a float or int. When time this reflects seconds.",
33+
)
2834

2935
def __str__(self) -> str:
3036
"""Return a string representation of the PerformanceMetric."""
3137
return f"{self.display_value} {self.display_unit}"
3238

33-
@field_validator("display_value", mode="before")
34-
@classmethod
35-
def convert_to_time_format(cls, value: str | None | float | int) -> time | float | None:
36-
"""Convert display_value to a time object if it is in the format of HH:MM:SS or MM:SS.
37-
38-
Args:
39-
value (str | None | float | int): The value to convert.
40-
41-
Returns:
42-
time | float: The converted value, or the original value if it is not in the expected format.
43-
"""
44-
if not value:
45-
return None
46-
47-
if isinstance(value, float | int):
48-
return value
49-
50-
if isinstance(value, str) and ":" in value:
51-
if value.count(":") == 1:
52-
minutes, seconds = value.split(":")
53-
return time(minute=int(minutes), second=int(seconds))
54-
if value.count(":") == 2:
55-
hours, minutes, seconds = value.split(":")
56-
return time(hour=int(hours), minute=int(minutes), second=int(seconds))
57-
58-
return value # type: ignore
59-
6039

6140
class BaseEquipment(OtfItemBase):
6241
avg_pace: PerformanceMetric

0 commit comments

Comments
 (0)