bug fixes et améliorations, paramétrages #1

Merged
SebF merged 12 commits from externalisation_traductions_et_requetes into master 2022-05-09 21:58:08 +02:00
5 changed files with 274 additions and 173 deletions
Showing only changes of commit 4960e78fa8 - Show all commits

148
champs_generiques.json Normal file
View File

@ -0,0 +1,148 @@
{
"CHAMPS_STATIONNEMENT": {
"amenity": {
"export_json": "Non",
"FR": "aménagement"
},
"capacity": {
"export_json": "Oui",
"FR": "nombre d'emplacements"
},
"access": {
"export_json": "Oui",
"FR": "accès"
},
"bicycle_parking": {
"export_json": "Oui",
"FR": "type"
},
"covered": {
"export_json": "Oui",
"FR": "couvert"
},
"operator": {
"export_json": "Oui",
"FR": "opérateur"
},
"operator:type": {
"export_json": "Oui",
"FR": "type d'opérateur"
},
"fee": {
"export_json": "Oui",
"FR": "frais"
},
"check_date:capacity": {
"export_json": "Non",
"FR": "date_vérification"
},
"source": {
"export_json": "Non",
"FR": "source"
}
},
"CHAMPS_POI": {
"name": {
"export_json": "Oui",
"FR": ""
},
"description": {
"export_json": "Oui",
"FR": ""
},
"website": {
"export_json": "Oui",
"FR": ""
},
"addr:housenumber": {
"export_json": "Oui",
"FR": ""
},
"addr:street": {
"export_json": "Oui",
"FR": ""
},
"addr:postcode": {
"export_json": "Oui",
"FR": ""
},
"addr:city": {
"export_json": "Oui",
"FR": ""
},
"contact:email": {
"export_json": "Oui",
"FR": "email"
},
"contact:twitter": {
"export_json": "Oui",
"FR": "Twitter"
},
"contact:facebook": {
"export_json": "Oui",
"FR": "Facebook"
},
"contact:phone": {
"export_json": "Oui",
"FR": "Téléphone"
},
"network": {
"export_json": "Oui",
"FR": "Réseau"
},
"office": {
"export_json": "Oui",
"FR": "Bureau"
},
"opening_hours": {
"export_json": "Oui",
"FR": "Horaires"
}
},
"CHAMPS_ADRESSE": {
"api_adresse:geometry:coordinates:lon": {
"export_json": "Non",
"FR": "lon_adresse_etalab"
},
"api_adresse:geometry:coordinates:lat": {
"export_json": "Non",
"FR": "lat_adresse_etalab"
},
"api_adresse:properties:label": {
"export_json": "Non",
"FR": "adresse_etalab"
},
"api_adresse:properties:score": {
"export_json": "Non",
"FR": "score_etalab"
},
"api_adresse:properties:housenumber": {
"export_json": "Non",
"FR": "numero_etalab"
},
"api_adresse:properties:type": {
"export_json": "Non",
"FR": "type_etalab"
},
"api_adresse:properties:name": {
"export_json": "Non",
"FR": "numero_et_voie_etalab"
},
"api_adresse:properties:postcode": {
"export_json": "Non",
"FR": "code_postal_etalab"
},
"api_adresse:properties:citycode": {
"export_json": "Non",
"FR": "code_INSEE_etalab"
},
"api_adresse:properties:city": {
"export_json": "Non",
"FR": "ville_etalab"
},
"api_adresse:properties:street": {
"export_json": "Non",
"FR": "rue_etalab"
}
}
}

View File

@ -1,166 +0,0 @@
#!/usr/bin/env python3
# Copyright 2021 Olav63, SebF
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
"""Module des requêtes"""
class Requete:
"""Objet requête"""
nom: str
critere: str
champs: dict
def __init__(self, nom, critere, champs):
self.nom = nom
self.critere = critere
self.champs = champs
REQS = []
CHAMPS_STATIONNEMENT = {
"amenity": {"export_json": "Non", "FR": "aménagement"},
"capacity": {"export_json": "Oui", "FR": "nombre d'emplacements"},
"access": {"export_json": "Oui", "FR": "accès"},
"bicycle_parking": {"export_json": "Oui", "FR": "type"},
"covered": {"export_json": "Oui", "FR": "couvert"},
"operator": {"export_json": "Oui", "FR": "opérateur"},
"operator:type": {"export_json": "Oui", "FR": "type d'opérateur"},
"fee": {"export_json": "Oui", "FR": "frais"},
"check_date:capacity": {"export_json": "Non", "FR": "date_vérification"},
"source": {"export_json": "Non", "FR": "source"},
}
CHAMPS_POI = {
"name": {"export_json": "Oui", "FR": ""},
"description": {"export_json": "Oui", "FR": ""},
"website": {"export_json": "Oui", "FR": ""},
"addr:housenumber": {"export_json": "Oui", "FR": ""},
"addr:street": {"export_json": "Oui", "FR": ""},
"addr:postcode": {"export_json": "Oui", "FR": ""},
"addr:city": {"export_json": "Oui", "FR": ""},
"contact:email": {"export_json": "Oui", "FR": "email"},
"contact:twitter": {"export_json": "Oui", "FR": "Twitter"},
"contact:facebook": {"export_json": "Oui", "FR": "Facebook"},
"contact:phone": {"export_json": "Oui", "FR": "Téléphone"},
"network": {"export_json": "Oui", "FR": "Réseau"},
"office": {"export_json": "Oui", "FR": "Bureau"},
"opening_hours": {"export_json": "Oui", "FR": "Horaires"},
}
CHAMPS_ADRESSE = {
"api_adresse:geometry:coordinates:lon": {
"export_json": "Non",
"FR": "lon_adresse_etalab",
},
"api_adresse:geometry:coordinates:lat": {
"export_json": "Non",
"FR": "lat_adresse_etalab",
},
"api_adresse:properties:label": {"export_json": "Non", "FR": "adresse_etalab"},
"api_adresse:properties:score": {"export_json": "Non", "FR": "score_etalab"},
"api_adresse:properties:housenumber": {"export_json": "Non", "FR": "numero_etalab"},
"api_adresse:properties:type": {"export_json": "Non", "FR": "type_etalab"},
"api_adresse:properties:name": {
"export_json": "Non",
"FR": "numero_et_voie_etalab",
},
"api_adresse:properties:postcode": {
"export_json": "Non",
"FR": "code_postal_etalab",
},
"api_adresse:properties:citycode": {
"export_json": "Non",
"FR": "code_INSEE_etalab",
},
"api_adresse:properties:city": {"export_json": "Non", "FR": "ville_etalab"},
"api_adresse:properties:street": {"export_json": "Non", "FR": "rue_etalab"},
}
# pylint: disable=C0301
STATIONNEMENT_NON_PUBLIC_REQ = r'nwr["amenity"="bicycle_parking"]["access"~"(no|permit|private|customers|permissive)"](area:aire_de_recherche);'
REQS.append(
Requete(
"stationnements_velos_non_publics",
STATIONNEMENT_NON_PUBLIC_REQ,
dict(CHAMPS_STATIONNEMENT, **CHAMPS_ADRESSE),
)
)
REQS.append(
Requete(
"stationnements_velos_publics",
# pylint: disable=C0301
rf'nwr["amenity"="bicycle_parking"](area:aire_de_recherche); - {STATIONNEMENT_NON_PUBLIC_REQ}',
dict(CHAMPS_STATIONNEMENT, **CHAMPS_ADRESSE),
)
)
CHAMP_LOCAL = {"service:bicycle:diy": {"export_json": "Non", "FR": ""}}
REQS.append(
Requete(
"ateliers_autoreparation",
r'nwr["service:bicycle:diy"="yes"](area:aire_de_recherche);',
dict(CHAMP_LOCAL, **CHAMPS_POI, **CHAMPS_ADRESSE),
)
)
CHAMP_LOCAL = {"association": {"export_json": "Non", "FR": ""}}
REQS.append(
Requete(
"associations_velo",
r'nwr["association"="bicycle"](area:aire_de_recherche);',
dict(CHAMP_LOCAL, **CHAMPS_POI, **CHAMPS_ADRESSE),
)
)
CHAMP_LOCAL = {"craft": {"export_json": "Non", "FR": ""}}
REQS.append(
Requete(
"fabriquants_velo",
r'nwr["craft"="bicycle"](area:aire_de_recherche);',
dict(CHAMP_LOCAL, **CHAMPS_POI, **CHAMPS_ADRESSE),
)
)
CHAMP_LOCAL = {"shop": {"export_json": "Non", "FR": ""}}
REQS.append(
Requete(
"vendeurs_velo",
# pylint: disable=C0301
r'nwr["shop"="bicycle"](area:aire_de_recherche); nwr["service:bicycle:retail"="yes"](area:aire_de_recherche);',
dict(CHAMP_LOCAL, **CHAMPS_POI, **CHAMPS_ADRESSE),
)
)
CHAMP_LOCAL = {"amenity": {"export_json": "Non", "FR": ""}}
REQS.append(
Requete(
"velos_libre_service",
r'nwr["amenity"="bicycle_rental"](area:aire_de_recherche);',
dict(CHAMP_LOCAL, **CHAMPS_POI, **CHAMPS_ADRESSE),
)
)
CHAMP_LOCAL = {"service:bicycle:rental": {"export_json": "Non", "FR": ""}}
REQS.append(
Requete(
"location_velo",
r'nwr["service:bicycle:rental"="yes"](area:aire_de_recherche);',
dict(CHAMP_LOCAL, **CHAMPS_POI, **CHAMPS_ADRESSE),
)
)

View File

@ -47,6 +47,8 @@ class Utils:
with open("traductions.json", encoding="utf-8") as trads:
self.traductions = json.load(trads)
self.lecture_requetes()
def save_as_ods(self, fields, data, nom_req, ods_data_sheet=OrderedDict()):
"""Sauvegarde de data dans un classeur ods"""
@ -257,3 +259,21 @@ class Utils:
for file in os.listdir(self.dossier_resultats)
if not os.path.isdir(self.dossier_resultats + file)
]
def lecture_requetes(self):
"""Lecture des requêtes dans les fichiers de configuration"""
with open("requetes.json", encoding="utf-8") as reqs:
self.json_reqs = json.load(reqs)
with open("champs_generiques.json", encoding="utf-8") as champs_generiques:
self.json_champs_generiques = json.load(champs_generiques)
for req in self.json_reqs:
self.json_reqs[req]["champs"] = dict(self.json_reqs[req]["champ_local"])
for champ in self.json_reqs[req]["champs_generiques"]:
self.json_reqs[req]["champs"].update(self.json_champs_generiques[champ])
# nettoyage
self.json_reqs[req].pop("champ_local", None)
self.json_reqs[req].pop("champs_generiques", None)

17
rdoo.py
View File

@ -32,7 +32,6 @@ import argparse
import logging
import sys
from osm_vc63 import errors
from osm_vc63 import requetes
from osm_vc63.utils import Utils
OVERPASS_URL = "http://overpass-api.de/api/interpreter"
@ -131,14 +130,16 @@ def main():
# l'id de l'area se calcule en ajoutant 3600000000 au numéro de l'objet OSM
aire_de_recherche = str(3_600_000_000 + args.zone)
for req in requetes.REQS:
for req in utils.json_reqs:
for nb_essai in range(MAX_RETRY): # on tente max_retry fois
try:
logging.info(f"# Requête en cours : {req.nom}")
logging.info(f"# Requête en cours : {req}")
# appel overpass
data = utils.run_overpass_query(req.critere, aire_de_recherche)
data = utils.run_overpass_query(
utils.json_reqs[req]["overpass"], aire_de_recherche
)
nb_resultats = len(data["elements"])
logging.info(f"{nb_resultats} résultats")
@ -153,10 +154,12 @@ def main():
# Sauvegarde
os.makedirs(args.dossier_resultats, exist_ok=True)
export_json = utils.nettoyage_json_pour_umap(data, req.champs)
export_json = utils.nettoyage_json_pour_umap(
data, utils.json_reqs[req]["champs"]
)
utils.save_as_json(export_json, req.nom)
utils.save_as_ods(req.champs, data, req.nom)
utils.save_as_json(export_json, req)
utils.save_as_ods(utils.json_reqs[req]["champs"], data, req)
# doucement sur overpass
time.sleep(30)

96
requetes.json Normal file
View File

@ -0,0 +1,96 @@
{
"stationnements_velos_non_publics": {
"overpass": "nwr[\"amenity\"=\"bicycle_parking\"][\"access\"~\"(no|permit|private|customers|permissive)\"](area:aire_de_recherche);",
"champs_generiques": [
"CHAMPS_STATIONNEMENT",
"CHAMPS_ADRESSE"
],
"champ_local": ""
},
"stationnements_velos_publics": {
"overpass": "nwr[\"amenity\"=\"bicycle_parking\"](area:aire_de_recherche); - nwr[\"amenity\"=\"bicycle_parking\"][\"access\"~\"(no|permit|private|customers|permissive)\"](area:aire_de_recherche);",
"champs_generiques": [
"CHAMPS_STATIONNEMENT",
"CHAMPS_ADRESSE"
],
"champ_local": ""
},
"ateliers_autoreparation": {
"overpass": "nwr[\"service:bicycle:diy\"=\"yes\"](area:aire_de_recherche);",
"champs_generiques": [
"CHAMPS_POI",
"CHAMPS_ADRESSE"
],
"champ_local": {
"service:bicycle:diy": {
"export_json": "Non",
"FR": ""
}
}
},
"associations_velo": {
"overpass": "nwr[\"association\"=\"bicycle\"](area:aire_de_recherche);",
"champs_generiques": [
"CHAMPS_POI",
"CHAMPS_ADRESSE"
],
"champ_local": {
"association": {
"export_json": "Non",
"FR": ""
}
}
},
"fabriquants_velo": {
"overpass": "nwr[\"craft\"=\"bicycle\"](area:aire_de_recherche);",
"champs_generiques": [
"CHAMPS_POI",
"CHAMPS_ADRESSE"
],
"champ_local": {
"craft": {
"export_json": "Non",
"FR": ""
}
}
},
"vendeurs_velo": {
"overpass": "nwr[\"shop\"=\"bicycle\"](area:aire_de_recherche); nwr[\"service:bicycle:retail\"=\"yes\"](area:aire_de_recherche);",
"champs_generiques": [
"CHAMPS_POI",
"CHAMPS_ADRESSE"
],
"champ_local": {
"shop": {
"export_json": "Non",
"FR": ""
}
}
},
"velos_libre_service": {
"overpass": "nwr[\"amenity\"=\"bicycle_rental\"](area:aire_de_recherche);",
"champs_generiques": [
"CHAMPS_POI",
"CHAMPS_ADRESSE"
],
"champ_local": {
"amenity": {
"export_json": "Non",
"FR": ""
}
}
},
"location_velo": {
"overpass": "nwr[\"service:bicycle:rental\"=\"yes\"](area:aire_de_recherche);",
"champs_generiques": [
"CHAMPS_POI",
"CHAMPS_ADRESSE"
],
"champ_local": {
"service:bicycle:rental": {
"export_json": "Non",
"FR": ""
}
}
}
}