- Updated the README to include new activity production architecture and phases, improving clarity on the development roadmap. - Enhanced the `ACTIVITY_SESSION_METRICS_EAV_AGENT_GUIDE` with details on the target architecture and phase plan for production readiness. - Introduced a new function `merge_column_backed_and_eav_metrics` to streamline the merging of metrics from column-backed and EAV sources, ensuring data integrity and reducing duplication. - Refactored session metrics handling to eliminate deprecated synchronization methods, improving the overall efficiency of data processing. - Added unit tests for the new merging logic, ensuring robust validation of metrics handling.
79 lines
2.6 KiB
Python
79 lines
2.6 KiB
Python
"""
|
|
Kanonische Aufteilung activity_log vs. EAV für Aktivitätssessions.
|
|
|
|
Single Source für: welche Felder das CSV-/Registry-Modul „activity“ direkt in activity_log schreibt,
|
|
und welche training_parameters primär über EAV laufen (mit optionalem Lesefallback auf Legacy-Spalten).
|
|
|
|
Normative Doku: .claude/docs/technical/ACTIVITY_PRODUCTION_ARCHITECTURE_AND_PHASES.md
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from typing import Dict, Final
|
|
|
|
# ── activity_log: Modul „activity“ (Universal-CSV-Kern) ───────────────────────
|
|
# Nur diese Keys erscheinen in csv_parser.module_registry MODULE_DEFINITIONS["activity"].fields.
|
|
# Alles Weitere: training_parameters + EAV (Import über upsert_session_metrics_from_csv_mapped).
|
|
ACTIVITY_MODULE_REGISTRY_FIELD_KEYS: Final[frozenset[str]] = frozenset(
|
|
{
|
|
"date",
|
|
"start_time",
|
|
"end_time",
|
|
"activity_type",
|
|
"duration_min",
|
|
"kcal_active",
|
|
"kcal_resting",
|
|
"distance_km",
|
|
"hr_avg",
|
|
"hr_max",
|
|
"rpe",
|
|
"notes",
|
|
}
|
|
)
|
|
|
|
# Parameter-Keys (training_parameters.key), die primär in EAV geführt werden; source_field nach Migration 057 NULL.
|
|
# Lesefallback: activity_log-Spalte unter ACTIVITY_LOG_LEGACY_COLUMN_FOR_EAV_PRIMARY_PARAM, falls EAV leer.
|
|
ACTIVITY_EAV_PRIMARY_PARAMETER_KEYS: Final[frozenset[str]] = frozenset(
|
|
{
|
|
"min_hr",
|
|
"pace_min_per_km",
|
|
"cadence",
|
|
"avg_power",
|
|
"elevation_gain",
|
|
"temperature_celsius",
|
|
"humidity_percent",
|
|
"avg_hr_percent",
|
|
"kcal_per_km",
|
|
}
|
|
)
|
|
|
|
# Spaltenname activity_log für Legacy-Lesefallback (Merge), wenn EAV für den Parameter fehlt.
|
|
ACTIVITY_LOG_LEGACY_COLUMN_FOR_EAV_PRIMARY_PARAM: Final[Dict[str, str]] = {
|
|
"min_hr": "hr_min",
|
|
"pace_min_per_km": "pace_min_per_km",
|
|
"cadence": "cadence",
|
|
"avg_power": "avg_power",
|
|
"elevation_gain": "elevation_gain",
|
|
"temperature_celsius": "temperature_celsius",
|
|
"humidity_percent": "humidity_percent",
|
|
"avg_hr_percent": "avg_hr_percent",
|
|
"kcal_per_km": "kcal_per_km",
|
|
}
|
|
|
|
# Spalten, die mit training_parameters.source_field (nach Migration 057) noch activity_log abbilden.
|
|
# Erweiterte Metriken sind EAV-primär — nicht hier auflisten.
|
|
ACTIVITY_LOG_PATCHABLE_COLUMNS: Final[frozenset[str]] = frozenset(
|
|
{
|
|
"start_time",
|
|
"end_time",
|
|
"activity_type",
|
|
"duration_min",
|
|
"kcal_active",
|
|
"kcal_resting",
|
|
"hr_avg",
|
|
"hr_max",
|
|
"distance_km",
|
|
"rpe",
|
|
"notes",
|
|
}
|
|
)
|