@trillboards/edge-sdk 0.2.267 → 0.2.276
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/deploy/detector/pyproject.toml +1 -1
- package/deploy/detector/tests/test_loader.py +1 -1
- package/deploy/detector/tests/test_staff_uniform.py +342 -0
- package/deploy/detector/trillboards_detector/_version.py +2 -2
- package/deploy/detector/trillboards_detector/loader.py +6 -0
- package/deploy/detector/trillboards_detector/registry.py +30 -1
- package/deploy/detector/trillboards_detector/server.py +43 -0
- package/deploy/detector/trillboards_detector/staff_uniform.py +190 -0
- package/deploy/detector/trillboards_detector/tasks.py +9 -1
- package/deploy/windows/build-windows.ps1 +3 -0
- package/deploy/windows/ci/test-published-install.ps1 +1 -1
- package/deploy/windows/e2e/test-recorder-family.ps1 +1 -1
- package/deploy/windows/process-priority.ps1 +229 -0
- package/dist/ActorPerception.d.ts.map +1 -1
- package/dist/ActorPerception.js +3 -1
- package/dist/ActorPerception.js.map +1 -1
- package/dist/AlertClips.d.ts +120 -0
- package/dist/AlertClips.d.ts.map +1 -1
- package/dist/AlertClips.js +296 -17
- package/dist/AlertClips.js.map +1 -1
- package/dist/AudienceAnalyzeClient.d.ts +34 -0
- package/dist/AudienceAnalyzeClient.d.ts.map +1 -1
- package/dist/AudienceAnalyzeClient.js +89 -15
- package/dist/AudienceAnalyzeClient.js.map +1 -1
- package/dist/CctvLiveViewCoordinator.d.ts +23 -2
- package/dist/CctvLiveViewCoordinator.d.ts.map +1 -1
- package/dist/CctvLiveViewCoordinator.js +50 -0
- package/dist/CctvLiveViewCoordinator.js.map +1 -1
- package/dist/ConnectorStatusClient.d.ts +8 -0
- package/dist/ConnectorStatusClient.d.ts.map +1 -1
- package/dist/ConnectorStatusClient.js +3 -0
- package/dist/ConnectorStatusClient.js.map +1 -1
- package/dist/DetectorFields.d.ts +114 -7
- package/dist/DetectorFields.d.ts.map +1 -1
- package/dist/DetectorFields.js +168 -43
- package/dist/DetectorFields.js.map +1 -1
- package/dist/EdgeAgent.js +1 -1
- package/dist/FloorObjects.d.ts +131 -8
- package/dist/FloorObjects.d.ts.map +1 -1
- package/dist/FloorObjects.js +396 -24
- package/dist/FloorObjects.js.map +1 -1
- package/dist/LocalDetectorClient.d.ts +21 -0
- package/dist/LocalDetectorClient.d.ts.map +1 -1
- package/dist/LocalDetectorClient.js +43 -0
- package/dist/LocalDetectorClient.js.map +1 -1
- package/dist/NativeReadiness.d.ts.map +1 -1
- package/dist/NativeReadiness.js +8 -3
- package/dist/NativeReadiness.js.map +1 -1
- package/dist/QueueDwell.d.ts +87 -0
- package/dist/QueueDwell.d.ts.map +1 -0
- package/dist/QueueDwell.js +167 -0
- package/dist/QueueDwell.js.map +1 -0
- package/dist/ScopedVlmReview.d.ts +21 -2
- package/dist/ScopedVlmReview.d.ts.map +1 -1
- package/dist/ScopedVlmReview.js +68 -10
- package/dist/ScopedVlmReview.js.map +1 -1
- package/dist/SensingProfileClient.d.ts +7 -0
- package/dist/SensingProfileClient.d.ts.map +1 -1
- package/dist/SensingProfileClient.js +1 -0
- package/dist/SensingProfileClient.js.map +1 -1
- package/dist/VideoSegmentUploader.d.ts +6 -0
- package/dist/VideoSegmentUploader.d.ts.map +1 -1
- package/dist/VideoSegmentUploader.js +31 -4
- package/dist/VideoSegmentUploader.js.map +1 -1
- package/dist/config.d.ts +8 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js.map +1 -1
- package/dist/connectorUpdate.d.ts +6 -0
- package/dist/connectorUpdate.d.ts.map +1 -1
- package/dist/connectorUpdate.js +8 -1
- package/dist/connectorUpdate.js.map +1 -1
- package/dist/diagnose.d.ts +1 -1
- package/dist/diagnose.js +1 -1
- package/dist/enterpriseNetwork.d.ts +9 -0
- package/dist/enterpriseNetwork.d.ts.map +1 -1
- package/dist/enterpriseNetwork.js +14 -0
- package/dist/enterpriseNetwork.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/localSensing.d.ts +29 -1
- package/dist/localSensing.d.ts.map +1 -1
- package/dist/localSensing.js +64 -6
- package/dist/localSensing.js.map +1 -1
- package/dist/mainThreadStall.d.ts +11 -0
- package/dist/mainThreadStall.d.ts.map +1 -1
- package/dist/mainThreadStall.js +35 -0
- package/dist/mainThreadStall.js.map +1 -1
- package/dist/pipelineSwitches.d.ts +61 -2
- package/dist/pipelineSwitches.d.ts.map +1 -1
- package/dist/pipelineSwitches.js +93 -15
- package/dist/pipelineSwitches.js.map +1 -1
- package/dist/processPriority.d.ts +75 -0
- package/dist/processPriority.d.ts.map +1 -0
- package/dist/processPriority.js +380 -0
- package/dist/processPriority.js.map +1 -0
- package/dist/sensingRunMode.d.ts.map +1 -1
- package/dist/sensingRunMode.js +22 -3
- package/dist/sensingRunMode.js.map +1 -1
- package/dist/vehicleEndWarmup.d.ts +60 -0
- package/dist/vehicleEndWarmup.d.ts.map +1 -0
- package/dist/vehicleEndWarmup.js +209 -0
- package/dist/vehicleEndWarmup.js.map +1 -0
- package/dist/windowsLiveView.d.ts +3 -1
- package/dist/windowsLiveView.d.ts.map +1 -1
- package/dist/windowsLiveView.js +2 -0
- package/dist/windowsLiveView.js.map +1 -1
- package/package.json +4 -4
- package/retained/RetainedCaptureClient.cjs +30 -4
- package/retained/__tests__/archive-lifecycle.test.cjs +44 -0
- package/retained/__tests__/held-frames.test.cjs +94 -0
- package/retained/__tests__/paired-theft-manager.test.cjs +24 -0
- package/retained/__tests__/queue-dwell.test.cjs +238 -0
- package/retained/__tests__/support/theft-builder.cjs +3 -1
- package/retained/held-frames.cjs +39 -0
- package/retained/manager.cjs +15 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// floor_object_left_v2's trail (retained/held-frames.cjs): the frames this camera's capture archive holds between the
|
|
3
|
+
// floor memory's last look and the look under review, as the connector hands them to the method.
|
|
4
|
+
const {test}=require('node:test'),assert=require('node:assert/strict');
|
|
5
|
+
const fs=require('node:fs'),os=require('node:os'),path=require('node:path'),crypto=require('node:crypto');
|
|
6
|
+
const {resolveHeldFrames}=require('../held-frames.cjs');
|
|
7
|
+
const {RetainedCaptureClient}=require('../RetainedCaptureClient.cjs');
|
|
8
|
+
const sha=b=>crypto.createHash('sha256').update(b).digest('hex');
|
|
9
|
+
|
|
10
|
+
// An archive of one camera's grabs every 500 ms from `from` to `to` (inclusive), linked by previousCaptureId as the
|
|
11
|
+
// capture client links them; each grab's bytes name its time.
|
|
12
|
+
function archiveOf(t,from,to,{camera='aisle_10',everyMs=500}={}){
|
|
13
|
+
const dir=fs.mkdtempSync(path.join(os.tmpdir(),'held-frames-'));t.after(()=>fs.rmSync(dir,{recursive:true,force:true}));
|
|
14
|
+
const records=new Map();let previous=null;
|
|
15
|
+
for(let at=from;at<=to;at+=everyMs){
|
|
16
|
+
const jpeg=Buffer.from(`grab ${at}`),r={id:`r${at}`,cameraId:camera,capturedAt:at,imageSha256:sha(jpeg),imageBytes:jpeg.length,
|
|
17
|
+
previousCaptureId:previous};
|
|
18
|
+
fs.writeFileSync(path.join(dir,r.imageSha256+'.jpg'),jpeg);records.set(r.id,r);previous=r.id;
|
|
19
|
+
}
|
|
20
|
+
return {records,image:r=>path.join(dir,r.imageSha256+'.jpg'),last:records.get(previous)};
|
|
21
|
+
}
|
|
22
|
+
const times=frames=>frames.map(f=>f.capturedAtMs);
|
|
23
|
+
|
|
24
|
+
test('a 30 s look gap: the last look\'s own frame first, then the grabs at least the pitch apart, oldest first',t=>{
|
|
25
|
+
const a=archiveOf(t,0,60000),current=a.last;
|
|
26
|
+
const held=resolveHeldFrames(a,current,30000,4000,16);
|
|
27
|
+
assert.deepEqual(times(held),[30000,34000,38000,42000,46000,50000,54000,58000]);
|
|
28
|
+
for(const h of held)assert.equal(h.jpeg.toString(),`grab ${h.capturedAtMs}`);
|
|
29
|
+
// The look under review is never among them.
|
|
30
|
+
assert(!times(held).includes(current.capturedAt));
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('a gap longer than maxFrames pitches holds: the pitch widens so the frames still span it',t=>{
|
|
34
|
+
const a=archiveOf(t,0,120000);
|
|
35
|
+
const held=resolveHeldFrames(a,a.last,0,4000,16);
|
|
36
|
+
assert.equal(held.length,16);
|
|
37
|
+
assert.equal(held[0].capturedAtMs,0);
|
|
38
|
+
for(let i=1;i<held.length;i++)assert(held[i].capturedAtMs-held[i-1].capturedAtMs>=7500);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('the walk stops where the archive no longer holds the chain, at another camera\'s grab or one out of order',t=>{
|
|
42
|
+
const a=archiveOf(t,0,40000);
|
|
43
|
+
a.records.delete('r20000');
|
|
44
|
+
assert.deepEqual(times(resolveHeldFrames(a,a.last,0,4000,16)),[20500,24500,28500,32500,36500]);
|
|
45
|
+
const b=archiveOf(t,0,40000);
|
|
46
|
+
b.records.get('r30000').cameraId='aisle_9';
|
|
47
|
+
assert.deepEqual(times(resolveHeldFrames(b,b.last,0,4000,16)),[30500,34500,38500]);
|
|
48
|
+
const c=archiveOf(t,0,40000);
|
|
49
|
+
c.records.get('r30000').capturedAt=45000;
|
|
50
|
+
assert.deepEqual(times(resolveHeldFrames(c,c.last,0,4000,16)),[30500,34500,38500]);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('a grab whose bytes no longer match its record is left out; a missing image is left out',t=>{
|
|
54
|
+
const a=archiveOf(t,0,40000);
|
|
55
|
+
fs.writeFileSync(a.image(a.records.get('r8000')),Buffer.from('rewritten'));
|
|
56
|
+
fs.rmSync(a.image(a.records.get('r16000')));
|
|
57
|
+
const held=times(resolveHeldFrames(a,a.last,0,4000,16));
|
|
58
|
+
assert(!held.includes(8000)&&!held.includes(16000));
|
|
59
|
+
assert.deepEqual(held,[0,4000,8500,12500,16500,20500,24500,28500,32500,36500]);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test('nothing to hand over: no look before, a since at or after the look, or bad numbers; never a throw',t=>{
|
|
63
|
+
const a=archiveOf(t,0,10000);
|
|
64
|
+
for(const args of [[10000,4000,16],[12000,4000,16],[-1.5,4000,16],[0,-1,16],[0,4000,0],[0,4000,1.5],[NaN,4000,16]])
|
|
65
|
+
assert.deepEqual(resolveHeldFrames(a,a.last,...args),[],JSON.stringify(args));
|
|
66
|
+
const broken={records:{get(){throw new Error('archive closed');}},image:a.image};
|
|
67
|
+
assert.deepEqual(resolveHeldFrames(broken,a.last,0,4000,16),[]);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('the capture client hands the review its own archive\'s held frames',async t=>{
|
|
71
|
+
const dir=fs.mkdtempSync(path.join(os.tmpdir(),'held-frames-client-'));t.after(()=>fs.rmSync(dir,{recursive:true,force:true}));
|
|
72
|
+
const requests=[];
|
|
73
|
+
const client={getEndpoint:()=> 'http://127.0.0.1:18791/v2/earner/audience-analyze',
|
|
74
|
+
async reviewCandidate(req){requests.push(req);req.checkpointAnalysis({version:1,evidenceSha256:sha(req.jpeg)});},
|
|
75
|
+
async analyze(req){return {ok:true,body:{accepted:true,evidenceId:req.evidenceId,evidenceReview:{version:1,capturedAtMs:req.capturedAt}}};}};
|
|
76
|
+
const archive=new RetainedCaptureClient(client,dir,{cameraId:'aisle_10',intervalMs:500,maxCaptures:200,maxBytes:50*1024**2,
|
|
77
|
+
archiveRetentionMs:600000});
|
|
78
|
+
const context={version:1,profileState:'active',prompt:'Held frames fixture.',
|
|
79
|
+
schema:{type:'object',properties:{floor:{type:'boolean'}},required:['floor']},
|
|
80
|
+
retainedFieldContract:{version:1,required:[{field:'floor',type:'boolean'}]},producerFields:[],regions:[],operatingPoints:[],
|
|
81
|
+
absenceWatchedFields:[]};
|
|
82
|
+
let current;
|
|
83
|
+
for(let at=1000;at<=31000;at+=500){
|
|
84
|
+
archive.retainOrderedCapture({name:'aisle_10',enqueuedAtMs:at,jpeg:Buffer.from(`grab ${at}`),reviewContext:context});
|
|
85
|
+
current=archive.previousCaptureRecord;
|
|
86
|
+
}
|
|
87
|
+
await archive.analyze({evidenceId:current.id,capturedAt:current.capturedAt,jpeg:Buffer.from(`grab ${current.capturedAt}`),
|
|
88
|
+
reviewContext:context,checkpointAnalysis(){}});
|
|
89
|
+
const req=requests.at(-1);
|
|
90
|
+
assert.equal(typeof req.resolveHeldFrames,'function');
|
|
91
|
+
const held=req.resolveHeldFrames(1000,4000,16);
|
|
92
|
+
assert.deepEqual(times(held),[1000,5000,9000,13000,17000,21000,25000,29000]);
|
|
93
|
+
assert.equal(held[3].jpeg.toString(),'grab 13000');
|
|
94
|
+
});
|
|
@@ -99,6 +99,30 @@ async function fixture({enabled=true,positive=true,live=false}={}) {
|
|
|
99
99
|
return {directory,input,deps,state,registration,runtime,build,refresh,retain,capture,baseTime,api};
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
+
test('Queue & Dwell is optional and binds only the named website camera', async () => {
|
|
103
|
+
const f = await fixture({enabled:false});
|
|
104
|
+
const off = await f.build();
|
|
105
|
+
assert.deepEqual(off.clients.map(client=>client.queueDwellRecorder),[undefined,undefined]);
|
|
106
|
+
const ordinaryContext=off.clients[0].captureReviewContext();
|
|
107
|
+
f.input.pilot.queueDwell={
|
|
108
|
+
version:1,cameraId:f.input.cameras[0].screenId,routeId:'queue_route',zoneId:'queue',zoneRevision:'1',
|
|
109
|
+
zoneName:'Paint counter',thresholdMs:120000,maxGapMs:3000,
|
|
110
|
+
points:[{x:.2,y:.2},{x:.8,y:.2},{x:.8,y:.8},{x:.2,y:.8}],
|
|
111
|
+
};
|
|
112
|
+
const on=await f.build();
|
|
113
|
+
assert.equal(on.clients[0].queueDwellRecorder.rule.zoneName,'Paint counter');
|
|
114
|
+
assert.equal(on.clients[1].queueDwellRecorder,undefined);
|
|
115
|
+
assert.deepEqual(on.clients[0].captureReviewContext().modelSelection,ordinaryContext.modelSelection);
|
|
116
|
+
assert.equal(f.state.opens,0);
|
|
117
|
+
assert.equal(f.state.detects,0);
|
|
118
|
+
const errors=[];
|
|
119
|
+
f.deps.onQueueDwellError=error=>errors.push(error.message);
|
|
120
|
+
f.input.pilot.queueDwell.cameraId='another-camera';
|
|
121
|
+
const wrongCamera=await f.build();
|
|
122
|
+
assert.deepEqual(wrongCamera.clients.map(client=>client.queueDwellRecorder),[undefined,undefined]);
|
|
123
|
+
assert.equal(errors.length,1);
|
|
124
|
+
});
|
|
125
|
+
|
|
102
126
|
test('live shelf profile selection starts case review and switching away stops it without affecting the other camera', async () => {
|
|
103
127
|
const f = await fixture({live:true}), r = await f.build();
|
|
104
128
|
const client = r.clients[0], peer = r.clients[1];
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const assert = require('node:assert/strict');
|
|
4
|
+
const {execFileSync} = require('node:child_process');
|
|
5
|
+
const {createHash} = require('node:crypto');
|
|
6
|
+
const {readFileSync, mkdtempSync, rmSync, writeFileSync} = require('node:fs');
|
|
7
|
+
const {tmpdir} = require('node:os');
|
|
8
|
+
const {join} = require('node:path');
|
|
9
|
+
const {test} = require('node:test');
|
|
10
|
+
const {ActorPerceptionClient} = require('../../dist/ActorPerception');
|
|
11
|
+
const {actorProofHash} = require('../../dist/ActorTracking');
|
|
12
|
+
const {QueueDwellRecorder, QueueDwellTimer} = require('../../dist/QueueDwell');
|
|
13
|
+
const {readJpegFrameSize} = require('../../dist/jpegFrameSize');
|
|
14
|
+
const {replayQueueDwell} = require('../../scripts/queue-dwell-replay.cjs');
|
|
15
|
+
const {WebsiteAdmissionCaptureClient} = require('../WebsiteAdmissionCaptureClient.cjs');
|
|
16
|
+
|
|
17
|
+
const jpeg = readFileSync(join(__dirname, '../../src/__tests__/fixtures/cctv-cstore-empty.jpg'));
|
|
18
|
+
const frameSize = readJpegFrameSize(jpeg);
|
|
19
|
+
const imageSha256 = createHash('sha256').update(jpeg).digest('hex');
|
|
20
|
+
const detector = {modelId: 'rfdetr_medium', sha256: '8e8197112112b79d7cc5d0a94ecef659c05317a658aadc7c7643374c539d7615'};
|
|
21
|
+
const modelHashes = {[detector.modelId]: detector.sha256};
|
|
22
|
+
const policy = {version: 1, cameraId: 'camera_1', sourceId: 'front_stream', detector, minConfidence: 0.25};
|
|
23
|
+
const rule = {
|
|
24
|
+
version: 1, cameraId: policy.cameraId, routeId: 'route_1', zoneId: 'queue', zoneRevision: '1',
|
|
25
|
+
zoneName: 'Paint counter', thresholdMs: 120000, maxGapMs: 3000,
|
|
26
|
+
points: [{x: 0.25, y: 0.4}, {x: 0.75, y: 0.4}, {x: 0.75, y: 0.75}, {x: 0.25, y: 0.75}],
|
|
27
|
+
};
|
|
28
|
+
const inside = {x: 290, y: 110, width: 60, height: 150};
|
|
29
|
+
const outside = {x: 530, y: 110, width: 60, height: 150};
|
|
30
|
+
const actor = (id, epoch) => ({kind: 'person', cameraId: policy.cameraId, id, epoch});
|
|
31
|
+
|
|
32
|
+
function wire(request, {people = [], unconfirmed = [], ended = [], epoch = 'epoch_1',
|
|
33
|
+
continuity = 'continued', includeTracks = true} = {}) {
|
|
34
|
+
const detections = [...people.map(([, box]) => box), ...unconfirmed].map(box => ({label: 'person', box, confidence: 0.9}));
|
|
35
|
+
const actors = people.map(([id], detectionIndex) => ({detectionIndex, actor: actor(id, epoch)}));
|
|
36
|
+
const tracking = {
|
|
37
|
+
...request, epoch, continuity, actors, algorithm: 'bytetrack_2.6.1', imageSha256, modelHashes,
|
|
38
|
+
contextSha256: '1'.repeat(64),
|
|
39
|
+
unconfirmed: unconfirmed.map((_, index) => people.length + index),
|
|
40
|
+
endedActors: ended.map(id => actor(id, epoch)),
|
|
41
|
+
};
|
|
42
|
+
tracking.sha256 = actorProofHash(tracking);
|
|
43
|
+
const tracks = actors.map(({actor, detectionIndex}) => ({
|
|
44
|
+
version: 1, actorId: actor.id, kind: 'person', epoch, firstSeenAtMs: request.capturedAtMs,
|
|
45
|
+
lastSeenAtMs: request.capturedAtMs, frames: 1, box: detections[detectionIndex].box,
|
|
46
|
+
confidence: 0.9, face: null,
|
|
47
|
+
}));
|
|
48
|
+
return {detections, inference_ms: 40, model: detector.modelId, model_hashes: modelHashes, tracking,
|
|
49
|
+
...(includeTracks ? {tracks} : {})};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function observe(timer, at, people, options = {}) {
|
|
53
|
+
const reply = wire({
|
|
54
|
+
version: 1, cameraId: policy.cameraId, sourceId: options.sourceId || policy.sourceId,
|
|
55
|
+
frameId: options.frameId || 'frame_' + at, capturedAtMs: at,
|
|
56
|
+
}, {people, ...options});
|
|
57
|
+
return timer.observe({result: {tracking: reply.tracking, detections: reply.detections}}, frameSize);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
test('the 120-second replay crosses the detector contract and retained archive even with no semantic review', async t => {
|
|
61
|
+
const directory = mkdtempSync(join(tmpdir(), 'queue-dwell-'));
|
|
62
|
+
t.after(() => rmSync(directory, {recursive: true, force: true}));
|
|
63
|
+
const attempted = [];
|
|
64
|
+
let retry = true;
|
|
65
|
+
const perceiver = new ActorPerceptionClient(policy, {poster: async (_url, _options, body) => {
|
|
66
|
+
const {tracking} = JSON.parse(body);
|
|
67
|
+
attempted.push(tracking.capturedAtMs);
|
|
68
|
+
if (retry) {
|
|
69
|
+
retry = false;
|
|
70
|
+
return {statusCode: 503, body: '{}'};
|
|
71
|
+
}
|
|
72
|
+
const sec = (tracking.capturedAtMs - 1000000) / 1000;
|
|
73
|
+
const people = [];
|
|
74
|
+
if (sec >= 2) people.push(['a', sec === 126 ? outside : inside]);
|
|
75
|
+
if (sec >= 84 && sec <= 90) people.push(['b', sec === 90 ? outside : inside]);
|
|
76
|
+
const reply = wire(tracking, {
|
|
77
|
+
people, unconfirmed: sec === 0 ? [inside] : [], includeTracks: sec !== 2,
|
|
78
|
+
continuity: sec === 0 ? 'start' : 'continued',
|
|
79
|
+
});
|
|
80
|
+
return {statusCode: 200, body: JSON.stringify(reply)};
|
|
81
|
+
}});
|
|
82
|
+
const unusedReceiver = {getEndpoint: () => 'http://127.0.0.1:18791/v2/earner/audience-analyze'};
|
|
83
|
+
const options = {cameraId: 'capture_feed_1', pairedCameraId: policy.cameraId, reviewStage: () => null, actorPerceiver: perceiver};
|
|
84
|
+
const start = () => new WebsiteAdmissionCaptureClient(unusedReceiver, directory, {
|
|
85
|
+
...options, queueDwellRecorder: new QueueDwellRecorder(rule),
|
|
86
|
+
});
|
|
87
|
+
let archive = start();
|
|
88
|
+
for (let sec = 0; sec <= 128; sec += 2) {
|
|
89
|
+
archive.retainOrderedCapture({
|
|
90
|
+
name: options.cameraId, enqueuedAtMs: 1000000 + sec * 1000, jpeg, reviewContext: {version: 1},
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
await assert.rejects(archive.perceiveNextOrderedCapture(), /HTTP 503/);
|
|
94
|
+
archive.perceptionPending.values().next().value.actorPerceptionFailure.retryAtMs = 0;
|
|
95
|
+
for (let i = 0; i < 65; i++) {
|
|
96
|
+
assert.equal(await archive.perceiveNextOrderedCapture(), true);
|
|
97
|
+
if (i === 30 || i === 61) archive = start();
|
|
98
|
+
}
|
|
99
|
+
assert.equal(await archive.perceiveNextOrderedCapture(), false);
|
|
100
|
+
assert.deepEqual(attempted, [1000000, ...Array.from({length: 65}, (_, i) => 1000000 + i * 2000)]);
|
|
101
|
+
assert.deepEqual(archive.pendingOrderedCandidates(), []);
|
|
102
|
+
const report = replayQueueDwell(directory, rule);
|
|
103
|
+
assert.deepEqual(report.coverage, {
|
|
104
|
+
captures: 65, trackedCaptures: 65, missingPerception: 0, capturesWithConfirmedActors: 64,
|
|
105
|
+
trackedWithoutSemanticReview: 65, trackedSampleGaps: 64, p50GapMs: 2000, p95GapMs: 2000, maxGapMs: 2000,
|
|
106
|
+
});
|
|
107
|
+
assert.equal(report.thresholdEvents.length, 1);
|
|
108
|
+
const [fired] = report.thresholdEvents;
|
|
109
|
+
const recorded = Array.from(archive.records.values()).flatMap(row => row.queueDwell.transitions);
|
|
110
|
+
assert.deepEqual(recorded.filter(transition => transition.kind === 'threshold_reached').map(transition => transition.visit), [fired]);
|
|
111
|
+
assert.equal(fired.trackId, 'a');
|
|
112
|
+
assert.equal(fired.entry.capturedAtMs, 1002000);
|
|
113
|
+
assert.equal(fired.threshold.capturedAtMs, 1122000);
|
|
114
|
+
assert.equal(fired.observedDurationMs, 120000);
|
|
115
|
+
assert.equal(fired.end, null);
|
|
116
|
+
const [short, finished, reentered] = report.endedVisits;
|
|
117
|
+
assert.equal(short.trackId, 'b');
|
|
118
|
+
assert.equal(short.threshold, null);
|
|
119
|
+
assert.equal(finished.visitId, fired.visitId);
|
|
120
|
+
assert.deepEqual(finished.threshold, fired.threshold);
|
|
121
|
+
assert.equal(finished.lastInZone.capturedAtMs, 1124000);
|
|
122
|
+
assert.equal(finished.end.exit.capturedAtMs, 1126000);
|
|
123
|
+
assert.equal(finished.observedDurationMs, 122000);
|
|
124
|
+
assert.equal(reentered.entry.capturedAtMs, 1128000);
|
|
125
|
+
assert.equal(reentered.end.reason, 'replay_ended');
|
|
126
|
+
assert.notEqual(reentered.visitId, fired.visitId);
|
|
127
|
+
assert.deepEqual(recorded.filter(transition => transition.kind === 'visit_ended').map(transition => transition.visit), [short, finished]);
|
|
128
|
+
const ruleFile = join(directory, 'queue-dwell-rule.json');
|
|
129
|
+
writeFileSync(ruleFile, JSON.stringify(rule));
|
|
130
|
+
const replayed = execFileSync(process.execPath, [
|
|
131
|
+
join(__dirname, '../../scripts/queue-dwell-replay.cjs'), directory, ruleFile,
|
|
132
|
+
], {encoding: 'utf8'});
|
|
133
|
+
assert.deepEqual(JSON.parse(replayed), report);
|
|
134
|
+
const gateOff = new WebsiteAdmissionCaptureClient(unusedReceiver, directory, options);
|
|
135
|
+
assert.deepEqual(gateOff.stats(), archive.stats());
|
|
136
|
+
assert.equal(gateOff.hasPendingOrderedPerception(), false);
|
|
137
|
+
|
|
138
|
+
const decidingRow = archive.records.get(fired.threshold.frameId);
|
|
139
|
+
const decidingFile = archive.file(decidingRow.id);
|
|
140
|
+
const originalRow = JSON.parse(readFileSync(decidingFile, 'utf8'));
|
|
141
|
+
writeFileSync(decidingFile, JSON.stringify({...originalRow, actorPerception: undefined}));
|
|
142
|
+
const incomplete = replayQueueDwell(directory, rule);
|
|
143
|
+
assert.equal(incomplete.coverage.missingPerception, 1);
|
|
144
|
+
assert.equal(incomplete.thresholdEvents.length, 0);
|
|
145
|
+
assert.ok(incomplete.endedVisits.some(visit => visit.end.reason === 'perception_missing'));
|
|
146
|
+
writeFileSync(decidingFile, JSON.stringify({...originalRow, imageSha256: '0'.repeat(64)}));
|
|
147
|
+
assert.throws(() => replayQueueDwell(directory, rule), /ENOENT|image digest changed/);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
test('a failed dwell calculation and a default-off archive leave original perception and review unchanged', async t => {
|
|
151
|
+
for (const brokenRecording of [false, true]) {
|
|
152
|
+
const directory = mkdtempSync(join(tmpdir(), 'queue-dwell-disabled-'));
|
|
153
|
+
t.after(() => rmSync(directory, {recursive: true, force: true}));
|
|
154
|
+
const perceiver = new ActorPerceptionClient(policy, {poster: async (_url, _options, body) => ({
|
|
155
|
+
statusCode: 200, body: JSON.stringify(wire(JSON.parse(body).tracking, {people: [['p', inside]]})),
|
|
156
|
+
})});
|
|
157
|
+
const errors = [];
|
|
158
|
+
const archive = new WebsiteAdmissionCaptureClient({
|
|
159
|
+
getEndpoint: () => 'http://127.0.0.1:18791/v2/earner/audience-analyze',
|
|
160
|
+
}, directory, {
|
|
161
|
+
cameraId: 'capture_feed_1', pairedCameraId: policy.cameraId, actorPerceiver: perceiver,
|
|
162
|
+
...(brokenRecording ? {
|
|
163
|
+
queueDwellRecorder: {prepare() { throw new Error('dwell fixture failure'); }},
|
|
164
|
+
onQueueDwellError(error) { errors.push(error.message); },
|
|
165
|
+
} : {}),
|
|
166
|
+
});
|
|
167
|
+
archive.retainOrderedCapture({name: 'capture_feed_1', enqueuedAtMs: 1000000, jpeg, reviewContext: {version: 1}});
|
|
168
|
+
assert.equal(await archive.perceiveNextOrderedCapture(), true);
|
|
169
|
+
assert.equal(archive.previousCaptureRecord.queueDwell, undefined);
|
|
170
|
+
assert.ok(archive.previousCaptureRecord.actorPerception);
|
|
171
|
+
assert.equal(archive.stats().actorPerception.pending, 0);
|
|
172
|
+
assert.equal(archive.pendingOrderedCandidates().length, 1);
|
|
173
|
+
assert.deepEqual(errors, brokenRecording ? ['dwell fixture failure'] : []);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test('one physical track can qualify once on each observed re-entry', () => {
|
|
178
|
+
const timer = new QueueDwellTimer({...rule, thresholdMs: 1000});
|
|
179
|
+
assert.deepEqual(observe(timer, 0, [['p', outside]]), []);
|
|
180
|
+
assert.deepEqual(observe(timer, 1000, [['p', inside]]), []);
|
|
181
|
+
assert.deepEqual(observe(timer, 1900, [['p', inside]]), []);
|
|
182
|
+
const [first] = observe(timer, 2000, [['p', inside]]);
|
|
183
|
+
assert.deepEqual(observe(timer, 2000, [['p', inside]]), []);
|
|
184
|
+
assert.throws(() => observe(timer, 2000, [['p', inside]], {frameId: 'different'}), /order conflict/);
|
|
185
|
+
assert.throws(() => observe(timer, 1900, [['p', inside]]), /order conflict/);
|
|
186
|
+
assert.deepEqual(observe(timer, 3000, [['p', inside]]), []);
|
|
187
|
+
const [end] = observe(timer, 4000, [['p', outside]]);
|
|
188
|
+
assert.equal(end.visit.end.status, 'complete');
|
|
189
|
+
assert.deepEqual(end.visit.threshold, first.visit.threshold);
|
|
190
|
+
observe(timer, 5000, [['p', inside]]);
|
|
191
|
+
const [second] = observe(timer, 6000, [['p', inside]]);
|
|
192
|
+
assert.notEqual(first.visit.visitId, second.visit.visitId);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
test('an unconfirmed detection cannot count, and a gap cannot turn a later outside box into an exit', () => {
|
|
196
|
+
const timer = new QueueDwellTimer({...rule, thresholdMs: 2000});
|
|
197
|
+
observe(timer, 1000, [['p', inside]]);
|
|
198
|
+
assert.deepEqual(observe(timer, 3000, [], {unconfirmed: [inside]}), []);
|
|
199
|
+
const [gap] = observe(timer, 4001, [['p', outside]]);
|
|
200
|
+
assert.equal(gap.visit.end.reason, 'observation_gap');
|
|
201
|
+
assert.equal(gap.visit.observedDurationMs, 0);
|
|
202
|
+
assert.equal(gap.visit.threshold, null);
|
|
203
|
+
observe(timer, 5000, [['p', inside]]);
|
|
204
|
+
observe(timer, 6000, [], {unconfirmed: [inside]});
|
|
205
|
+
assert.equal(observe(timer, 7000, [['p', inside]])[0].kind, 'threshold_reached');
|
|
206
|
+
assert.equal(observe(timer, 8000, [], {ended: ['p']})[0].visit.end.reason, 'track_ended');
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
test('tracker epoch, source, and zone revisions cannot carry dwell across a boundary', () => {
|
|
210
|
+
const settings = {...rule, thresholdMs: 2000};
|
|
211
|
+
const timer = new QueueDwellTimer(settings);
|
|
212
|
+
observe(timer, 1000, [['p', inside]]);
|
|
213
|
+
const [reset] = observe(timer, 3000, [['p', inside]], {epoch: 'epoch_2', continuity: 'recovery_reset'});
|
|
214
|
+
assert.equal(reset.visit.end.reason, 'tracker_changed');
|
|
215
|
+
assert.equal(reset.visit.threshold, null);
|
|
216
|
+
const [source] = observe(timer, 5000, [['p', inside]], {sourceId: 'camera_reconnected', epoch: 'epoch_2'});
|
|
217
|
+
assert.equal(source.visit.end.reason, 'source_changed');
|
|
218
|
+
const [edited] = timer.configure({...settings, zoneRevision: '2'}, {frameId: 'change', capturedAtMs: 6000, imageSha256});
|
|
219
|
+
assert.equal(edited.visit.end.reason, 'rule_changed');
|
|
220
|
+
assert.equal(edited.visit.zoneRevision, '1');
|
|
221
|
+
assert.deepEqual(observe(timer, 7000, [['p', inside]], {sourceId: 'camera_reconnected', epoch: 'epoch_2'}), []);
|
|
222
|
+
const [threshold] = observe(timer, 9000, [['p', inside]], {sourceId: 'camera_reconnected', epoch: 'epoch_2'});
|
|
223
|
+
assert.equal(threshold.visit.zoneRevision, '2');
|
|
224
|
+
assert.equal(threshold.visit.entry.capturedAtMs, 7000);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
test('the bottom centre must be in the drawn concave polygon, including on its edge', () => {
|
|
228
|
+
const timer = new QueueDwellTimer({...rule, thresholdMs: 1000, points: [
|
|
229
|
+
{x: 0.2, y: 0.2}, {x: 0.8, y: 0.2}, {x: 0.8, y: 0.5},
|
|
230
|
+
{x: 0.5, y: 0.5}, {x: 0.5, y: 0.8}, {x: 0.2, y: 0.8},
|
|
231
|
+
]});
|
|
232
|
+
const edge = {x: 300, y: 50, width: 40, height: 210};
|
|
233
|
+
const notch = {x: 310, y: 50, width: 40, height: 210};
|
|
234
|
+
observe(timer, 1000, [['edge', edge], ['notch', notch]]);
|
|
235
|
+
const events = observe(timer, 2000, [['edge', edge], ['notch', notch]]);
|
|
236
|
+
assert.deepEqual(events.map(event => event.visit.trackId), ['edge']);
|
|
237
|
+
assert.throws(() => new QueueDwellTimer({...rule, points: [rule.points[0], rule.points[1], rule.points[0]]}), /polygon/);
|
|
238
|
+
});
|
|
@@ -31,7 +31,9 @@ function fixture(options={}) {
|
|
|
31
31
|
if(request==='./CloudSensingManager')return {resolveFeeds:config=>config.cameras??[]};
|
|
32
32
|
if(request==='./continuousReview')return {retainedReviewApiBase:(_review,base)=>base};
|
|
33
33
|
if(request==='./dataDir')return {resolveDataDir:value=>value};
|
|
34
|
-
if(request==='./mainThreadStall')
|
|
34
|
+
if(request==='./mainThreadStall'){const start=settings=>{stallClocks.push(settings);return ()=>undefined;};
|
|
35
|
+
return {startMainThreadStallClock:start,runMainThreadStallClockUnderSwitch:start};}
|
|
36
|
+
if(request==='./processPriority')return {startProcessPriority:()=>()=>undefined};
|
|
35
37
|
if(request==='./RecorderAddressRecovery')return {RecorderAddressRecovery:class {async recover(){return null;}}};
|
|
36
38
|
if(request==='../retained/manager.cjs')return {createWebsiteManager:async(...args)=>{
|
|
37
39
|
factoryCalls.push(args);if(options.factoryError)throw options.factoryError;return {manager};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const fs=require('node:fs'),crypto=require('node:crypto');
|
|
3
|
+
const hash=bytes=>crypto.createHash('sha256').update(bytes).digest('hex');
|
|
4
|
+
/**
|
|
5
|
+
* floor_object_left_v2's trail (edge-sdk src/FloorObjects.ts): this camera's own frames from sinceMs (the floor
|
|
6
|
+
* memory's last look, whose own frame comes first while the archive still holds it) up to the look under review, at
|
|
7
|
+
* least pitchMs apart, oldest first, at most maxFrames (a longer gap widens the pitch to fit). The archive keeps every
|
|
8
|
+
* grab (intervalMs, 0.5 s) for archiveRetentionMs (10 min), linked by previousCaptureId, so a 30 s look gap holds ~60
|
|
9
|
+
* grabs and a 4 s pitch hands the method 8. The walk stops at the first record the archive no longer holds, another
|
|
10
|
+
* camera's, or one out of capture order; a frame whose bytes no longer match its record is left out. Never throws: the
|
|
11
|
+
* trail is evidence for the method, never a reason to fail the look.
|
|
12
|
+
*/
|
|
13
|
+
function resolveHeldFrames(archive,current,sinceMs,pitchMs,maxFrames){
|
|
14
|
+
if(!Number.isSafeInteger(sinceMs)||!(sinceMs<current.capturedAt)||!Number.isSafeInteger(pitchMs)||pitchMs<0
|
|
15
|
+
||!Number.isSafeInteger(maxFrames)||maxFrames<1)return [];
|
|
16
|
+
const chain=[];
|
|
17
|
+
try{
|
|
18
|
+
let id=current.previousCaptureId,lastAt=current.capturedAt,walked=0;
|
|
19
|
+
while(id&&walked++<4096){
|
|
20
|
+
const r=archive.records.get(id);
|
|
21
|
+
if(!r||r.cameraId!==current.cameraId||!(r.capturedAt<lastAt)||r.capturedAt<sinceMs)break;
|
|
22
|
+
chain.push(r);lastAt=r.capturedAt;id=r.previousCaptureId;
|
|
23
|
+
}
|
|
24
|
+
}catch{return [];}
|
|
25
|
+
chain.reverse();
|
|
26
|
+
if(!chain.length)return [];
|
|
27
|
+
const pitch=Math.max(pitchMs,Math.ceil((current.capturedAt-chain[0].capturedAt)/maxFrames));
|
|
28
|
+
const out=[];
|
|
29
|
+
for(const r of chain){
|
|
30
|
+
if(out.length&&r.capturedAt-out[out.length-1].capturedAtMs<pitch)continue;
|
|
31
|
+
let jpeg;
|
|
32
|
+
try{jpeg=fs.readFileSync(archive.image(r));}catch{continue;}
|
|
33
|
+
if(jpeg.length!==r.imageBytes||hash(jpeg)!==r.imageSha256)continue;
|
|
34
|
+
out.push({capturedAtMs:r.capturedAt,jpeg});
|
|
35
|
+
if(out.length>=maxFrames)break;
|
|
36
|
+
}
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
39
|
+
module.exports={resolveHeldFrames};
|
package/retained/manager.cjs
CHANGED
|
@@ -97,6 +97,20 @@ async function createWebsiteManager(input, stateDirectory, deps = {}) {
|
|
|
97
97
|
// does not start capture, submit historical images, or change account settings.
|
|
98
98
|
for (const feed of feeds) capabilities.set(feed.name, await (deps.capabilityCheck ?? checkRetainedApi)(base, feed));
|
|
99
99
|
const bindings = new Map(feeds.map(feed => [feed.name, captureBinding(feed, capabilities.get(feed.name).cameraId)]));
|
|
100
|
+
let queueDwellFeed = null;
|
|
101
|
+
let queueDwellRecorder = null;
|
|
102
|
+
if (websiteManaged && config.pilot.queueDwell !== undefined) {
|
|
103
|
+
try {
|
|
104
|
+
const recorder = new (take('QueueDwell').QueueDwellRecorder)(config.pilot.queueDwell);
|
|
105
|
+
const eligible = Array.from(bindings).filter(([name, binding]) =>
|
|
106
|
+
binding.cameraId === recorder.rule.cameraId && !theftRegistrations.has(name));
|
|
107
|
+
assert.equal(eligible.length, 1, 'Queue & Dwell requires one paired camera using the standard archive');
|
|
108
|
+
queueDwellFeed = eligible[0][0];
|
|
109
|
+
queueDwellRecorder = recorder;
|
|
110
|
+
} catch (error) {
|
|
111
|
+
deps.onQueueDwellError?.(error);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
100
114
|
const liveBinding = theftModule ? require('./LiveTheftBinding.cjs') : null;
|
|
101
115
|
// One live-alert age bound: the value the server suppresses late alerts with
|
|
102
116
|
// (SENSING_LOCAL_MAX_CAPTURE_AGE_MS), or this connector's review window when
|
|
@@ -245,6 +259,7 @@ async function createWebsiteManager(input, stateDirectory, deps = {}) {
|
|
|
245
259
|
...(websiteManaged ? { liveLookIntervalMs: LIVE_LOOK_INTERVAL_MS } : {}),
|
|
246
260
|
...(theftRoute ? {actorPerceiver: theftRoute.perceiver, perceptionSink: theftRoute.sink, theftRoute}
|
|
247
261
|
: rule.mode==='immediate'?{actorPerceiver:new SelectedActorPerceptionClient(binding)}:{}),
|
|
262
|
+
...(loop.name === queueDwellFeed ? {queueDwellRecorder, onQueueDwellError: deps.onQueueDwellError} : {}),
|
|
248
263
|
onOfferStall: report => offerStallSink(loop.name, report),
|
|
249
264
|
// Plan v7 W8: a frame a model answered directly becomes the frame later captures are judged
|
|
250
265
|
// against for look reuse (FrameGroupingShadow.noteReviewed). Bound once the manager exists.
|