2020from typing import Optional
2121
2222
23+ def _round_ms (value : float ) -> float :
24+ return round (float (value ), 6 )
25+
26+
2327class 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