Skip to main content

subtr_actor/stats/analysis_graph/nodes/
match_stats.rs

1use super::*;
2use crate::stats::calculators::*;
3use crate::*;
4
5pub struct MatchStatsNode {
6    calculator: MatchStatsCalculator,
7}
8
9impl MatchStatsNode {
10    pub fn new() -> Self {
11        Self {
12            calculator: MatchStatsCalculator::new(),
13        }
14    }
15}
16
17impl Default for MatchStatsNode {
18    fn default() -> Self {
19        Self::new()
20    }
21}
22
23impl AnalysisNode for MatchStatsNode {
24    type State = MatchStatsCalculator;
25
26    fn name(&self) -> &'static str {
27        "match_stats"
28    }
29
30    fn dependencies(&self) -> Vec<AnalysisDependency> {
31        vec![
32            frame_info_dependency(),
33            gameplay_state_dependency(),
34            ball_frame_state_dependency(),
35            player_frame_state_dependency(),
36            frame_events_state_dependency(),
37            live_play_dependency(),
38            touch_state_dependency(),
39            // Not consumed per-frame; needed at finish to attach per-goal pressure.
40            territorial_pressure_dependency(),
41        ]
42    }
43
44    fn evaluate(&mut self, ctx: &AnalysisStateContext<'_>) -> SubtrActorResult<()> {
45        self.calculator.update_parts(
46            ctx.get::<FrameInfo>()?,
47            ctx.get::<GameplayState>()?,
48            ctx.get::<BallFrameState>()?,
49            ctx.get::<PlayerFrameState>()?,
50            ctx.get::<FrameEventsState>()?,
51            ctx.get::<LivePlayState>()?,
52            ctx.get::<TouchState>()?,
53        )
54    }
55
56    fn finish(&mut self, ctx: &AnalysisStateContext<'_>) -> SubtrActorResult<()> {
57        // Finalize goal contexts first, then attach pressure duration from the
58        // now-final territorial-pressure sessions.
59        self.calculator.finish()?;
60        let territorial_pressure = ctx.get::<TerritorialPressureCalculator>()?;
61        self.calculator
62            .attach_goal_pressure_durations(&territorial_pressure.projected_events());
63        Ok(())
64    }
65
66    fn state(&self) -> &Self::State {
67        &self.calculator
68    }
69}
70
71pub(crate) fn boxed_default() -> Box<dyn AnalysisNodeDyn> {
72    Box::new(MatchStatsNode::new())
73}