2022-11-16 16:10:30 +01:00
|
|
|
from flask import Flask, request
|
|
|
|
|
2023-02-28 22:31:35 +01:00
|
|
|
from coordinates import check_coordinates_args, adapt_coordinates_to_max_area
|
2022-11-16 16:10:30 +01:00
|
|
|
from eligibility_api.elig_api_exceptions import ApiParamException
|
2023-03-03 14:16:34 +01:00
|
|
|
from ipe_fetcher import NetwooEligibility, FAIEligibilityStatus
|
2023-01-11 15:35:12 +01:00
|
|
|
from ipe_fetcher.axione import AXIONE_MAX_AREA, Axione
|
2023-03-03 14:16:34 +01:00
|
|
|
from netwo.netwo import Netwo
|
2022-11-16 16:10:30 +01:00
|
|
|
|
2023-02-28 22:31:35 +01:00
|
|
|
|
2022-11-16 16:10:30 +01:00
|
|
|
class EligibilityApiRoutes:
|
2023-03-03 14:16:34 +01:00
|
|
|
def __init__(self, flask_app: Flask, axione_ipe: Axione, netwo: Netwo):
|
2022-11-16 16:10:30 +01:00
|
|
|
self.flask_app = flask_app
|
|
|
|
self.axione_ipe = axione_ipe
|
2023-03-03 14:16:34 +01:00
|
|
|
self.netwo = netwo
|
2022-11-16 16:10:30 +01:00
|
|
|
|
|
|
|
def add_routes(self):
|
|
|
|
@self.flask_app.route("/eligibilite/axione", methods=["GET"])
|
|
|
|
def get_axione_eligibility_per_immeuble():
|
|
|
|
refimmeuble = request.args.get("refimmeuble")
|
|
|
|
if not refimmeuble:
|
2023-02-28 22:31:35 +01:00
|
|
|
raise ApiParamException(
|
|
|
|
"You need to specify path parameter 'refimmeuble'"
|
|
|
|
)
|
2022-11-16 16:10:30 +01:00
|
|
|
return self.axione_ipe.get_eligibilite_per_id_immeuble(refimmeuble)
|
|
|
|
|
2023-01-11 15:35:12 +01:00
|
|
|
@self.flask_app.route("/eligibilite/axione/coord", methods=["GET"])
|
|
|
|
def get_axione_eligibility_per_coordinates():
|
|
|
|
args = request.args
|
|
|
|
try:
|
|
|
|
processed_args = check_coordinates_args(args)
|
2023-02-28 22:31:35 +01:00
|
|
|
coordinates = adapt_coordinates_to_max_area(
|
|
|
|
processed_args, AXIONE_MAX_AREA
|
|
|
|
)
|
|
|
|
return self.axione_ipe.get_area_buildings(coordinates, {})
|
2023-01-11 15:35:12 +01:00
|
|
|
except ValueError:
|
2023-02-28 22:31:35 +01:00
|
|
|
raise ApiParamException(
|
|
|
|
"You need to specify path parameters 'swx' 'swy' 'nex' 'ney'"
|
|
|
|
)
|
2023-03-03 14:16:34 +01:00
|
|
|
|
|
|
|
@self.flask_app.route("/eligibilite/netwo", methods=["GET"])
|
|
|
|
def get_netwo_eligibility():
|
|
|
|
args = request.args
|
|
|
|
ref_imb = args.get("ref_imb")
|
|
|
|
lat = args.get("lat")
|
|
|
|
lng = args.get("lng")
|
|
|
|
timeout_sec = None
|
|
|
|
search_ftto = args.get("ftto", "False").lower() == "true"
|
|
|
|
if args.get("timeout_sec"):
|
|
|
|
try:
|
|
|
|
timeout_sec = int(args.get("timeout_sec"))
|
|
|
|
except ValueError:
|
|
|
|
raise ApiParamException("timeout_sec param must be an integer")
|
|
|
|
elig_status = (
|
|
|
|
FAIEligibilityStatus(
|
|
|
|
isEligible=True, ftthStatus="Deployed", reasonNotEligible=""
|
|
|
|
),
|
|
|
|
)
|
|
|
|
if ref_imb:
|
|
|
|
elig_status, lat, lng = self.netwo.get_netwo_imb_coordinates(
|
|
|
|
args["ref_imb"]
|
|
|
|
)
|
|
|
|
if not elig_status.get("isEligible"):
|
|
|
|
return NetwooEligibility(
|
|
|
|
eligStatus=elig_status,
|
|
|
|
)
|
|
|
|
return self.netwo.start_netwo_eligibility(
|
|
|
|
lat, lng, elig_status, search_ftto, timeout_sec
|
|
|
|
)
|