From 05fca55c73909659bbd05eb57db654cb73db70ec Mon Sep 17 00:00:00 2001 From: Scott Pruett Date: Sun, 5 Jun 2022 15:37:57 -0400 Subject: [PATCH] tracking delta positions --- config.json | 2 +- src/analysis.rs | 3 ++- src/main.rs | 38 ++++++++++++++++++++++++++++++++++---- src/state.rs | 1 + suggestions.md | 3 ++- 5 files changed, 40 insertions(+), 7 deletions(-) diff --git a/config.json b/config.json index 56f9e4e..12d5a21 100644 --- a/config.json +++ b/config.json @@ -91,5 +91,5 @@ "track_recognition_threshold": 10, "dump_frame_fraction": null, "light_mode": false, - "font_scale": 1.3 + "font_scale": 1.2 } \ No newline at end of file diff --git a/src/analysis.rs b/src/analysis.rs index 13d0742..52c3793 100644 --- a/src/analysis.rs +++ b/src/analysis.rs @@ -85,7 +85,7 @@ fn merge_frames(prev: &LapState, next: &LapState) -> LapState { } } fn handle_new_frame(state: &mut AppState, lap_state: LapState, image: &RgbImage) { - if lap_state.lap_time.is_some() { + if lap_state.lap_time.is_some() || (lap_state.lap.is_some() && lap_state.total_laps.is_some()) { state.last_frame = Some(lap_state.clone()); state.frames_without_lap = 0; @@ -109,6 +109,7 @@ fn handle_new_frame(state: &mut AppState, lap_state: LapState, image: &RgbImage) track_hash, track: track_name.unwrap_or_default(), inferred_track, + starting_position: lap_state.position.unwrap_or_default(), total_laps: lap_state.total_laps.unwrap_or_default(), total_positions: lap_state.total_positions.unwrap_or_default(), ..Default::default() diff --git a/src/main.rs b/src/main.rs index 18cffe8..0e2610b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -178,11 +178,19 @@ fn show_race_state( config: &Config, ocr_db: &OcrDatabase, ) { - ui.label(format!("Total laps: {}", race.total_laps)); - ui.label(format!("Total competitors: {}", race.total_positions)); + if race.total_laps > 1 { + ui.label(format!("Laps: {}", race.total_laps)); + } + if race.total_positions > 1 { + ui.label(format!( + "Starting position: {}/{}", + race.starting_position, race.total_positions + )); + } egui::Grid::new(format!("race:{}", race_name)).show(ui, |ui| { ui.label("Lap"); ui.label("Position"); + ui.label("Δ P"); ui.label("Time"); ui.label("Δ Previous"); ui.label("Δ Best"); @@ -198,6 +206,28 @@ fn show_race_state( ui.label(format!("#{}", lap.lap.unwrap_or(i + 1))); ui.label(format!("P{}", lap.position.unwrap_or_default())); + match lap + .position + .unwrap_or_default() + .cmp(&race.starting_position) + { + std::cmp::Ordering::Less => ui.colored_label( + Color32::GREEN, + format!( + "+{}", + race.starting_position - lap.position.unwrap_or_default() + ), + ), + std::cmp::Ordering::Equal => ui.label("--"), + std::cmp::Ordering::Greater => ui.colored_label( + Color32::RED, + format!( + "-{}", + lap.position.unwrap_or_default() - race.starting_position + ), + ), + }; + if Some(lap_time) == fastest_lap { ui.colored_label(Color32::GREEN, format_time(lap_time)); } else { @@ -392,7 +422,7 @@ impl eframe::App for AppUi { ui.separator(); ui.heading("Strategy"); if let Some(tyre_wear) = race.tyre_wear() { - ui.label(&format!("Median Tyre Wear: {}", tyre_wear)); + ui.label(&format!("Tyre Wear: {}", tyre_wear)); if let Some(tyres) = frame.tyres { ui.label(&format!( "Out of tires in {:.1} lap(s)", @@ -401,7 +431,7 @@ impl eframe::App for AppUi { } } if let Some(gas_wear) = race.gas_per_lap() { - ui.label(&format!("Median Gas Wear: {}", gas_wear)); + ui.label(&format!("Gas: {}", gas_wear)); if let Some(gas) = frame.gas { ui.label(&format!( "Out of gas in {:.1} lap(s)", diff --git a/src/state.rs b/src/state.rs index 5a89d26..293287e 100644 --- a/src/state.rs +++ b/src/state.rs @@ -107,6 +107,7 @@ pub struct RaceState { pub laps: Vec, pub last_lap_record_time: Option, + pub starting_position: usize, pub total_laps: usize, pub total_positions: usize, diff --git a/suggestions.md b/suggestions.md index ccbe0be..c55b0c3 100644 --- a/suggestions.md +++ b/suggestions.md @@ -5,7 +5,8 @@ - Autocomplete for car/track - Detect car name from load screen - TTS for pit strategies - - Show delta positions + - Post race metric charts + - [DONE] Show delta positions - [DONE] Track penalties - [DONE] Re-do debug/learn functionality - [DONE] Detect position, max laps