@7365admin1/layer-common 4.159.0 → 4.161.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -4
- package/components/CctvEngine/DetectionCreate.vue +260 -0
- package/components/CctvEngine/DetectionDetail.vue +266 -0
- package/components/CctvEngine/Detections.vue +135 -0
- package/components/CctvEngine/EventDetail.vue +108 -0
- package/components/CctvEngine/Events.vue +6 -84
- package/components/CctvEngine/Search.vue +177 -0
- package/components/CctvEngine/Shell.vue +3 -1
- package/composables/useCctvEngine.ts +24 -0
- package/package.json +1 -1
- package/plugins/secure-member.client.ts +15 -2
- package/utils/cctv-engine.ts +122 -1
package/utils/cctv-engine.ts
CHANGED
|
@@ -29,7 +29,9 @@ export type TCctvSection =
|
|
|
29
29
|
| "plates"
|
|
30
30
|
| "faces"
|
|
31
31
|
| "alerts"
|
|
32
|
-
| "engines"
|
|
32
|
+
| "engines"
|
|
33
|
+
| "search"
|
|
34
|
+
| "detections";
|
|
33
35
|
|
|
34
36
|
/** The menu, in the order people use it. `needs` is the permission the server enforces on that screen's routes. */
|
|
35
37
|
export const CCTV_SECTIONS: { key: TCctvSection; title: string; icon: string; needs: TCctvPermission; face?: boolean }[] = [
|
|
@@ -37,7 +39,9 @@ export const CCTV_SECTIONS: { key: TCctvSection; title: string; icon: string; ne
|
|
|
37
39
|
{ key: "events", title: "Events", icon: "mdi-timeline-clock-outline", needs: CCTV_PERMISSIONS.viewEvents },
|
|
38
40
|
{ key: "playback", title: "Playback & export", icon: "mdi-play-box-outline", needs: CCTV_PERMISSIONS.viewEvents },
|
|
39
41
|
{ key: "zones", title: "Zones & wrong-way", icon: "mdi-vector-polygon", needs: CCTV_PERMISSIONS.manageZones },
|
|
42
|
+
{ key: "search", title: "Smart search", icon: "mdi-text-search", needs: CCTV_PERMISSIONS.viewEvents },
|
|
40
43
|
{ key: "plates", title: "Known plates", icon: "mdi-car-info", needs: CCTV_PERMISSIONS.managePlates },
|
|
44
|
+
{ key: "detections", title: "Smart detection", icon: "mdi-shape-plus-outline", needs: CCTV_PERMISSIONS.manageZones },
|
|
41
45
|
{ key: "faces", title: "Face library", icon: "mdi-face-recognition", needs: CCTV_PERMISSIONS.manageFaces, face: true },
|
|
42
46
|
{ key: "alerts", title: "Alerts", icon: "mdi-bell-ring-outline", needs: CCTV_PERMISSIONS.manageAlerts },
|
|
43
47
|
{ key: "engines", title: "Engines & health", icon: "mdi-server-network", needs: CCTV_PERMISSIONS.manageEngine },
|
|
@@ -84,6 +88,7 @@ export const EVENT_KINDS = [
|
|
|
84
88
|
{ value: "audio", title: "Sound heard" },
|
|
85
89
|
{ value: "wrong-way", title: "Wrong way" },
|
|
86
90
|
{ value: "review", title: "Review item" },
|
|
91
|
+
{ value: "classification", title: "Smart detection" },
|
|
87
92
|
];
|
|
88
93
|
export const EVENT_SEVERITIES = [
|
|
89
94
|
{ value: "alert", title: "Alert" },
|
|
@@ -328,3 +333,119 @@ export function summariseHealth(stats: THealthStats | null | undefined): THealth
|
|
|
328
333
|
cameras: stats?.cameras ?? [],
|
|
329
334
|
};
|
|
330
335
|
}
|
|
336
|
+
|
|
337
|
+
// --------------------------------------------------------------------------- smart search
|
|
338
|
+
|
|
339
|
+
export const SEARCH_MIN = 2;
|
|
340
|
+
export const SEARCH_MAX = 200;
|
|
341
|
+
|
|
342
|
+
/** The words typed in the search box -> what the API takes, or the plain-words problem. */
|
|
343
|
+
export function buildSearchQuery(
|
|
344
|
+
text: string,
|
|
345
|
+
camera?: string | null,
|
|
346
|
+
limit = 24,
|
|
347
|
+
): { ok: true; query: Record<string, string | number> } | { ok: false; problem: string } {
|
|
348
|
+
const q = (text ?? "").trim().replace(/\s+/g, " ");
|
|
349
|
+
if (q.length < SEARCH_MIN) return { ok: false, problem: `Type at least ${SEARCH_MIN} letters describing what you are looking for.` };
|
|
350
|
+
if (q.length > SEARCH_MAX) return { ok: false, problem: `Keep it under ${SEARCH_MAX} characters.` };
|
|
351
|
+
const query: Record<string, string | number> = { q, limit: Math.min(50, Math.max(1, Math.floor(limit) || 24)) };
|
|
352
|
+
if (camera) query.camera = camera;
|
|
353
|
+
return { ok: true, query };
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/** Event heading: smart detections read "rubbish (bin_area)", everything else is the object name. */
|
|
357
|
+
export function classificationTitle(e: { kind?: string; label?: string; subLabel?: string }) {
|
|
358
|
+
return e.kind === "classification" && e.subLabel ? `${e.label} (${e.subLabel})` : String(e.label ?? "");
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// --------------------------------------------------------------------------- smart detection (custom training)
|
|
362
|
+
|
|
363
|
+
export const MIN_PHOTOS_PER_RESULT = 5;
|
|
364
|
+
export const MAX_RESULTS = 10;
|
|
365
|
+
export const DEFAULT_RESULTS = ["clean", "rubbish"];
|
|
366
|
+
const WORD = /^[a-z0-9_]{1,40}$/;
|
|
367
|
+
|
|
368
|
+
/** What a person types ("Bin Area", "Rubbish!") -> the lowercase word the engine takes ("bin_area", "rubbish"). */
|
|
369
|
+
export const toWord = (v: string) =>
|
|
370
|
+
(v ?? "").toString().trim().toLowerCase().replace(/\s+/g, "_").replace(/[^a-z0-9_]/g, "").slice(0, 40);
|
|
371
|
+
|
|
372
|
+
/** Plain-words problem with a detection name, or "". */
|
|
373
|
+
export function detectionNameProblem(name: string): string {
|
|
374
|
+
const w = toWord(name);
|
|
375
|
+
if (!w) return "Give the detection a short name, for example bin_area.";
|
|
376
|
+
if (!WORD.test(w)) return "Use letters, numbers and underscores only (up to 40).";
|
|
377
|
+
return "";
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/** Plain-words problem with the list of results, or "". "none" is reserved by the engine. */
|
|
381
|
+
export function resultsProblem(states: readonly string[], alertStates: readonly string[] = []): string {
|
|
382
|
+
if (states.length < 2) return "Add at least two results, for example clean and rubbish.";
|
|
383
|
+
if (states.length > MAX_RESULTS) return `Use at most ${MAX_RESULTS} results.`;
|
|
384
|
+
if (new Set(states).size !== states.length) return "Each result must be different.";
|
|
385
|
+
if (states.some((s) => !WORD.test(s) || s === "none")) return 'Results use letters, numbers and underscores only, and "none" is not allowed.';
|
|
386
|
+
if (alertStates.some((a) => !states.includes(a))) return "An alert result must be one of the results.";
|
|
387
|
+
return "";
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
export type TCrop = [number, number, number, number];
|
|
391
|
+
export const MIN_CROP_SIDE = 0.03;
|
|
392
|
+
|
|
393
|
+
/** Mouse drag inside the picture box (pixels) -> [left, top, right, bottom] as 0..1 fractions, clamped and ordered. */
|
|
394
|
+
export function cropFromDrag(
|
|
395
|
+
box: { left: number; top: number; width: number; height: number },
|
|
396
|
+
from: { x: number; y: number },
|
|
397
|
+
to: { x: number; y: number },
|
|
398
|
+
): TCrop {
|
|
399
|
+
const a = pointFromClick(box, from.x, from.y);
|
|
400
|
+
const b = pointFromClick(box, to.x, to.y);
|
|
401
|
+
return [Math.min(a[0], b[0]), Math.min(a[1], b[1]), Math.max(a[0], b[0]), Math.max(a[1], b[1])];
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/** Big enough to teach from (each side at least 3% of the picture). */
|
|
405
|
+
export const cropIsUsable = (c: readonly number[] | null | undefined) =>
|
|
406
|
+
!!c && c.length === 4 && c[2] - c[0] >= MIN_CROP_SIDE && c[3] - c[1] >= MIN_CROP_SIDE;
|
|
407
|
+
|
|
408
|
+
export type TClassifier = {
|
|
409
|
+
name: string;
|
|
410
|
+
camera?: string;
|
|
411
|
+
alertStates?: string[];
|
|
412
|
+
states?: string[];
|
|
413
|
+
counts?: Record<string, number>;
|
|
414
|
+
waiting?: number;
|
|
415
|
+
training?: { trained: boolean; lastTrainedAt: string | null; changedSinceTraining: boolean } | null;
|
|
416
|
+
engineUnreachable?: boolean;
|
|
417
|
+
};
|
|
418
|
+
|
|
419
|
+
/** Results that still need more sorted photos. */
|
|
420
|
+
export function shortResults(c: Pick<TClassifier, "states" | "counts">, min = MIN_PHOTOS_PER_RESULT) {
|
|
421
|
+
return (c.states ?? [])
|
|
422
|
+
.map((state) => ({ state, have: c.counts?.[state] ?? 0 }))
|
|
423
|
+
.filter((r) => r.have < min)
|
|
424
|
+
.map((r) => ({ ...r, need: min - r.have }));
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/** Why Teach is not available yet, in plain words ("" = go ahead). */
|
|
428
|
+
export function teachProblem(c: Pick<TClassifier, "states" | "counts">, min = MIN_PHOTOS_PER_RESULT): string {
|
|
429
|
+
if (!(c.states ?? []).length) return "This detection has no results yet.";
|
|
430
|
+
const short = shortResults(c, min);
|
|
431
|
+
if (!short.length) return "";
|
|
432
|
+
return `Sort at least ${min} photos into each result first. Still needed: ${short.map((r) => `${r.state} (${r.have} of ${min})`).join(", ")}.`;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/** One chip for the list: what stage this detection is at. `teaching` = Teach was pressed on this screen and is running. */
|
|
436
|
+
export function classifierStatus(
|
|
437
|
+
c: TClassifier,
|
|
438
|
+
opts: { teaching?: boolean; date?: (iso: string) => string } = {},
|
|
439
|
+
): { key: "teaching" | "collecting" | "sorting" | "ready" | "trained" | "changed"; title: string; color: string } {
|
|
440
|
+
const date = opts.date ?? ((iso: string) => new Date(iso).toLocaleDateString());
|
|
441
|
+
if (opts.teaching) return { key: "teaching", title: "Teaching...", color: "info" };
|
|
442
|
+
const t = c.training;
|
|
443
|
+
if (t?.trained) {
|
|
444
|
+
if (t.changedSinceTraining) return { key: "changed", title: "Changed since last teaching", color: "warning" };
|
|
445
|
+
return { key: "trained", title: t.lastTrainedAt ? `Trained on ${date(t.lastTrainedAt)}` : "Trained", color: "success" };
|
|
446
|
+
}
|
|
447
|
+
if (!teachProblem(c)) return { key: "ready", title: "Ready to teach", color: "primary" };
|
|
448
|
+
const waiting = c.waiting ?? 0;
|
|
449
|
+
if (waiting > 0) return { key: "sorting", title: `Needs sorting (${waiting} waiting)`, color: "warning" };
|
|
450
|
+
return { key: "collecting", title: "Collecting photos", color: "default" };
|
|
451
|
+
}
|