Skip to content

Commit

Permalink
Buffering of results table now working propoerly
Browse files Browse the repository at this point in the history
Scroll to the top of the new results on filter.
  • Loading branch information
Mattk70 committed Nov 21, 2023
1 parent ab9e205 commit 832490e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
14 changes: 9 additions & 5 deletions js/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ function resetResults(clearSummary, clearPagination) {
if (clearSummary) summaryTable.innerText = '';
clearPagination && pagination.forEach(item => item.classList.add('d-none'));
const resultTable = document.getElementById('resultTableBody');
resultTable.innerHTML = '';
resultsBuffer = resultTable.cloneNode(false)
predictions = {};
seenTheDarkness = false;
shownDaylightBanner = false;
Expand Down Expand Up @@ -1511,6 +1511,9 @@ const setUpWorkerMessaging = () => {
}
break;
case 'hide-spinner':
const table = document.getElementById('resultTableBody')
table.replaceWith(resultsBuffer);
document.getElementById('resultsDiv').scrollTo({ top: 0, left: 0, behavior: "smooth" });
hideLoadingSpinner();
break;
case 'location-list':
Expand Down Expand Up @@ -2635,7 +2638,7 @@ async function onPredictionDone({
if (resultsBuffer) {
const results = document.getElementById('resultTableBody');
results.replaceWith(resultsBuffer);
resultsBuffer = undefined;
// resultsBuffer = undefined;
}

updateSummary({ summary: summary, filterSpecies: filterSpecies });
Expand Down Expand Up @@ -2874,7 +2877,7 @@ async function renderResult({
}


let resultsBuffer, detectionsModal;
let resultsBuffer = document.getElementById('resultTableBody').cloneNode(false), detectionsModal;
const detectionsModalDiv = document.getElementById('detectionsModal')

detectionsModalDiv.addEventListener('hide.bs.modal', (e) => {
Expand All @@ -2886,11 +2889,11 @@ const updateResultTable = (row, isFromDB, isSelection) => {
const table = isSelection ? document.getElementById('selectionResultTableBody')
: document.getElementById('resultTableBody');
if (isFromDB && !isSelection) {
if (!resultsBuffer) resultsBuffer = table.cloneNode();
//if (!resultsBuffer) resultsBuffer = table.cloneNode();
resultsBuffer.lastElementChild ?
resultsBuffer.lastElementChild.insertAdjacentHTML('afterend', row) :
resultsBuffer.innerHTML = row;
table.replaceWith(resultsBuffer);

} else {
if (isSelection) {
if (!detectionsModal || !detectionsModal._isShown) {
Expand Down Expand Up @@ -3139,6 +3142,7 @@ const changeNocmigMode = () => {
});
updatePrefs();
worker.postMessage({ action: 'update-state', globalOffset: 0, filteredOffset: {}});
resetResults(true, true);
worker.postMessage({
action: 'filter',
species: isSpeciesViewFiltered(true),
Expand Down
24 changes: 9 additions & 15 deletions js/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let workerInstance = 0;
let TEMP, appPath, CACHE_LOCATION, BATCH_SIZE, LABELS, BACKEND, batchChunksToSend = {};
let SEEN_LIST_UPDATE = false // Prevents list updates from every worker on every change

const DEBUG = false;
const DEBUG = true;

const DATASET = true;
const adding_chirpity_additions = true;
Expand Down Expand Up @@ -79,9 +79,9 @@ const createDB = async (file) => {
UNIQUE (day, fileID),
CONSTRAINT fk_files
FOREIGN KEY (fileID) REFERENCES files(id) ON DELETE CASCADE)`);
// await db.runAsync('CREATE INDEX idx_datetime ON records(dateTime)');
// await db.runAsync('CREATE INDEX idx_species ON records(speciesID)');
// await db.runAsync('CREATE INDEX idx_files ON records(fileID)');
await db.runAsync('CREATE INDEX idx_datetime ON records(dateTime)');
await db.runAsync('CREATE INDEX idx_species ON records(speciesID)');
await db.runAsync('CREATE INDEX idx_files ON records(fileID)');
if (archiveMode) {
for (let i = 0; i < LABELS.length; i++) {
const [sname, cname] = LABELS[i].replaceAll("'", "''").split('_');
Expand Down Expand Up @@ -132,7 +132,7 @@ async function loadDB(path) {
console.log('Added isDaylight column to records table')
}
// const datetime = diskDB.runAsync('CREATE INDEX IF NOT EXISTS idx_datetime ON records (dateTime)');
// const covering_total = diskDB.runAsync('CREATE INDEX IF NOT EXISTS idx_covering_total ON records (confidence, isDaylight)');
const covering_total = diskDB.runAsync('CREATE INDEX IF NOT EXISTS idx_covering_total ON records (confidence, isDaylight)');
// const species = diskDB.runAsync('CREATE INDEX IF NOT EXISTS idx_species ON records (speciesID)');
//await Promise.all([datetime, species, files, covering_total]);
console.log("Opened and cleaned disk db " + file)
Expand Down Expand Up @@ -270,12 +270,12 @@ async function handleMessage(e) {
t0 = Date.now()
UI.postMessage({event: 'show-spinner'});
await getResults(args);
args.updateSummary && await getSummary(args);
const t1 = Date.now()
args.updateSummary && await getSummary(args);
const t2 = Date.now()
await getTotal(args);
//await Promise.all([getResults(args), getSummary(args)]);
console.log('Filter took ', (Date.now() - t0) / 1000, 'seconds', '\nGettotal took ', (Date.now() - t1) / 1000, 'seconds',)

console.log('Filter took ', (Date.now() - t0) / 1000, 'seconds', '\nGetTotal took ', (Date.now() - t2) / 1000, 'seconds', '\nGetSummary took ', (t2 - t1) / 1000, 'seconds')
}
break;
case 'get-detected-species-list':
Expand Down Expand Up @@ -437,7 +437,6 @@ const getSummaryParams = (species) => {
extraParams.push(...blocked);
STATE.locationID && extraParams.push(STATE.locationID);
params.push(...extraParams);
species && params.push(species);
return params
}

Expand Down Expand Up @@ -477,9 +476,7 @@ const prepSummaryStatement = (species) => {
SELECT cname, sname, COUNT(*) as count, SUM(callcount) as calls, ROUND(MAX(ranked_records.confidence) / 10.0, 0) as max
FROM ranked_records
WHERE ranked_records.rank <= ${STATE.topRankin}
GROUP BY speciesID`;
if (species) summaryStatement += ` WHERE cname = ? `;
summaryStatement += ' ORDER BY cname';
GROUP BY speciesID ORDER BY cname`;
STATE.GET_SUMMARY_SQL = STATE.db.prepare(summaryStatement);
//console.log('Summary SQL statement:\n' + summaryStatement)
}
Expand Down Expand Up @@ -2143,8 +2140,6 @@ const getResults = async ({

let index = offset;
AUDACITY = {};
let t0 = Date.now();

const params = getResultsParams(species, confidence, offset, limit, topRankin);
prepResultsStatement(species, limit === Infinity);

Expand Down Expand Up @@ -2186,7 +2181,6 @@ const getResults = async ({
sendResult(++index, r, true)
}
}
console.log("Get Results took", (Date.now() - t0) / 1000, " seconds");
if (!result.length) {
if (STATE.selection) {
// No more detections in the selection
Expand Down

0 comments on commit 832490e

Please sign in to comment.