Files
drone-detector/server/models/DroneDetection.js
2025-09-17 22:43:44 +02:00

140 lines
3.5 KiB
JavaScript

const { DataTypes } = require('sequelize');
module.exports = (sequelize) => {
const DroneDetection = sequelize.define('DroneDetection', {
id: {
type: DataTypes.UUID,
defaultValue: sequelize.Sequelize.UUIDV4,
primaryKey: true
},
device_id: {
type: DataTypes.STRING(255),
allowNull: false,
references: {
model: 'devices',
key: 'id'
},
comment: 'ID of the detecting device'
},
tenant_id: {
type: DataTypes.UUID,
allowNull: true,
references: {
model: 'tenants',
key: 'id'
},
comment: 'Tenant ID for multi-tenant isolation'
},
drone_id: {
type: DataTypes.BIGINT,
allowNull: false,
defaultValue: 999999,
comment: 'Detected drone identifier (BIGINT for large IDs)'
},
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,
defaultValue: 2400,
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: sequelize.Sequelize.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.STRING,
allowNull: true,
validate: {
isIn: [['monitoring', 'low', 'medium', 'high', 'critical']]
},
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'
},
raw_payload: {
type: DataTypes.JSON,
allowNull: true,
comment: 'Complete raw payload received from detector (for debugging)'
},
created_at: {
type: DataTypes.DATE,
defaultValue: sequelize.Sequelize.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;
};