Compare commits
7 Commits
ccd9bbf303
...
Ben8AvrilA
| Author | SHA1 | Date | |
|---|---|---|---|
| 255ad3809c | |||
| a56c59456b | |||
| c8ee9b0a37 | |||
| dc2ea03224 | |||
| 519ce77813 | |||
| 110784a530 | |||
| c62a99089d |
BIN
UML/classes.png
BIN
UML/classes.png
Binary file not shown.
|
Before Width: | Height: | Size: 240 KiB After Width: | Height: | Size: 283 KiB |
@@ -3,6 +3,7 @@
|
|||||||
namespace ecoparasite {
|
namespace ecoparasite {
|
||||||
|
|
||||||
class Application {
|
class Application {
|
||||||
|
+ {static} main
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace ecoparasite.input {
|
namespace ecoparasite.input {
|
||||||
@@ -119,30 +120,70 @@ namespace ecoparasite {
|
|||||||
|
|
||||||
namespace ecoparasite.completion {
|
namespace ecoparasite.completion {
|
||||||
class Completion {
|
class Completion {
|
||||||
+ {static} completeColumnsMoyenne
|
+ {static} completeColumnsMoyenne()
|
||||||
+ {static} completeColumnsLinear
|
+ {static} completeColumnsLinear()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace ecoparasite.nettoyage {
|
namespace ecoparasite.nettoyage {
|
||||||
class Nettoyage {
|
class Nettoyage {
|
||||||
+ {static} nettoieColumnsMoyenne
|
+ {static} nettoieColumns()
|
||||||
+ {static} nettoieColumnsLinear
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace ecoparasite.unknown {
|
namespace ecoparasite.representation {
|
||||||
|
class ValeursXY {
|
||||||
note top of ecoparasite.unknown : Ce paquet est temporaire pour des classes / interfaces qui devront avoir plus de déclinaisons.
|
- double x
|
||||||
|
- double y
|
||||||
class DataCleaner {
|
+ {static} HashSet<ValeursXY> convertToXY()
|
||||||
+ DataCleaner()
|
}
|
||||||
+ String toString()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface DataCompletion {
|
namespace ecoparasite.svg {
|
||||||
+ void exception()
|
class SVGFactory {
|
||||||
|
+ {static} createSVG()
|
||||||
|
+ {static} createSVGCode()
|
||||||
|
+ {static} createFile()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class Coordonnees {
|
||||||
|
- double x
|
||||||
|
- double y
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace ecoparasite.svg.elements {
|
||||||
|
|
||||||
|
class ElementsFactory {
|
||||||
|
+ {static} SVGAxes()
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class Element {
|
||||||
|
+ {abstract} toSVG()
|
||||||
|
}
|
||||||
|
|
||||||
|
Element o--> ecoparasite.svg.Coordonnees : # coordonnees
|
||||||
|
|
||||||
|
class Circle extends Element {
|
||||||
|
- int rayon
|
||||||
|
- String color
|
||||||
|
}
|
||||||
|
|
||||||
|
class Line extends Element {
|
||||||
|
- int lineWidth
|
||||||
|
- String color
|
||||||
|
}
|
||||||
|
|
||||||
|
class Text extends Element {
|
||||||
|
- String text
|
||||||
|
- String color
|
||||||
|
- int size
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Line o--> ecoparasite.svg.Coordonnees : # coordonneesB
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,36 @@
|
|||||||
package ecoparasite;
|
package ecoparasite;
|
||||||
|
|
||||||
|
import ecoparasite.completion.Completion;
|
||||||
|
import ecoparasite.input.InputFactory;
|
||||||
|
import ecoparasite.input.InputFileException;
|
||||||
|
import ecoparasite.input.RawData;
|
||||||
|
import ecoparasite.input.RawDataOverflow;
|
||||||
|
import ecoparasite.nettoyage.Nettoyage;
|
||||||
|
import ecoparasite.poisson.MackerelSerra;
|
||||||
|
import ecoparasite.poisson.Poisson;
|
||||||
|
import ecoparasite.representation.ValeursXY;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
public class Application {
|
public class Application {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) throws InputFileException, RawDataOverflow {
|
||||||
System.out.println("Hello World");
|
|
||||||
|
RawData rawMackerel = InputFactory.readData("test2.csv", ",");
|
||||||
|
|
||||||
|
HashSet<Poisson> mackerelSet = MackerelSerra.parse(rawMackerel);
|
||||||
|
|
||||||
|
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 );
|
||||||
|
|
||||||
|
HashSet<ValeursXY> mackerelXY = ValeursXY.convertToXY( mackerelSet, getLength, getInfes );
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -79,7 +79,7 @@ public class LectureEval {
|
|||||||
|
|
||||||
public static void main(String[] args) throws RawDataOverflow {
|
public static void main(String[] args) throws RawDataOverflow {
|
||||||
|
|
||||||
RawData popRaw;
|
RawData popRaw; int index;
|
||||||
try {
|
try {
|
||||||
popRaw = InputFactory.readData("test3.csv", "," );
|
popRaw = InputFactory.readData("test3.csv", "," );
|
||||||
} catch(InputFileException e) {
|
} catch(InputFileException e) {
|
||||||
@@ -91,30 +91,32 @@ public class LectureEval {
|
|||||||
|
|
||||||
// System.out.println( popRaw.getEntry(1) );
|
// System.out.println( popRaw.getEntry(1) );
|
||||||
|
|
||||||
|
index = 1;
|
||||||
for( Population p: pop){
|
for( Population p: pop){
|
||||||
System.out.println(p);
|
System.out.println(String.valueOf(index++) + p);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Complétion de la masse.
|
// Nettoyage de la masse.
|
||||||
Function<Population,Double> getWeight = population -> {
|
Function<Population,Double> getWeight = population -> {
|
||||||
return population.getTotal().getWidth() != null ? population.getTotal().getWidth().transformToDouble() : null;
|
return population.getTotal().getWidth() != null ? population.getTotal().getWidth().transformToDouble() : null;
|
||||||
};
|
};
|
||||||
BiConsumer<Population,Double> setWeight = (population, aDouble) -> {
|
BiConsumer<Population,Double> setWeight = (population, aDouble) -> {
|
||||||
population.getTotal().setWidth(new PopulationArgInterval(aDouble,aDouble));
|
population.getTotal().setWidth(aDouble != null ? new PopulationArgInterval(aDouble,aDouble) : null);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pop = Nettoyage.nettoieColumns(pop, getWeight, setWeight, false);
|
||||||
|
System.out.println("---");
|
||||||
|
index = 1;
|
||||||
|
for( Population p: pop){
|
||||||
|
System.out.println(String.valueOf(index++) + p);
|
||||||
|
}
|
||||||
|
|
||||||
// Complétion de la masse.
|
// Complétion de la masse.
|
||||||
pop = Completion.completeColumnsMoyenne(pop, getWeight, setWeight);
|
pop = Completion.completeColumnsMoyenne(pop, getWeight, setWeight);
|
||||||
System.out.println("---");
|
System.out.println("---");
|
||||||
|
index = 1;
|
||||||
for( Population p: pop){
|
for( Population p: pop){
|
||||||
System.out.println(p);
|
System.out.println(String.valueOf(index++) + p);
|
||||||
}
|
|
||||||
|
|
||||||
// Nettoyage de la masse.
|
|
||||||
pop = Nettoyage.nettoieColumnsMoyenne(pop, getWeight, setWeight, false);
|
|
||||||
System.out.println("---");
|
|
||||||
for( Population p: pop){
|
|
||||||
System.out.println(p);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,31 @@ import java.util.function.Function;
|
|||||||
*/
|
*/
|
||||||
public class Nettoyage {
|
public class Nettoyage {
|
||||||
|
|
||||||
|
public static <T,V extends Number> HashSet<T> nettoieColumns(HashSet<T> list, Function<T,V> getValue, BiConsumer<T,V> setValue, boolean allowNegative ){
|
||||||
|
|
||||||
|
ArrayList<Double> array = new ArrayList<>();
|
||||||
|
for ( T item : list) {
|
||||||
|
if (getValue.apply(item)!= null){ //Test des valeurs null pour les Tests Unitaires. Je ne devrais pas en avoir.
|
||||||
|
array.add(getValue.apply(item).doubleValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Collections.sort(array);
|
||||||
|
|
||||||
|
int quartIndex = array.size()/4;
|
||||||
|
Double firstQuart = array.get(quartIndex);
|
||||||
|
Double thirdQuart = array.get(quartIndex *3);
|
||||||
|
Double IQR = thirdQuart - firstQuart;
|
||||||
|
|
||||||
|
for(T item : list){
|
||||||
|
if( getValue.apply(item) == null || getValue.apply(item).doubleValue() < firstQuart - (IQR * 1.5) || getValue.apply(item).doubleValue() > thirdQuart + (IQR * 1.5) || ( !allowNegative && getValue.apply(item).doubleValue() < 0 ) ){
|
||||||
|
setValue.accept( item, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Permet de remplacer les valeurs abérrantes d'un paramètre d'un HashSet par la moyenne des autres valeurs (non nulles).
|
* Permet de remplacer les valeurs abérrantes d'un paramètre d'un HashSet par la moyenne des autres valeurs (non nulles).
|
||||||
* Exemple d'utilisation : T = Poisson, V = Double, getValue = Poisson::getInfestation, setValue = Poisson::setInfestation.
|
* Exemple d'utilisation : T = Poisson, V = Double, getValue = Poisson::getInfestation, setValue = Poisson::setInfestation.
|
||||||
@@ -26,6 +51,7 @@ public class Nettoyage {
|
|||||||
* @param <T> Le type de données cobaye. Exemple : Poisson, Population
|
* @param <T> Le type de données cobaye. Exemple : Poisson, Population
|
||||||
* @param <V> Le type de la donnée à vérifier, doit être un Wrapper Number. Exemple : Double.
|
* @param <V> Le type de la donnée à vérifier, doit être un Wrapper Number. Exemple : Double.
|
||||||
*/
|
*/
|
||||||
|
/*
|
||||||
public static <T,V extends Number> HashSet<T> nettoieColumnsMoyenne(HashSet<T> list, Function<T,V> getValue, BiConsumer<T,V> setValue, boolean allowNegative ){
|
public static <T,V extends Number> HashSet<T> nettoieColumnsMoyenne(HashSet<T> list, Function<T,V> getValue, BiConsumer<T,V> setValue, boolean allowNegative ){
|
||||||
|
|
||||||
Double mean = Completion.calculateMean(list, getValue);
|
Double mean = Completion.calculateMean(list, getValue);
|
||||||
@@ -52,6 +78,7 @@ public class Nettoyage {
|
|||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Polymorphisme de la fonction précédente. Autorise les valeurs abérrantes à être négative.
|
* Polymorphisme de la fonction précédente. Autorise les valeurs abérrantes à être négative.
|
||||||
@@ -62,10 +89,10 @@ public class Nettoyage {
|
|||||||
* @param <T>
|
* @param <T>
|
||||||
* @param <V>
|
* @param <V>
|
||||||
*
|
*
|
||||||
* @see Nettoyage::nettoieColumnsMoyenne
|
* @see Nettoyage::nettoieColumns
|
||||||
*/
|
*/
|
||||||
public static <T,V extends Number> HashSet<T> nettoieColumnsMoyenne(HashSet<T> list, Function<T,V> getValue, BiConsumer<T,V> setValue){
|
public static <T,V extends Number> HashSet<T> nettoieColumns(HashSet<T> list, Function<T,V> getValue, BiConsumer<T,V> setValue){
|
||||||
return nettoieColumnsMoyenne(list, getValue, setValue, true);
|
return nettoieColumns(list, getValue, setValue, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -81,6 +108,7 @@ public class Nettoyage {
|
|||||||
* @param <T> Le type de données cobaye. Exemple : Poisson, Population
|
* @param <T> Le type de données cobaye. Exemple : Poisson, Population
|
||||||
* @param <V> Le type de la donnée à vérifier, doit être un Wrapper Number. Exemple : Double.
|
* @param <V> Le type de la donnée à vérifier, doit être un Wrapper Number. Exemple : Double.
|
||||||
*/
|
*/
|
||||||
|
/*
|
||||||
public static <T,V extends Number> HashSet<T> nettoieColumnsLinear(HashSet<T> list, Function<T,V> getX, Function<T,V> getY, BiConsumer<T,V> setY, boolean allowNegative ){
|
public static <T,V extends Number> HashSet<T> nettoieColumnsLinear(HashSet<T> list, Function<T,V> getX, Function<T,V> getY, BiConsumer<T,V> setY, boolean allowNegative ){
|
||||||
|
|
||||||
double meanX = Completion.calculateMean(list, getX);
|
double meanX = Completion.calculateMean(list, getX);
|
||||||
@@ -112,6 +140,7 @@ public class Nettoyage {
|
|||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Polymorphisme de la fonction nettoyage de colonne linéaire avec par défaut, l'autorisation des valeurs négatives.
|
* Polymorphisme de la fonction nettoyage de colonne linéaire avec par défaut, l'autorisation des valeurs négatives.
|
||||||
@@ -123,7 +152,9 @@ public class Nettoyage {
|
|||||||
* @param <T>
|
* @param <T>
|
||||||
* @param <V>
|
* @param <V>
|
||||||
*/
|
*/
|
||||||
|
/*
|
||||||
public static <T,V extends Number> HashSet<T> nettoieColumnsLinear(HashSet<T> list, Function<T,V> getX, Function<T,V> getY, BiConsumer<T,V> setY){
|
public static <T,V extends Number> HashSet<T> nettoieColumnsLinear(HashSet<T> list, Function<T,V> getX, Function<T,V> getY, BiConsumer<T,V> setY){
|
||||||
return nettoieColumnsLinear(list, getX, getY, setY, true);
|
return nettoieColumnsLinear(list, getX, getY, setY, true);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|||||||
46
src/ecoparasite/representation/ValeursXY.java
Normal file
46
src/ecoparasite/representation/ValeursXY.java
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
package ecoparasite.representation;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
public class ValeursXY {
|
||||||
|
|
||||||
|
private double x;
|
||||||
|
private double y;
|
||||||
|
|
||||||
|
public ValeursXY(double x, double y){
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getX() {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
public void setX(double x) {
|
||||||
|
this.x = x;
|
||||||
|
}
|
||||||
|
public double getY() {
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
public void setY(double y) {
|
||||||
|
this.y = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T,V extends Number> HashSet<ValeursXY> convertToXY(HashSet<T> list, Function<T,V> getX, Function<T,V> getY){
|
||||||
|
HashSet<ValeursXY> xy = new HashSet<ValeursXY>();
|
||||||
|
for(T item : list){
|
||||||
|
if(getX.apply(item) != null && getY.apply(item) != null){
|
||||||
|
xy.add( new ValeursXY(getX.apply(item).doubleValue(), getY.apply(item).doubleValue()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return xy;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
public static ValeursXY getMinX( HashSet<ValeursXY> list ){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
}
|
||||||
27
src/ecoparasite/svg/Coordonnees.java
Normal file
27
src/ecoparasite/svg/Coordonnees.java
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package ecoparasite.svg;
|
||||||
|
|
||||||
|
public class Coordonnees {
|
||||||
|
|
||||||
|
private double x;
|
||||||
|
private double y;
|
||||||
|
|
||||||
|
public Coordonnees(double x, double y) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getX() {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
public void setX(double x) {
|
||||||
|
this.x = x;
|
||||||
|
}
|
||||||
|
public double getY() {
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
public void setY(double y) {
|
||||||
|
this.y = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
76
src/ecoparasite/svg/SVGFactory.java
Normal file
76
src/ecoparasite/svg/SVGFactory.java
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
package ecoparasite.svg;
|
||||||
|
|
||||||
|
import ecoparasite.svg.elements.Element;
|
||||||
|
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class SVGFactory {
|
||||||
|
|
||||||
|
static final private String EXPORT_PATH = "export/";
|
||||||
|
static final private String EXTENSION = ".svg";
|
||||||
|
|
||||||
|
public static boolean createSVG(ArrayList<Element> mesElements){
|
||||||
|
|
||||||
|
String code = createSVGCode(mesElements);
|
||||||
|
|
||||||
|
try {
|
||||||
|
createFile(code);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean createSVG(ArrayList<Element> mesElements, String filename) {
|
||||||
|
|
||||||
|
String code = createSVGCode(mesElements);
|
||||||
|
|
||||||
|
try {
|
||||||
|
createFile(code,filename);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String createSVGCode(ArrayList<Element> mesElements){
|
||||||
|
|
||||||
|
String code = "<svg height=\"800\" width=\"800\" >";
|
||||||
|
|
||||||
|
for (Element e : mesElements){
|
||||||
|
|
||||||
|
code += e.toSVG();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
code += "</svg>";
|
||||||
|
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void createFile(String data) throws IOException {
|
||||||
|
String id = UUID.randomUUID().toString();
|
||||||
|
createFile(data,id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void createFile(String data, String filename) throws IOException {
|
||||||
|
|
||||||
|
// create a FileWriter object with the file name
|
||||||
|
FileWriter writer = new FileWriter(EXPORT_PATH + filename + EXTENSION);
|
||||||
|
|
||||||
|
// write the string to the file
|
||||||
|
writer.write(data);
|
||||||
|
|
||||||
|
// close the writer
|
||||||
|
writer.close();
|
||||||
|
|
||||||
|
System.out.println("Successfully wrote text to file.");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
49
src/ecoparasite/svg/elements/Circle.java
Normal file
49
src/ecoparasite/svg/elements/Circle.java
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
package ecoparasite.svg.elements;
|
||||||
|
|
||||||
|
import ecoparasite.svg.Coordonnees;
|
||||||
|
|
||||||
|
public class Circle extends Element {
|
||||||
|
|
||||||
|
private int rayon;
|
||||||
|
private String color;
|
||||||
|
|
||||||
|
public Circle(Coordonnees coordonnees, int rayon, String color) {
|
||||||
|
super(coordonnees);
|
||||||
|
this.rayon = rayon;
|
||||||
|
this.color = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Circle(Coordonnees coordonnees, int rayon) {
|
||||||
|
super(coordonnees);
|
||||||
|
this.rayon = rayon;
|
||||||
|
this.color = ElementsFactory.COLOR_RED;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRayon() {
|
||||||
|
return rayon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRayon(int rayon) {
|
||||||
|
this.rayon = rayon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getColor() {
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColor(String color) {
|
||||||
|
this.color = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toSVG() {
|
||||||
|
StringBuilder svg = new StringBuilder();
|
||||||
|
svg.append("<circle ");
|
||||||
|
|
||||||
|
String str = String.format( "r=\"%d\" cx=\"%d\" cy=\"%d\" fill=\"%s\"", this.rayon, this.coordonnees.getX(), this.coordonnees.getY(), this.color);
|
||||||
|
svg.append( str );
|
||||||
|
svg.append(" />");
|
||||||
|
|
||||||
|
return svg.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
31
src/ecoparasite/svg/elements/Element.java
Normal file
31
src/ecoparasite/svg/elements/Element.java
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package ecoparasite.svg.elements;
|
||||||
|
|
||||||
|
import ecoparasite.svg.Coordonnees;
|
||||||
|
|
||||||
|
abstract public class Element {
|
||||||
|
|
||||||
|
protected Coordonnees coordonnees;
|
||||||
|
|
||||||
|
public Element(Coordonnees coordonnees) {
|
||||||
|
this.coordonnees = coordonnees;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Coordonnees getCoordonnees() {
|
||||||
|
return coordonnees;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCoordonnees(Coordonnees coordonnees) {
|
||||||
|
this.coordonnees = coordonnees;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCoordonnees(int x, int y) {
|
||||||
|
this.coordonnees = new Coordonnees(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Méthode abstraite qui va permettre de transformer notre élément en SVG.
|
||||||
|
* @return La String SVF
|
||||||
|
*/
|
||||||
|
abstract public String toSVG();
|
||||||
|
|
||||||
|
}
|
||||||
68
src/ecoparasite/svg/elements/ElementsFactory.java
Normal file
68
src/ecoparasite/svg/elements/ElementsFactory.java
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
package ecoparasite.svg.elements;
|
||||||
|
|
||||||
|
import ecoparasite.svg.Coordonnees;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
public class ElementsFactory {
|
||||||
|
|
||||||
|
final public static int SVG_SIZE = 800;
|
||||||
|
final public static int SVG_OFFSET = 50;
|
||||||
|
|
||||||
|
final public static int AXES_TEXT_SIZE = 10;
|
||||||
|
|
||||||
|
final public static String COLOR_RED = "red";
|
||||||
|
final public static String COLOR_BLUE = "blue";
|
||||||
|
final public static String COLOR_BLACK = "black";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Permet de générer les éléments axes du fichier SVG.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static ArrayList<Element> SVGAxes(String HName, String VName ){
|
||||||
|
|
||||||
|
final int begin = SVG_OFFSET + AXES_TEXT_SIZE + (AXES_TEXT_SIZE / 2);
|
||||||
|
final int end = SVG_SIZE - SVG_OFFSET - AXES_TEXT_SIZE - (AXES_TEXT_SIZE / 2);
|
||||||
|
|
||||||
|
Element V = new Line(
|
||||||
|
new Coordonnees( begin, begin ),
|
||||||
|
new Coordonnees( begin, SVG_SIZE - SVG_OFFSET ),
|
||||||
|
COLOR_BLACK,
|
||||||
|
2
|
||||||
|
);
|
||||||
|
|
||||||
|
Element H = new Line(
|
||||||
|
new Coordonnees( begin, SVG_SIZE - SVG_OFFSET ),
|
||||||
|
new Coordonnees( end, SVG_SIZE - SVG_OFFSET ),
|
||||||
|
COLOR_BLACK,
|
||||||
|
2
|
||||||
|
);
|
||||||
|
|
||||||
|
Element VLabel = new Text(
|
||||||
|
new Coordonnees( SVG_OFFSET, SVG_OFFSET ),
|
||||||
|
VName,
|
||||||
|
COLOR_BLACK,
|
||||||
|
AXES_TEXT_SIZE
|
||||||
|
);
|
||||||
|
Element HLabel = new Text(
|
||||||
|
new Coordonnees( SVG_SIZE - SVG_OFFSET - AXES_TEXT_SIZE, SVG_SIZE - SVG_OFFSET - AXES_TEXT_SIZE ),
|
||||||
|
HName,
|
||||||
|
COLOR_BLACK,
|
||||||
|
AXES_TEXT_SIZE
|
||||||
|
);
|
||||||
|
|
||||||
|
ArrayList<Element> SVGAxes = new ArrayList<>();
|
||||||
|
SVGAxes.add(V);
|
||||||
|
SVGAxes.add(H);
|
||||||
|
SVGAxes.add(VLabel);
|
||||||
|
SVGAxes.add(HLabel);
|
||||||
|
return SVGAxes;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ArrayList<Element> SVGAxes(){
|
||||||
|
return SVGAxes( "None", "None" );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
76
src/ecoparasite/svg/elements/Line.java
Normal file
76
src/ecoparasite/svg/elements/Line.java
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
package ecoparasite.svg.elements;
|
||||||
|
|
||||||
|
import ecoparasite.svg.Coordonnees;
|
||||||
|
|
||||||
|
public class Line extends Element {
|
||||||
|
|
||||||
|
private Coordonnees coordonneesB;
|
||||||
|
private String color;
|
||||||
|
private int lineWidth;
|
||||||
|
|
||||||
|
public Line(Coordonnees coordonneesA, Coordonnees coordonneesB, String color, int lineWidth) {
|
||||||
|
super(coordonneesA);
|
||||||
|
this.coordonneesB = coordonneesB;
|
||||||
|
this.color = color;
|
||||||
|
this.lineWidth = lineWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Line(Coordonnees coordonneesA, Coordonnees coordonneesB) {
|
||||||
|
super(coordonneesA);
|
||||||
|
this.coordonneesB = coordonneesB;
|
||||||
|
this.color = ElementsFactory.COLOR_RED;
|
||||||
|
this.lineWidth = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Coordonnees getCoordonneesA() {
|
||||||
|
return coordonnees;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCoordonneesA(Coordonnees coordonnees) {
|
||||||
|
this.coordonnees = coordonnees;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Coordonnees getCoordonneesB() {
|
||||||
|
return coordonneesB;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCoordonneesB(Coordonnees coordonnees) {
|
||||||
|
this.coordonneesB = coordonnees;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getColor() {
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColor(String color) {
|
||||||
|
this.color = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLineWidth() {
|
||||||
|
return lineWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLineWidth(int lineWidth) {
|
||||||
|
this.lineWidth = lineWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toSVG() {
|
||||||
|
StringBuilder svg = new StringBuilder();
|
||||||
|
svg.append("<line ");
|
||||||
|
|
||||||
|
String params = String.format( "x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" style=\"stroke:%s;stroke-width:%d\"",
|
||||||
|
this.coordonnees.getX(),
|
||||||
|
this.coordonnees.getY(),
|
||||||
|
this.coordonneesB.getX(),
|
||||||
|
this.coordonneesB.getY(),
|
||||||
|
this.color,
|
||||||
|
this.lineWidth
|
||||||
|
);
|
||||||
|
svg.append(params);
|
||||||
|
svg.append( "/>" );
|
||||||
|
|
||||||
|
return svg.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
62
src/ecoparasite/svg/elements/Text.java
Normal file
62
src/ecoparasite/svg/elements/Text.java
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
package ecoparasite.svg.elements;
|
||||||
|
|
||||||
|
import ecoparasite.svg.Coordonnees;
|
||||||
|
|
||||||
|
public class Text extends Element {
|
||||||
|
|
||||||
|
private String text;
|
||||||
|
private String color;
|
||||||
|
private int size;
|
||||||
|
|
||||||
|
public Text(Coordonnees coordonnees, String text, String color, int size) {
|
||||||
|
super(coordonnees);
|
||||||
|
this.text = text;
|
||||||
|
this.color = color;
|
||||||
|
this.size = size;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Text(Coordonnees coordonnees, String text) {
|
||||||
|
super(coordonnees);
|
||||||
|
this.text = text;
|
||||||
|
this.color = ElementsFactory.COLOR_BLACK;
|
||||||
|
this.size = ElementsFactory.AXES_TEXT_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getText() {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setText(String text) {
|
||||||
|
this.text = text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getColor() {
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColor(String color) {
|
||||||
|
this.color = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSize() {
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSize(int size) {
|
||||||
|
this.size = size;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toSVG() {
|
||||||
|
StringBuilder svg = new StringBuilder();
|
||||||
|
svg.append("<text ");
|
||||||
|
|
||||||
|
String params = String.format( "x=\"%d\" y=\"%d\" fill=\"%s\" font-size=\"%s\"", coordonnees.getX(), coordonnees.getY(), color, size);
|
||||||
|
svg.append(params);
|
||||||
|
svg.append(" >");
|
||||||
|
svg.append( this.text );
|
||||||
|
svg.append("</text>");
|
||||||
|
return svg.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ import ecoparasite.input.InputFactory;
|
|||||||
import ecoparasite.input.InputFileException;
|
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.poisson.Mackerel;
|
import ecoparasite.poisson.Mackerel;
|
||||||
import ecoparasite.poisson.Poisson;
|
import ecoparasite.poisson.Poisson;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@@ -44,6 +45,7 @@ class CompletionTest {
|
|||||||
Function<Poisson,Double> getInfes = Poisson::getInfestation;
|
Function<Poisson,Double> getInfes = Poisson::getInfestation;
|
||||||
BiConsumer<Poisson,Double> setInfes = Poisson::setInfestation;
|
BiConsumer<Poisson,Double> setInfes = Poisson::setInfestation;
|
||||||
|
|
||||||
|
testp = Nettoyage.nettoieColumns(testp,getInfes,setInfes,false);
|
||||||
testp = Completion.completeColumnsLinear(testp,getLength,getInfes,setInfes);
|
testp = Completion.completeColumnsLinear(testp,getLength,getInfes,setInfes);
|
||||||
System.out.println(testp);
|
System.out.println(testp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class NettoyageTest {
|
|||||||
|
|
||||||
System.out.println(testp);
|
System.out.println(testp);
|
||||||
|
|
||||||
testp = Nettoyage.nettoieColumnsMoyenne( testp, getInfes, setInfes );
|
// testp = Nettoyage.nettoieColumnsMoyenne( testp, getInfes, setInfes );
|
||||||
|
|
||||||
System.out.println(testp);
|
System.out.println(testp);
|
||||||
}
|
}
|
||||||
@@ -50,11 +50,7 @@ class NettoyageTest {
|
|||||||
Function<Poisson,Double> getInfes = Poisson::getInfestation;
|
Function<Poisson,Double> getInfes = Poisson::getInfestation;
|
||||||
BiConsumer<Poisson,Double> setInfes = Poisson::setInfestation;
|
BiConsumer<Poisson,Double> setInfes = Poisson::setInfestation;
|
||||||
|
|
||||||
testp = Completion.completeColumnsLinear( testp, getLength, getInfes, setInfes );
|
testp = Nettoyage.nettoieColumns( testp, getInfes, setInfes, false );
|
||||||
|
|
||||||
System.out.println(testp);
|
|
||||||
|
|
||||||
testp = Nettoyage.nettoieColumnsLinear( testp, getLength, getInfes, setInfes, false );
|
|
||||||
|
|
||||||
System.out.println(testp);
|
System.out.println(testp);
|
||||||
}
|
}
|
||||||
|
|||||||
15
tests/ecoparasite/svg/SVGFactoryTest.java
Normal file
15
tests/ecoparasite/svg/SVGFactoryTest.java
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package ecoparasite.svg;
|
||||||
|
|
||||||
|
import ecoparasite.svg.elements.ElementsFactory;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class SVGFactoryTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void generateSVGAxes(){
|
||||||
|
SVGFactory.createSVG( ElementsFactory.SVGAxes() );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user