Fix jwt-token
This commit is contained in:
@@ -92,10 +92,10 @@ class SwedishDroneSimulator:
|
|||||||
self.devices: List[DroneDevice] = []
|
self.devices: List[DroneDevice] = []
|
||||||
self.running = False
|
self.running = False
|
||||||
self.threat_scenarios = {
|
self.threat_scenarios = {
|
||||||
"low_threat": {"probability": 0.7, "rssi_range": (-90, -70), "distance_km": (5, 15)},
|
"low_threat": {"probability": 0.4, "rssi_range": (-90, -70)},
|
||||||
"medium_threat": {"probability": 0.2, "rssi_range": (-70, -55), "distance_km": (0.2, 5)},
|
"medium_threat": {"probability": 0.3, "rssi_range": (-70, -55)},
|
||||||
"high_threat": {"probability": 0.08, "rssi_range": (-55, -40), "distance_km": (0.05, 0.2)},
|
"high_threat": {"probability": 0.2, "rssi_range": (-55, -40)},
|
||||||
"critical_threat": {"probability": 0.02, "rssi_range": (-40, -25), "distance_km": (0, 0.05)}
|
"critical_threat": {"probability": 0.1, "rssi_range": (-40, -25)}
|
||||||
}
|
}
|
||||||
|
|
||||||
def generate_devices(self, num_devices: int) -> List[DroneDevice]:
|
def generate_devices(self, num_devices: int) -> List[DroneDevice]:
|
||||||
@@ -128,55 +128,30 @@ class SwedishDroneSimulator:
|
|||||||
self.devices = devices
|
self.devices = devices
|
||||||
return devices
|
return devices
|
||||||
|
|
||||||
def calculate_threat_based_rssi(self, distance_km: float, base_rssi: int = -30) -> int:
|
|
||||||
"""Calculate RSSI based on distance for realistic threat simulation"""
|
|
||||||
# Free space path loss formula adapted for drone detection
|
|
||||||
# RSSI = base_rssi - 20*log10(distance_m) - path_loss_factor
|
|
||||||
distance_m = distance_km * 1000
|
|
||||||
if distance_m < 1:
|
|
||||||
distance_m = 1
|
|
||||||
|
|
||||||
path_loss = 20 * math.log10(distance_m) + random.randint(5, 15)
|
|
||||||
rssi = base_rssi - int(path_loss)
|
|
||||||
|
|
||||||
# Clamp to realistic RSSI range
|
|
||||||
return max(-100, min(-25, rssi))
|
|
||||||
|
|
||||||
def generate_detection_near_device(self, device: DroneDevice, threat_level: str = "low_threat") -> DroneDetection:
|
def generate_detection_near_device(self, device: DroneDevice, threat_level: str = "low_threat") -> DroneDetection:
|
||||||
"""Generate a drone detection near a specific device with threat-based parameters"""
|
"""Generate a drone detection with realistic RSSI and drone type"""
|
||||||
|
|
||||||
threat_config = self.threat_scenarios[threat_level]
|
threat_config = self.threat_scenarios[threat_level]
|
||||||
|
|
||||||
# Generate distance based on threat level
|
# Generate RSSI (what the device actually measures)
|
||||||
min_dist, max_dist = threat_config["distance_km"]
|
|
||||||
distance_km = random.uniform(min_dist, max_dist)
|
|
||||||
|
|
||||||
# Calculate realistic RSSI based on distance
|
|
||||||
rssi = self.calculate_threat_based_rssi(distance_km)
|
|
||||||
|
|
||||||
# Ensure RSSI is within threat level range
|
|
||||||
rssi_min, rssi_max = threat_config["rssi_range"]
|
rssi_min, rssi_max = threat_config["rssi_range"]
|
||||||
rssi = max(rssi_min, min(rssi_max, rssi))
|
rssi = random.randint(rssi_min, rssi_max)
|
||||||
|
|
||||||
# Generate coordinates near device (within distance)
|
# Drone type based on threat level and realistic scenarios
|
||||||
lat_offset = (random.random() - 0.5) * (distance_km / 111.0) * 2 # ~111km per degree
|
|
||||||
lon_offset = (random.random() - 0.5) * (distance_km / (111.0 * math.cos(math.radians(device.lat)))) * 2
|
|
||||||
|
|
||||||
detection_lat = device.lat + lat_offset
|
|
||||||
detection_lon = device.lon + lon_offset
|
|
||||||
|
|
||||||
# Drone type based on threat level
|
|
||||||
if threat_level == "critical_threat":
|
if threat_level == "critical_threat":
|
||||||
drone_type = 1 # Professional/Military
|
# Critical threats: Military drones (Orlan, Zala, Lancet)
|
||||||
|
drone_type = random.choice([2, 3, 5, 6, 14]) # Orlan, Zala, Lancet variants, Supercam
|
||||||
elif threat_level == "high_threat":
|
elif threat_level == "high_threat":
|
||||||
drone_type = random.choice([1, 2]) # Professional or Racing
|
# High threats: Maybe military or FPV attack drones
|
||||||
|
drone_type = random.choice([7, 8, 9, 10, 11]) # FPV drones, Maybe Orlan/Zala/Lancet
|
||||||
else:
|
else:
|
||||||
drone_type = random.choice([0, 0, 0, 1, 2]) # Mostly consumer
|
# Low/medium threats: Commercial/DJI drones or unknown
|
||||||
|
drone_type = random.choice([1, 13, 16, 17, 18]) # Unknown, DJI, various commercial types
|
||||||
|
|
||||||
return DroneDetection(
|
return DroneDetection(
|
||||||
device_id=device.device_id,
|
device_id=device.device_id,
|
||||||
geo_lat=round(detection_lat, 6),
|
geo_lat=device.lat, # Use device location - backend will handle positioning
|
||||||
geo_lon=round(detection_lon, 6),
|
geo_lon=device.lon, # Use device location - backend will handle positioning
|
||||||
device_timestamp=int(time.time()),
|
device_timestamp=int(time.time()),
|
||||||
drone_type=drone_type,
|
drone_type=drone_type,
|
||||||
rssi=rssi,
|
rssi=rssi,
|
||||||
@@ -319,12 +294,24 @@ class SwedishDroneSimulator:
|
|||||||
|
|
||||||
# Generate detections
|
# Generate detections
|
||||||
if current_time - last_detection_time >= detection_interval:
|
if current_time - last_detection_time >= detection_interval:
|
||||||
# Simulate detection probability (not every interval)
|
# Higher chance of detection for testing (70% chance)
|
||||||
if random.random() < 0.4: # 40% chance of detection
|
if random.random() < 0.7:
|
||||||
device = random.choice(self.devices)
|
# Sometimes generate multiple simultaneous detections for testing alarms
|
||||||
|
num_detections = 1
|
||||||
|
if random.random() < 0.3: # 30% chance of multiple detections
|
||||||
|
num_detections = random.randint(2, min(4, len(self.devices)))
|
||||||
|
|
||||||
|
print(f"🎯 Generating {num_detections} simultaneous detection{'s' if num_detections > 1 else ''}...")
|
||||||
|
|
||||||
|
# Select different devices for simultaneous detections
|
||||||
|
selected_devices = random.sample(self.devices, num_detections)
|
||||||
|
|
||||||
|
for device in selected_devices:
|
||||||
threat_level = self.select_threat_level()
|
threat_level = self.select_threat_level()
|
||||||
detection = self.generate_detection_near_device(device, threat_level)
|
detection = self.generate_detection_near_device(device, threat_level)
|
||||||
self.send_detection(detection)
|
self.send_detection(detection)
|
||||||
|
# Small delay between simultaneous detections for realism
|
||||||
|
time.sleep(0.5)
|
||||||
|
|
||||||
last_detection_time = current_time
|
last_detection_time = current_time
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user