4 Commits

Author SHA1 Message Date
90ebe64393 JavaDoc et Gradation des axes Dones 2026-04-22 11:17:31 +02:00
35274a963b JavaDoc 2026-04-22 11:05:14 +02:00
7305393f6c JavaDoc 2026-04-20 16:39:00 +02:00
c13bb289ed JavaDoc 2026-04-08 16:00:42 +02:00
10 changed files with 186 additions and 223 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 283 KiB

After

Width:  |  Height:  |  Size: 240 KiB

View File

@@ -3,7 +3,6 @@
namespace ecoparasite { namespace ecoparasite {
class Application { class Application {
+ {static} main
} }
namespace ecoparasite.input { namespace ecoparasite.input {
@@ -120,70 +119,30 @@ 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} nettoieColumns() + {static} nettoieColumnsMoyenne
+ {static} nettoieColumnsLinear
} }
} }
namespace ecoparasite.representation { namespace ecoparasite.unknown {
class ValeursXY {
- double x
- double y
+ {static} HashSet<ValeursXY> convertToXY()
}
}
namespace ecoparasite.svg { note top of ecoparasite.unknown : Ce paquet est temporaire pour des classes / interfaces qui devront avoir plus de déclinaisons.
class SVGFactory {
+ {static} createSVG() class DataCleaner {
+ {static} createSVGCode() + DataCleaner()
+ {static} createFile() + String toString()
} }
class Coordonnees { interface DataCompletion {
- double x + void exception()
- 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
} }
} }

View File

@@ -27,8 +27,8 @@ public class Application {
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, getInfes, setInfes, false );
mackerelSet = Completion.completeColumnsLinear( mackerelSet, getLength, getInfes, setInfes ); mackerelSet = Completion.completeColumnsLinear( mackerelSet, getLength, getInfes, setInfes );
mackerelSet = Nettoyage.nettoieColumnsLinear( mackerelSet, getLength, getInfes, setInfes, false );
HashSet<ValeursXY> mackerelXY = ValeursXY.convertToXY( mackerelSet, getLength, getInfes ); HashSet<ValeursXY> mackerelXY = ValeursXY.convertToXY( mackerelSet, getLength, getInfes );

View File

@@ -1,124 +0,0 @@
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.Poisson;
import ecoparasite.population.Population;
import ecoparasite.population.PopulationArgInterval;
import ecoparasite.population.PopulationArgs;
import java.util.HashMap;
import java.util.HashSet;
import java.util.function.BiConsumer;
import java.util.function.Function;
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; int index;
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) );
index = 1;
for( Population p: pop){
System.out.println(String.valueOf(index++) + p);
}
// Nettoyage 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(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.
pop = Completion.completeColumnsMoyenne(pop, getWeight, setWeight);
System.out.println("---");
index = 1;
for( Population p: pop){
System.out.println(String.valueOf(index++) + p);
}
}
}

View File

@@ -14,31 +14,6 @@ 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.
@@ -51,7 +26,6 @@ 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);
@@ -78,7 +52,6 @@ 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.
@@ -89,10 +62,10 @@ public class Nettoyage {
* @param <T> * @param <T>
* @param <V> * @param <V>
* *
* @see Nettoyage::nettoieColumns * @see Nettoyage::nettoieColumnsMoyenne
*/ */
public static <T,V extends Number> HashSet<T> nettoieColumns(HashSet<T> list, Function<T,V> getValue, BiConsumer<T,V> setValue){ public static <T,V extends Number> HashSet<T> nettoieColumnsMoyenne(HashSet<T> list, Function<T,V> getValue, BiConsumer<T,V> setValue){
return nettoieColumns(list, getValue, setValue, true); return nettoieColumnsMoyenne(list, getValue, setValue, true);
} }
/** /**
@@ -108,7 +81,6 @@ 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);
@@ -140,7 +112,6 @@ 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.
@@ -152,9 +123,7 @@ 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);
} }
*/
} }

View File

@@ -77,6 +77,13 @@ public class Poisson{
this.infestation = infestation; this.infestation = infestation;
} }
/**
* Setter de l'attribut length
* @param length le Double de la nouvelle valeur de la length
*/
public void setLength(Double length) {
this.length = length;
}
/** /**
* Setter de l'attribut des parties de poisson. * Setter de l'attribut des parties de poisson.
@@ -95,4 +102,6 @@ public class Poisson{
String result = "[ %5s : %4f mm, %4f g, %4f taux d'infestation ]"; String result = "[ %5s : %4f mm, %4f g, %4f taux d'infestation ]";
return String.format(result, this.getClass().getSimpleName(), this.getLength(), this.getWeight(), this.getInfestation() ); return String.format(result, this.getClass().getSimpleName(), this.getLength(), this.getWeight(), this.getInfestation() );
} }
} }

View File

@@ -36,11 +36,4 @@ public class ValeursXY {
return xy; return xy;
} }
/*
public static ValeursXY getMinX( HashSet<ValeursXY> list ){
}
*/
} }

View File

@@ -1,10 +1,13 @@
package ecoparasite.svg; package ecoparasite.svg;
import ecoparasite.representation.ValeursXY;
import ecoparasite.svg.elements.Element; import ecoparasite.svg.elements.Element;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.UUID; import java.util.UUID;
public class SVGFactory { public class SVGFactory {
@@ -12,6 +15,11 @@ public class SVGFactory {
static final private String EXPORT_PATH = "export/"; static final private String EXPORT_PATH = "export/";
static final private String EXTENSION = ".svg"; static final private String EXTENSION = ".svg";
/**
* Permet la création du fichier SVG
* @param mesElements un array des elements à ajouter dans le svg
* @return True si la création est un succès, False sinon
*/
public static boolean createSVG(ArrayList<Element> mesElements){ public static boolean createSVG(ArrayList<Element> mesElements){
String code = createSVGCode(mesElements); String code = createSVGCode(mesElements);
@@ -25,6 +33,12 @@ public class SVGFactory {
return true; return true;
} }
/**
* Permet la création du fichier SVG (Polymorphisme pour ajouter un nom de fichier)
* @param mesElements un Array des elements à ajouter dans le SVG
* @param filename une String représentant le nom du fichier choisi
* @return True si la création est un succès, False sinon
*/
public static boolean createSVG(ArrayList<Element> mesElements, String filename) { public static boolean createSVG(ArrayList<Element> mesElements, String filename) {
String code = createSVGCode(mesElements); String code = createSVGCode(mesElements);
@@ -38,6 +52,11 @@ public class SVGFactory {
return true; return true;
} }
/**
* Fonction basique de transformation des éléments en code SVG
* @param mesElements un array contenant les éléments à mettre dans le svg
* @return une String contenant la totalité du code SVG de notre graphique
*/
public static String createSVGCode(ArrayList<Element> mesElements){ public static String createSVGCode(ArrayList<Element> mesElements){
String code = "<svg height=\"800\" width=\"800\" >"; String code = "<svg height=\"800\" width=\"800\" >";
@@ -53,11 +72,22 @@ public class SVGFactory {
return code; return code;
} }
/**
* fonction qui créer le fichier, ici avec une ID random comme nom de fichier
* @param data une String contenant le contenue du fichier désiré (ici pour le SVG)
* @throws IOException Déclenché par un échec de la création du fichier
*/
public static void createFile(String data) throws IOException { public static void createFile(String data) throws IOException {
String id = UUID.randomUUID().toString(); String id = UUID.randomUUID().toString();
createFile(data,id); createFile(data,id);
} }
/**
* Permet la création du fichier
* @param data une String contenant le contenue du fichier désiré
* @param filename une String contenant le nom du fichier voulu
* @throws IOException Déclenché par un échec de la création du fichier
*/
public static void createFile(String data, String filename) throws IOException { public static void createFile(String data, String filename) throws IOException {
// create a FileWriter object with the file name // create a FileWriter object with the file name
@@ -73,4 +103,129 @@ public class SVGFactory {
} }
/**
* Permet de renvoyer des valeurs "clean" pour l'affichage des axes
* @param h Contient les Coordonnées de chacun des points de nos données
* @return une HashMap de String et de Hashset de Double.
* Avec la String "AxeX", un Hashset de Double contenant les valeurs des gradations de l'axe X
* Avec la String "AxeY", un Hashset de Double contenant les valeurs des gragations de l'axe Y
* Avec la String "OffsetX", un Hashset de Double contenant uniquement la valeur de l'offset des points par rapport à l'axe X
* Avec la String "OffsetY", un Hashset de Double contenant uniquement la valeur de l'offset des points par rapport à l'axe Y
*/
public static HashMap< String ,HashSet<Double>> PointAXES(HashSet<ValeursXY> h){
HashMap< String, HashSet<Double> > map = new HashMap<>();
//Définition des min et max
double max_x = Double.MIN_VALUE;
double min_x = Double.MAX_VALUE;
double max_y = Double.MIN_VALUE;
double min_y = Double.MAX_VALUE;
//Trouvé les min et max
for (ValeursXY var : h) {
if (max_x < var.getX()){
max_x = var.getX();
} else if (min_x > var.getX()){
min_x = var.getX();
}
if (max_y < var.getY()){
max_y = var.getY();
} else if (min_y > var.getY()){
min_y = var.getY();
}
}
double range_x = max_x-min_x;
double range_y = max_y-min_y;
int target = 10; // Ideal Number of Gradation
double step_x = niceStep(range_x,target);
double step_y = niceStep(range_y,target);
double nicemin_x = roundMin(min_x,step_x);
double nicemax_x = roundMax(max_x,step_x);
double nicemin_y = roundMin(min_y,step_y);
double nicemax_y = roundMax(max_y,step_y);
// Compléter un Hashset de Double pour X et pour Y et Offset X et Y. TODO
HashSet<Double> axeX = new HashSet<>();
HashSet<Double> axeY = new HashSet<>();
HashSet<Double> OffsetX = new HashSet<>();
HashSet<Double> OffsetY = new HashSet<>();
Double ix = nicemin_x;
while ( ix <= nicemax_x ) {
axeX.add(ix);
ix+=step_x;
};
map.put("AxeX", axeX);
Double iy = nicemin_y;
while ( iy <= nicemax_y ) {
axeY.add(iy);
iy+=step_y;
}
map.put("AxeY",axeY);
double offsetX = min_x - nicemin_x;
double offsetY = min_y - nicemin_y;
HashSet<Double> offsetXHash = new HashSet<>();
offsetXHash.add(offsetX);
HashSet<Double> offsetYHash = new HashSet<>();
offsetYHash.add(offsetY);
map.put("OffsetX", offsetXHash);
map.put("OffsetY", offsetYHash);
return map;
}
/**
* Fonction de calcul d'un step rond
* Cette fonction est basé sur une idée demandée à ChatGPT
* @param range écart entre la plus petite et la plus grande valeur
* @param targetTicks nombre de gradation ideal
* @return
*/
public static double niceStep(double range, int targetTicks) {
double rawStep = range / targetTicks;
double exponent = Math.floor(Math.log10(rawStep));
double fraction = rawStep / Math.pow(10, exponent);
double niceFraction;
if (fraction < 1.5)
niceFraction = 1;
else if (fraction < 3)
niceFraction = 2;
else if (fraction < 7)
niceFraction = 5;
else
niceFraction = 10;
return niceFraction * Math.pow(10, exponent);
}
/**
* retourne une valeur arrondi "joli" adapter à un graphique
* @param value
* @param step
* @return
*/
public static double roundMin(double value, double step) {
return Math.floor(value / step) * step;
}
public static double roundMax(double value, double step) {
return Math.ceil(value / step) * step;
}
} }

View File

@@ -4,7 +4,6 @@ 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;
@@ -45,7 +44,6 @@ 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);
} }

View File

@@ -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,7 +50,11 @@ 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 = Nettoyage.nettoieColumns( testp, getInfes, setInfes, false ); testp = Completion.completeColumnsLinear( testp, getLength, getInfes, setInfes );
System.out.println(testp);
testp = Nettoyage.nettoieColumnsLinear( testp, getLength, getInfes, setInfes, false );
System.out.println(testp); System.out.println(testp);
} }