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):
|
||||
'''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
|
||||
from math import atan2, cos, radians, sin, degrees
|
||||
frm = (radians(frm[0]), radians(frm[1]))
|
||||
|
@ -11,14 +11,14 @@ def calculate_from_bearing(frm, to):
|
|||
from_bearing += 360
|
||||
return from_bearing
|
||||
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']
|
||||
ix = int(round(d / (360. / len(dirs))))
|
||||
card = dirs[ix % len(dirs)]
|
||||
print(card)
|
||||
return card
|
||||
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)
|
||||
across_inital = 360 - abs(original_heading-new_heading)
|
||||
if across_inital < normal:
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import json
|
||||
import os
|
||||
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:
|
||||
aircraft = json.load(aircrafts_json)
|
||||
try:
|
||||
reg = aircraft[icao.upper()]
|
||||
reg = aircraft[icao.upper()][0]
|
||||
except KeyError:
|
||||
reg = None
|
||||
return reg
|
||||
|
@ -20,7 +20,7 @@ def get_db_ver():
|
|||
dbver = json.load(dbver_json)
|
||||
return dbver["version"]
|
||||
def test():
|
||||
print(get_aircraft_by_icao("A835AF"))
|
||||
print(get_aircraft_reg_by_icao("A835AF"))
|
||||
print(get_type_desc("GLF6"))
|
||||
print(get_db_ver())
|
||||
#test()
|
|
@ -213,8 +213,11 @@ class Plane:
|
|||
elif type == "divert":
|
||||
header = "Now diverting back to"
|
||||
route_to = f"{header} {airport_text}" + (f" {arrival_rel}" if arrival_rel is not None else "")
|
||||
return route_to
|
||||
extra_route_info = clean_data(lookup_route(self.reg, (self.latitude, self.longitude), self.type, self.alt_ft))
|
||||
return route_to
|
||||
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
|
||||
if extra_route_info is None:
|
||||
pass
|
||||
|
@ -448,7 +451,7 @@ class Plane:
|
|||
self.circle_history["traces"].remove(trace)
|
||||
#Expire touchngo
|
||||
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:
|
||||
#Squawks
|
||||
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 = round(track_change, 3)
|
||||
self.circle_history["traces"].append((time.time(), self.latitude, self.longitude, track_change))
|
||||
|
||||
|
||||
total_change = 0
|
||||
coords = []
|
||||
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:
|
||||
print("Circling Bearing Change Met")
|
||||
from shapely.geometry import MultiPoint
|
||||
from geopy.distance import geodesic
|
||||
from geopy.distance import geodesic
|
||||
aircraft_coords = (self.latitude, self.longitude)
|
||||
points = MultiPoint(coords)
|
||||
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)
|
||||
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.circle_history['triggered'] = True
|
||||
elif abs(total_change) <= 360 and self.circle_history["triggered"]:
|
||||
print("No Longer Circling, trigger cleared")
|
||||
self.circle_history['triggered'] = False
|
||||
self.circle_history['triggered'] = False
|
||||
# #Power Up
|
||||
# if self.last_feeding == False and self.speed == 0 and self.on_ground:
|
||||
# if self.config.getboolean('DISCORD', 'ENABLE'):
|
||||
|
@ -606,8 +609,8 @@ class Plane:
|
|||
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()}"
|
||||
if "threat_id_hex" in ra['acas_ra'].keys():
|
||||
from mictronics_parse import get_aircraft_by_icao
|
||||
threat_reg = get_aircraft_by_icao(ra['acas_ra']['threat_id_hex'])[0]
|
||||
from mictronics_parse import get_aircraft_reg_by_icao
|
||||
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']
|
||||
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']}"
|
||||
|
|
Loading…
Reference in New Issue