コード例 #1
0
    def pedir_datos(self):
        while True:

            try:
                self.coeficiente = int(
                    input("Por favor, introduce el coeficiente de x: "))
                break
            except ValueError:
                print(
                    "Error! El coeficiente introducido no es un número. Por favor, inténtelo de nuevo."
                )

        while True:

            try:
                self.termino_independiente = int(
                    input("Por favor, introduce el término independiente: "))
                break
            except ValueError:
                print(
                    "Error! El término introducido no es un número. Por favor, inténtelo de nuevo."
                )

        db = DB('demo')
        self.id = db.insert(
            'ecuacion', {
                'coeficiente': self.coeficiente,
                'termino_independiente': self.termino_independiente
            })
コード例 #2
0
def tripmaster():
    # Prefered average speed
    pref_avg_speed = DB().get_pref_avg_speed()
    # Ideal start time
    ideal_start_time = DB().get_ideal_start_time()

    return render_template('tripmaster.html',
                           pref_avg_speed=pref_avg_speed,
                           ideal_start_time=ideal_start_time)
コード例 #3
0
def loadDBs():
    try:
        dbs = {}
        dbs['57'] = DB(57, 0, 72)
        dbs['55'] = DB(55, 0, 72)
        return dbs
    except Exception as e:
        print e
        logging.error(str(e))
コード例 #4
0
def ajax_update_trip_state():
    state = DB().get_trip_state()
    if state == 0:
        # Update to the 1 state
        DB().update_trip_state(1)
    else:
        # Update to the 0 state
        DB().update_trip_state(0)
    return str(state)
コード例 #5
0
def ajax_update_wrong_traject_state():
    state = DB().get_wrong_traject_state()
    if state == 0:
        # Update to the 1 state
        DB().update_wrong_traject_state(1)
    else:
        # Update to the 0 state
        DB().update_wrong_traject_state(0)
    return str(state)
コード例 #6
0
def ajax_get_trip_ideal_stop_time():
    total_dist = DB().get_total_distance() - DB().get_total_distance_wrong()
    total_dist_m = total_dist / 1000
    time = 60
    avg = DB().get_pref_avg_speed()
    minutes_to_add = (total_dist_m * time) / avg
    start_time = datetime.datetime.strptime(str(DB().get_ideal_start_time()),
                                            '%H:%M:%S')
    ideal_stop_time = start_time + datetime.timedelta(minutes=minutes_to_add)
    return str(ideal_stop_time.strftime("%H:%M:%S"))
コード例 #7
0
ファイル: Formulas.py プロジェクト: RosiersRobin/Tripmaster
 def avg_speed():
     # Speed = Distance ÷ Time
     cur_time = datetime.datetime.now().replace(microsecond=0)
     db_time_record = datetime.datetime.strptime(DB().start_time(),
                                                 "%Y-%m-%d %H:%M:%S")
     elapsed = cur_time - db_time_record
     seconds = elapsed.total_seconds()
     # print(str(time_diff).split(":"))
     total_distance = DB().get_total_distance()
     result = (total_distance / seconds)
     return round(result, 2)
コード例 #8
0
def loadDBs():
    try:
        dbs = {}
        dbs['50'] = DB(50, 0, 42)
        dbs['51'] = DB(51, 0, 48)
        dbs['61'] = DB(61, 0, 72)
        dbs['90'] = DB(90, 0, 82)

        return dbs
    except Exception as e:
        print e
        logging.error(str(e))
        restart_program()
コード例 #9
0
def ajax_avg_speed():
    if DB().get_trip_state() == 1:
        avg_speed = Formulas.avg_speed()
    else:
        avg_speed = 0.0
    # avg_speed = Formulas.avg_speed()
    return str(avg_speed)
コード例 #10
0
def settings():
    try:
        # First of all, we need to determine the used interface (wifi of ethernet)
        def_gw_device = ni.gateways()['default'][ni.AF_INET][1]
        # Get the IP
        ip = ni.ifaddresses(def_gw_device)[2][0]['addr']
    except KeyError:
        ip = "None"
    # Get the GPS status
    status = DB().get_fix()
    # Get the current setted screen brightness
    brightness = DB().get_screen_brightness()

    return render_template('settings.html',
                           ip=ip,
                           status=status,
                           brightness=brightness)
コード例 #11
0
def ajax_total_distance():
    # So, we need to get the total distance in KM,
    # As we speak, we have the distance in meters, but
    # we display it as KM, SOOOOOOOOOOOOO
    # we need to divide it by 1000 -> get km.
    m = DB().get_total_distance()
    distance = (m / 1000)
    return str(round(distance, 3))
コード例 #12
0
    def pedir_datos(self):
        while True:

            try:
                self.coeficiente_a = int(input("Por favor, introduce el coeficiente de x^2: "))
                break
            except ValueError:
                print("Error! El coeficiente introducido no es un número. Por favor, inténtelo de nuevo.")

        Ecuacion.pedir_datos(self)
        self.coeficiente_b = self.coeficiente
        self.coeficiente_c = self.termino_independiente

        db = DB('demo')
        coeficientes = {
            'coeficiente_a': self.coeficiente_a,
            'coeficiente_b': self.coeficiente_b,
            'coeficiente_c': self.coeficiente_c,
        }
        self.id = db.insert('ecuacion_segundo_grado', coeficientes)
コード例 #13
0
ファイル: Transporte.py プロジェクト: jdlcgarcia/resuelvEDP
    def cargar(self, identificador):
        db = DB('demo')
        ecuacion = db.select_por_id('edp_transporte', 'id', str(identificador))
        if not ecuacion:
            print("Ecuación no encontrada")
            return false

        self.id = identificador
        self.a = ecuacion[0][1]
        self.b = ecuacion[0][2]
        self.c = ecuacion[0][3]
        self.d = ecuacion[0][4]
        self.m = ecuacion[0][5]
        self.n = ecuacion[0][6]
        self.p = ecuacion[0][7]
        self.progresion = {
            'tiempo': ecuacion[0][8],
            'espacio': ecuacion[0][9]
        }
        self.condicion_inicial_x = ecuacion[0][10]
        self.condicion_inicial_t = ecuacion[0][11]
        self.inicializar_estructura()
        return true
コード例 #14
0
def ajax_update_pref_brightness():
    # Do the action
    # First get the data
    new_brightness = request.form.get('brightness')
    DB().update_screen_brightness(new_brightness)
    return "OK"
コード例 #15
0
def ajax_update_trip_ideal_start_time():
    # Do the action
    # First get the data
    new_start_time = request.form.get('ideal_time')
    DB().update_ideal_start_time(new_start_time)
    return "OK"
コード例 #16
0
def ajax_update_trip_pref_avg_speed():
    # Do the action
    # First get the data
    new_avg_speed = request.form.get('pref_speed')
    DB().update_pref_avg_speed(new_avg_speed)
    return "OK"
コード例 #17
0
ファイル: main.py プロジェクト: RosiersRobin/Tripmaster
timestamp = "010117 000000.000"


############################################################
# Timer functions
############################################################
# This conatains the variables for the timer,
# It will only start a script when there is a GPS fix and
# and it will execute the script once every 5 minutes.
############################################################
update_interval = timedelta(minutes=10)
last_update = datetime.min  # 1970-1-1 avoids having to check for None while still ensuring update @ first fix


data = None
db = DB()

while True:

    try:
        # Get the data from the serial monitor.
        data = ser.readline().decode().split(',')
        print(data)
        if data[0] == "$GPGGA" or data[0] == "$GPVTG" or data[0] == "$GPRMC":

            # Set the data to correct data to work with
            # Create a parse object to parse all the data easily
            parse = GPSParser(data)

            if Formulas.chksum_nmea(data[0]):
コード例 #18
0
 def trip_state():
     return DB().get_trip_state()
コード例 #19
0
def ajax_get_total_drove_wrong_distance():
    return str(round((DB().get_total_distance_wrong() / 1000), 2))
コード例 #20
0
ファイル: Transporte.py プロジェクト: jdlcgarcia/resuelvEDP
 def guardar_solucion(self):
     db = DB('demo')
     campos = {'puntos_solucion': self.aplanar_solucion()}
     db.update_por_id('edp_transporte', campos, 'id', self.id)
     self.pintar_grafico()
コード例 #21
0
def ajax_cur_speed():
    speed = DB().get_cur_speed()
    if speed > 1:
        return str(speed)
    else:
        return str(0)
コード例 #22
0
 def cargar(self, identificador):
     db = DB('demo')
     ecuacion = db.select_por_id('ecuacion_segundo_grado', 'id', str(identificador))
     self.coeficiente_a = ecuacion[0][1]
     self.coeficiente_b = ecuacion[0][2]
     self.coeficiente_c = ecuacion[0][3]
コード例 #23
0
def ajax_reset_database():
    DB().reset_database()
    return "OK"
コード例 #24
0
 def cargar(self, identificador):
     db = DB('demo')
     ecuacion = db.select_por_id('ecuacion', 'id', str(identificador))
     self.coeficiente = ecuacion[0][1]
     self.termino_independiente = ecuacion[0][2]
コード例 #25
0
def ajax_update_toggle_trip_state():
    trip = request.form.get("trip")
    state = request.form.get("state")
    DB().toggle_trip_state(trip, state)
    return "OK"
コード例 #26
0
def ajax_get_trip_state():
    return str(DB().get_trip_state())
コード例 #27
0
def ajax_get_toggle_trip_distance(trip):
    return str(round((DB().get_toggle_trip_distance(trip) / 1000), 2))
コード例 #28
0
def ajax_reset_toggle_trip():
    trip = request.form.get("trip")
    return str(DB().reset_toggle_trip(trip))
コード例 #29
0
from model.DB import DB

db = DB('demo')
db.create(
    'ecuacion', '''id INTEGER PRIMARY KEY,
                            coeficiente INTEGER NOT NULL,
                            termino_independiente INTEGER NOT NULL,
                            resultado REAL NULL''')
db.create(
    'ecuacion_segundo_grado', '''id INTEGER PRIMARY KEY,
                            coeficiente_A INTEGER NOT NULL,
                            coeficiente_B INTEGER NOT NULL,
                            coeficiente_C INTEGER NOT NULL,
                            resultado_1 REAL NULL,
                            resultado_2 REAL NULL''')
db.create(
    'edp_transporte', '''id INTEGER PRIMARY KEY,
                            a INTEGER NOT NULL,
                            b INTEGER NOT NULL,
                            c INTEGER NOT NULL,
                            d INTEGER NOT NULL,
                            m INTEGER NOT NULL,
                            n INTEGER NOT NULL,
                            p REAL NOT NULL,
                            progresion_tiempo INTEGER NOT NULL,
                            progresion_espacio INTEGER NOT NULL,
                            condicion_inicial_x TEXT NOT NULL,
                            condicion_inicial_t TEXT NOT NULL,
                            puntos_solucion TEXT NULL''')
コード例 #30
0
ファイル: Transporte.py プロジェクト: jdlcgarcia/resuelvEDP
    def pedir_datos(self):
        while True:
            try:
                self.a = int(input("Por favor, introduzca el primer componente del intervalo de x: "))
                break
            except ValueError:
                print("Error! El dato introducido no es un número. Por favor, inténtelo de nuevo.")

        while True:
            try:
                self.b = int(input("Por favor, introduzca el segundo componente del intervalo de x: "))
                break
            except ValueError:
                print("Error! El dato introducido no es un número. Por favor, inténtelo de nuevo.")

        while True:
            try:
                self.c = int(input("Por favor, introduzca el primer componente del intervalo de t: "))
                break
            except ValueError:
                print("Error! El dato introducido no es un número. Por favor, inténtelo de nuevo.")

        while True:
            try:
                self.d = int(input("Por favor, introduzca el segundo componente del intervalo de t: "))
                break
            except ValueError:
                print("Error! El dato introducido no es un número. Por favor, inténtelo de nuevo.")

        while True:
            try:
                self.m = int(input("Por favor, introduzca el número de nodos que se desean en el eje x: "))
                break
            except ValueError:
                print("Error! El dato introducido no es un número. Por favor, inténtelo de nuevo.")

        while True:
            try:
                self.n = int(input("Por favor, introduzca el número de nodos que se desean en el eje y: "))
                break
            except ValueError:
                print("Error! El dato introducido no es un número. Por favor, inténtelo de nuevo.")
        while True:
            try:
                self.p = float(input("Por favor, introduzca el coeficiente de Ux: "))
                break
            except ValueError:
                print("Error! El dato introducido no es un número. Por favor, inténtelo de nuevo.")
        while True:
            try:
                self.progresion['tiempo'] = int(
                    input("Por favor, introduzca el esquema en el tiempo: (1) progresivo, (0) regresivo: ")
                )
                break
            except ValueError:
                print("Error! El dato introducido no es un número. Por favor, inténtelo de nuevo.")
        while True:
            try:
                self.progresion['espacio'] = int(
                    input("Por favor, introduzca el esquema en el espacio: (1) progresivo, (0) regresivo: ")
                )
                break
            except ValueError:
                print("Error! El dato introducido no es un número. Por favor, inténtelo de nuevo.")
        while True:
            try:
                self.condicion_inicial_x = input("Por favor, introduzca la condición inicial en x: ")
                break
            except ValueError:
                print("Error! la condicion inicial en x no es válida. Por favor, inténtelo de nuevo.")
        while True:
            try:
                self.condicion_inicial_t = input("Por favor, introduzca la condicion inicial en t: ")
                break
            except ValueError:
                print("Error! la condicion inicial en t no es válida. Por favor, inténtelo de nuevo.")
        db = DB('demo')
        self.id = db.insert('edp_transporte', {
            'a': self.a,
            'b': self.b,
            'c': self.c,
            'd': self.d,
            'm': self.m,
            'n': self.n,
            'p': self.p,
            'progresion_tiempo': self.progresion['tiempo'],
            'progresion_espacio': self.progresion['espacio'],
            'condicion_inicial_x': '"' + self.condicion_inicial_x + '"',
            'condicion_inicial_t': '"' + self.condicion_inicial_t + '"',
        })