Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/garmy/localdb/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ def store_timeseries_batch(self, user_id: int, metric_type: MetricType, data: Li
"""Store batch of timeseries data."""
with self.get_session() as session:
for timestamp, value, metadata in data:
# Skip entries with None values (NOT NULL constraint)
if value is None:
continue
timeseries = TimeSeries(
user_id=user_id,
metric_type=metric_type.value,
Expand Down
7 changes: 6 additions & 1 deletion src/garmy/localdb/extractors.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ def extract_timeseries_data(self, data: Any, metric_type: MetricType) -> List[Tu
if metric_type == MetricType.BODY_BATTERY:
if hasattr(data, 'body_battery_readings') and data.body_battery_readings:
for reading in data.body_battery_readings:
if reading.level is None:
continue
metadata = {
'status': getattr(reading, 'status', None),
'version': getattr(reading, 'version', None)
Expand All @@ -198,6 +200,8 @@ def extract_timeseries_data(self, data: Any, metric_type: MetricType) -> List[Tu
elif metric_type == MetricType.STRESS:
if hasattr(data, 'stress_readings') and data.stress_readings:
for reading in data.stress_readings:
if reading.stress_level is None:
continue
metadata = {}
if hasattr(reading, 'stress_category'):
metadata['stress_category'] = reading.stress_category
Expand All @@ -208,7 +212,8 @@ def extract_timeseries_data(self, data: Any, metric_type: MetricType) -> List[Tu
for reading in data.heart_rate_values_array:
if isinstance(reading, (list, tuple)) and len(reading) >= 2:
timestamp, heart_rate = reading[0], reading[1]
timeseries_data.append((timestamp, heart_rate, {}))
if heart_rate is not None:
timeseries_data.append((timestamp, heart_rate, {}))

elif metric_type == MetricType.RESPIRATION:
# Respiration might have different format - check if it has readings
Expand Down
6 changes: 5 additions & 1 deletion src/garmy/localdb/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ def task_failed(self, task: str, sync_date: date):
def info(self, message: str):
"""Log info message."""
self.logger.info(message)


def warning(self, message: str):
"""Log warning message."""
self.logger.warning(message)

def error(self, message: str):
"""Log error message."""
self.logger.error(message)
Expand Down
7 changes: 6 additions & 1 deletion src/garmy/localdb/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ def initialize(self, email: str, password: str):
from garmy import AuthClient, APIClient

auth_client = AuthClient()
auth_client.login(email, password)
auth_client.login(
email,
password,
prompt_mfa=lambda: input("MFA code: "),
)

self.api_client = APIClient(auth_client=auth_client)

self.activities_iterator = ActivitiesIterator(
Expand Down