chore: use 1s STEP

This commit is contained in:
js0ny 2025-12-06 05:09:16 +00:00
parent acf9d132f7
commit 0ce7faaa07
5 changed files with 1304 additions and 1348 deletions

View file

@ -83,7 +83,8 @@
return new Date(earliest).toISOString().slice(0, 16); return new Date(earliest).toISOString().slice(0, 16);
} }
startTime = deriveStartTime(defaultDispatch) || new Date().toISOString().slice(0, 16); // Set to current time
startTime = new Date().toISOString().slice(0, 16);
desiredTime = startTime; desiredTime = startTime;
function jumpToTime(timeValue) { function jumpToTime(timeValue) {
@ -186,49 +187,6 @@
stopPlaying(); stopPlaying();
}); });
async function requestPath() {
let payload;
try {
payload = JSON.parse(dispatchBody);
} catch (err) {
status = "Error: Invalid JSON format.";
return;
}
if (!Array.isArray(payload)) {
status = "Error: Payload must be an array.";
return;
}
const derivedStart = deriveStartTime(payload);
if (derivedStart) {
startTime = derivedStart;
desiredTime = derivedStart;
}
loading = true;
status = "Transmitting dispatch to API...";
stopPlaying();
try {
const res = await fetch(`${apiBase}/calcDeliveryPath`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload),
});
if (!res.ok) throw new Error(`${res.status} ${res.statusText}`);
plannedPath = await res.json();
tick = 0;
fitMapToBounds();
status = "Flight path received. Ready for simulation.";
} catch (err) {
plannedPath = samplePathResponse;
status = `API Link Failed. Using offline sample data. (${err.message})`;
} finally {
loading = false;
}
}
function loadSample() { function loadSample() {
plannedPath = samplePathResponse; plannedPath = samplePathResponse;
status = "Loaded sample simulation data."; status = "Loaded sample simulation data.";
@ -386,10 +344,6 @@
<div class="text-[10px] space-y-0.5 font-mono opacity-80"> <div class="text-[10px] space-y-0.5 font-mono opacity-80">
<div class="flex justify-between"><span>Lat:</span> <span>${drone.current.lat.toFixed(4)}</span></div> <div class="flex justify-between"><span>Lat:</span> <span>${drone.current.lat.toFixed(4)}</span></div>
<div class="flex justify-between"><span>Lng:</span> <span>${drone.current.lng.toFixed(4)}</span></div> <div class="flex justify-between"><span>Lng:</span> <span>${drone.current.lng.toFixed(4)}</span></div>
<div class="flex justify-between mt-1 pt-1 border-t border-white/10">
<span>Status:</span>
<span class="${isMoving ? "text-green-400" : "text-slate-400"}">${isMoving ? "MOVING" : "IDLE"}</span>
</div>
</div> </div>
</div> </div>
`; `;
@ -514,7 +468,6 @@
{status} {status}
{loading} {loading}
on:close={() => (sidebarOpen = false)} on:close={() => (sidebarOpen = false)}
on:request={requestPath}
on:loadSample={loadSample} on:loadSample={loadSample}
/> />
</div> </div>

View file

@ -31,6 +31,11 @@
@apply bg-gray-800 text-white p-2 rounded-md border-gray-700 border; @apply bg-gray-800 text-white p-2 rounded-md border-gray-700 border;
} }
/* Arrow should be the same color as the tooltip background */
.drone-tooltip.leaflet-tooltip-top::before {
border-top-color: theme('colors.gray.800');
}
/* Custom Scrollbar */ /* Custom Scrollbar */
.custom-scrollbar::-webkit-scrollbar { .custom-scrollbar::-webkit-scrollbar {
width: 6px; width: 6px;
@ -55,4 +60,4 @@
} }
.drone-popup .leaflet-popup-content { .drone-popup .leaflet-popup-content {
margin: 12px; margin: 12px;
} }

View file

@ -134,7 +134,7 @@
<label <label
for="api" for="api"
class="block text-xs text-slate-600 dark:text-slate-400 mb-1" class="block text-xs text-slate-600 dark:text-slate-400 mb-1"
>Planner API Endpoint</label >Planner API Endpoint (Debug Only)</label
> >
<input <input
id="api" id="api"
@ -189,21 +189,16 @@
spellcheck="false" spellcheck="false"
></textarea> ></textarea>
</div> </div>
<div class="flex gap-2 mt-auto pt-4 border-t border-slate-200 dark:border-slate-800">
<button
class="flex-1 p-2.5 rounded-lg font-semibold text-sm transition-all disabled:opacity-50 disabled:cursor-not-allowed text-white bg-sky-500 shadow-[0_4px_12px_theme(colors.sky.500/30)] hover:bg-sky-600 disabled:hover:bg-sky-500"
on:click={() => dispatch('request')}
disabled={loading}
>
{loading ? "CALCULATING..." : "REQUEST PATH"}
</button>
</div>
</div> </div>
<div class="flex gap-2 mt-auto pt-4 border-t border-slate-200 dark:border-slate-800"> </aside>
<button
class="flex-1 p-2.5 rounded-lg font-semibold text-sm transition-all disabled:opacity-50 disabled:cursor-not-allowed text-white bg-sky-500 shadow-[0_4px_12px_theme(colors.sky.500/30)] hover:bg-sky-600 disabled:hover:bg-sky-500"
on:click={() => dispatch('request')}
disabled={loading}
>
{loading ? "CALCULATING..." : "REQUEST PATH"}
</button>
<button
class="flex-1 p-2.5 rounded-lg font-semibold text-sm transition-all disabled:opacity-50 disabled:cursor-not-allowed text-slate-800 dark:text-slate-100 bg-slate-500/20 hover:bg-slate-500/30"
on:click={() => dispatch('loadSample')}
>
LOAD SAMPLE
</button>
</div>
</aside>

File diff suppressed because it is too large Load diff

View file

@ -23,7 +23,10 @@ public record DroneEvent(
double latitude, double latitude,
double longitude, double longitude,
String timestamp) { String timestamp) {
final static int STEP = 1; // seconds between events
// Helper method that converts from DeliveryPathResponse to List<DroneEvent> // Helper method that converts from DeliveryPathResponse to List<DroneEvent>
public static List<DroneEvent> fromPathResponse(DeliveryPathResponse resp) { public static List<DroneEvent> fromPathResponse(DeliveryPathResponse resp) {
List<DroneEvent> events = new java.util.ArrayList<>(); List<DroneEvent> events = new java.util.ArrayList<>();
for (var p : resp.dronePaths()) { for (var p : resp.dronePaths()) {
@ -57,7 +60,7 @@ public record DroneEvent(
coord.lat(), coord.lat(),
coord.lng(), coord.lng(),
timestamp.toString())); timestamp.toString()));
timestamp = timestamp.plusSeconds(1); // Increment timestamp for each event timestamp = timestamp.plusSeconds(STEP); // Increment timestamp for each event
} }
} }
} }
@ -80,7 +83,7 @@ public record DroneEvent(
coord.lat(), coord.lat(),
coord.lng(), coord.lng(),
current.toString())); current.toString()));
current = current.plusSeconds(1); current = current.plusSeconds(STEP);
} }
} }
} }