Skip to content

Commit

Permalink
Diagnostics improvements
Browse files Browse the repository at this point in the history
Summary update now every time a prediction received
  • Loading branch information
Mattk70 committed Nov 10, 2023
1 parent db520da commit f928a19
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 26 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,7 @@ <h5 class="modal-title" id="gotoModalLabel">Set Location</h5>
<table id='results' class="text-center table w-100 align-middle">
<thead id="resultsHead" class="d-none">
<tr class="bg-dark">
<th class="time-sort col text-start timeOfDay" title="Sort results by detection time"><span class="text-muted material-symbols-outlined time-sort-icon">sort</span> Time</th>
<th class="time-sort col text-start timeOfDay pointer" title="Sort results by detection time"><span class="text-muted material-symbols-outlined time-sort-icon">sort</span> Time</th>
<th class="time-sort text-start timestamp pointer" title="Sort results by detection time"><span class="text-muted material-symbols-outlined time-sort-icon">sort</span> Position</th>
<th id="confidence-sort" class="text-start pointer" title="Sort results by detection confidence"><span class="text-muted material-symbols-outlined species-sort-icon d-none">sort</span> Species</th>
<th class="text-end">Calls</th>
Expand Down
21 changes: 13 additions & 8 deletions js/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -2650,16 +2654,17 @@ 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
const resultTable = document.getElementById('resultTableBody');
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];
Expand Down Expand Up @@ -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(`
<a class="dropdown-item play ${hideInSummary}"><span class='material-symbols-outlined'>play_circle</span> Play</a>
Expand Down
32 changes: 15 additions & 17 deletions js/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 })

}

Expand All @@ -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);
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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') {
Expand All @@ -2525,7 +2523,7 @@ async function onDelete({
// Update the seen species list
if (db === diskDB) {
getSpecies();
}else {
} else {
UI.postMessage({event: 'unsaved-records'});
}
}
Expand Down

0 comments on commit f928a19

Please sign in to comment.