Docstring fix, ignore route lookup when no type, reg fix

This commit is contained in:
Jack Sweeney 2021-09-22 13:55:47 -04:00
parent 6809dadf24
commit 40caa6c016
3 changed files with 18 additions and 15 deletions

View File

@ -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:

View File

@ -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()

View File

@ -214,7 +214,10 @@ class Plane:
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
@ -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()}&timestamp={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()}&timestamp={ra['acas_ra']['unix_timestamp']}"