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:
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():
if isEligible:
etatImm = AXIONE_ETAT_DEPLOYE_NON_COMMANDABLE
date_commandable = date_formatted.strftime('%d/%m/%Y')
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,6 +175,7 @@ class Axione:
print("Error while connecting to DB: ", err)
raise "Could not get Axione data"
try:
cur.execute(
f"""
SELECT EtatImmeuble, DateDebutAcceptationCmdAcces
@ -178,16 +188,23 @@ class Axione:
imm_elig = res[0]
isEligible = imm_elig == AXIONE_ETAT_DEPLOYE
reasonNotEligible = "" if isEligible else "Pas encore deploye"
dateCommandable = res[1]
else:
isEligible = False
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 != "") {
@ -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`,
@ -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();