Skip to content

Commit

Permalink
Candidate release
Browse files Browse the repository at this point in the history
  • Loading branch information
Mattk70 committed Jan 30, 2024
1 parent 28eee67 commit 4bb6338
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
20 changes: 11 additions & 9 deletions js/ui.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let seenTheDarkness = false, shownDaylightBanner = false, LOCATIONS, locationID = undefined;
const startTime = performance.now();
let labels = [], DELETE_HISTORY = [];
let LABELS = [], DELETE_HISTORY = [];

const STATE = {
mode: 'analyse',
Expand Down Expand Up @@ -1623,7 +1623,7 @@ function generateBirdList(store, rows) {
function generateBirdOptionList({ store, rows, selected }) {
let listHTML = '';
if (store === 'allSpecies') {
let sortedList = labels.map(label => label.split('_')[1]);
let sortedList = LABELS.map(label => label.split('_')[1]);
sortedList.sort((a, b) => a.localeCompare(b));
// Check if we have prepared this before
const all = document.getElementById('allSpecies');
Expand Down Expand Up @@ -2137,8 +2137,8 @@ locale.addEventListener('change', async ()=> {
if (! response.ok) throw new Error('Network response was not ok');
return response.text();
}).then(filecontents => {
const labels = filecontents.trim().split('\n');
worker.postMessage({action: 'update-locale', locale: labels})
LABELS = filecontents.trim().split('\n');
worker.postMessage({action: 'update-locale', locale: LABELS})
}).catch(error =>{
console.error('There was a problem fetching the label file:', error);
})
Expand Down Expand Up @@ -2621,7 +2621,7 @@ function displayWarmUpMessage() {

function onModelReady(args) {
modelReady = true;
labels = args.labels;
LABELS = args.labels;
sampleRate = args.sampleRate;
warmupText.classList.add('d-none');
if (fileLoaded) {
Expand Down Expand Up @@ -2954,10 +2954,12 @@ async function renderResult({
if (index <= 1) {
if (selection) {
const selectionTable = document.getElementById('selectionResultTableBody');
selectionTable.innerHTML = '';
selectionTable.textContent = '';
}
else {
showElement(['resultTableContainer', 'resultsHead'], false);
const resultTable = document.getElementById('resultTableBody');
resultTable.textContent = ''
}
} else if (!isFromDB && index % (config.limit + 1) === 0) {
addPagination(index, 0)
Expand Down Expand Up @@ -4038,9 +4040,9 @@ audioDownmix.addEventListener('change', (e) => {
});

function getSnameFromCname(cname) {
for (let i = 0; i < labels.length; i++) {
if (labels[i].includes(cname)) {
return labels[i].split('_')[0];
for (let i = 0; i < LABELS.length; i++) {
if (LABELS[i].includes(cname)) {
return LABELS[i].split('_')[0];
}
}
return ; // Substring not found in any item
Expand Down
33 changes: 23 additions & 10 deletions js/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ async function loadDB(path) {
await diskDB.runAsync('VACUUM');
await diskDB.runAsync('PRAGMA foreign_keys = ON');
const { count } = await diskDB.getAsync('SELECT COUNT(*) as count FROM records')
const labelList = await diskDB.allAsync('SELECT sname, cname FROM species');
LABELS = labelList.map(obj => `${obj.sname}_${obj.cname}`);
if (count) {
UI.postMessage({ event: 'diskDB-has-records' })
}
Expand All @@ -146,7 +148,7 @@ async function loadDB(path) {
// await Promise.all([species, files]);
console.log("Opened and cleaned disk db " + file)
}
return true
return LABELS
}


Expand Down Expand Up @@ -1925,13 +1927,14 @@ let SEEN_LABELS = false, SEEN_MODEL_READY = false;
async function parseMessage(e) {
const response = e.data;
switch (response['message']) {
case "labels": {t0 = Date.now();
LABELS = response["labels"];
if ( !SEEN_LABELS) {
SEEN_LABELS = true;
await loadDB(appPath);
memoryDB || await createDB();
}
case "labels": {
t0 = Date.now();
if ( !SEEN_LABELS) {
LABELS = response["labels"];
SEEN_LABELS = true;
LABELS = await loadDB(appPath);
memoryDB || await createDB();
}
break;
}
case "model-ready": {if ( !SEEN_MODEL_READY) {
Expand Down Expand Up @@ -2801,10 +2804,20 @@ async function onUpdateLocale(labels){
await diskDB.runAsync('BEGIN');
for (let i = 0; i < labels.length; i++){
const [sname, cname] = labels[i].split('_');
diskDB.runAsync('UPDATE species SET cname = ? WHERE sname = ?', cname, sname);
await diskDB.runAsync('UPDATE species SET cname = ? WHERE sname = ?', cname, sname);
}
await diskDB.runAsync('END');
await createDB();
await memoryDB.runAsync('BEGIN');
for (let i = 0; i < labels.length; i++){
const [sname, cname] = labels[i].split('_');
await memoryDB.runAsync('UPDATE species SET cname = ? WHERE sname = ?', cname, sname);
}
await memoryDB.runAsync('END');
// //reset index to flush results table
// index = 0;
await getResults()
await getSummary();

}
}

Expand Down

0 comments on commit 4bb6338

Please sign in to comment.