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):
'''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:

View File

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

View File

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