Skip to main content

supreme_replay_analyzer/
models.rs

1//! Data models for replay analysis
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
5pub struct Position {
6    pub x: f32,
7    pub y: f32,
8    pub z: f32,
9}
10
11#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
12pub struct Quaternion {
13    pub x: f32,
14    pub y: f32,
15    pub z: f32,
16    pub w: f32,
17}
18
19#[derive(Debug, Clone, Serialize, Deserialize)]
20pub struct LevelDataEntry {
21    pub name: String,
22    pub uniform_scale: f32,
23    pub position: Position,
24    pub quat: Quaternion,
25}
26
27#[derive(Debug, Clone, Serialize, Deserialize)]
28pub struct Level {
29    pub name: String,
30    pub entries: Vec<LevelDataEntry>,
31}
32
33#[derive(Debug, Clone, Serialize, Deserialize)]
34pub struct RowData {
35    pub x: f32,
36    pub y: f32,
37    pub z: f32,
38}
39
40#[derive(Debug, Clone, Serialize, Deserialize)]
41pub struct CoordinateData {
42    pub rows: Vec<RowData>,
43}
44
45#[derive(Debug, Clone, Serialize, Deserialize)]
46pub struct CheckpointTimesComputed {
47    pub start_computed: Option<f32>,
48    pub cp1_computed: Option<f32>,
49    pub cp2_computed: Option<f32>,
50    pub finish_computed: Option<f32>,
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
54pub struct AnalyzeResult {
55    pub player_name: String,
56    pub track_name: Option<String>,
57    pub displayed_ms: f32,
58    pub start_ms: f32,
59    pub total_ms: f32,
60    pub lag_start_ms: f32,
61    pub lag_finish_ms: f32,
62    pub recording_ms: f32,
63    pub checkpoint1_ms: f32,
64    pub coords: Option<CoordinateData>,
65    pub checkpoint_times: Option<CheckpointTimesComputed>,
66}
67
68impl AnalyzeResult {
69    #[must_use]
70    pub fn format_display(&self) -> String {
71        let track_info = if let Some(ref track) = self.track_name {
72            format!("Track: {track}\n\n")
73        } else {
74            String::new()
75        };
76
77        format!(
78            "Player: {}\n\n{track_info}
79Timing Data:\n- Displayed Time: {:.2}s\n- Start Time: {:.2}s\n- Total Time: {:.2}s\n- Checkpoint 1: {:.2}s\n\nRecording Info:\n- Recording Duration: {:.2}s\n- Lag Before Start: {:.2}s\n- Lag After Finish: {:.2}s",
80            self.player_name,
81            self.displayed_ms / 1000.0,
82            self.start_ms / 1000.0,
83            self.total_ms / 1000.0,
84            self.checkpoint1_ms / 1000.0,
85            self.recording_ms / 1000.0,
86            self.lag_start_ms / 1000.0,
87            self.lag_finish_ms / 1000.0
88        )
89    }
90}