feat: Enhance activity import functionality with additional metrics
- Updated the `_import_activity` function to include new metrics: duration_min, kcal_active, kcal_resting, hr_avg, hr_max, and distance_km during CSV imports. - Modified the `insert_activity_csv_minimal` function to accept and store these additional metrics in the activity log. - Enhanced the `run_activity_post_write_hooks_import` function to utilize the new metrics for auto-evaluation after activity imports. - Updated the activity import router to pass the new metrics from the CSV file to the database functions, ensuring comprehensive data handling. - Improved frontend handling of activity entry forms to accommodate the new metrics, enhancing user experience during activity log edits.
This commit is contained in:
1 parent
5cda485458
commit
7d6fdab812
4 files changed
+109
-48
No files matched your search
+20
-14
@@ -641,7 +641,14 @@ async def import_activity_csv(file: UploadFile=File(...), x_profile_id: Optional
|
||||
cur,
|
||||
pid,
|
||||
str(existing_id),
|
||||
workout_date=workout_date,
|
||||
training_type_id=training_type_id,
|
||||
duration_min=duration_min,
|
||||
hr_avg=hr_av,
|
||||
hr_max=hr_mx,
|
||||
distance_km=dist_km,
|
||||
kcal_active=kcal_a,
|
||||
kcal_resting=kcal_r,
|
||||
)
|
||||
else:
|
||||
new_id = new_activity_id()
|
||||
@@ -653,31 +660,30 @@ async def import_activity_csv(file: UploadFile=File(...), x_profile_id: Optional
|
||||
start_time=workout_start_t,
|
||||
end_time=row.get("End", "") or None,
|
||||
activity_type=wtype,
|
||||
duration_min=duration_min,
|
||||
kcal_active=kcal_a,
|
||||
kcal_resting=kcal_r,
|
||||
hr_avg=hr_av,
|
||||
hr_max=hr_mx,
|
||||
distance_km=dist_km,
|
||||
training_type_id=training_type_id,
|
||||
training_category=training_category,
|
||||
training_subcategory=training_subcategory,
|
||||
source="apple_health",
|
||||
)
|
||||
apple_metrics = {
|
||||
k: v
|
||||
for k, v in {
|
||||
"duration_min": duration_min,
|
||||
"kcal_active": kcal_a,
|
||||
"kcal_resting": kcal_r,
|
||||
"hr_avg": hr_av,
|
||||
"hr_max": hr_mx,
|
||||
"distance_km": dist_km,
|
||||
}.items()
|
||||
if v is not None
|
||||
}
|
||||
if apple_metrics:
|
||||
update_activity_columns(cur, pid, new_id, apple_metrics)
|
||||
inserted += 1
|
||||
run_activity_post_write_hooks_import(
|
||||
cur,
|
||||
pid,
|
||||
new_id,
|
||||
workout_date=workout_date,
|
||||
training_type_id=training_type_id,
|
||||
duration_min=duration_min,
|
||||
hr_avg=hr_av,
|
||||
hr_max=hr_mx,
|
||||
distance_km=dist_km,
|
||||
kcal_active=kcal_a,
|
||||
kcal_resting=kcal_r,
|
||||
)
|
||||
except Exception as e:
|
||||
logger.warning(f"Import row failed: {e}")
|
||||
|
||||
Reference in new issue
Block a user