mirror of
https://github.com/sstent/GarminSync.git
synced 2026-01-26 00:52:32 +00:00
python v2 - added feartures 1 and 2 - daemon hsa errors
This commit is contained in:
@@ -12,6 +12,28 @@ class Activity(Base):
|
||||
start_time = Column(String, nullable=False)
|
||||
filename = Column(String, unique=True, nullable=True)
|
||||
downloaded = Column(Boolean, default=False, nullable=False)
|
||||
last_sync = Column(String, nullable=True) # ISO timestamp of last sync
|
||||
|
||||
class DaemonConfig(Base):
|
||||
__tablename__ = 'daemon_config'
|
||||
|
||||
id = Column(Integer, primary_key=True, default=1)
|
||||
enabled = Column(Boolean, default=True, nullable=False)
|
||||
schedule_cron = Column(String, default="0 */6 * * *", nullable=False) # Every 6 hours
|
||||
last_run = Column(String, nullable=True)
|
||||
next_run = Column(String, nullable=True)
|
||||
status = Column(String, default="stopped", nullable=False) # stopped, running, error
|
||||
|
||||
class SyncLog(Base):
|
||||
__tablename__ = 'sync_logs'
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
timestamp = Column(String, nullable=False)
|
||||
operation = Column(String, nullable=False) # sync, download, daemon_start, daemon_stop
|
||||
status = Column(String, nullable=False) # success, error, partial
|
||||
message = Column(String, nullable=True)
|
||||
activities_processed = Column(Integer, default=0, nullable=False)
|
||||
activities_downloaded = Column(Integer, default=0, nullable=False)
|
||||
|
||||
def init_db():
|
||||
"""Initialize database connection and create tables"""
|
||||
@@ -28,6 +50,7 @@ def get_session():
|
||||
|
||||
def sync_database(garmin_client):
|
||||
"""Sync local database with Garmin Connect activities"""
|
||||
from datetime import datetime
|
||||
session = get_session()
|
||||
try:
|
||||
# Fetch activities from Garmin Connect
|
||||
@@ -44,7 +67,8 @@ def sync_database(garmin_client):
|
||||
new_activity = Activity(
|
||||
activity_id=activity_id,
|
||||
start_time=start_time,
|
||||
downloaded=False
|
||||
downloaded=False,
|
||||
last_sync=datetime.now().isoformat()
|
||||
)
|
||||
session.add(new_activity)
|
||||
|
||||
@@ -54,6 +78,24 @@ def sync_database(garmin_client):
|
||||
raise e
|
||||
finally:
|
||||
session.close()
|
||||
|
||||
def get_offline_stats():
|
||||
"""Return statistics about cached data without API calls"""
|
||||
session = get_session()
|
||||
try:
|
||||
total = session.query(Activity).count()
|
||||
downloaded = session.query(Activity).filter_by(downloaded=True).count()
|
||||
missing = total - downloaded
|
||||
# Get most recent sync timestamp
|
||||
last_sync = session.query(Activity).order_by(Activity.last_sync.desc()).first()
|
||||
return {
|
||||
'total': total,
|
||||
'downloaded': downloaded,
|
||||
'missing': missing,
|
||||
'last_sync': last_sync.last_sync if last_sync else 'Never synced'
|
||||
}
|
||||
finally:
|
||||
session.close()
|
||||
|
||||
# Example usage:
|
||||
# from .garmin import GarminClient
|
||||
|
||||
Reference in New Issue
Block a user