feat: Enhance activity import functionality with additional metrics
Deploy Development / deploy (push) Successful in 58s
Build Test / pytest-backend (push) Successful in 4s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 17s

- 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:
Lars committed 2026-04-16 11:04:43 +02:00
1 parent 5cda485458
commit 7d6fdab812
4 files changed
+109 -48

No files matched your search

+32 -2
View File
@@ -96,7 +96,7 @@ const ACTIVITY_LOG_PAYLOAD_KEYS = new Set([
'training_subcategory',
])
/** activity_log-Spalten, die im EntryForm editiert werden (nicht aus metricDraft überschreiben). */
/** activity_log-Spalten, die im EntryForm editiert werden (Kurzform). */
const ACTIVITY_ENTRY_FORM_COLUMNS = new Set([
'duration_min',
'kcal_active',
@@ -568,6 +568,27 @@ export default function ActivityPage() {
setMetricDraft(m)
}, [sessionDetail])
/** Nach GET /activity/:id: Kopf-Spalten ins EntryForm, wenn die Listenzeile leer war (Parameter-Keys vs. Spalten). */
useEffect(() => {
const h = sessionDetail?.header
if (!h?.id || !editing?.id) return
if (String(h.id) !== String(editing.id)) return
setEditing((prev) => {
if (String(h.id) !== String(prev.id)) return prev
let changed = false
const next = { ...prev }
for (const col of ACTIVITY_ENTRY_FORM_COLUMNS) {
const cur = next[col]
const empty = cur === null || cur === undefined || cur === ''
if (empty && h[col] != null && h[col] !== '') {
next[col] = h[col]
changed = true
}
}
return changed ? next : prev
})
}, [sessionDetail, editing?.id])
const handleSave = async () => {
setSaving(true)
setError(null)
@@ -612,7 +633,16 @@ export default function ActivityPage() {
if (!col || !ACTIVITY_LOG_PAYLOAD_KEYS.has(col)) continue
const useFormColumn = ACTIVITY_ENTRY_FORM_COLUMNS.has(col)
if (!useFormColumn && !(s.key in metricDraft)) continue
const raw = useFormColumn ? editing[col] : metricDraft[s.key]
let raw
if (useFormColumn) {
const fromForm = editing[col]
const fromDraft = metricDraft[s.key]
const formEmpty = fromForm === null || fromForm === undefined || fromForm === ''
const draftEmpty = fromDraft === null || fromDraft === undefined || fromDraft === ''
raw = !formEmpty ? fromForm : !draftEmpty ? fromDraft : fromForm
} else {
raw = metricDraft[s.key]
}
const rawStr = raw === null || raw === undefined ? '' : String(raw).trim()
if (rawStr === '') {
payload[col] = null