Skip to content

Commit 7c96b91

Browse files
authored
Adding schema files to download (#173)
* adding schema files to the zip download * revert yarn change * fixing list * indentation
1 parent 84150e9 commit 7c96b91

File tree

6 files changed

+251
-41
lines changed

6 files changed

+251
-41
lines changed
+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"type": "object",
4+
"properties": {
5+
"hash": { "type": "string" },
6+
"filename": { "type": "string" },
7+
"exifdata": {
8+
"type": "object",
9+
"properties": {
10+
"Make": { "type": "string" },
11+
"Model": { "type": "string" },
12+
"DateTimeOriginal": { "type": "integer" },
13+
"ModifyDate": { "type": "integer" },
14+
"CreateDate": { "type": "integer" },
15+
"GPSLatitudeRef": { "type": "string" },
16+
"GPSLatitude": { "type": "number" },
17+
"GPSLongitudeRef": { "type": "string" },
18+
"GPSLongitude": { "type": "number" },
19+
"GPSAltitudeRef": { "type": "integer" },
20+
"GPSAltitude": { "type": "number" },
21+
"GPSTimeStamp": {
22+
"type": "array",
23+
"items": { "type": "integer" }
24+
},
25+
"GPSDateStamp": { "type": "string" },
26+
"ExifImageWidth": { "type": "integer" },
27+
"ExifImageHeight": { "type": "integer" }
28+
},
29+
"required": [
30+
"Make",
31+
"Model",
32+
"DateTimeOriginal",
33+
"ModifyDate",
34+
"CreateDate",
35+
"GPSLatitudeRef",
36+
"GPSLatitude",
37+
"GPSLongitudeRef",
38+
"GPSLongitude",
39+
"GPSAltitudeRef",
40+
"GPSAltitude",
41+
"GPSTimeStamp",
42+
"GPSDateStamp",
43+
"ExifImageWidth",
44+
"ExifImageHeight"
45+
]
46+
},
47+
"metadata": {
48+
"type": "array",
49+
"items": {
50+
"type": "object",
51+
"properties": {
52+
"score": { "type": "string" },
53+
"correction": { "type": "string" },
54+
"remove": { "type": "boolean" },
55+
"is_tf": { "type": "boolean" },
56+
"id": { "type": "string" },
57+
"label": { "type": "string" },
58+
"area": {
59+
"type": "object",
60+
"properties": {
61+
"x1": { "type": "number" },
62+
"y1": { "type": "number" },
63+
"x2": { "type": "number" },
64+
"y2": { "type": "number" }
65+
},
66+
"required": ["x1", "y1", "x2", "y2"]
67+
}
68+
},
69+
"required": [
70+
"score",
71+
"correction",
72+
"remove",
73+
"is_tf",
74+
"id",
75+
"label",
76+
"area"
77+
]
78+
}
79+
}
80+
},
81+
"required": ["hash", "filename", "exifdata", "metadata"]
82+
}
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Image Schema Description
2+
3+
**hash** (String): A hash associated with the image file.
4+
5+
**filename** (String): The filename of the image.
6+
7+
**exifdata** (Object): An object that contains EXIF data with the following properties:
8+
9+
- **Make** (String): The manufacturer of the camera that took the image.
10+
- **Model** (String): The camera model that took the image.
11+
- **DateTimeOriginal** (Integer): The original date and time the image was taken, represented as a Unix timestamp.
12+
- **ModifyDate** (Integer): The date and time the image was last modified, represented as a Unix timestamp.
13+
- **CreateDate** (Integer): The date and time the image was created, represented as a Unix timestamp.
14+
- **GPSLatitudeRef** (String): The reference for latitude (usually "N" or "S").
15+
- **GPSLatitude** (Number): The latitude coordinate of where the image was taken.
16+
- **GPSLongitudeRef** (String): The reference for longitude (usually "E" or "W").
17+
- **GPSLongitude** (Number): The longitude coordinate of where the image was taken.
18+
- **GPSAltitudeRef** (Integer): The reference for altitude (usually 0).
19+
- **GPSAltitude** (Number): The altitude where the image was taken.
20+
- **GPSTimeStamp** (Array): The GPS timestamp of when the image was taken, represented as an array of integers [hours, minutes, seconds].
21+
- **GPSDateStamp** (String): The GPS date when the image was taken.
22+
- **ExifImageWidth** (Integer): The width of the original image.
23+
- **ExifImageHeight** (Integer): The height of the original image.
24+
25+
**metadata** (Array): An array of objects where each object represents a detected item with the following properties:
26+
27+
- **score** (String): The confidence score of the AI model for the detection.
28+
- **correction** (String): A correction applied to the AI model's prediction. This is usually empty if no correction is applied.
29+
- **remove** (Boolean): A flag indicating whether this detection should be removed. False means the detection is valid.
30+
- **is_tf** (Boolean): A flag indicating if the detection is a true positive (true) or false positive (false).
31+
- **id** (String): A unique identifier for the detection.
32+
- **label** (String): The label of the detected item (e.g., "Plastic film").
33+
area (Object): An object that contains the coordinates of the detected area with the following properties:
34+
- **x1** (Number): The x-coordinate of the top left corner of the detected area.
35+
- **y1** (Number): The y-coordinate of the top left corner of the detected area.
36+
- **x2** (Number): The x-coordinate of the bottom right corner of the detected area.
37+
- **y2** (Number): The y-coordinate of the bottom right corner of the detected area.
38+
Please note that all of the properties described above are required. If any property is missing or if a property's value is of an incorrect type, the JSON will not validate against the schema.
+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"type": "object",
4+
"properties": {
5+
"detected_objects": {
6+
"type": "array",
7+
"items": {
8+
"type": "object",
9+
"properties": {
10+
"name": { "type": "string" },
11+
"count": { "type": "integer", "minimum": 0 },
12+
"hashes": { "type": "array", "items": { "type": "string" } }
13+
},
14+
"required": ["name", "count", "hashes"]
15+
}
16+
},
17+
"no_detection_hashes": {
18+
"type": "array",
19+
"items": { "type": "string" }
20+
},
21+
"unique_detections": { "type": "integer", "minimum": 0 },
22+
"total_detections": { "type": "integer", "minimum": 0 },
23+
"gps": {
24+
"type": "object",
25+
"properties": {
26+
"list": {
27+
"type": "array",
28+
"items": {
29+
"type": "object",
30+
"properties": {
31+
"coordinate": {
32+
"type": "object",
33+
"properties": {
34+
"lat": { "type": "number" },
35+
"lng": { "type": "number" }
36+
},
37+
"required": ["lat", "lng"]
38+
},
39+
"hash": { "type": "string" }
40+
},
41+
"required": ["coordinate", "hash"]
42+
}
43+
}
44+
},
45+
"required": ["list"]
46+
}
47+
},
48+
"required": [
49+
"detected_objects",
50+
"no_detection_hashes",
51+
"unique_detections",
52+
"total_detections",
53+
"gps"
54+
]
55+
}
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Summary Schema Description
2+
3+
**detected_objects** (Array): An array of objects where each object represents a detected item with the following properties:
4+
5+
- **name** (String): The name of the detected item (e.g., "Plastic film").
6+
- **count** (Integer): The count of the detected item. This number should be a non-negative integer.
7+
- **hashes** (Array): An array of strings where each string represents a hash associated with the detected item.
8+
9+
**no_detection_hashes** (Array): An array of strings where each string represents a hash that is associated with items not detected.
10+
11+
**unique_detections** (Integer): The count of unique detections. This number should be a non-negative integer.
12+
13+
**total_detections** (Integer): The total count of detections. This number should be a non-negative integer.
14+
15+
**gps** (Object): An object that contains GPS information with the following properties:
16+
17+
- **list** (Array): An array of objects where each object represents a GPS location with the following properties:
18+
19+
- **coordinate** (Object): An object that contains the GPS coordinates with the following properties:
20+
- **lat** (Number): The latitude of the location.
21+
- **lng** (Number): The longitude of the location.
22+
- **hash** (String): A hash associated with the location.

frontend/src/lib/store/images.ts

+45-40
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
import { imagedb, dataURLtoBlob } from '@/lib/imagedb'
2-
import { saveAs } from 'file-saver'
3-
import TensorFlow from '@/lib/tensorflow'
4-
import JSZip from 'jszip'
5-
import lodash from 'lodash'
6-
import { defineStore } from 'pinia'
7-
import type { _GettersTree } from 'pinia'
8-
import { log } from '@/lib/logging'
9-
import PQueue from 'p-queue'
101
import { DrawCanvas } from '@/lib/draw'
11-
import { resizeImage } from '@/lib/util'
2+
import { dataURLtoBlob, imagedb } from '@/lib/imagedb'
3+
import { log } from '@/lib/logging'
124
import {
13-
Display,
14-
Progress,
5+
BaseImage,
156
Capacity,
16-
Summary,
7+
Display,
178
PAGE_SIZE,
18-
StorageCapacity,
19-
BaseImage,
9+
Progress,
2010
SaveData,
11+
StorageCapacity,
12+
Summary,
2113
TrashObject,
2214
} from '@/lib/models'
15+
import TensorFlow from '@/lib/tensorflow'
16+
import { getStaticFiles, resizeImage } from '@/lib/util'
17+
import { saveAs } from 'file-saver'
18+
import JSZip from 'jszip'
19+
import lodash from 'lodash'
20+
import PQueue from 'p-queue'
21+
import type { _GettersTree } from 'pinia'
22+
import { defineStore } from 'pinia'
2323

2424
let initialized = false
2525

@@ -133,30 +133,21 @@ export const useImageStore = defineStore<
133133
this.capacity = await StorageCapacity.getCapacity()
134134
},
135135
async do_sampleupload() {
136-
const sample_files = async () => {
137-
const files = [
138-
'sample01.jpg',
139-
'sample02.jpg',
140-
'sample03.jpg',
141-
'sample05.jpg',
142-
'sample06.jpg',
143-
'sample07.jpg',
144-
'sample08.jpg',
145-
]
146-
const retval = []
147-
for (let i = 0; i < files.length; i++) {
148-
const file = files[i]
149-
const url = `/samples/${file}`
150-
const blob = await fetch(url).then((r) => r.blob())
151-
retval.push(
152-
new File([blob], file, {
153-
type: blob.type,
154-
}),
155-
)
156-
}
157-
return retval
158-
}
159-
const files = await sample_files()
136+
const blobs = await getStaticFiles([
137+
'/samples/sample01.jpg',
138+
'/samples/sample02.jpg',
139+
'/samples/sample03.jpg',
140+
'/samples/sample05.jpg',
141+
'/samples/sample06.jpg',
142+
'/samples/sample07.jpg',
143+
'/samples/sample08.jpg',
144+
])
145+
const files = blobs.map(
146+
(f) =>
147+
new File([f.blob], f.filePath.substring(9), {
148+
type: f.blob.type,
149+
}),
150+
)
160151
await this.doupload(files)
161152
},
162153

@@ -325,7 +316,21 @@ export const useImageStore = defineStore<
325316
const zp = this.zip
326317

327318
return new Promise(async (resolve) => {
328-
zp.total = await imagedb.savedata.count()
319+
const schemaFilePaths = [
320+
'/schema/image_schema.json',
321+
'/schema/image_schema.md',
322+
'/schema/summary_schema.json',
323+
'/schema/summary_schema.md',
324+
]
325+
326+
zp.total =
327+
(await imagedb.savedata.count()) + schemaFilePaths.length
328+
329+
const schemaFiles = await getStaticFiles(schemaFilePaths)
330+
schemaFiles.map((r) =>
331+
folder!.file(r.filePath.substring(1), r.blob),
332+
)
333+
329334
await imagedb.savedata.each((image: SaveData) => {
330335
zp.current = image.filename ?? ''
331336
const blob = dataURLtoBlob(image!.processeddataUrl!)

frontend/src/lib/util.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ export const invertImageData = (data: ImageData) => {
101101
return data
102102
}
103103

104-
105104
export function Timer(callback: Function, time: number) {
106105
// @ts-ignore
107106
this.setTimeout(callback, time)
@@ -129,3 +128,12 @@ Timer.prototype.add = function (time: number) {
129128
this.setTimeout(this.callback, time)
130129
}
131130
}
131+
132+
export const getStaticFiles = (filePaths: string[]) =>
133+
Promise.all(
134+
filePaths.map((path) =>
135+
fetch(path)
136+
.then((r) => r.blob())
137+
.then((blob) => ({ filePath: path, blob })),
138+
),
139+
)

0 commit comments

Comments
 (0)