First Version EAV Importer. feat: Enhance activity detail retrieval with EAV metrics and refactor activity import logic
Deploy Development / deploy (push) Successful in 53s
Build Test / pytest-backend (push) Successful in 4s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 16s

- Updated the `get_activity_detail` function to include session metrics in the activity detail output, allowing for enriched data representation.
- Refactored the activity import logic to streamline the process of inserting and updating activity records, utilizing new helper functions for better maintainability.
- Improved the handling of duplicate activity entries by implementing a more robust identification mechanism.
- Enhanced the metadata for activity detail registration to reflect the inclusion of EAV metrics and updated source tables.
This commit is contained in:
Lars committed 2026-04-15 07:25:39 +02:00
1 parent c6e8371d5a
commit 934b915357
8 files changed
+550 -361

No files matched your search

+19 -12
View File
@@ -124,7 +124,8 @@ def get_activity_detail_data(
"duration_min": int,
"kcal_active": int,
"hr_avg": int | None,
"training_category": str | None
"training_category": str | None,
"session_metrics": list | None, # EAV (enrich_sessions_with_metrics)
},
...
],
@@ -143,6 +144,7 @@ def get_activity_detail_data(
cur.execute(
"""SELECT
id,
date,
activity_type,
duration_min,
@@ -153,7 +155,7 @@ def get_activity_detail_data(
WHERE profile_id=%s AND date >= %s
ORDER BY date DESC
LIMIT %s""",
(profile_id, cutoff, limit)
(profile_id, cutoff, limit),
)
rows = cur.fetchall()
@@ -162,19 +164,24 @@ def get_activity_detail_data(
"activities": [],
"total_count": 0,
"confidence": "insufficient",
"days_analyzed": days
"days_analyzed": days,
}
activities = []
for row in rows:
activities.append({
"date": row['date'],
"activity_type": row['activity_type'],
"duration_min": safe_int(row['duration_min']),
"kcal_active": safe_int(row['kcal_active']),
"hr_avg": safe_int(row['hr_avg']) if row.get('hr_avg') else None,
"training_category": row.get('training_category')
})
activities.append(
{
"id": str(row["id"]),
"date": row["date"],
"activity_type": row["activity_type"],
"duration_min": safe_int(row["duration_min"]),
"kcal_active": safe_int(row["kcal_active"]),
"hr_avg": safe_int(row["hr_avg"]) if row.get("hr_avg") else None,
"training_category": row.get("training_category"),
}
)
enrich_sessions_with_metrics(cur, activities)
confidence = calculate_confidence(len(activities), days, "general")
@@ -182,7 +189,7 @@ def get_activity_detail_data(
"activities": activities,
"total_count": len(activities),
"confidence": confidence,
"days_analyzed": days
"days_analyzed": days,
}