Merge commit '366928e'

This commit is contained in:
gregoirenovel 2018-10-16 10:57:08 +02:00
commit d3a58f2fce
20 changed files with 81 additions and 17239 deletions

View file

@ -275,28 +275,34 @@ class StatsController < ApplicationController
processed_dossiers = dossiers
.where(:processed_at => min_date..max_date)
.pluck(:procedure_id, :created_at, :en_construction_at, :processed_at)
.pluck(
:procedure_id,
Arel.sql('EXTRACT(EPOCH FROM (en_construction_at - created_at)) / 60 AS processing_time'),
:processed_at
)
# Group dossiers by month
processed_dossiers_by_month = processed_dossiers
.group_by do |e|
e[3].beginning_of_month.to_s
.group_by do |(*_, processed_at)|
processed_at.beginning_of_month.to_s
end
processed_dossiers_by_month.map do |month, value|
procedure_id_type_de_champs_count = TypeDeChamp
.where(private: false)
.group(:procedure_id)
.count
processed_dossiers_by_month.map do |month, dossier_plucks|
# Group the dossiers for this month by procedure
dossiers_grouped_by_procedure = value.group_by { |dossier| dossier[0] }
dossiers_grouped_by_procedure = dossier_plucks.group_by { |(procedure_id, *_)| procedure_id }
# Compute the mean time for this procedure
procedure_processing_times = dossiers_grouped_by_procedure.map do |procedure_id, procedure_dossiers|
procedure_dossiers_processing_time = procedure_dossiers.map do |dossier|
(dossier[2] - dossier[1]).to_f / 60
end
procedure_dossiers_processing_time = procedure_dossiers.map { |_, processing_time, _| processing_time }
procedure_mean = mean(procedure_dossiers_processing_time)
# We normalize the data for 24 fields
procedure_fields_count = Procedure.find(procedure_id).types_de_champ.count
procedure_fields_count = procedure_id_type_de_champs_count[procedure_id]
procedure_mean * (MEAN_NUMBER_OF_CHAMPS_IN_A_FORM / procedure_fields_count)
end

View file

@ -19,8 +19,8 @@ class Users::CarteController < UsersController
dossier.cadastres.each(&:destroy)
if geo_json.present?
ModuleApiCartoService.save_qp! dossier, geo_json
ModuleApiCartoService.save_cadastre! dossier, geo_json
ModuleApiCartoService.save_qp!(dossier, geo_json)
ModuleApiCartoService.save_cadastre!(dossier, geo_json)
end
dossier.update!(json_latlngs: geo_json)
@ -38,7 +38,7 @@ class Users::CarteController < UsersController
@error = true
else
if @dossier.procedure.module_api_carto.quartiers_prioritaires?
quartiers_prioritaires = ModuleApiCartoService.generate_qp(geo_json).values
quartiers_prioritaires = ModuleApiCartoService.generate_qp(geo_json)
@dossier.quartier_prioritaires.build(quartiers_prioritaires)
@data[:quartiersPrioritaires] = quartiers_prioritaires
end

View file

@ -4,23 +4,22 @@ class CARTO::SGMAP::API
def self.search_qp(geojson)
url = [API_CARTO_URL, "quartiers-prioritaires", "search"].join("/")
call(url, { geojson: geojson.to_s })
call(url, geojson)
end
def self.search_cadastre(geojson)
url = [API_CARTO_URL, "cadastre", "geometrie"].join("/")
call(url, { geojson: geojson.to_s })
call(url, geojson)
end
private
def self.call(url, params = {})
def self.call(url, geojson)
verify_ssl_mode = OpenSSL::SSL::VERIFY_NONE
params = geojson.to_s
RestClient::Resource.new(
url,
verify_ssl: verify_ssl_mode
).post params[:geojson], content_type: 'application/json'
client = RestClient::Resource.new(url, verify_ssl: verify_ssl_mode)
client.post(params, content_type: 'application/json')
rescue RestClient::InternalServerError
raise RestClient::ResourceNotFound

View file

@ -7,26 +7,23 @@ class CARTO::SGMAP::Cadastre::Adapter
@data_source ||= JSON.parse(CARTO::SGMAP::API.search_cadastre(@coordinates), symbolize_names: true)
end
def to_params
def results
data_source[:features].map do |feature|
tmp = filter_properties feature[:properties]
tmp[:geometry] = feature[:geometry]
tmp
filter_properties(feature[:properties]).merge({ geometry: feature[:geometry] })
end
end
def filter_properties(properties)
{
surface_intersection: properties[:surface_intersection],
surface_parcelle: properties[:surface_parcelle],
numero: properties[:numero],
feuille: properties[:feuille],
section: properties[:section],
code_dep: properties[:code_dep],
nom_com: properties[:nom_com],
code_com: properties[:code_com],
code_arr: properties[:code_arr]
}
properties.slice(
:surface_intersection,
:surface_parcelle,
:numero,
:feuille,
:section,
:code_dep,
:nom_com,
:code_com,
:code_arr
)
end
end

View file

@ -7,16 +7,9 @@ class CARTO::SGMAP::QuartiersPrioritaires::Adapter
@data_source ||= JSON.parse(CARTO::SGMAP::API.search_qp(@coordinates), symbolize_names: true)
end
def to_params
params = {}
data_source[:features].each do |feature|
qp_code = feature[:properties][:code]
params[qp_code] = feature[:properties]
params[qp_code][:geometry] = feature[:geometry]
def results
data_source[:features].map do |feature|
feature[:properties].merge({ geometry: feature[:geometry] })
end
params
end
end

View file

@ -4,18 +4,4 @@ class ModuleAPICarto < ApplicationRecord
validates :use_api_carto, presence: true, allow_blank: true, allow_nil: false
validates :quartiers_prioritaires, presence: true, allow_blank: true, allow_nil: false
validates :cadastre, presence: true, allow_blank: true, allow_nil: false
def classes
modules = ''
if quartiers_prioritaires?
modules += 'qp '
end
if cadastre?
modules += 'cadastre '
end
modules
end
end

View file

@ -1,9 +1,9 @@
class ModuleApiCartoService
def self.save_qp!(dossier, json_latlngs)
if dossier.procedure.module_api_carto.quartiers_prioritaires?
qp_list = generate_qp JSON.parse(json_latlngs)
qp_list = generate_qp(JSON.parse(json_latlngs))
qp_list.each_value do |qp|
qp_list.each do |qp|
qp[:dossier_id] = dossier.id
qp[:geometry] = qp[:geometry].to_json
QuartierPrioritaire.create(qp)
@ -24,18 +24,18 @@ class ModuleApiCartoService
end
def self.generate_qp(coordinates)
coordinates.inject({}) { |acc, coordinate|
acc.merge CARTO::SGMAP::QuartiersPrioritaires::Adapter.new(
coordinates.flat_map do |coordinate|
CARTO::SGMAP::QuartiersPrioritaires::Adapter.new(
coordinate.map { |element| [element['lng'], element['lat']] }
).to_params
}
).results
end
end
def self.generate_cadastre(coordinates)
coordinates.flat_map do |coordinate|
CARTO::SGMAP::Cadastre::Adapter.new(
coordinate.map { |element| [element['lng'], element['lat']] }
).to_params
).results
end
end
end

View file

@ -1,19 +1,25 @@
- if dossier.procedure.module_api_carto.quartiers_prioritaires?
.col-md-9.col-lg-9#qp.col-md-3.col-lg-3.list
%h3.text-info Quartiers prioritaires
%ul
- dossier.quartier_prioritaires.each do |qp|
%li #{qp.commune} : #{qp.nom}
- if dossier.quartier_prioritaires.blank?
Aucun quartier prioritaire sur les zones séléctionnées
- else
%ul
- dossier.quartier_prioritaires.each do |qp|
%li #{qp.commune} : #{qp.nom}
- if error.present?
%b Merci de dessiner une surface plus petite afin de récupérer les quartiers prioritaires.
- if error.present?
%b Merci de dessiner une surface plus petite afin de récupérer les quartiers prioritaires.
- if dossier.procedure.module_api_carto.cadastre?
.col-md-9.col-lg-9#cadastre.col-md-3.col-lg-3.list
%h3.text-warning Parcelles cadastrales
%ul
- dossier.cadastres.each do |cadastre|
%li Parcelle nº #{cadastre.numero} - Feuille #{cadastre.code_arr} #{cadastre.section} #{cadastre.feuille}
- if dossier.cadastres.blank?
Aucune parcelle cadastrale sur les zones séléctionnées
- else
%ul
- dossier.cadastres.each do |cadastre|
%li Parcelle nº #{cadastre.numero} - Feuille #{cadastre.code_arr} #{cadastre.section} #{cadastre.feuille}
- if error.present?
%b Merci de dessiner une surface plus petite afin de récupérer les parcelles cadastrales.
- if error.present?
%b Merci de dessiner une surface plus petite afin de récupérer les parcelles cadastrales.

View file

@ -114,8 +114,8 @@ shared_examples 'carte_controller_spec' do
before do
allow_any_instance_of(CARTO::SGMAP::QuartiersPrioritaires::Adapter)
.to receive(:to_params)
.and_return({ "QPCODE1234" => { :code => "QPCODE1234", :nom => "QP de test", :commune => "Paris", :geometry => { :type => "MultiPolygon", :coordinates => [[[[2.38715792094576, 48.8723062632126], [2.38724851642619, 48.8721392348061]]]] } } })
.to receive(:results)
.and_return([{ :code => "QPCODE1234", :nom => "QP de test", :commune => "Paris", :geometry => { :type => "MultiPolygon", :coordinates => [[[[2.38715792094576, 48.8723062632126], [2.38724851642619, 48.8721392348061]]]] } }])
post :save, params: { dossier_id: dossier.id, selection: json_latlngs }
end
@ -161,7 +161,7 @@ shared_examples 'carte_controller_spec' do
before do
allow_any_instance_of(CARTO::SGMAP::Cadastre::Adapter)
.to receive(:to_params)
.to receive(:results)
.and_return([{ :surface_intersection => "0.0006", :surface_parcelle => 11252.692583090324, :numero => "0013", :feuille => 1, :section => "CD", :code_dep => "30", :nom_com => "Le Grau-du-Roi", :code_com => "133", :code_arr => "000", :geometry => { :type => "MultiPolygon", :coordinates => [[[[4.134084, 43.5209193], [4.1346615, 43.5212035], [4.1346984, 43.521189], [4.135096, 43.5213848], [4.1350839, 43.5214122], [4.1352697, 43.521505], [4.1356278, 43.5211065], [4.1357402, 43.5207188], [4.1350935, 43.5203936], [4.135002, 43.5204366], [4.1346051, 43.5202412], [4.134584, 43.5202472], [4.1345572, 43.5202551], [4.134356, 43.5203137], [4.1342488, 43.5203448], [4.134084, 43.5209193]]]] } }])
post :save, params: { dossier_id: dossier.id, selection: json_latlngs }
@ -216,8 +216,8 @@ shared_examples 'carte_controller_spec' do
before do
allow_any_instance_of(CARTO::SGMAP::QuartiersPrioritaires::Adapter)
.to receive(:to_params)
.and_return({ "QPCODE1234" => { :code => "QPCODE1234", :geometry => { :type => "MultiPolygon", :coordinates => [[[[2.38715792094576, 48.8723062632126], [2.38724851642619, 48.8721392348061]]]] } } })
.to receive(:results)
.and_return([{ :code => "QPCODE1234", :geometry => { :type => "MultiPolygon", :coordinates => [[[[2.38715792094576, 48.8723062632126], [2.38724851642619, 48.8721392348061]]]] } }])
post :zones, params: { dossier_id: dossier.id, selection: json_latlngs.to_json }, format: 'js'
end

File diff suppressed because it is too large Load diff

View file

@ -1,93 +0,0 @@
---
http_interactions:
- request:
method: get
uri: https://api.github.com/repos/betagouv/tps/releases/latest
body:
encoding: US-ASCII
string: ''
headers:
Accept:
- "*/*"
Accept-Encoding:
- gzip, deflate
User-Agent:
- rest-client/2.0.0 (darwin15.6.0 x86_64) ruby/2.3.1p112
response:
status:
code: 200
message: OK
headers:
Server:
- GitHub.com
Date:
- Thu, 15 Dec 2016 15:48:21 GMT
Content-Type:
- application/json; charset=utf-8
Transfer-Encoding:
- chunked
Status:
- 200 OK
X-Ratelimit-Limit:
- '60'
X-Ratelimit-Remaining:
- '46'
X-Ratelimit-Reset:
- '1481819650'
Cache-Control:
- public, max-age=60, s-maxage=60
Vary:
- Accept
- Accept-Encoding
Etag:
- W/"104562bed37a43b27f0e4ba70c1d2cff"
Last-Modified:
- Thu, 17 Nov 2016 10:56:47 GMT
X-Github-Media-Type:
- github.v3
Access-Control-Expose-Headers:
- ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset,
X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval
Access-Control-Allow-Origin:
- "*"
Content-Security-Policy:
- default-src 'none'
Strict-Transport-Security:
- max-age=31536000; includeSubdomains; preload
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- deny
X-Xss-Protection:
- 1; mode=block
X-Served-By:
- 46808ddc41c302090177e58148908b23
Content-Encoding:
- gzip
X-Github-Request-Id:
- B918B84A:73B5:C61DB9:5852BB44
body:
encoding: ASCII-8BIT
string: !binary |-
H4sIAAAAAAAAA6VVy27bMBD8FUKXXBzTap4V0hZFeikQNIe0RdEHDFqiZQaU
yHJJt6mRf+nV3+Ef65BSnMTIA0ZPssTd4ezs7niRBaezIpt5b6ngXFg1rJWf
hcmwNA130hriVDfCcgTgXUtBkvj+4fHBwdFeNsgEkfQ0/i8Y3oEALVhtRLWB
1n2kbYj1iIs3rWjkQIuJ1NeAn/lGb4DfqfaBOr2o+TwfHg9jqarKir7wQYaT
cQSHeOsAL1wt/RjKNcormuGsEeSlQ3Ife4oz2XqhnCRmhWPlTDSWmPRMNKul
VsYJr0zLKsn0jvxtjfPxd2WIlHQ0BFTlxNRnxVRokmhA8DPjsmKRaVOrFnd+
uQz6fd4TzvdG+f7LwxEC5wIENzuVPt5oG0i60rQeDFP/A79JfzN/FSWoXY8S
tchiw54anwhHfE3nafXXYVOjtfmFzE2q92fzLjhf54BS91u19db5yFlw42cS
KoF6nJha0XPTfY9Iil/w+BirKiIQ9HVyc6Y3Fu0eRp8BKr9asFikNUxQYUKl
UzYOyDbq3MsDjnG1aNWfNGjb4CCPkJ5cYQtxUzzy5BxztU1il7Dg1qm5KK+i
BE6WUs0h59ZgG5nA8lc2ru8ntDqKq7wci6qJK5RW63qQWSd7y1uvW+mk8Lhf
YAOzF6P8cDfPd/Ojj/mo2DsuXoy+AsqGicb6Pxx1cFjsH8Wo3vSKbz+im7iJ
0Jve9Iwb90m3BvVH2e1R+qRblImprlDbyWzv9QcT5hIGs1rSCcf7d/e9PQm6
e2qVnp9aNtXhdzSpaHy9uTFJnjVCRS8RLcyNyJRqtWSrv9HyfgZEd85X7QS4
XWdvTExVsj6Li41yrFJUBhgoI7talmqqkBivYCBlAs5jMoVL6YeJG+9JnfCe
ZfoK5m/vmuvjxZzdWi6tPTeycUzDsEWJEq2oW4xAcHhnqyXEWVv3ajlk5y2z
MsC0IZpxkADm3tm4bNnpxecB+3J2Ef3+/N3FkL1DrTrQ4K5WqIy667x3ahI8
qCS5omo3ShFsugfGRc9Uf2pgQWVa90f7eBvTqToJNRraltKlBsbyUYwGlx3I
EAhlg5VDW2QyJPYzKNZKRjtiOlVgqzz+4AgY6e7UtgdoZtf/AIfUb6aECAAA
http_version:
recorded_at: Thu, 15 Dec 2016 15:48:21 GMT
recorded_with: VCR 3.0.3

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,7 +1,7 @@
require 'spec_helper'
describe CARTO::SGMAP::Cadastre::Adapter do
subject { described_class.new(coordinates).to_params }
subject { described_class.new(coordinates).results }
before do
stub_request(:post, "https://apicarto.sgmap.fr/cadastre/geometrie")
@ -16,15 +16,15 @@ describe CARTO::SGMAP::Cadastre::Adapter do
let(:body) { File.read('spec/support/files/geojson/response_cadastre.json') }
it { expect(subject).to be_a_instance_of(Array) }
it { expect(subject.size).to eq 16 }
it { expect(subject.size).to eq(16) }
describe 'Attribut filter' do
let(:adapter) { described_class.new(coordinates) }
subject { adapter.filter_properties adapter.data_source }
subject { adapter.filter_properties(adapter.data_source[:features].first[:properties]) }
it { expect(subject.size).to eq 9 }
it { expect(subject.size).to eq(9) }
it do
expect(subject.keys).to eq [
expect(subject.keys).to eq([
:surface_intersection,
:surface_parcelle,
:numero,
@ -34,7 +34,7 @@ describe CARTO::SGMAP::Cadastre::Adapter do
:nom_com,
:code_com,
:code_arr
]
])
end
end

View file

@ -1,7 +1,7 @@
require 'spec_helper'
describe CARTO::SGMAP::QuartiersPrioritaires::Adapter do
subject { described_class.new(coordinates).to_params }
subject { described_class.new(coordinates).results }
before do
stub_request(:post, "https://apicarto.sgmap.fr/quartiers-prioritaires/search")
@ -15,18 +15,16 @@ describe CARTO::SGMAP::QuartiersPrioritaires::Adapter do
let(:status) { 200 }
let(:body) { File.read('spec/support/files/geojson/response_qp.json') }
it { expect(subject).to be_a_instance_of(Hash) }
it { expect(subject).to be_a_instance_of(Array) }
context 'Attributes' do
let(:qp_code) { 'QP057019' }
subject { super()[qp_code] }
it { expect(subject.first[:code]).to eq(qp_code) }
it { expect(subject.first[:nom]).to eq('Hauts De Vallières') }
it { expect(subject.first[:commune]).to eq('Metz') }
it { expect(subject[:code]).to eq(qp_code) }
it { expect(subject[:nom]).to eq('Hauts De Vallières') }
it { expect(subject[:commune]).to eq('Metz') }
it { expect(subject[:geometry]).to eq({ :type => "MultiPolygon", :coordinates => [[[[6.2136923480551, 49.1342109827851], [6.21416055031881, 49.1338823553928]]]] }) }
it { expect(subject.first[:geometry]).to eq({ :type => "MultiPolygon", :coordinates => [[[[6.2136923480551, 49.1342109827851], [6.21416055031881, 49.1338823553928]]]] }) }
end
end

View file

@ -10,44 +10,4 @@ describe ModuleAPICarto do
it { is_expected.to have_db_column(:quartiers_prioritaires) }
it { is_expected.to have_db_column(:cadastre) }
end
describe '#classes' do
let(:module_api_carto) { create(:module_api_carto, quartiers_prioritaires: qp, cadastre: cadastre) }
context 'when module api carto qp is true' do
let(:qp) { true }
let(:cadastre) { false }
subject { module_api_carto.classes }
it { is_expected.to eq 'qp ' }
end
context 'when module api carto cadastre is true' do
let(:qp) { false }
let(:cadastre) { true }
subject { module_api_carto.classes }
it { is_expected.to eq 'cadastre ' }
end
context 'when module api carto qp is true and cadastre is true' do
let(:qp) { true }
let(:cadastre) { true }
subject { module_api_carto.classes }
it { is_expected.to eq 'qp cadastre ' }
end
context 'when module api carto qp is false and cadastre is false' do
let(:qp) { false }
let(:cadastre) { false }
subject { module_api_carto.classes }
it { is_expected.to eq '' }
end
end
end