show fancier stats

This commit is contained in:
perf3ct 2025-03-08 23:21:21 +00:00
parent 1ca98e2fc2
commit 51c83bbbc8
No known key found for this signature in database
GPG Key ID: 569C4EEC436F5232
3 changed files with 52 additions and 2 deletions

View File

@ -201,7 +201,10 @@ export default class AiSettingsWidget extends OptionsWidget {
<div><strong>${t("ai_llm.queued_notes")}:</strong> <span class="embedding-queued-notes">-</span></div>
<div><strong>${t("ai_llm.failed_notes")}:</strong> <span class="embedding-failed-notes">-</span></div>
<div><strong>${t("ai_llm.last_processed")}:</strong> <span class="embedding-last-processed">-</span></div>
<div class="progress mt-2" style="height: 10px;">
<div class="mt-2">
<strong>${t("ai_llm.progress")}:</strong> <span class="embedding-status-text">-</span>
</div>
<div class="progress mt-1" style="height: 10px;">
<div class="progress-bar embedding-progress" role="progressbar" style="width: 0%;"
aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">0%</div>
</div>
@ -456,6 +459,30 @@ export default class AiSettingsWidget extends OptionsWidget {
$progressBar.css('width', `${stats.percentComplete}%`);
$progressBar.attr('aria-valuenow', stats.percentComplete.toString());
$progressBar.text(`${stats.percentComplete}%`);
// Update status text based on state
const $statusText = this.$widget.find('.embedding-status-text');
if (stats.queuedNotesCount > 0) {
$statusText.text(t("ai_llm.processing", { percentage: stats.percentComplete }));
} else if (stats.percentComplete < 100) {
$statusText.text(t("ai_llm.incomplete", { percentage: stats.percentComplete }));
} else {
$statusText.text(t("ai_llm.complete"));
}
// Change progress bar color based on state
if (stats.queuedNotesCount > 0) {
// Processing in progress - use animated progress bar
$progressBar.addClass('progress-bar-striped progress-bar-animated bg-info');
$progressBar.removeClass('bg-success');
} else if (stats.percentComplete < 100) {
// Incomplete - use standard progress bar
$progressBar.removeClass('progress-bar-striped progress-bar-animated bg-info bg-success');
} else {
// Complete - show success color
$progressBar.removeClass('progress-bar-striped progress-bar-animated bg-info');
$progressBar.addClass('bg-success');
}
}
} catch (error) {
console.error("Error fetching embedding stats:", error);

View File

@ -1174,6 +1174,10 @@
"failed_notes": "Failed Notes",
"last_processed": "Last Processed",
"never": "Never",
"progress": "Progress",
"processing": "Processing ({{percentage}}%)",
"incomplete": "Incomplete ({{percentage}}%)",
"complete": "Complete (100%)",
"refresh_stats": "Refresh Stats",
"refreshing": "Refreshing...",
"stats_error": "Error fetching embedding statistics",

View File

@ -496,13 +496,32 @@ export async function getEmbeddingStats() {
"SELECT utcDateCreated FROM note_embeddings ORDER BY utcDateCreated DESC LIMIT 1"
) as string | null || null;
// Calculate the actual completion percentage
// When reprocessing, we need to consider notes in the queue as not completed yet
// We calculate the percentage of notes that are embedded and NOT in the queue
// First, get the count of notes that are both in the embeddings table and queue
const notesInQueueWithEmbeddings = await sql.getValue(`
SELECT COUNT(DISTINCT eq.noteId)
FROM embedding_queue eq
JOIN note_embeddings ne ON eq.noteId = ne.noteId
`) as number;
// The number of notes with valid, up-to-date embeddings
const upToDateEmbeddings = embeddedNotesCount - notesInQueueWithEmbeddings;
// Calculate the percentage of notes that are properly embedded
const percentComplete = totalNotesCount > 0
? Math.round((upToDateEmbeddings / totalNotesCount) * 100)
: 0;
return {
totalNotesCount,
embeddedNotesCount,
queuedNotesCount,
failedNotesCount,
lastProcessedDate,
percentComplete: totalNotesCount > 0 ? Math.round((embeddedNotesCount / totalNotesCount) * 100) : 0
percentComplete: Math.max(0, Math.min(100, percentComplete)) // Ensure between 0-100
};
}