rill_view/flow/data/
gauge.rs1use rill_protocol::flow::core::{Flow, TimedEvent};
2use rill_protocol::io::provider::{StreamType, Timestamp};
3use rill_protocol::range::Range;
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct GaugeState {
8 pub range: Range,
10
11 pub timestamp: Option<Timestamp>,
13 pub value: f64,
14}
15
16impl GaugeState {
17 pub fn new(range: Range) -> Self {
18 Self {
19 range,
20 timestamp: None,
21 value: 0.0,
22 }
23 }
24
25 pub fn last(&self) -> Option<TimedEvent<f64>> {
26 self.timestamp.map(|ts| TimedEvent {
27 timestamp: ts,
28 event: self.value,
29 })
30 }
31}
32
33impl Flow for GaugeState {
34 type Action = ();
35 type Event = GaugeEvent;
36
37 fn stream_type() -> StreamType {
38 StreamType::from("rillrate.data.gauge.v0")
39 }
40
41 fn apply(&mut self, event: TimedEvent<Self::Event>) {
42 match event.event {
43 GaugeEvent::Set(delta) => {
44 self.timestamp = Some(event.timestamp);
45 self.value = delta;
46 }
47 }
48 }
49}
50
51pub type GaugeDelta = Vec<TimedEvent<GaugeEvent>>;
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
54pub enum GaugeEvent {
55 Set(f64),
56}