diff --git a/index.html b/index.html index 056ef718..e3b7c0ba 100644 --- a/index.html +++ b/index.html @@ -1004,7 +1004,7 @@
+ Time | Time | Position | Species | Calls | diff --git a/js/ui.js b/js/ui.js index 43270144..6150e204 100644 --- a/js/ui.js +++ b/js/ui.js @@ -676,6 +676,7 @@ async function onOpenFiles(args) { hideAll(); showElement(['spectrogramWrapper'], false); resetResults(); + resetDiagnostics(); //completeDiv.hide(); // Store the file list and Load First audio file fileList = args.filePaths; @@ -713,11 +714,17 @@ async function showSaveDialog() { await window.electron.saveFile({ currentFile: currentFile, labels: AUDACITY_LABELS[currentFile] }); } +function resetDiagnostics() { + delete diagnostics['Audio Duration']; + delete diagnostics['Analysis Rate']; + delete diagnostics['Analysis Duration']; +} + // Worker listeners function analyseReset() { fileNumber.innerText = ''; PREDICTING = true; - delete diagnostics['Audio Duration']; + resetDiagnostics(); AUDACITY_LABELS = {}; progressDiv.classList.remove('d-none'); // Diagnostics @@ -815,9 +822,6 @@ function postAnalyseMessage(args) { analyseReset(); resetResults(); refreshResultsView(); - } else { - //progressDiv.classList.remove('d-none'); - delete diagnostics['Audio Duration']; } if (filesInScope.length > 1) { batchInProgress = true; @@ -2650,8 +2654,9 @@ async function onPredictionDone({ // Diagnostics: t1_analysis = Date.now(); - diagnostics['Analysis Duration'] = ((t1_analysis - t0_analysis) / 1000).toFixed(2) + ' seconds'; - diagnostics['Analysis Rate'] = (diagnostics['Audio Duration'] / ((t1_analysis - t0_analysis) / 1000)).toFixed(0) + 'x faster than real time performance.'; + const analysisTime = ((t1_analysis - t0_analysis) / 1000).toFixed(2); + diagnostics['Analysis Duration'] = analysisTime + ' seconds'; + diagnostics['Analysis Rate'] = (diagnostics['Audio Duration'] / analysisTime).toFixed(0) + 'x faster than real time performance.'; } // Set active Row @@ -2659,7 +2664,7 @@ async function onPredictionDone({ if (active) { // Refresh node and scroll to active row: activeRow = resultTable.rows[active]; - if (activeRow === null) { // because: after an edit the active row may not exist + if (activeRow) { // because: after an edit the active row may not exist const rows = resultTable.querySelectorAll('tr.daytime, tr.nighttime') if (rows.length) { activeRow = rows[rows.length - 1]; @@ -3730,7 +3735,7 @@ async function createContextMenu(e) { } } if (region === undefined && ! inSummary) return; - const createOrEdit = (['archive', 'explore'].includes(STATE.mode)) && (region?.attributes.label || target.closest('#summary')) ? 'Edit' : 'Create'; + const createOrEdit = ((region?.attributes.label || target.closest('#summary'))) ? 'Edit' : 'Create'; menu.html(` play_circle Play diff --git a/js/worker.js b/js/worker.js index e2a14288..589f4462 100644 --- a/js/worker.js +++ b/js/worker.js @@ -276,13 +276,13 @@ async function handleMessage(e) { break; case 'insert-manual-record': const count = await onInsertManualRecord(args); - if (STATE.mode !== 'explore' && !args.batch) { + // if (STATE.mode !== 'explore' && !args.batch) { UI.postMessage({ event: 'generate-alert', - message: `${count} ${args.cname} record has been saved to the archive.`, + // message: `${count} ${args.cname} record has been saved to the archive.`, filter: true }) - } + // } break; case 'load-model': SEEN_LABELS = false; @@ -645,8 +645,10 @@ async function onAnalyse({ await getResults({ topRankin: 5 }); } else { onChangeMode('archive'); + FILE_QUEUE.forEach(file => UI.postMessage({ event: 'update-audio-duration', value: metadata[file].duration })) await getResults(); await getSummary(); + } return; } @@ -1670,7 +1672,6 @@ async function batchInsertRecords(cname, label, files, originalCname) { } await db.runAsync('END'); console.log(`Batch record update took ${(Date.now() - t0) / 1000} seconds`) - if (STATE.mode !== 'explore' && toDisk) UI.postMessage({ event: 'generate-alert', message: `${count} ${cname} records have been saved to the archive.`, savedToDB: true }) } @@ -1679,7 +1680,7 @@ const onInsertManualRecord = async ({ cname, start, end, comment, count, file, l start = parseFloat(start), end = parseFloat(end); const startMilliseconds = Math.round(start * 1000); let changes, fileID, fileStart; - const db = STATE.db; // toDisk ? diskDB : memoryDB; + const db = STATE.db; const { speciesID } = await db.getAsync(`SELECT id as speciesID FROM species WHERE cname = ?`, cname); let res = await db.getAsync(`SELECT id,filestart FROM files WHERE name = ?`, file); @@ -1712,8 +1713,8 @@ const onInsertManualRecord = async ({ cname, start, end, comment, count, file, l if (response.changes){ STATE.db === diskDB ? UI.postMessage({ event: 'diskDB-has-records' }) : UI.postMessage({event: 'unsaved-records'}); } - let test = await db.allAsync('SELECT * from records where datetime = ?', dateTime) - console.log('After insert: ',JSON.stringify(test)); + // let test = await db.allAsync('SELECT * from records where datetime = ?', dateTime) + // console.log('After insert: ',JSON.stringify(test)); return response.changes } @@ -1793,9 +1794,8 @@ const parsePredictions = async (response) => { updateFilesBeingProcessed(response.file) console.log(`Prediction done ${filesBeingProcessed.length} files to go`); console.log('Analysis took ' + (new Date() - predictionStart) / 1000 + ' seconds.'); - } else if (STATE.increment() === 0) { - getSummary({ interim: true }); } + getSummary({ interim: true }); return response.worker } @@ -2500,19 +2500,17 @@ async function onDelete({ speciesFiltered }) { const db = STATE.db; - const { filestart } = await db.getAsync('SELECT filestart from files WHERE name = ?', file); + const { id, filestart } = await db.getAsync('SELECT id, filestart from files WHERE name = ?', file); const datetime = filestart + (parseFloat(start) * 1000); end = parseFloat(end); - const params = [datetime, end]; - let sql = 'DELETE FROM records WHERE datetime = ? AND end = ?'; + const params = [id, datetime, end]; + let sql = 'DELETE FROM records WHERE fileID = ? AND datetime = ? AND end = ?'; if (species) { sql += ' AND speciesID = (SELECT id FROM species WHERE cname = ?)' params.push(species); } - // Catch inserted manual records - if (STATE.db === memoryDB) { - await diskDB.runAsync(sql, ...params); - } + let test = await db.allAsync('SELECT * from records WHERE speciesID = (SELECT id FROM species WHERE cname = ?)', species) + console.log('After insert: ',JSON.stringify(test)); let { changes } = await db.runAsync(sql, ...params); if (changes) { if (STATE.mode !== 'selection') { @@ -2525,7 +2523,7 @@ async function onDelete({ // Update the seen species list if (db === diskDB) { getSpecies(); - }else { + } else { UI.postMessage({event: 'unsaved-records'}); } }
---|