87 lines
3.3 KiB
Python
87 lines
3.3 KiB
Python
import sys
|
|
import os
|
|
from sqlalchemy import create_engine
|
|
from sqlalchemy.orm import sessionmaker
|
|
import logging
|
|
|
|
# Add curdir to path
|
|
sys.path.append(os.getcwd())
|
|
|
|
from src.models.activity import Activity
|
|
from src.services.sync.activity import GarminActivitySync
|
|
|
|
# Configure logging to see the output from the service
|
|
logging.basicConfig(level=logging.INFO)
|
|
logger = logging.getLogger(__name__)
|
|
|
|
# Using localhost:5433 as per docker-compose port mapping
|
|
DATABASE_URL = "postgresql://postgres:password@localhost:5433/fitbit_garmin_sync"
|
|
|
|
def verify_fix(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"Before Backfill:")
|
|
print(f" Distance: {activity.distance}")
|
|
print(f" Avg Power: {activity.avg_power}")
|
|
print(f" Max Power: {activity.max_power}")
|
|
print(f" Avg Cadence: {activity.avg_cadence}")
|
|
|
|
# Instantiate Sync Service with dummy client (not needed for this method)
|
|
sync_service = GarminActivitySync(session, None)
|
|
|
|
# Run Backfill
|
|
print("\nRunning _backfill_metrics_from_file...")
|
|
sync_service._backfill_metrics_from_file(activity)
|
|
|
|
# Check results (pending commit)
|
|
print(f"\nAfter Backfill (InMemory):")
|
|
print(f" Distance: {activity.distance}")
|
|
print(f" Avg Power: {activity.avg_power}")
|
|
print(f" Max Power: {activity.max_power}")
|
|
print(f" Avg Cadence: {activity.avg_cadence}")
|
|
|
|
if activity.distance is not None and activity.avg_power is not None:
|
|
print("\nSUCCESS: Metrics were populated.")
|
|
|
|
print("\nExtended Metrics Check:")
|
|
print(f" Pedal Smoothness (L/R): {activity.avg_left_pedal_smoothness} / {activity.avg_right_pedal_smoothness}")
|
|
print(f" Torque Effectiveness (L/R): {activity.avg_left_torque_effectiveness} / {activity.avg_right_torque_effectiveness}")
|
|
print(f" Grit/Flow: {activity.grit} / {activity.flow}")
|
|
print(f" Total Work: {activity.total_work}")
|
|
print(f" Respiration Rate (Avg/Max): {activity.avg_respiration_rate} / {activity.max_respiration_rate}")
|
|
|
|
print("\nStandard Metrics Check:")
|
|
print(f" Max HR: {activity.max_hr}")
|
|
print(f" Max Speed: {activity.max_speed}")
|
|
print(f" Elevation Gain/Loss: {activity.elevation_gain} / {activity.elevation_loss}")
|
|
print(f" Training Effect (Aerobic/Anaerobic): {activity.aerobic_te} / {activity.anaerobic_te}")
|
|
print(f" TSS: {activity.tss}")
|
|
print(f" Normalized Power: {activity.norm_power}")
|
|
|
|
# Commit to save changes
|
|
session.commit()
|
|
print("Changes committed to DB.")
|
|
else:
|
|
print("\nFAILURE: Metrics were NOT populated.")
|
|
|
|
except Exception as e:
|
|
print(f"Error: {e}")
|
|
finally:
|
|
session.close()
|
|
|
|
if __name__ == "__main__":
|
|
verify_fix("21517046364")
|