Skip to content

Commit

Permalink
Update pagination during the initial analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
Mattk70 committed Nov 3, 2024
1 parent df0c01c commit c559c9d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 33 deletions.
2 changes: 1 addition & 1 deletion js/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -3281,7 +3281,7 @@ function formatDuration(seconds){
const pagination = document.querySelectorAll('.pagination');
pagination.forEach(item => {
item.addEventListener('click', (e) => {
if (e.target.tagName === 'A') { // Did we click a link in the list?
if (STATE.analysisDone && e.target.tagName === 'A') { // Did we click a link in the list?
let clicked = e.target.textContent;
let currentPage = pagination[0].querySelector('.active');
currentPage = parseInt(currentPage.textContent);
Expand Down
68 changes: 36 additions & 32 deletions js/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,7 @@ async function handleMessage(e) {
await getResults(args);
args.updateSummary && await getSummary(args);
args.included = await getIncludedIDs(args.file);
const [total, offset, species] = await getTotal(args);
UI.postMessage({event: 'total-records', total: total, offset: offset, species: species})
await getTotal(args);
}
break;
}
Expand Down Expand Up @@ -799,7 +798,7 @@ const prepSummaryStatement = (included) => {
}


const getTotal = async ({species = undefined, offset = undefined, included = [], file = undefined}= {}) => {
const getTotal = async ({species = undefined, offset = undefined, included = STATE.included, file = undefined}= {}) => {
let params = [];
const range = STATE.mode === 'explore' ? STATE.explore.range : undefined;
offset = offset ?? (species !== undefined ? STATE.filteredOffset[species] : STATE.globalOffset);
Expand Down Expand Up @@ -827,7 +826,7 @@ const getTotal = async ({species = undefined, offset = undefined, included = [],
SQL += ' AND speciesID = (SELECT id from species WHERE cname = ?) ';
}
const {total} = await STATE.db.getAsync(SQL, ...params)
return [total, offset, species]
UI.postMessage({event: 'total-records', total: total, offset: offset, species: species})
}

const prepResultsStatement = (species, noLimit, included, offset, topRankin) => {
Expand Down Expand Up @@ -1137,36 +1136,39 @@ async function loadAudioFile({
}) {

if (file) {
const audio = await fetchAudioBuffer({ file, start, end })
fetchAudioBuffer({ file, start, end })
.then(audio => {
let audioArray = getMonoChannelData(audio);
UI.postMessage({
event: 'worker-loaded-audio',
location: METADATA[file].locationID,
start: METADATA[file].fileStart,
sourceDuration: METADATA[file].duration,
bufferBegin: start,
file: file,
position: position,
contents: audioArray,
fileRegion: region,
preserveResults: preserveResults,
play: play,
queued: queued,
goToRegion,
metadata: METADATA[file].metadata
}, [audioArray.buffer]);
let week;
if (STATE.list === 'location'){
week = STATE.useWeek ? new Date(METADATA[file].fileStart).getWeekNumber() : -1
// Send the week number of the surrent file
UI.postMessage({event: 'current-file-week', week: week})
} else { UI.postMessage({event: 'current-file-week', week: undefined}) }
})
.catch( (error) => {
console.log(error);
console.warn(error);
// notify and return null if no matching file was found
generateAlert({type: 'error', message: error.message});
error.code === 'ENOENT' && notifyMissingFile(file)
})
let audioArray = getMonoChannelData(audio);
UI.postMessage({
event: 'worker-loaded-audio',
location: METADATA[file].locationID,
start: METADATA[file].fileStart,
sourceDuration: METADATA[file].duration,
bufferBegin: start,
file: file,
position: position,
contents: audioArray,
fileRegion: region,
preserveResults: preserveResults,
play: play,
queued: queued,
goToRegion,
metadata: METADATA[file].metadata
}, [audioArray.buffer]);
let week;
if (STATE.list === 'location'){
week = STATE.useWeek ? new Date(METADATA[file].fileStart).getWeekNumber() : -1
// Send the week number of the surrent file
UI.postMessage({event: 'current-file-week', week: week})
} else { UI.postMessage({event: 'current-file-week', week: undefined}) }

}
}

Expand Down Expand Up @@ -2163,7 +2165,10 @@ const parsePredictions = async (response) => {
DEBUG && console.log(`File ${file} processed after ${(new Date() - predictionStart) / 1000} seconds: ${filesBeingProcessed.length} files to go`);
}

!STATE.selection && (STATE.increment() === 0) && await getSummary({ interim: true });
if (!STATE.selection && STATE.increment() === 0) {
getSummary({ interim: true });
getTotal()
}

return response.worker
}
Expand Down Expand Up @@ -2405,8 +2410,7 @@ const getResults = async ({
offset = (position.page - 1) * limit;
active = position.row;
// update the pagination
const [total, , ] = await getTotal({species: species, offset: offset, included: included})
UI.postMessage({event: 'total-records', total: total, offset: offset, species: species})
await getTotal({species: species, offset: offset, included: included})
}
offset = offset ?? (species ? (STATE.filteredOffset[species] ?? 0) : STATE.globalOffset);
if (species) STATE.filteredOffset[species] = offset;
Expand Down

0 comments on commit c559c9d

Please sign in to comment.