Round DSP report values to whole numbers

This commit is contained in:
2026-10-15 14:49:33 +08:00
parent 29eb138f93
commit fdf269e3f5
2 changed files with 10 additions and 6 deletions
+7 -3
View File
@@ -59,11 +59,15 @@ def read_response(response) -> str:
return response.read().decode("utf-8", errors="replace")
def to_number(value) -> float:
def to_number(value) -> int:
"""Return a nearest whole number for report metrics."""
try:
return float(value or 0)
number = float(value or 0)
except (TypeError, ValueError):
return 0.0
return 0
# Metrics are non-negative in the source; this also handles any negative
# values with conventional half-away-from-zero rounding.
return int(number + 0.5) if number >= 0 else int(number - 0.5)
def normalise_date(value) -> str: