8a6ed249be
- HTTP connection pooling: UpstreamClient & WebsiteClient reuse httpx.Client - Deduplicate decimal_string into shared app/utils/number.py - Split scheduler transaction: snapshot write → webhook/website sync in separate sessions - Remove hardcoded 170.106.100.210 migration from database.py - Reset consecutive_failures on upstream update - Healthcheck: install curl, replace python -c with curl -f - Add .dockerignore to reduce build context - Frontend: add axios-retry with exponential backoff (5xx/network errors only)
26 lines
709 B
Python
26 lines
709 B
Python
"""Shared numeric formatting utilities."""
|
|
from __future__ import annotations
|
|
|
|
from decimal import Decimal, InvalidOperation
|
|
from typing import Any
|
|
|
|
|
|
def decimal_string(value: Any) -> str:
|
|
"""Format a numeric value as a clean decimal string.
|
|
|
|
- None / empty → ""
|
|
- Whole numbers → no decimal point (e.g. "5")
|
|
- Decimals → trailing zeros stripped (e.g. "3.14")
|
|
- Unparseable → raw str()
|
|
"""
|
|
if value is None or value == "":
|
|
return ""
|
|
try:
|
|
d = Decimal(str(value))
|
|
except (InvalidOperation, ValueError):
|
|
return str(value)
|
|
n = d.normalize()
|
|
if n == n.to_integral():
|
|
return str(n.quantize(Decimal("1")))
|
|
return format(n, "f")
|