johan/add-api #7

Merged
johan.le.baut merged 17 commits from johan/add-api into master 2023-02-28 22:32:35 +01:00
2 changed files with 69 additions and 49 deletions
Showing only changes of commit 39bec33217 - Show all commits

View file

@ -31,7 +31,9 @@ class Axione:
except Exception as err:
print("Error while connecting to DB: ", err)
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
if cur.fetchone()[0] == 1:
self.db_name_refimm = AXIONE_REFIMM_TABLE_NAME
@ -51,7 +53,6 @@ class Axione:
else:
return 21
def getAreaBuildings(
self, areaCoordinates: AreaCoordinates, existing_buildings: 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)
# 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:
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():
etatImm = AXIONE_ETAT_DEPLOYE_NON_COMMANDABLE
date_commandable = date_formatted.strftime('%d/%m/%Y')
if isEligible:
etatImm = AXIONE_ETAT_DEPLOYE_NON_COMMANDABLE
date_commandable = date_formatted.strftime("%d/%m/%Y")
except ValueError as err:
print("Error while mainpulating DateDebutAcceptationCmdAcces from Axione DB: ", err)
print(
"Error while mainpulating DateDebutAcceptationCmdAcces from Axione DB: ",
err,
)
aquilenetEligStatus = FAIEligibilityStatus(
isEligible=isEligible,
ftthStatus=etatImm,
reasonNotEligible=reasonNotEligible,
dateCommandable=date_commandable
dateCommandable=date_commandable,
)
etat_priority = self._get_etat_priority(etatImm)
if buildings.get(idImm):
buildings[idImm]["aquilenetEligStatus"] = aquilenetEligStatus
buildings[idImm]['etat_imm_priority'] = etat_priority
if buildings[idImm].get('found_in'):
buildings[idImm]['found_in'].append("axione")
buildings[idImm]["etat_imm_priority"] = etat_priority
if buildings[idImm].get("found_in"):
buildings[idImm]["found_in"].append("axione")
else:
buildings[idImm]['found_in'] = ["axione"]
buildings[idImm]["found_in"] = ["axione"]
else:
building = Building(
@ -146,11 +151,15 @@ class Axione:
codePostal=b[7],
commune=b[8],
bat_info="",
found_in = ["axione"],
found_in=["axione"],
etat_imm_priority=etat_priority,
aquilenetEligStatus=aquilenetEligStatus,
fdnEligStatus=FAIEligibilityStatus(isEligible=False, reasonNotEligible="", ftthStatus=""),
othersEligStatus=FAIEligibilityStatus(isEligible=False, reasonNotEligible="", ftthStatus=""),
fdnEligStatus=FAIEligibilityStatus(
isEligible=False, reasonNotEligible="", ftthStatus=""
),
othersEligStatus=FAIEligibilityStatus(
isEligible=False, reasonNotEligible="", ftthStatus=""
),
)
buildings[idImm] = building
return buildings
@ -166,28 +175,36 @@ class Axione:
print("Error while connecting to DB: ", err)
raise "Could not get Axione data"
cur.execute(
f"""
SELECT EtatImmeuble, DateDebutAcceptationCmdAcces
FROM {self.db_name_refimm}
WHERE IdentifiantImmeuble == '{id_immeuble}'
"""
)
res = cur.fetchone()
if res:
imm_elig = res[0]
isEligible = imm_elig == AXIONE_ETAT_DEPLOYE
reasonNotEligible = "" if isEligible else "Pas encore deploye"
else:
isEligible = False
try:
cur.execute(
f"""
SELECT EtatImmeuble, DateDebutAcceptationCmdAcces
FROM {self.db_name_refimm}
WHERE IdentifiantImmeuble == '{id_immeuble}'
"""
)
res = cur.fetchone()
if res:
imm_elig = res[0]
isEligible = imm_elig == AXIONE_ETAT_DEPLOYE
reasonNotEligible = "" if isEligible else "Pas encore deploye"
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"
isEligible = False
reasonNotEligible = "Axione ne gere pas ce batiment"
dateCommandable = ""
eligStatus = FAIEligibilityStatus(
isEligible=isEligible,
ftthStatus=imm_elig,
reasonNotEligible=reasonNotEligible,
dateCommandable=res[1]
dateCommandable=dateCommandable,
)
return eligStatus

View file

@ -151,7 +151,7 @@ async function initLimitsBox(map, btn) {
}
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
@ -207,7 +207,7 @@ function initAddrSearch(map) {
function updateEligData(map, eligData) {
let buildings = eligData.buildings;
buildings.forEach(building => {
if (! markers.has(building.idImm)) {
if (!markers.has(building.idImm)) {
const latlng = new L.latLng(building.y, building.x);
let addrImm = `${building.numVoieImm} ${building.typeVoieImm} ${building.nomVoieImm}`
if (building.bat_info != "") {
@ -219,17 +219,17 @@ function updateEligData(map, eligData) {
// éligible chez Aquilenet, lien pour le test
if (building.aquilenetEligStatus.isEligible) {
// Si fibre Axione déployé mais pas encore commandable
if (building.aquilenetEligStatus.ftthStatus == "DEPLOYE MAIS NON COMMANDABLE") {
colorMarker = 'orange'
messageElig = `<p class=deployeeAquilenet>Fibre deployée mais ne sera commandable qu\'à partir du ${building.aquilenetEligStatus.dateCommandable}</p>`
} else {
messageElig = `<p class=deployeeAquilenet>Fibre deployée et disponible par Aquilenet !</p>`
const zip = encodeURIComponent(building.codePostal);
const idImm = encodeURIComponent(building.idImm);
messageElig += `<br/><a href=${urlTestFTTH}?ftth=1&axione=1&adsltel=NOUVEAU&cp=${zip}&refimmeuble=${idImm}` +
`>Tester l'éligibilité</a>`
colorMarker = 'green'
// Si fibre Axione déployé mais pas encore commandable
if (building.aquilenetEligStatus.ftthStatus == "DEPLOYE MAIS NON COMMANDABLE") {
colorMarker = 'orange'
messageElig = `<p class=deployeeAquilenet>Fibre deployée mais ne sera commandable qu\'à partir du ${building.aquilenetEligStatus.dateCommandable}</p>`
} else {
messageElig = `<p class=deployeeAquilenet>Fibre deployée et disponible par Aquilenet !</p>`
const zip = encodeURIComponent(building.codePostal);
const idImm = encodeURIComponent(building.idImm);
messageElig += `<br/><a href=${urlTestFTTH}?ftth=1&axione=1&adsltel=NOUVEAU&cp=${zip}&refimmeuble=${idImm}` +
`>Tester l'éligibilité</a>`
colorMarker = 'green'
}
// 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
if (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({
iconUrl: `static/icons/marker-icon-${colorMarker}.png`,
@ -273,13 +276,13 @@ function updateEligData(map, eligData) {
shadowSize: [41, 41]
});
const marker = new L.marker(latlng, {
icon: markerIcon,
zIndexOffset: - building.etat_imm_priority
})
icon: markerIcon,
zIndexOffset: - building.etat_imm_priority
})
.bindPopup(`${addrImm}<br/>${building.codePostal} ${building.commune}` +
`<br/><br/>${messageElig}<br/><br/>Ref Immeuble: ${building.idImm}`, {
maxWidth: 560
});
maxWidth: 560
});
map.addLayer(marker);
markers.set(building.idImm, marker)
}
@ -325,7 +328,7 @@ function setBtnListener(btn, map) {
// Reset markers when button is clicked
if (markers) {
for (let marker of markers.values()){
for (let marker of markers.values()) {
map.removeLayer(marker);
}
markers.clear();