def verEspectro(): data = request.get_json() data['errorBd'] = "" nombreMisionCrear = data['nombreMisionCrear'] waypointSeleccionado = data['waypointSeleccionado'] try: conn = conexion() daoMision = DaoMision(conn) mision = daoMision.getMisionNombre(nombreMisionCrear) idMision = mision.id daoWaypoints = DaoWaypoints(conn) wayp = daoWaypoints.getWaypointByNumber(waypointSeleccionado, idMision) idWayp = wayp.id daoEspway = DaoEspway(conn) espway = daoEspway.getEspwayWaypoint(idWayp) idEspectro = espway.espectros_id daoEspectros = DaoEspectros(conn) espectro = daoEspectros.getEspectros(idEspectro) resultado = espectro.resultado conn.close() b = makeImageC(resultado, 1) with open(b, "rb") as image_file: encoded_string = base64.b64encode(image_file.read()) encoded_string = encoded_string.decode("utf-8") data['espectroC'] = encoded_string except Exception as errorBd: data['errorBd'] = "T" raise errorBd finally: return json.dumps(data)
def guardarTodos(): data = request.get_json() data['errorBd'] = "" nombreMisionCrear = data['nombreMisionCrear'] ruta = str(data['ruta']) usuario = str(data['usuario']) try: if os.path.isdir(ruta): data['errorCarpeta'] = "" idsWaypoints = [] idsEspectros = [] latlonsWaypoints = [] conn = conexion() daoMision = DaoMision(conn) mision = daoMision.getMisionNombre(nombreMisionCrear) idMision = mision.id altura = mision.elevacion daoWaypoints = DaoWaypoints(conn) waypointsList = daoWaypoints.getAllWaypoints2(idMision) for i in range(0, len(waypointsList)): idsWaypoints.append(waypointsList[i].id) latlonsWaypoints.append(waypointsList[i].latlon) print(idsWaypoints) for i in range(0, len(idsWaypoints)): daoEspway = DaoEspway(conn) espway = daoEspway.getEspwayWaypoint(idsWaypoints[i]) idEspectro = espway.espectros_id idsEspectros.append(idEspectro) print(idsEspectros) for i in range(0, len(idsEspectros)): latlons = latlonsWaypoints[i].split(",") rutaG = ruta daoEspectros = DaoEspectros(conn) espectro = daoEspectros.getEspectros(idsEspectros[i]) resultado = espectro.resultado rutaG += "/Usuario("+usuario+")"+"Mision("+nombreMisionCrear+")"+ "WaypointNumber("+str(i)+")" print(rutaG) generate(resultado, rutaG, float(latlons[0]), float(latlons[1]), altura) # generate(resultado, rutaG, float(latlons[0]), float(latlons[1]), 5) conn.close() else: data['errorCarpeta'] = "T" # with open("D:/Tesis/Api/Flask/imagenEspectroC2.png", "rb") as image_file: # encoded_string = base64.b64encode(image_file.read()) # encoded_string = encoded_string.decode("utf-8") # data['espectroR'] = encoded_string pass except Exception as errorBd: data['errorBd'] = "T" raise errorBd return json.dumps(data)
def guardarTodos(): data = request.get_json() data['errorBd'] = "" nombreMisionCrear = data['nombreMisionCrear'] ruta = str(data['ruta']) filePath = FileManagement.to_relative(ruta) usuario = str(data['usuario']) try: if os.path.isdir(filePath): data['errorCarpeta'] = "" idsWaypoints = [] idsEspectros = [] latlonsWaypoints = [] conn = conexion() daoMision = DaoMision(conn) mision = daoMision.getMisionNombre(nombreMisionCrear) idMision = mision.id altura = mision.elevacion daoWaypoints = DaoWaypoints(conn) waypointsList = daoWaypoints.getAllWaypoints2(idMision) print(waypointsList[0].id, waypointsList[1].id) #272" lista de obj for i in range(0, len(waypointsList)): idsWaypoints.append(waypointsList[i].id) latlonsWaypoints.append(waypointsList[i].latlon) print(idsWaypoints) # print("J") print(latlonsWaypoints) for i in range(0, len(idsWaypoints)): daoEspway = DaoEspway(conn) espway = daoEspway.getEspwayWaypoint(idsWaypoints[i]) idEspectro = espway.espectros_id idsEspectros.append(idEspectro) for i in range(0, len(idsEspectros)): latlons = latlonsWaypoints[i].split(",") rutaG = filePath daoEspectros = DaoEspectros(conn) espectro = daoEspectros.getEspectros(idsEspectros[i]) resultado = espectro.resultado rutaG += "/Usuario(" + usuario + ")" + "Mision(" + nombreMisionCrear + ")" + "WaypointNumber(" + str( i) + ")" # filePath = FileManagement.to_relative(rutaG) generate(resultado, rutaG, float(latlons[0]), float(latlons[1]), altura) conn.close() else: data['errorCarpeta'] = "T" except Exception as errorBd: data['errorBd'] = "T" print("Error en guardarTodos: ", errorBd) raise errorBd finally: return json.dumps(data)
def guardarEspectro(): data = request.get_json() data['errorBd'] = "" data['waypointsList'] = "" data['espectroC'] = "" data['espectroR'] = "" nombreMisionCrear = data['nombreMisionCrear'] waypointSeleccionado = data['waypointSeleccionado'] ruta = str(data['ruta']) usuario = str(data['usuario']) print(waypointSeleccionado) try: if os.path.isdir(ruta): conn = conexion() daoMision = DaoMision(conn) mision = daoMision.getMisionNombre(nombreMisionCrear) idMision = mision.id altura = mision.elevacion daoWaypoints = DaoWaypoints(conn) wayp = daoWaypoints.getWaypointByNumber(waypointSeleccionado, idMision) idWayp = wayp.id latlon = wayp.latlon latlon = latlon.split(",") daoEspway = DaoEspway(conn) espway = daoEspway.getEspwayWaypoint(idWayp) idEspectro = espway.espectros_id daoEspectros = DaoEspectros(conn) espectro = daoEspectros.getEspectros(idEspectro) resultado = espectro.resultado conn.close() ruta += "/Usuario("+usuario+")"+"Mision("+nombreMisionCrear+")"+ "Waypoint("+waypointSeleccionado+")" print(ruta) generate(resultado, ruta, float(latlon[0]), float(latlon[1]), altura) # generate(resultado, ruta, float(latlon[0]), float(latlon[1]), 5) # makeImageG(resultado, ruta, float(latlon[0]), float(latlon[1]), 5) # with open("D:/Tesis/Api/Flask/imagenEspectroC2.png", "rb") as image_file: # encoded_string = base64.b64encode(image_file.read()) # encoded_string = encoded_string.decode("utf-8") # data['espectroR'] = encoded_string else: data['errorCarpeta'] = "T" except Exception as errorBd: data['errorBd'] = "T" raise errorBd return json.dumps(data)
def guardarTodos(): data = request.get_json() data['errorBd'] = "" nombreMisionCrear = data['nombreMisionCrear'] ruta = str(data['ruta']) usuario = str(data['usuario']) try: idsWaypoints = [] idsEspectros = [] conn = conexion() daoMision = DaoMision(conn) mision = daoMision.getMisionNombre(nombreMisionCrear) idMision = mision.id daoWaypoints = DaoWaypoints(conn) waypointsList = daoWaypoints.getAllWaypoints2(idMision) for i in range(0, len(waypointsList)): idsWaypoints.append(waypointsList[i].id) print(idsWaypoints) for i in range(0, len(idsWaypoints)): daoEspway = DaoEspway(conn) espway = daoEspway.getEspwayWaypoint(idsWaypoints[i]) idEspectro = espway.espectros_id idsEspectros.append(idEspectro) print(idsEspectros) for i in range(0, len(idsEspectros)): rutaG = ruta daoEspectros = DaoEspectros(conn) espectro = daoEspectros.getEspectros(idsEspectros[i]) resultado = espectro.resultado rutaG += "/Usuario(" + usuario + ")" + "Mision(" + nombreMisionCrear + ")" + "WaypointNumber(" + str( i) + ")" + ".png" print(rutaG) makeImageG(resultado, rutaG) conn.close() # with open("D:/Tesis/Api/Flask/imagenEspectroC2.png", "rb") as image_file: # encoded_string = base64.b64encode(image_file.read()) # encoded_string = encoded_string.decode("utf-8") # data['espectroR'] = encoded_string pass except Exception as errorBd: data['errorBd'] = "T" raise errorBd return json.dumps(data)
def seleccionarMision(): data = request.get_json() data['errorBd'] = "" data['waypointsList'] = "" misionSeleccionada = data['misionSeleccionada'] numWaypoints = [] try: conn = conexion() daoMision = DaoMision(conn) mision = daoMision.getMisionNombre(misionSeleccionada) idMision = mision.id # stringsql = """SELECT * FROM mision WHERE nombre='%s';""" %(misionSeleccionada) # conn = psycopg2.connect(host="localhost", port = 5432, database="geospectre", user="******", password="******") # cur = conn.cursor() # cur.execute(stringsql) # idMision = cur.fetchall()[0][0] # print(idMision) # cur.close() # conn.close() daoWaypoints = DaoWaypoints(conn) waypointsList = daoWaypoints.getAllWaypoints(idMision) for i in range(0, len(waypointsList)): numWaypoints.append(str(waypointsList[i].num_waypoint)) # stringsql = """SELECT latlon FROM waypoints WHERE mision_id='%s';""" %(idMision) # print(stringsql) # conn = psycopg2.connect(host="localhost", port = 5432, database="geospectre", user="******", password="******") # cur = conn.cursor() # cur.execute(stringsql) # waypointsList = (cur.fetchall()) # waypointsList = (cur.fetchall()) # for i in range (0, len(waypointsList)): # nombreWaypoints.append(waypointsList[i][1]) # print(nombreWaypoints) print(numWaypoints) conn.close() data['waypoints'] = numWaypoints pass except Exception as errorBd: data['errorBd'] = "T" raise errorBd return json.dumps(data)
def seleccionarMision(): data = request.get_json() data['errorBd'] = "" data['waypointsList'] = "" misionSeleccionada = data['misionSeleccionada'] numWaypoints = [] try: # Obtengo ID de mision conn = conexion() daoMision = DaoMision(conn) mision = daoMision.getMisionNombre(misionSeleccionada) idMision = mision.id # Obtengo lista IDs sensores 201, 202, 203 daoSensores = DaoSensores(conn) sensores = daoSensores.getSensoresMision(idMision) # Por cada ID de sensores obtengo ID de espectros 137, 138, 139 for i in range(len(sensores)): daoEspectros = DaoEspectros(conn) espectros = daoEspectros.getEspectrosSensores(sensores[i]) # Por cada ID de espectros retorno el RESULTADO del espectro # y verifico si está vacío for j in range(len(espectros)): espectro = daoEspectros.getEspectros(espectros[j]) idEspectro = espectro.id print(idEspectro) resultado = espectro.resultado # Si está vació borro el waypoint, y el espectro # CASCADE espway if len(resultado) == 0: daoEspway = DaoEspway(conn) espway = daoEspway.getEspwayEspectro(idEspectro) print("llego al if") if espway == None: print("if") daoEspectros.borrarEspectros(idEspectro) else: print("else") idWaypoint = espway.waypoints_id daoWaypoints = DaoWaypoints(conn) daoWaypoints.borrarWaypoint(idWaypoint) daoEspectros.borrarEspectros(idEspectro) daoWaypoints = DaoWaypoints(conn) waypointsList = daoWaypoints.getAllWaypoints(idMision) for i in range(0, len(waypointsList)): numWaypoints.append(str(waypointsList[i].num_waypoint)) conn.close() data['waypoints'] = numWaypoints pass except Exception as errorBd: data['errorBd'] = "T" raise errorBd finally: return json.dumps(data)
def waypointsDB(nombreMisionCrear): latlon = valores_waypoints.lat + "," + valores_waypoints.lon print(latlon) conn = conexion() daoMision = DaoMision(conn) daoWaypoints = DaoWaypoints(conn) mision = daoMision.getMisionNombre(nombreMisionCrear) idMision = mision.id wayp = Waypoints() wayp.num_waypoint = valores_waypoints.numeroWaypoint wayp.latlon = latlon wayp.mision_id = idMision wayp = daoWaypoints.guardarWaypoint(wayp) id_waypoints = wayp.id valores_waypoints.id_waypointsList.append(id_waypoints) conn.close() valores_waypoints.numeroWaypoint += 1 return id_waypoints
def guardarEspectro(): data = request.get_json() data['errorBd'] = "" nombreMisionCrear = data['nombreMisionCrear'] waypointSeleccionado = data['waypointSeleccionado'] ruta = str(data['ruta']) usuario = str(data['usuario']) filePath = FileManagement.to_relative(ruta) try: if os.path.isdir(filePath): conn = conexion() daoMision = DaoMision(conn) mision = daoMision.getMisionNombre(nombreMisionCrear) idMision = mision.id altura = mision.elevacion daoWaypoints = DaoWaypoints(conn) wayp = daoWaypoints.getWaypointByNumber(waypointSeleccionado, idMision) idWayp = wayp.id latlon = wayp.latlon.split(",") daoEspway = DaoEspway(conn) espway = daoEspway.getEspwayWaypoint(idWayp) idEspectro = espway.espectros_id daoEspectros = DaoEspectros(conn) espectro = daoEspectros.getEspectros(idEspectro) resultado = espectro.resultado conn.close() filePath += "/Usuario(" + usuario + ")" + "Mision(" + nombreMisionCrear + ")" + "Waypoint(" + waypointSeleccionado + ")" generate(resultado, filePath, float(latlon[0]), float(latlon[1]), altura) else: data['errorCarpeta'] = "T" except Exception as errorBd: data['errorBd'] = "T" raise errorBd finally: return json.dumps(data)
from Daos.AccesoDatos.DaoWaypoints import DaoWaypoints from Daos.AccesoDatos.Logica.Waypoints import Waypoints from Daos.AccesoDatos.DaoEspectros import DaoEspectros from Daos.AccesoDatos.Logica.Espectros import Espectros from Daos.AccesoDatos.DaoEspway import DaoEspway from Daos.AccesoDatos.Logica.Espway import Espway nombreMisionCrear = "201" waypointSeleccionado = 0 conn = conexion() daoMision = DaoMision(conn) mision = daoMision.getMisionNombre(nombreMisionCrear) idMision = mision.id print(idMision) daoWaypoints = DaoWaypoints(conn) wayp = daoWaypoints.getWaypointByNumber(waypointSeleccionado, idMision) idWayp = wayp.id print(idWayp) daoEspway = DaoEspway(conn) espway = daoEspway.getEspwayWaypoint(idWayp) idEspectro = espway.espectros_id print(idEspectro) daoEspectros = DaoEspectros(conn) espectro = daoEspectros.getEspectros(idEspectro) capturado = espectro.capturado resultado = espectro.resultado conn.close() print(capturado) print(resultado)