fastest lap in purple and global

This commit is contained in:
Scott Pruett 2022-05-23 22:50:06 -04:00
parent 70ad975866
commit 35415d2724
4 changed files with 20 additions and 3 deletions

View File

@ -52,5 +52,12 @@
"height": 410,
"threshold": 0.85
},
"penalty_orange_region": {
"name": "penalty",
"x": 989,
"y": 117,
"width": 30,
"height": 30
},
"ocr_server_endpoint": "https://tesserver.spruett.dev/"
}

View File

@ -146,13 +146,18 @@ fn show_race_state(
ui.label("Tyres");
ui.end_row();
let mut prev_lap: Option<&LapState> = None;
let fastest_lap = race.fastest_lap();
for (i, lap) in race.laps.iter_mut().enumerate() {
if let Some(lap_time) = lap.lap_time {
ui.label(format!("#{}", lap.lap.unwrap_or(i + 1)));
ui.label(format_time(lap_time));
if Some(lap_time) == fastest_lap {
ui.colored_label(Color32::from_rgb(255, 0, 255), format_time(lap_time));
} else {
ui.label(format_time(lap_time));
};
label_time_delta(ui, lap_time, prev_lap.and_then(|p| p.lap_time));
label_time_delta(ui, lap_time, lap.best_time);
label_time_delta(ui, lap_time, fastest_lap);
show_optional_usize_with_diff(
ui,

View File

@ -89,6 +89,10 @@ impl RaceState {
}
name
}
pub fn fastest_lap(&self) -> Option<Duration> {
self.laps.iter().filter_map(|lap| lap.lap_time.clone()).max()
}
}
pub struct DebugOcrFrame {

View File

@ -18,6 +18,7 @@ pub fn export_race_stats(race_stats: &mut RaceState) -> Result<()> {
let writer = BufWriter::new(file);
let mut csv_writer = csv::Writer::from_writer(writer);
let fastest_lap = race_stats.fastest_lap();
for lap in &race_stats.laps {
if lap.striked {
continue;
@ -36,7 +37,7 @@ pub fn export_race_stats(race_stats: &mut RaceState) -> Result<()> {
),
format!(
"{:.3}",
lap.best_time
fastest_lap
.unwrap_or(Duration::from_secs(0))
.as_secs_f64()
),