121 lines
3.0 KiB
JavaScript
121 lines
3.0 KiB
JavaScript
const { DataTypes } = require('sequelize');
|
|
|
|
module.exports = (sequelize) => {
|
|
const DroneDetection = sequelize.define('DroneDetection', {
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true
|
|
},
|
|
device_id: {
|
|
type: DataTypes.INTEGER,
|
|
allowNull: false,
|
|
references: {
|
|
model: 'devices',
|
|
key: 'id'
|
|
},
|
|
comment: 'ID of the detecting device'
|
|
},
|
|
drone_id: {
|
|
type: DataTypes.INTEGER,
|
|
allowNull: false,
|
|
comment: 'Detected drone identifier'
|
|
},
|
|
drone_type: {
|
|
type: DataTypes.INTEGER,
|
|
allowNull: false,
|
|
defaultValue: 0,
|
|
comment: 'Type of drone detected (0=unknown, 1=commercial, 2=racing, etc.)'
|
|
},
|
|
rssi: {
|
|
type: DataTypes.INTEGER,
|
|
allowNull: false,
|
|
defaultValue: 0,
|
|
comment: 'Received Signal Strength Indicator'
|
|
},
|
|
freq: {
|
|
type: DataTypes.INTEGER,
|
|
allowNull: false,
|
|
comment: 'Frequency detected'
|
|
},
|
|
geo_lat: {
|
|
type: DataTypes.DECIMAL(10, 8),
|
|
allowNull: true,
|
|
comment: 'Latitude where detection occurred'
|
|
},
|
|
geo_lon: {
|
|
type: DataTypes.DECIMAL(11, 8),
|
|
allowNull: true,
|
|
comment: 'Longitude where detection occurred'
|
|
},
|
|
device_timestamp: {
|
|
type: DataTypes.BIGINT,
|
|
allowNull: true,
|
|
comment: 'Unix timestamp from the device'
|
|
},
|
|
server_timestamp: {
|
|
type: DataTypes.DATE,
|
|
defaultValue: DataTypes.NOW,
|
|
comment: 'When the detection was received by server'
|
|
},
|
|
confidence_level: {
|
|
type: DataTypes.DECIMAL(3, 2),
|
|
allowNull: true,
|
|
comment: 'Confidence level of detection (0.00-1.00)'
|
|
},
|
|
signal_duration: {
|
|
type: DataTypes.INTEGER,
|
|
allowNull: true,
|
|
comment: 'Duration of signal in milliseconds'
|
|
},
|
|
processed: {
|
|
type: DataTypes.BOOLEAN,
|
|
defaultValue: false,
|
|
comment: 'Whether this detection has been processed for alerts'
|
|
},
|
|
threat_level: {
|
|
type: DataTypes.ENUM('monitoring', 'low', 'medium', 'high', 'critical'),
|
|
allowNull: true,
|
|
comment: 'Assessed threat level based on RSSI and drone type'
|
|
},
|
|
estimated_distance: {
|
|
type: DataTypes.INTEGER,
|
|
allowNull: true,
|
|
comment: 'Estimated distance to drone in meters'
|
|
},
|
|
requires_action: {
|
|
type: DataTypes.BOOLEAN,
|
|
defaultValue: false,
|
|
comment: 'Whether this detection requires immediate security action'
|
|
},
|
|
created_at: {
|
|
type: DataTypes.DATE,
|
|
defaultValue: DataTypes.NOW
|
|
}
|
|
}, {
|
|
tableName: 'drone_detections',
|
|
timestamps: true,
|
|
createdAt: 'created_at',
|
|
updatedAt: false,
|
|
indexes: [
|
|
{
|
|
fields: ['device_id']
|
|
},
|
|
{
|
|
fields: ['drone_id']
|
|
},
|
|
{
|
|
fields: ['server_timestamp']
|
|
},
|
|
{
|
|
fields: ['processed']
|
|
},
|
|
{
|
|
fields: ['device_id', 'drone_id', 'server_timestamp']
|
|
}
|
|
]
|
|
});
|
|
|
|
return DroneDetection;
|
|
};
|