- Integrated compact JSON payload generation for session metrics in `get_training_sessions_recent_weeks_data`. - Updated the registration of activity session insights to reflect the new compact format for session metrics. - Improved documentation to clarify the structure and semantics of the session metrics in the JSON output. - Added normalization for prompt numbers to ensure consistent formatting in the metrics.
60 lines
1.4 KiB
Python
60 lines
1.4 KiB
Python
"""Tests für data_layer.prompt_output_compact (KI-Platzhalter, Token)."""
|
|
|
|
import pytest
|
|
|
|
from data_layer.prompt_output_compact import (
|
|
compact_float_for_prompt,
|
|
compact_json_payload_for_prompts,
|
|
normalize_prompt_number,
|
|
session_metrics_list_to_key_value_compact,
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"x,expected",
|
|
[
|
|
(0.0, 0),
|
|
(123.456, 123),
|
|
(45.67, 46),
|
|
(9.876, 9.88),
|
|
(0.99, 0.99),
|
|
(0.055, 0.055),
|
|
(0.01234, 0.012),
|
|
],
|
|
)
|
|
def test_compact_float_for_prompt(x, expected):
|
|
out = compact_float_for_prompt(x)
|
|
if isinstance(expected, float):
|
|
assert abs(float(out) - expected) < 0.0001
|
|
else:
|
|
assert out == expected
|
|
|
|
|
|
def test_compact_json_nested():
|
|
raw = {"a": 12.345678, "b": {"c": 0.0666}, "d": [1.111, 2.0]}
|
|
out = compact_json_payload_for_prompts(raw)
|
|
assert out["a"] == 12
|
|
assert abs(out["b"]["c"] - 0.067) < 0.001
|
|
assert out["d"][0] == 1.11
|
|
|
|
|
|
def test_session_metrics_key_value_only():
|
|
sm = [
|
|
{
|
|
"key": "rpe",
|
|
"data_type": "integer",
|
|
"value": 7,
|
|
"name_de": "RPE",
|
|
"description_de": "lang",
|
|
},
|
|
{
|
|
"key": "watts",
|
|
"data_type": "float",
|
|
"value": 199.999,
|
|
"unit": "W",
|
|
},
|
|
]
|
|
out = session_metrics_list_to_key_value_compact(sm)
|
|
assert out == {"rpe": 7, "watts": 200}
|
|
assert "name_de" not in str(out)
|