Skip to content

Commit

Permalink
Normalisation des indices de repetition BAN - bis ter quater (WIP #223)
Browse files Browse the repository at this point in the history
  • Loading branch information
vdct committed Feb 7, 2021
1 parent b74d768 commit fe6f6d1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 11 deletions.
21 changes: 10 additions & 11 deletions bano/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,16 @@ def has_addreses_with_suffix(insee):

def load_ban_hsnr(code_insee):
dict_node_relations = {}
with db.bano_cache.cursor() as cur:
cur.execute(f"SELECT id,TRIM (BOTH FROM (numero||' '||COALESCE(rep,''))), nom_voie, lon, lat FROM ban_odbl WHERE code_insee = '{code_insee}';")
for id, housenumber, name, lon, lat in cur:
if not name or len(name) < 2 or not lon:
continue
adresses.register(name)
if not id in dict_node_relations:
dict_node_relations[id] = []
dict_node_relations[id].append(hp.normalize(name))
if hp.is_valid_housenumber(housenumber):
adresses.add_adresse(Adresse(Node({'id':id,'lon':lon,'lat':lat},{}),housenumber,name,'',''), 'BAN')
data = get_data_from_pg_direct('ban_hsnr',code_insee)
for id, housenumber, name, lon, lat in data:
if not name or len(name) < 2 or not lon:
continue
adresses.register(name)
if not id in dict_node_relations:
dict_node_relations[id] = []
dict_node_relations[id].append(hp.normalize(name))
if hp.is_valid_housenumber(housenumber):
adresses.add_adresse(Adresse(Node({'id':id,'lon':lon,'lat':lat},{}),housenumber,name,'',''), 'BAN')

def load_bases_adresses_locales_hsnr(code_insee):
dict_node_relations = {}
Expand Down
30 changes: 30 additions & 0 deletions bano/sql/ban_hsnr_nocache.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
WITH
j
AS
(SELECT id,
numero,
nom_voie,
lon,
lat,
rep,
CASE r.numero
WHEN b.numero THEN
CASE
WHEN rep = 'b' THEN 'bis'
WHEN rep = 't' THEN 'ter'
WHEN rep = 'q' THEN 'quater'
ELSE NULL
END
ELSE NULL
END as rep_bis
FROM ban_odbl b
LEFT OUTER JOIN rep_b_as_bis r
USING (id_fantoir,numero)
WHERE code_insee = '__com__')

SELECT id,
TRIM (BOTH FROM (numero||' '||COALESCE(rep_bis,rep,''))),
nom_voie,
lon,
lat
FROM j;

0 comments on commit fe6f6d1

Please sign in to comment.