fairness localisation

This commit is contained in:
catvayor 2024-09-04 12:50:55 +02:00
parent 1706f2ac78
commit 57f64ad046
Signed by: lbailly
GPG key ID: CE3E645251AC63F3
4 changed files with 10 additions and 1 deletions

View file

@ -4,6 +4,7 @@ bonus_timeout = 5000
event_timeout = 100 event_timeout = 100
admin_token = "root" admin_token = "root"
serve_static = true serve_static = true
fairness_timeout = 10000
teams = [ teams = [
{ id = "team00", name = "Équipe 00", vieux = false}, { id = "team00", name = "Équipe 00", vieux = false},
{ id = "team01", name = "Équipe 01", vieux = false}, { id = "team01", name = "Équipe 01", vieux = false},

View file

@ -26,6 +26,7 @@ pub struct Config {
pub admin_token: String, pub admin_token: String,
pub teams: Vec<TeamConfig>, pub teams: Vec<TeamConfig>,
pub serve_static: bool, pub serve_static: bool,
pub fairness_timeout: u64,
} }
#[derive(Serialize, Deserialize, Clone)] #[derive(Serialize, Deserialize, Clone)]
@ -114,6 +115,7 @@ pub struct Tracked {
pub name: String, pub name: String,
pub pos: (f32, f32), pub pos: (f32, f32),
pub state: TrackedState, pub state: TrackedState,
pub last_coord: Instant,
} }
pub fn build_conscrit(id: String, name: String) -> Tracked { 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, invisibility_codes: 0,
blur_codes: 0, blur_codes: 0,
}, },
last_coord: Instant::now(),
} }
} }
@ -141,6 +144,7 @@ pub fn build_vieux(id: String, name: String) -> Tracked {
invisible: true, invisible: true,
color: 1, color: 1,
}, },
last_coord: Instant::now(),
} }
} }

View file

@ -31,6 +31,9 @@ fn index() -> &'static str {
fn send_coords(tracking: &Tracking, evt_queue: &TrackingEventQueue, config: &Config) { fn send_coords(tracking: &Tracking, evt_queue: &TrackingEventQueue, config: &Config) {
for (id, queue) in evt_queue.iter() { for (id, queue) in evt_queue.iter() {
let watcher = tracking.get(id).unwrap().read().unwrap(); let watcher = tracking.get(id).unwrap().read().unwrap();
if watcher.last_coord.elapsed() > Duration::from_millis(config.fairness_timeout) {
continue
}
let mut infos: Vec<TrackedInfo> = Vec::new(); let mut infos: Vec<TrackedInfo> = Vec::new();
for (_, tracked) in tracking.iter() { for (_, tracked) in tracking.iter() {
if let Some(info) = if let Some(info) =

View file

@ -3,7 +3,7 @@ use rocket::{
response::stream::{Event, EventStream}, response::stream::{Event, EventStream},
tokio::{ tokio::{
self, select, self, select,
time::{self, sleep, Duration}, time::{self, sleep, Duration, Instant},
}, },
Route, Shutdown, State, Route, Shutdown, State,
}; };
@ -80,6 +80,7 @@ fn store_pos(
) -> Status { ) -> Status {
if let Some(tracked) = tracking.get(&id.to_string()) { if let Some(tracked) = tracking.get(&id.to_string()) {
tracked.write().unwrap().pos = (lat, long); tracked.write().unwrap().pos = (lat, long);
tracked.write().unwrap().last_coord = Instant::now();
state_update(&tracked.read().unwrap(), &evt_queues, &admin_queue); state_update(&tracked.read().unwrap(), &evt_queues, &admin_queue);
Status::Accepted Status::Accepted
} else { } else {