mirror of
https://github.com/30hours/3lips.git
synced 2024-11-18 12:33:58 +00:00
Add API saving and remove save folder
This commit is contained in:
parent
363d08c9d1
commit
5c0a1bb9b4
6 changed files with 64 additions and 8 deletions
|
@ -30,6 +30,7 @@ services:
|
||||||
volumes:
|
volumes:
|
||||||
- ./common:/app/common
|
- ./common:/app/common
|
||||||
- ./test:/app/test
|
- ./test:/app/test
|
||||||
|
- ./save:/app/save
|
||||||
container_name: 3lips-event
|
container_name: 3lips-event
|
||||||
|
|
||||||
cesium-apache:
|
cesium-apache:
|
||||||
|
|
|
@ -25,12 +25,13 @@ class AdsbAssociator:
|
||||||
@brief Constructor for the AdsbAssociator class.
|
@brief Constructor for the AdsbAssociator class.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def process(self, radar_list, radar_data):
|
def process(self, radar_list, radar_data, timestamp):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@brief Associate detections from 2+ radars.
|
@brief Associate detections from 2+ radars.
|
||||||
@param radar_list (list): List of radars to associate.
|
@param radar_list (list): List of radars to associate.
|
||||||
@param radar_data (dict): Radar data for list of radars.
|
@param radar_data (dict): Radar data for list of radars.
|
||||||
|
@param timestamp (int): Timestamp to compute delays at (ms).
|
||||||
@return dict: Associated detections by [hex][radar].
|
@return dict: Associated detections by [hex][radar].
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -60,7 +61,8 @@ class AdsbAssociator:
|
||||||
|
|
||||||
# associate radar and truth
|
# associate radar and truth
|
||||||
assoc_detections_radar.append(self.process_1_radar(
|
assoc_detections_radar.append(self.process_1_radar(
|
||||||
radar, radar_data[radar]["detection"], adsb_detections))
|
radar, radar_data[radar]["detection"],
|
||||||
|
adsb_detections, timestamp))
|
||||||
|
|
||||||
# associate detections between radars
|
# associate detections between radars
|
||||||
output = {}
|
output = {}
|
||||||
|
@ -74,7 +76,7 @@ class AdsbAssociator:
|
||||||
|
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def process_1_radar(self, radar, radar_detections, adsb_detections):
|
def process_1_radar(self, radar, radar_detections, adsb_detections, timestamp):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@brief Associate detections between 1 radar/truth pair.
|
@brief Associate detections between 1 radar/truth pair.
|
||||||
|
@ -94,6 +96,11 @@ class AdsbAssociator:
|
||||||
|
|
||||||
if 'delay' in adsb_detections[aircraft] and len(radar_detections['delay']) >= 1:
|
if 'delay' in adsb_detections[aircraft] and len(radar_detections['delay']) >= 1:
|
||||||
|
|
||||||
|
# extrapolate delay/Doppler to current time
|
||||||
|
# delta_t = (timestamp - adsb_detections[aircraft]['timestamp'])/1000
|
||||||
|
# delay = 1000*adsb_detections[aircraft]['delay'] + \
|
||||||
|
|
||||||
|
|
||||||
# distance from aircraft to all detections
|
# distance from aircraft to all detections
|
||||||
closest_point, distance = self.closest_point(
|
closest_point, distance = self.closest_point(
|
||||||
adsb_detections[aircraft]['delay'],
|
adsb_detections[aircraft]['delay'],
|
||||||
|
@ -107,7 +114,8 @@ class AdsbAssociator:
|
||||||
assoc_detections[aircraft] = {
|
assoc_detections[aircraft] = {
|
||||||
'radar': radar,
|
'radar': radar,
|
||||||
'delay': closest_point[0],
|
'delay': closest_point[0],
|
||||||
'doppler': closest_point[1]
|
'doppler': closest_point[1],
|
||||||
|
'timestamp': adsb_detections[aircraft]['timestamp']
|
||||||
}
|
}
|
||||||
|
|
||||||
return assoc_detections
|
return assoc_detections
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
import math
|
|
||||||
|
|
||||||
class AdsbTruth:
|
class AdsbTruth:
|
||||||
|
|
||||||
|
|
|
@ -33,10 +33,12 @@ ellipseParametric = EllipseParametric()
|
||||||
ellipsoidParametric = EllipsoidParametric()
|
ellipsoidParametric = EllipsoidParametric()
|
||||||
sphericalIntersection = SphericalIntersection()
|
sphericalIntersection = SphericalIntersection()
|
||||||
adsbTruth = AdsbTruth(5)
|
adsbTruth = AdsbTruth(5)
|
||||||
|
save = True
|
||||||
|
saveFile = '/app/save/' + str(int(time.time())) + '.ndjson'
|
||||||
|
|
||||||
async def event():
|
async def event():
|
||||||
|
|
||||||
global api
|
global api, save
|
||||||
timestamp = int(time.time()*1000)
|
timestamp = int(time.time()*1000)
|
||||||
api_event = copy.copy(api)
|
api_event = copy.copy(api)
|
||||||
|
|
||||||
|
@ -91,7 +93,6 @@ async def event():
|
||||||
adsb_urls = list(set(adsb_urls))
|
adsb_urls = list(set(adsb_urls))
|
||||||
for url in adsb_urls:
|
for url in adsb_urls:
|
||||||
truth_adsb[url] = adsbTruth.process(url)
|
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:
|
||||||
|
@ -122,7 +123,7 @@ async def event():
|
||||||
return
|
return
|
||||||
|
|
||||||
# processing
|
# processing
|
||||||
associated_dets = associator.process(item["server"], radar_dict_item)
|
associated_dets = associator.process(item["server"], radar_dict_item, timestamp)
|
||||||
associated_dets_3_radars = {
|
associated_dets_3_radars = {
|
||||||
key: value
|
key: value
|
||||||
for key, value in associated_dets.items()
|
for key, value in associated_dets.items()
|
||||||
|
@ -181,6 +182,10 @@ async def event():
|
||||||
# update API
|
# update API
|
||||||
api = api_event
|
api = api_event
|
||||||
|
|
||||||
|
# save to file
|
||||||
|
if save:
|
||||||
|
append_api_to_file(api)
|
||||||
|
|
||||||
|
|
||||||
# event loop
|
# event loop
|
||||||
async def main():
|
async def main():
|
||||||
|
@ -189,6 +194,11 @@ async def main():
|
||||||
await event()
|
await event()
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
|
|
||||||
|
def append_api_to_file(api_object, filename=saveFile):
|
||||||
|
with open(filename, 'a') as json_file:
|
||||||
|
json.dump(api_object, json_file)
|
||||||
|
json_file.write('\n')
|
||||||
|
|
||||||
def short_hash(input_string, length=10):
|
def short_hash(input_string, length=10):
|
||||||
|
|
||||||
hash_object = hashlib.sha256(input_string.encode())
|
hash_object = hashlib.sha256(input_string.encode())
|
||||||
|
|
5
script/README.md
Normal file
5
script/README.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
This folder is for post-processing scripts on API data.
|
||||||
|
|
||||||
|
## Scripts
|
||||||
|
|
||||||
|
- TODO
|
33
script/plot_accuracy.py
Normal file
33
script/plot_accuracy.py
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
import argparse
|
||||||
|
import json
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
def parse_posix_time(value):
|
||||||
|
try:
|
||||||
|
return int(value)
|
||||||
|
except ValueError:
|
||||||
|
raise argparse.ArgumentTypeError("Invalid POSIX time format")
|
||||||
|
|
||||||
|
def parse_command_line_arguments():
|
||||||
|
parser = argparse.ArgumentParser(description="Process command line arguments.")
|
||||||
|
|
||||||
|
parser.add_argument("json_string", type=str, help="Input JSON string")
|
||||||
|
parser.add_argument("target_name", type=str, help="Target name")
|
||||||
|
parser.add_argument("--start_time", type=parse_posix_time, help="Optional start time in POSIX seconds")
|
||||||
|
parser.add_argument("--stop_time", type=parse_posix_time, help="Optional stop time in POSIX seconds")
|
||||||
|
|
||||||
|
return parser.parse_args()
|
||||||
|
|
||||||
|
def main():
|
||||||
|
|
||||||
|
args = parse_command_line_arguments()
|
||||||
|
json_data = json.loads(args.json_string)
|
||||||
|
start_time = args.start_time if args.start_time else None
|
||||||
|
stop_time = args.stop_time if args.stop_time else None
|
||||||
|
print("JSON String:", json_data)
|
||||||
|
print("Target Name:", args.target_name)
|
||||||
|
print("Start Time:", start_time)
|
||||||
|
print("Stop Time:", stop_time)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
Loading…
Reference in a new issue