From b4f956d63878c7d10236521f733d92f4384a6ead Mon Sep 17 00:00:00 2001
From: MonkeyWhisper <82112471+MonkeyWhisper@users.noreply.github.com>
Date: Sun, 5 Nov 2023 14:24:12 -0500
Subject: [PATCH] Officers Activity Updated
---
ui/app.js | 63 +++++++++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 54 insertions(+), 9 deletions(-)
diff --git a/ui/app.js b/ui/app.js
index 3d63425c..9c2989ed 100644
--- a/ui/app.js
+++ b/ui/app.js
@@ -5705,24 +5705,69 @@ window.addEventListener("message", (event) => {
});
function updateOfficerData(officerData) {
+ officerData.forEach(officer => {
+ officer.totalSeconds = timeStringToSeconds(officer.totalTime);
+ });
+
+ officerData.sort((a, b) => b.totalSeconds - a.totalSeconds);
+
const leaderboardBox = document.querySelector('.leaderboard-box');
leaderboardBox.innerHTML = '';
- const positions = ['1st', '2nd', '3rd', '4th', '5th', '6th', '7th', '8th', '9th', '10th', '11th', '12th', '13th', '14th', '15th', '16th', '17th', '18th', '19th', '20th', '21th', '22th', '23th', '24th', '25th'];
+ const positions = ['1st', '2nd', '3rd', '4th', '5th', '6th', '7th', '8th', '9th', '10th', '11th', '12th', '13th', '14th', '15th', '16th', '17th', '18th', '19th', '20th', '21st', '22nd', '23rd', '24th', '25th'];
officerData.forEach((officer, index) => {
- const position = positions[index];
- const officerDiv = document.createElement('div');
- officerDiv.className = 'leaderboard-box-test';
- officerDiv.style.fontSize = '1.3vh';
- officerDiv.style.fontWeight = 'lighter';
- officerDiv.style.color = index < 3 ? 'white' : 'grey';
+ const position = positions[index];
+ const officerDiv = document.createElement('div');
+ officerDiv.className = 'leaderboard-box-test';
+ officerDiv.style.fontSize = '1.3vh';
+ officerDiv.style.fontWeight = 'lighter';
+ officerDiv.style.color = index < 3 ? 'white' : 'grey';
- officerDiv.innerHTML = `► ${position}: ${officer.name} (${officer.callsign})${officer.totalTime}`;
- leaderboardBox.appendChild(officerDiv);
+ officerDiv.innerHTML = `► ${position}: ${officer.name} (${officer.callsign})${officer.totalTime}`;
+ leaderboardBox.appendChild(officerDiv);
});
}
+function timeStringToSeconds(t) {
+ if (!t) return 0;
+
+ let days = 0, hours = 0, minutes = 0, seconds = 0;
+ let daysPart = '0';
+ let timePart = t;
+
+ // days vs day check
+ if (t.includes(' days ')) {
+ [daysPart, timePart] = t.split(' days ');
+ }
+
+ const timeParts = timePart.split(' ');
+
+ for (let i = 0; i < timeParts.length; i += 2) {
+ const val = parseInt(timeParts[i]);
+ switch (timeParts[i + 1]) {
+ case 'hours':
+ hours = val;
+ break;
+ case 'minutes':
+ minutes = val;
+ break;
+ case 'seconds':
+ seconds = val;
+ break;
+ }
+ }
+
+ days = parseInt(daysPart);
+
+ return (
+ days * 86400 +
+ hours * 3600 +
+ minutes * 60 +
+ seconds
+ );
+}
+
window.addEventListener("load", function () {
document