ajout de priorité dans l'affichage des immeubles selon leur statut de déploiement

This commit is contained in:
Johan Le Baut 2022-11-30 19:29:27 +01:00
parent f52e29463a
commit 270812f6d6
6 changed files with 49 additions and 14 deletions

View file

@ -1,6 +1,7 @@
from os.path import exists
from ipe_fetcher.model import AreaCoordinates, Building, FAIEligibilityStatus from ipe_fetcher.model import AreaCoordinates, Building, FAIEligibilityStatus
from ipe_fetcher.sqlite_connector.cursor import getCursorWithSpatialite from ipe_fetcher.sqlite_connector.cursor import getCursorWithSpatialite
from os.path import exists
ARCEP_ETAT_DEPLOYE = "deploye" ARCEP_ETAT_DEPLOYE = "deploye"
@ -12,6 +13,18 @@ class Arcep:
if not exists(self.db_arcep_ipe_path): if not exists(self.db_arcep_ipe_path):
raise ValueError(f"File {self.db_arcep_ipe_path} does not exist") raise ValueError(f"File {self.db_arcep_ipe_path} does not exist")
@staticmethod
def _get_etat_priority(etat_imm):
if etat_imm == ARCEP_ETAT_DEPLOYE:
return 0
elif etat_imm == "en cours de deploiement":
return 1
elif etat_imm != "abandonne":
return 3
else:
return 4
def getAreaBuildings( def getAreaBuildings(
self, areaCoordinates: AreaCoordinates, existing_buildings: dict self, areaCoordinates: AreaCoordinates, existing_buildings: dict
) -> dict: ) -> dict:
@ -73,9 +86,12 @@ class Arcep:
ftthStatus=etatImm, ftthStatus=etatImm,
reasonNotEligible=None if isEligible else "Pas encore deploye", reasonNotEligible=None if isEligible else "Pas encore deploye",
) )
etat_priority = self._get_etat_priority(etatImm)
if buildings.get(idImm): if buildings.get(idImm):
buildings[idImm]["othersEligStatus"] = othersEligStatus buildings[idImm]["othersEligStatus"] = othersEligStatus
buildings[idImm]["bat_info"] = bat_info buildings[idImm]["bat_info"] = bat_info
buildings[idImm]['etat_imm_priority'] = etat_priority
if buildings[idImm].get('found_in'): if buildings[idImm].get('found_in'):
buildings[idImm]['found_in'].append("arcep") buildings[idImm]['found_in'].append("arcep")
else: else:
@ -92,6 +108,7 @@ class Arcep:
commune=commune, commune=commune,
bat_info=bat_info, bat_info=bat_info,
found_in = ["arcep"], found_in = ["arcep"],
etat_imm_priority=etat_priority,
aquilenetEligStatus=FAIEligibilityStatus(isEligible=False, reasonNotEligible="", ftthStatus=""), aquilenetEligStatus=FAIEligibilityStatus(isEligible=False, reasonNotEligible="", ftthStatus=""),
fdnEligStatus=FAIEligibilityStatus(isEligible=False, reasonNotEligible="", ftthStatus=""), fdnEligStatus=FAIEligibilityStatus(isEligible=False, reasonNotEligible="", ftthStatus=""),
othersEligStatus=othersEligStatus, othersEligStatus=othersEligStatus,

View file

@ -1,9 +1,7 @@
import time from os.path import exists
from ipe_fetcher.model import AreaCoordinates, Building, FAIEligibilityStatus from ipe_fetcher.model import AreaCoordinates, Building, FAIEligibilityStatus
from ipe_fetcher.sqlite_connector.cursor import getCursorWithSpatialite, getBasicCursor from ipe_fetcher.sqlite_connector.cursor import getCursorWithSpatialite, getBasicCursor
from os.path import exists
AXIONE_ETAT_DEPLOYE = "DEPLOYE" AXIONE_ETAT_DEPLOYE = "DEPLOYE"
AXIONE_ETAT_DEPLOIEMENT = "EN COURS DE DEPLOIEMENT" AXIONE_ETAT_DEPLOIEMENT = "EN COURS DE DEPLOIEMENT"
@ -33,6 +31,19 @@ class Axione:
if cur.fetchone()[0] == 1: if cur.fetchone()[0] == 1:
self.db_name_refimm = AXIONE_REFIMM_TABLE_NAME self.db_name_refimm = AXIONE_REFIMM_TABLE_NAME
@staticmethod
def _get_etat_priority(etat_imm):
if etat_imm == AXIONE_ETAT_DEPLOYE:
return 0
elif etat_imm == AXIONE_ETAT_DEPLOIEMENT:
return 1
elif etat_imm == AXIONE_ETAT_RAD_DEPLOIEMENT:
return 2
elif etat_imm != AXIONE_ETAT_ABANDONNE:
return 3
else:
return 4
def getAreaBuildings( def getAreaBuildings(
self, areaCoordinates: AreaCoordinates, existing_buildings: dict self, areaCoordinates: AreaCoordinates, existing_buildings: dict
@ -89,8 +100,10 @@ class Axione:
ftthStatus=etatImm, ftthStatus=etatImm,
reasonNotEligible="" if isEligible else "Pas encore deploye", reasonNotEligible="" if isEligible else "Pas encore deploye",
) )
etat_priority = self._get_etat_priority(etatImm)
if buildings.get(idImm): if buildings.get(idImm):
buildings[idImm]["aquilenetEligStatus"] = aquilenetEligStatus buildings[idImm]["aquilenetEligStatus"] = aquilenetEligStatus
buildings[idImm]['etat_imm_priority'] = etat_priority
if buildings[idImm].get('found_in'): if buildings[idImm].get('found_in'):
buildings[idImm]['found_in'].append("axione") buildings[idImm]['found_in'].append("axione")
else: else:
@ -108,6 +121,7 @@ class Axione:
commune=b[8], commune=b[8],
bat_info="", bat_info="",
found_in = ["axione"], found_in = ["axione"],
etat_imm_priority=etat_priority,
aquilenetEligStatus=aquilenetEligStatus, aquilenetEligStatus=aquilenetEligStatus,
fdnEligStatus=FAIEligibilityStatus(isEligible=False, reasonNotEligible="", ftthStatus=""), fdnEligStatus=FAIEligibilityStatus(isEligible=False, reasonNotEligible="", ftthStatus=""),
othersEligStatus=FAIEligibilityStatus(isEligible=False, reasonNotEligible="", ftthStatus=""), othersEligStatus=FAIEligibilityStatus(isEligible=False, reasonNotEligible="", ftthStatus=""),

View file

@ -17,7 +17,7 @@ class Liazo:
r = c.getresponse() r = c.getresponse()
if r.status < 200 or r.status >= 300: if r.status < 200 or r.status >= 300:
print("Erreur de serveur chez FDN.") print("Erreur de serveur chez FDN.")
return return existing_buildings
d = r.read() d = r.read()
c.close() c.close()
v = json.loads(d.decode("utf-8")) v = json.loads(d.decode("utf-8"))
@ -38,7 +38,6 @@ class Liazo:
else: else:
buildings[idImm]['found_in'] = ["liazo"] buildings[idImm]['found_in'] = ["liazo"]
if not buildings.get(idImm): if not buildings.get(idImm):
building = Building( building = Building(
y=building.get('lat'), y=building.get('lat'),
x=building.get('lon'), x=building.get('lon'),
@ -50,6 +49,7 @@ class Liazo:
commune="", commune="",
bat_info="", bat_info="",
found_in = ["liazo"], found_in = ["liazo"],
etat_imm_priority=1,
fdnEligStatus=fdnEligStatus, fdnEligStatus=fdnEligStatus,
aquilenetEligStatus=FAIEligibilityStatus(isEligible=False, reasonNotEligible="", ftthStatus=""), aquilenetEligStatus=FAIEligibilityStatus(isEligible=False, reasonNotEligible="", ftthStatus=""),
othersEligStatus=FAIEligibilityStatus(isEligible=False, reasonNotEligible="", ftthStatus=""), othersEligStatus=FAIEligibilityStatus(isEligible=False, reasonNotEligible="", ftthStatus=""),

View file

@ -18,6 +18,7 @@ class Building(TypedDict):
commune: str commune: str
bat_info: str bat_info: str
found_in: list[str] found_in: list[str]
etat_imm_priority: int = 10
aquilenetEligStatus: FAIEligibilityStatus aquilenetEligStatus: FAIEligibilityStatus
fdnEligStatus: FAIEligibilityStatus fdnEligStatus: FAIEligibilityStatus
othersEligStatus: FAIEligibilityStatus othersEligStatus: FAIEligibilityStatus

View file

@ -1,12 +1,12 @@
import configparser
import os
from typing import TypedDict
from flask import Flask, request, render_template, redirect from flask import Flask, request, render_template, redirect
from typing import TypedDict
import configparser
import sqlite3
import os
from ipe_fetcher import Liazo,Axione,Arcep,AreaCoordinates
from eligibility_api.elig_api_exceptions import FlaskExceptions from eligibility_api.elig_api_exceptions import FlaskExceptions
from eligibility_api.elig_api_routes import EligibilityApiRoutes from eligibility_api.elig_api_routes import EligibilityApiRoutes
from ipe_fetcher import Liazo, Axione, Arcep, AreaCoordinates
class Config(TypedDict): class Config(TypedDict):
@ -81,8 +81,9 @@ def getEligData():
print("Could not get Axione data for this area:", err) print("Could not get Axione data for this area:", err)
buildings = liazo.getAreaBuildings(narrow_coordinates, buildings) buildings = liazo.getAreaBuildings(narrow_coordinates, buildings)
sorted_buildings = sorted(buildings.values(), key=lambda d: d.get('etat_imm_priority', 1), reverse=True)
return {"buildings": buildings} return {"buildings": list(sorted_buildings)}
else: else:
return "Invalid bounding box coordinates", 400 return "Invalid bounding box coordinates", 400

View file

@ -138,9 +138,11 @@ function initAddrSearch(map) {
} }
function updateEligData(map, eligData) { function updateEligData(map, eligData) {
if (markers) {
markers.map(marker => map.removeLayer(marker)); markers.map(marker => map.removeLayer(marker));
}
let buildings = eligData.buildings; let buildings = eligData.buildings;
markers = Object.values(buildings).map(building => { markers = buildings.forEach(building => {
const latlng = new L.latLng(building.y, building.x); const latlng = new L.latLng(building.y, building.x);
let addrImm = `${building.numVoieImm} ${building.typeVoieImm} ${building.nomVoieImm}` let addrImm = `${building.numVoieImm} ${building.typeVoieImm} ${building.nomVoieImm}`
if (building.bat_info != "") { if (building.bat_info != "") {