Skip to content

Commit

Permalink
Fixed issue where changing 'take about of the week of the year' would…
Browse files Browse the repository at this point in the history
… prevent lists being generated

Better handling of model swap during prediction
  • Loading branch information
Mattk70 committed Mar 6, 2024
1 parent 5126bcc commit daa196e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ <h5 class="offcanvas-title" id="offcanvasExampleLabel">Settings</h5>
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch" id="nocmig">
<label class="form-check-label" for="nocmig">Only analyse night time periods.</label>
<a class="circle" tabindex="-1" data-bs-toggle="popover" data-bs-trigger="focus" data-bs-title="Nocmig Mode" data-bs-content="When enabled, this Nocmig mode only searches for and only displays detections found during the night">?</a>
<a class="circle" tabindex="-1" data-bs-toggle="popover" data-bs-trigger="focus" data-bs-title="Nocmig Mode" data-bs-content="When enabled, this 'Nocmig mode' only searches for and only displays detections found during the night">?</a>
</div>
</div>
</fieldset>
Expand Down
8 changes: 5 additions & 3 deletions js/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -1560,7 +1560,7 @@ window.onload = async () => {
DOM.defaultLat.value = config.latitude;
DOM.defaultLon.value = config.longitude;
place.innerHTML = '<span class="material-symbols-outlined">fmd_good</span>' + config.location;

setListUIState(config.list);
worker.postMessage({
action: 'update-state',
path: appPath,
Expand Down Expand Up @@ -2281,6 +2281,7 @@ function onChartData(args) {
})

const loadModel = () => {
if (PREDICTING)
t0_warmup = Date.now();
worker.postMessage({
action: 'load-model',
Expand Down Expand Up @@ -2316,7 +2317,8 @@ function onChartData(args) {
contextAwareIconDisplay();
}
}

PREDICTING = false;
STATE.analysisDone = true;
}
// Update threads and batch Size in UI
DOM.threadSlider.value = config[config.backend].threads;
Expand Down Expand Up @@ -4221,7 +4223,7 @@ DOM.gain.addEventListener('input', () => {
config.backend = 'tensorflow';
document.getElementById('tensorflow').checked = true;
handleBackendChange(config.backend);
STATE.analysisDone = false;
setListUIState(config.list)
break;
}
case 'thread-slider': {
Expand Down
17 changes: 8 additions & 9 deletions js/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,8 @@ case "insert-manual-record": { await onInsertManualRecord(args);
break;
}
case "load-model": {
predictWorkers.length && terminateWorkers();
if (filesBeingProcessed.length) onAbort(args);
else predictWorkers.length && terminateWorkers();
await onLaunch(args);
break;
}
Expand Down Expand Up @@ -350,10 +351,8 @@ case "update-list": {
STATE.customList = args.list === 'custom' ? args.customList : STATE.customList;
const {lat, lon, week} = STATE;
// Clear the LIST_CACHE & STATE.included kesy to force list regeneration
if (args.customList) {
delete LIST_CACHE[`${lat}-${lon}-${week}-${STATE.model}-${STATE.list}`];
delete STATE.included?.[STATE.model]?.[STATE.list];
}
LIST_CACHE = {}; //[`${lat}-${lon}-${week}-${STATE.model}-${STATE.list}`];
delete STATE.included?.[STATE.model]?.[STATE.list];
await setIncludedIDs(lat, lon, week )
args.refreshResults && await Promise.all([getResults(), getSummary()]);
break;
Expand Down Expand Up @@ -3096,7 +3095,7 @@ const prepSummaryStatement = (included) => {
const location = lat.toString() + lon.toString();
if (STATE.included?.[STATE.model]?.[STATE.list]?.[week]?.[location] === undefined ) {
// Cache miss
await setIncludedIDs(lat,lon,week)
const list = await setIncludedIDs(lat,lon,week)
hitOrMiss = 'miss';
}
DEBUG && console.log(`Cache ${hitOrMiss}: setting the ${STATE.list} list took ${Date.now() -t0}ms`)
Expand Down Expand Up @@ -3128,9 +3127,9 @@ async function setIncludedIDs(lat, lon, week) {
const key = `${lat}-${lon}-${week}-${STATE.model}-${STATE.list}`;
if (LIST_CACHE[key]) {
// If a promise is in the cache, return it
return LIST_CACHE[key];
return await LIST_CACHE[key];
}

console.log('calling for a new list')
// Store the promise in the cache immediately
LIST_CACHE[key] = (async () => {
const { result, messages } = await LIST_WORKER({
Expand Down Expand Up @@ -3173,7 +3172,7 @@ async function setIncludedIDs(lat, lon, week) {
})();

// Await the promise
return LIST_CACHE[key];
return await LIST_CACHE[key];
}

/// Track errors
Expand Down

0 comments on commit daa196e

Please sign in to comment.