feat: Update activity metrics handling to prioritize legacy columns over EAV
- Enhanced the `merge_column_backed_and_eav_metrics` function to ensure that when both legacy columns and EAV values are present, the legacy column takes precedence. - Revised documentation in `ACTIVITY_PRODUCTION_ARCHITECTURE_AND_PHASES.md` and `ACTIVITY_SCALAR_KANON_TABLE.md` to reflect the new reading logic and clarify the handling of metrics. - Updated the `activity_data_canon.py` to specify the new merge behavior, ensuring consistency in data retrieval. - Added unit tests to validate the new logic, confirming that legacy columns are preferred when available.
This commit is contained in:
1 parent
38797d687d
commit
680ecd1c06
6 files changed
+111
-23
No files matched your search
@@ -307,6 +307,58 @@ def test_merge_eav_primary_falls_back_to_legacy_hr_min_column():
|
||||
assert out[0]["value"] == 88
|
||||
|
||||
|
||||
def test_merge_eav_primary_prefers_legacy_column_over_eav_when_both():
|
||||
"""Kanon: bei min_hr + hr_min und EAV-Zeile gewinnt activity_log (hr_min)."""
|
||||
schema = [
|
||||
{
|
||||
"training_parameter_id": 9,
|
||||
"key": "min_hr",
|
||||
"data_type": "integer",
|
||||
"unit": "bpm",
|
||||
"validation_rules": {},
|
||||
"source_field": None,
|
||||
}
|
||||
]
|
||||
eav = [
|
||||
{
|
||||
"training_parameter_id": 9,
|
||||
"key": "min_hr",
|
||||
"data_type": "integer",
|
||||
"unit": "bpm",
|
||||
"value": 100,
|
||||
}
|
||||
]
|
||||
out = merge_column_backed_and_eav_metrics({"hr_min": 88}, schema, eav)
|
||||
assert len(out) == 1
|
||||
assert out[0]["value"] == 88
|
||||
|
||||
|
||||
def test_merge_registry_key_prefers_activity_log_column_over_eav():
|
||||
"""Parameter-Key = Registry-Feld (z. B. duration_min): Spalte vor EAV."""
|
||||
schema = [
|
||||
{
|
||||
"training_parameter_id": 3,
|
||||
"key": "duration_min",
|
||||
"data_type": "float",
|
||||
"unit": "min",
|
||||
"validation_rules": {},
|
||||
"source_field": None,
|
||||
}
|
||||
]
|
||||
eav = [
|
||||
{
|
||||
"training_parameter_id": 3,
|
||||
"key": "duration_min",
|
||||
"data_type": "float",
|
||||
"unit": "min",
|
||||
"value": 99.0,
|
||||
}
|
||||
]
|
||||
out = merge_column_backed_and_eav_metrics({"duration_min": 45.0}, schema, eav)
|
||||
assert len(out) == 1
|
||||
assert out[0]["value"] == 45.0
|
||||
|
||||
|
||||
@patch("data_layer.activity_session_metrics.resolve_activity_attribute_schema")
|
||||
def test_upsert_csv_skips_eav_when_source_field_maps_activity_log(mock_schema):
|
||||
"""Parameter mit source_field: kanonisch activity_log — kein doppeltes EAV (z. B. avg_hr → hr_avg)."""
|
||||
|
||||
Reference in new issue
Block a user