refactor: Remove source field handling from activity session metrics logic
- Eliminated checks for `source_field` in the `replace_activity_session_metrics` function to streamline EAV row replacement, ensuring consistency with existing logic. - Updated frontend logic to simplify the filtering of metrics during payload construction, enhancing maintainability. - Removed outdated unit tests related to `source_field` handling, reflecting the updated logic in the codebase.
This commit is contained in:
1 parent
94bb4a8199
commit
2a26e4fecf
3 files changed
+2
-104
No files matched your search
@@ -10,7 +10,6 @@ from data_layer.activity_session_metrics import (
|
||||
enrich_sessions_with_metrics,
|
||||
merge_column_backed_and_eav_metrics,
|
||||
merge_parameter_schema_rows,
|
||||
replace_activity_session_metrics,
|
||||
resolve_activity_attribute_schema,
|
||||
upsert_session_metrics_from_csv_mapped,
|
||||
_row_value_tuple,
|
||||
@@ -378,58 +377,3 @@ def test_upsert_csv_writes_eav_when_no_source_field(mock_schema):
|
||||
1,
|
||||
)
|
||||
assert cur.asm_inserts == 1
|
||||
|
||||
|
||||
@patch("data_layer.activity_session_metrics.fetch_activity_session_metrics", return_value=[])
|
||||
@patch("data_layer.activity_session_metrics.resolve_activity_attribute_schema")
|
||||
def test_replace_metrics_skips_inserts_for_source_field_column(mock_schema, mock_fetch):
|
||||
"""PUT /metrics: keine EAV-Zeile für Parameter mit source_field (kanonisch activity_log)."""
|
||||
mock_schema.return_value = [
|
||||
{
|
||||
"key": "avg_hr",
|
||||
"training_parameter_id": 1,
|
||||
"data_type": "integer",
|
||||
"validation_rules": {},
|
||||
"source_field": "hr_avg",
|
||||
"required": False,
|
||||
},
|
||||
{
|
||||
"key": "custom_x",
|
||||
"training_parameter_id": 2,
|
||||
"data_type": "string",
|
||||
"validation_rules": {},
|
||||
"source_field": None,
|
||||
"required": False,
|
||||
},
|
||||
]
|
||||
|
||||
class Cur:
|
||||
def __init__(self):
|
||||
self.asm_inserts = 0
|
||||
|
||||
def execute(self, sql, params=None):
|
||||
self._sql = sql
|
||||
if "INSERT INTO activity_session_metrics" in sql:
|
||||
self.asm_inserts += 1
|
||||
|
||||
def fetchone(self):
|
||||
if "FROM activity_log" in getattr(self, "_sql", ""):
|
||||
return {
|
||||
"id": "00000000-0000-0000-0000-000000000002",
|
||||
"profile_id": "00000000-0000-0000-0000-000000000001",
|
||||
"training_category": "cardio",
|
||||
"training_type_id": 1,
|
||||
}
|
||||
return None
|
||||
|
||||
cur = Cur()
|
||||
replace_activity_session_metrics(
|
||||
cur,
|
||||
"00000000-0000-0000-0000-000000000001",
|
||||
"00000000-0000-0000-0000-000000000002",
|
||||
[
|
||||
{"parameter_key": "avg_hr", "value": 120},
|
||||
{"parameter_key": "custom_x", "value": "y"},
|
||||
],
|
||||
)
|
||||
assert cur.asm_inserts == 1
|
||||
Reference in new issue
Block a user