Пример #1
0
def insertLog(data=None): 
    """ 
        Query, que inserta la data en la tabla de Log 

        >>> import Log.logDB
        >>> import datetime
        >>> # Si el ANT051 esta registrado en la tabla gps
        >>> data = {'codEvent': '05', 'weeks': '1693', 'dayWeek': '4', 'ageData': '2', 'position': '(4.81534,-75.69489)', 'type': 'R', 'address': ('127.0.0.1', 54436), \
        ... 'geocoding': u'RUEDA MILLONARIA PEREIRA, Calle 18 # CARRERA 7, Pereira, Colombia', 'data': '>REV051693476454+0481534-0756948900102632;ID=ANT051<', 'course': '026', \
        ... 'gpsSource': '3', 'time': '76454', 'lat': '4.81534', 'typeEvent': 'EV', 'lng': '-75.69489', 'datetime': datetime.datetime(2012, 7, 16, 18, 34, 38, 833105), 'speed': 1.0, 'id': 'ANT051'}
        >>> Log.logDB.insertLog(data)
        procpid: 6390
        Actualizando y Cerranda la conexión
        'INSERT 0 1'
        >>>
        >>> # Si el ANT050 no esta registrado en la tabla gps
        >>> data = {'codEvent': '05', 'weeks': '1693', 'dayWeek': '4', 'ageData': '2', 'position': '(4.81534,-75.69489)', 'type': 'R', 'address': ('127.0.0.1', 54436), \
        ... 'geocoding': u'RUEDA MILLONARIA PEREIRA, Calle 18 # CARRERA 7, Pereira, Colombia', 'data': '>REV051693476454+0481534-0756948900102632;ID=ANT051<', 'course': '026', \
        ... 'gpsSource': '3', 'time': '76454', 'lat': '4.81534', 'typeEvent': 'EV', 'lng': '-75.69489', 'datetime': datetime.datetime(2012, 7, 16, 18, 34, 38, 833105), 'speed': 1.0, 'id': 'ANT050'}
        >>> Log.logDB.insertLog(data)
        procpid: 6437
        Actualizando y Cerranda la conexión
        'INSERT 0 0'
        >>> 

    """
    query = """INSERT INTO log_gps (name, address, evento, fecha, posicion, ubicacion, grados, altura, satelites, estado_data, trama) 
               VALUES (%(id)s, %(address)s, 
                       %(codEvent)s, %(datetime)s, 
                       %(position)s, %(geocoding)s, 
                       %(course)s, %(altura)s, %(gpsSource)s, 
                       %(ageData)s, %(data)s)
            """
    db = PgSQL()
    return db.exe(query, data)
Пример #2
0
def insertLog(data=None): 
    """ 
        Query, que inserta la data en la tabla de Log 
    """
    query = """INSERT INTO log_gps (name, address, evento, fecha, posicion, ubicacion, grados, altura, satelites, estado_data, trama) 
               VALUES (%(id)s, %(address)s, 
                       %(codEvent)s, %(datetime)s, 
                       %(position)s, %(geocoding)s, 
                       %(course)s, %(altura)s, %(gpsSource)s, 
                       %(ageData)s, %(data)s)
            """
    db = PgSQL()
    return db.exe(query, data)
Пример #3
0
def event7(data=None): 
    # Insert vehicle_state:
    #queryVehiState = """SELECT fn_ingresar_vehicle_state(%(gps_id)s,  'f', NULL, NULL, NULL);"""
    queryVehiState = """SELECT fn_ingresar_vehicle_state(%(gps_id)s,  'f', NULL, NULL, NULL, %(datetime)s);"""

    try:
        from DB.pgSQL import PgSQL
        db = PgSQL()
        db.cur.execute(queryVehiState, data)
        print "Se guardan los stados del vehiculo" # Print de prueba
    except:
        exc_type, exc_value, exc_traceback = sys.exc_info()
        print >> sys.stderr, '-'*60
        print >> sys.stderr, "*** print exception <<insertEventShutdown>>:"
        traceback.print_exception(exc_type, exc_value, exc_traceback,
                                           limit=2, file=sys.stderr)
        print >> sys.stderr, '-'*60
        return "No se guarda el Start"
    finally:
        print >> sys.stdout, "Actualizando y Cerranda la conexión"
        # Realizamos los cambios en la DB
        db.conn.commit()
        # Cerramos la comunicación
        db.cur.close()
        db.conn.close()

    return "Shutdown"
Пример #4
0
    def insert(data):
        """ 
            Llama la función PL/pgSQL. 
        """
        from DB.pgSQL import PgSQL
            
        print "\nINSERT:", evento.__name__ # print de prueba 
        
        ###### SQL:
        # Insert Positions:
        queryPositions = """SELECT fn_save_event_position_gps(%(id)s, %(position)s, %(geocoding)s, 
                         %(speed)s, %(altura)s, %(course)s, %(gpsSource)s, %(address)s, %(datetime)s);"""
        # Insert Eventos:
        queryEventos = """INSERT INTO eventos(gps_id, positions_gps_id, type, fecha) 
                          VALUES (%(gps_id)s, %(positions_id)s, %(codEvent)s, %(datetime)s);"""

        try:
            print "Insert Positions_gps" # Print de prueba
            db = PgSQL()
            db.cur.execute(queryPositions, data) # INSERT positions_gps

            if evento.__name__ == "event5": return evento(data) # Terminamos la ejecucion Llamando a event5
            try:
                # Si no se realiza la inserción no retorna nada.
                data['positions_id'], data['gps_id'] = eval(db.cur.fetchone()[0]) # No exite en gps retorna (None,). Si active=f retorna ('(,)',). 
                                                                                  # Para lo cual sucede una excepción y se termina la ejecución. 
            except:
                print "Se termina de Gestionar el Evento", evento.__name__
                return # Se termina la ejecución. 
                
            print "RETURN:", data['positions_id'], data['gps_id'] # print de prueba 

            # Insert Eventos:
            print "Insert Eventos" # Print de prueba
            db.cur.execute(queryEventos, data) # INSERT eventos

        except:
            exc_type, exc_value, exc_traceback = sys.exc_info()
            print >> sys.stderr, '-'*60
            print >> sys.stderr, "*** print exception <<insertEvent>>:"
            traceback.print_exception(exc_type, exc_value, exc_traceback,
                                               limit=2, file=sys.stderr)
            print >> sys.stderr, '-'*60
            return
        finally:
            print >> sys.stdout, "Actualizando y Cerranda la conexión"
            # Realizamos los cambios en la DB
            db.conn.commit()
            # Cerramos la comunicación
            db.cur.close()
            db.conn.close()


        return evento(data) 
Пример #5
0
    def insert(data):
        """ 
            Llama la función PL/pgSQL. 
        """
        from DB.pgSQL import PgSQL

        ###### SQL:
        # Insert Positions:
        queryPositions = """SELECT fn_save_event_position_gps(%(id)s, %(position)s, %(geocoding)s, 
                         %(speed)s, %(altura)s, %(course)s, %(gpsSource)s, %(address)s, %(datetime)s);"""
        # Insert Eventos:
        queryEventos = """INSERT INTO eventos(gps_id, positions_gps_id, type, fecha) 
                          VALUES (%(gps_id)s, %(positions_id)s, %(codEvent)s, %(datetime)s);"""

        try:
            db = PgSQL()
            db.cur.execute(queryPositions, data)

            if evento.__name__ == "event5": return evento(data)
            try:
                data['positions_id'], data['gps_id'] = eval(
                    db.cur.fetchone()[0])
            except:
                return

            db.cur.execute(queryEventos, data)

        except:
            exc_type, exc_value, exc_traceback = sys.exc_info()
            print >> sys.stderr, '-' * 60
            print >> sys.stderr, "*** print exception <<insertEvent>>:"
            traceback.print_exception(exc_type,
                                      exc_value,
                                      exc_traceback,
                                      limit=2,
                                      file=sys.stderr)
            print >> sys.stderr, '-' * 60
            return
        finally:
            db.conn.commit()
            db.cur.close()
            db.conn.close()

        return evento(data)