| Name | Message | Date |
|---|---|---|
| 📁 assets | 1 month ago | |
| 📁 components | 1 month ago | |
| 📄 birdnet.worker.ts | 1 month ago | |
| 📄 history.ts | 1 month ago | |
| 📄 index.ts | 1 month ago | |
| 📄 labels.ts | 1 month ago | |
| 📄 types.ts | 1 month ago |
📄
src/lib/history.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { writable } from "svelte/store";
import type { HistoryEntry, Prediction } from "./types";
const STORAGE_KEY = "birdgo-history";
function load(): HistoryEntry[] {
if (typeof localStorage === "undefined") return [];
try {
const raw = localStorage.getItem(STORAGE_KEY);
return raw ? (JSON.parse(raw) as HistoryEntry[]) : [];
} catch {
return [];
}
}
const store = writable<HistoryEntry[]>(load());
store.subscribe((entries) => {
if (typeof localStorage !== "undefined") {
localStorage.setItem(STORAGE_KEY, JSON.stringify(entries));
}
});
let sessionSeen = new Set<number>();
export function startSession() {
sessionSeen = new Set();
}
export function endSession() {
sessionSeen = new Set();
}
export function addDetection(p: Pick<Prediction, "labelIndex" | "confidence">) {
if (p.confidence < 0.7) return;
if (sessionSeen.has(p.labelIndex)) return;
sessionSeen.add(p.labelIndex);
store.update((entries) => [
{
labelIndex: p.labelIndex,
confidence: p.confidence,
detectedAt: new Date().toISOString(),
},
...entries,
]);
}
export const historyStore = { subscribe: store.subscribe };