feat: enhance formatting and normalization of activity metrics
- Introduced `format_scalar_for_prompt_text` function to standardize the representation of scalar values in activity summaries and details. - Updated `get_activity_summary` and `get_activity_detail` functions to utilize the new formatting for improved readability. - Added normalization for float values in session metrics to prevent excessively long representations. - Enhanced unit tests to verify the new formatting and normalization behavior.
This commit is contained in:
1 parent
6756dc60f3
commit
178534e9eb
5 files changed
+103
-4
No files matched your search
@@ -121,6 +121,38 @@ def test_merge_parameter_schema_includes_descriptions():
|
||||
assert merged[0]["description_en"] == "5 min average power"
|
||||
|
||||
|
||||
def test_merge_eav_float_value_normalized_no_long_tail():
|
||||
"""Layer 1: lange Floats (z. B. kcal_per_km) für Lesepfad kompakt."""
|
||||
schema = [
|
||||
{
|
||||
"training_parameter_id": 1,
|
||||
"key": "kcal_per_km",
|
||||
"data_type": "float",
|
||||
"unit": "kcal/km",
|
||||
"validation_rules": {},
|
||||
"source_field": None,
|
||||
"name_de": "Kcal/km",
|
||||
"name_en": "kcal/km",
|
||||
"description_de": None,
|
||||
"description_en": None,
|
||||
"param_category": "performance",
|
||||
}
|
||||
]
|
||||
eav = [
|
||||
{
|
||||
"training_parameter_id": 1,
|
||||
"key": "kcal_per_km",
|
||||
"data_type": "float",
|
||||
"unit": "kcal/km",
|
||||
"value": 51.5818181818181818,
|
||||
}
|
||||
]
|
||||
out = merge_column_backed_and_eav_metrics({}, schema, eav)
|
||||
assert len(out) == 1
|
||||
v = out[0]["value"]
|
||||
assert "581818" not in repr(v)
|
||||
|
||||
|
||||
def test_merge_column_backed_includes_human_labels_from_schema():
|
||||
schema = [
|
||||
{
|
||||
|
||||
@@ -5,6 +5,7 @@ import pytest
|
||||
from data_layer.prompt_output_compact import (
|
||||
compact_float_for_prompt,
|
||||
compact_json_payload_for_prompts,
|
||||
format_scalar_for_prompt_text,
|
||||
normalize_prompt_number,
|
||||
session_metrics_list_to_key_value_compact,
|
||||
)
|
||||
@@ -38,6 +39,12 @@ def test_compact_json_nested():
|
||||
assert out["d"][0] == 1.11
|
||||
|
||||
|
||||
def test_format_scalar_no_long_float_tail():
|
||||
s = format_scalar_for_prompt_text(51.5818181818181818)
|
||||
assert "181818" not in s
|
||||
assert len(s) <= 8
|
||||
|
||||
|
||||
def test_session_metrics_key_value_only():
|
||||
sm = [
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user