mirror of
https://github.com/30hours/3lips.git
synced 2024-11-18 12:33:58 +00:00
Added truth to API
This commit is contained in:
parent
bb6ef6166d
commit
363d08c9d1
2 changed files with 80 additions and 0 deletions
67
event/algorithm/truth/AdsbTruth.py
Normal file
67
event/algorithm/truth/AdsbTruth.py
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
"""
|
||||||
|
@file AdsbTruth.py
|
||||||
|
@author 30hours
|
||||||
|
"""
|
||||||
|
|
||||||
|
import requests
|
||||||
|
import math
|
||||||
|
|
||||||
|
class AdsbTruth:
|
||||||
|
|
||||||
|
"""
|
||||||
|
@class AdsbTruth
|
||||||
|
@brief A class for storing ADS-B truth in the API response.
|
||||||
|
@details Uses truth data in delay-Doppler space from an tar1090 server.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, seen_pos_limit):
|
||||||
|
|
||||||
|
"""
|
||||||
|
@brief Constructor for the AdsbTruth class.
|
||||||
|
"""
|
||||||
|
|
||||||
|
self.seen_pos_limit = seen_pos_limit
|
||||||
|
|
||||||
|
def process(self, server):
|
||||||
|
|
||||||
|
"""
|
||||||
|
@brief Store ADS-B truth for each target in LLA.
|
||||||
|
@param server (str): The tar1090 server to get truth from.
|
||||||
|
@return dict: Associated detections by [hex].
|
||||||
|
"""
|
||||||
|
|
||||||
|
output = {}
|
||||||
|
|
||||||
|
# get tar1090 URL
|
||||||
|
url = 'https://' + server + '/data/aircraft.json'
|
||||||
|
|
||||||
|
# get ADSB detections
|
||||||
|
try:
|
||||||
|
response = requests.get(url, timeout=1)
|
||||||
|
response.raise_for_status()
|
||||||
|
data = response.json()
|
||||||
|
adsb = data
|
||||||
|
except requests.exceptions.RequestException as e:
|
||||||
|
print(f"Error fetching data from {url}: {e}")
|
||||||
|
adsb = None
|
||||||
|
|
||||||
|
# store relevant data
|
||||||
|
if adsb:
|
||||||
|
|
||||||
|
# loop over aircraft
|
||||||
|
for aircraft in adsb["aircraft"]:
|
||||||
|
|
||||||
|
if aircraft.get("seen_pos") and \
|
||||||
|
aircraft.get("alt_geom") and \
|
||||||
|
aircraft.get("flight") and \
|
||||||
|
aircraft.get("seen_pos") < self.seen_pos_limit:
|
||||||
|
|
||||||
|
output[aircraft["hex"]] = {}
|
||||||
|
output[aircraft["hex"]]["lat"] = aircraft["lat"]
|
||||||
|
output[aircraft["hex"]]["lon"] = aircraft["lon"]
|
||||||
|
output[aircraft["hex"]]["alt"] = aircraft["alt_geom"]
|
||||||
|
output[aircraft["hex"]]["flight"] = aircraft["flight"]
|
||||||
|
output[aircraft["hex"]]["timestamp"] = \
|
||||||
|
adsb["now"] - aircraft["seen_pos"]
|
||||||
|
|
||||||
|
return output
|
|
@ -17,6 +17,7 @@ from algorithm.associator.AdsbAssociator import AdsbAssociator
|
||||||
from algorithm.localisation.EllipseParametric import EllipseParametric
|
from algorithm.localisation.EllipseParametric import EllipseParametric
|
||||||
from algorithm.localisation.EllipsoidParametric import EllipsoidParametric
|
from algorithm.localisation.EllipsoidParametric import EllipsoidParametric
|
||||||
from algorithm.localisation.SphericalIntersection import SphericalIntersection
|
from algorithm.localisation.SphericalIntersection import SphericalIntersection
|
||||||
|
from algorithm.truth.AdsbTruth import AdsbTruth
|
||||||
from common.Message import Message
|
from common.Message import Message
|
||||||
|
|
||||||
from data.Ellipsoid import Ellipsoid
|
from data.Ellipsoid import Ellipsoid
|
||||||
|
@ -31,6 +32,7 @@ adsbAssociator = AdsbAssociator()
|
||||||
ellipseParametric = EllipseParametric()
|
ellipseParametric = EllipseParametric()
|
||||||
ellipsoidParametric = EllipsoidParametric()
|
ellipsoidParametric = EllipsoidParametric()
|
||||||
sphericalIntersection = SphericalIntersection()
|
sphericalIntersection = SphericalIntersection()
|
||||||
|
adsbTruth = AdsbTruth(5)
|
||||||
|
|
||||||
async def event():
|
async def event():
|
||||||
|
|
||||||
|
@ -81,6 +83,16 @@ async def event():
|
||||||
"config": radar_config[i]
|
"config": radar_config[i]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# store truth in dict
|
||||||
|
truth_adsb = {}
|
||||||
|
adsb_urls = []
|
||||||
|
for item in api_event:
|
||||||
|
adsb_urls.append(item["adsb"])
|
||||||
|
adsb_urls = list(set(adsb_urls))
|
||||||
|
for url in adsb_urls:
|
||||||
|
truth_adsb[url] = adsbTruth.process(url)
|
||||||
|
print(truth_adsb, flush=True)
|
||||||
|
|
||||||
# main processing
|
# main processing
|
||||||
for item in api_event:
|
for item in api_event:
|
||||||
|
|
||||||
|
@ -157,6 +169,7 @@ async def event():
|
||||||
|
|
||||||
# output data to API
|
# output data to API
|
||||||
item["timestamp_event"] = timestamp
|
item["timestamp_event"] = timestamp
|
||||||
|
item["truth"] = truth_adsb[item["adsb"]]
|
||||||
item["detections_associated"] = associated_dets
|
item["detections_associated"] = associated_dets
|
||||||
item["detections_localised"] = localised_dets
|
item["detections_localised"] = localised_dets
|
||||||
item["ellipsoids"] = ellipsoids
|
item["ellipsoids"] = ellipsoids
|
||||||
|
|
Loading…
Reference in a new issue