Skip to main content

subtr_actor/stats/analysis_graph/nodes/
ball_half.rs

1use super::*;
2use crate::stats::calculators::*;
3use crate::*;
4
5/// Tracks which half of the field the ball is in from ball-frame and live-play state.
6pub struct BallHalfNode {
7    calculator: BallHalfCalculator,
8}
9
10impl BallHalfNode {
11    pub fn new() -> Self {
12        Self::with_config(BallHalfCalculatorConfig::default())
13    }
14
15    pub fn with_config(config: BallHalfCalculatorConfig) -> Self {
16        Self {
17            calculator: BallHalfCalculator::with_config(config),
18        }
19    }
20}
21
22impl Default for BallHalfNode {
23    fn default() -> Self {
24        Self::new()
25    }
26}
27
28impl AnalysisNode for BallHalfNode {
29    type State = BallHalfCalculator;
30
31    fn name(&self) -> &'static str {
32        "ball_half"
33    }
34
35    fn emitted_events(&self) -> &'static [crate::stats::calculators::EmittedEvent] {
36        crate::stats::calculators::BALL_HALF_EMITTED_EVENTS
37    }
38
39    fn dependencies(&self) -> NodeDependencies {
40        vec![
41            frame_info_dependency(),
42            ball_frame_state_dependency(),
43            live_play_dependency(),
44        ]
45    }
46
47    fn evaluate(&mut self, ctx: &AnalysisStateContext<'_>) -> SubtrActorResult<()> {
48        self.calculator.update(
49            ctx.get::<FrameInfo>()?,
50            ctx.get::<BallFrameState>()?,
51            ctx.get::<LivePlayState>()?,
52        )
53    }
54
55    fn finish(&mut self, _ctx: &AnalysisStateContext<'_>) -> SubtrActorResult<()> {
56        self.calculator.flush_pending_event();
57        Ok(())
58    }
59
60    fn state(&self) -> &Self::State {
61        &self.calculator
62    }
63}
64
65pub(crate) fn boxed_default() -> Box<dyn AnalysisNodeDyn> {
66    Box::new(BallHalfNode::new())
67}