fix data commandable logic

This commit is contained in:
Johan Le Baut 2023-01-11 16:44:06 +01:00
parent f2b749e6d3
commit 39bec33217
2 changed files with 69 additions and 49 deletions

View file

@ -31,7 +31,9 @@ class Axione:
except Exception as err: except Exception as err:
print("Error while connecting to DB: ", err) print("Error while connecting to DB: ", err)
raise "Could not connect to axione DB" raise "Could not connect to axione DB"
cur.execute(f''' SELECT count(name) FROM sqlite_master WHERE type='table' AND name='{AXIONE_REFIMM_TABLE_NAME}' ''') cur.execute(
f""" SELECT count(name) FROM sqlite_master WHERE type='table' AND name='{AXIONE_REFIMM_TABLE_NAME}' """
)
self.db_name_refimm = db_name self.db_name_refimm = db_name
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
@ -51,7 +53,6 @@ class Axione:
else: else:
return 21 return 21
def getAreaBuildings( def getAreaBuildings(
self, areaCoordinates: AreaCoordinates, existing_buildings: dict self, areaCoordinates: AreaCoordinates, existing_buildings: dict
) -> dict: ) -> dict:
@ -109,31 +110,35 @@ class Axione:
# C'est bien déployé, cependant ce n'est pas encore commandable (donc bientôt et on a la date) # C'est bien déployé, cependant ce n'est pas encore commandable (donc bientôt et on a la date)
# On laisse isEligible = True, côté JS il faut regarder le statut pour laj l'affichage en conséquence # On laisse isEligible = True, côté JS il faut regarder le statut pour laj l'affichage en conséquence
if isEligible and date_debut: if date_debut:
try: try:
date_formatted = datetime.strptime(date_debut, '%Y%m%d').date() date_formatted = datetime.strptime(date_debut, "%Y%m%d").date()
if date_formatted >= datetime.now().date(): if date_formatted >= datetime.now().date():
etatImm = AXIONE_ETAT_DEPLOYE_NON_COMMANDABLE if isEligible:
date_commandable = date_formatted.strftime('%d/%m/%Y') etatImm = AXIONE_ETAT_DEPLOYE_NON_COMMANDABLE
date_commandable = date_formatted.strftime("%d/%m/%Y")
except ValueError as err: except ValueError as err:
print("Error while mainpulating DateDebutAcceptationCmdAcces from Axione DB: ", err) print(
"Error while mainpulating DateDebutAcceptationCmdAcces from Axione DB: ",
err,
)
aquilenetEligStatus = FAIEligibilityStatus( aquilenetEligStatus = FAIEligibilityStatus(
isEligible=isEligible, isEligible=isEligible,
ftthStatus=etatImm, ftthStatus=etatImm,
reasonNotEligible=reasonNotEligible, reasonNotEligible=reasonNotEligible,
dateCommandable=date_commandable dateCommandable=date_commandable,
) )
etat_priority = self._get_etat_priority(etatImm) 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 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:
buildings[idImm]['found_in'] = ["axione"] buildings[idImm]["found_in"] = ["axione"]
else: else:
building = Building( building = Building(
@ -146,11 +151,15 @@ class Axione:
codePostal=b[7], codePostal=b[7],
commune=b[8], commune=b[8],
bat_info="", bat_info="",
found_in = ["axione"], found_in=["axione"],
etat_imm_priority=etat_priority, etat_imm_priority=etat_priority,
aquilenetEligStatus=aquilenetEligStatus, aquilenetEligStatus=aquilenetEligStatus,
fdnEligStatus=FAIEligibilityStatus(isEligible=False, reasonNotEligible="", ftthStatus=""), fdnEligStatus=FAIEligibilityStatus(
othersEligStatus=FAIEligibilityStatus(isEligible=False, reasonNotEligible="", ftthStatus=""), isEligible=False, reasonNotEligible="", ftthStatus=""
),
othersEligStatus=FAIEligibilityStatus(
isEligible=False, reasonNotEligible="", ftthStatus=""
),
) )
buildings[idImm] = building buildings[idImm] = building
return buildings return buildings
@ -166,28 +175,36 @@ class Axione:
print("Error while connecting to DB: ", err) print("Error while connecting to DB: ", err)
raise "Could not get Axione data" raise "Could not get Axione data"
cur.execute( try:
f""" cur.execute(
SELECT EtatImmeuble, DateDebutAcceptationCmdAcces f"""
FROM {self.db_name_refimm} SELECT EtatImmeuble, DateDebutAcceptationCmdAcces
WHERE IdentifiantImmeuble == '{id_immeuble}' FROM {self.db_name_refimm}
""" WHERE IdentifiantImmeuble == '{id_immeuble}'
) """
res = cur.fetchone() )
if res: res = cur.fetchone()
imm_elig = res[0] if res:
isEligible = imm_elig == AXIONE_ETAT_DEPLOYE imm_elig = res[0]
reasonNotEligible = "" if isEligible else "Pas encore deploye" isEligible = imm_elig == AXIONE_ETAT_DEPLOYE
else: reasonNotEligible = "" if isEligible else "Pas encore deploye"
isEligible = False dateCommandable = res[1]
else:
imm_elig = "NOT_AXIONE"
isEligible = False
reasonNotEligible = "Axione ne gere pas ce batiment"
dateCommandable = ""
except Exception as err:
imm_elig = "NOT_AXIONE" imm_elig = "NOT_AXIONE"
isEligible = False
reasonNotEligible = "Axione ne gere pas ce batiment" reasonNotEligible = "Axione ne gere pas ce batiment"
dateCommandable = ""
eligStatus = FAIEligibilityStatus( eligStatus = FAIEligibilityStatus(
isEligible=isEligible, isEligible=isEligible,
ftthStatus=imm_elig, ftthStatus=imm_elig,
reasonNotEligible=reasonNotEligible, reasonNotEligible=reasonNotEligible,
dateCommandable=res[1] dateCommandable=dateCommandable,
) )
return eligStatus return eligStatus

View file

@ -151,7 +151,7 @@ async function initLimitsBox(map, btn) {
} }
function createRectangleBox(map) { function createRectangleBox(map) {
return L.rectangle(getRectangleCoord(map), {color: "#ff7800", fillOpacity: 0.07, weight: 1}); return L.rectangle(getRectangleCoord(map), { color: "#ff7800", fillOpacity: 0.07, weight: 1 });
} }
// Ask server the narrowed area bounds that it will search in // Ask server the narrowed area bounds that it will search in
@ -207,7 +207,7 @@ function initAddrSearch(map) {
function updateEligData(map, eligData) { function updateEligData(map, eligData) {
let buildings = eligData.buildings; let buildings = eligData.buildings;
buildings.forEach(building => { buildings.forEach(building => {
if (! markers.has(building.idImm)) { if (!markers.has(building.idImm)) {
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 != "") {
@ -219,17 +219,17 @@ function updateEligData(map, eligData) {
// éligible chez Aquilenet, lien pour le test // éligible chez Aquilenet, lien pour le test
if (building.aquilenetEligStatus.isEligible) { if (building.aquilenetEligStatus.isEligible) {
// Si fibre Axione déployé mais pas encore commandable // Si fibre Axione déployé mais pas encore commandable
if (building.aquilenetEligStatus.ftthStatus == "DEPLOYE MAIS NON COMMANDABLE") { if (building.aquilenetEligStatus.ftthStatus == "DEPLOYE MAIS NON COMMANDABLE") {
colorMarker = 'orange' colorMarker = 'orange'
messageElig = `<p class=deployeeAquilenet>Fibre deployée mais ne sera commandable qu\'à partir du ${building.aquilenetEligStatus.dateCommandable}</p>` messageElig = `<p class=deployeeAquilenet>Fibre deployée mais ne sera commandable qu\'à partir du ${building.aquilenetEligStatus.dateCommandable}</p>`
} else { } else {
messageElig = `<p class=deployeeAquilenet>Fibre deployée et disponible par Aquilenet !</p>` messageElig = `<p class=deployeeAquilenet>Fibre deployée et disponible par Aquilenet !</p>`
const zip = encodeURIComponent(building.codePostal); const zip = encodeURIComponent(building.codePostal);
const idImm = encodeURIComponent(building.idImm); const idImm = encodeURIComponent(building.idImm);
messageElig += `<br/><a href=${urlTestFTTH}?ftth=1&axione=1&adsltel=NOUVEAU&cp=${zip}&refimmeuble=${idImm}` + messageElig += `<br/><a href=${urlTestFTTH}?ftth=1&axione=1&adsltel=NOUVEAU&cp=${zip}&refimmeuble=${idImm}` +
`>Tester l'éligibilité</a>` `>Tester l'éligibilité</a>`
colorMarker = 'green' colorMarker = 'green'
} }
// pas de données Axione mais Kosc nous renvoie qque chose à cette adresse (fdnEligStatus) // pas de données Axione mais Kosc nous renvoie qque chose à cette adresse (fdnEligStatus)
@ -263,6 +263,9 @@ function updateEligData(map, eligData) {
// Si pas d'éligibilité fibre, on affiche la raison si elle existe // Si pas d'éligibilité fibre, on affiche la raison si elle existe
if (building.aquilenetEligStatus.reasonNotEligible != "") { if (building.aquilenetEligStatus.reasonNotEligible != "") {
messageElig += `<br/> Pour Aquilenet, raison non eligible: ${building.aquilenetEligStatus.reasonNotEligible}` messageElig += `<br/> Pour Aquilenet, raison non eligible: ${building.aquilenetEligStatus.reasonNotEligible}`
if (building.aquilenetEligStatus.dateCommandable != "") {
messageElig += ` (date commandable: ${building.aquilenetEligStatus.dateCommandable})`
}
} }
var markerIcon = new L.Icon({ var markerIcon = new L.Icon({
iconUrl: `static/icons/marker-icon-${colorMarker}.png`, iconUrl: `static/icons/marker-icon-${colorMarker}.png`,
@ -273,13 +276,13 @@ function updateEligData(map, eligData) {
shadowSize: [41, 41] shadowSize: [41, 41]
}); });
const marker = new L.marker(latlng, { const marker = new L.marker(latlng, {
icon: markerIcon, icon: markerIcon,
zIndexOffset: - building.etat_imm_priority zIndexOffset: - building.etat_imm_priority
}) })
.bindPopup(`${addrImm}<br/>${building.codePostal} ${building.commune}` + .bindPopup(`${addrImm}<br/>${building.codePostal} ${building.commune}` +
`<br/><br/>${messageElig}<br/><br/>Ref Immeuble: ${building.idImm}`, { `<br/><br/>${messageElig}<br/><br/>Ref Immeuble: ${building.idImm}`, {
maxWidth: 560 maxWidth: 560
}); });
map.addLayer(marker); map.addLayer(marker);
markers.set(building.idImm, marker) markers.set(building.idImm, marker)
} }
@ -325,7 +328,7 @@ function setBtnListener(btn, map) {
// Reset markers when button is clicked // Reset markers when button is clicked
if (markers) { if (markers) {
for (let marker of markers.values()){ for (let marker of markers.values()) {
map.removeLayer(marker); map.removeLayer(marker);
} }
markers.clear(); markers.clear();