subtr_actor/stats/analysis_graph/nodes/
ball_third.rs1use super::*;
2use crate::stats::calculators::*;
3use crate::*;
4
5pub struct BallThirdNode {
6 calculator: BallThirdCalculator,
7}
8
9impl BallThirdNode {
10 pub fn new() -> Self {
11 Self::with_config(BallThirdCalculatorConfig::default())
12 }
13
14 pub fn with_config(config: BallThirdCalculatorConfig) -> Self {
15 Self {
16 calculator: BallThirdCalculator::with_config(config),
17 }
18 }
19}
20
21impl Default for BallThirdNode {
22 fn default() -> Self {
23 Self::new()
24 }
25}
26
27impl AnalysisNode for BallThirdNode {
28 type State = BallThirdCalculator;
29
30 fn name(&self) -> &'static str {
31 "ball_third"
32 }
33
34 fn emitted_events(&self) -> &'static [crate::stats::calculators::EmittedEvent] {
35 crate::stats::calculators::BALL_THIRD_EMITTED_EVENTS
36 }
37
38 fn dependencies(&self) -> NodeDependencies {
39 vec![
40 frame_info_dependency(),
41 ball_frame_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::<LivePlayState>()?,
51 )
52 }
53
54 fn finish(&mut self, _ctx: &AnalysisStateContext<'_>) -> SubtrActorResult<()> {
55 self.calculator.flush_pending_event();
56 Ok(())
57 }
58
59 fn state(&self) -> &Self::State {
60 &self.calculator
61 }
62}
63
64pub(crate) fn boxed_default() -> Box<dyn AnalysisNodeDyn> {
65 Box::new(BallThirdNode::new())
66}