Skip to content
Snippets Groups Projects
Commit 560517d1 authored by Campos Cordobes, Sergio's avatar Campos Cordobes, Sergio
Browse files

Update src/app.py

Deleted src/app - copia.py
parent b41717ec
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on: 16/01/2023
@author: Andoni Aranguren Ubierna
"""
import sys
print(sys.path)
from src import constants
import mysql.connector
from flask import Flask, request, render_template
from src import recommender, database, planner
app = Flask(__name__)
cnx = None
@app.plan_detail("/")
def index():
return render_template("index.html")
# RECOMMENDERS: -------------------------------------------------------------------------------------------------------
@app.get("/recommender/popularity")
def recommender_popularity():
"""
We ask for actions based on popularity of the actions
:return: json
"""
return recommender.recommender_popularity(cnx, request)
@app.get("/recommender/geographic/action_id")
def recommender_geographic_id():
"""
We ask for actions based on popularity of the actions
:return: json
"""
return recommender.recommender_geographic_id(cnx, request)
@app.get("/recommender/geographic/lat_lon")
def recommender_geographic_lat_lon():
"""
We ask for actions based on popularity of the actions
:return: json
"""
return recommender.recommender_geographic_lat_lon(cnx, request)
@app.get("/recommender/preferences")
def recommender_preferences():
"""
We ask for kpis based on the affinity to the kpi provided.
:return: json
"""
return recommender.recommender_preferences(cnx, request)
@app.get("/recommender/kpis/kpi_id")
def recommender_kpis_kpi_id():
"""
Provided a action it returns a set of kpis by their affinity regarding the provided action
:return: json
"""
return recommender.recommender_kpis_kpi_id(cnx, request)
@app.get("/recommender/kpis/action_id")
def recommender_kpis_action_id():
"""
Provided a action it returns a set of kpis by their affinity regarding the provided action
:return: json
"""
return recommender.recommender_kpis_action_id(cnx, request)
@app.get("/recommender/bayesian")
def recommender_bayesian_action_id():
"""
We ask for actions based on popularity of the actions
:return: json
"""
return recommender.recommender_bayesian_action_id(cnx, request)
# DATABASE SAVE: -------------------------------------------------------------------------------------------------------
@app.post("/database/save/plan")
def database_save_plan():
"""
It stores the plan_details that have been selected.
The json provided should have the same format that /planner/plan_detail outputs filled with each plan_detail
:return: json with the plan_detail
"""
if request.json:
return database.database_save_plan(cnx, request)
else:
return constants.ERROR_JSON_NEEDED
# plan_detail PLANNER: -------------------------------------------------------------------------------------------------------
@app.get("/planner/plan_detail")
def planner_plan_detail():
"""
It calculates the best plan_detail traversing streets and reordering the intermediate nodes provided.
:return: json with the plan_detail
"""
return planner.planner_plan_detail(cnx, request)
# MAIN: ----------------------------------------------------------------------------------------------------------------
if __name__ == "__main__":
cnx = mysql.connector.connect(**constants.DDBB_CONFIG)
app.run(debug=True, host='0.0.0.0')
......@@ -3,6 +3,7 @@
"""
Created on: 16/01/2023
@author: Andoni Aranguren Ubierna
-- Adaptations: 02/2023 @author: Sergio Campos
"""
import sys
print(sys.path)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment