''' @author: olivier.massot, 2018 ''' from core import mn, gis from core.validation import NetgeoValidator, DuplicatedPk, RelationError, \ DuplicatedGeom, MissingItem, DimensionError from schemas.netgeo_1_12_doe.models import Artere, Cable, Equipement, Noeud, \ Tranchee, Zapbo class Netgeo112DoeValidator(NetgeoValidator): schema_name = "Netgeo v1.12 DOE" models = [Artere, Cable, Equipement, Noeud, Tranchee, Zapbo] def _technical_validation(self): # construction des index arteres = self.dataset[Artere] cables = self.dataset[Cable] tranchees = self.dataset[Tranchee] noeuds = {} for noeud in self.dataset[Noeud]: if not noeud.NO_NOM in noeuds: noeuds[noeud.NO_NOM] = noeud else: self.log_error(DuplicatedPk("Doublons dans le champs: {}".format(noeud.NO_NOM), filename=Noeud.filename, field="NO_NOM")) equipements = {} for equipement in self.dataset[Equipement]: if not equipement.EQ_NOM in equipements: equipements[equipement.EQ_NOM] = equipement else: self.log_error(DuplicatedPk("Doublons dans le champs: {}".format(equipement.NO_NOM), filename=Equipement.filename, field="EQ_NOM")) zapbos = {} for zapbo in self.dataset[Zapbo]: if not zapbo.ID_ZAPBO in zapbos: zapbos[zapbo.ID_ZAPBO] = zapbo else: self.log_error(DuplicatedPk("Doublons dans le champs: {}".format(zapbo.NO_NOM), filename=Zapbo.filename, field="ID_ZAPBO")) # rattachement les noeuds aux artères for artere in arteres: try: artere.noeud_a = noeuds[artere.AR_NOEUD_A] except KeyError: artere.noeud_a = None self.log_error(RelationError("Le noeud '{}' n'existe pas".format(artere.AR_NOEUD_A), filename=Artere.filename, field="AR_NOEUD_A")) try: artere.noeud_b = noeuds[artere.AR_NOEUD_B] except KeyError: artere.noeud_b = None self.log_error(RelationError("Le noeud '{}' n'existe pas".format(artere.AR_NOEUD_B), filename=Artere.filename, field="AR_NOEUD_A")) # rattachement des equipements aux cables for cable in cables: try: cable.equipement_a = equipements[cable.CA_EQ_A] except KeyError: cable.equipement_a = None self.log_error(RelationError("L'équipement '{}' n'existe pas".format(cable.CA_EQ_A), filename=Cable.filename, field="CA_EQ_A")) try: cable.equipement_b = equipements[cable.CA_EQ_B] except KeyError: cable.equipement_b = None self.log_error(RelationError("L'équipement '{}' n'existe pas".format(cable.CA_EQ_B), filename=Cable.filename, field="CA_EQ_B")) # rattachement des equipements aux noeuds for equipement in equipements.values(): try: equipement.noeud = noeuds[equipement.EQ_NOM_NOE] except KeyError: equipement.noeud = None self.log_error(RelationError("Le noeud '{}' n'existe pas".format(equipement.EQ_NOM_NOE, equipement.EQ_NOM), filename=Equipement.filename, field="EQ_NOM_NOE")) # verifie que tous les equipements sont l'equipement B d'au moins un cable equipements_b = [cable.CA_EQ_B for cable in cables] for eq_id in equipements: if not eq_id in equipements_b: self.log_error(RelationError("L'equipement '{}' n'est l'équipement B d'aucun cable".format(noeud.NO_NOM), filename=Equipement.filename, field="EQ_NOM")) # if self.critical_happened(): # return # controle des doublons graphiques for i, tranchee in enumerate(tranchees): for other in tranchees[i+1:]: if gis.same_geom(tranchee.geom, other.geom): self.log_error(DuplicatedGeom("Une entité graphique est dupliquée".format(tranchee), filename=Tranchee.filename, field="geom")) for i, artere in enumerate(arteres): for other in arteres[i+1:]: if gis.same_geom(artere.geom, other.geom): self.log_error(DuplicatedGeom("Une entité graphique est dupliquée ('')".format(artere), filename=Artere.filename, field="geom")) for i, cable in enumerate(cables): for other in cables[i+1:]: if gis.same_geom(cable.geom, other.geom): self.log_error(DuplicatedGeom("Une entité graphique est dupliquée ('')".format(cable), filename=Cable.filename, field="geom")) ls_noeuds = list(noeuds.values()) for i, noeud in enumerate(ls_noeuds): for other in ls_noeuds[i+1:]: if gis.same_geom(noeud.geom, other.geom): self.log_error(DuplicatedGeom("Une entité graphique est dupliquée ('')".format(noeud), filename=Noeud.filename, field="geom")) del ls_noeuds ls_zapbos = list(zapbos.values()) for i, zapbo in enumerate(ls_zapbos): for other in ls_zapbos[i+1:]: if gis.same_geom(zapbo.geom, other.geom): self.log_error(DuplicatedGeom("Une entité graphique est dupliquée ('')".format(zapbo), filename=Zapbo.filename, field="geom")) del ls_zapbos # Arteres: comparer la géométrie à celle des noeuds for artere in arteres: point_a, point_b = artere.geom.points[0], artere.geom.points[-1] if not artere.noeud_a or artere.noeud_b: continue if point_a not in (artere.noeud_a.geom.points[0], artere.noeud_b.geom.points[0]): self.log_error(DuplicatedGeom("Pas de noeud aux coordonnées attendues ('')".format(artere), filename=Artere.filename, field="geom")) if point_b not in (artere.noeud_a.geom.points[0], artere.noeud_b.geom.points[0]): self.log_error(DuplicatedGeom("Pas de noeud aux coordonnées attendues ('')".format(artere), filename=Artere.filename, field="geom")) # Cables: comparer la géométrie à celle des equipements (on utilise en fait la geom du noeud correspondant à l'équipement) for cable in cables: point_a, point_b = cable.geom.points[0], cable.geom.points[-1] if not cable.equipement_a or cable.equipement_b: continue if point_a not in (cable.equipement_a.noeud.geom.points[0], cable.equipement_b.noeud.geom.points[0]): self.log_error(DuplicatedGeom("Pas d'equipement aux coordonnées attendues ('')".format(cable), filename=Cable.filename, field="geom")) if point_b not in (cable.equipement_a.noeud.points[0], cable.equipement_b.noeud.geom.points[0]): self.log_error(DuplicatedGeom("Pas d'equipement aux coordonnées attendues ('')".format(cable), filename=Cable.filename, field="geom")) # Verifie que chaque tranchée a au moins une artère for tranchee in tranchees: found = False for artere in arteres: if tranchee.geom.bbox == artere.geom.bbox: found = True break if not found: self.log_error(MissingItem("Pas de tranchée correspondant à l'artère ('')".format(artere), filename=Artere.filename, field="-")) # Verifie que chaque cable a au moins une artère (sauf si commentaire contient 'baguette') for cable in cables: found = False if "baguette" in cable.CA_COMMENT.lower(): continue for artere in arteres: if tranchee.geom.bbox == artere.geom.bbox: found = True break if not found: self.log_error(MissingItem("Pas d'artère correspondante au cable ('')".format(cable), filename=Cable.filename, field="-")) # Verifie que chaque artère a au moins un cable (sauf si commentaire contient un de ces mots 'racco client adductio attente bus 'sans cable'') for tranchee in tranchees: found = False if any(x in cable.CA_COMMENT.lower() for x in ['racco','client','adductio','attente','bus','sans cable']): continue for artere in arteres: if tranchee.geom.bbox == artere.geom.bbox: found = True break if not found: self.log_error(MissingItem("Pas de cable correspondant à l'artère ('')".format(artere), filename=Artere.filename, field="-")) # Contrôle des dimensions logiques for artere in arteres: if not int(artere.AR_FOU_DIS) <= int(artere.AR_NB_FOUR): self.log_error(DimensionError("Le nombre de fourreaux disponibles doit être inférieur au nombre total ('')".format(artere), filename=Artere.filename, field="AR_FOU_DIS")) for cable in cables: if not int(cable.CA_NB_FO_U) <= int(artere.CA_NB_FO): self.log_error(DimensionError("Le nombre de fourreaux utilisés doit être inférieur au nombre total ('')".format(cable), filename=Cable.filename, field="CA_NB_FO_U")) if not int(cable.CA_NB_FO_D) <= int(artere.CA_NB_FO): self.log_error(DimensionError("Le nombre de fourreaux disponibles doit être inférieur au nombre total ('')".format(cable), filename=Cable.filename, field="CA_NB_FO_D")) # Contrôler l'emprise des ZAPBO # Verifier que chaque equipement de type PBO est contenu dans une zapbo, et que le nom de la zapbo contient le nom de l'equipement ### Verifs en base ant_db = mn.ANTDb() # Contrôler dans la base si des éléments portant ces codes existent à des emplacements différents # verifier que toutes les prises de la plaque sont inclues dans une zapbo if __name__ == "__main__": from core.constants import MAIN subject = MAIN / "work" / "STURNO_228CP0_APD_180301_OK.zip" report = Netgeo112DoeValidator.submit(subject) print(report)