Skip to content

Commit 0346356

Browse files
committed
fix(log-analysis): preserve fractional parameter values in review dialogs
Format parameter values without truncating decimals in the log-quality parameter-change review dialog. Add coverage for integral and fractional display values. Signed-off-by: Dr.-Ing. Amilcar do Carmo Lucas <amilcar.lucas@iav.de>
1 parent ad594ec commit 0346356

2 files changed

Lines changed: 52 additions & 2 deletions

File tree

ardupilot_methodic_configurator/frontend_tkinter_log_quality.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@
4545
)
4646

4747

48+
def _format_parameter_value(value: float) -> str:
49+
"""Format a parameter value without hiding fractional changes."""
50+
return str(int(value)) if value.is_integer() else str(value)
51+
52+
4853
class LogQualityReportWindow(BaseWindow): # pylint: disable=too-many-instance-attributes
4954
"""Displays log analysis results as a beginner-friendly, detailed dashboard."""
5055

@@ -185,9 +190,14 @@ def _open_review_dialog(self, fixes: list[tuple[str, float, float, list[str]]])
185190
row = ttk.Frame(rows_frame)
186191
row.pack(fill=tk.X, pady=4)
187192
ttk.Label(row, text=param_name, width=18, font=("TkDefaultFont", 11, "bold")).pack(side=tk.LEFT)
188-
ttk.Label(row, text=str(int(current)), foreground="gray").pack(side=tk.LEFT, padx=(0, 6))
193+
ttk.Label(row, text=_format_parameter_value(current), foreground="gray").pack(side=tk.LEFT, padx=(0, 6))
189194
ttk.Label(row, text="->").pack(side=tk.LEFT, padx=(0, 6))
190-
value_lbl = ttk.Label(row, text=str(int(proposed)), foreground="darkgreen", font=("TkDefaultFont", 11, "bold"))
195+
value_lbl = ttk.Label(
196+
row,
197+
text=_format_parameter_value(proposed),
198+
foreground="darkgreen",
199+
font=("TkDefaultFont", 11, "bold"),
200+
)
191201
value_lbl.pack(side=tk.LEFT)
192202
show_tooltip(value_lbl, "\n".join(f"- {r}" for r in reasons))
193203

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env python3
2+
3+
"""
4+
Tests for ardupilot_methodic_configurator/frontend_tkinter_log_quality.py.
5+
6+
This file is part of ArduPilot Methodic Configurator. https://github.com/ArduPilot/MethodicConfigurator
7+
8+
SPDX-FileCopyrightText: 2024-2026 Amilcar do Carmo Lucas <amilcar.lucas@iav.de>
9+
10+
SPDX-License-Identifier: GPL-3.0-or-later
11+
"""
12+
13+
import pytest
14+
15+
from ardupilot_methodic_configurator.frontend_tkinter_log_quality import _format_parameter_value
16+
17+
18+
@pytest.mark.parametrize(
19+
("value", "expected"),
20+
[
21+
(123.0, "123"),
22+
(0.15, "0.15"),
23+
(1.25, "1.25"),
24+
],
25+
)
26+
def test_parameter_value_formatting_preserves_fractional_changes(value: float, expected: str) -> None:
27+
"""
28+
Display parameter values without silently changing their meaning.
29+
30+
GIVEN integral and fractional parameter values,
31+
WHEN they are formatted for the parameter-change review dialog,
32+
THEN integral values omit an unnecessary decimal and fractional values are preserved.
33+
"""
34+
# Arrange: parametrized parameter values represent pending FC changes.
35+
36+
# Act: format the value shown to the user.
37+
actual = _format_parameter_value(value)
38+
39+
# Assert: the text faithfully represents the value that will be uploaded.
40+
assert actual == expected

0 commit comments

Comments
 (0)