Skip to content

Commit

Permalink
Table rep_b_as_bis pour la normalisation (WIP #223)
Browse files Browse the repository at this point in the history
  • Loading branch information
vdct committed Feb 6, 2021
1 parent 0be5837 commit b74d768
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
7 changes: 7 additions & 0 deletions bano/bin.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ def main():
)
subparser.set_defaults(func=cadastre_gouv.process)

subparser = subparsers.add_parser(
"update_bis_table",
help="Identifie les indices de répétition b,t,q assimilables à bis, ter, quater",
description="Identifie les indices de répétition b,t,q assimilables à bis, ter, quater",
)
subparser.set_defaults(func=ban.update_bis_table)

subparser = subparsers.add_parser(
"pre_process_suffixe",
help="Détermine les zones où les noms dans le Cadastre sont suffixés",
Expand Down
9 changes: 9 additions & 0 deletions bano/db_helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import time
import os

from . import db

Expand All @@ -24,3 +25,11 @@ def age_etape_dept(etape,dept):
cur.execute(str_query)
c = cur.fetchone()
return round(time.mktime(time.localtime()),0) - c[0]

def process_sql(database,query_name,dict_args):
with open(os.path.join(os.path.dirname(os.path.abspath(__file__)),'sql/{:s}.sql'.format(query_name)),'r') as fq:
str_query = fq.read()
for k,v in dict_args.items():
str_query = str_query.replace(k,str(v))
with database.cursor() as cur :
cur.execute(str_query)
4 changes: 4 additions & 0 deletions bano/sources/ban.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from ..constants import DEPARTEMENTS
from .. import db
from .. import db_helpers as dbh
from .. import outils_de_gestion as m
from .. import update_manager as um

Expand Down Expand Up @@ -70,3 +71,6 @@ def get_destination(departement):
if not cwd.exists():
raise ValueError(f"Le répertoire {cwd} n'existe pas")
return cwd / f'adresses-{departement}.csv.gz'

def update_bis_table(**kwargs):
dbh.process_sql(db.bano_cache,'update_table_rep_b_as_bis',dict())
29 changes: 29 additions & 0 deletions bano/sql/update_table_rep_b_as_bis.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
DROP TABLE IF EXISTS rep_b_as_bis CASCADE;
CREATE TABLE rep_b_as_bis
AS
SELECT id_fantoir,
numero
FROM ban_odbl
WHERE rep = 'b'

EXCEPT

(SELECT id_fantoir,
numero
FROM ban_odbl
WHERE rep = 'a'

UNION

SELECT id_fantoir,
numero
FROM ban_odbl
WHERE rep = 'c'

UNION

SELECT id_fantoir,
numero
FROM ban_odbl
WHERE rep = 'd');
COMMIT;
3 changes: 3 additions & 0 deletions cron_bano.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ cat deplist.txt | parallel -j 4 export LANG=fr_FR.UTF-8\; bano download_bal BAL
cat deplist.txt | parallel -j 4 export LANG=fr_FR.UTF-8\; bano download_ban {1}
cat deplist.txt | parallel -j 4 export LANG=fr_FR.UTF-8\; bano download_cadastre lieux_dits {1}
bano update_code_cadastre
bano update_bis_table
./copy_table_from_osm_to_cadastre.sh rep_b_as_bis


# BANO
bano update_insee_lists
Expand Down

0 comments on commit b74d768

Please sign in to comment.