diff --git a/webapp/ipe_fetcher/__init__.py b/webapp/ipe_fetcher/__init__.py index b229412..4ef1b32 100644 --- a/webapp/ipe_fetcher/__init__.py +++ b/webapp/ipe_fetcher/__init__.py @@ -1,2 +1,4 @@ from .axione import * -from .liazo import * \ No newline at end of file +from .liazo import * +from .arcep import * +from .model import * \ No newline at end of file diff --git a/webapp/ipe_fetcher/arcep.py b/webapp/ipe_fetcher/arcep.py index 5866e57..55d9439 100644 --- a/webapp/ipe_fetcher/arcep.py +++ b/webapp/ipe_fetcher/arcep.py @@ -42,7 +42,9 @@ class Arcep: num_voie, type_voie, nom_voie, - batiment + batiment, + code_poste, + nom_com FROM {self.db_name} WHERE ROWID IN ( SELECT ROWID FROM SpatialIndex @@ -63,7 +65,8 @@ class Arcep: typeVoieImm=b[5] nomVoieImm=b[6] bat_info=b[7] - + codePostal=b[8] + commune=b[9] isEligible = etatImm == ARCEP_ETAT_DEPLOYE othersEligStatus = FAIEligibilityStatus( isEligible=isEligible, @@ -85,8 +88,12 @@ class Arcep: numVoieImm=numVoieImm, typeVoieImm=typeVoieImm, nomVoieImm=nomVoieImm, + codePostal=codePostal, + commune=commune, bat_info=bat_info, found_in = ["arcep"], + aquilenetEligStatus=FAIEligibilityStatus(isEligible=False, reasonNotEligible="", ftthStatus=""), + fdnEligStatus=FAIEligibilityStatus(isEligible=False, reasonNotEligible="", ftthStatus=""), othersEligStatus=othersEligStatus, ) buildings[idImm] = building diff --git a/webapp/ipe_fetcher/axione.py b/webapp/ipe_fetcher/axione.py index fed7e56..29866c7 100644 --- a/webapp/ipe_fetcher/axione.py +++ b/webapp/ipe_fetcher/axione.py @@ -48,7 +48,9 @@ class Axione: EtatImmeuble, NumeroVoieImmeuble, TypeVoieImmeuble, - NomVoieImmeuble + NomVoieImmeuble, + CodePostalImmeuble, + CommuneImmeuble FROM {self.db_name} WHERE ROWID IN ( SELECT ROWID FROM SpatialIndex @@ -68,7 +70,7 @@ class Axione: aquilenetEligStatus = FAIEligibilityStatus( isEligible=isEligible, ftthStatus=etatImm, - reasonNotEligible=None if isEligible else "Pas encore deploye", + reasonNotEligible="" if isEligible else "Pas encore deploye", ) if buildings.get(idImm): buildings[idImm]["aquilenetEligStatus"] = aquilenetEligStatus @@ -85,9 +87,13 @@ class Axione: numVoieImm=b[4], typeVoieImm=b[5], nomVoieImm=b[6], + codePostal=b[7], + commune=b[8], bat_info="", found_in = ["axione"], aquilenetEligStatus=aquilenetEligStatus, + fdnEligStatus=FAIEligibilityStatus(isEligible=False, reasonNotEligible="", ftthStatus=""), + othersEligStatus=FAIEligibilityStatus(isEligible=False, reasonNotEligible="", ftthStatus=""), ) buildings[idImm] = building return buildings diff --git a/webapp/ipe_fetcher/liazo.py b/webapp/ipe_fetcher/liazo.py index e8adbc2..2543b6c 100644 --- a/webapp/ipe_fetcher/liazo.py +++ b/webapp/ipe_fetcher/liazo.py @@ -7,16 +7,16 @@ class Liazo: self.https_conn = httplib.HTTPSConnection("vador.fdn.fr") def getAreaBuildings( - self, center_lat: float, center_lng: float, existing_buildings: dict + self, narrow_coordinates: AreaCoordinates(), existing_buildings: dict ) -> dict: + nc=narrow_coordinates c = self.https_conn - req = "/souscription/gps-batiments.cgi?etape=gps_batiments&lat1=%f&lat2=%f&lon1=%f&lon2=%f" % (center_lat-0.0011, center_lat+0.0011, center_lng-0.0022, center_lng+0.0022) + req = "/souscription/gps-batiments.cgi?etape=gps_batiments&lat1=%f&lat2=%f&lon1=%f&lon2=%f" % (nc['swy'],nc['ney'],nc['swx'],nc['nex']) req = req.replace(" ", "%20") - print("Req FDN with: ", req) c.request("GET", req) r = c.getresponse() if r.status < 200 or r.status >= 300: - print("Erreur de serveur chez FDN. Merci de nous faire remonter le numéro de téléphone qui provoque cette erreur") + print("Erreur de serveur chez FDN.") return d = r.read() c.close() @@ -27,7 +27,7 @@ class Liazo: for building in v: fdnEligStatus = FAIEligibilityStatus( isEligible=True, - ftthStatus="DEPLOYE", + ftthStatus="DEPLOYE", # Pas de status donc on dit que c'est ok mais on check avec l'arcep si axione KO cote front reasonNotEligible=None, ) idImm=building.get('ref') @@ -46,9 +46,13 @@ class Liazo: numVoieImm="", typeVoieImm="", nomVoieImm="", + codePostal="", + commune="", bat_info="", found_in = ["liazo"], fdnEligStatus=fdnEligStatus, + aquilenetEligStatus=FAIEligibilityStatus(isEligible=False, reasonNotEligible="", ftthStatus=""), + othersEligStatus=FAIEligibilityStatus(isEligible=False, reasonNotEligible="", ftthStatus=""), ) print("add building ", building) buildings[idImm] = building diff --git a/webapp/ipe_fetcher/model.py b/webapp/ipe_fetcher/model.py index fe8be10..8fc1e19 100644 --- a/webapp/ipe_fetcher/model.py +++ b/webapp/ipe_fetcher/model.py @@ -14,8 +14,10 @@ class Building(TypedDict): numVoieImm: str typeVoieImm: str nomVoieImm: str + codePostal: str + commune: str bat_info: str - found_in: list(str) + found_in: list[str] aquilenetEligStatus: FAIEligibilityStatus fdnEligStatus: FAIEligibilityStatus othersEligStatus: FAIEligibilityStatus diff --git a/webapp/ipe_fetcher/sqlite_connector/cursor.py b/webapp/ipe_fetcher/sqlite_connector/cursor.py index b41527f..dc49ba3 100644 --- a/webapp/ipe_fetcher/sqlite_connector/cursor.py +++ b/webapp/ipe_fetcher/sqlite_connector/cursor.py @@ -1,6 +1,7 @@ import sqlite3 def getCursorWithSpatialite(db_path: str = None) -> sqlite3.Cursor: + print(db_path) db = sqlite3.connect(db_path) cur = db.cursor() db.enable_load_extension(True) diff --git a/webapp/main.py b/webapp/main.py index 01b734b..39178b4 100644 --- a/webapp/main.py +++ b/webapp/main.py @@ -4,9 +4,12 @@ from typing import TypedDict import configparser import sqlite3 import os -from ipe_fetcher import Liazo,Axione,Arcep +from ipe_fetcher import Liazo,Axione,Arcep,AreaCoordinates class Config(TypedDict): axione_ipe_path: str + axione_ipe_db_name: str + arcep_ipe_path: str + arcep_ipe_db_name: str def parseConfig() -> Config: @@ -16,15 +19,17 @@ def parseConfig() -> Config: cfg.read_file(f) return { "axione_ipe_path": cfg.get("DB", "axione_ipe_path"), - "axione_ipe_path": cfg.get("DB", "axione_ipe_path"), + "axione_ipe_db_name": cfg.get("DB", "axione_ipe_db_name"), + "arcep_ipe_path": cfg.get("DB", "arcep_ipe_path"), + "arcep_ipe_db_name": cfg.get("DB", "arcep_ipe_db_name"), } app = Flask(__name__) cfg: Config = parseConfig() -axione = Axione(cfg.get("axione_ipe_path"), "ipe") -arcep = Arcep() +axione = Axione(cfg.get("axione_ipe_path"), cfg.get("axione_ipe_db_name")) +arcep = Arcep(cfg.get("arcep_ipe_path"), cfg.get("arcep_ipe_db_name")) liazo = Liazo() @@ -46,13 +51,27 @@ def getEligData(): except ValueError: valid_args = False if valid_args: + ## Need to narrow coordinates for Liazo API call + # wide_coordinates=AreaCoordinates( + # swx=processed_args['swx'], + # swy=processed_args['swy'], + # nex=processed_args['nex'], + # ney=processed_args['ney'], + # ) + narrow_coordinates=AreaCoordinates( + swx=processed_args['centerlng']-0.0022, + swy=processed_args['centerlat']-0.0011, + nex=processed_args['centerlng']+0.0022, + ney=processed_args['centerlat']+0.0011, + ) buildings = dict() try: - buildings = axione.getAreaBuildings(processed_args, buildings) + buildings = arcep.getAreaBuildings(narrow_coordinates, buildings) + buildings = axione.getAreaBuildings(narrow_coordinates, buildings) except ValueError as err: print("Could not get Axione data for this area:", err) - buildings = liazo.getAreaBuildings(processed_args["centerlat"], processed_args["centerlng"], buildings) + buildings = liazo.getAreaBuildings(narrow_coordinates, buildings) return {"buildings": buildings} else: diff --git a/webapp/static/style.css b/webapp/static/style.css index e9d8711..43ce804 100644 --- a/webapp/static/style.css +++ b/webapp/static/style.css @@ -21,3 +21,20 @@ body { z-index: 1; padding: .5em; } + +.deployeeAquilenet { + display: inline; + color: green; +} +.deployeeFDN { + display: inline; + color: orange; +} +.deployeeAutres { + display: inline; + color: red; +} +.nonDeployee { + display: inline; + color: brown; +} \ No newline at end of file diff --git a/webapp/templates/app.js b/webapp/templates/app.js index 20ee31c..67772f2 100644 --- a/webapp/templates/app.js +++ b/webapp/templates/app.js @@ -10,7 +10,6 @@ function initMap(btn) { if (x && y && z) { map.setView([y, x], z); fetchEligData(map); - displayBtn(btn); } else { map.setView([46.710, 3.669], 6); } @@ -68,15 +67,40 @@ function initAddrSearch(map) { function updateEligData(map, eligData) { markers.map(marker => map.removeLayer(marker)); let buildings = eligData.buildings; - console.log(buildings) markers = Object.values(buildings).map(building => { - console.log(building.numVoieImm) - console.log("lat", building.y) - console.log("lng", building.x) const latlng = new L.latLng(building.y, building.x); - const addrImm = `${building.numVoieImm} ${building.typeVoieImm} ${building.nomVoieImm}` + let addrImm = `${building.numVoieImm} ${building.typeVoieImm} ${building.nomVoieImm}` + if (building.bat_info != "") { + addrImm += ` (Bat ${building.bat_info})` + } + let messageElig = `` + eligTestApi=`testeligibilite/immeuble?idImm=${building.idImm}&codePostal=${building.codePostal}` + if (building.aquilenetEligStatus.isEligible) { + messageElig = `

Fibre deployee !` + messageElig += `
Tester l'eligibilite par Aquilenet` + if (building.fdnEligStatus.isEligible) { + messageElig += " et FDN" + } + messageElig += "

" + } else if (building.fdnEligStatus.isEligible && building.othersEligStatus.isEligible) { + messageElig = `

Fibre deployee mais pas chez Aquilenet !` + messageElig += `
Tester l'eligibilite par FDN

` + } else if (building.othersEligStatus.isEligible) { + messageElig = `

Fibre deployee mais non eligible Aquilenet, desole :(

` + } else { + messageElig = `

Fibre non deployee :(

` + if (building.othersEligStatus.reasonNotEligible != "") { + messageElig += `

Status general ARCEP: ${building.othersEligStatus.reasonNotEligible}` + } + } + if (building.aquilenetEligStatus.reasonNotEligible != "") { + messageElig += `
Pour Aquilenet, raison non eligible: ${building.aquilenetEligStatus.reasonNotEligible}` + } const marker = new L.marker(latlng) - .bindPopup(`${addrImm}
Etat: ${building.etatImm}
Code Immeuble: ${building.idImm}`); + .bindPopup(`${addrImm}
${building.codePostal} ${building.commune}` + + `

${messageElig}

Ref Immeuble: ${building.idImm}`, { + maxWidth : 560 + }); map.addLayer(marker); return marker }); @@ -94,11 +118,14 @@ async function fetchEligData(map) { const bounds = map.getBounds(); const sw = bounds.getSouthWest(); const ne = bounds.getNorthEast(); + const btn = document.getElementById("btn-load-elig-data"); + waitBtn(btn); const reqUri = encodeURI(`eligdata?swx=${sw.lng}&swy=${sw.lat}&nex=${ne.lng}&ney=${ne.lat}¢erlat=${mc.lat}¢erlng=${mc.lng}`); const source = await fetch(reqUri); const eligData = await source.json(); updateEligData(map, eligData); updateUrl(map); + displayBtn(btn); } } @@ -119,6 +146,10 @@ function hideBtn(btn) { btn.disabled = true; btn.title = "Veuillez zoomer plus la carte avant de lancer une recherche d'éligibilité."; } +function waitBtn(btn) { + btn.disabled = true; + btn.title = "Chargement des batiments..."; +} const btn = initBtn();