From ec0895b63e8b1e8bbf2c4298556a23f3ccd4e4d8 Mon Sep 17 00:00:00 2001 From: Mattk70 Date: Sun, 5 Nov 2023 20:14:36 +0000 Subject: [PATCH] fixed devtools disconnected error daylight banner now works --- js/model.js | 18 +++--------------- js/ui.js | 6 +++--- js/worker.js | 25 ++++++++++++++++++------- 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/js/model.js b/js/model.js index 6017295e..916facac 100644 --- a/js/model.js +++ b/js/model.js @@ -189,22 +189,11 @@ class Model { // find the position of the blocked items in the label list NOT_BIRDS.forEach(notBird => BLOCKED_IDS.push(this.labels.indexOf(notBird))) } else if (this.list === 'migrants') { - let v1_migrants; - if (this.version === 'v1') { - // strip (call) from migrants set - v1_migrants = new Set(); - MIGRANTS.forEach((element) => { - const newElement = element.replace(' (call)', ''); - v1_migrants.add(newElement); - }) - - } - const listToCheck = v1_migrants || MIGRANTS; + const listToCheck = MIGRANTS; for (let i = 0; i < this.labels.length; i++) { const item = this.labels[i]; if (!listToCheck.has(item) && !MYSTERIES.includes(item)) BLOCKED_IDS.push(i); } - } GRAYLIST.forEach(species => SUPPRESSED_IDS.push(this.labels.indexOf(species))) GOLDEN_LIST.forEach(species => ENHANCED_IDS.push(this.labels.indexOf(species))) @@ -393,16 +382,15 @@ class Model { const numSamples = buffer.shape / this.chunkLength; let buffers = tf.reshape(buffer, [numSamples, this.chunkLength]); buffer.dispose(); - const bufferList = this.normalise_audio_batch(buffers); - buffers.dispose(); + const bufferList = this.version !== 'v4' ? this.normalise_audio_batch(buffers) : buffers; const specBatch = tf.tidy(() => { const bufferArray = tf.unstack(bufferList); const toStack = bufferArray.map(x => { return this.makeSpectrogram(x) - //return this.version === 'v2' ? this.makeSpectrogram(x) : this.makeSpectrogram(this.normalise_audio(x)); }) return this.fixUpSpecBatch(tf.stack(toStack)) }); + buffers.dispose(); bufferList.dispose(); //const specBatch = tf.stack(bufferList); const batchKeys = [...Array(numSamples).keys()].map(i => start + this.chunkLength * i); diff --git a/js/ui.js b/js/ui.js index dd1b27a0..279ce3a6 100644 --- a/js/ui.js +++ b/js/ui.js @@ -2574,7 +2574,8 @@ async function onPredictionDone({ offset = 0, action = undefined }) { - + // Reset daylight banner + shownDaylightBanner = false; AUDACITY_LABELS = audacityLabels; enableMenuItem(['save2db', 'export2audio']); // Defer further processing until batch complete @@ -2663,8 +2664,7 @@ pagination.forEach(item => { const limit = config.limit; const offset = (clicked - 1) * limit; const species = isSpeciesViewFiltered(true); - // Reset daylight banner - shownDaylightBanner = false; + worker.postMessage({ action: 'filter', species: species, diff --git a/js/worker.js b/js/worker.js index 47c66299..efc1fdd9 100644 --- a/js/worker.js +++ b/js/worker.js @@ -69,7 +69,7 @@ const createDB = async (file) => { await db.runAsync(`CREATE TABLE records( dateTime INTEGER, position INTEGER, fileID INTEGER, speciesID INTEGER, confidence INTEGER, label TEXT, - comment TEXT, end INTEGER, callCount INTEGER, + comment TEXT, end INTEGER, callCount INTEGER, isDaylight INTEGER, UNIQUE (dateTime, fileID, speciesID), CONSTRAINT fk_files FOREIGN KEY (fileID) REFERENCES files(id) ON DELETE CASCADE, @@ -121,6 +121,14 @@ async function loadDB(path) { if (count) { UI.postMessage({ event: 'diskDB-has-records' }) } + const sql = 'PRAGMA table_info(records)'; + const result = await diskDB.allAsync(sql); + // Update legacy tables + const columnExists = result.some((column) => column.name === 'isDaylight'); + if (!columnExists) { + await diskDB.runAsync('ALTER TABLE records ADD COLUMN isDaylight INTEGER') + console.log('Added isDaylight column to records table') + } console.log("Opened and cleaned disk db " + file) } return true @@ -448,7 +456,7 @@ const prepSummaryStatement = () => { const useRange = range?.start; let summaryStatement = ` WITH ranked_records AS ( - SELECT records.dateTime, records.speciesID, records.confidence, records.fileID, cname, sname, callCount, + SELECT records.dateTime, records.speciesID, records.confidence, records.fileID, cname, sname, callCount, isDaylight, RANK() OVER (PARTITION BY records.dateTime ORDER BY records.confidence DESC) AS rank FROM records JOIN files ON files.id = records.fileID @@ -461,6 +469,9 @@ const prepSummaryStatement = () => { else if (useRange) { extraClause += ' AND dateTime BETWEEN ? AND ? '; } + if (STATE.detect.nocmig){ + extraClause += ' AND isDaylight != 1 '; + } if (STATE.blocked.length) { const excluded = prepParams(STATE.blocked); extraClause += ` AND speciesID NOT IN (${excluded}) `; @@ -1584,8 +1595,8 @@ const terminateWorkers = () => { predictWorkers = []; } -const insertRecord = async (key, speciesID, confidence, file) => { - +const insertRecord = async (timestamp, key, speciesID, confidence, file) => { + const isDaylight = isDuringDaylight(timestamp, STATE.lat, STATE.lon) const offset = key * 1000; let changes, fileID; confidence = Math.round(confidence); @@ -1605,9 +1616,9 @@ const insertRecord = async (key, speciesID, confidence, file) => { // No "OR IGNORE" in this statement because it should only run when the file is new await db.runAsync(`INSERT OR IGNORE INTO duration VALUES ${durationSQL}`); } - await db.runAsync('INSERT OR REPLACE INTO records VALUES (?,?,?,?,?,?,?,?,?)', + await db.runAsync('INSERT OR REPLACE INTO records VALUES (?,?,?,?,?,?,?,?,?,?)', metadata[file].fileStart + offset, key, fileID, speciesID, confidence, - null, null, key + 3, null); + null, null, key + 3, null, isDaylight); } async function batchInsertRecords(cname, label, toDisk, files, originalCname) { @@ -1726,7 +1737,7 @@ const parsePredictions = async (response) => { updateUI = (confidence > STATE.detect.confidence && STATE.blocked.indexOf(speciesID) === -1); //save all results to db, regardless of confidence - if (!STATE.selection) await insertRecord(key, speciesID, confidence, file); + if (!STATE.selection) await insertRecord(timestamp, key, speciesID, confidence, file); if (STATE.selection || updateUI) { let end, confidenceRequired; if (STATE.selection) {