drone-path-archive 1.2.0 → 1.2.1
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/query.d.ts +1 -0
- package/dist/query.js +25 -14
- package/dist/store.d.ts +2 -0
- package/dist/store.js +18 -0
- package/package.json +2 -2
package/dist/query.d.ts
CHANGED
package/dist/query.js
CHANGED
|
@@ -28,26 +28,37 @@ export function matchesMetadata(clip, { afterMs, beforeMs, minDistanceM }) {
|
|
|
28
28
|
function toClip({ record, availability }) {
|
|
29
29
|
return { ...record, availability };
|
|
30
30
|
}
|
|
31
|
-
function matchingClips(
|
|
31
|
+
function matchingClips(store, filters, overview = false) {
|
|
32
32
|
const segmentFilter = segmentFilterOf(filters);
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return matchesMetadata(clip, filters) ? [{ clip, flight: indexed.flight }] : [];
|
|
40
|
-
});
|
|
33
|
+
const clips = overview
|
|
34
|
+
? store.listClipOverviews(filters.bbox, filters.availability, segmentFilter)
|
|
35
|
+
: store.listClips(filters.bbox, filters.availability, segmentFilter);
|
|
36
|
+
return clips.flatMap((indexed) => {
|
|
37
|
+
const clip = toClip(indexed);
|
|
38
|
+
return matchesMetadata(clip, filters) ? [{ clip, flight: indexed.flight }] : [];
|
|
41
39
|
});
|
|
42
40
|
}
|
|
43
41
|
export function listArchive(db, filters = {}) {
|
|
44
|
-
return
|
|
42
|
+
return withArchiveStore(db, (store) => matchingClips(store, filters).map(({ clip }) => clip));
|
|
45
43
|
}
|
|
46
44
|
export function listArchiveFlights(db, filters = {}, options = {}) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
return withArchiveStore(db, (store) => {
|
|
46
|
+
const flights = [...groupFlightMembers(matchingClips(store, filters, options.overview === true))];
|
|
47
|
+
// Filters can omit the clip that started a flight.
|
|
48
|
+
const starts = options.overview
|
|
49
|
+
? store.readFlightStartTimes(flights.flatMap(([id, members]) => members[0].flight.order === 0 ? [] : [id]))
|
|
50
|
+
: undefined;
|
|
51
|
+
return flights.map(([flightId, members]) => {
|
|
52
|
+
const clips = members.map(({ clip, flight }) => ({ ...clip, splitFromKey: flight.splitFromKey }));
|
|
53
|
+
if (!options.overview)
|
|
54
|
+
return { flightId, clips };
|
|
55
|
+
const start = members[0].flight.order === 0
|
|
56
|
+
? clips[0].cameraCreationTime
|
|
57
|
+
: starts?.get(flightId);
|
|
58
|
+
const startMs = start ? zonedTimeMs(start) : NaN;
|
|
59
|
+
return { flightId, clips, startMs: Number.isFinite(startMs) ? startMs : null };
|
|
60
|
+
});
|
|
61
|
+
});
|
|
51
62
|
}
|
|
52
63
|
export function listArchiveFlightOverviews(db, filters = {}) {
|
|
53
64
|
return listArchiveFlights(db, filters, { overview: true });
|
package/dist/store.d.ts
CHANGED
|
@@ -62,6 +62,7 @@ export interface SharpnessSampleFilter {
|
|
|
62
62
|
export declare class ArchiveStore {
|
|
63
63
|
private readonly db;
|
|
64
64
|
constructor(file: string);
|
|
65
|
+
private ensureFlightStartIndex;
|
|
65
66
|
private schemaVersion;
|
|
66
67
|
private migrate;
|
|
67
68
|
close(): void;
|
|
@@ -144,6 +145,7 @@ export declare class ArchiveStore {
|
|
|
144
145
|
private revision;
|
|
145
146
|
private clipFilterClauses;
|
|
146
147
|
private selectClips;
|
|
148
|
+
readFlightStartTimes(flightIds: readonly string[]): Map<string, string | null>;
|
|
147
149
|
private refreshFlights;
|
|
148
150
|
private transaction;
|
|
149
151
|
private writeClip;
|
package/dist/store.js
CHANGED
|
@@ -176,12 +176,20 @@ export class ArchiveStore {
|
|
|
176
176
|
this.db.exec('PRAGMA foreign_keys = ON');
|
|
177
177
|
if (this.schemaVersion() !== ARCHIVE_SCHEMA_VERSION)
|
|
178
178
|
this.migrate();
|
|
179
|
+
this.ensureFlightStartIndex();
|
|
179
180
|
}
|
|
180
181
|
catch (error) {
|
|
181
182
|
this.db.close();
|
|
182
183
|
throw error;
|
|
183
184
|
}
|
|
184
185
|
}
|
|
186
|
+
ensureFlightStartIndex() {
|
|
187
|
+
// Older archive readers can still use the same schema after the index is added.
|
|
188
|
+
const present = this.db.prepare("SELECT 1 FROM sqlite_schema WHERE type = 'index' AND name = 'clip_flight_starts'").get();
|
|
189
|
+
if (!present) {
|
|
190
|
+
this.db.exec('CREATE INDEX IF NOT EXISTS clip_flight_starts ON clip_flights (flight_id) WHERE flight_order = 0');
|
|
191
|
+
}
|
|
192
|
+
}
|
|
185
193
|
schemaVersion() {
|
|
186
194
|
return this.db.prepare('PRAGMA user_version').get()?.user_version;
|
|
187
195
|
}
|
|
@@ -613,6 +621,16 @@ export class ArchiveStore {
|
|
|
613
621
|
? rows.map(decodeClipOverview)
|
|
614
622
|
: rows.map(decodeFlightClip);
|
|
615
623
|
}
|
|
624
|
+
readFlightStartTimes(flightIds) {
|
|
625
|
+
if (flightIds.length === 0)
|
|
626
|
+
return new Map();
|
|
627
|
+
const rows = this.db.prepare(`
|
|
628
|
+
SELECT flight_id, json_extract(record_json, '$.cameraCreationTime') AS camera_time
|
|
629
|
+
FROM clip_flights JOIN clips USING (clip_key)
|
|
630
|
+
WHERE flight_order = 0 AND flight_id IN (SELECT value FROM json_each(?))
|
|
631
|
+
`).all(JSON.stringify(flightIds));
|
|
632
|
+
return new Map(rows.map(({ flight_id, camera_time }) => [flight_id, camera_time]));
|
|
633
|
+
}
|
|
616
634
|
refreshFlights() {
|
|
617
635
|
const rows = this.db.prepare(`
|
|
618
636
|
SELECT clip_key, size, json_extract(record_json, '$.cameraCreationTime') AS camera_time,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drone-path-archive",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Scan a local library of drone recordings.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"directory": "packages/archive"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"drone-path-core": "~1.2.
|
|
43
|
+
"drone-path-core": "~1.2.1",
|
|
44
44
|
"leaflet": "~1.9.4",
|
|
45
45
|
"p-queue": "~10.0.0"
|
|
46
46
|
}
|