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 })
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)
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))
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)
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)
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"))
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)
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()
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)
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)
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))
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)
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
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"
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"
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"
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]):
def trip_state(): return DB().get_trip_state()
def ajax_get_total_drove_wrong_distance(): return str(round((DB().get_total_distance_wrong() / 1000), 2))
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()
def ajax_cur_speed(): speed = DB().get_cur_speed() if speed > 1: return str(speed) else: return str(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]
def ajax_reset_database(): DB().reset_database() return "OK"
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]
def ajax_update_toggle_trip_state(): trip = request.form.get("trip") state = request.form.get("state") DB().toggle_trip_state(trip, state) return "OK"
def ajax_get_trip_state(): return str(DB().get_trip_state())
def ajax_get_toggle_trip_distance(trip): return str(round((DB().get_toggle_trip_distance(trip) / 1000), 2))
def ajax_reset_toggle_trip(): trip = request.form.get("trip") return str(DB().reset_toggle_trip(trip))
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''')
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 + '"', })