const RARETE_COMMUNE = { code: 'Commune', label: 'Commune', frequence: 54, min: 27, max: 108 }; const RARETE_FREQUENTE = { code: 'Frequente', label: 'Fréquente', frequence: 18, min: 9, max: 36 }; const RARETE_RARE = { code: 'Rare', label: 'Rare', frequence: 6, min: 3, max: 12 }; const RARETE_RARISSIME = { code: 'Rarissime', label: 'Rarissime', frequence: 2, min: 1, max: 4 }; const RARETE_INEXISTANT = { code: 'Inexistant', label: 'Inexistant', frequence: 0, min: 0, max: 0 }; const RARETES = [ RARETE_COMMUNE, RARETE_FREQUENTE, RARETE_RARE, RARETE_RARISSIME, RARETE_INEXISTANT, ] export class RdDRaretes { static getRareteByCode(code = undefined) { return RARETES.find(it => it.code == code) ?? RARETE_FREQUENTE; } static getChamp(rarete, field = undefined) { const selected = this.getRareteByCode(rarete); return field ? selected[field] : selected[frequence]; } static rareteFrequente() { return RARETE_FREQUENTE; } static raretes() { return RARETES; } static selonEnvironnement(item, milieux = undefined) { const list = item.getEnvironnement(milieux); const freqMax = Math.max(0, ...list.map(env => env.frequence)); const env = list.find(env => env.frequence == freqMax); if (env) { return RdDRaretes.getRareteByCode(env.rarete) } if (milieux == undefined) { return RdDRaretes.selonQualite(item) } return RARETE_INEXISTANT; } static selonQualite(item) { const qualite = item.system.qualite ?? 0; if (qualite <= 0) { return RARETE_COMMUNE } if (qualite <= 3) { return RARETE_FREQUENTE } if (qualite <= 6) { return RARETE_RARE } if (qualite <= 9) { return RARETE_RARISSIME } return RARETE_INEXISTANT } }