step 6: add animation and high rate update stress tests

This commit is contained in:
2026-07-02 15:06:10 +02:00
parent 1a476bc91d
commit f4716e0d19
9 changed files with 352 additions and 21 deletions

View File

@@ -3,6 +3,7 @@
from __future__ import annotations
import math
import time
from dataclasses import dataclass, field, replace
from enum import IntFlag, auto
from typing import Any
@@ -144,6 +145,13 @@ def animation_config(config: GaugeConfig) -> AnimationConfig | None:
return animation
def smoothing_config(config: GaugeConfig) -> SmoothingConfig | None:
smoothing = config.smoothing
if isinstance(smoothing, bool):
return SmoothingConfig(enabled=smoothing)
return smoothing
def clamp_runtime_value(value: GaugeValue, config: GaugeConfig) -> tuple[float | None, bool]:
numeric = coerce_numeric_value(value)
if numeric is None:
@@ -203,8 +211,9 @@ def get_gauge_state(tag: Tag) -> GaugeState:
raise GaugeNotFoundError(msg) from exc
def set_runtime_value(tag: Tag, value: GaugeValue, *, now: float = 0.0) -> None:
def set_runtime_value(tag: Tag, value: GaugeValue, *, now: float | None = None) -> None:
state = get_gauge_state(tag)
now = time.monotonic() if now is None else now
clamped, invalid = clamp_runtime_value(value, state.config)
state.target_value = value
state.clamped_value = clamped
@@ -215,8 +224,15 @@ def set_runtime_value(tag: Tag, value: GaugeValue, *, now: float = 0.0) -> None:
state.displayed_value, clamped, animation_config(state.config), now
)
if not state.animation_state.active:
state.displayed_value = clamped
state.smoothing_state.value = clamped
smoothing = smoothing_config(state.config)
if smoothing is not None and smoothing.enabled and clamped is not None and not invalid:
if state.smoothing_state.value is None:
state.smoothing_state.value = state.previous_displayed_value
state.smoothing_state.active = state.smoothing_state.value != clamped
else:
state.displayed_value = clamped
state.smoothing_state.value = clamped
state.smoothing_state.active = False
state.dirty |= DirtyFlags.VALUE | DirtyFlags.DYNAMIC | DirtyFlags.TEXT
render_runtime_gauge(state)