def get_distance(self, algorithm, fza_ventas): try: if algorithm == int(3): query = "SELECT * FROM trabajo.resultados WHERE \ id_fza_ventas = %s ORDER BY distancia limit 1;" % ( str(fza_ventas)) else: if algorithm == int(1): algorithm_name = 'SA' else: algorithm_name = 'PS' query = "SELECT * FROM trabajo.resultados WHERE algoritmo = '%s'\ AND id_fza_ventas = %s ;" % (str(algorithm_name), str(fza_ventas)) print(query) df = get_data(query) print(df) distancia = df['distancia'][0] ruta = df['ruta_optima'][0].split(',') print(ruta) return distancia, ruta except (Exception) as error: print("Error while getting path", error)
def get_coordinates_list(self, ruta): coordenadas = [] for nodo in ruta: query = "SELECT * FROM trabajo.nodos \ WHERE nodo = %s ;" % (str(nodo)) nodo_info = get_data(query) coordenadas.append([nodo_info['lat'][0], \ nodo_info['lon'][0]]) return coordenadas
def update_dropdown_fza(tipo): query = "select distinct id_fza_ventas " + \ "from trabajo.resultados_vw where estado = '" + \ str(tipo) + "' order by id_fza_ventas;" print(query) df = get_data(query) df.columns = ['label'] df['value'] = df['label'] resp = [df.to_dict("records")] return resp
def get_results(self, algorithm, fza_ventas): if algorithm == int(1): algorithm_name = 'SA' elif algorithm == int(2): algorithm_name = 'PS' try: query = "SELECT * FROM trabajo.resultados WHERE algoritmo = '%s'\ AND id_fza_ventas = %s ;" % (str(algorithm_name), str(fza_ventas)) df = get_data(query) return df except (Exception) as error: print("Error while getting path", error)
def update_dropdown_ciudad(tipo): if tipo == int(1): algorithm_name = 'SA' elif tipo == int(2): algorithm_name = 'PS' query = "select distinct estado from trabajo.resultados_vw \ order by estado ; " print(query) df = get_data(query) df.columns = ['label'] df['value'] = df['label'] #df.index +1 print(df) resp = [df.to_dict("records")] return resp
def get_message(text, idx): logging.info('Received NLP object for the request.') result = "Sorry! We are unable to answer to you right now. Please try again after some time." button_list = [] try: if text.lower() == "display entries": result = db_utils.get_data(data=[idx, "0"]) send_message(idx, result) pass elif text.lower() == "new entry": button_list.extend(building_list) fbot.send_quick_message(recipient_id=idx, message="Select Building", buttons=button_list) elif text in building_list: button_list.extend(flat_list) fbot.send_quick_message(recipient_id=idx, message="Select Flat", buttons=button_list) elif text.lower() in flat_list: number = random.randint(1111, 9999) bot.send_text_message( recipient_id=idx, message="Your OTP is: " + str(number) + ". Please type <OTP>+<space>+visitor name to create entry.") db_utils.insert_data(data=[idx, str(number), "0"]) elif check_otp(text) is not None: sid = db_utils.get_otp(data=[check_otp(text), "0"]) OTP, name = get_otp_name(text) print(type(name), "0", type(sid[0]), type(OTP)) db_utils.update_data(data=[name, "0", sid[0], OTP]) fbot.send_quick_message(recipient_id=idx, message="Entry has been created", buttons=["Display Entries"]) else: button_list.extend(["New Entry", "Display Entries"]) fbot.send_quick_message(recipient_id=idx, message="What would you like to do", buttons=button_list) except Exception as error: print(str(error)) return result