drone-path-archive 0.0.0 → 1.0.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/dist/export.js +3 -7
- package/dist/indexed-scan.js +2 -8
- package/dist/query.js +7 -17
- package/dist/store.d.ts +2 -0
- package/dist/store.js +23 -3
- package/package.json +2 -2
package/dist/export.js
CHANGED
|
@@ -10,14 +10,13 @@ import { kmzBytes } from 'drone-path-core/track-kmz';
|
|
|
10
10
|
import { archiveMapHtml } from './export-map.js';
|
|
11
11
|
import { groupFlightMembers } from './flight-members.js';
|
|
12
12
|
import { matchesMetadata } from './query.js';
|
|
13
|
-
import {
|
|
13
|
+
import { withArchiveStore } from './store.js';
|
|
14
14
|
function exportFlights(db, { filters = {}, redactLaunchM = 0, includeGaze = false }, splitDateline = false) {
|
|
15
15
|
if (!Number.isFinite(redactLaunchM) || redactLaunchM < 0) {
|
|
16
16
|
throw new Error('expected a nonnegative launch redaction radius in meters');
|
|
17
17
|
}
|
|
18
18
|
const redact = redactLaunchM > 0;
|
|
19
|
-
|
|
20
|
-
try {
|
|
19
|
+
return withArchiveStore(db, (store) => {
|
|
21
20
|
const { clips, endpoints } = store.readExportCandidates(filters.bbox, filters.availability, ({ record }) => matchesMetadata(record, filters), { redact, includeGaze: includeGaze && !redact });
|
|
22
21
|
const redactTrack = launchRedactor(endpoints, redactLaunchM);
|
|
23
22
|
const flights = groupFlightMembers(clips);
|
|
@@ -36,10 +35,7 @@ function exportFlights(db, { filters = {}, redactLaunchM = 0, includeGaze = fals
|
|
|
36
35
|
});
|
|
37
36
|
return selected.length > 0 ? [{ clips: selected }] : [];
|
|
38
37
|
});
|
|
39
|
-
}
|
|
40
|
-
finally {
|
|
41
|
-
store.close();
|
|
42
|
-
}
|
|
38
|
+
});
|
|
43
39
|
}
|
|
44
40
|
function writeExport(db, output, content) {
|
|
45
41
|
const resolved = (file) => fs.existsSync(file) ? fs.realpathSync(file) : path.resolve(file);
|
package/dist/indexed-scan.js
CHANGED
|
@@ -3,7 +3,7 @@ import path from 'node:path';
|
|
|
3
3
|
import { createSrtSidecarLookup } from 'drone-path-core/srt-sidecar';
|
|
4
4
|
import { decimateSegments, sampleSegments } from './scan-track.js';
|
|
5
5
|
import { discoverRecordings, scanRecordings } from './scanner.js';
|
|
6
|
-
import {
|
|
6
|
+
import { CLIP_FINGERPRINT_VERSION, withArchiveStoreAsync } from './store.js';
|
|
7
7
|
function isMissing(error) {
|
|
8
8
|
const code = error?.code;
|
|
9
9
|
return code === 'ENOENT' || code === 'ENOTDIR';
|
|
@@ -75,13 +75,7 @@ async function scanRoots(dirs, indexedPaths, { prune, recurse, signal }) {
|
|
|
75
75
|
return { roots, present };
|
|
76
76
|
}
|
|
77
77
|
export async function scanArchive(dirs, options) {
|
|
78
|
-
|
|
79
|
-
try {
|
|
80
|
-
return await indexFolders(store, dirs, options);
|
|
81
|
-
}
|
|
82
|
-
finally {
|
|
83
|
-
store.close();
|
|
84
|
-
}
|
|
78
|
+
return withArchiveStoreAsync(options.db, (store) => indexFolders(store, dirs, options));
|
|
85
79
|
}
|
|
86
80
|
async function indexFolders(store, dirs, options) {
|
|
87
81
|
const { signal, recurse, prune, onRecord } = options;
|
package/dist/query.js
CHANGED
|
@@ -3,7 +3,7 @@ import { nearestOnTrack, radiusBbox } from 'drone-path-core/spatial';
|
|
|
3
3
|
import { zonedTimeMs } from './camera-time.js';
|
|
4
4
|
import { groupFlightMembers } from './flight-members.js';
|
|
5
5
|
import { groupSamples } from './scan-track.js';
|
|
6
|
-
import {
|
|
6
|
+
import { withArchiveStore } from './store.js';
|
|
7
7
|
export { parseDateBound } from './camera-time.js';
|
|
8
8
|
export const DEFAULT_RADIUS_M = 100;
|
|
9
9
|
export function matchesMetadata(clip, { afterMs, beforeMs, minDistanceM }) {
|
|
@@ -21,16 +21,10 @@ function toClip({ record, availability }) {
|
|
|
21
21
|
return { ...record, availability };
|
|
22
22
|
}
|
|
23
23
|
function matchingClips(db, filters) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return
|
|
27
|
-
|
|
28
|
-
return matchesMetadata(clip, filters) ? [{ clip, flight: indexed.flight }] : [];
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
finally {
|
|
32
|
-
store.close();
|
|
33
|
-
}
|
|
24
|
+
return withArchiveStore(db, (store) => store.listClips(filters.bbox, filters.availability).flatMap((indexed) => {
|
|
25
|
+
const clip = toClip(indexed);
|
|
26
|
+
return matchesMetadata(clip, filters) ? [{ clip, flight: indexed.flight }] : [];
|
|
27
|
+
}));
|
|
34
28
|
}
|
|
35
29
|
export function listArchive(db, filters = {}) {
|
|
36
30
|
return matchingClips(db, filters).map(({ clip }) => clip);
|
|
@@ -42,8 +36,7 @@ export function listArchiveFlights(db, filters = {}) {
|
|
|
42
36
|
}));
|
|
43
37
|
}
|
|
44
38
|
export function nearArchive(db, point, radiusM = DEFAULT_RADIUS_M, includeGaze = false) {
|
|
45
|
-
|
|
46
|
-
try {
|
|
39
|
+
return withArchiveStore(db, (store) => {
|
|
47
40
|
const hits = [];
|
|
48
41
|
const { tracks, gaze } = store.readNearCandidates(radiusBbox(point, radiusM), includeGaze ? point : undefined);
|
|
49
42
|
for (const { clip, samples } of tracks) {
|
|
@@ -59,8 +52,5 @@ export function nearArchive(db, point, radiusM = DEFAULT_RADIUS_M, includeGaze =
|
|
|
59
52
|
}
|
|
60
53
|
// Stable sorting preserves clip-key order within each match type for equal distances.
|
|
61
54
|
return hits.sort((a, b) => a.distanceM - b.distanceM);
|
|
62
|
-
}
|
|
63
|
-
finally {
|
|
64
|
-
store.close();
|
|
65
|
-
}
|
|
55
|
+
});
|
|
66
56
|
}
|
package/dist/store.d.ts
CHANGED
|
@@ -80,3 +80,5 @@ export declare class ArchiveStore {
|
|
|
80
80
|
private writeClip;
|
|
81
81
|
private writeGaze;
|
|
82
82
|
}
|
|
83
|
+
export declare function withArchiveStore<T>(db: string, run: (store: ArchiveStore) => T): T;
|
|
84
|
+
export declare function withArchiveStoreAsync<T>(db: string, run: (store: ArchiveStore) => Promise<T>): Promise<T>;
|
package/dist/store.js
CHANGED
|
@@ -139,7 +139,10 @@ export class ArchiveStore {
|
|
|
139
139
|
return this.transaction('BEGIN', () => this.selectClipViewport(bbox, availability));
|
|
140
140
|
}
|
|
141
141
|
selectClipViewport(bbox, availability) {
|
|
142
|
-
|
|
142
|
+
const clips = this.selectClips(bbox, availability, false);
|
|
143
|
+
if (bbox === undefined)
|
|
144
|
+
return clips;
|
|
145
|
+
return clips.filter(({ key, record }) => {
|
|
143
146
|
const raw = record.bbox;
|
|
144
147
|
if (raw === null)
|
|
145
148
|
return false;
|
|
@@ -150,8 +153,7 @@ export class ArchiveStore {
|
|
|
150
153
|
}
|
|
151
154
|
readExportCandidates(bbox, availability, matches, options) {
|
|
152
155
|
return this.transaction('BEGIN', () => {
|
|
153
|
-
const clips =
|
|
154
|
-
this.selectClipViewport(bbox, availability)).filter(matches);
|
|
156
|
+
const clips = this.selectClipViewport(bbox, availability).filter(matches);
|
|
155
157
|
const endpoints = options.redact ? this.readLaunchEndpoints(new Set(clips.map(({ flight }) => flight.flightId))) : [];
|
|
156
158
|
const gaze = options.includeGaze ? this.db.prepare('SELECT samples_json FROM clip_gaze WHERE clip_key = ?') : undefined;
|
|
157
159
|
return {
|
|
@@ -334,3 +336,21 @@ export class ArchiveStore {
|
|
|
334
336
|
this.db.prepare('INSERT INTO clip_gaze VALUES (?, ?, ?, ?, ?, ?)').run(key, bbox?.minLat ?? null, bbox?.maxLat ?? null, bbox?.minLon ?? null, bbox?.maxLon ?? null, JSON.stringify(gaze));
|
|
335
337
|
}
|
|
336
338
|
}
|
|
339
|
+
export function withArchiveStore(db, run) {
|
|
340
|
+
const store = new ArchiveStore(db);
|
|
341
|
+
try {
|
|
342
|
+
return run(store);
|
|
343
|
+
}
|
|
344
|
+
finally {
|
|
345
|
+
store.close();
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
export async function withArchiveStoreAsync(db, run) {
|
|
349
|
+
const store = new ArchiveStore(db);
|
|
350
|
+
try {
|
|
351
|
+
return await run(store);
|
|
352
|
+
}
|
|
353
|
+
finally {
|
|
354
|
+
store.close();
|
|
355
|
+
}
|
|
356
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drone-path-archive",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Scan a local library of drone recordings.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"directory": "packages/archive"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"drone-path-core": "~1.0.0
|
|
32
|
+
"drone-path-core": "~1.0.0",
|
|
33
33
|
"leaflet": "~1.9.4",
|
|
34
34
|
"p-queue": "~10.0.0"
|
|
35
35
|
}
|