Docstring fix, ignore route lookup when no type, reg fix
This commit is contained in:
parent
6809dadf24
commit
40caa6c016
|
@ -1,5 +1,5 @@
|
||||||
def calculate_from_bearing(frm, to):
|
def calculate_from_bearing(frm, to):
|
||||||
'''Calculate inital bearing from one coordinate to next (two tuples of coordinates(lat/lng) in degrees in, returns single bearing)'''
|
"""Calculate inital bearing from one coordinate to next (two tuples of coordinates(lat/lng) in degrees in, returns single bearing)"""
|
||||||
#https://gis.stackexchange.com/questions/228656/finding-compass-direction-between-two-distant-gps-points
|
#https://gis.stackexchange.com/questions/228656/finding-compass-direction-between-two-distant-gps-points
|
||||||
from math import atan2, cos, radians, sin, degrees
|
from math import atan2, cos, radians, sin, degrees
|
||||||
frm = (radians(frm[0]), radians(frm[1]))
|
frm = (radians(frm[0]), radians(frm[1]))
|
||||||
|
@ -11,14 +11,14 @@ def calculate_from_bearing(frm, to):
|
||||||
from_bearing += 360
|
from_bearing += 360
|
||||||
return from_bearing
|
return from_bearing
|
||||||
def calculate_cardinal(d):
|
def calculate_cardinal(d):
|
||||||
'''Finds cardinal direction from bearing degree'''
|
"""Finds cardinal direction from bearing degree"""
|
||||||
dirs = ['N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW']
|
dirs = ['N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW']
|
||||||
ix = int(round(d / (360. / len(dirs))))
|
ix = int(round(d / (360. / len(dirs))))
|
||||||
card = dirs[ix % len(dirs)]
|
card = dirs[ix % len(dirs)]
|
||||||
print(card)
|
print(card)
|
||||||
return card
|
return card
|
||||||
def calculate_deg_change(new_heading, original_heading):
|
def calculate_deg_change(new_heading, original_heading):
|
||||||
'''Calculates change between two headings, returns negative degree if change is left, positive if right'''
|
"""Calculates change between two headings, returns negative degree if change is left, positive if right"""
|
||||||
normal = abs(original_heading-new_heading)
|
normal = abs(original_heading-new_heading)
|
||||||
across_inital = 360 - abs(original_heading-new_heading)
|
across_inital = 360 - abs(original_heading-new_heading)
|
||||||
if across_inital < normal:
|
if across_inital < normal:
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
folder = os.getcwd() + "/dependencies"
|
folder = os.getcwd() + "/dependencies"
|
||||||
def get_aircraft_by_icao(icao):
|
def get_aircraft_reg_by_icao(icao):
|
||||||
with open(folder + '/aircrafts.json') as aircrafts_json:
|
with open(folder + '/aircrafts.json') as aircrafts_json:
|
||||||
aircraft = json.load(aircrafts_json)
|
aircraft = json.load(aircrafts_json)
|
||||||
try:
|
try:
|
||||||
reg = aircraft[icao.upper()]
|
reg = aircraft[icao.upper()][0]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
reg = None
|
reg = None
|
||||||
return reg
|
return reg
|
||||||
|
@ -20,7 +20,7 @@ def get_db_ver():
|
||||||
dbver = json.load(dbver_json)
|
dbver = json.load(dbver_json)
|
||||||
return dbver["version"]
|
return dbver["version"]
|
||||||
def test():
|
def test():
|
||||||
print(get_aircraft_by_icao("A835AF"))
|
print(get_aircraft_reg_by_icao("A835AF"))
|
||||||
print(get_type_desc("GLF6"))
|
print(get_type_desc("GLF6"))
|
||||||
print(get_db_ver())
|
print(get_db_ver())
|
||||||
#test()
|
#test()
|
|
@ -213,8 +213,11 @@ class Plane:
|
||||||
elif type == "divert":
|
elif type == "divert":
|
||||||
header = "Now diverting back to"
|
header = "Now diverting back to"
|
||||||
route_to = f"{header} {airport_text}" + (f" {arrival_rel}" if arrival_rel is not None else "")
|
route_to = f"{header} {airport_text}" + (f" {arrival_rel}" if arrival_rel is not None else "")
|
||||||
return route_to
|
return route_to
|
||||||
extra_route_info = clean_data(lookup_route(self.reg, (self.latitude, self.longitude), self.type, self.alt_ft))
|
if hasattr(self, "type"):
|
||||||
|
extra_route_info = clean_data(lookup_route(self.reg, (self.latitude, self.longitude), self.type, self.alt_ft))
|
||||||
|
else:
|
||||||
|
extra_route_info = None
|
||||||
route_to = None
|
route_to = None
|
||||||
if extra_route_info is None:
|
if extra_route_info is None:
|
||||||
pass
|
pass
|
||||||
|
@ -448,7 +451,7 @@ class Plane:
|
||||||
self.circle_history["traces"].remove(trace)
|
self.circle_history["traces"].remove(trace)
|
||||||
#Expire touchngo
|
#Expire touchngo
|
||||||
if "touchngo" in self.circle_history.keys() and (datetime.now() - datetime.fromtimestamp(self.circle_history['touchngo'])).total_seconds() >= 10*60:
|
if "touchngo" in self.circle_history.keys() and (datetime.now() - datetime.fromtimestamp(self.circle_history['touchngo'])).total_seconds() >= 10*60:
|
||||||
self.circle_history.pop("touchngo")
|
self.circle_history.pop("touchngo")
|
||||||
if self.feeding:
|
if self.feeding:
|
||||||
#Squawks
|
#Squawks
|
||||||
emergency_squawks ={"7500" : "Hijacking", "7600" :"Radio Failure", "7700" : "General Emergency"}
|
emergency_squawks ={"7500" : "Hijacking", "7600" :"Radio Failure", "7700" : "General Emergency"}
|
||||||
|
@ -517,7 +520,7 @@ class Plane:
|
||||||
track_change = calculate_deg_change(self.track, self.last_track)
|
track_change = calculate_deg_change(self.track, self.last_track)
|
||||||
track_change = round(track_change, 3)
|
track_change = round(track_change, 3)
|
||||||
self.circle_history["traces"].append((time.time(), self.latitude, self.longitude, track_change))
|
self.circle_history["traces"].append((time.time(), self.latitude, self.longitude, track_change))
|
||||||
|
|
||||||
total_change = 0
|
total_change = 0
|
||||||
coords = []
|
coords = []
|
||||||
for trace in self.circle_history["traces"]:
|
for trace in self.circle_history["traces"]:
|
||||||
|
@ -529,7 +532,7 @@ class Plane:
|
||||||
if abs(total_change) >= 720 and self.circle_history['triggered'] is False:
|
if abs(total_change) >= 720 and self.circle_history['triggered'] is False:
|
||||||
print("Circling Bearing Change Met")
|
print("Circling Bearing Change Met")
|
||||||
from shapely.geometry import MultiPoint
|
from shapely.geometry import MultiPoint
|
||||||
from geopy.distance import geodesic
|
from geopy.distance import geodesic
|
||||||
aircraft_coords = (self.latitude, self.longitude)
|
aircraft_coords = (self.latitude, self.longitude)
|
||||||
points = MultiPoint(coords)
|
points = MultiPoint(coords)
|
||||||
cent = (points.centroid) #True centroid, not necessarily an existing point
|
cent = (points.centroid) #True centroid, not necessarily an existing point
|
||||||
|
@ -565,11 +568,11 @@ class Plane:
|
||||||
self.tweet_api.create_media_metadata(media_id= twitter_media_map_obj.media_id, alt_text= alt_text)
|
self.tweet_api.create_media_metadata(media_id= twitter_media_map_obj.media_id, alt_text= alt_text)
|
||||||
tweet = self.tweet_api.user_timeline(count = 1)[0]
|
tweet = self.tweet_api.user_timeline(count = 1)[0]
|
||||||
self.tweet_api.update_status(status = f"{self.twitter_title} {message}".strip(), in_reply_to_status_id = tweet.id, media_ids=[twitter_media_map_obj.media_id])
|
self.tweet_api.update_status(status = f"{self.twitter_title} {message}".strip(), in_reply_to_status_id = tweet.id, media_ids=[twitter_media_map_obj.media_id])
|
||||||
|
|
||||||
self.circle_history['triggered'] = True
|
self.circle_history['triggered'] = True
|
||||||
elif abs(total_change) <= 360 and self.circle_history["triggered"]:
|
elif abs(total_change) <= 360 and self.circle_history["triggered"]:
|
||||||
print("No Longer Circling, trigger cleared")
|
print("No Longer Circling, trigger cleared")
|
||||||
self.circle_history['triggered'] = False
|
self.circle_history['triggered'] = False
|
||||||
# #Power Up
|
# #Power Up
|
||||||
# if self.last_feeding == False and self.speed == 0 and self.on_ground:
|
# if self.last_feeding == False and self.speed == 0 and self.on_ground:
|
||||||
# if self.config.getboolean('DISCORD', 'ENABLE'):
|
# if self.config.getboolean('DISCORD', 'ENABLE'):
|
||||||
|
@ -606,8 +609,8 @@ class Plane:
|
||||||
from defSS import get_adsbx_screenshot, generate_adsbx_screenshot_time_params
|
from defSS import get_adsbx_screenshot, generate_adsbx_screenshot_time_params
|
||||||
url_params = f"&lat={ra['lat']}&lon={ra['lon']}&zoom=11&largeMode=2&hideButtons&hideSidebar&mapDim=0&overlays={self.get_adsbx_map_overlays()}"
|
url_params = f"&lat={ra['lat']}&lon={ra['lon']}&zoom=11&largeMode=2&hideButtons&hideSidebar&mapDim=0&overlays={self.get_adsbx_map_overlays()}"
|
||||||
if "threat_id_hex" in ra['acas_ra'].keys():
|
if "threat_id_hex" in ra['acas_ra'].keys():
|
||||||
from mictronics_parse import get_aircraft_by_icao
|
from mictronics_parse import get_aircraft_reg_by_icao
|
||||||
threat_reg = get_aircraft_by_icao(ra['acas_ra']['threat_id_hex'])[0]
|
threat_reg = get_aircraft_reg_by_icao(ra['acas_ra']['threat_id_hex'])
|
||||||
threat_id = threat_reg if threat_reg is not None else "ICAO: " + ra['acas_ra']['threat_id_hex']
|
threat_id = threat_reg if threat_reg is not None else "ICAO: " + ra['acas_ra']['threat_id_hex']
|
||||||
ra_message += f", invader: {threat_id}"
|
ra_message += f", invader: {threat_id}"
|
||||||
url_params += generate_adsbx_screenshot_time_params(ra['acas_ra']['unix_timestamp']) + f"&icao={ra['acas_ra']['threat_id_hex']},{self.icao.lower()}×tamp={ra['acas_ra']['unix_timestamp']}"
|
url_params += generate_adsbx_screenshot_time_params(ra['acas_ra']['unix_timestamp']) + f"&icao={ra['acas_ra']['threat_id_hex']},{self.icao.lower()}×tamp={ra['acas_ra']['unix_timestamp']}"
|
||||||
|
|
Loading…
Reference in New Issue