@blueharford/scrypted-spatial-awareness 0.6.6 → 0.6.7

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/out/plugin.zip CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blueharford/scrypted-spatial-awareness",
3
- "version": "0.6.6",
3
+ "version": "0.6.7",
4
4
  "description": "Cross-camera object tracking for Scrypted NVR with spatial awareness",
5
5
  "author": "Joshua Seidel <blueharford>",
6
6
  "license": "Apache-2.0",
package/src/main.ts CHANGED
@@ -1584,7 +1584,7 @@ export class SpatialAwarenessPlugin extends ScryptedDeviceBase
1584
1584
  }
1585
1585
  }
1586
1586
 
1587
- private handleTrainingEndRequest(response: HttpResponse): void {
1587
+ private async handleTrainingEndRequest(response: HttpResponse): Promise<void> {
1588
1588
  if (!this.trackingEngine) {
1589
1589
  response.send(JSON.stringify({ error: 'Tracking engine not running' }), {
1590
1590
  code: 500,
@@ -1595,6 +1595,44 @@ export class SpatialAwarenessPlugin extends ScryptedDeviceBase
1595
1595
 
1596
1596
  const session = this.trackingEngine.endTrainingSession();
1597
1597
  if (session) {
1598
+ // Get unique visited cameras
1599
+ const visitedCameraIds = [...new Set(session.visits.map(v => v.cameraId))];
1600
+
1601
+ // Auto-run discovery on visited cameras to detect landmarks and zones
1602
+ if (this.discoveryEngine && visitedCameraIds.length > 0) {
1603
+ this.console.log(`[Training] Running discovery analysis on ${visitedCameraIds.length} visited cameras...`);
1604
+
1605
+ let landmarksFound = 0;
1606
+ let zonesFound = 0;
1607
+
1608
+ for (const cameraId of visitedCameraIds) {
1609
+ try {
1610
+ const analysis = await this.discoveryEngine.analyzeScene(cameraId);
1611
+ if (analysis.isValid) {
1612
+ landmarksFound += analysis.landmarks.length;
1613
+ zonesFound += analysis.zones.length;
1614
+ this.console.log(`[Training] ${cameraId}: Found ${analysis.landmarks.length} landmarks, ${analysis.zones.length} zones`);
1615
+ }
1616
+ } catch (e) {
1617
+ this.console.warn(`[Training] Failed to analyze ${cameraId}:`, e);
1618
+ }
1619
+ }
1620
+
1621
+ // Get all pending suggestions and auto-accept them
1622
+ const suggestions = this.discoveryEngine.getPendingSuggestions();
1623
+ for (const suggestion of suggestions) {
1624
+ this.applyDiscoverySuggestion(suggestion);
1625
+ this.discoveryEngine.acceptSuggestion(suggestion.id);
1626
+ }
1627
+
1628
+ // Persist topology after applying suggestions
1629
+ if (suggestions.length > 0 && this.trackingEngine) {
1630
+ const updatedTopology = this.trackingEngine.getTopology();
1631
+ await this.storageSettings.putSetting('topology', JSON.stringify(updatedTopology));
1632
+ this.console.log(`[Training] Auto-applied ${suggestions.length} discoveries (${landmarksFound} landmarks, ${zonesFound} zones)`);
1633
+ }
1634
+ }
1635
+
1598
1636
  response.send(JSON.stringify(session), {
1599
1637
  headers: { 'Content-Type': 'application/json' },
1600
1638
  });