diff --git a/src/load_data - copia.py b/src/load_data - copia.py deleted file mode 100644 index 8ec5476b9ef49e031146cd7c18452f045c2b0f33..0000000000000000000000000000000000000000 --- a/src/load_data - copia.py +++ /dev/null @@ -1,123 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -""" -Created on: 16/01/2023 -@author: Andoni Aranguren Ubierna -""" -import os - -import sys -import numpy as np -import pandas as pd -import requests -from mysql import connector -from utm.conversion import to_latlon as utm_to_latlon - -import sys -print(sys.path) -from src import constants - - -def to_latlon(df, x_str, y_str): - x, y = [], [] - - for index, row in df.iterrows(): - coords_portal = utm_to_latlon(row[x_str], row[y_str], zone_number=30, zone_letter="T") - x += [coords_portal[0]] - y += [coords_portal[1]] - df["lon"] = np.round(x, 8) - df["lat"] = np.round(y, 8) - - return df - - -def generate_POIs(cnx): - cursor = cnx.cursor(buffered=True) - path = constants.PATH_POIS - - file = path + "/POIS_LugaresTuristicos_Bilbao.csv" - if os.path.isfile(file): - df = pd.read_csv(file, encoding="utf-8", sep=";", decimal=".", encoding_errors='replace') - df = to_latlon(df, "COORDENADA_UTM_X", "COORDENADA_UTM_Y") - df.drop_duplicates(subset=["lon", "lat", "NOMBRE_LUGAR_CAS"], inplace=True) - valores_preferencias = set([i for x in df["TAGS"].unique().tolist() for i in x.split(",")]) - - df_sql = df[["ID", "lon", "lat", "NOMBRE_LUGAR_CAS"]] - cursor.executemany(constants.sql_insert_poi, df_sql.values.tolist()) - cnx.commit() - for tag in valores_preferencias: - cursor.execute(constants.sql_insert_tag, [tag]) - cnx.commit() - - names_dict = {} - for tag in valores_preferencias: - names_dict[tag] = "" - - cursor.execute(constants.sql_get_tag_ids.format(names="','".join(names_dict.keys())), ) - cnx.commit() - ret = cursor.fetchall() - - for row in ret: - names_dict[row[0]] = row[1] - - for index, row in df.iterrows(): - for tag in row["TAGS"].split(","): - cursor.execute(constants.sql_insert_poi_tag.format(tag=names_dict[tag]), - row[["lon", "lat", "NOMBRE_LUGAR_CAS"]].values.tolist()) - cnx.commit() - - -def generate_routes(cnx): - cursor = cnx.cursor(buffered=True) - a, b = 'áéÃóúüÃÉÃÓÚÜ', '%%%%%%%%%%%%' - trans = str.maketrans(a, b) - path = constants.PATH_ROUTES - for filename in os.listdir(path): - f = os.path.join(path, filename) - if os.path.isfile(f): - df = pd.read_csv(f, sep="\t") - json_itinerary = None - for index, row in df.iterrows(): - names = row["poi_names"].replace(";", "','") - dict_id = {} - for name in row["poi_names"].split(";"): - cursor.execute(constants.sql_get_chosen_poi_ids,[name.translate(trans)]) - cnx.commit() - ret = cursor.fetchall() - try: - dict_id[ret[0][0]] = str(ret[0][1]) - except: - pass - - poi_id = ",".join(list(dict_id.values())) - - url_route = 'http://localhost:5000/planner/route?' - parameters = "&".join(["fromPlace=" + row["from_place"], - "toPlace=" + row["to_place"], - "timeSlot=" + str(int(row["time_slot"])), - "sports=" + str(row["sports"]), - "culture=" + str(row["culture"]), - "sightseeing=" + str(row["sightseeing"]), - "gastronomy=" + str(row["gastronomy"])]) - if poi_id != '': - parameters += "&intermediateNodesIds=" + poi_id - - if json_itinerary is None: - json_itinerary = requests.get(url_route+parameters).json() - else: - time_slot = str(int(row["time_slot"])) - json_itinerary["routes"][time_slot] = requests.get(url_route+parameters).json()["routes"][time_slot] - url_save_it = 'http://localhost:5000/database/save/itinerary' - requests.post(url_save_it, json=json_itinerary) - - -def main(ddbb_config: dict): - cnx = connector.connect(**ddbb_config) - generate_POIs(cnx) - generate_routes(cnx) - cnx.close() - - -if __name__ == '__main__': - ddbb_config = constants.DDBB_CONFIG - main(ddbb_config) diff --git a/src/load_data.py b/src/load_data.py index e9ed3d54fb98aad745ecc0743015e4694a93abb8..acaec831ef886eb5829c1dff06333ccacd24bb2b 100644 --- a/src/load_data.py +++ b/src/load_data.py @@ -3,6 +3,8 @@ """ Created on: 16/01/2023 @author: Andoni Aranguren Ubierna +-- Adaptations: 02/2023 @author: Sergio Campos + """ import os