Esempio n. 1
0
 def deserialize(self, msg):
     row = None
     updated_row = False
     try:
         try:
             values = msg.split(self.delimiter)
             row = {k: v for k, v in zip(self.keys, values)}
             row = self.importer.update_row(row)
             updated_row = True
             if self.needs_flight:
                 flight = getActiveFlight()
                 row['flight'] = flight
             result = self.model(**row)
             if self.verbose:
                 print result
             return result
         except OperationalError as oe:
             reconnect_db()
             if not updated_row:
                 row = self.importer.update_row(row)
             if self.needs_flight:
                 flight = getActiveFlight()
                 row['flight'] = flight
             result = self.model(**row)
             if self.verbose:
                 print result
             return result
     except Exception as e:
         print 'deserializing:', msg
         if row:
             print 'deserialized:', row
         traceback.print_exc()
         persist_error(e, traceback.format_exc())
         return None
Esempio n. 2
0
 def deserialize(self, msg):
     """
     In this case the deserialize also stores the models
     :param msg:
     :return:
     """
     row = None
     print(msg)
     try:
         values = msg.split(self.delimiter)
         row = {k: v for k, v in zip(self.keys, values)}
         updated_row = False
         try:
             row['flight'] = getActiveFlight()
             row = self.importer.update_row(row)
             updated_row = True
             models = self.importer.build_models(row)
         except OperationalError as oe:
             reconnect_db()
             if not updated_row:
                 row['flight'] = getActiveFlight()
                 row = self.importer.update_row(row)
             models = self.importer.build_models(row)
         if self.verbose:
             print(models)
         return None  # because the importer build models stores them
     except Exception as e:
         print 'deserializing:', msg
         if row:
             print 'deserialized:', row
         traceback.print_exc()
         persist_error(e, traceback.format_exc())
         return None
Esempio n. 3
0
def get_active_dive():
    active_flight = getActiveFlight()
    if active_flight is not None:
        # there's an active flight underway
        active_dive = active_flight.group
        print 'found active dive %s ' % active_dive.name
        return active_dive
    return None
Esempio n. 4
0
def get_live_page(request):
    active_flight = getActiveFlight()
    if active_flight:
        group_flight_name = active_flight.group.name
        return getGroupFlightPlaybackPage(
            request,
            group_flight_name,
            templatePath='xgds_subsea_app/live_dive.html',
            video=False)
    return redirect('index')
Esempio n. 5
0
def get_active_track(vehicle):
    """
    Get the active track for a vehicle
    :param vehicle: the vehicle
    :return: the track or None
    """
    flight = getActiveFlight(vehicle=vehicle)
    if flight:
        return flight.track
    return None
Esempio n. 6
0
def lookup_active_flight(options):
    """
    Looks up a flight given the options
    :param options: a dictionary, should contain the vehicle or it will use the default vehicle
    :return: the found flight, and the flight name and vehicle name in options
    """
    if 'vehicle' not in options:
        vehicle = get_default_vehicle()
        options['vehicle'] = vehicle.name
    else:
        vehicle = get_vehicle(options['vehicle'])
    flight = getActiveFlight(vehicle)
    if not flight:
        options['flight'] = None
    else:
        options['flight'] = flight.name
    return flight
Esempio n. 7
0
    def __init__(self, config, prefix=""):
        self.verbose = config['verbose']
        self.prefix = prefix

        # Is there a current active group flight?
        self.active_dive = None
        active_flight = getActiveFlight()
        if active_flight is not None:
            # there's an active flight underway
            self.active_dive = active_flight.group
            print 'found active dive %s ' % self.active_dive.name

        if not self.active_dive:
            print 'NO ACTIVE DIVE'

        self.delimiter = '\t'
        self.tq = TelemetryQueue(config['channel_name'])

        # Start listener thread
        thread = threading.Thread(target=self.run)
        thread.daemon = True
        thread.start()
Esempio n. 8
0
    def deserialize(self, msg):
        row = None
        updated_row = False
        try:
            try:
                values = msg.split(self.delimiter)
                row = {k: v for k, v in zip(self.keys, values)}
                row = self.importer.update_row(row)
                updated_row = True
                if self.needs_flight:
                    flight = getActiveFlight()
                    row['flight'] = flight
                if self.verbose:
                    print 'deserialized', row
                self.queue.append(row['timestamp'], row)
            except OperationalError as oe:
                reconnect_db()
                if not updated_row:
                    row = self.importer.update_row(row)
                if self.needs_flight:
                    flight = getActiveFlight()
                    row['flight'] = flight
                if self.verbose:
                    print 'deserialized', row
                self.queue.append(row['timestamp'], row)

            # On the first time through we need to set set up the first desired time to interpolate
            # It should be the first whole interval timestamp after the first timestamp we get
            if self.desired_sample_time is None:
                self.desired_sample_time = row['timestamp']
                desired_second = int(1 + self.desired_sample_time.second / self.resample_interval_sec) * \
                                 self.resample_interval_sec
                self.desired_sample_time = self.desired_sample_time.replace(
                    second=desired_second)
                self.desired_sample_time = self.desired_sample_time.replace(
                    microsecond=0)
                if self.verbose:
                    print 'resample interval is', self.resample_interval_sec
                    print 'first desired sample time is', self.desired_sample_time

            # Get interpolated values if we can
            if len(self.queue.queue) > 1:
                models = []
                while self.queue.queue[-1][0] > self.desired_sample_time:
                    # We should have the information we need to interpolate
                    values = self.interpolate()
                    if values:
                        print 'interpolated', values
                        models.append(self.model(**values))

                    # Get rid of queued data we won't need again
                    self.queue.delete_before(self.desired_sample_time)
                    # Increment the next desired pose time
                    self.desired_sample_time += datetime.timedelta(
                        seconds=self.resample_interval_sec)
                return models
            return None

        except Exception as e:
            print 'deserializing:', msg
            if row:
                print 'deserialized:', row
            traceback.print_exc()
            persist_error(e, traceback.format_exc())
            return None