Skip to main content

subtr_actor/stats/analysis_graph/nodes/
player_possession.rs

1use super::*;
2use crate::stats::calculators::*;
3use crate::*;
4
5/// Tracks per-player possession from ball/player/possession/touch state.
6pub struct PlayerPossessionNode {
7    calculator: PlayerPossessionCalculator,
8}
9
10impl PlayerPossessionNode {
11    pub fn new() -> Self {
12        Self {
13            calculator: PlayerPossessionCalculator::new(),
14        }
15    }
16}
17
18impl Default for PlayerPossessionNode {
19    fn default() -> Self {
20        Self::new()
21    }
22}
23
24impl AnalysisNode for PlayerPossessionNode {
25    type State = PlayerPossessionCalculator;
26
27    fn name(&self) -> &'static str {
28        "player_possession"
29    }
30
31    fn emitted_events(&self) -> &'static [crate::stats::calculators::EmittedEvent] {
32        crate::stats::calculators::PLAYER_POSSESSION_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            possession_state_dependency(),
41            touch_state_dependency(),
42            live_play_dependency(),
43        ]
44    }
45
46    fn evaluate(&mut self, ctx: &AnalysisStateContext<'_>) -> SubtrActorResult<()> {
47        self.calculator.update(
48            ctx.get::<FrameInfo>()?,
49            ctx.get::<BallFrameState>()?,
50            ctx.get::<PlayerFrameState>()?,
51            ctx.get::<PossessionState>()?,
52            ctx.get::<TouchState>()?,
53            ctx.get::<LivePlayState>()?,
54        )
55    }
56
57    fn finish(&mut self, _ctx: &AnalysisStateContext<'_>) -> SubtrActorResult<()> {
58        self.calculator.finish();
59        Ok(())
60    }
61
62    fn state(&self) -> &Self::State {
63        &self.calculator
64    }
65}
66
67pub(crate) fn boxed_default() -> Box<dyn AnalysisNodeDyn> {
68    Box::new(PlayerPossessionNode::new())
69}