@adventurelabs/scout-core 1.4.16 → 1.4.18
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/helpers/artifacts.d.ts +10 -2
- package/dist/helpers/artifacts.js +10 -6
- package/dist/helpers/bounding_boxes.d.ts +2 -2
- package/dist/helpers/bounding_boxes.js +3 -5
- package/dist/helpers/tags.js +34 -16
- package/dist/providers/ScoutRefreshProvider.d.ts +283 -52
- package/dist/store/api.js +50 -2
- package/dist/types/db.d.ts +1 -0
- package/dist/types/supabase.d.ts +294 -52
- package/package.json +1 -1
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import { IArtifact, IArtifactWithMediaUrl, ArtifactInsert, ArtifactUpdate } from "../types/db";
|
|
2
2
|
import { IWebResponseCompatible } from "../types/requests";
|
|
3
3
|
import { SupabaseClient } from "@supabase/supabase-js";
|
|
4
|
-
export declare function server_get_artifacts_by_herd(herd_id: number, limit?: number, offset?: number,
|
|
4
|
+
export declare function server_get_artifacts_by_herd(herd_id: number, limit?: number, offset?: number, options?: {
|
|
5
|
+
start_timestamp?: string;
|
|
6
|
+
end_timestamp?: string;
|
|
7
|
+
client?: SupabaseClient;
|
|
8
|
+
}): Promise<IWebResponseCompatible<IArtifactWithMediaUrl[]>>;
|
|
5
9
|
export declare function server_get_artifacts_by_device_id(device_id: number, limit?: number, offset?: number, client?: SupabaseClient): Promise<IWebResponseCompatible<IArtifactWithMediaUrl[]>>;
|
|
6
10
|
export declare function server_get_total_artifacts_by_herd(herd_id: number): Promise<IWebResponseCompatible<number>>;
|
|
7
|
-
export declare function server_get_artifacts_by_device_ids_batch(device_ids: number[], limit_per_device?: number,
|
|
11
|
+
export declare function server_get_artifacts_by_device_ids_batch(device_ids: number[], limit_per_device?: number, options?: {
|
|
12
|
+
start_timestamp?: string;
|
|
13
|
+
end_timestamp?: string;
|
|
14
|
+
client?: SupabaseClient;
|
|
15
|
+
}): Promise<{
|
|
8
16
|
[device_id: number]: IArtifactWithMediaUrl[];
|
|
9
17
|
}>;
|
|
10
18
|
export declare function server_insert_artifact(artifact: ArtifactInsert | ArtifactInsert[], client?: SupabaseClient): Promise<IWebResponseCompatible<IArtifact[]>>;
|
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
import { newServerClient } from "../supabase/server";
|
|
3
3
|
import { IWebResponse } from "../types/requests";
|
|
4
4
|
import { generateSignedUrlsBatch } from "./storage";
|
|
5
|
-
export async function server_get_artifacts_by_herd(herd_id, limit = 50, offset = 0,
|
|
6
|
-
const supabase = client || (await newServerClient());
|
|
5
|
+
export async function server_get_artifacts_by_herd(herd_id, limit = 50, offset = 0, options) {
|
|
6
|
+
const supabase = options?.client || (await newServerClient());
|
|
7
7
|
const { data, error } = await supabase.rpc("get_artifacts_for_herd", {
|
|
8
8
|
herd_id_caller: herd_id,
|
|
9
9
|
limit_caller: limit,
|
|
10
10
|
offset_caller: offset,
|
|
11
|
+
start_timestamp: options?.start_timestamp,
|
|
12
|
+
end_timestamp: options?.end_timestamp,
|
|
11
13
|
});
|
|
12
14
|
if (error) {
|
|
13
15
|
return IWebResponse.error(error.message).to_compatible();
|
|
@@ -22,7 +24,7 @@ export async function server_get_artifacts_by_herd(herd_id, limit = 50, offset =
|
|
|
22
24
|
if (uniqueFilePaths.length === 0) {
|
|
23
25
|
return IWebResponse.success(data).to_compatible();
|
|
24
26
|
}
|
|
25
|
-
const signedUrls = await generateSignedUrlsBatch(uniqueFilePaths, undefined, client);
|
|
27
|
+
const signedUrls = await generateSignedUrlsBatch(uniqueFilePaths, undefined, options?.client);
|
|
26
28
|
const urlMap = new Map();
|
|
27
29
|
uniqueFilePaths.forEach((path, index) => {
|
|
28
30
|
urlMap.set(path, signedUrls[index]);
|
|
@@ -78,14 +80,16 @@ export async function server_get_total_artifacts_by_herd(herd_id) {
|
|
|
78
80
|
}
|
|
79
81
|
return IWebResponse.success(data || 0).to_compatible();
|
|
80
82
|
}
|
|
81
|
-
export async function server_get_artifacts_by_device_ids_batch(device_ids, limit_per_device = 10,
|
|
82
|
-
const supabase = client || (await newServerClient());
|
|
83
|
+
export async function server_get_artifacts_by_device_ids_batch(device_ids, limit_per_device = 10, options) {
|
|
84
|
+
const supabase = options?.client || (await newServerClient());
|
|
83
85
|
if (device_ids.length === 0) {
|
|
84
86
|
return {};
|
|
85
87
|
}
|
|
86
88
|
const { data, error } = await supabase.rpc("get_artifacts_for_devices_batch", {
|
|
87
89
|
device_ids: device_ids,
|
|
88
90
|
limit_per_device: limit_per_device,
|
|
91
|
+
start_timestamp: options?.start_timestamp,
|
|
92
|
+
end_timestamp: options?.end_timestamp,
|
|
89
93
|
});
|
|
90
94
|
if (error || !data) {
|
|
91
95
|
console.warn("Error fetching artifacts batch:", error?.message);
|
|
@@ -97,7 +101,7 @@ export async function server_get_artifacts_by_device_ids_batch(device_ids, limit
|
|
|
97
101
|
.filter((path) => !!path)));
|
|
98
102
|
let artifactsWithUrls = data;
|
|
99
103
|
if (uniqueFilePaths.length > 0) {
|
|
100
|
-
const signedUrls = await generateSignedUrlsBatch(uniqueFilePaths, undefined, client);
|
|
104
|
+
const signedUrls = await generateSignedUrlsBatch(uniqueFilePaths, undefined, options?.client);
|
|
101
105
|
const urlMap = new Map();
|
|
102
106
|
uniqueFilePaths.forEach((path, index) => {
|
|
103
107
|
urlMap.set(path, signedUrls[index]);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BoundingBox, EnumSourceBoundingBox } from "../types/bounding_boxes";
|
|
2
|
-
import { Tag } from "../types/db";
|
|
3
|
-
export declare function convertManualBoundingBoxToTag(boundingBox: BoundingBox, event_id: number):
|
|
2
|
+
import { Tag, TagInsert } from "../types/db";
|
|
3
|
+
export declare function convertManualBoundingBoxToTag(boundingBox: BoundingBox, event_id: number): TagInsert;
|
|
4
4
|
export declare function convertTagToBoundingBox(tag: Tag, source: EnumSourceBoundingBox): BoundingBox;
|
|
5
5
|
export declare function formatBoundingBoxLabel(label: string): string;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { SelectionStatus, } from "../types/bounding_boxes";
|
|
2
2
|
export function convertManualBoundingBoxToTag(boundingBox, event_id) {
|
|
3
3
|
const newClassName = boundingBox.label;
|
|
4
|
-
// try to convert if nan, make it 0
|
|
5
4
|
let newId = Number(boundingBox.id);
|
|
6
5
|
if (isNaN(newId)) {
|
|
7
6
|
newId = 0;
|
|
8
7
|
}
|
|
9
|
-
|
|
8
|
+
return {
|
|
10
9
|
id: newId,
|
|
11
10
|
x: boundingBox.xCenterPercentage,
|
|
12
11
|
y: boundingBox.yCenterPercentage,
|
|
@@ -15,11 +14,10 @@ export function convertManualBoundingBoxToTag(boundingBox, event_id) {
|
|
|
15
14
|
inserted_at: new Date().toISOString(),
|
|
16
15
|
conf: 1,
|
|
17
16
|
observation_type: "manual",
|
|
18
|
-
|
|
17
|
+
class: newClassName,
|
|
19
18
|
event_id: event_id,
|
|
20
19
|
location: null,
|
|
21
20
|
};
|
|
22
|
-
return newTag;
|
|
23
21
|
}
|
|
24
22
|
export function convertTagToBoundingBox(tag, source) {
|
|
25
23
|
const newBoundingBox = {
|
|
@@ -27,7 +25,7 @@ export function convertTagToBoundingBox(tag, source) {
|
|
|
27
25
|
yCenterPercentage: tag.y,
|
|
28
26
|
widthPercentage: tag.width,
|
|
29
27
|
heightPercentage: tag.height,
|
|
30
|
-
label: tag.
|
|
28
|
+
label: tag.class,
|
|
31
29
|
id: tag.id ? tag.id.toString() : "0",
|
|
32
30
|
left: 0,
|
|
33
31
|
top: 0,
|
package/dist/helpers/tags.js
CHANGED
|
@@ -125,7 +125,7 @@ export async function server_update_tags(tags) {
|
|
|
125
125
|
y: updateData.y,
|
|
126
126
|
width: updateData.width,
|
|
127
127
|
height: updateData.height,
|
|
128
|
-
|
|
128
|
+
class: updateData.class,
|
|
129
129
|
conf: updateData.conf,
|
|
130
130
|
observation_type: updateData.observation_type,
|
|
131
131
|
})
|
|
@@ -402,21 +402,39 @@ export async function get_event_and_tags_by_event_id(event_id) {
|
|
|
402
402
|
timestamp_observation: data[0].timestamp_observation,
|
|
403
403
|
is_public: data[0].is_public,
|
|
404
404
|
herd_id: deviceData.herd_id,
|
|
405
|
-
tags: (data[0].tags || []).map((tag) =>
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
405
|
+
tags: (data[0].tags || []).map((tag) => {
|
|
406
|
+
const loc = tag.location;
|
|
407
|
+
const lat = loc ? extractLatitude(loc) : null;
|
|
408
|
+
const lon = loc ? extractLongitude(loc) : null;
|
|
409
|
+
return {
|
|
410
|
+
id: tag.id,
|
|
411
|
+
inserted_at: tag.inserted_at,
|
|
412
|
+
artifact_id: tag.artifact_id,
|
|
413
|
+
event_id: tag.event_id,
|
|
414
|
+
detector: tag.detector,
|
|
415
|
+
width: tag.width,
|
|
416
|
+
height: tag.height,
|
|
417
|
+
conf: tag.conf,
|
|
418
|
+
x: tag.x,
|
|
419
|
+
y: tag.y,
|
|
420
|
+
class: tag.class,
|
|
421
|
+
timestamp_observation: tag.timestamp_observation,
|
|
422
|
+
origin_location: tag.origin_location ?? null,
|
|
423
|
+
origin_pitch: tag.origin_pitch,
|
|
424
|
+
origin_heading: tag.origin_heading,
|
|
425
|
+
origin_roll: tag.origin_roll,
|
|
426
|
+
sensor_pitch: tag.sensor_pitch,
|
|
427
|
+
sensor_yaw: tag.sensor_yaw,
|
|
428
|
+
sensor_roll: tag.sensor_roll,
|
|
429
|
+
origin_height: tag.origin_height,
|
|
430
|
+
subject_location: tag.subject_location ?? null,
|
|
431
|
+
subject_height: tag.subject_height,
|
|
432
|
+
origin_latitude: lat,
|
|
433
|
+
origin_longitude: lon,
|
|
434
|
+
subject_latitude: null,
|
|
435
|
+
subject_longitude: null,
|
|
436
|
+
};
|
|
437
|
+
}),
|
|
420
438
|
earthranger_url: data[0].earthranger_url,
|
|
421
439
|
file_path: data[0].file_path,
|
|
422
440
|
};
|