From 1f492c520c64e1e434aa22facab726bfc84d213c Mon Sep 17 00:00:00 2001 From: catvayor Date: Wed, 11 Sep 2024 14:50:47 +0200 Subject: [PATCH] send last_update --- src/coords.rs | 12 ++++++++++++ src/global.rs | 3 ++- src/main.rs | 2 ++ templates/admin.html.hbs | 17 ++++++++++------- templates/conscrit.html.hbs | 8 +++++--- 5 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/coords.rs b/src/coords.rs index 44cb3c7..fc3eff2 100644 --- a/src/coords.rs +++ b/src/coords.rs @@ -17,6 +17,7 @@ pub fn admin_view(team: &Tracked) -> AdminTrackedInfo { pos: team.pos, color: team.state.admin_color(), state: team.state.clone(), + last_pos: team.last_coord.elapsed() } } @@ -83,3 +84,14 @@ pub fn send_coords(tracking: &Tracking, evt_queue: &TrackingEventQueue, config: ); } } + +pub fn send_admin_coords(tracking: &Tracking, admin_queue: &AdminEventQueue) { + let full_info: Vec = tracking + .iter() + .map(|(_, tracked)| admin_view(&tracked.read().unwrap())) + .collect(); + admin_queue + .write() + .unwrap() + .push_back(Event::json(&full_info).event("full_update").into()); +} diff --git a/src/global.rs b/src/global.rs index ac624d3..f5a628b 100644 --- a/src/global.rs +++ b/src/global.rs @@ -124,7 +124,7 @@ pub fn build_conscrit(id: String, name: String) -> Tracked { blurred: false, captured: false, mallette: false, - invisibility_codes: 0, + invisibility_codes: 1, blur_codes: 0, }, last_coord: Instant::now(), @@ -189,6 +189,7 @@ pub struct AdminTrackedInfo { pub pos: (f32, f32), pub color: u8, pub state: TrackedState, + pub last_pos: Duration, } impl From for TrackedInfo { diff --git a/src/main.rs b/src/main.rs index 654c74f..61057b4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -122,10 +122,12 @@ async fn rocket() -> _ { tokio::spawn(async move { let mut clean_interval = time::interval(5 * Duration::from_millis(config.event_timeout)); let mut coord_interval = time::interval(Duration::from_millis(3000)); + let mut admin_interval = time::interval(Duration::from_millis(1000)); loop { select! { _ = coord_interval.tick() => send_coords(&tracking, &evt_queue, &config), _ = clean_interval.tick() => clean_expired_evt(&evt_queue, &admin_evt_queue, &config), + _ = admin_interval.tick() => send_admin_coords(&tracking, &admin_evt_queue), } } }); diff --git a/templates/admin.html.hbs b/templates/admin.html.hbs index 205f779..c1565f9 100644 --- a/templates/admin.html.hbs +++ b/templates/admin.html.hbs @@ -50,6 +50,7 @@ + @@ -57,7 +58,6 @@ - @@ -156,6 +156,7 @@ document.getElementById(`${id}.bonus.invisi`).value = state.invisibility_codes; document.getElementById(`${id}.bonus.blurred`).value = state.blur_codes; } + document.getElementById(`${id}.elapsed`).innerHTML = equipe.last_pos.secs + " sec"; equipes_markers[id].setLatLng(equipe.pos); equipes_markers[id].setIcon((id == bigTeam ? big_icons : icons)[equipe.color]); } @@ -177,6 +178,7 @@ var row = ""; if("Vieux" in data.state){ row = ``; + row += ``; row += ``; row += ``; row += ``; } else { row = ``; + row += ``; row += `` @@ -244,12 +247,12 @@ }); evtSource.addEventListener("full_update", (event) => { data = JSON.parse(event.data); - info_table.innerHTML = ""; - equipes = {}; - for(i in equipes_markers){ - equipes_markers[i].remove(); - } - equipes_markers = {}; + // info_table.innerHTML = ""; + // equipes = {}; + // for(i in equipes_markers){ + // equipes_markers[i].remove(); + // } + // equipes_markers = {}; for (tracked of data) { update(tracked); } diff --git a/templates/conscrit.html.hbs b/templates/conscrit.html.hbs index 428d396..9c8e290 100644 --- a/templates/conscrit.html.hbs +++ b/templates/conscrit.html.hbs @@ -15,7 +15,7 @@
NomLast Update Mallette Tracker InvisibleCode Invisibilité Code Brouillage Couleur
${data.name}${data.name}