Skip to main content

subtr_actor/stats/analysis_graph/nodes/
touch.rs

1use super::*;
2use crate::stats::calculators::*;
3use crate::*;
4
5/// Classifies ball touches (with rotation/possession/50-50/vertical context) into touch events/stats.
6pub struct TouchNode {
7    calculator: TouchCalculator,
8}
9
10impl TouchNode {
11    pub fn new() -> Self {
12        Self {
13            calculator: TouchCalculator::new(),
14        }
15    }
16}
17
18impl Default for TouchNode {
19    fn default() -> Self {
20        Self::new()
21    }
22}
23
24impl AnalysisNode for TouchNode {
25    type State = TouchCalculator;
26
27    fn name(&self) -> &'static str {
28        "touch"
29    }
30
31    fn emitted_events(&self) -> &'static [crate::stats::calculators::EmittedEvent] {
32        crate::stats::calculators::TOUCH_EMITTED_EVENTS
33    }
34
35    fn dependencies(&self) -> NodeDependencies {
36        vec![
37            frame_info_dependency(),
38            ball_frame_state_dependency(),
39            player_frame_state_dependency(),
40            player_vertical_state_dependency(),
41            rotation_dependency(),
42            touch_state_dependency(),
43            possession_state_dependency(),
44            fifty_fifty_state_dependency(),
45            frame_events_state_dependency(),
46            live_play_dependency(),
47        ]
48    }
49
50    fn evaluate(&mut self, ctx: &AnalysisStateContext<'_>) -> SubtrActorResult<()> {
51        let touch_state = ctx.get::<TouchState>()?;
52        self.calculator.update(
53            ctx.get::<FrameInfo>()?,
54            ctx.get::<BallFrameState>()?,
55            ctx.get::<PlayerFrameState>()?,
56            ctx.get::<PlayerVerticalState>()?,
57            ctx.get::<RotationCalculator>()?,
58            touch_state,
59            ctx.get::<PossessionState>()?,
60            ctx.get::<FiftyFiftyState>()?,
61            ctx.get::<FrameEventsState>()?,
62            ctx.get::<LivePlayState>()?,
63        )
64    }
65
66    fn finish(&mut self, _ctx: &AnalysisStateContext<'_>) -> SubtrActorResult<()> {
67        self.calculator.finish();
68        Ok(())
69    }
70
71    fn state(&self) -> &Self::State {
72        &self.calculator
73    }
74}
75
76pub(crate) fn boxed_default() -> Box<dyn AnalysisNodeDyn> {
77    Box::new(TouchNode::new())
78}