From 030f2c14d2066523cb10a6996ce72d346af5d873 Mon Sep 17 00:00:00 2001 From: Jack Sweeney Date: Fri, 20 Nov 2020 03:24:21 +0000 Subject: [PATCH] Source failover, from ADSBX to OPENS Landing by data loss after 5 mins now --- NotifyBotMulti.py | 24 +++++++++++++++--------- planeClass.py | 43 +++++++++++++++++++++++++------------------ 2 files changed, 40 insertions(+), 27 deletions(-) diff --git a/NotifyBotMulti.py b/NotifyBotMulti.py index f5c3232..04f39db 100644 --- a/NotifyBotMulti.py +++ b/NotifyBotMulti.py @@ -14,6 +14,7 @@ download_airports() download_font() main_config = configparser.ConfigParser() main_config.read('./configs/mainconf.ini') +source = main_config.get('DATA', 'SOURCE') import os import sys #Setup plane objects from plane configs @@ -25,6 +26,7 @@ for filename in os.listdir("./configs"): planes[plane_config.get('DATA', 'ICAO').upper()] = Plane(plane_config.get('DATA', 'ICAO'), filename) running_Count = 0 +failed_count = 0 try: tz = pytz.timezone(main_config.get('DATA', 'TZ')) except pytz.exceptions.UnknownTimeZoneError: @@ -37,7 +39,7 @@ while True: running_Count +=1 start_time = time.time() print (Back.GREEN, Fore.BLACK, "--------", running_Count, "--------", datetime_tz.strftime("%I:%M:%S %p"), "-------------------------------------------------------", Style.RESET_ALL) - if main_config.get('DATA', 'SOURCE') == "ADSBX": + if source == "ADSBX": from defADSBX import pullADSBX data, failed = pullADSBX(planes) if failed == False: @@ -46,15 +48,17 @@ while True: has_data = False for planeData in data['ac']: if planeData['icao'] == key: - obj.run(planeData) + obj.run(planeData, source) has_data = True break if has_data is False: - obj.run(None) + obj.run(None, source) else: for obj in planes.values(): - obj.run(None) - elif main_config.get('DATA', 'SOURCE') == "OPENS": + obj.run(None, source) + elif failed: + failed_count += 1 + elif source == "OPENS": from defOpenSky import pullOpenSky planeData, failed = pullOpenSky(planes) if failed == False: @@ -64,20 +68,22 @@ while True: has_data = False for dataState in planeData.states: if (dataState.icao24).upper() == key: - obj.run(dataState) + obj.run(dataState, source) has_data = True break if has_data is False: - obj.run(None) + obj.run(None, source) else: for obj in planes.values(): - obj.run(None) + obj.run(None, source) + if failed_count >= 10: + source = "OPENS" elapsed_calc_time = time.time() - start_time datetime_tz = datetime.now(tz) print (Back.GREEN, Fore.BLACK, "--------", running_Count, "--------", datetime_tz.strftime("%I:%M:%S %p"), "------------------------Elapsed Time-", elapsed_calc_time, " -------------------------------------", Style.RESET_ALL) - sleep_sec = 20 + sleep_sec = 5 for i in range(sleep_sec,0,-1): if i < 10: i = " " + str(i) diff --git a/planeClass.py b/planeClass.py index a8919d4..b407ecc 100644 --- a/planeClass.py +++ b/planeClass.py @@ -14,16 +14,17 @@ class Plane: self.latitude = None self.callsign = None self.takeoff_time = None - self.reg = None + self.map_file_name = icao.upper() + "_map.png" self.last_latitude = None self.last_longitude = None self.recheck_needed = None self.last_recheck_needed = None self.last_contact = None + self.last_feed_data = None def getICAO(self): return self.icao - def run(self, ac_dict): + def run(self, ac_dict, source): #Import Modules #Clear Terminal @@ -40,8 +41,6 @@ class Plane: import configparser self.config = configparser.ConfigParser() self.config.read(("./configs/"+ self.conf_file)) - main_config = configparser.ConfigParser() - main_config.read('./configs/mainconf.ini') #Platform for determining OS for strftime import platform @@ -76,8 +75,9 @@ class Plane: self.latitude = None self.on_ground = None self.has_location = None + time_since_contact = None #Parse OpenSky Vector - if main_config.get('DATA', 'SOURCE') == "OPENS": + if source == "OPENS": self.val_error = False if ac_dict != None: #print (Fore.YELLOW + "OpenSky Sourced Data: ", ac_dict) @@ -93,7 +93,7 @@ class Plane: print(e) #Parse ADBSX Vector - elif main_config.get('DATA', 'SOURCE') == "ADSBX": + elif source == "ADSBX": self.val_error = False if ac_dict != None: #print (Fore.YELLOW +"ADSBX Sourced Data: ", ac_dict, Style.RESET_ALL) @@ -179,7 +179,7 @@ class Plane: self.tookoff = True self.trigger_type = "no longer on ground" self.tookoff_header = "Took off from " - elif self.last_feeding is False and self.feeding: + elif self.last_feeding is False and self.feeding and self.last_feed_data == None: self.tookoff = True self.trigger_type = "data acquisition" self.tookoff_header = "Took off near " @@ -193,19 +193,26 @@ class Plane: #Check if Landed - if self.last_below_desired_ft: - if self.on_ground and self.last_on_ground is False: - self.landed = True - self.trigger_type = "now on ground" - self.landed_header = "Landed in " - elif self.last_feeding and self.feeding is False and self.last_on_ground is False: - self.landed = True - self.trigger_type = "data loss" - self.landed_header = "Landed near " - else: - self.landed = False + if self.on_ground and self.last_on_ground is False and self.last_below_desired_ft: + self.landed = True + self.trigger_type = "now on ground" + self.landed_header = "Landed in " + self.last_feed_data = None + #Store a dictionary when data is lost near landing conditions, + elif self.last_below_desired_ft and self.last_feeding and self.feeding is False and self.last_on_ground is False: + self.last_feed_data = {} + self.last_feed_data.update(self.__dict__) + print("Latest data stored") + + elif self.last_feed_data != None and self.feeding is False and time_since_contact.seconds >= 300: + self.__dict__.update(self.last_feed_data) + self.last_feed_data = None + self.landed = True + self.trigger_type = "data loss" + self.landed_header = "Landed near " else: self.landed = False + #self.landed = bool(self.last_below_desired_ft and ((self.last_feeding and self.feeding is False and self.last_on_ground is False) or (self.on_ground and self.last_on_ground is False))) #print ("Landed Just Now:", self.landed) if self.landed: