Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,18 @@

"map_unknownLocation": "Unknown Location",

"runs_title": "Runs",
"runs_empty": "No analysis runs yet",
"runs_emptyHint": "Go to the Analysis tab to start your first analysis.",
"runs_detectionCount": "{count} detections",
"runs_detectionCountSingular": "{count} detection",
"runs_noDetections": "No detections",
"runs_selectRun": "Select a run from the list to view its detections.",
"runs_status_running": "Running",
"runs_status_completed": "Completed",
"runs_status_failed": "Failed",
"runs_status_pending": "Pending",

"analysis_title": "Analysis",
"analysis_selectFile": "Select File",
"analysis_selectFileDesc": "Select an audio file to analyze",
Expand Down
5 changes: 5 additions & 0 deletions shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ export interface AnalysisRun {
completed_at: string | null;
}

export interface RunWithStats extends AnalysisRun {
detection_count: number;
location_name: string | null;
}

export interface Detection {
id: number;
run_id: number;
Expand Down
29 changes: 28 additions & 1 deletion src/main/db/runs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getDb } from './database';
import type { AnalysisRun } from '$shared/types';
import type { AnalysisRun, RunWithStats } from '$shared/types';

export function createRun(
sourcePath: string,
Expand All @@ -14,7 +14,7 @@
VALUES (?, ?, ?, ?, ?, 'running', datetime('now'))
`);
const result = stmt.run(locationId ?? null, sourcePath, model, minConfidence, settingsJson ?? null);
return getRunById(result.lastInsertRowid as number)!;

Check warning on line 17 in src/main/db/runs.ts

View workflow job for this annotation

GitHub Actions / Lint, Type Check & Build

Forbidden non-null assertion
}

export function updateRunStatus(id: number, status: AnalysisRun['status']): void {
Expand Down Expand Up @@ -47,3 +47,30 @@
db.prepare('DELETE FROM analysis_runs WHERE id = ?').run(id);
})();
}

/** Mark any runs left in 'running' state as 'failed' — they are stale from a previous session. */
export function markStaleRunsAsFailed(): number {
const db = getDb();
const result = db
.prepare("UPDATE analysis_runs SET status = 'failed', completed_at = datetime('now') WHERE status = 'running'")
.run();
return result.changes;
}

export function getRunsWithStats(): RunWithStats[] {
const db = getDb();
return db
.prepare(
`SELECT
r.*,
COALESCE(d.cnt, 0) AS detection_count,
l.name AS location_name
FROM analysis_runs r
LEFT JOIN (
SELECT run_id, COUNT(*) AS cnt FROM detections GROUP BY run_id
) d ON d.run_id = r.id
LEFT JOIN locations l ON l.id = r.location_id
ORDER BY r.started_at DESC`,
)
.all() as RunWithStats[];
}
7 changes: 7 additions & 0 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import fs from 'fs';
import { registerHandlers } from './ipc/handlers';
import { closeDb } from './db/database';
import { markStaleRunsAsFailed } from './db/runs';
import { buildLabelsPath, reloadLabels } from './labels/label-service';
import { listModels } from './birda/models';

Expand Down Expand Up @@ -190,6 +191,12 @@
registerBirdaMediaProtocol();
await registerHandlers();

// Mark any runs stuck in 'running' from a previous session as failed
const staleCount = markStaleRunsAsFailed();
if (staleCount > 0) {
console.log(`[startup] Marked ${staleCount} stale running run(s) as failed`);
}

// Initialize label service from default model's labels with saved language preference
try {
const models = await listModels();
Expand All @@ -198,7 +205,7 @@
// Read saved language preference
let language = 'en';
try {
const settingsRaw = await fs.promises.readFile(

Check warning on line 208 in src/main/index.ts

View workflow job for this annotation

GitHub Actions / Lint, Type Check & Build

Found readFile from package "fs" with non literal argument at index 0
path.join(app.getPath('userData'), 'birda-gui-settings.json'),
'utf-8',
);
Expand Down
5 changes: 5 additions & 0 deletions src/main/ipc/catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from '../db/detections';
import { clearDatabase } from '../db/database';
import { getLocations, getLocationsWithCounts } from '../db/locations';
import { getRunsWithStats } from '../db/runs';
import { resolveAll, searchByCommonName } from '../labels/label-service';
import type {
Detection,
Expand Down Expand Up @@ -37,6 +38,10 @@ function enrichSpeciesSummaries(summaries: SpeciesSummary[]): EnrichedSpeciesSum
}

export function registerCatalogHandlers(): void {
ipcMain.handle('catalog:get-runs', () => {
return getRunsWithStats();
});

ipcMain.handle('catalog:get-detections', (_event, filter: DetectionFilter) => {
// If species filter is set, also resolve common name matches from label service
if (filter.species) {
Expand Down
1 change: 1 addition & 0 deletions src/preload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const ALLOWED_INVOKE_CHANNELS = new Set([
'clip:save-spectrogram',
'clip:get-spectrogram',
'clip:export-region',
'catalog:get-runs',
'catalog:get-detections',
'catalog:search-species',
'catalog:get-species-summary',
Expand Down
5 changes: 2 additions & 3 deletions src/renderer/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
type BirdaEventEnvelope,
} from '$lib/stores/analysis.svelte';
import { addLog, type LogEntry } from '$lib/stores/log.svelte';
import { loadDetections } from '$lib/stores/catalog.svelte';
import {
getCatalogStats,
getSettings,
Expand Down Expand Up @@ -93,9 +92,9 @@
analysisState.status = 'completed';
appState.lastRunId = result.runId;
appState.lastSourceFile = appState.sourcePath;
appState.activeTab = 'analysis';
appState.selectedRunId = result.runId;
appState.activeTab = 'detections';
appState.catalogStats = await getCatalogStats();
await loadDetections();
} catch (err) {
analysisState.status = 'failed';
analysisState.error = (err as Error).message;
Expand Down
60 changes: 0 additions & 60 deletions src/renderer/src/lib/components/AudioPlayer.svelte

This file was deleted.

141 changes: 0 additions & 141 deletions src/renderer/src/lib/components/DetectionsTable.svelte

This file was deleted.

Loading
Loading