mn2_rec.py 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914
  1. '''
  2. Schéma de validation des données MN2
  3. @author: olivier.massot, 2018
  4. '''
  5. import logging
  6. from qgis.core import QgsProject #@UnresolvedImport
  7. from MnCheck.core.cerberus_ import is_float, is_multi_int, is_int, \
  8. is_modern_french_date, CerberusValidator, CerberusErrorHandler, \
  9. _translate_messages, is_positive_int, is_strictly_positive_float, \
  10. is_positive_float, is_strictly_positive_int, _tofloat
  11. from MnCheck.core.checking import BaseChecker, CheckingException
  12. from MnCheck.core.mncheck import QgsModel
  13. logger = logging.getLogger("mncheck")
  14. SCHEMA_NAME = "Schéma MN v2 REC"
  15. STATUTS = ['EN ETUDE', 'EN REALISATION', 'EN SERVICE', 'HORS SERVICE',
  16. 'En étude', 'En réalisation', 'En service', 'Hors service']
  17. XMIN, XMAX, YMIN, YMAX = 1341999, 1429750, 8147750, 8294000
  18. CRS = 'EPSG:3949' # Coordinate Reference System
  19. TOLERANCE = 0.5
  20. ##### Modeles
  21. class Artere(QgsModel):
  22. layername = "artere_geo"
  23. geom_type = QgsModel.GEOM_LINE
  24. crs = CRS
  25. bounding_box = (XMIN,YMIN,XMAX,YMAX)
  26. pk = "AR_CODE"
  27. schema = {'AR_CODE': {'type': 'string', 'empty': False, 'maxlength': 30},
  28. 'AR_NOM': {'type': 'string', 'empty': False, 'maxlength': 30},
  29. 'AR_ID_INSE': {'type': 'string', 'empty': False, 'regex': r'50\d{3}'},
  30. 'AR_LONG': {'empty': False, 'validator': is_float},
  31. 'AR_ETAT': {'type': 'string', 'empty': False, 'allowed': ['0', '1', '2', '3', '4']},
  32. 'AR_OCCP': {'type': 'string', 'empty': False, 'allowed': ['0', '1.1', '1.2', '2', '3', '4']},
  33. 'AR_NOEUD_A': {'type': 'string', 'empty': False, 'maxlength': 30},
  34. 'AR_NOEUD_B': {'type': 'string', 'empty': False, 'maxlength': 30},
  35. 'AR_NB_FOUR': {'empty': True, 'validator': is_multi_int},
  36. 'AR_FOU_DIS': {'empty': True, 'validator': is_int},
  37. 'AR_TYPE_FO': {'type': 'string', 'empty': False, 'multiallowed': ['PVC', 'PEHD', 'SOUS-TUBAGE PEHD', 'SOUS-TUBAGE SOUPLE', 'FACADE', 'AERIEN', 'ENCORBELLEMENT', 'AUTRE']},
  38. 'AR_TYFO_AI': {'type': 'string', 'empty': False, 'multiallowed': ['PVC', 'PEH', 'TUB', 'FAC', 'ENC', 'APP']},
  39. 'AR_DIAM_FO': {'type': 'string', 'multiallowed': ['10', '14', '18', '25', '28', '32', '40', '45', '60', '80', '150', 'NUL', '']},
  40. 'AR_PRO_FOU': {'type': 'string', 'empty': False, 'multiallowed': ['MANCHE NUMERIQUE', 'COLLECTIVITE', 'ORANGE', 'PRIVE', 'ERDF', 'ENEDIS', 'SDEM', 'AUTRE']},
  41. 'AR_FAB': {'type': 'string', 'empty': True, 'maxlength': 100},
  42. 'AR_REFFAB': {'type': 'string', 'empty': True, 'maxlength': 100},
  43. 'AR_COULEUR': {'type': 'string', 'empty': True, 'maxlength': 20},
  44. 'AR_AIGUIL': {'type': 'string', 'empty': True, 'maxlength': 3, 'allowed': ['OUI', 'NON']},
  45. 'AR_NBCABL': {'empty': False, 'validator': is_positive_int},
  46. 'AR_PRO_CAB': {'type': 'string', 'empty': False, 'allowed': ['MANCHE NUMERIQUE']},
  47. 'AR_GEST_FO': {'type': 'string', 'multiallowed': ['MANCHE NUMERIQUE', 'MANCHE TELECOM', 'COLLECTIVITE', 'ORANGE', 'MANCHE FIBRE', 'PRIVE', 'ERDF', 'ENEDIS', 'SDEM', 'AUTRE', 'NUL']},
  48. 'AR_UTIL_FO': {'type': 'string', 'multiallowed': ['MANCHE NUMERIQUE', 'MANCHE TELECOM', 'COLLECTIVITE', 'ORANGE', 'MANCHE FIBRE', 'PRIVE', 'AUTRE', 'SDEM', 'NUL', '']},
  49. 'AR_DATE_IN': {'empty': True, 'validator': is_modern_french_date},
  50. 'AR_DATE_RE': {'empty': True, 'validator': is_modern_french_date},
  51. 'AR_REF_PLA': {'type': 'string', 'maxlength': 100},
  52. 'AR_SRC_GEO': {'type': 'string', 'empty': True, 'maxlength': 50},
  53. 'AR_QLT_GEO': {'type': 'string', 'empty': False, 'allowed': ['A', 'B', 'C']},
  54. 'AR_PRO_MD': {'type': 'string', 'empty': False, 'default': 'MANCHE NUMERIQUE', 'allowed': ['MANCHE NUMERIQUE']},
  55. 'AR_COMMENT': {'type': 'string', 'maxlength': 300, 'empty': True},
  56. 'AR_STATUT': {'type': 'string', 'empty': False, 'allowed': STATUTS}}
  57. class Cable(QgsModel):
  58. layername = "cable_geo"
  59. geom_type = QgsModel.GEOM_LINE
  60. crs = CRS
  61. bounding_box = (XMIN,YMIN,XMAX,YMAX)
  62. pk = "CA_CODE"
  63. schema = {'CA_CODE': {'type': 'string', 'empty': False, 'maxlength': 30},
  64. 'CA_NOM': {'type': 'string', 'empty': False, 'maxlength': 30},
  65. 'CA_NUMERO': {'type': 'string', 'empty': False, 'maxlength': 30},
  66. 'CA_EMPRISE': {'type': 'string', 'empty': False, 'maxlength': 10},
  67. 'CA_FAB': {'type': 'string', 'empty': False, 'maxlength': 100},
  68. 'CA_REFFAB': {'type': 'string', 'empty': False, 'maxlength': 100},
  69. 'CA_MODELE': {'type': 'string', 'empty': False, 'maxlength': 10},
  70. 'CA_TYPE': {'type': 'string', 'maxlength': 10, 'empty': False, 'allowed': ['AERIEN', 'IMMEUBLE', 'FACADE', 'MIXTE', 'SOUTERRAIN']},
  71. 'CA_TYPFCT': {'type': 'string', 'maxlength': 3, 'empty': False, 'allowed': ['CDI', 'CTR', 'CBM', 'RAC', 'CBO']},
  72. 'CA_ETAT': {'type': 'string', 'maxlength': 1, 'empty': False, 'allowed': ['0', '1', '2', '3', '4']},
  73. 'CA_LONG': {'empty': False, 'validator': is_strictly_positive_float},
  74. 'CA_EQ_A': {'type': 'string', 'empty': False, 'maxlength': 30},
  75. 'CA_EQ_B': {'type': 'string', 'empty': False, 'maxlength': 30},
  76. 'CA_DIAMETR': {'empty': False, 'validator': is_positive_float},
  77. 'CA_COULEUR': {'type': 'string', 'maxlength': 20, 'empty': False, 'allowed': ['NOIR', 'BLEU', 'BLANC']},
  78. 'CA_TECHNOL': {'type': 'string', 'maxlength': 17, 'empty': False, 'allowed': ['G657A2_M6', 'G657A2_M12', 'G652D_M12']},
  79. 'CA_NB_FO_U': {'empty': False, 'validator': is_positive_int},
  80. 'CA_NB_FO_D': {'empty': False, 'validator': is_positive_int},
  81. 'CA_PRO': {'type': 'string', 'maxlength': 20, 'empty': False, 'allowed': ['MANCHE NUMERIQUE']},
  82. 'CA_GEST': {'type': 'string', 'maxlength': 20, 'empty': False, 'allowed': ['MANCHE FIBRE']},
  83. 'CA_DATE_IN': {'empty': True, 'validator': is_modern_french_date},
  84. 'CA_COMMENT': {'type': 'string', 'maxlength': 300, 'empty': True},
  85. 'CA_STATUT': {'type': 'string', 'empty': False, 'allowed': STATUTS}}
  86. class Equipement(QgsModel):
  87. layername = "equipement_passif"
  88. geom_type = QgsModel.GEOM_POINT
  89. crs = CRS
  90. bounding_box = (XMIN,YMIN,XMAX,YMAX)
  91. pk = "EQ_CODE"
  92. schema = {'EQ_CODE': {'type': 'string', 'empty': False, 'maxlength': 30},
  93. 'EQ_NOM': {'type': 'string', 'empty': False, 'maxlength': 30},
  94. 'EQ_NOM_NOE': {'type': 'string', 'empty': False, 'maxlength': 30},
  95. 'EQ_REF': {'type': 'string', 'empty': False, 'maxlength': 100},
  96. 'EQ_EMPRISE': {'type': 'string', 'empty': False, 'maxlength': 10},
  97. 'EQ_FABR': {'type': 'string', 'empty': False, 'maxlength': 100},
  98. 'EQ_CAPFO': {'empty': True, 'validator': is_strictly_positive_int},
  99. 'EQ_NBMXEQ': {'empty': True, 'validator': is_strictly_positive_int},
  100. 'EQ_NBCAB': {'empty': True, 'validator': is_strictly_positive_int},
  101. 'EQ_DIMENS': {'type': 'string', 'empty': True, 'maxlength': 50},
  102. 'EQ_TYPEQ': {'type': 'string', 'empty': True, 'maxlength': 100},
  103. 'EQ_ETAT': {'type': 'string', 'empty': False, 'allowed': ['0', '1', '2', '3', '4']},
  104. 'EQ_OCCP': {'type': 'string', 'empty': False, 'allowed': ['0', '1.1', '1.2', '2', '3', '4']},
  105. 'EQ_TYPE': {'type': 'string', 'empty': False, 'allowed': ['PBO', 'BPE', 'BAI', 'PEC']},
  106. 'EQ_TYPSTRC': {'type': 'string', 'empty': True, 'allowed': ['CHAMBRE', 'AERIEN', 'FACADE', 'COLONNE MONTANTE', 'PIED IMMEUBLE', 'DTIO', 'SHELTER']},
  107. 'EQ_TYPE_LQ': {'type': 'string', 'empty': False, 'allowed': ['PBO', 'BPE JB', 'BPE JD', 'BAIDC', 'BAIOP']},
  108. 'EQ_TYPE_PH': {'type': 'string', 'empty': False, 'allowed': ['PBO 6', 'PBO 12', 'BPE 12EP', 'BPE 24EP', 'BPE 48EP', 'BPE 72EP', 'BPE 96EP', 'BPE 144EP', 'BPE 288EP', 'BPE 576EP', 'BPE 720EP', 'BAI']},
  109. 'EQ_PRO': {'type': 'string', 'empty': False, 'allowed': ['MANCHE NUMERIQUE', 'COLLECTIVITE', 'ORANGE', 'PRIVE', 'AUTRE', 'NUL']},
  110. 'EQ_GEST': {'type': 'string', 'empty': False, 'allowed': ['MANCHE NUMERIQUE', 'MANCHE TELECOM', 'COLLECTIVITE', 'ORANGE', 'MANCHE FIBRE', 'PRIVE', 'AUTRE', 'NUL']},
  111. 'EQ_HAUT': {'empty': True, 'validator': is_float},
  112. 'EQ_DATE_IN': {'empty': True, 'validator': is_modern_french_date},
  113. 'EQ_COMMENT': {'type': 'string', 'maxlength': 300, 'empty': True},
  114. 'EQ_STATUT': {'type': 'string', 'empty': False, 'allowed': STATUTS}}
  115. class Noeud(QgsModel):
  116. layername = "noeud_geo"
  117. geom_type = QgsModel.GEOM_POINT
  118. crs = CRS
  119. bounding_box = (XMIN,YMIN,XMAX,YMAX)
  120. pk = "NO_CODE"
  121. schema = {'NO_CODE': {'type': 'string', 'empty': False, 'maxlength': 30},
  122. 'NO_NOM': {'type': 'string', 'empty': False, 'maxlength': 30},
  123. 'NO_ID_INSE': {'type': 'string', 'empty': False, 'regex': r'50\d{3}'},
  124. 'NO_VOIE': {'type': 'string', 'empty': False, 'maxlength': 100},
  125. 'NO_EMPRISE': {'type': 'string', 'empty': False, 'maxlength':10},
  126. 'NO_ETAT': {'type': 'string', 'empty': False, 'allowed': ['0', '1', '2', '3', '4']},
  127. 'NO_OCCP': {'type': 'string', 'empty': False, 'allowed': ['0', '1.1', '1.2', '2', '3', '4']},
  128. 'NO_TYPE': {'type': 'string', 'empty': False, 'allowed': ['CHA', 'POT', 'LTE', 'SEM', 'FAC', 'OUV', 'IMM']},
  129. 'NO_TYPFCT': {'type': 'string', 'empty': False, 'allowed': ['INTERCONNEXION', 'SATELLITE', 'PASSAGE', 'REGARD', 'INDETERMINE']},
  130. 'NO_TYPE_LQ': {'type': 'string', 'empty': False, 'allowed': ['CHTIR', 'CHRACC', 'POT', 'NRO', 'PM', 'MIMO', 'FAC', 'OUV', 'IMM']},
  131. 'NO_TYPE_PH': {'type': 'string', 'empty': False, 'allowed': ['CHAMBRE', 'POTEAU', 'ARMOIRE', 'SHELTER', 'BATIMENT', 'SITE MIMO', 'FACADE', 'OUVRAGE', 'IMMEUBLE']},
  132. 'NO_CODE_PH': {'type': 'string', 'maxlength': 20},
  133. 'NO_TECH_PS': {'type': 'string', 'maxlength': 20, 'multiallowed': ['COAX', 'CUT', 'ECL', 'ELEC', 'VP', 'OPT', 'NC']},
  134. 'NO_AMO': {'type': 'string', 'maxlength': 30},
  135. 'NO_PLINOX': {'required':False, 'type': 'string', 'maxlength': 3, 'allowed': ['OUI', 'NON']},
  136. 'NO_X': {'empty': True, 'validator': is_float},
  137. 'NO_Y': {'empty': True, 'validator': is_float},
  138. 'NO_PRO': {'type': 'string', 'maxlength': 20, 'empty': False, 'allowed': ['MANCHE NUMERIQUE', 'COLLECTIVITE', 'ORANGE', 'ERDF', 'PRIVE', 'ENEDIS', 'SDEM', 'AUTRE', 'NUL']},
  139. 'NO_GEST': {'type': 'string', 'maxlength': 20, 'empty': False, 'allowed': ['MANCHE NUMERIQUE', 'MANCHE TELECOM', 'COLLECTIVITE', 'ORANGE', 'ERDF', 'ENEDIS', 'SDEM', 'MANCHE FIBRE', 'PRIVE', 'AUTRE', 'NUL']},
  140. 'NO_HAUT': {'empty': True, 'validator': is_float},
  141. 'NO_DATE_IN': {'empty': True, 'validator': is_modern_french_date},
  142. 'NO_REF_PLA': {'type': 'string', 'maxlength': 100},
  143. 'NO_SRC_GEO': {'type': 'string', 'empty': True, 'maxlength': 50},
  144. 'NO_QLT_GEO': {'type': 'string', 'maxlength': 1, 'empty': False, 'allowed': ['A', 'B', 'C']},
  145. 'NO_PRO_MD': {'type': 'string', 'maxlength': 20, 'empty': False, 'allowed': ['MANCHE NUMERIQUE']},
  146. 'NO_COMMENT': {'type': 'string', 'maxlength': 300, 'empty': True},
  147. 'NO_STATUT': {'type': 'string', 'empty': False, 'allowed': STATUTS}}
  148. class Tranchee(QgsModel):
  149. layername = "tranchee_geo"
  150. geom_type = QgsModel.GEOM_LINE
  151. crs = CRS
  152. bounding_box = (XMIN,YMIN,XMAX,YMAX)
  153. pk = "TR_CODE"
  154. schema = {'TR_CODE': {'type': 'string', 'empty': False, 'maxlength': 30},
  155. 'TR_NOM': {'type': 'string', 'empty': False, 'maxlength': 30},
  156. 'TR_ID_INSE': {'type': 'string', 'empty': False, 'regex': r'50\d{3}'},
  157. 'TR_VOIE': {'type': 'string', 'empty': False, 'maxlength': 200},
  158. 'TR_TYP_IMP': {'type': 'string', 'empty': False, 'allowed': ['ACCOTEMENT STABILISE', 'ACCOTEMENT NON STABILISE', 'CHAUSSEE LOURDE', 'CHAUSSEE LEGERE', 'FOSSE', 'TROTTOIR', 'ESPACE VERT', 'ENCORBELLEMENT']},
  159. 'TR_MOD_POS': {'type': 'string', 'empty': False, 'allowed': ['TRADITIONNEL', 'MICRO TRANCHEE', 'FONCAGE 60', 'FONCAGE 90', 'FONCAGE 120', 'TRANCHEUSE', 'FORAGE URBAIN', 'FORAGE RURAL', 'ENCORBELLEMENT']},
  160. 'TR_MPOS_AI': {'type': 'string', 'empty': False, 'allowed': ['TRA', 'ALL', 'FONCAGE 60', 'FON', 'FOR', 'ENC']},
  161. 'TR_LONG': {'empty': True, 'validator': is_strictly_positive_float},
  162. 'TR_LARG': {'empty': True, 'validator': is_strictly_positive_float},
  163. 'TR_REVET': {'empty':True, 'type': 'string', 'allowed': ['SABLE', 'BICOUCHE', 'GRAVIER', 'ENROBE', 'BETON', 'PAVE', 'TERRAIN NATUREL']},
  164. 'TR_CHARGE': {'empty': True, 'validator': is_positive_float},
  165. 'TR_GRILLAG': {'empty':True, 'validator': is_positive_float},
  166. 'TR_REMBLAI': {'type': 'string', 'maxlength': 50},
  167. 'TR_PLYNOX': {'type': 'string', 'empty': False, 'allowed': ['OUI', 'NON']},
  168. 'TR_PRO_VOI': {'type': 'string', 'empty': False, 'allowed': ['COMMUNE', 'COMMUNAUTE DE COMMUNES', 'DEPARTEMENT', 'ETAT', 'PRIVE']},
  169. 'TR_GEST_VO': {'type': 'string', 'empty': False, 'allowed': ['COMMUNE', 'COMMUNAUTE DE COMMUNES', 'DEPARTEMENT', 'ETAT', 'PRIVE']},
  170. 'TR_SCHEMA': {'maxlength': 100, 'type': 'string'},
  171. 'TR_DATE_IN': {'empty': True, 'validator': is_modern_french_date},
  172. 'TR_SRC_GEO': {'type': 'string', 'empty': True, 'maxlength': 50},
  173. 'TR_QLT_GEO': {'type': 'string', 'empty': False, 'allowed': ['A', 'B', 'C']},
  174. 'TR_PRO_MD': {'type': 'string', 'empty': False, 'maxlength': 20, 'allowed': ['MANCHE NUMERIQUE']},
  175. 'TR_COMMENT': {'type': 'string', 'maxlength': 300, 'empty': True},
  176. 'TR_STATUT': {'type': 'string', 'empty': False, 'allowed': STATUTS}}
  177. class Zapbo(QgsModel):
  178. layername = "zapbo_geo"
  179. geom_type = QgsModel.GEOM_POLYGON
  180. crs = CRS
  181. bounding_box = (XMIN,YMIN,XMAX,YMAX)
  182. pk = "ID_ZAPBO"
  183. required = False
  184. schema = {'ID_ZAPBO': {'type': 'string', 'empty': False, 'maxlength': 30, 'contains_any_of': ['PBO', 'BPE', 'PEC', 'BAI']},
  185. 'COMMENTAIR': {'type': 'string', 'maxlength': 254, 'empty': True},
  186. 'STATUT': {'type': 'string', 'empty': False, 'allowed': STATUTS}}
  187. models = [Artere, Cable, Equipement, Noeud, Tranchee, Zapbo]
  188. class Prise(QgsModel):
  189. layername = "FTTH_SITES_GEO_VALIDE"
  190. layername_bis = "SITE_GEO"
  191. pk = "ID_PRISE"
  192. ####### Validateur
  193. class Mn2Checker(BaseChecker):
  194. def setUp(self):
  195. self.dataset = {}
  196. for model in models:
  197. model.layer = next((l for l in QgsProject.instance().mapLayers().values() \
  198. if l.name().lower() == model.layername.lower()), None)
  199. self.dataset[model] = [model(f) for f in model.layer.getFeatures()] if model.layer else []
  200. self.arteres = self.dataset.get(Artere, [])
  201. self.cables = self.dataset.get(Cable, [])
  202. self.equipements = self.dataset.get(Equipement, [])
  203. self.noeuds = self.dataset.get(Noeud, [])
  204. self.tranchees = self.dataset.get(Tranchee, [])
  205. self.zapbos = self.dataset.get(Zapbo, [])
  206. for artere in self.arteres:
  207. artere.noeud_a = next((n for n in self.noeuds if n.NO_CODE == artere.AR_NOEUD_A), None)
  208. artere.noeud_b = next((n for n in self.noeuds if n.NO_CODE == artere.AR_NOEUD_B), None)
  209. for cable in self.cables:
  210. cable.equipement_a = next((e for e in self.equipements if e.EQ_CODE == cable.CA_EQ_A), None)
  211. cable.equipement_b = next((e for e in self.equipements if e.EQ_CODE == cable.CA_EQ_B), None)
  212. for equipement in self.equipements:
  213. equipement.noeud = next((n for n in self.noeuds if n.NO_CODE == equipement.EQ_NOM_NOE), None)
  214. self.prises = []
  215. Prise.layer = next((l for l in QgsProject.instance().mapLayers().values() \
  216. if l.name().lower() in [Prise.layername.lower(), Prise.layername_bis.lower()]), None)
  217. # Zapm partielles concernées, déduites des prises
  218. self.zapm_pa = []
  219. def _load_prises(self):
  220. """ on charge la couche des prises si elle existe """
  221. if not self.prises:
  222. self.prises = []
  223. if Prise.layer:
  224. prises = [Prise(f) for f in Prise.layer.getFeatures()]
  225. self.prises = [p for p in prises if p.T_ETAT.lower() != "obsolete"]
  226. for prise in self.prises:
  227. prise.zapbos = []
  228. if self.zapbos:
  229. for zapbo in self.zapbos:
  230. zapbo.prises = []
  231. for prise in self.prises:
  232. if zapbo.geom.contains(prise.geom):
  233. zapbo.prises.append(prise)
  234. prise.zapbos.append(zapbo)
  235. if not prise.ID_ZAPM_PA in self.zapm_pa:
  236. # la prise est dans une zapbo: on ajoute son id de zapm partielles à la liste
  237. self.zapm_pa.append(prise.ID_ZAPM_PA)
  238. def test_load_layers(self):
  239. """ Chargement des données
  240. Contrôle la présence des couches attendues
  241. """
  242. for model in models:
  243. if model.layer is None:
  244. self.log_error("Couche manquante", model=model)
  245. continue
  246. if model.pk:
  247. if not model.pk.lower() in [f.name().lower() for f in model.layer.fields()]:
  248. self.log_error(f"Clef primaire manquante ({model.pk})", model=model)
  249. continue
  250. def test_scr(self):
  251. """ Contrôle des projections
  252. Vérifie que les couches ont le bon sytème de projection
  253. """
  254. for model in models:
  255. if model.layer and model.layer.crs().authid() != model.crs:
  256. self.log_error(f"Mauvaise projection (attendu: {model.crs})", model=model)
  257. def _validate_structure(self, model, items):
  258. v = CerberusValidator(model.schema, purge_unknown=True, error_handler=CerberusErrorHandler, require_all=True)
  259. for item in items:
  260. v.validate(item.__dict__)
  261. for field, verrors in v.errors.items():
  262. for err in verrors:
  263. self.log_error(f"{field} : {_translate_messages(err)}", item=item)
  264. def test_structure_arteres(self):
  265. """ Structure des données: Artères
  266. Contrôle les données attributaires de la couche ARTERE_GEO:
  267. présence, format, valeurs autorisées...
  268. """
  269. self._validate_structure(Artere, self.arteres)
  270. def test_structure_cables(self):
  271. """ Structure des données: Cables
  272. Contrôle les données attributaires de la couche CABLE_GEO:
  273. présence, format, valeurs autorisées...
  274. """
  275. self._validate_structure(Cable, self.cables)
  276. def test_structure_equipements(self):
  277. """ Structure des données: Equipements
  278. Contrôle les données attributaires de la couche EQUIPEMENT_GEO:
  279. présence, format, valeurs autorisées...
  280. """
  281. self._validate_structure(Equipement, self.equipements)
  282. def test_structure_noeuds(self):
  283. """ Structure des données: Noeuds
  284. Contrôle les données attributaires de la couche NOEUD_GEO:
  285. présence, format, valeurs autorisées...
  286. """
  287. self._validate_structure(Noeud, self.noeuds)
  288. def test_structure_tranchees(self):
  289. """ Structure des données: Tranchées
  290. Contrôle les données attributaires de la couche TRANCHEE_GEO:
  291. présence, format, valeurs autorisées...
  292. """
  293. self._validate_structure(Tranchee, self.tranchees)
  294. def test_structure_zapbos(self):
  295. """ Structure des données: Zapbos
  296. Contrôle les données attributaires de la couche ZAPBO_GEO:
  297. présence, format, valeurs autorisées...
  298. """
  299. self._validate_structure(Zapbo, self.zapbos)
  300. def test_geometry_validity(self):
  301. """ Contrôle de la validité des géométries
  302. """
  303. for model in models:
  304. for item in self.dataset[model]:
  305. if not item.is_geometry_valid():
  306. self.log_error("La géométrie de l'objet est invalide", item=item)
  307. elif item.geom.isMultipart() and len(item.geom.asGeometryCollection()) > 1:
  308. self.log_error("Géométrie multiple", item=item)
  309. def test_geometry_type(self):
  310. """ Contrôle des types de géométries
  311. """
  312. for model in models:
  313. for item in self.dataset[model]:
  314. item_geom_type = item.get_geom_type()
  315. if item_geom_type != model.geom_type:
  316. expected, found = model.get_geom_name(model.geom_type), model.get_geom_name(item_geom_type)
  317. self.log_error(f"Type de géométrie invalide (attendu: {expected}, trouvé: {found})", item=item)
  318. def test_bounding_box(self):
  319. """ Contrôle des emprises
  320. Vérifie que les objets sont dans le périmètre attendu
  321. """
  322. for model in models:
  323. xmin, ymin, xmax, ymax = model.bounding_box
  324. for item in self.dataset[model]:
  325. if not item.is_geometry_valid():
  326. continue
  327. x1, y1, x2, y2 = item.get_bounding_box()
  328. if any(x < xmin or x > xmax for x in (x1, x2)) or \
  329. any(y < ymin or y > ymax for y in (y1, y2)):
  330. self.log_error("Hors de l'emprise autorisée", item=item)
  331. def test_duplicates(self):
  332. """ Recherche de doublons
  333. Recherche d'éventuels doublons dans des champs qui supposent l'unicité
  334. """
  335. # doublons dans AR_CODE
  336. tmp = []
  337. for artere in self.arteres:
  338. if not artere.AR_CODE:
  339. continue
  340. if not artere.AR_CODE in tmp:
  341. tmp.append(artere.AR_CODE)
  342. else:
  343. self.log_error("Doublons dans le champs AR_CODE", item=artere)
  344. # doublons dans AR_NOM
  345. tmp = []
  346. for artere in self.arteres:
  347. if not artere.AR_NOM:
  348. continue
  349. if not artere.AR_NOM in tmp:
  350. tmp.append(artere.AR_NOM)
  351. else:
  352. self.log_error("Doublons dans le champs AR_NOM", item=artere)
  353. # doublons dans CA_CODE
  354. tmp = []
  355. for cable in self.cables:
  356. if not cable.CA_CODE:
  357. continue
  358. if not cable.CA_CODE in tmp:
  359. tmp.append(cable.CA_CODE)
  360. else:
  361. self.log_error("Doublons dans le champs CA_CODE", item=cable)
  362. # doublons dans CA_NOM
  363. tmp = []
  364. for cable in self.cables:
  365. if not cable.CA_NOM:
  366. continue
  367. if not cable.CA_NOM in tmp:
  368. tmp.append(cable.CA_NOM)
  369. else:
  370. self.log_error("Doublons dans le champs CA_NOM", item=cable)
  371. # doublons dans EQ_CODE
  372. tmp = []
  373. for equipement in self.equipements:
  374. if not equipement.EQ_CODE:
  375. continue
  376. if not equipement.EQ_CODE in tmp:
  377. tmp.append(equipement.EQ_CODE)
  378. else:
  379. self.log_error("Doublons dans le champs EQ_CODE", item=equipement)
  380. # doublons dans EQ_NOM
  381. tmp = []
  382. for equipement in self.equipements:
  383. if not equipement.EQ_NOM:
  384. continue
  385. if not equipement.EQ_NOM in tmp:
  386. tmp.append(equipement.EQ_NOM)
  387. else:
  388. self.log_error("Doublons dans le champs EQ_NOM", item=equipement)
  389. # doublons dans NO_CODE
  390. tmp = []
  391. for noeud in self.noeuds:
  392. if not noeud.NO_CODE:
  393. continue
  394. if not noeud.NO_CODE in tmp:
  395. tmp.append(noeud.NO_CODE)
  396. else:
  397. self.log_error("Doublons dans le champs NO_CODE", item=noeud)
  398. # doublons dans NO_NOM
  399. tmp = []
  400. for noeud in self.noeuds:
  401. if not noeud.NO_NOM:
  402. continue
  403. if not noeud.NO_NOM in tmp:
  404. tmp.append(noeud.NO_NOM)
  405. else:
  406. self.log_error("Doublons dans le champs NO_NOM", item=noeud)
  407. # doublons dans TR_CODE
  408. tmp = []
  409. for tranchee in self.tranchees:
  410. if not tranchee.TR_CODE:
  411. continue
  412. if not tranchee.TR_CODE in tmp:
  413. tmp.append(tranchee.TR_CODE)
  414. else:
  415. self.log_error("Doublons dans le champs TR_CODE", item=tranchee)
  416. # doublons dans TR_NOM
  417. tmp = []
  418. for tranchee in self.tranchees:
  419. if not tranchee.TR_NOM:
  420. continue
  421. if not tranchee.TR_NOM in tmp:
  422. tmp.append(tranchee.TR_NOM)
  423. else:
  424. self.log_error("Doublons dans le champs TR_NOM", item=tranchee)
  425. # doublons dans ID_ZAPBO
  426. tmp = []
  427. for zapbo in self.zapbos:
  428. if not zapbo.ID_ZAPBO:
  429. continue
  430. if not zapbo.ID_ZAPBO in tmp:
  431. tmp.append(zapbo.ID_ZAPBO)
  432. else:
  433. self.log_error("Doublons dans le champs ID_ZAPBO", item=zapbo)
  434. def test_constraints_arteres_noeuds(self):
  435. """ Application des contraintes: Artères / Noeuds
  436. Vérifie que les noeuds attachés aux artères existent
  437. """
  438. for artere in self.arteres:
  439. if artere.noeud_a is None:
  440. self.log_error(f"Le noeud lié '{artere.AR_NOEUD_A}' n'existe pas", item=artere)
  441. if artere.noeud_b is None:
  442. self.log_error(f"Le noeud lié '{artere.AR_NOEUD_B}' n'existe pas", item=artere)
  443. def test_constraints_cables_equipements(self):
  444. """ Application des contraintes: Equipements / Cables
  445. Vérifie que les équipements attachés aux cables existent """
  446. for cable in self.cables:
  447. if cable.equipement_a is None:
  448. self.log_error(f"L'équipement lié '{cable.CA_EQ_A}' n'existe pas", item=cable)
  449. if cable.equipement_b is None:
  450. self.log_error(f"L'équipement lié '{cable.CA_EQ_B}' n'existe pas", item=cable)
  451. if cable.CA_STATUT != cable.equipement_b.EQ_STATUT:
  452. self.log_error(f"L'équipement B du cable n'a pas le même statut que le cable", item=cable)
  453. def test_constraints_cables_equipements_b(self):
  454. """ Application des contraintes: Equipements B
  455. Vérifie que tous les équipements sont l'équipement B d'au moins un cable """
  456. equipements_b = [cable.CA_EQ_B for cable in self.cables]
  457. for equipement in self.equipements:
  458. if equipement.EQ_TYPE == "BAI":
  459. continue
  460. if not equipement.EQ_CODE in equipements_b:
  461. self.log_error(f"L'equipement '{equipement.EQ_CODE}' n'est l'équipement B d'aucun cable et n'est pas un PM", item=equipement)
  462. def test_constraints_equipements_noeuds(self):
  463. """ Application des contraintes: Noeuds / Equipements
  464. Vérifie que les noeuds attachés aux équipements existent
  465. """
  466. for equipement in self.equipements:
  467. if equipement.noeud is None:
  468. self.log_error(f"Le noeud lié '{equipement.EQ_NOM_NOE}' n'existe pas", item=equipement)
  469. def test_graphic_duplicates(self):
  470. """ Recherche de doublons graphiques """
  471. for i, tranchee in enumerate(self.tranchees):
  472. for other in self.tranchees[i+1:]:
  473. if tranchee.geom.equals(other.geom):
  474. self.log_error("Une entité graphique est dupliquée", item=tranchee)
  475. continue
  476. for i, artere in enumerate(self.arteres):
  477. for other in self.arteres[i+1:]:
  478. if artere.geom.equals(other.geom):
  479. self.log_error("Une entité graphique est dupliquée", item=artere)
  480. continue
  481. for i, cable in enumerate(self.cables):
  482. for other in self.cables[i+1:]:
  483. if cable.geom.equals(other.geom) and cable.CA_EQ_A == other.CA_EQ_A and cable.CA_EQ_B == other.CA_EQ_B:
  484. self.log_error("Une entité graphique est dupliquée", item=cable)
  485. continue
  486. for i, noeud in enumerate(self.noeuds):
  487. for other in self.noeuds[i+1:]:
  488. if noeud.geom.equals(other.geom):
  489. self.log_error("Une entité graphique est dupliquée", item=noeud)
  490. continue
  491. for i, zapbo in enumerate(self.zapbos):
  492. for other in self.zapbos[i+1:]:
  493. if zapbo.geom.equals(other.geom):
  494. self.log_error("Une entité graphique est dupliquée", item=zapbo)
  495. continue
  496. def test_positions_noeuds(self):
  497. """ Topologie: Noeuds / Artères
  498. Compare la géométrie des noeuds à celle des artères
  499. """
  500. for artere in self.arteres:
  501. if not artere.noeud_a or not artere.noeud_b:
  502. continue
  503. artere_points = artere.get_points()
  504. noeud_a_point = artere.noeud_a.get_points()[0]
  505. noeud_b_point = artere.noeud_b.get_points()[0]
  506. a_seen_at = []
  507. b_seen_at = []
  508. for i, p in enumerate(artere_points):
  509. if p.distanceSquared(noeud_a_point) <= TOLERANCE:
  510. a_seen_at.append(i)
  511. if p.distanceSquared(noeud_b_point) <= TOLERANCE:
  512. b_seen_at.append(i)
  513. if a_seen_at:
  514. if 0 in a_seen_at or (len(artere_points) - 1) in a_seen_at:
  515. pass # ok
  516. else:
  517. self.log_error(f"Le noeud A n'est pas situé à l'extremité de l'artère", item=artere)
  518. else:
  519. self.log_error(f"Le noeud A n'est pas aux coordonnées attendues ({artere.noeud_a.NO_CODE})", item=artere)
  520. if b_seen_at:
  521. if 0 in b_seen_at or (len(artere_points) - 1) in b_seen_at:
  522. pass # ok
  523. else:
  524. self.log_error(f"Le noeud B n'est pas situé à l'extremité de l'artère", item=artere)
  525. else:
  526. self.log_error(f"Le noeud B n'est pas aux coordonnées attendues ({artere.noeud_b.NO_CODE})", item=artere)
  527. def test_positions_equipements(self):
  528. """ Topologie: Equipements / Cables
  529. Compare la géométrie des équipements à celle des cables """
  530. for cable in self.cables:
  531. if not cable.equipement_a or not cable.equipement_b or not cable.is_geometry_valid() or not cable.equipement_a.noeud or not cable.equipement_b.noeud:
  532. continue
  533. #! attention: on utilise la géométrie du noeud associé à l'équipement, pas celle de l'équipement lui-même
  534. cable_points = cable.get_points()
  535. equip_a_point = cable.equipement_a.noeud.get_points()[0]
  536. equip_b_point = cable.equipement_b.noeud.get_points()[0]
  537. a_seen_at = []
  538. b_seen_at = []
  539. for i, p in enumerate(cable_points):
  540. if p.distanceSquared(equip_a_point) <= TOLERANCE:
  541. a_seen_at.append(i)
  542. if p.distanceSquared(equip_b_point) <= TOLERANCE:
  543. b_seen_at.append(i)
  544. if a_seen_at:
  545. if 0 in a_seen_at or (len(cable_points) - 1) in a_seen_at:
  546. pass # ok
  547. else:
  548. self.log_error(f"L'équipement A n'est pas situé à l'extremité du cable", item=cable)
  549. else:
  550. self.log_error(f"L'équipement A n'est pas aux coordonnées attendues ({cable.equipement_a.EQ_CODE})", item=cable)
  551. if b_seen_at:
  552. if 0 in b_seen_at or (len(cable_points) - 1) in b_seen_at:
  553. pass # ok
  554. else:
  555. self.log_error(f"L'équipement B n'est pas situé à l'extremité du cable", item=cable)
  556. else:
  557. self.log_error(f"L'équipement B n'est pas aux coordonnées attendues ({cable.equipement_b.EQ_CODE})", item=cable)
  558. def test_tranchee_artere(self):
  559. """ Topologie: Tranchées / Artères
  560. Compare la géométrie des tranchées à celle des artères """
  561. arteres_full_buffer = Artere.full_buffer(TOLERANCE)
  562. for tranchee in self.tranchees:
  563. if not arteres_full_buffer.contains(tranchee.geom):
  564. self.log_error("Tranchée ou portion de tranchée sans artère", item=tranchee)
  565. def test_cable_artere(self):
  566. """ Topologie: Cables / Artères
  567. Compare la géométrie des cables à celle des artères """
  568. # Vérifie que chaque cable a au moins une artère (sauf si commentaire contient 'baguette')
  569. arteres_full_buffer = Artere.full_buffer(TOLERANCE)
  570. for cable in self.cables:
  571. if "baguette" in cable.CA_COMMENT.lower() or not cable.is_geometry_valid():
  572. continue
  573. if not arteres_full_buffer.contains(cable.geom):
  574. self.log_error("Cable ou portion de cable sans artère", item=cable)
  575. def test_artere_cable(self):
  576. """ Topologie: Artères / Cables
  577. Compare la géométrie des artères à celle des cables """
  578. # Vérifie que chaque artère a au moins un cable (sauf si commentaire contient un de ces mots 'racco client adductio attente bus 'sans cable'')
  579. cables_full_buffer = Cable.full_buffer(TOLERANCE)
  580. for artere in self.arteres:
  581. if any(x in artere.AR_COMMENT.lower() for x in ['racco','client','adductio','attente','bus','sans cable']):
  582. continue
  583. if not cables_full_buffer.contains(artere.geom):
  584. self.log_error("Artère ou portion d'artère sans cable", item=artere)
  585. def test_boites(self):
  586. """ Données des boites
  587. Contrôle les données des équipements de type BPE / PBO """
  588. for equipement in self.equipements:
  589. if equipement.EQ_TYPE == "BAI" or not equipement.EQ_DATE_IN:
  590. continue
  591. for field in ["EQ_CAPFO", "EQ_NBMXEQ", "EQ_NBCAB", "EQ_DIMENS", "EQ_TYPEQ", "EQ_TYPSTRC"]:
  592. if not hasattr(equipement, field):
  593. self.log_error("Le champs est obligatoire: {}".format(field), item=equipement)
  594. elif getattr(equipement, field) == "":
  595. self.log_error("Le champs doit être renseigné: {}".format(field), item=equipement)
  596. if equipement.EQ_TYPE == "BPE" and equipement.noeud.NO_TYPE_PH == "POTEAU":
  597. self.log_error("Une BPE ne peut pas être sur un poteau", item=equipement)
  598. if equipement.EQ_TYPE == "PBO" and equipement.noeud.NO_TYPE_PH == "POTEAU":
  599. try:
  600. if not 2.4 <= _tofloat(equipement.EQ_HAUT) <= 4.0:
  601. self.log_error("PBO sur poteau: La hauteur doit être comprise entre 2.40m et 4.00m", item=equipement)
  602. except (TypeError, ValueError):
  603. self.log_error("PBO sur poteau: Hauteur manquante ou invalide", item=equipement)
  604. def test_arteres_enterrees(self):
  605. """ Données des artères enterrées
  606. Contrôle les données des artères enterrées ou en encorbellement """
  607. for artere in self.arteres:
  608. if artere.AR_TYPE_FO in ["FACADE", "AERIEN"]:
  609. continue
  610. for field in ["AR_NB_FOUR", "AR_FOU_DIS", "AR_DIAM_FO", "AR_AIGUIL"]:
  611. if not hasattr(artere, field):
  612. self.log_error("Le champs est obligatoire: {}".format(field), item=artere)
  613. elif getattr(artere, field) == "":
  614. self.log_error("Le champs doit être renseigné: {}".format(field), item=artere)
  615. if artere.AR_DATE_IN:
  616. for field in ["AR_COULEUR", "AR_FAB", "AR_REFFAB"]:
  617. if not hasattr(artere, field):
  618. self.log_error("Le champs est obligatoire: {}".format(field), item=artere)
  619. elif getattr(artere, field) == "":
  620. self.log_error("Le champs doit être renseigné: {}".format(field), item=artere)
  621. def test_largeur_tranchees(self):
  622. """ Tranchées: Dimensions
  623. Vérifie que la cohérence des dimensions des tranchées """
  624. for tranchee in self.tranchees:
  625. if not ("FONCAGE" in tranchee.TR_MOD_POS or
  626. "FORAGE" in tranchee.TR_MOD_POS or
  627. "ENCORBELLEMENT" in tranchee.TR_MOD_POS):
  628. try:
  629. if float(tranchee.TR_LARG) > 0:
  630. continue
  631. except (TypeError, ValueError):
  632. pass
  633. self.log_error("La largeur de la tranchée doit être supérieure à 0", item=tranchee)
  634. def test_dimensions_fourreaux(self):
  635. """ Dimensions logiques: fourreaux
  636. Vérifie que les nombres de fourreaux renseignés sont cohérents """
  637. for artere in self.arteres:
  638. if artere.AR_TYPE_FO in ["FACADE", "AERIEN"]:
  639. continue
  640. try:
  641. if not int(artere.AR_FOU_DIS) <= int(artere.AR_NB_FOUR):
  642. self.log_error("Le nombre de fourreaux disponibles (AR_FOU_DIS) doit être inférieur au nombre total (AR_NB_FOUR)", item=artere)
  643. except (TypeError, ValueError):
  644. pass
  645. def test_prop_gest(self):
  646. """ Propriétaires / Gestionnaires
  647. Vérifie la cohérence des propriétaires et gestionnaires renseignés """
  648. cases = {
  649. "ORANGE": ["ORANGE"],
  650. "ERDF": ["ERDF"],
  651. "ENEDIS": ["ENEDIS"],
  652. "MANCHE NUMERIQUE": ["MANCHE FIBRE", "MANCHE TELECOM"]
  653. }
  654. for artere in self.arteres:
  655. for prop, gests in cases.items():
  656. if artere.AR_PRO_FOU.upper() == prop and not artere.AR_GEST_FO.upper() in gests:
  657. self.log_error("Propriétaire: {}, gestionnaire(s) possible(s): {} (renseigné: {})".format(prop, ', '.join(gests), artere.AR_GEST_FO), item=artere)
  658. for equipement in self.equipements:
  659. for prop, gests in cases.items():
  660. if equipement.EQ_PRO.upper() == prop and not equipement.EQ_GEST.upper() in gests:
  661. self.log_error("Propriétaire: {}, gestionnaire(s) possible(s): {} (renseigné: {})".format(prop, ', '.join(gests), equipement.EQ_GEST), item=equipement)
  662. for noeud in self.noeuds:
  663. for prop, gests in cases.items():
  664. if noeud.NO_PRO.upper() == prop and not noeud.NO_GEST.upper() in gests:
  665. self.log_error("Propriétaire: {}, gestionnaire(s) possible(s): {} (renseigné: {})".format(prop, ', '.join(gests), noeud.NO_GEST), item=noeud)
  666. for artere in self.arteres:
  667. if artere.AR_PRO_FOU.upper() == "ORANGE" and (artere.noeud_a.NO_PRO.upper() == "MANCHE NUMERIQUE" \
  668. or artere.noeud_b.NO_PRO.upper() == "MANCHE NUMERIQUE"):
  669. self.log_error("Les noeuds d'une artère ORANGE ne peuvent pas être propriété de MANCHE NUMERIQUE", item=artere)
  670. def test_dates_install(self):
  671. """ Dates d'installation
  672. Vérifie que les dates d'installation sont renseignées pour les équipements en service """
  673. for equipement in self.equipements:
  674. if equipement.EQ_STATUT == "EN SERVICE" and not equipement.EQ_DATE_IN:
  675. self.log_error("Date d'installation (EQ_DATE_IN) manquante", item=equipement)
  676. for cable in self.cables:
  677. if cable.CA_STATUT == "EN SERVICE" and not cable.CA_DATE_IN:
  678. self.log_error("Date d'installation (CA_DATE_IN) manquante", item=cable)
  679. for tranchee in self.tranchees:
  680. if tranchee.TR_STATUT == "EN SERVICE" and not tranchee.TR_DATE_IN:
  681. self.log_error("Date d'installation (TR_DATE_IN) manquante", item=tranchee)
  682. def test_statuts(self):
  683. """ Cohérence des statuts
  684. Vérifie que les statuts des éléments sont cohérents """
  685. for cable in self.cables:
  686. if cable.equipement_a and cable.CA_STATUT == "REC" and cable.equipement_a.EQ_STATUT in ('PRO', 'EXE'):
  687. self.log_error(f"Incohérence de statut entre le cable et son équipement A", item=cable)
  688. if cable.equipement_b and cable.CA_STATUT == "REC" and cable.equipement_b.EQ_STATUT in ('PRO', 'EXE'):
  689. self.log_error(f"Incohérence de statut entre le cable et son équipement B", item=cable)
  690. def _za_for_pbo(self, pbo):
  691. # retourne la ZAPBO correspondant à la PBO en parametre, None si aucune
  692. if hasattr(pbo, 'zapbo') and pbo.zapbo:
  693. return pbo.zapbo
  694. for zapbo in self.zapbos:
  695. if zapbo.geom.contains(pbo.geom) and pbo.EQ_NOM in zapbo.ID_ZAPBO:
  696. return zapbo
  697. return None
  698. def test_pbos(self):
  699. """ Topologie: PBO / ZAPBO
  700. Compare la géométrie et le nom des équipements de type PBO à celle des ZAPBO
  701. """
  702. # 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
  703. for equipement in self.equipements:
  704. if not equipement.EQ_TYPE == "PBO":
  705. continue
  706. #zapbos englobant l'equipement
  707. candidates = [z for z in self.zapbos if z.geom.contains(equipement.noeud.geom)]
  708. # le pbo doit être contenu dans une zapbo
  709. if not candidates:
  710. self.log_error("Le PBO n'est contenu dans aucune ZAPBO", item=equipement)
  711. continue
  712. # On se base sur le nom pour trouver la zapbo correspondante
  713. equipement.zapbo = next((z for z in candidates if equipement.EQ_CODE in z.ID_ZAPBO), None)
  714. if not equipement.zapbo:
  715. self.log_error("Le nom de la PBO ne coincide avec le nom d'aucune des ZAPBO qui le contiennent", item=equipement)
  716. continue
  717. if equipement.EQ_STATUT != equipement.zapbo.STATUT:
  718. self.log_error("Le statut de la PBO ne coincide pas avec celui de sa ZAPBO", item=equipement)
  719. continue
  720. def test_comments(self):
  721. """ Présence de commentaires
  722. Vérifie la présence de commentaires là où ils sont attendus
  723. """
  724. for equipement in self.equipements:
  725. if equipement.EQ_STATUT.upper() != 'EN SERVICE' and not equipement.EQ_COMMENT:
  726. self.log_error("L'equipement n'est pas en REC, un commentaire devrait en préciser la raison", item=equipement)
  727. for zapbo in self.zapbos:
  728. if zapbo.STATUT.upper() != 'EN SERVICE' and not zapbo.COMMENTAIR:
  729. self.log_error("La Zapbo n'est pas en REC, un commentaire devrait en préciser la raison", item=zapbo)
  730. def test_zapbos_prises(self):
  731. """ Topologie: Zapbos / Prises
  732. Toutes les zapbo contiennent au moins une prise"""
  733. self._load_prises()
  734. if not self.prises:
  735. raise CheckingException("La couche des prises n'est pas chargée")
  736. for zapbo in self.zapbos:
  737. if not zapbo.prises:
  738. self.log_error("La Zapbo ne contient aucune prise", item=zapbo)
  739. for prise in self.prises:
  740. if prise.ID_ZAPM_PA in self.zapm_pa and not prise.zapbos:
  741. self.log_error("La prise n'est contenue dans aucune ZAPBO", item=prise)
  742. def test_pbo_dimension(self):
  743. """ Dimensionnement des PBO
  744. Compare la couche des prises (si chargée) au dimensionnement des PBO"""
  745. self._load_prises()
  746. if not self.prises:
  747. raise CheckingException("La couche des prises n'est pas chargée")
  748. for equipement in self.equipements:
  749. if not equipement.EQ_TYPE == "PBO":
  750. continue
  751. zapbo = self._za_for_pbo(equipement)
  752. if not zapbo:
  753. continue
  754. zapbo.nb_prises = sum([int(prise.NB_PRISE) for prise in zapbo.prises if prise.NB_PRISE])
  755. # Controle du dimensionnement des PBO
  756. if equipement.EQ_TYPE_PH == 'PBO 6' and not zapbo.nb_prises < 6:
  757. self.log_error("Le PBO 6 contient plus de 5 prises", item=equipement)
  758. if equipement.EQ_TYPE_PH == 'PBO 12' and not zapbo.nb_prises >= 6 and zapbo.nb_prises <= 8:
  759. self.log_error("Le PBO 12 contient moins de 6 prises ou plus de 8 prises", item=equipement)
  760. if zapbo.STATUT == "REC" and not equipement.EQ_STATUT == "REC":
  761. self.log_error("Le statut du PBO n'est pas cohérent avec le statut de sa ZAPBO", item=equipement)
  762. if equipement.EQ_STATUT == "REC" and not zapbo.STATUT == "REC" and not zapbo.ID_ZAPBO[:4].lower() == "att_":
  763. self.log_error("Le statut du PBO n'est pas cohérent avec le statut de sa ZAPBO", item=equipement)
  764. checkers = [Mn2Checker]