Skip to main content

subtr_actor/stats/analysis_graph/nodes/
fifty_fifty.rs

1use super::*;
2use crate::stats::calculators::*;
3use crate::*;
4
5/// Derives 50/50 stats and events from the shared fifty-fifty state node.
6pub struct FiftyFiftyNode {
7    calculator: FiftyFiftyCalculator,
8}
9
10impl FiftyFiftyNode {
11    pub fn new() -> Self {
12        Self {
13            calculator: FiftyFiftyCalculator::new(),
14        }
15    }
16}
17
18impl Default for FiftyFiftyNode {
19    fn default() -> Self {
20        Self::new()
21    }
22}
23
24impl AnalysisNode for FiftyFiftyNode {
25    type State = FiftyFiftyCalculator;
26
27    fn name(&self) -> &'static str {
28        "fifty_fifty"
29    }
30
31    fn emitted_events(&self) -> &'static [crate::stats::calculators::EmittedEvent] {
32        crate::stats::calculators::FIFTY_FIFTY_EMITTED_EVENTS
33    }
34
35    fn dependencies(&self) -> NodeDependencies {
36        vec![fifty_fifty_state_dependency()]
37    }
38
39    fn evaluate(&mut self, ctx: &AnalysisStateContext<'_>) -> SubtrActorResult<()> {
40        let fifty_fifty_state = ctx.get::<FiftyFiftyState>()?;
41        self.calculator.update(fifty_fifty_state)
42    }
43
44    fn state(&self) -> &Self::State {
45        &self.calculator
46    }
47}
48
49pub(crate) fn boxed_default() -> Box<dyn AnalysisNodeDyn> {
50    Box::new(FiftyFiftyNode::new())
51}