78 lines
3.1 KiB
Python
78 lines
3.1 KiB
Python
import sys
|
|
import os
|
|
from sqlalchemy import create_engine, select
|
|
from sqlalchemy.orm import sessionmaker
|
|
import fitdecode
|
|
import io
|
|
|
|
# Add curdir to path to allow imports from src
|
|
sys.path.append(os.getcwd())
|
|
|
|
# Import models - adjust import paths if needed strictly relative or absolute
|
|
from src.models.activity import Activity
|
|
from src.services.parsers import _extract_data_from_fit
|
|
|
|
# Using localhost:5433 as per docker-compose port mapping for host access
|
|
DATABASE_URL = "postgresql://postgres:password@localhost:5433/fitbit_garmin_sync"
|
|
|
|
def debug_activity(garmin_id):
|
|
print(f"Connecting to DB: {DATABASE_URL}")
|
|
try:
|
|
engine = create_engine(DATABASE_URL)
|
|
Session = sessionmaker(bind=engine)
|
|
session = Session()
|
|
except Exception as e:
|
|
print(f"Failed to connect to DB: {e}")
|
|
return
|
|
|
|
try:
|
|
activity = session.query(Activity).filter(Activity.garmin_activity_id == garmin_id).first()
|
|
if not activity:
|
|
print(f"Activity {garmin_id} not found in DB.")
|
|
return
|
|
|
|
print(f"Activity Found: ID={activity.id}, GarminID={activity.garmin_activity_id}")
|
|
print(f" Name: {activity.activity_name}")
|
|
print(f" Type: {activity.activity_type}")
|
|
print(f" Distance: {activity.distance}")
|
|
print(f" Avg Power: {activity.avg_power}")
|
|
print(f" Avg Speed: {activity.avg_speed}")
|
|
print(f" File Type: {activity.file_type}")
|
|
print(f" File Content Size: {len(activity.file_content) if activity.file_content else 0} bytes")
|
|
|
|
if activity.file_content and activity.file_type == 'fit':
|
|
print("\n--- Parsing FIT File Content ---")
|
|
try:
|
|
data = _extract_data_from_fit(activity.file_content)
|
|
print(f" Data Keys: {data.keys()}")
|
|
print(f" Points Count: {len(data.get('points', []))}")
|
|
|
|
power_data = data.get('power', [])
|
|
print(f" Power Count: {len(power_data)}")
|
|
valid_power = [p for p in power_data if p is not None]
|
|
if valid_power:
|
|
print(f" Avg Power (Calculated from stream): {sum(valid_power)/len(valid_power)}")
|
|
print(f" Max Power (Calculated from stream): {max(valid_power)}")
|
|
else:
|
|
print(f" Avg Power (Calculated from stream): None")
|
|
|
|
none_power = sum(1 for x in power_data if x is None)
|
|
print(f" Power None values: {none_power} / {len(power_data)}")
|
|
|
|
# Check lat/long
|
|
points = data.get('points', [])
|
|
if points:
|
|
print(f" First point: {points[0]}")
|
|
print(f" Last point: {points[-1]}")
|
|
|
|
except Exception as e:
|
|
print(f" Error parsing FIT file: {e}")
|
|
else:
|
|
print(f" No FIT file content or file type is not 'fit' (Type: {activity.file_type})")
|
|
|
|
finally:
|
|
session.close()
|
|
|
|
if __name__ == "__main__":
|
|
debug_activity("21517046364")
|