Skip to content

Commit

Permalink
Merge pull request #5 from AgenceBio/maud/changement_structure
Browse files Browse the repository at this point in the history
Changement structure des données et du module
  • Loading branch information
jillro authored Jun 5, 2024
2 parents e980798 + 4cb364b commit e999d5e
Show file tree
Hide file tree
Showing 14 changed files with 281 additions and 45,495 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,9 @@ dist

# TernJS port file
.tern-port

# Custom build output
data/cpf.json
data/cepages.json
dist/
*.d.ts
14 changes: 10 additions & 4 deletions bin/assemble.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { createReadStream } from 'node:fs'
import { writeFile } from 'node:fs/promises'
import { join, dirname } from 'node:path'
import { fileURLToPath } from 'node:url'
import { createCpfResolver, isOrganicProductionCode, toBoolean } from '../index.js'
import { cepageCategorieCpf } from '../cepages.js'
import { createCpfResolver, isOrganicProductionCode, toBoolean } from '../src/resolvers.js'
import { cepageCategorieCpf } from '../src/cepages.js'

const here = dirname(fileURLToPath(new URL(import.meta.url)))

Expand All @@ -26,6 +26,7 @@ const DESTINATION_CEPAGES_FILE = join(here, '..', 'data', 'cepages.json')
* @type {Map<String, UnifiedCulture>}
*/
const CPF = new Map()
const PAC = new Map()

/**
* @type {Map<String, Cepage>}
Expand Down Expand Up @@ -85,12 +86,14 @@ for await (const { code_pac, code_precision, lbl_pac, code_cpf, correspondance_d
requires_precision: toBoolean(correspondance_directe) === false
}

const code_with_precision = `${code_pac}:${code_precision}`
PAC.set(code_with_precision, new_culture)
resolvedRecords.forEach(({ code_cpf }) => {
const record = CPF.get(code_cpf)
CPF.set(code_cpf, {
...record,
// extension PAC
cultures_pac: Array.isArray(record.cultures_pac) ? [...record.cultures_pac, new_culture] : [new_culture]
cultures_pac: Array.isArray(record.cultures_pac) ? [...record.cultures_pac, [code_pac, code_precision]] : [[code_pac, code_precision]]
})
})
}
Expand Down Expand Up @@ -176,5 +179,8 @@ for await (const { Code, Libellé, Couleur, Catégorie, Statut } of csvParser) {
}

// 99. Write
await writeFile(DESTINATION_FILE, JSON.stringify(Array.from(CPF.values()), null, 2))
await writeFile(DESTINATION_FILE, JSON.stringify({
"CPF": Array.from(CPF.values()),
"PAC": Array.from(PAC.values()),
}, null, 2))
await writeFile(DESTINATION_CEPAGES_FILE, JSON.stringify(Object.fromEntries(CEPAGES.entries()), null, 2))
29 changes: 0 additions & 29 deletions cepages.d.ts

This file was deleted.

40 changes: 4 additions & 36 deletions cepages.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,7 @@
/**
* Built with `npm run build`
*
* @type {Object.<String, Cepage>}
* @module cepages
* @deprecated
*/
import cepages from './data/cepages.json' assert { type: 'json' }

/**
* @typedef Cepage
* @property {String} code
* @property {String} libelle
* @property {CepageCouleur} couleur
* @property {String=} code_cpf
* @property {Boolean} is_selectable
*/

export const CepageCouleur = {
BLANC: 'Blanc',
INDETERMINÉ: 'Indéterminé',
NOIR: 'Noir',
ROUGE: 'Rouge',
ROSÉ: 'Rose'
}

export const CepageCatégorie = {
Cuve: '01.21.12',
Multiplication: '01.21.1',
Table: '01.21.11',
Mixte: '01.21.1',
Interdit: '01.21.1'
}

export function cepageCategorieCpf (categorie) {
return CepageCatégorie[String(categorie)] ?? null
}

export function fromCepageCode (code) {
return cepages[String(code)] ?? null
}
export { fromCepageCode } from './src/converters.js'
export * from './src/cepages.js'
3 changes: 1 addition & 2 deletions cepages.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { describe, it } from 'node:test'
import { ok, deepEqual } from 'node:assert/strict'
import { deepEqual } from 'node:assert/strict'
import { CepageCouleur, fromCepageCode } from './cepages.js'

import cepages from './data/cepages.json' assert { type: 'json' }

describe('fromCepageCode()', () => {
it('should return null when code is not found', () => {
Expand Down
Loading

0 comments on commit e999d5e

Please sign in to comment.