#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on: 16/01/2023 @author: Andoni Aranguren Ubierna -- Adaptations: 02/2023 @author: Sergio Campos """ DDBB_CONFIG = {'user': 'root', 'password': 'admin', 'host': 'localhost', 'database': 'urbanite_recommender', 'autocommit': True} OTP_CONFIG = {'host': 'https://afrp.santander.urbanage.digital.tecnalia.dev/'} ERROR_EXCEPTION = [{"error": "Upss... Something went wrong"}, 415] ERROR_JSON_NEEDED = [{"error": "Request must be JSON"}, 415] ERROR_plan_DATE_MISSING = [{"error": " ".join(["No date was found in the plan.", "That's weird, did you do it by hand? Use /planner/plan_detail"])}, 415] ERROR_INVALID_action_ID = [{"error": "At least one of the provided action id are not found in the database"}, 415] ALL_RIGHT = [{"All right!": "The request has been completed correctly"}, 200] DEFAULT_PREFERENCES = ["sports", "culture", "sightseeing", "gastronomy"] DEFAULT_TIME_SLOTS = ["08:30", "12:30", "15:30", "19:30", "23:30"] DEFAULT_INSERT_plan_detail_ORDER = ["plan_id", "time_slot", "fecha_hora", "arrive_by", "wheelchair", "max_walk_distance", "from_lat", "from_lon", "to_lat", "to_lon", "sports", "culture", "sightseeing", "gastronomy", "action_id_array"] REGEXP_COORDS = r"^\-?[0-9]+\.[0-9]+,\-?[0-9]+\.[0-9]+$" REGEXP_DATE = r"^2[0-9][0-9][0-9]-[0-1][0-9]-[0-3][0-9] [0-2][0-9]:[0-5][0-9]:[0-5][0-9]$" REGEXP_INTERMEDIATE_NODES = r"^[0-9]+(?:,[0-9]+)*$" REGEXP_TIME = r"^[0-2][0-9]:[0-5][0-9]$" DEFAULT_SHIFTING = 0.0001 DEFAULT_SHIFTING_AMOUNT = 1.01 DEFAULT_MAX_TRIES_TO_RELOCATE_ENDING_actionNT = 100 DEFAULT_OTP_TOO_CLOSE = 'ES-los Origin is within a trivial distance of the destination.' plan_JSON_TEMPLATE = dict(date=None, plan_details={0: {}, # Morning plan_detail 1: {}, # Lunch brake or pintxos plan_detail 2: {}, # Afternoon plan_detail 3: {}}) # Dinner brake or pintxos plan_detail # Load data PATH_plan_detailS = "data/Rutas" PATH_actionS = "data/actions" # Load data - SQL queries sql_insert_action = """ INSERT IGNORE INTO action(action_id, lat, lon, action_name) VALUES (%s, %s, %s, %s) """ sql_insert_kpi = """INSERT IGNORE INTO kpi(kpi_name) VALUES(%s)""" sql_get_kpi_ids = """SELECT kpi_name, kpi_id FROM kpi WHERE kpi_name IN ('{names}')""" sql_insert_action_kpi = """ INSERT IGNORE INTO kpi_action(action_id, kpi_id) VALUES ( (SELECT action_id FROM action WHERE lat = %s AND lon = %s AND action_name = %s), {kpi}) """ sql_insert_plan = """ INSERT IGNORE INTO plan(plan_date) VALUES(%s); """ sql_insert_plan_detail = """ INSERT IGNORE INTO plan_detail(plan_id, time_slot, from_lat, from_lon, to_lat, to_lon, fecha_hora, sports, culture, sightseeing, gastronomy) VALUES((SELECT plan_id FROM plan WHERE plan_date = '{date}'), %s, 43.2668, -2.9353, 43.2600, -2.9393, %s, %s, %s, %s, %s) """ sql_get_chosen_action_ids = """SELECT action_name, action_id FROM action WHERE action_name LIKE %s""" sql_insert_chosen_action = """ INSERT IGNORE INTO CHOSEN_action(plan_id, time_slot, action_id) VALUES((SELECT plan_id FROM plan WHERE plan_date = '{date}'), %s, %s) """