A lot of things².

- Change DataParsing to a generic interface.
- Add PartiePoisson
- Add comments to Population class.
This commit is contained in:
2026-04-01 14:34:07 +02:00
parent 3a6968f40f
commit 6420a4c606
12 changed files with 401 additions and 54 deletions

View File

@@ -1,50 +1,118 @@
package ecoparasite.population;
package ecoparasite.population;
import java.util.HashMap;
import java.util.HashSet;
import ecoparasite.input.DataParsing;
import ecoparasite.input.InvalidParsingException;
import ecoparasite.input.RawData;
import ecoparasite.input.RawDataOverflow;
public class Population {
import java.util.HashMap;
import java.util.HashSet;
private String id;
private PopulationArgs total;
private HashMap<Integer,PopulationArgs> perYear;
/**
* Permet de gérer une population selon les années.
*/
public class Population implements DataParsing {
public Population(String id, PopulationArgs total, HashMap<Integer,PopulationArgs> perYear) {
this.id = id;
this.total = total;
this.perYear = perYear;
}
/**
* Espèce de la population.
*/
private String id;
public Population(String id, PopulationArgs total) {
this.id = id;
this.total = total;
this.perYear = new HashMap<>();
}
/**
* Les informations de la population sur le total.
*/
private PopulationArgs total;
public Population(String id) {
this.id = id;
this.total = null;
this.perYear = new HashMap<>();
}
public String getId() {
return id;
}
public PopulationArgs getTotal() {
return total;
}
public HashMap<Integer,PopulationArgs> getPerYear() {
return perYear;
}
public void setTotal(PopulationArgs total) {
this.total = total;
}
public void setPerYear(HashMap<Integer,PopulationArgs> perYear) {
this.perYear = perYear;
}
/**
* Les informations de la population par année.
* Clé : Année, Valeur : Informations de la population.
*/
private HashMap<Integer,PopulationArgs> perYear;
/**
* Constructeur.
* @param id Espèce
* @param total Les informations totales.
* @param perYear Les informations par année.
*/
public Population(String id, PopulationArgs total, HashMap<Integer,PopulationArgs> perYear) {
this.id = id;
this.total = total;
this.perYear = perYear;
}
/**
* Constructeur.
* Pour les informations par année, crée une HashMap vide. Devra être rempli après coup.
* @param id Espèce de la population.
* @param total Les informations totales.
*/
public Population(String id, PopulationArgs total) {
this.id = id;
this.total = total;
this.perYear = new HashMap<>();
}
/**
* Constructeur.
* Pour les informations du total, sont remplacés par null.
* Pour les informations par année, crée une HashMap vide. Devra être rempli après coup.
* @param id Espèce de la population.
*/
public Population(String id) {
this.id = id;
this.total = null;
this.perYear = new HashMap<>();
}
/*
GETTERS / SETTERS
*/
public String getId() {
return id;
}
public PopulationArgs getTotal() {
return total;
}
public HashMap<Integer,PopulationArgs> getPerYear() {
return perYear;
}
public void setTotal(PopulationArgs total) {
this.total = total;
}
public void setPerYear(HashMap<Integer,PopulationArgs> perYear) {
this.perYear = perYear;
}
/**
* Raccourci vers les méthodes de DataParsing.
* @param data Notre objet RawData.
* @param parseTypeId L'ID de parsing.
* @return
*/
public static HashSet<Population> parse(RawData data, int parseTypeId ) throws RawDataOverflow, InvalidParsingException {
switch (parseTypeId) {
case 1:
return PopulationParsing.parseParasitesPeru(data);
default:
throw new InvalidParsingException(parseTypeId, Population.class.getSimpleName() );
}
}
/**
* Raccourci vers les méthodes de DataParsing.
* Va par défaut faire ceux des parasites du Perou.
*
* @param data Notre objet RawData.
* @return Notre tableau de populations.
*/
public static HashSet<Population> parse(RawData data){
return PopulationParsing.parseParasitesPeru(data);
}
}

View File

@@ -1,17 +1,44 @@
package ecoparasite.population;
/**
* Classe qui permet de gérer un intervalle de données issues d'un CSV.
*
* Trois données : minimum, maximum et moyenne entre minimum et maximum.
*/
public class PopulationArgInterval {
/**
* Valeur minimale.
*/
private Double min;
/**
* Valeur maximale.
*/
private Double max;
/**
* Moyenne entre la valeur minimale et maximale.
*/
private Double mean;
/**
* Constructeur. La moyenne doit être précisée.
* @param min Valeur minimale
* @param max Valeur maximale
* @param mean Moyenne
*/
public PopulationArgInterval(Double min, Double max, Double mean) {
this.min = min;
this.max = max;
this.mean = mean;
}
/**
* Constructeur. La moyenne est calculé automatiquement.
* @param min Valeur minimale
* @param max Valeur maximale.
*/
public PopulationArgInterval(Double min, Double max) {
this.min = min;
this.max = max;
@@ -28,12 +55,26 @@ public class PopulationArgInterval {
return this.mean;
}
/**
* Permet de transformer un intervalle en double.
* Si le minimum est égal au maximum, cette valeur est retourné.
* Sinon la moyenne est retourné.
*
* @return La valeur transformée en Double.
*/
public Double transformToDouble(){
if( this.min == this.max )
return this.min;
return this.mean;
}
/**
* Permet de transformer une String (Extraite d'un fichier CSV) et de la transformer en Intervalle.
* Gère les séparateurs +/- ainsi que l'entre deux. Sinon, elle sera juste convertie avec minimum = maximum.
*
* @param rawValue La valeur brute.
* @return La valeur en tant qu'intervalle.
*/
public static PopulationArgInterval fromString( String rawValue ){
if( rawValue.contains( "±" ) ){ // Plus ou moins.

View File

@@ -1,9 +1,19 @@
package ecoparasite.population;
/**
* Permet de stocker les paramètres d'une population pour une année spécifique.
* Par convention, si on est sur le total, on mettra comme année 0.
*/
public class PopulationArgs {
/**
* Année de référence pour ces paramètres.
*/
private int year;
/**
* Le nombre d'individus analysés.
*/
private int number;
private PopulationArgInterval length;
private PopulationArgInterval width;
@@ -12,6 +22,19 @@ public class PopulationArgs {
private Double intensity;
private Double abondance;
/**
* Constructeur.
* Toutes les données peuvent être préremplis dans ce constructeur sauf l'année.
* L'année sera par défaut à zéro.
*
* @param N
* @param length
* @param width
* @param prevalence
* @param ic
* @param intensity
* @param abondance
*/
public PopulationArgs(
int N,
PopulationArgInterval length,
@@ -31,6 +54,19 @@ public class PopulationArgs {
this.abondance = abondance;
}
/**
* Constructeur.
* Toutes les données ainsi que l'année peuvent être préremplis.
*
* @param year
* @param N
* @param length
* @param width
* @param prevalence
* @param ic
* @param intensity
* @param abondance
*/
public PopulationArgs(
int year,
int N,
@@ -51,16 +87,30 @@ public class PopulationArgs {
this.abondance = abondance;
}
/**
* Constructeur.
* Permet de remplir tout d'abord l'année, les autres paramètres seront remplis par les setters.
*
* @param year
*/
public PopulationArgs(
int year
){
this.year = year;
}
/**
* Constructeur.
* Initialise l'objet avec une année par défaut (0).
*/
public PopulationArgs(){
this.year = 0;
}
/*
GETTERS / SETTERS
*/
public int getYear() {
return year;
}

View File

@@ -6,9 +6,18 @@ import ecoparasite.input.RawDataOverflow;
import java.util.HashMap;
import java.util.HashSet;
/**
* Permet de parser une population spécifique via les schémas fournis.
*/
public class PopulationParsing {
public static HashMap<String,Population> parseParasitesPeru(RawData peruRawData ){
/**
* Permet, à partir d'un objet RawData, de parse les données tel que le fichier parasitesPeru est structuré.
*
* @param peruRawData
* @return Une liste des populations incluses.
*/
public static HashSet<Population> parseParasitesPeru(RawData peruRawData ){
HashMap<String,Population> response = new HashMap<>();
@@ -19,9 +28,9 @@ public class PopulationParsing {
HashMap<String,String> fields = peruRawData.getEntry(index);
String espece = fields.get("Espèce");
System.out.println(espece);
String parametre = fields.get("Paramètre");
// Récupère la population si elle existe déjà.
Population population = null;
if( response.containsKey( espece ) ){
population = response.get(espece);
@@ -59,13 +68,20 @@ public class PopulationParsing {
response.put( espece, population );
index++;
}
} catch (RawDataOverflow e){
} catch (RawDataOverflow e){ // Débordement, on a atteint la fin de l'objet RawData.
// Stop.
}
return response;
return new HashSet<Population>( response.values() );
}
/**
* Permet d'appliquer la valeur au paramètre respectif en se basant sur le nom de la colonne.
*
* @param populationArgs Les paramètres de la population actuelle.
* @param column Le nom de la colonne dans le fichier CSV
* @param value La valeur a affecter
*/
private static void applyValueForParasitesPeru( PopulationArgs populationArgs, String column, String value ){
switch( column ){
case "N":