Compare commits
4 Commits
appTime
...
4db6dd24df
| Author | SHA1 | Date | |
|---|---|---|---|
| 4db6dd24df | |||
| d227208578 | |||
| 9c006f94fb | |||
| d0a5315ca2 |
@@ -6,86 +6,48 @@ import ecoparasite.input.InputFileException;
|
|||||||
import ecoparasite.input.RawData;
|
import ecoparasite.input.RawData;
|
||||||
import ecoparasite.input.RawDataOverflow;
|
import ecoparasite.input.RawDataOverflow;
|
||||||
import ecoparasite.nettoyage.Nettoyage;
|
import ecoparasite.nettoyage.Nettoyage;
|
||||||
import ecoparasite.poisson.Mackerel;
|
|
||||||
import ecoparasite.poisson.MackerelSerra;
|
import ecoparasite.poisson.MackerelSerra;
|
||||||
import ecoparasite.poisson.Merlu;
|
|
||||||
import ecoparasite.poisson.Poisson;
|
import ecoparasite.poisson.Poisson;
|
||||||
import ecoparasite.population.Population;
|
|
||||||
import ecoparasite.population.PopulationArgInterval;
|
|
||||||
import ecoparasite.population.PopulationParsing;
|
|
||||||
import ecoparasite.representation.ValeursXY;
|
import ecoparasite.representation.ValeursXY;
|
||||||
import ecoparasite.svg.IncorrectAxesPointsException;
|
import ecoparasite.svg.IncorrectAxesPointsException;
|
||||||
import ecoparasite.svg.SVGBuilder;
|
import ecoparasite.svg.SVGBuilder;
|
||||||
import ecoparasite.svg.SVGFactory;
|
import ecoparasite.svg.SVGFactory;
|
||||||
import ecoparasite.svg.elements.Element;
|
import ecoparasite.svg.elements.Element;
|
||||||
|
|
||||||
import java.io.File;
|
import java.util.ArrayList;
|
||||||
import java.util.*;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
public class Application {
|
public class Application {
|
||||||
|
|
||||||
static final String[] VALID_FILES = {"Campagne/mackerel.97442.csv", "Campagne/merlu2018_75164.csv","Combinés/ParasitesPeru2021.csv"};
|
public static void main(String[] args) throws InputFileException, RawDataOverflow {
|
||||||
|
|
||||||
public static void validFileName(File dir, HashSet<String> listeName){
|
RawData rawMackerel = InputFactory.readData("test2.csv", ",");
|
||||||
|
|
||||||
File[] liste = dir.listFiles();
|
HashSet<Poisson> mackerelSet = MackerelSerra.parse(rawMackerel);
|
||||||
|
|
||||||
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);
|
|
||||||
*/
|
|
||||||
|
|
||||||
while (!isValid) {
|
|
||||||
System.out.println("Veuillez rentrez le nom du fichier :");
|
|
||||||
name = sc.nextLine();
|
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++) {
|
|
||||||
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 nettoyage et complétion" );
|
||||||
System.out.println( mackerelSet );
|
System.out.println( mackerelSet );
|
||||||
|
|
||||||
Function<Poisson,Double> getLength = Poisson::getLength;
|
Function<Poisson,Double> getLength = Poisson::getLength;
|
||||||
Function<Poisson,Double> getInfes = Poisson::getInfestation;
|
Function<Poisson,Double> getInfes = Poisson::getInfestation;
|
||||||
BiConsumer<Poisson,Double> setInfes = Poisson::setInfestation;
|
BiConsumer<Poisson,Double> setInfes = Poisson::setInfestation;
|
||||||
|
|
||||||
|
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 );
|
||||||
|
|
||||||
mackerelSet = Nettoyage.nettoieColumns( mackerelSet, getInfes, setInfes, false );
|
mackerelSet = Nettoyage.nettoieColumns( mackerelSet, getInfes, setInfes, false );
|
||||||
mackerelSet = Completion.completeColumnsLinear( mackerelSet, getLength, getInfes, setInfes );
|
mackerelSet = Completion.completeColumnsLinear( mackerelSet, getLength, getInfes, setInfes );
|
||||||
|
|
||||||
|
System.out.println( "Après Nettoyage et complétion du taux d'infestation des poissons" );
|
||||||
|
System.out.println( mackerelSet );
|
||||||
|
|
||||||
|
// Conversion des valeurs.
|
||||||
HashSet<ValeursXY> mackerelXY = ValeursXY.convertToXY( mackerelSet, getLength, getInfes );
|
HashSet<ValeursXY> mackerelXY = ValeursXY.convertToXY( mackerelSet, getLength, getInfes );
|
||||||
HashMap<String, ArrayList<Double>> axes = SVGBuilder.calcPointAxes( mackerelXY );
|
HashMap<String, ArrayList<Double>> axes = SVGBuilder.calcPointAxes( mackerelXY );
|
||||||
System.out.println( axes );
|
System.out.println( axes );
|
||||||
@@ -101,122 +63,8 @@ public class Application {
|
|||||||
// Sauvegarde pour plus tard.
|
// Sauvegarde pour plus tard.
|
||||||
double[] ABCoef = Completion.getLinearCoef(mackerelSet, getLength, getInfes);
|
double[] ABCoef = Completion.getLinearCoef(mackerelSet, getLength, getInfes);
|
||||||
|
|
||||||
ArrayList<Element> SVGElements = axesInstance.buildAll( "Length", "Infestation", mackerelXY, ABCoef[0], ABCoef[1] );
|
ArrayList<Element> SVGElements = axesInstance.buildAll( "Length (mm)", "Taux d'infestation", mackerelXY, ABCoef[0], ABCoef[1] );
|
||||||
SVGFactory.createSVG( SVGElements );
|
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( 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 );
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
ArrayList<Element> SVGElements = axesInstance.buildAll( "Length", "Infestation", merluXY, ABCoef[0], ABCoef[1] );
|
|
||||||
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;
|
|
||||||
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 -> {
|
|
||||||
return population.getTotal().getAbondance() != null ? population.getTotal().getPrevalence().transformToDouble() : null;
|
|
||||||
};
|
|
||||||
|
|
||||||
popSet = Nettoyage.nettoieColumns(popSet, getLength, setLength, false);
|
|
||||||
System.out.println("---");
|
|
||||||
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("---");
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ArrayList<Element> elements = new ArrayList<>();
|
|
||||||
|
|
||||||
elements.addAll(axesInstance.buildAxes("Taille en mm", "Abondance"));
|
|
||||||
elements.addAll(axesInstance.buildXTicks());
|
|
||||||
elements.addAll(axesInstance.buildYTicks());
|
|
||||||
elements.addAll(axesInstance.buildPoints(popXY));
|
|
||||||
|
|
||||||
SVGFactory.createSVG(elements);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) throws InputFileException, RawDataOverflow {
|
|
||||||
|
|
||||||
String nameFile = Application.validFile();
|
|
||||||
|
|
||||||
if (nameFile.contains("mackerel")) {
|
|
||||||
MackerelFile(nameFile);
|
|
||||||
} else if (nameFile.contains("merlu")){
|
|
||||||
MerluFile(nameFile);
|
|
||||||
} else if (nameFile.contains("Peru")) {
|
|
||||||
PopPeru(nameFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -98,17 +98,17 @@ public class SVGBuilder {
|
|||||||
Coordonnees right = getResizer().resize( maxPointsX, beginAxeY );
|
Coordonnees right = getResizer().resize( maxPointsX, beginAxeY );
|
||||||
|
|
||||||
// Axes
|
// Axes
|
||||||
elements.add( new Line( bottom, top, ElementsFactory.COLOR_BLACK, 2 ) );
|
elements.add( new Line( bottom, top, ElementsFactory.COLOR_WHITE, 2 ) );
|
||||||
elements.add( new Line( left, right, ElementsFactory.COLOR_BLACK, 2 ) );
|
elements.add( new Line( left, right, ElementsFactory.COLOR_WHITE, 2 ) );
|
||||||
|
|
||||||
// Labels.
|
// Labels.
|
||||||
elements.add( new Text(
|
elements.add( new Text(
|
||||||
new Coordonnees( right.getX() + OFFSET_TEXT_AXISX_X, right.getY() + OFFSET_TEXT_AXISX_Y ),
|
new Coordonnees( right.getX() + OFFSET_TEXT_AXISX_X, right.getY() + OFFSET_TEXT_AXISX_Y ),
|
||||||
XLabel, ElementsFactory.COLOR_BLACK, ElementsFactory.AXES_TEXT_SIZE
|
XLabel, ElementsFactory.COLOR_WHITE, ElementsFactory.AXES_TEXT_SIZE
|
||||||
) );
|
) );
|
||||||
elements.add( new Text(
|
elements.add( new Text(
|
||||||
new Coordonnees( top.getX() + OFFSET_TEXT_AXISY_X, top.getY() + OFFSET_TEXT_AXISY_Y ),
|
new Coordonnees( top.getX() + OFFSET_TEXT_AXISY_X, top.getY() + OFFSET_TEXT_AXISY_Y ),
|
||||||
YLabel, ElementsFactory.COLOR_BLACK, ElementsFactory.AXES_TEXT_SIZE
|
YLabel, ElementsFactory.COLOR_WHITE, ElementsFactory.AXES_TEXT_SIZE
|
||||||
));
|
));
|
||||||
|
|
||||||
return elements;
|
return elements;
|
||||||
@@ -130,12 +130,12 @@ public class SVGBuilder {
|
|||||||
elements.add(new Line(
|
elements.add(new Line(
|
||||||
coords,
|
coords,
|
||||||
new Coordonnees( coords.getX(), coords.getY() + OFFSET_TICK ),
|
new Coordonnees( coords.getX(), coords.getY() + OFFSET_TICK ),
|
||||||
ElementsFactory.COLOR_BLACK, 1
|
ElementsFactory.COLOR_WHITE, 1
|
||||||
));
|
));
|
||||||
elements.add(new Text(
|
elements.add(new Text(
|
||||||
new Coordonnees( coords.getX() + OFFSET_TEXT_X, coords.getY() + OFFSET_TEXT_Y ),
|
new Coordonnees( coords.getX() + OFFSET_TEXT_X, coords.getY() + OFFSET_TEXT_Y ),
|
||||||
X.toString(),
|
X.toString(),
|
||||||
ElementsFactory.COLOR_BLACK,
|
ElementsFactory.COLOR_WHITE,
|
||||||
SIZE_TICK_TEXT
|
SIZE_TICK_TEXT
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@@ -158,12 +158,12 @@ public class SVGBuilder {
|
|||||||
elements.add(new Line(
|
elements.add(new Line(
|
||||||
new Coordonnees(coords.getX() + OFFSET_TICK, coords.getY() ),
|
new Coordonnees(coords.getX() + OFFSET_TICK, coords.getY() ),
|
||||||
coords,
|
coords,
|
||||||
ElementsFactory.COLOR_BLACK, 1
|
ElementsFactory.COLOR_WHITE, 1
|
||||||
));
|
));
|
||||||
elements.add(new Text(
|
elements.add(new Text(
|
||||||
new Coordonnees( coords.getX() + OFFSET_TEXT_X, coords.getY() + OFFSET_TEXT_Y ),
|
new Coordonnees( coords.getX() + OFFSET_TEXT_X, coords.getY() + OFFSET_TEXT_Y ),
|
||||||
Y.toString(),
|
Y.toString(),
|
||||||
ElementsFactory.COLOR_BLACK,
|
ElementsFactory.COLOR_WHITE,
|
||||||
SIZE_TICK_TEXT
|
SIZE_TICK_TEXT
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ public class ElementsFactory {
|
|||||||
|
|
||||||
final public static int AXES_TEXT_SIZE = 10;
|
final public static int AXES_TEXT_SIZE = 10;
|
||||||
|
|
||||||
|
final public static String COLOR_WHITE = "white";
|
||||||
final public static String COLOR_RED = "red";
|
final public static String COLOR_RED = "red";
|
||||||
final public static String COLOR_BLUE = "blue";
|
final public static String COLOR_BLUE = "blue";
|
||||||
final public static String COLOR_BLACK = "black";
|
final public static String COLOR_BLACK = "black";
|
||||||
|
|||||||
Reference in New Issue
Block a user