2026-03-18 13:00:50 +01:00
|
|
|
package ecoparasite;
|
|
|
|
|
|
2026-04-08 14:47:42 +02:00
|
|
|
import ecoparasite.completion.Completion;
|
|
|
|
|
import ecoparasite.input.InputFactory;
|
|
|
|
|
import ecoparasite.input.InputFileException;
|
|
|
|
|
import ecoparasite.input.RawData;
|
|
|
|
|
import ecoparasite.input.RawDataOverflow;
|
|
|
|
|
import ecoparasite.nettoyage.Nettoyage;
|
2026-04-29 11:14:07 +02:00
|
|
|
import ecoparasite.poisson.Mackerel;
|
2026-04-08 14:47:42 +02:00
|
|
|
import ecoparasite.poisson.MackerelSerra;
|
2026-04-29 11:14:07 +02:00
|
|
|
import ecoparasite.poisson.Merlu;
|
2026-04-08 14:47:42 +02:00
|
|
|
import ecoparasite.poisson.Poisson;
|
2026-04-29 11:14:07 +02:00
|
|
|
import ecoparasite.population.Population;
|
|
|
|
|
import ecoparasite.population.PopulationArgInterval;
|
|
|
|
|
import ecoparasite.population.PopulationParsing;
|
2026-04-08 14:47:42 +02:00
|
|
|
import ecoparasite.representation.ValeursXY;
|
2026-04-27 12:56:24 +02:00
|
|
|
import ecoparasite.svg.IncorrectAxesPointsException;
|
2026-04-27 15:18:30 +02:00
|
|
|
import ecoparasite.svg.SVGBuilder;
|
2026-04-27 12:56:24 +02:00
|
|
|
import ecoparasite.svg.SVGFactory;
|
|
|
|
|
import ecoparasite.svg.elements.Element;
|
|
|
|
|
|
2026-04-29 11:14:07 +02:00
|
|
|
import java.io.File;
|
|
|
|
|
import java.util.*;
|
2026-04-08 14:47:42 +02:00
|
|
|
import java.util.function.BiConsumer;
|
|
|
|
|
import java.util.function.Function;
|
|
|
|
|
|
2026-03-18 13:00:50 +01:00
|
|
|
public class Application {
|
2026-04-27 12:56:24 +02:00
|
|
|
|
2026-04-29 11:14:07 +02:00
|
|
|
static final String[] VALID_FILES = {"Campagne/mackerel.97442.csv", "Campagne/merlu2018_75164.csv","Combinés/ParasitesPeru2021.csv", "test2.csv"};
|
2026-04-08 14:47:42 +02:00
|
|
|
|
2026-04-29 11:14:07 +02:00
|
|
|
public static void validFileName(File dir, HashSet<String> listeName){
|
|
|
|
|
|
|
|
|
|
File[] liste = dir.listFiles();
|
|
|
|
|
|
|
|
|
|
for (File item : liste) {
|
|
|
|
|
if (!item.isDirectory()){
|
|
|
|
|
listeName.add(item.getName());
|
|
|
|
|
} else {
|
|
|
|
|
validFileName(new File(dir.getName()+ "/" + item.getName()), listeName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String validFile(){
|
|
|
|
|
|
|
|
|
|
Scanner sc = new Scanner(System.in);
|
|
|
|
|
String name = "";
|
|
|
|
|
boolean isValid = false;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
File dir = new File("data");
|
|
|
|
|
|
|
|
|
|
HashSet<String> listeName = new HashSet<>();
|
|
|
|
|
|
|
|
|
|
Application.validFileName(dir,listeName);
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
System.out.println( "Liste des fichiers valides:" );
|
|
|
|
|
for (String validFile : VALID_FILES) {
|
|
|
|
|
System.out.print(validFile + " ");
|
|
|
|
|
}
|
|
|
|
|
System.out.println();
|
|
|
|
|
|
|
|
|
|
while (!isValid) {
|
|
|
|
|
System.out.println("Veuillez rentrez le nom du fichier :");
|
|
|
|
|
name = sc.nextLine();
|
|
|
|
|
|
2026-04-29 11:21:15 +02:00
|
|
|
for (int i = 0; i < VALID_FILES.length; i++) {
|
2026-04-29 11:14:07 +02:00
|
|
|
if (name.contains(VALID_FILES[i])){
|
|
|
|
|
isValid = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void MackerelFile(String name) throws InputFileException, RawDataOverflow {
|
|
|
|
|
|
|
|
|
|
RawData rawMackerel = InputFactory.readData(name);
|
|
|
|
|
|
|
|
|
|
HashSet<Poisson> mackerelSet = Mackerel.parse(rawMackerel);
|
|
|
|
|
|
|
|
|
|
System.out.println( "Avant le nettoyage et complétion");
|
|
|
|
|
System.out.println( mackerelSet );
|
|
|
|
|
|
|
|
|
|
Function<Poisson,Double> getLength = Poisson::getLength;
|
|
|
|
|
Function<Poisson,Double> getInfes = Poisson::getInfestation;
|
|
|
|
|
BiConsumer<Poisson,Double> setInfes = Poisson::setInfestation;
|
|
|
|
|
|
|
|
|
|
mackerelSet = Nettoyage.nettoieColumns( mackerelSet, getInfes, setInfes, false );
|
|
|
|
|
mackerelSet = Completion.completeColumnsLinear( mackerelSet, getLength, getInfes, setInfes );
|
|
|
|
|
|
|
|
|
|
System.out.println( "Après le nettoyage et complétion");
|
|
|
|
|
System.out.println( mackerelSet );
|
|
|
|
|
|
|
|
|
|
HashSet<ValeursXY> mackerelXY = ValeursXY.convertToXY( mackerelSet, getLength, getInfes );
|
|
|
|
|
HashMap<String, ArrayList<Double>> axes = SVGBuilder.calcPointAxes( mackerelXY );
|
|
|
|
|
System.out.println( axes );
|
|
|
|
|
|
|
|
|
|
SVGBuilder axesInstance;
|
|
|
|
|
try {
|
|
|
|
|
axesInstance = new SVGBuilder(axes);
|
|
|
|
|
} catch (IncorrectAxesPointsException e) {
|
|
|
|
|
System.out.println( "Mauvais format communiqué" );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Sauvegarde pour plus tard.
|
|
|
|
|
double[] ABCoef = Completion.getLinearCoef(mackerelSet, getLength, getInfes);
|
|
|
|
|
|
2026-04-29 11:21:15 +02:00
|
|
|
ArrayList<Element> SVGElements = axesInstance.buildAll( "Length (mm)", "Taux d'infestation", mackerelXY, ABCoef[0], ABCoef[1] );
|
2026-04-29 11:14:07 +02:00
|
|
|
SVGFactory.createSVG( SVGElements );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void MerluFile(String name) throws InputFileException, RawDataOverflow {
|
|
|
|
|
|
|
|
|
|
RawData rawMerlu = InputFactory.readData(name);
|
|
|
|
|
|
|
|
|
|
HashSet<Poisson> merluSet = Merlu.parse(rawMerlu);
|
|
|
|
|
|
|
|
|
|
System.out.println( "Avant le nettoyage et complétion");
|
|
|
|
|
System.out.println( merluSet );
|
|
|
|
|
|
|
|
|
|
Function<Poisson,Double> getLength = Poisson::getLength;
|
|
|
|
|
Function<Poisson,Double> getInfes = Poisson::getInfestation;
|
|
|
|
|
BiConsumer<Poisson,Double> setInfes = Poisson::setInfestation;
|
|
|
|
|
|
|
|
|
|
merluSet = Nettoyage.nettoieColumns( merluSet, getInfes, setInfes, false );
|
|
|
|
|
merluSet = Completion.completeColumnsLinear( merluSet, getLength, getInfes, setInfes );
|
|
|
|
|
|
|
|
|
|
System.out.println( "Après le nettoyage et complétion");
|
|
|
|
|
System.out.println( merluSet );
|
|
|
|
|
|
|
|
|
|
HashSet<ValeursXY> merluXY = ValeursXY.convertToXY( merluSet, getLength, getInfes );
|
|
|
|
|
HashMap<String, ArrayList<Double>> axes = SVGBuilder.calcPointAxes( merluXY );
|
|
|
|
|
System.out.println( axes );
|
|
|
|
|
|
|
|
|
|
SVGBuilder axesInstance;
|
|
|
|
|
try {
|
|
|
|
|
axesInstance = new SVGBuilder(axes);
|
|
|
|
|
} catch (IncorrectAxesPointsException e) {
|
|
|
|
|
System.out.println( "Mauvais format communiqué" );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Sauvegarde pour plus tard.
|
|
|
|
|
double[] ABCoef = Completion.getLinearCoef(merluSet, getLength, getInfes);
|
|
|
|
|
|
2026-04-29 11:21:15 +02:00
|
|
|
ArrayList<Element> SVGElements = axesInstance.buildAll( "Length (mm)", "Taux d'infestation", merluXY, ABCoef[0], ABCoef[1] );
|
2026-04-29 11:14:07 +02:00
|
|
|
SVGFactory.createSVG( SVGElements );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void PopPeru(String name) throws InputFileException,RawDataOverflow{
|
|
|
|
|
|
|
|
|
|
RawData popRaw; int index;
|
|
|
|
|
try {
|
|
|
|
|
popRaw = InputFactory.readData(name , "," );
|
|
|
|
|
} catch(InputFileException e) {
|
|
|
|
|
System.out.println(e.getMessage());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HashSet<Population> popSet = PopulationParsing.parseParasitesPeru(popRaw);
|
|
|
|
|
|
|
|
|
|
index = 1;
|
|
|
|
|
System.out.println( "Avant complétion et nettoyage de la masse" );
|
|
|
|
|
for( Population p: popSet){
|
|
|
|
|
System.out.println(String.valueOf(index++) + p);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Nettoyage de la taille.
|
|
|
|
|
Function<Population,Double> getLength = population -> {
|
|
|
|
|
return population.getTotal().getLength() != null ? population.getTotal().getLength().transformToDouble() : null;
|
|
|
|
|
};
|
|
|
|
|
BiConsumer<Population,Double> setLength = (population, aDouble) -> {
|
|
|
|
|
population.getTotal().setLength(aDouble != null ? new PopulationArgInterval(aDouble,aDouble) : null);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Function<Population,Double> getInfes = population -> {
|
2026-04-29 11:54:29 +02:00
|
|
|
return population.getTotal().getAbondance() != null ? population.getTotal().getAbondance() : null;
|
2026-04-29 11:14:07 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
popSet = Nettoyage.nettoieColumns(popSet, getLength, setLength, false);
|
|
|
|
|
System.out.println("Après nettoyage de la masse");
|
|
|
|
|
index = 1;
|
|
|
|
|
for( Population p: popSet){
|
|
|
|
|
System.out.println(String.valueOf(index++) + p);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Complétion de la masse.
|
|
|
|
|
popSet = Completion.completeColumnsMoyenne(popSet, getLength, setLength);
|
|
|
|
|
System.out.println("Après complétion de la masse");
|
|
|
|
|
|
|
|
|
|
index = 1;
|
|
|
|
|
for( Population p: popSet){
|
|
|
|
|
System.out.println(String.valueOf(index++) + p);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HashSet<ValeursXY> popXY = ValeursXY.convertToXY( popSet, getLength, getInfes );
|
|
|
|
|
HashMap<String, ArrayList<Double>> axes = SVGBuilder.calcPointAxes( popXY );
|
|
|
|
|
System.out.println( axes );
|
|
|
|
|
|
|
|
|
|
SVGBuilder axesInstance;
|
|
|
|
|
try {
|
|
|
|
|
axesInstance = new SVGBuilder(axes);
|
|
|
|
|
} catch (IncorrectAxesPointsException e) {
|
|
|
|
|
System.out.println( "Mauvais format communiqué" );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-29 11:21:15 +02:00
|
|
|
double[] ABCoef = Completion.getLinearCoef(popSet, getLength, getInfes);
|
2026-04-29 11:14:07 +02:00
|
|
|
|
2026-04-29 11:21:15 +02:00
|
|
|
ArrayList<Element> elements = axesInstance.buildAll( "Taille en mm", "Abondance", popXY, ABCoef[0], ABCoef[1] );
|
2026-04-29 11:14:07 +02:00
|
|
|
SVGFactory.createSVG(elements);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void test2Render(String name) throws InputFileException,RawDataOverflow{
|
|
|
|
|
|
|
|
|
|
RawData rawMackerel = InputFactory.readData(name, ",");
|
2026-04-08 14:47:42 +02:00
|
|
|
|
|
|
|
|
HashSet<Poisson> mackerelSet = MackerelSerra.parse(rawMackerel);
|
|
|
|
|
|
2026-04-29 09:23:17 +02:00
|
|
|
System.out.println( "Avant nettoyage et complétion" );
|
2026-04-08 14:47:42 +02:00
|
|
|
System.out.println( mackerelSet );
|
|
|
|
|
|
|
|
|
|
Function<Poisson,Double> getLength = Poisson::getLength;
|
|
|
|
|
Function<Poisson,Double> getInfes = Poisson::getInfestation;
|
|
|
|
|
BiConsumer<Poisson,Double> setInfes = Poisson::setInfestation;
|
|
|
|
|
|
2026-04-29 09:23:17 +02:00
|
|
|
mackerelSet = Nettoyage.nettoieColumns( mackerelSet, Poisson::getLength, Poisson::setLength, false );
|
|
|
|
|
mackerelSet = Completion.completeColumnsMoyenne( mackerelSet, Poisson::getLength, Poisson::setLength );
|
|
|
|
|
|
|
|
|
|
System.out.println( "Après Nettoyage et complétion de la longueur du poisson." );
|
|
|
|
|
System.out.println( mackerelSet );
|
|
|
|
|
|
2026-04-08 15:25:40 +02:00
|
|
|
mackerelSet = Nettoyage.nettoieColumns( mackerelSet, getInfes, setInfes, false );
|
2026-04-08 14:47:42 +02:00
|
|
|
mackerelSet = Completion.completeColumnsLinear( mackerelSet, getLength, getInfes, setInfes );
|
|
|
|
|
|
2026-04-29 09:23:17 +02:00
|
|
|
System.out.println( "Après Nettoyage et complétion du taux d'infestation des poissons" );
|
|
|
|
|
System.out.println( mackerelSet );
|
|
|
|
|
|
|
|
|
|
// Conversion des valeurs.
|
2026-04-08 14:47:42 +02:00
|
|
|
HashSet<ValeursXY> mackerelXY = ValeursXY.convertToXY( mackerelSet, getLength, getInfes );
|
2026-04-27 15:18:30 +02:00
|
|
|
HashMap<String, ArrayList<Double>> axes = SVGBuilder.calcPointAxes( mackerelXY );
|
2026-04-27 12:56:24 +02:00
|
|
|
System.out.println( axes );
|
|
|
|
|
|
2026-04-27 15:18:30 +02:00
|
|
|
SVGBuilder axesInstance;
|
2026-04-27 12:56:24 +02:00
|
|
|
try {
|
2026-04-27 15:18:30 +02:00
|
|
|
axesInstance = new SVGBuilder(axes);
|
2026-04-27 12:56:24 +02:00
|
|
|
} catch (IncorrectAxesPointsException e) {
|
|
|
|
|
System.out.println( "Mauvais format communiqué" );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-27 15:18:30 +02:00
|
|
|
// Sauvegarde pour plus tard.
|
|
|
|
|
double[] ABCoef = Completion.getLinearCoef(mackerelSet, getLength, getInfes);
|
|
|
|
|
|
2026-04-29 09:23:17 +02:00
|
|
|
ArrayList<Element> SVGElements = axesInstance.buildAll( "Length (mm)", "Taux d'infestation", mackerelXY, ABCoef[0], ABCoef[1] );
|
2026-04-27 12:56:24 +02:00
|
|
|
SVGFactory.createSVG( SVGElements );
|
2026-04-08 14:47:42 +02:00
|
|
|
|
2026-03-18 13:00:50 +01:00
|
|
|
}
|
2026-04-29 11:14:07 +02:00
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
|
|
|
|
|
String nameFile = Application.validFile();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
if (nameFile.contains("mackerel")) {
|
|
|
|
|
MackerelFile(nameFile);
|
|
|
|
|
} else if (nameFile.contains("merlu")) {
|
|
|
|
|
MerluFile(nameFile);
|
|
|
|
|
} else if (nameFile.contains("Peru")) {
|
|
|
|
|
PopPeru(nameFile);
|
|
|
|
|
} else if (nameFile.contains("test2")) {
|
2026-04-29 11:21:15 +02:00
|
|
|
test2Render(nameFile);
|
2026-04-29 11:14:07 +02:00
|
|
|
}
|
|
|
|
|
} catch ( InputFileException e ){
|
|
|
|
|
System.out.println( e.getMessage() );
|
|
|
|
|
} catch ( RawDataOverflow e ){
|
|
|
|
|
System.out.println( e.getMessage() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2026-03-18 13:00:50 +01:00
|
|
|
}
|