csv writing
This commit is contained in:
parent
9aaff38d96
commit
601eb8d942
|
@ -33,6 +33,7 @@ def main():
|
||||||
config = json.load(open(args.config, 'r'))
|
config = json.load(open(args.config, 'r'))
|
||||||
for region in config['ocr_regions']:
|
for region in config['ocr_regions']:
|
||||||
scale_region(region, from_resolution, to_resolution)
|
scale_region(region, from_resolution, to_resolution)
|
||||||
|
scale_region(config['track_region'], from_resolution, to_resolution)
|
||||||
print(json.dumps(config, indent=4))
|
print(json.dumps(config, indent=4))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ pub struct Config {
|
||||||
pub ocr_server_endpoint: String,
|
pub ocr_server_endpoint: String,
|
||||||
pub filter_threshold: Option<f64>,
|
pub filter_threshold: Option<f64>,
|
||||||
pub use_ocr_cache: Option<bool>,
|
pub use_ocr_cache: Option<bool>,
|
||||||
|
pub ocr_interval_ms: Option<u64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
"ocr_regions": [
|
"ocr_regions": [
|
||||||
{
|
{
|
||||||
"name": "lap",
|
"name": "lap",
|
||||||
"x": 2290,
|
"x": 2300,
|
||||||
"y": 46,
|
"y": 46,
|
||||||
"width": 145,
|
"width": 145,
|
||||||
"height": 90
|
"height": 90
|
||||||
|
@ -43,5 +43,13 @@
|
||||||
"height": 43
|
"height": 43
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
"track_region": {
|
||||||
|
"name": "track",
|
||||||
|
"x": 2020,
|
||||||
|
"y": 1030,
|
||||||
|
"width": 540,
|
||||||
|
"height": 410,
|
||||||
|
"threshold": 0.85
|
||||||
|
},
|
||||||
"ocr_server_endpoint": "https://tesserver.spruett.dev/"
|
"ocr_server_endpoint": "https://tesserver.spruett.dev/"
|
||||||
}
|
}
|
|
@ -13,7 +13,7 @@ use crate::{
|
||||||
capture,
|
capture,
|
||||||
image_processing::{self, hash_image, Region, extract_and_filter},
|
image_processing::{self, hash_image, Region, extract_and_filter},
|
||||||
ocr,
|
ocr,
|
||||||
state::{AppState, DebugOcrFrame, ParsedFrame, RaceState, SharedAppState}, config::Config,
|
state::{AppState, DebugOcrFrame, ParsedFrame, RaceState, SharedAppState},
|
||||||
};
|
};
|
||||||
|
|
||||||
fn is_finished_lap(state: &AppState, frame: &ParsedFrame) -> bool {
|
fn is_finished_lap(state: &AppState, frame: &ParsedFrame) -> bool {
|
||||||
|
@ -172,6 +172,6 @@ pub fn run_control_loop(state: SharedAppState) {
|
||||||
if let Err(e) = run_loop_once(&mut capturer, &state) {
|
if let Err(e) = run_loop_once(&mut capturer, &state) {
|
||||||
eprintln!("Error in control loop: {:?}", e)
|
eprintln!("Error in control loop: {:?}", e)
|
||||||
}
|
}
|
||||||
thread::sleep(Duration::from_millis(500));
|
thread::sleep(Duration::from_millis(state.lock().unwrap().config.ocr_interval_ms.unwrap_or(500)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use image::{codecs::png::PngEncoder, ColorType, ImageEncoder, Rgb, RgbImage};
|
use image::{codecs::png::PngEncoder, ColorType, ImageEncoder, Rgb, RgbImage};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::config::Config;
|
|
||||||
|
|
||||||
#[derive(Clone, Deserialize, Serialize)]
|
#[derive(Clone, Deserialize, Serialize)]
|
||||||
pub struct Region {
|
pub struct Region {
|
||||||
|
|
|
@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::{Config, LearnedConfig},
|
config::{Config, LearnedConfig},
|
||||||
image_processing::{extract_region, filter_to_white, hash_image, extract_and_filter},
|
image_processing::{hash_image, extract_and_filter},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
|
13
src/state.rs
13
src/state.rs
|
@ -2,6 +2,7 @@ use std::{sync::{Arc, Mutex, RwLock}, time::{Duration, Instant, SystemTime}, col
|
||||||
|
|
||||||
use egui_extras::RetainedImage;
|
use egui_extras::RetainedImage;
|
||||||
use image::RgbImage;
|
use image::RgbImage;
|
||||||
|
use time::{OffsetDateTime, format_description};
|
||||||
|
|
||||||
use crate::config::{Config, LearnedConfig};
|
use crate::config::{Config, LearnedConfig};
|
||||||
|
|
||||||
|
@ -72,6 +73,18 @@ pub struct RaceState {
|
||||||
pub track: String,
|
pub track: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl RaceState {
|
||||||
|
pub fn name(&self) -> String {
|
||||||
|
let race_time = self.race_time.unwrap_or_else(SystemTime::now);
|
||||||
|
let race_time: OffsetDateTime = race_time.into();
|
||||||
|
let mut name = race_time.format(&format_description::parse("[year]-[month]-[day]-[hour]:[minute]").unwrap()).unwrap();
|
||||||
|
if !self.track.is_empty() {
|
||||||
|
name += &format!(" ({})", self.track);
|
||||||
|
}
|
||||||
|
name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct DebugOcrFrame {
|
pub struct DebugOcrFrame {
|
||||||
pub image: RetainedImage,
|
pub image: RetainedImage,
|
||||||
pub rgb_image: RgbImage,
|
pub rgb_image: RgbImage,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::{
|
use std::{
|
||||||
io::BufWriter,
|
io::BufWriter,
|
||||||
time::{Duration, Instant, SystemTime},
|
time::{Duration, SystemTime},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::state::RaceState;
|
use crate::state::RaceState;
|
||||||
|
@ -9,9 +9,7 @@ use anyhow::Result;
|
||||||
use time::{OffsetDateTime, format_description};
|
use time::{OffsetDateTime, format_description};
|
||||||
|
|
||||||
pub fn export_race_stats(race_stats: &mut RaceState) -> Result<()> {
|
pub fn export_race_stats(race_stats: &mut RaceState) -> Result<()> {
|
||||||
let race_time = race_stats.race_time.unwrap_or_else(|| SystemTime::now());
|
let race_name = race_stats.name();
|
||||||
let race_time: OffsetDateTime = race_time.into();
|
|
||||||
let race_time: String = race_time.format(&format_description::parse("[year]-[month]-[day]-[hour]:[minute]")?)?;
|
|
||||||
|
|
||||||
let file = std::fs::OpenOptions::new()
|
let file = std::fs::OpenOptions::new()
|
||||||
.create(true)
|
.create(true)
|
||||||
|
@ -22,7 +20,7 @@ pub fn export_race_stats(race_stats: &mut RaceState) -> Result<()> {
|
||||||
|
|
||||||
for lap in &race_stats.laps {
|
for lap in &race_stats.laps {
|
||||||
csv_writer.write_record(vec![
|
csv_writer.write_record(vec![
|
||||||
race_time.clone(),
|
race_name.clone(),
|
||||||
race_stats.track.clone(),
|
race_stats.track.clone(),
|
||||||
race_stats.car.clone(),
|
race_stats.car.clone(),
|
||||||
lap.lap
|
lap.lap
|
||||||
|
|
Loading…
Reference in New Issue