Skip to content

Commit

Permalink
feat: projections légales pour le calcul de surface
Browse files Browse the repository at this point in the history
Signed-off-by: Maud Royer <hello@maudroyer.fr>
  • Loading branch information
jillro committed Apr 23, 2024
1 parent a9420ae commit ec59177
Show file tree
Hide file tree
Showing 27 changed files with 401 additions and 151 deletions.
230 changes: 210 additions & 20 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"@algolia/autocomplete-theme-classic": "^1.8.3",
"@gouvfr/dsfr": "1.11.2",
"@sentry/vue": "^7.50.0",
"@turf/area": "^6.5.0",
"@turf/bbox": "^6.5.0",
"@turf/bbox-polygon": "^6.5.0",
"@turf/centroid": "^6.5.0",
"@turf/difference": "^6.5.0",
"@turf/helpers": "^6.5.0",
Expand All @@ -36,8 +36,11 @@
"@vueuse/core": "^9.6.0",
"axios": "^1.4.0",
"fuse.js": "^6.6.2",
"geometric": "^2.5.4",
"maplibre-gl": "^3.0.0",
"pinia": "^2.0.26",
"proj4": "^2.11.0",
"reproject": "^1.2.7",
"terra-draw": "^0.0.1-alpha.49",
"vue": "^3.3.11",
"vue-matomo": "^4.1.0",
Expand All @@ -46,7 +49,7 @@
"xlsx": "^0.18.5"
},
"devDependencies": {
"@agencebio/cartobio-types": "^1.4.0",
"@agencebio/cartobio-types": "^1.6.1",
"@pinia/testing": "^0.1.3",
"@testing-library/vue": "^8.0.1",
"@vitejs/plugin-legacy": "^5.2.0",
Expand Down
4 changes: 2 additions & 2 deletions src/components/Features/AddFlow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
@delete="cadastreParcelles.splice(index, 1)"
/>
<span v-if="cadastreParcelles[index].feature" class="fr-hint-text fr-message--valid">
Parcelle cadastrale sélectionnée ({{ inHa(surface(cadastreParcelles[index].feature)) }} ha)
Parcelle cadastrale sélectionnée ({{ inHa(legalProjectionSurface(cadastreParcelles[index].feature)) }} ha)
</span>
</div>
</div>
Expand Down Expand Up @@ -80,7 +80,7 @@ import { computed, markRaw, reactive, ref, toRaw, watch } from 'vue'
import CadastreField from '@/components/Forms/CadastreField.vue'
import { submitNewParcelle } from '@/cartobio-api.js';
import { featureCollection } from '@turf/helpers'
import { diff, featureName, inHa, merge, surface } from './index.js'
import { diff, featureName, inHa, legalProjectionSurface, merge } from './index.js'
import CommuneSelect from "@/components/Forms/CommuneSelect.vue";
import { useRouter } from "vue-router";
import { useFeaturesStore, useOperatorStore, useRecordStore } from "@/stores/index.js"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('BureauVeritasExporter', () => {
"",
"",
"Ilots : 4.1",
1.0464881572673355,
0.753054443359375,
"ha",
"",
"",
Expand All @@ -49,7 +49,7 @@ describe('BureauVeritasExporter', () => {
"",
"",
"Ilots : 3.1",
1.0464881572673355,
0.753054443359375,
"ha",
"",
"",
Expand All @@ -61,7 +61,7 @@ describe('BureauVeritasExporter', () => {
"1125",
"",
"Ilots : 1.1 (nom personnalisé) ; 1.2",
2.092976314534671,
1.50610888671875,
"ha",
"C1",
"2023-01-01",
Expand All @@ -73,7 +73,7 @@ describe('BureauVeritasExporter', () => {
"1125",
"",
"Ilots : 2.1, 0.70ha",
1.0464881572673355,
0.753054443359375,
"ha",
"AB",
"2021-01-01",
Expand All @@ -85,7 +85,7 @@ describe('BureauVeritasExporter', () => {
"1124",
"4 feuilles",
"Ilots : 2.1, 4 feuilles, semis le 01/03/2023, 0.30ha",
1.0464881572673355,
0.753054443359375,
"ha",
"AB",
"2021-01-01",
Expand All @@ -97,7 +97,7 @@ describe('BureauVeritasExporter', () => {
"1124",
"4 feuilles",
"Ilots : 2.2, 4 feuilles, semis le 01/03/2023",
1.0464881572673355,
0.753054443359375,
"ha",
"AB",
"2015-01-01",
Expand Down
20 changes: 14 additions & 6 deletions src/components/Features/ExportStrategies/CertipaqExporter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { utils, write } from 'xlsx'
import { fromCodeCpf } from '@agencebio/rosetta-cultures'
import { cultureLabel, featureName, getFeatureGroups, GROUPE_CULTURE, GROUPE_NIVEAU_CONVERSION, surface } from '@/components/Features/index.js'
import {
cultureLabel,
featureName,
getFeatureGroups,
GROUPE_CULTURE,
GROUPE_NIVEAU_CONVERSION,
legalProjectionSurface
} from '@/components/Features/index.js'

import BaseExporter, { generateAutresInfos } from "@/components/Features/ExportStrategies/BaseExporter.js";

Expand Down Expand Up @@ -73,8 +80,9 @@ function getSheet () {
placeholder: ''
}

sheet_add_aoa(sheet, this.getSortedFeatures().map(({ geometry, properties: props, id }) => {
const surfaceHa = (surface(geometry) / 10_000).toLocaleString('fr-FR', { maximumFractionDigits: 2 })
sheet_add_aoa(sheet, this.getSortedFeatures().map((feature) => {
const { geometry, properties: props, id } = feature
const surfaceHa = (legalProjectionSurface(feature) / 10_000).toLocaleString('fr-FR', { maximumFractionDigits: 2 })
const culture = props.cultures?.at(0) ? fromCodeCpf(props.cultures?.at(0).CPF) : { libelle_code_cpf: '[ERREUR] culture absente' }

return [
Expand Down Expand Up @@ -125,7 +133,7 @@ function getSheet () {
// Totaux par niveau de conversion
const groups = Object.fromEntries(
getFeatureGroups(featureCollection, GROUPE_NIVEAU_CONVERSION)
.map(({ key, features }) => ([key, surface({ type: 'FeatureCollection', features }) / 10_000]))
.map(({ key, features }) => ([key, legalProjectionSurface(features) / 10_000]))
)

sheet_add_aoa(sheet, [
Expand All @@ -137,7 +145,7 @@ function getSheet () {
groups.C2?.toLocaleString('fr-FR', { maximumFractionDigits: 2 }) ?? 0,
groups.C3?.toLocaleString('fr-FR', { maximumFractionDigits: 2 }) ?? 0,
groups.CONV?.toLocaleString('fr-FR', { maximumFractionDigits: 2 }) ?? 0,
(surface(featureCollection) / 10_000)?.toLocaleString('fr-FR', { maximumFractionDigits: 2 })
(legalProjectionSurface(featureCollection) / 10_000)?.toLocaleString('fr-FR', { maximumFractionDigits: 2 })
],
], { origin: 'S4'});

Expand All @@ -151,7 +159,7 @@ function getSheet () {
const culture = fromCodeCpf(key)
const groups = Object.fromEntries(
getFeatureGroups({ type: 'FeatureCollection', features }, GROUPE_NIVEAU_CONVERSION)
.map(({ key, features }) => ([key, surface({ type: 'FeatureCollection', features }) / 10_000]))
.map(({ key, features }) => ([key, legalProjectionSurface(features) / 10_000]))
)

sheet_add_aoa(sheet, [[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('CertipaqExporter', () => {
'nom personnalisé',
'',
'',
'1,05',
'0,75',
'',
'',
new Date('2023-01-01T00:00:00.000Z'),
Expand All @@ -63,7 +63,7 @@ describe('CertipaqExporter', () => {
'',
'',
'',
'1,05',
'0,75',
'',
'',
new Date('2023-01-01T00:00:00.000Z'),
Expand All @@ -81,7 +81,7 @@ describe('CertipaqExporter', () => {
'Luzerne',
'Trèfle, 4 feuilles',
'',
'1,05',
'0,75',
'',
'',
'',
Expand All @@ -100,7 +100,7 @@ describe('CertipaqExporter', () => {
'Trèfle',
'4 feuilles',
'',
'1,05',
'0,75',
'',
'',
'',
Expand Down
15 changes: 10 additions & 5 deletions src/components/Features/ExportStrategies/CertisExporter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { utils, write } from 'xlsx'
import { fromCodeCpf } from '@agencebio/rosetta-cultures'
import { GROUPE_NIVEAU_CONVERSION, getFeatureGroups, surface } from '@/components/Features/index.js'
import {
GROUPE_NIVEAU_CONVERSION,
getFeatureGroups,
legalProjectionSurface
} from '@/components/Features/index.js'

import BaseExporter, { generateAutresInfos } from "@/components/Features/ExportStrategies/BaseExporter.js";

Expand Down Expand Up @@ -78,8 +82,9 @@ function getSheet () {
{ wch: 16 },
]

sheet_add_aoa(sheet, this.getSortedFeatures().map(({ geometry, properties }) => {
const surfaceHa = surface(geometry) / 10_000
sheet_add_aoa(sheet, this.getSortedFeatures().map((feature) => {
const { properties } = feature
const surfaceHa = legalProjectionSurface(feature) / 10_000
const culture = properties.cultures.at(0) ? fromCodeCpf(properties.cultures.at(0)?.CPF) : { libelle_code_cpf: '[ERREUR] culture absente' }

return [
Expand Down Expand Up @@ -159,10 +164,10 @@ function getSheet () {
// totals
const groups = Object.fromEntries(
getFeatureGroups(featureCollection, GROUPE_NIVEAU_CONVERSION)
.map(({ key, features }) => ([key, surface({ type: 'FeatureCollection', features }) / 10_000]))
.map(({ key, features }) => ([key, legalProjectionSurface(features) / 10_000]))
)

const totalSurface = (surface(featureCollection) / 10_000)?.toLocaleString('fr-FR', { maximumFractionDigits: 2 })
const totalSurface = (legalProjectionSurface(featureCollection) / 10_000)?.toLocaleString('fr-FR', { maximumFractionDigits: 2 })
sheet_add_aoa(sheet, [
['Total C1', groups.CONV?.toLocaleString('fr-FR', { maximumFractionDigits: 2 }) ?? '0,00', `Total : ${totalSurface} ha`],
['Total C2', groups.AB?.toLocaleString('fr-FR', { maximumFractionDigits: 2 }) ?? '0,00'],
Expand Down
12 changes: 6 additions & 6 deletions src/components/Features/ExportStrategies/CertisExporter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('CertisExporter', () => {
'nom personnalisé',
'1',
'1',
1.0464881572673355,
0.753054443359375,
new Date('2023-01-01T00:00:00.000Z'),
'',
'01.19.10.8',
Expand All @@ -76,7 +76,7 @@ describe('CertisExporter', () => {
'',
'1',
'2',
1.0464881572673355,
0.753054443359375,
new Date('2023-01-01T00:00:00.000Z'),
'',
'01.19.10.8',
Expand All @@ -103,7 +103,7 @@ describe('CertisExporter', () => {
'',
'2',
'1',
1.0464881572673355,
0.753054443359375,
new Date('2021-01-01T00:00:00.000Z'),
'',
'01.19.10.8',
Expand All @@ -130,7 +130,7 @@ describe('CertisExporter', () => {
'',
'2',
'2',
1.0464881572673355,
0.753054443359375,
new Date('2015-01-01T00:00:00.000Z'),
'',
'01.19.10.7',
Expand All @@ -157,7 +157,7 @@ describe('CertisExporter', () => {
'',
'3',
'1',
1.0464881572673355,
0.753054443359375,
'',
'',
'',
Expand All @@ -184,7 +184,7 @@ describe('CertisExporter', () => {
'',
'4',
'1',
1.0464881572673355,
0.753054443359375,
'',
'',
'',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ describe('CertisudExporter', () => {
],
[
'[ERREUR] culture absente',
1.0464881572673355,
0.753054443359375,
'4.1',
'',
'',
'6'
],
[
'[ERREUR] culture inconnue (01.19.99)',
1.0464881572673355,
0.753054443359375,
'3.1',
'',
'',
Expand All @@ -46,7 +46,7 @@ describe('CertisudExporter', () => {
[
'Luzerne',
// expect.closeTo(2.1), // in vite@5 + vitest@1
2.092976314534671,
1.50610888671875,
'1.1 (nom personnalisé), Visitée ; 1.2, Prélèvement effectué, À risque',
'C1',
new Date('2023-01-01T00:00:00.000Z'),
Expand All @@ -55,7 +55,7 @@ describe('CertisudExporter', () => {
[
'Luzerne',
// expect.closeTo(1.0), // in vite@5 + vitest@1
1.0464881572673355,
0.753054443359375,
'2.1, 0.70ha, Réduction de conversion (Dérogation acceptée)',
'AB',
new Date('2021-01-01T00:00:00.000Z'),
Expand All @@ -64,7 +64,7 @@ describe('CertisudExporter', () => {
[
'Trèfle',
// expect.closeTo(1.0), // in vite@5 + vitest@1
1.0464881572673355,
0.753054443359375,
'2.1, 4 feuilles, semis le 01/03/2023, 0.30ha, Réduction de conversion (Dérogation acceptée)',
'AB',
new Date('2021-01-01T00:00:00.000Z'),
Expand All @@ -73,7 +73,7 @@ describe('CertisudExporter', () => {
[
'Trèfle',
// expect.closeTo(1.0), // in vite@5 + vitest@1
1.0464881572673355,
0.753054443359375,
'2.2, 4 feuilles, semis le 01/03/2023',
'AB',
new Date('2015-01-01T00:00:00.000Z'),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import BaseExporter, { generateAutresInfos } from "@/components/Features/ExportStrategies/BaseExporter.js";
import { utils, write } from "xlsx";
import { surface } from "@/components/Features/index.js"
import { legalProjectionSurface } from "@/components/Features/index.js"
import { fromCodeCpf } from "@agencebio/rosetta-cultures"

function getSheet () {
Expand Down Expand Up @@ -51,8 +51,9 @@ function getSheet () {
utils.decode_range('A3:E3')
]

utils.sheet_add_aoa(sheet, this.getSortedFeatures().map(({ geometry, properties: props }) => {
const surfaceHa = surface(geometry) / 10_000
utils.sheet_add_aoa(sheet, this.getSortedFeatures().map((feature) => {
const { properties: props } = feature
const surfaceHa = legalProjectionSurface(feature) / 10_000
const culture = props.cultures.at(0) ? fromCodeCpf(props.cultures.at(0)?.CPF) : { libelle_code_cpf: '[ERREUR] culture absente' }

return [
Expand Down
Loading

0 comments on commit ec59177

Please sign in to comment.