Ejemplo n.º 1
0
    def report_events(self):

        takeoff_time = Aircraft.event_not_detected
        landing_time = Aircraft.event_not_detected
        total_duration = datetime.timedelta(seconds=0)

        for count, event in enumerate(self.events):
            if isinstance(event, TakeoffEvent):
                takeoff_time = event.getTimestamp()
                takeoff_rwy = event.getRwy()
                takeoff_alt_agl = event.getAltitudeAGL()
                takeoff_speed = event.speed

            if isinstance(event, LandingEvent):
                landing_time = event.getTimestamp()
                landing_rwy = event.getRwy()
                landing_alt_agl = event.getAltitudeAGL()
                landing_speed = event.speed

                duration = landing_time - takeoff_time
                total_duration += duration

                if landing_time < takeoff_time + datetime.timedelta(hours=16):
                    print(
                        "%2d " % count,
                        "%s" % str(takeoff_time.astimezone(Groundstation.timezone())),
                        " R%02d" % takeoff_rwy,
                        " %+3dagl" % takeoff_alt_agl,
                        " %3dkph" % takeoff_speed.kph(),
                        "%6s" % " ==>> ",
                        "%s" % str(landing_time.astimezone(Groundstation.timezone())),
                        " R%02d" % landing_rwy,
                        " %+3dagl" % landing_alt_agl,
                        " %3dkph " % landing_speed.kph(),
                        duration,
                        sep='')
                else:
                    print("Landing", landing_time)

        print("%104s" % "======= ")
        print("%95s" % " ",
              total_duration)
Ejemplo n.º 2
0
    def detect_takeoff(self, window):

        if not window:
            return Aircraft.event_not_detected

        # takeoff inital rolling speed
        # when too slow, a towplane rolling-up to a glider
        # gets included! The heading of the towplane is wrong at that point,
        # which messes with runway calculation.

        rolling = window[0]
        # rolling_low = Aircraft.takeoff_rolling_min()
        # rolling_high = Aircraft.takeoff_rolling_max()
        lower_limit, higher_limit = Aircraft.takeoff_rolling_limits()
        if not lower_limit <= rolling.speed.kph() <= higher_limit:
            return Aircraft.event_not_detected

        climbout = window[-1]

        # climbout speed at least this
        if not climbout.speed.kph() >= Aircraft.climbout_speed_min():
            return Aircraft.event_not_detected

        # must be close to the ground initially
        if not Groundstation.at_groundlevel(rolling.get_alt_agl()):
            return Aircraft.event_not_detected

        # must be at least this much higher during climbout
        if not climbout.get_alt_agl() >= rolling.get_alt_agl() + Aircraft.climbout_alt_min():
            return Aircraft.event_not_detected


        # at this point, a takeoff event has been reliably detected.

        # determine the track of the aircraft.
        track = Aircraft.detect_track(window)

        # set all the pertinent properties of the takeoff and
        # append the event for this aircraft.
        takeoff = TakeoffEvent(rolling.get_timestamp(), rolling.lat, rolling.lon,
                               rolling.get_alt_agl(), track, rolling.speed)
        self.events.append(takeoff)

        # return the timestamp of the takeoff event.
        return rolling.get_timestamp()
Ejemplo n.º 3
0
    def detect_landing(self, window):

        if not window:
            return Aircraft.event_not_detected

        rollout = window[-1]

        # ensure rollout speed
        if not rollout.speed.kph() <= Aircraft.rolling_speed_max():
            return Aircraft.event_not_detected

        # ensure on the ground
        if not Groundstation.at_groundlevel(rollout.get_alt_agl()):
            return Aircraft.event_not_detected

        approach = window[0]

        # ensure approaching at speed
        if not approach.speed.kph() >= Aircraft.approach_speed_min():
            return Aircraft.event_not_detected

        # ensure approaching from altitude
        if not approach.get_alt_agl() >= rollout.get_alt_agl() + Aircraft.approach_alt_min():
            return Aircraft.event_not_detected

        # at this point, a landing event has been reliably detected.

        # determine the track of the landed aircraft.
        track = Aircraft.detect_track(window)

        # set all the pertinent properties of the landing and append
        # the event to the list of events for this aircraft.
        landing = LandingEvent(rollout.get_timestamp(), rollout.lat, rollout.lon,
                               rollout.get_alt_agl(), track, rollout.speed)
        self.events.append(landing)

        # return the rollout timestamp of the landing event.
        return rollout.get_timestamp()
Ejemplo n.º 4
0
    def detect_track(window):
        track = 0
        count = 0

        for ndx, observation in enumerate(window):
            if Groundstation.at_groundlevel(
                    observation.get_alt_agl() and
                    observation.speed.kph() > 10):

                # this won't work for North, where values are near 360 and 0

                track += observation.get_track()
                count += 1

        # calculate the average
        track = int(track/count)

        # correct for known runways. This is Kars specific, for now.
        if 220 <= track <= 270:
            track = 260
        elif 60 <= track <= 100:
            track = 80

        return int(track)
Ejemplo n.º 5
0
 def get_alt_agl(self):
     return self.relative_vertical - Groundstation.height_of_groundstation()
Ejemplo n.º 6
0
def eachAircraft(infile):

    groundstation = Groundstation()

    aircraft_seen = {}

    conn = sqlite3.connect('flightevents.db')

    nmea = open(infile, 'r')

    for line in nmea:
        try:
            commas = line.count(',')
            sentence = pynmea2.parse(line, check=True)
        except pynmea2.ChecksumError:
            # ignore sentences that produce a checksum error
            continue
        except pynmea2.ParseError:
            # ignore sentences that can't be parsed
            continue

        # ignore Flarm PFLAU sentences
        if Observation.is_pflau_sentence(sentence):
            continue

        # The groundstation must have received the UTC time from the GPS
        # before we permit any processing of Flarm PFLAA observations.
        if (groundstation.valid_time()
                and Observation.is_pflaa_sentence(sentence)):
            observation = Observation()
            if observation.set(conn, groundstation, sentence):
                aircraft_id = observation.get_aircraft_id()
                if aircraft_id not in aircraft_seen:
                    aircraft_seen[aircraft_id] = Aircraft(aircraft_id)
                aircraft_seen[aircraft_id].append_observations(observation)

        elif sentence.sentence_type == 'RMC':
            # this sentence contains the current date
            groundstation.set_date(sentence.datestamp)
            groundstation.set(sentence)
        elif (sentence.sentence_type == 'GGA' and groundstation.valid_date()
              and commas == 14):

            # this sentence has the groundstation timestamp, lat, lon, elevation
            groundstation.set(sentence)

    conn.close()

    print("%s" % list(aircraft_seen.keys()))

    groundstation.report()

    # reg = "C-GFOP"
    # print("")
    # print(reg)
    # aircraft_seen[reg].printObservations()

    print("")
    print("FLIGHTS PER AIRCRAFT")
    print("====================")
    for aircraft in list(aircraft_seen.keys()):
        print("")
        print(aircraft)
        aircraft_seen[aircraft].detect_events()
        aircraft_seen[aircraft].report_events()

    flight_sheet = []
    for aircraft in list(aircraft_seen.keys()):
        reg = aircraft_seen[aircraft].get_aircraft_id()
        the_events = aircraft_seen[aircraft].events
        for event in the_events:
            if isinstance(event, TakeoffEvent):
                launch_event = LaunchEvent(reg, event.getTimestamp(),
                                           event.getLat(), event.getLon(),
                                           event.getAltitudeAGL(),
                                           event.getTrack(), event.speed)
                flight_sheet.append(launch_event)

    flight_sheet.sort()

    print("")
    print("Flight Sheet")
    print("============")

    item_num = 1

    # we work with pairs, so starting at the second takeoff and looking at
    # the first...
    for ndx in range(1, len(flight_sheet)):
        previous = flight_sheet[ndx - 1].getTimestamp()
        current = flight_sheet[ndx].getTimestamp()
        if ndx < len(flight_sheet) - 1:
            nxt = flight_sheet[ndx + 1].getTimestamp()
        else:
            nxt = Event.event_not_detected

        # are the current and previous takeoff within 30 seconds?
        if (previous - datetime.timedelta(seconds=30) < current <
                previous + datetime.timedelta(seconds=30)):
            # this is a takeoff pair
            print("%02d" % item_num, "Launch ", current,
                  "R%02d" % flight_sheet[ndx].getRwy(),
                  flight_sheet[ndx].getReg(), flight_sheet[ndx - 1].getReg())
            item_num += 1
        # the pair is not a match. what about the upcoming pair?
        elif nxt - datetime.timedelta(
                seconds=30) < current < nxt + datetime.timedelta(seconds=30):
            # do nothing. the next iteration of the loop will process the pair
            pass
        else:
            # this is a lone takeoff event
            print("%02d" % item_num, "Takeoff", current,
                  "R%02d" % flight_sheet[ndx].getRwy(),
                  flight_sheet[ndx].getReg())
            item_num += 1

    return
Ejemplo n.º 7
0
def eachAircraft():

    groundstation = Groundstation()

    aircraft_seen = {}

    conn = sqlite3.connect('flightevents.db')

    nmea = open('data.nmea', 'r')

    for line in nmea:
        try:
            commas = line.count(',')
            sentence = pynmea2.parse(line, check=True)
        except pynmea2.ChecksumError:
            # ignore sentences that produce a checksum error
            continue
        except pynmea2.ParseError:
            # ignore sentences that can't be parsed
            continue

        # ignore Flarm PFLAU sentences
        if Observation.is_pflau_sentence(sentence):
            continue

        # The groundstation must have received the UTC time from the GPS
        # before we permit any processing of Flarm PFLAA observations.
        if (groundstation.valid_time()
                and Observation.is_pflaa_sentence(sentence)):
            observation = Observation()
            if observation.set(conn, groundstation, sentence):
                aircraft_id = observation.get_aircraft_id()
                if aircraft_id not in aircraft_seen:
                    aircraft_seen[aircraft_id] = Aircraft(aircraft_id)
                aircraft_seen[aircraft_id].append_observations(observation)

        elif sentence.sentence_type == 'RMC':
            # this sentence contains the current date
            groundstation.set_date(sentence.datestamp)
            groundstation.set(sentence)
        elif (sentence.sentence_type == 'GGA' and groundstation.valid_date()
              and commas == 14):

            # this sentence has the groundstation timestamp, lat, lon, elevation
            groundstation.set(sentence)

    conn.commit()
    conn.close()

    print("%s" % list(aircraft_seen.keys()))

    groundstation.report()

    return