subtr_actor/processor/
debug.rs1use super::*;
2
3impl<'a> ReplayProcessor<'a> {
4 pub fn map_attribute_keys(
6 &self,
7 hash_map: &HashMap<boxcars::ObjectId, (boxcars::Attribute, usize)>,
8 ) -> HashMap<String, boxcars::Attribute> {
9 hash_map
10 .iter()
11 .map(|(k, (v, _updated))| {
12 self.object_id_to_name
13 .get(k)
14 .map(|name| (name.clone(), v.clone()))
15 .unwrap()
16 })
17 .collect()
18 }
19
20 pub fn all_mappings_string(&self) -> String {
22 let pairs = [
23 ("player_to_car", &self.player_to_car),
24 ("player_to_team", &self.player_to_team),
25 ("car_to_player", &self.car_to_player),
26 ("car_to_boost", &self.car_to_boost),
27 ("car_to_jump", &self.car_to_jump),
28 ("car_to_double_jump", &self.car_to_double_jump),
29 ("car_to_dodge", &self.car_to_dodge),
30 ];
31 let mut strings: Vec<_> = pairs
32 .iter()
33 .map(|(map_name, map)| format!("{map_name:?}: {map:?}"))
34 .collect();
35 strings.push(format!("name_to_object_id: {:?}", &self.name_to_object_id));
36 strings.join("\n")
37 }
38
39 pub fn actor_state_string(&self, actor_id: &boxcars::ActorId) -> String {
41 match self.get_actor_state(actor_id) {
42 Ok(actor_state) => {
43 format!("{:?}", self.map_attribute_keys(&actor_state.attributes))
44 }
45 _ => String::from("error"),
46 }
47 }
48
49 pub fn print_actors_by_id<'b>(&self, actor_ids: impl Iterator<Item = &'b boxcars::ActorId>) {
51 actor_ids.for_each(|actor_id| {
52 let state = self.get_actor_state(actor_id).unwrap();
53 println!(
54 "{:?}\n\n\n",
55 self.object_id_to_name.get(&state.object_id).unwrap()
56 );
57 println!("{:?}", self.map_attribute_keys(&state.attributes))
58 })
59 }
60
61 pub fn print_actors_of_type(&self, actor_type: &'static str) {
63 self.iter_actors_by_type(actor_type)
64 .unwrap()
65 .for_each(|(_actor_id, state)| {
66 log::debug!("{:?}", self.map_attribute_keys(&state.attributes));
67 });
68 }
69
70 pub fn print_actor_types(&self) {
72 let types: Vec<_> = self
73 .actor_state
74 .actor_ids_by_type
75 .keys()
76 .filter_map(|id| self.object_id_to_name.get(id))
77 .collect();
78 log::debug!("{types:?}");
79 }
80
81 pub fn print_all_actors(&self) {
83 self.actor_state
84 .actor_states
85 .iter()
86 .for_each(|(actor_id, actor_state)| {
87 log::debug!(
88 "{}: {:?}",
89 self.object_id_to_name
90 .get(&actor_state.object_id)
91 .unwrap_or(&String::from("unknown")),
92 self.actor_state_string(actor_id)
93 )
94 });
95 }
96}