Skip to content

Commit

Permalink
outil liste espèces
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBruant committed Feb 16, 2024
1 parent 078d5b5 commit 590b254
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# pitchou
Mieux contrôler les dérogations d'espèces protégées


## Outils

`node outils/liste-espèces.js`
62 changes: 62 additions & 0 deletions outils/liste-espèces.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//@ts-check

import {readFileSync, writeFileSync} from 'node:fs'
import {csvParse, tsvParse, dsvFormat} from 'd3-dsv'


// BDC_STATUTS

let bdc_statuts_raw = csvParse(readFileSync('data/BDC_STATUTS_17.csv', 'utf-8'))

console.log('bdc_statuts_raw.length', bdc_statuts_raw.length)

const keptCdTypeStatus = new Set(['POM', 'PD', 'PM', 'PR'])

const bdc_statuts = bdc_statuts_raw
.filter(({CD_TYPE_STATUT}) => keptCdTypeStatus.has(CD_TYPE_STATUT))
.map(
({CD_NOM, CD_TYPE_STATUT, LABEL_STATUT}) => ({CD_NOM, CD_TYPE_STATUT, LABEL_STATUT})
)

// @ts-ignore
bdc_statuts_raw = undefined // for GC

console.log('bdc_statuts.length', bdc_statuts.length)

console.log('bdc_statuts unique CD_NOM', new Set(bdc_statuts.map(({CD_NOM}) => CD_NOM)).size)


// TAXREF

let taxref_raw = tsvParse(readFileSync('data/TAXREFv17.txt', 'utf-8'))

console.log('taxref_raw.length', taxref_raw.length)

const taxref = taxref_raw
.filter(({CD_NOM, CD_REF}) => CD_NOM === CD_REF)
.map(({LB_NOM, NOM_COMPLET_HTML, CD_NOM, NOM_VERN}) => ({LB_NOM, NOM_COMPLET_HTML, CD_NOM, NOM_VERN}))

// @ts-ignore
taxref_raw = undefined // for GC

const taxrefByCD_NOM = new Map()

for(const taxon of taxref){
const {CD_NOM} = taxon
taxrefByCD_NOM.set(CD_NOM, taxon)
}


const output = bdc_statuts.map(bdc_statut => {
const {CD_NOM} = bdc_statut

const taxon = taxrefByCD_NOM.get(CD_NOM)

return Object.assign(
{},
bdc_statut,
taxon
)
})

writeFileSync('liste_especes_17.csv', dsvFormat(';').format(output))

0 comments on commit 590b254

Please sign in to comment.