Skip to main content

subtr_actor/stats/analysis_graph/nodes/
stats_timeline_events.rs

1use super::*;
2use crate::stats::calculators::*;
3use crate::*;
4
5#[derive(Debug, Clone, Default)]
6pub struct StatsTimelineEventsState {
7    pub events: ReplayStatsTimelineEvents,
8}
9
10pub struct StatsTimelineEventsNode {
11    state: StatsTimelineEventsState,
12}
13
14impl StatsTimelineEventsNode {
15    pub fn new() -> Self {
16        Self {
17            state: StatsTimelineEventsState::default(),
18        }
19    }
20}
21
22impl_analysis_node! {
23    node = StatsTimelineEventsNode,
24    state = StatsTimelineEventsState,
25    name = "stats_timeline_events",
26    dependencies = [
27        match_stats_dependency(),
28        demo_dependency(),
29        backboard_dependency(),
30        ceiling_shot_dependency(),
31        double_tap_dependency(),
32        fifty_fifty_dependency(),
33        rush_dependency(),
34        speed_flip_dependency(),
35    ],
36    inputs = {
37        match_stats: MatchStatsCalculator,
38        demo: DemoCalculator,
39        backboard: BackboardCalculator,
40        ceiling_shot: CeilingShotCalculator,
41        double_tap: DoubleTapCalculator,
42        fifty_fifty: FiftyFiftyCalculator,
43        rush: RushCalculator,
44        speed_flip: SpeedFlipCalculator,
45    },
46    evaluate = |node| {
47        let mut timeline = match_stats.timeline().to_vec();
48        timeline.extend(demo.timeline().to_vec());
49        timeline.sort_by(|left, right| left.time.total_cmp(&right.time));
50
51        node.state.events = ReplayStatsTimelineEvents {
52            timeline,
53            backboard: backboard.events().to_vec(),
54            ceiling_shot: ceiling_shot.events().to_vec(),
55            double_tap: double_tap.events().to_vec(),
56            fifty_fifty: fifty_fifty.events().to_vec(),
57            rush: rush.events().to_vec(),
58            speed_flip: speed_flip.events().to_vec(),
59        };
60        Ok(())
61    },
62    state_ref = |node| &node.state,
63}