Skip to content

Commit

Permalink
refactor(telemetry): rename dna_api to telemetry_api
Browse files Browse the repository at this point in the history
  • Loading branch information
NodeJSmith committed Jun 13, 2024
1 parent 01d9d78 commit f44f828
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 45 deletions.
2 changes: 1 addition & 1 deletion examples/workout_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ async def main():
# telemetry is a detailed record of a specific workout - minute by minute, or more granular if desired
# this endpoint takes a class_history_uuid, as well as a number of max data points - if you do not pass
# this value it will attempt to return enough data points for 30 second intervals
telemetry = await otf.dna_api.get_telemetry(workouts.workouts[0].class_history_uuid)
telemetry = await otf.telemetry_api.get_telemetry(workouts.workouts[0].class_history_uuid)
print(json.dumps(telemetry.model_dump(), indent=4, default=str))

"""
Expand Down
18 changes: 9 additions & 9 deletions src/otf_api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from . import classes_api, dna_api, member_api, studio_api
from . import classes_api, member_api, studios_api, telemetry_api
from .api import Api
from .models.auth import User
from .models.responses import (
Expand All @@ -10,9 +10,6 @@
ChallengeTrackerContent,
ChallengeTrackerDetailList,
ChallengeType,
DnaHrHistory,
DnaMaxHr,
DnaTelemetry,
EquipmentType,
FavoriteStudioList,
HistoryClassStatus,
Expand All @@ -28,6 +25,9 @@
StudioDetailList,
StudioServiceList,
StudioStatus,
TelemetryHrHistory,
TelemetryItem,
TelemetryMaxHr,
TotalClasses,
WorkoutList,
)
Expand Down Expand Up @@ -55,11 +55,11 @@
"FavoriteStudioList",
"OtfClassList",
"classes_api",
"studio_api",
"dna_api",
"DnaHrHistory",
"DnaTelemetry",
"DnaMaxHr",
"studios_api",
"telemetry_api",
"TelemetryHrHistory",
"TelemetryItem",
"TelemetryMaxHr",
"StudioDetail",
"StudioDetailList",
"ALL_CLASS_STATUS",
Expand Down
10 changes: 6 additions & 4 deletions src/otf_api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from otf_api.models.auth import User
from otf_api.performance_api import PerformanceApi
from otf_api.studio_api import StudiosApi
from otf_api.telemetry_api import TelemtryApi

if typing.TYPE_CHECKING:
from loguru import Logger
Expand All @@ -21,7 +22,7 @@

API_BASE_URL = "api.orangetheory.co"
API_IO_BASE_URL = "api.orangetheory.io"
API_DNA_BASE_URL = "api.yuzu.orangetheory.com"
API_TELEMETRY_BASE_URL = "api.yuzu.orangetheory.com"
REQUEST_HEADERS = {"Authorization": None, "Content-Type": "application/json", "Accept": "application/json"}


Expand All @@ -48,6 +49,7 @@ def __init__(self, username: str, password: str):
self.classes_api = ClassesApi(self)
self.studios_api = StudiosApi(self)
self.dna_api = DnaApi(self)
self.telemetry_api = TelemtryApi(self)
self.performance_api = PerformanceApi(self)

@classmethod
Expand Down Expand Up @@ -122,9 +124,9 @@ async def _default_request(self, method: str, url: str, params: dict[str, Any] |
"""Perform an API request to the default API."""
return await self._do(method, API_BASE_URL, url, params)

async def _dna_request(self, method: str, url: str, params: dict[str, Any] | None = None) -> Any:
"""Perform an API request to the DNA API."""
return await self._do(method, API_DNA_BASE_URL, url, params)
async def _telemetry_request(self, method: str, url: str, params: dict[str, Any] | None = None) -> Any:
"""Perform an API request to the Telemetry API."""
return await self._do(method, API_TELEMETRY_BASE_URL, url, params)

async def _performance_summary_request(
self, method: str, url: str, headers: dict[str, str], params: dict[str, Any] | None = None
Expand Down
12 changes: 6 additions & 6 deletions src/otf_api/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
ChallengeTrackerContent,
ChallengeTrackerDetailList,
ChallengeType,
DnaHrHistory,
DnaMaxHr,
DnaTelemetry,
EquipmentType,
FavoriteStudioList,
HistoryClassStatus,
Expand All @@ -26,6 +23,9 @@
StudioDetailList,
StudioServiceList,
StudioStatus,
TelemetryHrHistory,
TelemetryItem,
TelemetryMaxHr,
TotalClasses,
WorkoutList,
)
Expand All @@ -50,9 +50,9 @@
"WorkoutList",
"FavoriteStudioList",
"OtfClassList",
"DnaHrHistory",
"DnaTelemetry",
"DnaMaxHr",
"TelemetryHrHistory",
"TelemetryItem",
"TelemetryMaxHr",
"StudioDetail",
"StudioDetailList",
"ALL_CLASS_STATUS",
Expand Down
12 changes: 6 additions & 6 deletions src/otf_api/models/responses/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
from .challenge_tracker_content import ChallengeTrackerContent
from .challenge_tracker_detail import ChallengeTrackerDetailList
from .classes import OtfClassList
from .dna_hr_history import DnaHrHistory
from .dna_max_hr import DnaMaxHr
from .dna_telemetry import DnaTelemetry
from .enums import (
ALL_CLASS_STATUS,
ALL_HISTORY_CLASS_STATUS,
Expand All @@ -25,6 +22,9 @@
from .performance_summary_list import PerformanceSummaryList
from .studio_detail import StudioDetail, StudioDetailList
from .studio_services import StudioServiceList
from .telemetry_hr_history import TelemetryHrHistory
from .telemetry_item import TelemetryItem
from .telemetry_max_hr import TelemetryMaxHr
from .total_classes import TotalClasses
from .workouts import WorkoutList

Expand All @@ -47,9 +47,9 @@
"StudioStatus",
"FavoriteStudioList",
"OtfClassList",
"DnaHrHistory",
"DnaTelemetry",
"DnaMaxHr",
"TelemetryHrHistory",
"TelemetryItem",
"TelemetryMaxHr",
"StudioDetail",
"StudioDetailList",
"ALL_CLASS_STATUS",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ class HistoryItem(OtfBaseModel):
assigned_at: str = Field(..., alias="assignedAt")


class DnaHrHistory(OtfBaseModel):
class TelemetryHrHistory(OtfBaseModel):
member_uuid: str = Field(..., alias="memberUuid")
history: list[HistoryItem]
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class TelemetryItem(OtfBaseModel):
tread_data: TreadData | None = Field(None, alias="treadData")


class DnaTelemetry(OtfBaseModel):
class TelemetryItem(OtfBaseModel):
member_uuid: str = Field(..., alias="memberUuid")
class_history_uuid: str = Field(..., alias="classHistoryUuid")
class_start_time: datetime = Field(..., alias="classStartTime")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ class MaxHr(OtfBaseModel):
value: int


class DnaMaxHr(OtfBaseModel):
class TelemetryMaxHr(OtfBaseModel):
member_uuid: str = Field(..., alias="memberUuid")
max_hr: MaxHr = Field(..., alias="maxHr")
32 changes: 16 additions & 16 deletions src/otf_api/dna_api.py → src/otf_api/telemetry_api.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import typing
from math import ceil

from otf_api.models.responses.dna_hr_history import DnaHrHistory
from otf_api.models.responses.dna_max_hr import DnaMaxHr
from otf_api.models.responses.dna_telemetry import DnaTelemetry
from otf_api.models.responses.telemetry_hr_history import TelemetryHrHistory
from otf_api.models.responses.telemetry_item import TelemetryItem
from otf_api.models.responses.telemetry_max_hr import TelemetryMaxHr

if typing.TYPE_CHECKING:
from otf_api import Api


class DnaApi:
class TelemtryApi:
def __init__(self, api: "Api"):
self._api = api
self.logger = api.logger
Expand All @@ -18,38 +18,38 @@ def __init__(self, api: "Api"):
self._member_id = self._api.user.member_id
self._member_uuid = self._api.user.member_uuid

async def get_hr_history(self) -> DnaHrHistory:
async def get_hr_history(self) -> TelemetryHrHistory:
"""Get the heartrate history for the user.
Returns a list of history items that contain the max heartrate, start/end bpm for each zone,
the change from the previous, the change bucket, and the assigned at time.
Returns:
DnaHrHistory: The heartrate history for the user.
TelemetryHrHistory: The heartrate history for the user.
"""
path = "/v1/physVars/maxHr/history"

params = {"memberUuid": self._member_id}
res = await self._api._dna_request("GET", path, params=params)
return DnaHrHistory(**res)
res = await self._api._telemetry_request("GET", path, params=params)
return TelemetryHrHistory(**res)

async def get_max_hr(self) -> DnaMaxHr:
async def get_max_hr(self) -> TelemetryMaxHr:
"""Get the max heartrate for the user.
Returns a simple object that has the member_uuid and the max_hr.
Returns:
DnaMaxHr: The max heartrate for the user.
TelemetryMaxHr: The max heartrate for the user.
"""
path = "/v1/physVars/maxHr"

params = {"memberUuid": self._member_id}

res = await self._api._dna_request("GET", path, params=params)
return DnaMaxHr(**res)
res = await self._api._telemetry_request("GET", path, params=params)
return TelemetryMaxHr(**res)

async def get_telemetry(self, class_history_uuid: str, max_data_points: int = 0) -> DnaTelemetry:
async def get_telemetry(self, class_history_uuid: str, max_data_points: int = 0) -> TelemetryItem:
"""Get the telemetry for a class history.
This returns an object that contains the max heartrate, start/end bpm for each zone,
Expand All @@ -61,16 +61,16 @@ async def get_telemetry(self, class_history_uuid: str, max_data_points: int = 0)
get the max data points from the workout. If the workout is not found, it will default to 120 data points.
Returns:
DnaTelemetry: The telemetry for the class history.
TelemetryItem: The telemetry for the class history.
"""
path = "/v1/performance/summary"

max_data_points = max_data_points or await self._get_max_data_points(class_history_uuid)

params = {"classHistoryUuid": class_history_uuid, "maxDataPoints": max_data_points}
res = await self._api._dna_request("GET", path, params=params)
return DnaTelemetry(**res)
res = await self._api._telemetry_request("GET", path, params=params)
return TelemetryItem(**res)

async def _get_max_data_points(self, class_history_uuid: str) -> int:
"""Get the max data points to use for the telemetry.
Expand Down

0 comments on commit f44f828

Please sign in to comment.