feat(commune): remove Paris, Marseille and Lyon top level insee code

This commit is contained in:
Paul Chavard 2023-07-25 12:43:13 +02:00
parent aed4791b3c
commit 2e61c16dfd
7 changed files with 39 additions and 9 deletions

View file

@ -79,7 +79,7 @@ class APIGeoService
private private
def communes_by_postal_code_map def communes_by_postal_code_map
Rails.cache.fetch('api_geo_communes_v2', expires_in: 1.week) do Rails.cache.fetch('api_geo_communes', expires_in: 1.day, version: 3) do
departements departements
.filter { _1[:code] != '99' } .filter { _1[:code] != '99' }
.flat_map { communes(_1[:code]) } .flat_map { communes(_1[:code]) }
@ -88,7 +88,7 @@ class APIGeoService
end end
def get_from_api_geo(scope) def get_from_api_geo(scope)
Rails.cache.fetch("api_geo_#{scope}_v2", expires_in: 1.week) do Rails.cache.fetch("api_geo_#{scope}", expires_in: 1.day, version: 3) do
JSON.parse(Rails.root.join('lib', 'data', 'api_geo', "#{scope}.json").read, symbolize_names: true) JSON.parse(Rails.root.join('lib', 'data', 'api_geo', "#{scope}.json").read, symbolize_names: true)
end end
end end

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1 +1 @@
[{"name":"Paris","code":"75056","epci_code":"200054781","departement_code":"75","postal_code":"75001"},{"name":"Paris","code":"75056","epci_code":"200054781","departement_code":"75","postal_code":"75002"},{"name":"Paris","code":"75056","epci_code":"200054781","departement_code":"75","postal_code":"75003"},{"name":"Paris","code":"75056","epci_code":"200054781","departement_code":"75","postal_code":"75004"},{"name":"Paris","code":"75056","epci_code":"200054781","departement_code":"75","postal_code":"75005"},{"name":"Paris","code":"75056","epci_code":"200054781","departement_code":"75","postal_code":"75006"},{"name":"Paris","code":"75056","epci_code":"200054781","departement_code":"75","postal_code":"75007"},{"name":"Paris","code":"75056","epci_code":"200054781","departement_code":"75","postal_code":"75008"},{"name":"Paris","code":"75056","epci_code":"200054781","departement_code":"75","postal_code":"75009"},{"name":"Paris","code":"75056","epci_code":"200054781","departement_code":"75","postal_code":"75010"},{"name":"Paris","code":"75056","epci_code":"200054781","departement_code":"75","postal_code":"75011"},{"name":"Paris","code":"75056","epci_code":"200054781","departement_code":"75","postal_code":"75012"},{"name":"Paris","code":"75056","epci_code":"200054781","departement_code":"75","postal_code":"75013"},{"name":"Paris","code":"75056","epci_code":"200054781","departement_code":"75","postal_code":"75014"},{"name":"Paris","code":"75056","epci_code":"200054781","departement_code":"75","postal_code":"75015"},{"name":"Paris","code":"75056","epci_code":"200054781","departement_code":"75","postal_code":"75016"},{"name":"Paris","code":"75056","epci_code":"200054781","departement_code":"75","postal_code":"75017"},{"name":"Paris","code":"75056","epci_code":"200054781","departement_code":"75","postal_code":"75018"},{"name":"Paris","code":"75056","epci_code":"200054781","departement_code":"75","postal_code":"75019"},{"name":"Paris","code":"75056","epci_code":"200054781","departement_code":"75","postal_code":"75020"},{"name":"Paris","code":"75056","epci_code":"200054781","departement_code":"75","postal_code":"75116"},{"name":"Paris 1er Arrondissement","code":"75101","departement_code":"75","postal_code":"75001"},{"name":"Paris 2e Arrondissement","code":"75102","departement_code":"75","postal_code":"75002"},{"name":"Paris 3e Arrondissement","code":"75103","departement_code":"75","postal_code":"75003"},{"name":"Paris 4e Arrondissement","code":"75104","departement_code":"75","postal_code":"75004"},{"name":"Paris 5e Arrondissement","code":"75105","departement_code":"75","postal_code":"75005"},{"name":"Paris 6e Arrondissement","code":"75106","departement_code":"75","postal_code":"75006"},{"name":"Paris 7e Arrondissement","code":"75107","departement_code":"75","postal_code":"75007"},{"name":"Paris 8e Arrondissement","code":"75108","departement_code":"75","postal_code":"75008"},{"name":"Paris 9e Arrondissement","code":"75109","departement_code":"75","postal_code":"75009"},{"name":"Paris 10e Arrondissement","code":"75110","departement_code":"75","postal_code":"75010"},{"name":"Paris 11e Arrondissement","code":"75111","departement_code":"75","postal_code":"75011"},{"name":"Paris 12e Arrondissement","code":"75112","departement_code":"75","postal_code":"75012"},{"name":"Paris 13e Arrondissement","code":"75113","departement_code":"75","postal_code":"75013"},{"name":"Paris 14e Arrondissement","code":"75114","departement_code":"75","postal_code":"75014"},{"name":"Paris 15e Arrondissement","code":"75115","departement_code":"75","postal_code":"75015"},{"name":"Paris 16e Arrondissement","code":"75116","departement_code":"75","postal_code":"75016"},{"name":"Paris 16e Arrondissement","code":"75116","departement_code":"75","postal_code":"75116"},{"name":"Paris 17e Arrondissement","code":"75117","departement_code":"75","postal_code":"75017"},{"name":"Paris 18e Arrondissement","code":"75118","departement_code":"75","postal_code":"75018"},{"name":"Paris 19e Arrondissement","code":"75119","departement_code":"75","postal_code":"75019"},{"name":"Paris 20e Arrondissement","code":"75120","departement_code":"75","postal_code":"75020"}] [{"name":"Paris 1er Arrondissement","code":"75101","departement_code":"75","postal_code":"75001"},{"name":"Paris 2e Arrondissement","code":"75102","departement_code":"75","postal_code":"75002"},{"name":"Paris 3e Arrondissement","code":"75103","departement_code":"75","postal_code":"75003"},{"name":"Paris 4e Arrondissement","code":"75104","departement_code":"75","postal_code":"75004"},{"name":"Paris 5e Arrondissement","code":"75105","departement_code":"75","postal_code":"75005"},{"name":"Paris 6e Arrondissement","code":"75106","departement_code":"75","postal_code":"75006"},{"name":"Paris 7e Arrondissement","code":"75107","departement_code":"75","postal_code":"75007"},{"name":"Paris 8e Arrondissement","code":"75108","departement_code":"75","postal_code":"75008"},{"name":"Paris 9e Arrondissement","code":"75109","departement_code":"75","postal_code":"75009"},{"name":"Paris 10e Arrondissement","code":"75110","departement_code":"75","postal_code":"75010"},{"name":"Paris 11e Arrondissement","code":"75111","departement_code":"75","postal_code":"75011"},{"name":"Paris 12e Arrondissement","code":"75112","departement_code":"75","postal_code":"75012"},{"name":"Paris 13e Arrondissement","code":"75113","departement_code":"75","postal_code":"75013"},{"name":"Paris 14e Arrondissement","code":"75114","departement_code":"75","postal_code":"75014"},{"name":"Paris 15e Arrondissement","code":"75115","departement_code":"75","postal_code":"75015"},{"name":"Paris 16e Arrondissement","code":"75116","departement_code":"75","postal_code":"75016"},{"name":"Paris 16e Arrondissement","code":"75116","departement_code":"75","postal_code":"75116"},{"name":"Paris 17e Arrondissement","code":"75117","departement_code":"75","postal_code":"75017"},{"name":"Paris 18e Arrondissement","code":"75118","departement_code":"75","postal_code":"75018"},{"name":"Paris 19e Arrondissement","code":"75119","departement_code":"75","postal_code":"75019"},{"name":"Paris 20e Arrondissement","code":"75120","departement_code":"75","postal_code":"75020"}]

View file

@ -21,7 +21,9 @@ namespace :api_geo_data do
data = [] data = []
PATH.join("#{filename}.json").open('w') do |f| PATH.join("#{filename}.json").open('w') do |f|
response = Typhoeus.get("#{API_GEO_URL}/#{query}") response = Typhoeus.get("#{API_GEO_URL}/#{query}")
json = JSON.parse(response.body).map(&:symbolize_keys).flat_map do |result| json = JSON.parse(response.body).map(&:symbolize_keys).filter do |result|
!result[:code].in?(['75056', '13055', '69123'])
end.flat_map do |result|
item = { item = {
name: result[:nom].tr("'", ''), name: result[:nom].tr("'", ''),
code: result[:code], code: result[:code],

View file

@ -0,0 +1,28 @@
namespace :after_party do
desc 'Deployment task: remove_toplevel_communes'
task remove_toplevel_communes: :environment do
puts "Running deploy task 'remove_toplevel_communes'"
communes = Champs::CommuneChamp.where(external_id: ['75056', '13055', '69123'])
progress = ProgressReport.new(communes.count)
communes.find_each do |commune|
external_id = case commune.external_id
when '75056'
'75101'
when '13055'
'13201'
when '69123'
'69381'
end
commune.update_columns(external_id:, value: APIGeoService.commune_name(commune.code_departement, external_id))
progress.inc
end
progress.finish
# Update task as completed. If you remove the line below, the task will
# run with every deploy (or every time you call after_party:run).
AfterParty::TaskRecord
.create version: AfterParty::TaskRecorder.new(__FILE__).timestamp
end
end

View file

@ -47,9 +47,9 @@ describe APIGeoService do
describe 'communes_by_postal_code' do describe 'communes_by_postal_code' do
it 'return results' do it 'return results' do
expect(APIGeoService.communes_by_postal_code('01500').size).to eq(8) expect(APIGeoService.communes_by_postal_code('01500').size).to eq(8)
expect(APIGeoService.communes_by_postal_code('75019').size).to eq(2) expect(APIGeoService.communes_by_postal_code('75019').size).to eq(1)
expect(APIGeoService.communes_by_postal_code('69005').size).to eq(2) expect(APIGeoService.communes_by_postal_code('69005').size).to eq(1)
expect(APIGeoService.communes_by_postal_code('13006').size).to eq(2) expect(APIGeoService.communes_by_postal_code('13006').size).to eq(1)
expect(APIGeoService.communes_by_postal_code('73480').size).to eq(3) expect(APIGeoService.communes_by_postal_code('73480').size).to eq(3)
expect(APIGeoService.communes_by_postal_code('20000').first[:code]).to eq('2A004') expect(APIGeoService.communes_by_postal_code('20000').first[:code]).to eq('2A004')
expect(APIGeoService.communes_by_postal_code('37160').size).to eq(7) expect(APIGeoService.communes_by_postal_code('37160').size).to eq(7)