Example #1
0
    def task(self):
        for infile in self.infiles:
            with open(infile.name, 'r') as database:
                try:
                    head = [database.readline() for x in xrange(2)
                            ]  # get first two lines (header + first)
                    first_timestamp = float(head[-1].split('\t')[0])
                    # dict of files with first timestamp as key
                    self.infiles_dict[first_timestamp] = infile
                    self.num_lines += sum(1.0 for line in database)
                except Exception:
                    print 'Error in file: ' + infile.name
                    self.core.controller.print_console('Error in file: ' +
                                                       infile.name)

        for timestamp in sortedDictKeys(self.infiles_dict):
            # display name of current database running
            if not self.core.first_file_name:
                self.core.first_file_name = self.infiles_dict[timestamp].name
            print self.infiles_dict[timestamp].name
            self.core.controller.setCurrent(
                'File %d/%d: %s' %
                (self.file_count, len(self.infiles_dict),
                 get_file_name(self.infiles_dict[timestamp])))
            # icao_filter = '343147'
            icao_filter = None
            self.core.files_data_dict[timestamp] = {}  # icao_dict
            self.extract_data.run(timestamp, self.infiles_dict[timestamp],
                                  icao_filter)
            self.file_count += 1
            # validate when finished with each file
            self.core.validate(False)

        if not self.forced_exit:
            self.core.done()
Example #2
0
 def set_new_pos(self, epoch, lon, lat, alt):
     # some icao sending positions may be a ground vehicle
     if self.not_an_aircraft and alt > airport_altitude + 100:
         self.not_an_aircraft = False
     for key in sortedDictKeys(self.pos_buffer_dict):
         if len(self.pos_buffer_dict.keys(
         )) > self.min_buffer_items and epoch - key > self.buffer_time:
             self.pos_buffer_dict.pop(key,
                                      None)  # remove key for old position
     self.pos_buffer_dict[epoch] = Position(lon, lat, alt, epoch)
Example #3
0
    def set_call(self, new_call, epoch):
        if not self.flights_dict.keys():
            new_callsign = Callsign(self, new_call, epoch)
            self.flights_dict[new_callsign] = Flight(new_callsign, self, epoch)
            return

        current_callsign = sortedDictKeys(self.flights_dict)[-1]

        if current_callsign.call == new_call:
            # new call already in flight_dict.keys(). Same or new flight?
            if epoch - current_callsign.last_seen < 3600:  # same flight
                self.flights_dict[current_callsign].set_last_seen(epoch)
            else:  # new flight
                new_callsign = Callsign(self, new_call, epoch)
                self.flights_dict[new_callsign] = Flight(
                    new_callsign, self, epoch)

        elif current_callsign.call == no_call:
            if new_call == no_call:
                # current_callsign is no_call and another no_call shows up... treat as same?
                self.flights_dict[current_callsign].set_last_seen(epoch)
                return

            for callsign in self.flights_dict.keys():
                # check if this no_call is in between a previous callsign with same call
                if callsign.call == new_call and epoch - callsign.last_seen < 1800:
                    # no_call was splitting a same call for at most 30 min, ideally merge this no_call to prev call
                    self.flights_dict.pop(current_callsign, None)
                    self.flights_dict[callsign].set_last_seen(epoch)
                    return

            # move current_flight to a known call key
            new_callsign = Callsign(self, new_call, epoch)
            self.flights_dict[new_callsign] = self.flights_dict[
                current_callsign]
            self.flights_dict.pop(current_callsign, None)
            self.flights_dict[new_callsign].callsign = new_callsign
            self.flights_dict[new_callsign].set_last_seen(epoch)

        else:
            # simply a new different call
            new_callsign = Callsign(self, new_call, epoch)
            self.flights_dict[new_callsign] = Flight(new_callsign, self, epoch)
Example #4
0
 def get_current_flight(self):
     if self.flights_dict.keys():
         return self.flights_dict[sortedDictKeys(self.flights_dict)[-1]]
Example #5
0
 def set_new_vel(self, epoch, vrate, gs, ttrack):
     for key in sortedDictKeys(self.vel_buffer_dict):
         if len(self.pos_buffer_dict.keys(
         )) > self.min_buffer_items and epoch - key > self.buffer_time:
             self.vel_buffer_dict.pop(key, None)  # remove key for old entry
     self.vel_buffer_dict[epoch] = Velocity(epoch, vrate, gs, ttrack)