-
Notifications
You must be signed in to change notification settings - Fork 0
/
Project.ts
105 lines (95 loc) · 2.87 KB
/
Project.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import mongoose from 'mongoose';
import { LocationSchema } from './shared/index.js';
import { randomUUID } from 'node:crypto';
const Schema = mongoose.Schema;
const AutomationRuleSchema = new Schema({
name: { type: String, required: true },
event: {
type: {
type: String,
enum: ['image-added', 'label-added'],
required: true,
},
label: { type: String },
},
action: {
type: {
type: String,
enum: ['run-inference', 'send-alert'],
required: true,
},
alertRecipients: { type: [String] },
mlModel: { type: String, ref: 'MLModel' },
categoryConfig: {
type: Map,
of: new Schema({
confThreshold: { type: Number },
disabled: { type: Boolean },
}),
},
},
});
const FiltersSchema = new Schema({
cameras: { type: [String], default: undefined },
deployments: { type: [String], default: undefined },
labels: { type: [String], default: undefined },
createdStart: { type: Date },
createdEnd: { type: Date },
addedStart: { type: Date },
addedEnd: { type: Date },
reviewed: { type: Boolean },
notReviewed: { type: Boolean },
custom: { type: String },
});
const ViewSchema = new Schema({
name: { type: String, required: true },
filters: { type: FiltersSchema, required: true },
description: { type: String },
editable: { type: Boolean },
});
const DeploymentSchema = new Schema({
name: { type: String, required: true },
description: { type: String },
location: { type: LocationSchema },
timezone: { type: String, required: true },
startDate: { type: Date },
editable: { type: Boolean },
});
const ProjectLabelSchema = new Schema({
_id: { type: String, required: true, default: randomUUID },
name: { type: String, required: true },
color: { type: String, required: true },
reviewerEnabled: { type: Boolean, required: true, default: true },
});
const CameraConfigSchema = new Schema({
_id: { type: String, required: true } /* _id is serial number */,
deployments: { type: [DeploymentSchema] },
});
const ProjectSchema = new Schema({
_id: { type: String, required: true } /* _id is name in_snake_case */,
name: { type: String, required: true },
timezone: { type: String, default: 'America/Los_Angeles', required: true },
description: { type: String },
views: { type: [ViewSchema], required: true },
cameraConfigs: { type: [CameraConfigSchema] },
availableMLModels: { type: [{ type: String, ref: 'MLModel' }] },
automationRules: { type: [AutomationRuleSchema] },
labels: {
type: [ProjectLabelSchema],
default: [
{
_id: 'empty',
name: 'empty',
color: '#8D8D8D',
},
{
_id: 'unknown',
name: 'unknown',
color: '#E93D82',
},
],
required: true,
},
});
export default mongoose.model('Project', ProjectSchema);
export type ProjectSchema = mongoose.InferSchemaType<typeof ProjectSchema>;