Skip to content

Commit

Permalink
fixed devtools disconnected error
Browse files Browse the repository at this point in the history
daylight banner now works
  • Loading branch information
Mattk70 committed Nov 5, 2023
1 parent 57dfd2f commit ec0895b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 25 deletions.
18 changes: 3 additions & 15 deletions js/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions js/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
25 changes: 18 additions & 7 deletions js/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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}) `;
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit ec0895b

Please sign in to comment.