subtr_actor/stats/analysis_graph/
collector.rs1use super::graph::AnalysisGraph;
2use crate::stats::calculators::FrameInput;
3use crate::*;
4
5#[allow(dead_code)]
6pub struct AnalysisNodeCollector {
7 graph: AnalysisGraph,
8 last_sample_time: Option<f32>,
9 replay_meta_initialized: bool,
10 last_demolish_count: usize,
11 last_boost_pad_event_count: usize,
12 last_touch_event_count: usize,
13 last_player_stat_event_count: usize,
14 last_goal_event_count: usize,
15}
16
17#[allow(dead_code)]
18impl AnalysisNodeCollector {
19 pub fn new(mut graph: AnalysisGraph) -> Self {
20 graph.register_input_state::<FrameInput>();
21 Self {
22 graph,
23 last_sample_time: None,
24 replay_meta_initialized: false,
25 last_demolish_count: 0,
26 last_boost_pad_event_count: 0,
27 last_touch_event_count: 0,
28 last_player_stat_event_count: 0,
29 last_goal_event_count: 0,
30 }
31 }
32
33 pub fn graph(&self) -> &AnalysisGraph {
34 &self.graph
35 }
36
37 pub fn graph_mut(&mut self) -> &mut AnalysisGraph {
38 &mut self.graph
39 }
40
41 pub fn into_graph(self) -> AnalysisGraph {
42 self.graph
43 }
44}
45
46impl Collector for AnalysisNodeCollector {
47 fn process_frame(
48 &mut self,
49 processor: &ReplayProcessor,
50 _frame: &boxcars::Frame,
51 frame_number: usize,
52 current_time: f32,
53 ) -> SubtrActorResult<TimeAdvance> {
54 if !self.replay_meta_initialized {
55 self.graph.on_replay_meta(&processor.get_replay_meta()?)?;
56 self.replay_meta_initialized = true;
57 }
58
59 let dt = self
60 .last_sample_time
61 .map(|last_time| (current_time - last_time).max(0.0))
62 .unwrap_or(0.0);
63 let frame_input = FrameInput::aggregate(
64 processor,
65 frame_number,
66 current_time,
67 dt,
68 self.last_demolish_count,
69 self.last_boost_pad_event_count,
70 self.last_touch_event_count,
71 self.last_player_stat_event_count,
72 self.last_goal_event_count,
73 );
74 self.graph.evaluate_with_state(&frame_input)?;
75 self.last_sample_time = Some(current_time);
76 self.last_demolish_count = processor.demolishes.len();
77 self.last_boost_pad_event_count = processor.boost_pad_events.len();
78 self.last_touch_event_count = processor.touch_events.len();
79 self.last_player_stat_event_count = processor.player_stat_events.len();
80 self.last_goal_event_count = processor.goal_events.len();
81
82 Ok(TimeAdvance::NextFrame)
83 }
84
85 fn finish_replay(&mut self, _processor: &ReplayProcessor) -> SubtrActorResult<()> {
86 self.graph.finish()
87 }
88}