def analyseList(eventlist, dbconn, airport, logToDB=False, debug=False, printJSON=False, quiet=False): """ Attempts to determine if event was a takeoff or landing Args: eventlist: A list of planereports ordered by time dbconn: a psycopg2 connection to a Postgres DB. Will be used to log events. logToDB: boolean to trigger logging events to a DB debug: Boolean for printing debug statements Returns: Nothing """ firstplane = eventlist[0] lastplane = eventlist[-1] if firstplane.altitude >= lastplane.altitude: event = "landed at " elif firstplane.altitude < lastplane.altitude: event = "took off at" elif firstplane.vert_rate < -200 and lastplane.vert_rate > 100: if not quiet: print("Starting vert_rate", firstplane.vert_rate, "altitude", firstplane.altitude, firstplane.speed, "at", time.strftime("%F %H:%M:%S", time.localtime(firstplane.time)), "ending vert_rate", lastplane.vert_rate, "altitude", lastplane.altitude, lastplane.speed, "at", time.strftime("%F %H:%M:%S", time.localtime(lastplane.time))) event = "bump and go" else: event = "dunno what to call this" airport_event = pr.AirportDailyEvents(airport=airport, event_time=lastplane.time, type_of_event=event[0], flight=lastplane.flight, hex=lastplane.hex) if not quiet: if printJSON: print(airport_event.to_JSON()) else: print("Plane", lastplane.hex, "as flight", lastplane.flight, event, time.strftime("%F %H:%M:%S", time.localtime(lastplane.time))) if logToDB: airport_event.logToDB(dbconn, printQuery=debug) dbconn.commit()
def analyseList(eventlist, dbconn, airport, runway, logToDB=False, debug=False, printJSON=False, quiet=False): """ Attempts to determine if event was a takeoff or landing Args: eventlist: A list of planereports ordered by time dbconn: a psycopg2 connection to a Postgres DB. Will be used to log events. logToDB: boolean to trigger logging events to a DB debug: Boolean for printing debug statements Returns: Nothing """ firstplane = eventlist[0] lastplane = eventlist[-1] middleplane = eventlist[int(len(eventlist) / 2)] # # Are we actually using this runway, or are we crossing it? # Use runway heading and middleplane heading to find out. # otherheading = runway.heading - 180 if otherheading < 0: otherheading += 360 if not checkbearing(middleplane.track, runway.heading, 4) and not checkbearing( middleplane.track, otherheading, 4): return if firstplane.altitude >= lastplane.altitude: event = "landed at" elif firstplane.altitude < lastplane.altitude: event = "took off at" else: event = "dunno what to call this" airport_event = pr.AirportDailyEvents(airport=airport, event_time=lastplane.time, type_of_event=event[0], flight=lastplane.flight, hex=lastplane.hex, runway=runway.name) if not quiet: if printJSON: print(airport_event.to_JSON()) else: print("Plane", lastplane.hex, "as flight", lastplane.flight, event, time.strftime("%F %H:%M:%S", time.localtime(lastplane.time)), "on runway", runway.name) if logToDB: airport_event.logToDB(dbconn, printQuery=debug) dbconn.commit()