8 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
c8ee9b0a37 Merge pull request 'Ben8Avril' (#12) from Ben8Avril into master
Reviewed-on: #12
2026-04-08 12:48:21 +00:00
dc2ea03224 Merge branch 'master' into Ben8Avril 2026-04-08 12:48:14 +00:00
519ce77813 Merge remote-tracking branch 'origin/Ben8Avril' into Ben8Avril 2026-04-08 14:47:46 +02:00
110784a530 Begin SVG. 2026-04-08 14:47:42 +02:00
12 changed files with 638 additions and 124 deletions

View File

@@ -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 = Completion.completeColumnsLinear( mackerelSet, getLength, getInfes, setInfes );
mackerelSet = Nettoyage.nettoieColumnsLinear( mackerelSet, getLength, getInfes, setInfes, false );
HashSet<ValeursXY> mackerelXY = ValeursXY.convertToXY( mackerelSet, getLength, getInfes );
} }
} }

View File

@@ -1,122 +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;
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);
}
// 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);
}
}
}

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

@@ -0,0 +1,39 @@
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;
}
}

View 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;
}
}

View File

@@ -0,0 +1,231 @@
package ecoparasite.svg;
import ecoparasite.representation.ValeursXY;
import ecoparasite.svg.elements.Element;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.UUID;
public class SVGFactory {
static final private String EXPORT_PATH = "export/";
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){
String code = createSVGCode(mesElements);
try {
createFile(code);
} catch (Exception e) {
return false;
}
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) {
String code = createSVGCode(mesElements);
try {
createFile(code,filename);
} catch (Exception e) {
return false;
}
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){
String code = "<svg height=\"800\" width=\"800\" >";
for (Element e : mesElements){
code += e.toSVG();
}
code += "</svg>";
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 {
String id = UUID.randomUUID().toString();
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 {
// 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.");
}
/**
* 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

@@ -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();
}
}

View 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();
}

View 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" );
}
}

View 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();
}
}

View 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();
}
}

View 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() );
}
}