From 83ee5cbd264048ea7f684a951d8a6840291fe62a Mon Sep 17 00:00:00 2001 From: rakadu1 Date: Wed, 3 Sep 2025 10:44:07 +0530 Subject: [PATCH] Sochin fix reimplemented just to be sure. --- steps/src/main.js | 69 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 57 insertions(+), 12 deletions(-) diff --git a/steps/src/main.js b/steps/src/main.js index 363d597..296457e 100644 --- a/steps/src/main.js +++ b/steps/src/main.js @@ -111,74 +111,119 @@ clearCacheBtn.addEventListener("click", async () => { }); jsonFileInput.addEventListener("change", (event) => { + const file = event.target.files[0]; - if (!file) return; + if (!file) return; + appState.jsonFilename = file.name; + localStorage.setItem("jsonFilename", appState.jsonFilename); + calculateAndSetOffset(); - saveFileToDB("json", file); // Save the file object for the next session + saveFileToDB("json", file); // Save the file object for the next session + // 1. Show a loading modal immediately. - showModal("Parsing large JSON file, please wait..."); + showModal("Parsing large JSON file, please wait..."); + // 2. Create a temporary URL for the streaming parser. - const fileURL = URL.createObjectURL(file); + const fileURL = URL.createObjectURL(file); + // 3. Use the robust streaming parser. + parseJsonWithOboe( + fileURL, + async (parsedData) => { + // This is the success callback, running after the file is parsed. - // We make it async so we can `await` the next step. + // We make it async so we can `await` the next step. + const result = await parseVisualizationJson( + parsedData, + appState.radarStartTimeMs, + appState.videoStartDate - ); + ); + // Revoke the temporary URL to free up memory. - URL.revokeObjectURL(fileURL); + URL.revokeObjectURL(fileURL); + if (result.error) { + showModal(result.error); + return; - } + } + appState.vizData = result.data; + appState.globalMinSnr = result.minSnr; - appState.globalMaxSnr = result.maxSnr; + appState.globalMaxSnr = result.maxSnr; + // Update UI with the correct, awaited data. + snrMinInput.value = appState.globalMinSnr.toFixed(1); + snrMaxInput.value = appState.globalMaxSnr.toFixed(1); + resetVisualization(); + canvasPlaceholder.style.display = "none"; - featureToggles.classList.remove("hidden"); + featureToggles.classList.remove("hidden"); + if (!appState.p5_instance) { + appState.p5_instance = new p5(radarSketch); - } + } + if (appState.speedGraphInstance) { + appState.speedGraphInstance.setData( + appState.canData, + appState.vizData, + videoPlayer.duration + ); - } + } + // Close the loading modal. + document.getElementById("modal-ok-btn").click(); + }, + (error) => { + // This is the error callback for the streaming parser. + showModal(error); + URL.revokeObjectURL(fileURL); + } + ); + }); + // Event listener for video file input change. videoFileInput.addEventListener("change", (event) => {