2026-04-08 10:32:11 +02:00
|
|
|
package ecoparasite;
|
|
|
|
|
|
2026-04-08 11:10:15 +02:00
|
|
|
import ecoparasite.completion.Completion;
|
2026-04-08 10:32:11 +02:00
|
|
|
import ecoparasite.input.InputFactory;
|
|
|
|
|
import ecoparasite.input.InputFileException;
|
|
|
|
|
import ecoparasite.input.RawData;
|
|
|
|
|
import ecoparasite.input.RawDataOverflow;
|
2026-04-08 11:10:15 +02:00
|
|
|
import ecoparasite.nettoyage.Nettoyage;
|
|
|
|
|
import ecoparasite.poisson.Poisson;
|
2026-04-08 10:32:11 +02:00
|
|
|
import ecoparasite.population.Population;
|
|
|
|
|
import ecoparasite.population.PopulationArgInterval;
|
|
|
|
|
import ecoparasite.population.PopulationArgs;
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.HashSet;
|
2026-04-08 11:10:15 +02:00
|
|
|
import java.util.function.BiConsumer;
|
|
|
|
|
import java.util.function.Function;
|
2026-04-08 10:32:11 +02:00
|
|
|
|
|
|
|
|
public class LectureEval {
|
|
|
|
|
|
|
|
|
|
public static HashSet<Population> parseEval( RawData popRaw ){
|
|
|
|
|
|
|
|
|
|
HashSet<Population> popEspece = new HashSet<>();
|
|
|
|
|
|
|
|
|
|
int index = 1;
|
|
|
|
|
try {
|
|
|
|
|
while(true){
|
|
|
|
|
HashMap<String,String> fields = popRaw.getEntry(index);
|
|
|
|
|
|
|
|
|
|
String espece = fields.get("Espèce");
|
|
|
|
|
|
|
|
|
|
Population population = new Population(espece);
|
|
|
|
|
|
|
|
|
|
if( population.getTotal() == null ){
|
|
|
|
|
population.setTotal( new PopulationArgs() );
|
|
|
|
|
}
|
|
|
|
|
for( String k: fields.keySet() ){
|
|
|
|
|
if( k.equals("Espèce") )
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
LectureEval.applyValueForPopEval( population.getTotal(), k, fields.get(k) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
popEspece.add(population);
|
|
|
|
|
index++;
|
|
|
|
|
}
|
|
|
|
|
} catch (RawDataOverflow e) {
|
|
|
|
|
// Fin de la liste.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return popEspece;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void applyValueForPopEval( PopulationArgs popArgs, String column, String value ){
|
|
|
|
|
|
|
|
|
|
if( value == null || value == "" ) // On n'ajoute pas les valeurs nulles.
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
switch (column){
|
|
|
|
|
case "zone":
|
|
|
|
|
popArgs.setZone(value);
|
|
|
|
|
break;
|
|
|
|
|
case "N":
|
|
|
|
|
popArgs.setNumber( Integer.parseInt(value) );
|
|
|
|
|
break;
|
|
|
|
|
case "Prevalence":
|
|
|
|
|
popArgs.setPrevalence(PopulationArgInterval.fromString(value));
|
|
|
|
|
break;
|
|
|
|
|
case "LT mm":
|
|
|
|
|
popArgs.setLength(PopulationArgInterval.fromString(value));
|
|
|
|
|
break;
|
|
|
|
|
case "Masse g":
|
|
|
|
|
popArgs.setWidth(PopulationArgInterval.fromString(value));
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) throws RawDataOverflow {
|
|
|
|
|
|
|
|
|
|
RawData popRaw;
|
|
|
|
|
try {
|
|
|
|
|
popRaw = InputFactory.readData("test3.csv", "," );
|
|
|
|
|
} catch(InputFileException e) {
|
|
|
|
|
System.out.println(e.getMessage());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HashSet<Population> pop = parseEval(popRaw);
|
|
|
|
|
|
|
|
|
|
// System.out.println( popRaw.getEntry(1) );
|
|
|
|
|
|
|
|
|
|
for( Population p: pop){
|
|
|
|
|
System.out.println(p);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-08 11:10:15 +02:00
|
|
|
// Complétion de la masse.
|
|
|
|
|
Function<Population,Double> getWeight = population -> {
|
|
|
|
|
return population.getTotal().getWidth() != null ? population.getTotal().getWidth().transformToDouble() : null;
|
|
|
|
|
};
|
|
|
|
|
BiConsumer<Population,Double> setWeight = (population, aDouble) -> {
|
|
|
|
|
population.getTotal().setWidth(new PopulationArgInterval(aDouble,aDouble));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Complétion de la masse.
|
|
|
|
|
pop = Completion.completeColumnsMoyenne(pop, getWeight, setWeight);
|
|
|
|
|
System.out.println("---");
|
|
|
|
|
for( Population p: pop){
|
|
|
|
|
System.out.println(p);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Nettoyage de la masse.
|
|
|
|
|
pop = Nettoyage.nettoieColumnsMoyenne(pop, getWeight, setWeight, false);
|
|
|
|
|
System.out.println("---");
|
|
|
|
|
for( Population p: pop){
|
|
|
|
|
System.out.println(p);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-08 10:32:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|