feat: enhance normalization of metric values for improved handling
Deploy Development / deploy (push) Successful in 50s
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 `_normalize_metric_value_for_read` to compact numeric strings and ensure consistent formatting for string data types.
- Enhanced `normalize_prompt_number` to handle numeric strings and non-finite float values effectively.
- Improved unit tests to validate the new normalization behavior for session metrics and scalar formatting.
This commit is contained in:
Lars committed 2026-04-18 10:43:21 +02:00
1 parent 178534e9eb
commit 7676897fda
4 files changed
+64 -10

No files matched your search

@@ -6,6 +6,7 @@ from unittest.mock import patch
import pytest
from data_layer.activity_session_metrics import (
_normalize_metric_value_for_read,
ActivitySessionMetricsError,
enrich_sessions_with_metrics,
merge_column_backed_and_eav_metrics,
@@ -206,6 +207,11 @@ def test_row_value_tuple_mapping():
assert _row_value_tuple("boolean", True) == (None, None, None, True)
def test_normalize_metric_string_dtype_compacts_numeric_strings():
assert _normalize_metric_value_for_read("string", "51.58181818181818") == 52
assert _normalize_metric_value_for_read("string", "Freitext") == "Freitext"
class _FakeCursor:
"""Sequences fetchone/fetchall for resolve_activity_attribute_schema."""
@@ -45,6 +45,29 @@ def test_format_scalar_no_long_float_tail():
assert len(s) <= 8
def test_format_scalar_numeric_string_no_long_tail():
s = format_scalar_for_prompt_text("51.581818181818181818")
assert "181818" not in s
def test_session_metrics_string_dtype_compacts_numeric_strings():
sm = [
{
"key": "temp_c",
"data_type": "string",
"value": "22.333333333333336",
},
{
"key": "kcal_per_km",
"data_type": "string",
"value": "51.581818181818181818",
},
]
out = session_metrics_list_to_key_value_compact(sm)
assert out["temp_c"] == 22
assert out["kcal_per_km"] == 52
def test_session_metrics_key_value_only():
sm = [
{