display per result

This commit is contained in:
Johan Le Baut 2022-04-12 23:17:40 +02:00
parent 58bb3e0d1b
commit e6d6ba013b
9 changed files with 113 additions and 24 deletions

View file

@ -1,2 +1,4 @@
from .axione import *
from .liazo import *
from .liazo import *
from .arcep import *
from .model import *

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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:

View file

@ -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;
}

View file

@ -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 = `<p class=deployeeAquilenet>Fibre deployee !`
messageElig += `<br/><a href=${eligTestApi}>Tester l'eligibilite par Aquilenet`
if (building.fdnEligStatus.isEligible) {
messageElig += " et FDN"
}
messageElig += "</a></p>"
} else if (building.fdnEligStatus.isEligible && building.othersEligStatus.isEligible) {
messageElig = `<p class=deployeeFDN>Fibre deployee mais pas chez Aquilenet !`
messageElig += `<br/><a href=${eligTestApi}>Tester l'eligibilite par FDN</a></p>`
} else if (building.othersEligStatus.isEligible) {
messageElig = `<p class=deployeeAutres>Fibre deployee mais non eligible Aquilenet, desole :(</p>`
} else {
messageElig = `<p class=nonDeployee>Fibre non deployee :(</p>`
if (building.othersEligStatus.reasonNotEligible != "") {
messageElig += `<br/><br/>Status general ARCEP: ${building.othersEligStatus.reasonNotEligible}`
}
}
if (building.aquilenetEligStatus.reasonNotEligible != "") {
messageElig += `<br/> Pour Aquilenet, raison non eligible: ${building.aquilenetEligStatus.reasonNotEligible}`
}
const marker = new L.marker(latlng)
.bindPopup(`${addrImm}<br/>Etat: ${building.etatImm}<br/>Code Immeuble: ${building.idImm}`);
.bindPopup(`${addrImm}<br/>${building.codePostal} ${building.commune}`
+ `<br/><br/>${messageElig}<br/><br/>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}&centerlat=${mc.lat}&centerlng=${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();