From 57f64ad046bb980bbcac24b2cbc6ad382b806dc5 Mon Sep 17 00:00:00 2001 From: catvayor Date: Wed, 4 Sep 2024 12:50:55 +0200 Subject: [PATCH] fairness localisation --- Rocket.toml | 1 + src/global.rs | 4 ++++ src/main.rs | 3 +++ src/track.rs | 3 ++- 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Rocket.toml b/Rocket.toml index 8fb93dc..a94d81b 100644 --- a/Rocket.toml +++ b/Rocket.toml @@ -4,6 +4,7 @@ bonus_timeout = 5000 event_timeout = 100 admin_token = "root" serve_static = true +fairness_timeout = 10000 teams = [ { id = "team00", name = "Équipe 00", vieux = false}, { id = "team01", name = "Équipe 01", vieux = false}, diff --git a/src/global.rs b/src/global.rs index a9725fa..0539e12 100644 --- a/src/global.rs +++ b/src/global.rs @@ -26,6 +26,7 @@ pub struct Config { pub admin_token: String, pub teams: Vec, pub serve_static: bool, + pub fairness_timeout: u64, } #[derive(Serialize, Deserialize, Clone)] @@ -114,6 +115,7 @@ pub struct Tracked { pub name: String, pub pos: (f32, f32), pub state: TrackedState, + pub last_coord: Instant, } pub fn build_conscrit(id: String, name: String) -> Tracked { @@ -129,6 +131,7 @@ pub fn build_conscrit(id: String, name: String) -> Tracked { invisibility_codes: 0, blur_codes: 0, }, + last_coord: Instant::now(), } } @@ -141,6 +144,7 @@ pub fn build_vieux(id: String, name: String) -> Tracked { invisible: true, color: 1, }, + last_coord: Instant::now(), } } diff --git a/src/main.rs b/src/main.rs index c9da8df..6976aeb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,6 +31,9 @@ fn index() -> &'static str { fn send_coords(tracking: &Tracking, evt_queue: &TrackingEventQueue, config: &Config) { for (id, queue) in evt_queue.iter() { let watcher = tracking.get(id).unwrap().read().unwrap(); + if watcher.last_coord.elapsed() > Duration::from_millis(config.fairness_timeout) { + continue + } let mut infos: Vec = Vec::new(); for (_, tracked) in tracking.iter() { if let Some(info) = diff --git a/src/track.rs b/src/track.rs index b246e79..4b35d6c 100644 --- a/src/track.rs +++ b/src/track.rs @@ -3,7 +3,7 @@ use rocket::{ response::stream::{Event, EventStream}, tokio::{ self, select, - time::{self, sleep, Duration}, + time::{self, sleep, Duration, Instant}, }, Route, Shutdown, State, }; @@ -80,6 +80,7 @@ fn store_pos( ) -> Status { if let Some(tracked) = tracking.get(&id.to_string()) { tracked.write().unwrap().pos = (lat, long); + tracked.write().unwrap().last_coord = Instant::now(); state_update(&tracked.read().unwrap(), &evt_queues, &admin_queue); Status::Accepted } else {