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: 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():
if isEligible:
etatImm = AXIONE_ETAT_DEPLOYE_NON_COMMANDABLE 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: 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(
@ -149,8 +154,12 @@ class Axione:
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,6 +175,7 @@ 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"
try:
cur.execute( cur.execute(
f""" f"""
SELECT EtatImmeuble, DateDebutAcceptationCmdAcces SELECT EtatImmeuble, DateDebutAcceptationCmdAcces
@ -178,16 +188,23 @@ class Axione:
imm_elig = res[0] imm_elig = res[0]
isEligible = imm_elig == AXIONE_ETAT_DEPLOYE isEligible = imm_elig == AXIONE_ETAT_DEPLOYE
reasonNotEligible = "" if isEligible else "Pas encore deploye" reasonNotEligible = "" if isEligible else "Pas encore deploye"
dateCommandable = res[1]
else: else:
isEligible = False
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 = ""
except Exception as err:
imm_elig = "NOT_AXIONE"
isEligible = False
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

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