- Replaced hardcoded keys in `activity_data_canon.py` with a dynamic retrieval method from the module registry, ensuring that `ACTIVITY_MODULE_REGISTRY_FIELD_KEYS` reflects the current configuration. - Updated `activity_persistence_orchestrator.py` to utilize the new dynamic field retrieval function, enhancing consistency across the data layer. - Modified `activity_session_metrics.py` to reference the dynamic field keys, improving maintainability and reducing redundancy in the codebase.
61 lines
2.3 KiB
Python
61 lines
2.3 KiB
Python
"""
|
|
Kanonische Aufteilung activity_log vs. EAV für Aktivitätssessions.
|
|
|
|
- **Kern / Mapping-Ziele für activity_log:** ausschließlich die Keys aus
|
|
``csv_parser.module_registry.MODULE_DEFINITIONS["activity"].fields`` (keine zweite hartcodierte Liste).
|
|
- **Alle anderen Attribute:** ``training_parameters`` + Attributprofil (Kategorie/Typ) → EAV;
|
|
Lesefallback für bekannte Legacy-Spalten siehe unten.
|
|
|
|
Normative Doku: .claude/docs/technical/ACTIVITY_PRODUCTION_ARCHITECTURE_AND_PHASES.md
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from typing import Dict, Final
|
|
|
|
from csv_parser.module_registry import get_module_definition
|
|
|
|
|
|
def get_activity_module_registry_field_keys() -> frozenset[str]:
|
|
"""Keys des Universal-CSV-Moduls ``activity`` (= feste activity_log-Kernfelder / Mapping-Ziele)."""
|
|
mod = get_module_definition("activity")
|
|
if not mod:
|
|
return frozenset()
|
|
return frozenset((mod.get("fields") or {}).keys())
|
|
|
|
|
|
# Gleiche Menge wie ``MODULE_DEFINITIONS["activity"].fields`` — zur Laufzeit aus der Registry abgeleitet.
|
|
ACTIVITY_MODULE_REGISTRY_FIELD_KEYS: Final[frozenset[str]] = get_activity_module_registry_field_keys()
|
|
|
|
# Teil-UPDATEs (Import): alle Kernfelder außer ``date`` (Identität / Duplikat-Key).
|
|
ACTIVITY_LOG_PATCHABLE_COLUMNS: Final[frozenset[str]] = ACTIVITY_MODULE_REGISTRY_FIELD_KEYS - {"date"}
|
|
|
|
# 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",
|
|
}
|
|
|