send last_update

This commit is contained in:
catvayor 2024-09-11 14:50:47 +02:00
parent 799724b122
commit 1f492c520c
Signed by: lbailly
GPG key ID: CE3E645251AC63F3
5 changed files with 31 additions and 11 deletions

View file

@ -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<AdminTrackedInfo> = tracking
.iter()
.map(|(_, tracked)| admin_view(&tracked.read().unwrap()))
.collect();
admin_queue
.write()
.unwrap()
.push_back(Event::json(&full_info).event("full_update").into());
}

View file

@ -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<AdminTrackedInfo> for TrackedInfo {

View file

@ -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),
}
}
});

View file

@ -50,6 +50,7 @@
<table id="teamTable">
<thead><tr>
<th onclick="sortTeams(0)">Nom</th>
<th>Last Update</th>
<th>Mallette</th>
<th>Tracker</th>
<th>Invisible</th>
@ -57,7 +58,6 @@
<th>Code Invisibilité</th>
<th>Code Brouillage</th>
<th>Couleur</th>
<!-- <th>Last Update</th> -->
</tr></thead>
<tbody id="teamInfos">
</tbody>
@ -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 = `<td class="vieux">${data.name}</td>`;
row += `<td><span id="${id}.elapsed"></span></td>`;
row += `<td></td>`;
row += `<td></td>`;
row += `<td><input type="checkbox"
@ -200,6 +202,7 @@
</select></td>`;
} else {
row = `<td class="conscrit">${data.name}</td>`;
row += `<td><span id="${id}.elapsed"></span></td>`;
row += `<td><input type="checkbox"
id="${id}.mallette"
onchange="modifyConscrit('${id}')" /></td>`
@ -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);
}

View file

@ -15,7 +15,7 @@
<style type="text/css">
#map { height: 600px; }
#codes {
#code-field {
position: fixed;
bottom: 0px;
z-index: 10000;
@ -29,7 +29,7 @@
<body>
<div id="map"></div><br/>
<div id="codes"></div>
<div id="code-field"><span id="nb-codes"></span><span id="codes"></span></div>
<div id="thanks">
<a href="https://dgnum.eu"><img src="/dgnum-logo.png" height=50px /></a><br/>
<span style="font-size: 0.8em">Merci à la <a href="https://dgnum.eu">Délégation Générale NUMérique de l'ENS</a>, qui héberge ce site.</span>
@ -51,13 +51,15 @@
var code_buttons = "";
if(state.Conscrit.invisibility_codes > 0)
code_buttons += `<button onclick="fetch('/track/{{id}}/vanish', { method: 'PUT' })">
Invisibilité
Activer l'invisibilité
</button>`;
if(state.Conscrit.blur_codes > 0)
code_buttons += `<button onclick="fetch('/track/{{id}}/blur', { method: 'PUT' })">
Brouillage
</button>`;
document.getElementById(`codes`).innerHTML = code_buttons;
document.getElementById(`nb-codes`).innerHTML = state.Conscrit.invisibility_codes +
" code(s) d'invisibilité ";
};
setup_evtlisten_common();