Skip to content

Commit 5ea51d9

Browse files
authored
Refactor time calculations to use _round_ms function
1 parent ca0aa96 commit 5ea51d9

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

src/ohip_interfaces/signal_health.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
from typing import Optional
2121

2222

23+
def _round_ms(value: float) -> float:
24+
return round(float(value), 6)
25+
26+
2327
class SignalHealth(str, Enum):
2428
"""
2529
Health classification for one normalized signal source.
@@ -57,7 +61,7 @@ class FreshnessPolicy:
5761

5862
def is_fresh(self, *, sample_timestamp_utc_s: float, now_utc_s: Optional[float] = None) -> bool:
5963
now = float(now_utc_s if now_utc_s is not None else time())
60-
age_ms = (now - float(sample_timestamp_utc_s)) * 1000.0
64+
age_ms = _round_ms((now - float(sample_timestamp_utc_s)) * 1000.0)
6165
return age_ms <= float(self.max_age_ms)
6266

6367

@@ -81,10 +85,10 @@ class SignalQuality:
8185

8286
def age_ms(self, *, now_utc_s: Optional[float] = None) -> float:
8387
now = float(now_utc_s if now_utc_s is not None else time())
84-
return max(0.0, (now - float(self.sample_timestamp_utc_s)) * 1000.0)
88+
return max(0.0, _round_ms((now - float(self.sample_timestamp_utc_s)) * 1000.0))
8589

8690
def transport_latency_ms(self) -> float:
87-
return max(0.0, (float(self.received_timestamp_utc_s) - float(self.sample_timestamp_utc_s)) * 1000.0)
91+
return max(0.0, _round_ms((float(self.received_timestamp_utc_s) - float(self.sample_timestamp_utc_s)) * 1000.0))
8892

8993
def is_fresh(self, policy: FreshnessPolicy, *, now_utc_s: Optional[float] = None) -> bool:
9094
return policy.is_fresh(

0 commit comments

Comments
 (0)