From b1f3758bf5a47fd4ea47c16fae3d8718bf2a3511 Mon Sep 17 00:00:00 2001 From: Mattk70 Date: Thu, 28 Mar 2024 12:53:14 +0000 Subject: [PATCH] Stop sending analysis-complete twice --- js/tracking.js | 2 +- js/ui.js | 19 +++++++++---------- js/worker.js | 17 ++++++++--------- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/js/tracking.js b/js/tracking.js index 01b2dd08..c67ea88f 100644 --- a/js/tracking.js +++ b/js/tracking.js @@ -1,5 +1,5 @@ const DEBUG = false; -const ID_SITE = 2; +const ID_SITE = 3; function trackEvent(uuid, event, action, name, value){ diff --git a/js/ui.js b/js/ui.js index f1688e80..cc99dab7 100644 --- a/js/ui.js +++ b/js/ui.js @@ -2923,16 +2923,15 @@ function onChartData(args) { // DIAGNOSTICS: t1_analysis = Date.now(); const analysisTime = ((t1_analysis - t0_analysis) / 1000).toFixed(2); - if (! STATE.selection){ - DIAGNOSTICS['Analysis Duration'] = analysisTime + ' seconds'; - const rate = (DIAGNOSTICS['Audio Duration'] / analysisTime); - DIAGNOSTICS['Analysis Rate'] = rate.toFixed(0) + 'x faster than real time performance.'; - trackEvent(config.UUID, `${config.model}-${config.backend}`, 'Audio Duration', config.backend, Math.round(DIAGNOSTICS['Audio Duration'])); - trackEvent(config.UUID, `${config.model}-${config.backend}`, 'Analysis Duration', config.backend, parseInt(analysisTime)); - trackEvent(config.UUID, `${config.model}-${config.backend}`, 'Analysis Rate', config.backend, parseInt(rate)); - generateToast({ message:'Analysis complete.'}) - activateResultFilters(); - } + const duration = STATE.selection ? STATE.selection.end - STATE.selection.start : DIAGNOSTICS['Audio Duration']; + DIAGNOSTICS['Analysis Duration'] = analysisTime + ' seconds'; + const rate = duration / analysisTime; + DIAGNOSTICS['Analysis Rate'] = rate.toFixed(0) + 'x faster than real time performance.'; + trackEvent(config.UUID, `${config.model}-${config.backend}`, 'Audio Duration', config.backend, Math.round(duration)); + trackEvent(config.UUID, `${config.model}-${config.backend}`, 'Analysis Duration', config.backend, parseInt(analysisTime)); + trackEvent(config.UUID, `${config.model}-${config.backend}`, 'Analysis Rate', config.backend, parseInt(rate)); + STATE.selection || generateToast({ message:'Analysis complete.'}) + STATE.selection || activateResultFilters(); } /* diff --git a/js/worker.js b/js/worker.js index da829199..7a5e9b6d 100644 --- a/js/worker.js +++ b/js/worker.js @@ -1287,7 +1287,7 @@ const getPredictBuffers = async ({ else { error.message = error.message + '|' + error.stack; } - reject(console.warn('Error in ffmpeg extracting audio segment:', error.message)); + reject(console.warn('getPredictBuffers: Error in ffmpeg extracting audio segment:', error.message)); }); command.on('start', function (commandLine) { DEBUG && console.log('FFmpeg command: ' + commandLine); @@ -1309,12 +1309,10 @@ const getPredictBuffers = async ({ console.log('STREAM ended, destroyed') } else { - // try/catch may no longer be necessary try { concatenatedBuffer = concatenatedBuffer.length ? Buffer.concat([concatenatedBuffer, chunk]) : chunk; } catch (error) { console.warn(error) - console.warn('concat bugger length', concatenatedBuffer.length, 'chunk.length', chunk.length, chunk.buffer.detached, concatenatedBuffer.buffer.detached) } // if we have a full buffer @@ -1383,7 +1381,7 @@ const fetchAudioBuffer = async ({ command.on('error', error => { UI.postMessage({event: 'generate-alert', message: error.message}) - reject(new Error('Error extracting audio segment:', error)); + reject(new Error('fetchAudioBuffer: Error extracting audio segment:', error)); }); command.on('start', function (commandLine) { DEBUG && console.log('FFmpeg command: ' + commandLine); @@ -2087,11 +2085,12 @@ async function parseMessage(e) { if (remaining === 0) { if (filesBeingProcessed.length) { processNextFile({ worker: worker }); - } else if ( !STATE.selection) { - getSummary() //.then(() => UI.postMessage({event: "analysis-complete"})); - } else { - UI.postMessage({event: "analysis-complete"}); - } + } + // else if ( !STATE.selection) { + // getSummary() //.then(() => UI.postMessage({event: "analysis-complete"})); + // } else { + // UI.postMessage({event: "analysis-complete"}); + // } } } break;