Compare commits
16 Commits
Ben8AvrilA
...
d227208578
| Author | SHA1 | Date | |
|---|---|---|---|
| d227208578 | |||
| 9c006f94fb | |||
| d0a5315ca2 | |||
| 7b3e3f8829 | |||
| 3fd7ef15b4 | |||
| 1b9efaa239 | |||
| 96cdac60eb | |||
| 82901f623b | |||
| 8ac87e9edb | |||
| e48826b765 | |||
| 7800a92dae | |||
| 90ebe64393 | |||
| 35274a963b | |||
| 7305393f6c | |||
| c13bb289ed | |||
| c9dbe7dc3b |
BIN
UML/classes.png
BIN
UML/classes.png
Binary file not shown.
|
Before Width: | Height: | Size: 283 KiB After Width: | Height: | Size: 240 KiB |
@@ -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
|
note top of ecoparasite.unknown : Ce paquet est temporaire pour des classes / interfaces qui devront avoir plus de déclinaisons.
|
||||||
- double y
|
|
||||||
+ {static} HashSet<ValeursXY> convertToXY()
|
class DataCleaner {
|
||||||
}
|
+ DataCleaner()
|
||||||
|
+ String toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace ecoparasite.svg {
|
interface DataCompletion {
|
||||||
class SVGFactory {
|
+ void exception()
|
||||||
+ {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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,28 +9,62 @@ import ecoparasite.nettoyage.Nettoyage;
|
|||||||
import ecoparasite.poisson.MackerelSerra;
|
import ecoparasite.poisson.MackerelSerra;
|
||||||
import ecoparasite.poisson.Poisson;
|
import ecoparasite.poisson.Poisson;
|
||||||
import ecoparasite.representation.ValeursXY;
|
import ecoparasite.representation.ValeursXY;
|
||||||
|
import ecoparasite.svg.IncorrectAxesPointsException;
|
||||||
|
import ecoparasite.svg.SVGBuilder;
|
||||||
|
import ecoparasite.svg.SVGFactory;
|
||||||
|
import ecoparasite.svg.elements.Element;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
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 {
|
||||||
|
|
||||||
public static void main(String[] args) throws InputFileException, RawDataOverflow {
|
public static void main(String[] args) throws InputFileException, RawDataOverflow {
|
||||||
|
|
||||||
RawData rawMackerel = InputFactory.readData("test2.csv", ",");
|
RawData rawMackerel = InputFactory.readData("test2.csv", ",");
|
||||||
|
|
||||||
HashSet<Poisson> mackerelSet = MackerelSerra.parse(rawMackerel);
|
HashSet<Poisson> mackerelSet = MackerelSerra.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 );
|
||||||
|
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);
|
||||||
|
|
||||||
|
ArrayList<Element> SVGElements = axesInstance.buildAll( "Length (mm)", "Taux d'infestation", mackerelXY, ABCoef[0], ABCoef[1] );
|
||||||
|
SVGFactory.createSVG( SVGElements );
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -139,4 +139,16 @@ public class Completion {
|
|||||||
return meanY - valueA * meanX;
|
return meanY - valueA * meanX;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <T,V extends Number> double[] getLinearCoef( HashSet<T> list, Function<T,V> getX, Function<T,V> getY ){
|
||||||
|
|
||||||
|
double meanX = calculateMean(list, getX);
|
||||||
|
double meanY = calculateMean(list, getY);
|
||||||
|
|
||||||
|
double a = calculateLinearA(list,getX,getY,meanX,meanY);
|
||||||
|
double b = calculateLinearB(meanX,meanY,a);
|
||||||
|
|
||||||
|
return new double[]{a,b};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
4
src/ecoparasite/svg/IncorrectAxesPointsException.java
Normal file
4
src/ecoparasite/svg/IncorrectAxesPointsException.java
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
package ecoparasite.svg;
|
||||||
|
|
||||||
|
public class IncorrectAxesPointsException extends Exception{
|
||||||
|
}
|
||||||
332
src/ecoparasite/svg/SVGBuilder.java
Normal file
332
src/ecoparasite/svg/SVGBuilder.java
Normal file
@@ -0,0 +1,332 @@
|
|||||||
|
package ecoparasite.svg;
|
||||||
|
|
||||||
|
import ecoparasite.representation.ValeursXY;
|
||||||
|
import ecoparasite.svg.elements.*;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
public class SVGBuilder {
|
||||||
|
|
||||||
|
final int SIZE_TICK_TEXT = ElementsFactory.AXES_TEXT_SIZE - 3;
|
||||||
|
|
||||||
|
private ArrayList<Double> pointsX;
|
||||||
|
private ArrayList<Double> pointsY;
|
||||||
|
private Double offsetX;
|
||||||
|
private Double offsetY;
|
||||||
|
private SVGResizing resizer;
|
||||||
|
|
||||||
|
private Double minPointsX;
|
||||||
|
private Double minPointsY;
|
||||||
|
private Double maxPointsX;
|
||||||
|
private Double maxPointsY;
|
||||||
|
|
||||||
|
public SVGBuilder(HashMap<String, ArrayList<Double>> axesPoints ) throws IncorrectAxesPointsException {
|
||||||
|
|
||||||
|
if( axesPoints.get("AxeX") == null || axesPoints.get("AxeY") == null || axesPoints.get("OffsetX") == null || axesPoints.get("OffsetY") == null ){
|
||||||
|
throw new IncorrectAxesPointsException();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.pointsX = axesPoints.get("AxeX");
|
||||||
|
this.pointsY = axesPoints.get("AxeY");
|
||||||
|
this.offsetX = axesPoints.get("OffsetX").getFirst();
|
||||||
|
this.offsetY = axesPoints.get("OffsetY").getFirst();
|
||||||
|
|
||||||
|
this.minPointsX = this.pointsX.getFirst();
|
||||||
|
this.minPointsY = this.pointsY.getFirst();
|
||||||
|
this.maxPointsX = this.pointsX.getLast();
|
||||||
|
this.maxPointsY = this.pointsY.getLast();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Double> getPointsX() {
|
||||||
|
return pointsX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Double> getPointsY() {
|
||||||
|
return pointsY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getOffsetX() {
|
||||||
|
return offsetX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getOffsetY() {
|
||||||
|
return offsetY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SVGResizing getResizer() {
|
||||||
|
if( this.resizer == null ){
|
||||||
|
this.resizer = new SVGResizing( this.minPointsX, this.minPointsY, this.maxPointsX, this.maxPointsY );
|
||||||
|
}
|
||||||
|
return resizer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setResizer(SVGResizing resizer) {
|
||||||
|
this.resizer = resizer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Element> buildAll(String XLabel, String YLabel, HashSet<ValeursXY> points, double A, double B){
|
||||||
|
|
||||||
|
ArrayList<Element> elements = new ArrayList<>();
|
||||||
|
|
||||||
|
elements.addAll(buildAxes(XLabel, YLabel));
|
||||||
|
elements.addAll(buildXTicks());
|
||||||
|
elements.addAll(buildYTicks());
|
||||||
|
elements.addAll(buildPoints(points));
|
||||||
|
elements.addAll(buildRegression(A,B));
|
||||||
|
|
||||||
|
return elements;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Element> buildAxes(String XLabel, String YLabel){
|
||||||
|
|
||||||
|
final int OFFSET_TEXT_AXISX_X = -20;
|
||||||
|
final int OFFSET_TEXT_AXISX_Y = -10;
|
||||||
|
final int OFFSET_TEXT_AXISY_X = +5;
|
||||||
|
final int OFFSET_TEXT_AXISY_Y = +10;
|
||||||
|
|
||||||
|
ArrayList<Element> elements = new ArrayList<>();
|
||||||
|
|
||||||
|
double beginAxeX = getBeginAxeX();
|
||||||
|
double beginAxeY = getBeginAxeY();
|
||||||
|
|
||||||
|
Coordonnees bottom = getResizer().resize( beginAxeX, minPointsY );
|
||||||
|
Coordonnees top = getResizer().resize( beginAxeX, maxPointsY );
|
||||||
|
Coordonnees left = getResizer().resize( minPointsX, beginAxeY );
|
||||||
|
Coordonnees right = getResizer().resize( maxPointsX, beginAxeY );
|
||||||
|
|
||||||
|
// Axes
|
||||||
|
elements.add( new Line( bottom, top, ElementsFactory.COLOR_WHITE, 2 ) );
|
||||||
|
elements.add( new Line( left, right, ElementsFactory.COLOR_WHITE, 2 ) );
|
||||||
|
|
||||||
|
// Labels.
|
||||||
|
elements.add( new Text(
|
||||||
|
new Coordonnees( right.getX() + OFFSET_TEXT_AXISX_X, right.getY() + OFFSET_TEXT_AXISX_Y ),
|
||||||
|
XLabel, ElementsFactory.COLOR_WHITE, ElementsFactory.AXES_TEXT_SIZE
|
||||||
|
) );
|
||||||
|
elements.add( new Text(
|
||||||
|
new Coordonnees( top.getX() + OFFSET_TEXT_AXISY_X, top.getY() + OFFSET_TEXT_AXISY_Y ),
|
||||||
|
YLabel, ElementsFactory.COLOR_WHITE, ElementsFactory.AXES_TEXT_SIZE
|
||||||
|
));
|
||||||
|
|
||||||
|
return elements;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Element> buildXTicks(){
|
||||||
|
|
||||||
|
final int OFFSET_TICK = -5;
|
||||||
|
final int OFFSET_TEXT_X = -10;
|
||||||
|
final int OFFSET_TEXT_Y = +15;
|
||||||
|
|
||||||
|
ArrayList<Element> elements = new ArrayList<>();
|
||||||
|
|
||||||
|
double beginAxeY = getBeginAxeY();
|
||||||
|
for( Double X : this.pointsX ){
|
||||||
|
Coordonnees coords = getResizer().resize( X, beginAxeY );
|
||||||
|
|
||||||
|
elements.add(new Line(
|
||||||
|
coords,
|
||||||
|
new Coordonnees( coords.getX(), coords.getY() + OFFSET_TICK ),
|
||||||
|
ElementsFactory.COLOR_WHITE, 1
|
||||||
|
));
|
||||||
|
elements.add(new Text(
|
||||||
|
new Coordonnees( coords.getX() + OFFSET_TEXT_X, coords.getY() + OFFSET_TEXT_Y ),
|
||||||
|
X.toString(),
|
||||||
|
ElementsFactory.COLOR_WHITE,
|
||||||
|
SIZE_TICK_TEXT
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
return elements;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Element> buildYTicks(){
|
||||||
|
|
||||||
|
final int OFFSET_TICK = +5;
|
||||||
|
final int OFFSET_TEXT_X = -35;
|
||||||
|
final int OFFSET_TEXT_Y = +5;
|
||||||
|
|
||||||
|
ArrayList<Element> elements = new ArrayList<>();
|
||||||
|
|
||||||
|
double beginAxeX = getBeginAxeX();
|
||||||
|
for( Double Y : this.pointsY ){
|
||||||
|
Coordonnees coords = getResizer().resize( beginAxeX, Y );
|
||||||
|
|
||||||
|
elements.add(new Line(
|
||||||
|
new Coordonnees(coords.getX() + OFFSET_TICK, coords.getY() ),
|
||||||
|
coords,
|
||||||
|
ElementsFactory.COLOR_WHITE, 1
|
||||||
|
));
|
||||||
|
elements.add(new Text(
|
||||||
|
new Coordonnees( coords.getX() + OFFSET_TEXT_X, coords.getY() + OFFSET_TEXT_Y ),
|
||||||
|
Y.toString(),
|
||||||
|
ElementsFactory.COLOR_WHITE,
|
||||||
|
SIZE_TICK_TEXT
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
return elements;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Element> buildPoints( HashSet<ValeursXY> points ){
|
||||||
|
|
||||||
|
ArrayList<Element> elements = new ArrayList<>();
|
||||||
|
for( ValeursXY point : points ){
|
||||||
|
Coordonnees coords = getResizer().resize( point.getX(), point.getY() );
|
||||||
|
elements.add(new Circle(coords,3,ElementsFactory.COLOR_BLUE) );
|
||||||
|
}
|
||||||
|
|
||||||
|
return elements;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Element> buildRegression( double A, double B ){
|
||||||
|
ArrayList<Element> elements = new ArrayList<>();
|
||||||
|
|
||||||
|
double y1 = A * minPointsX + B;
|
||||||
|
double y2 = A * maxPointsX + B;
|
||||||
|
|
||||||
|
Coordonnees coords1 = getResizer().resize(minPointsX, y1);
|
||||||
|
Coordonnees coords2 = getResizer().resize(maxPointsX, y2);
|
||||||
|
|
||||||
|
elements.add( new Line( coords1, coords2, ElementsFactory.COLOR_RED, 2 ) );
|
||||||
|
return elements;
|
||||||
|
}
|
||||||
|
|
||||||
|
private double getBeginAxeX(){
|
||||||
|
return ( minPointsX > 0 ) ? minPointsX : ( maxPointsX < 0 ? maxPointsX : 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
private double getBeginAxeY(){
|
||||||
|
return ( minPointsY > 0 ) ? minPointsY : ( maxPointsY < 0 ? maxPointsY : 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 ,ArrayList<Double>> calcPointAxes(HashSet<ValeursXY> h){
|
||||||
|
|
||||||
|
HashMap< String, ArrayList<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();
|
||||||
|
}
|
||||||
|
if (min_x > var.getX()){
|
||||||
|
min_x = var.getX();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (max_y < var.getY()){
|
||||||
|
max_y = var.getY();
|
||||||
|
}
|
||||||
|
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
|
||||||
|
ArrayList<Double> axeX = new ArrayList<>();
|
||||||
|
ArrayList<Double> axeY = new ArrayList<>();
|
||||||
|
ArrayList<Double> OffsetX = new ArrayList<>();
|
||||||
|
ArrayList<Double> OffsetY = new ArrayList<>();
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
ArrayList<Double> offsetXHash = new ArrayList<>();
|
||||||
|
offsetXHash.add(offsetX);
|
||||||
|
ArrayList<Double> offsetYHash = new ArrayList<>();
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
|||||||
57
src/ecoparasite/svg/SVGResizing.java
Normal file
57
src/ecoparasite/svg/SVGResizing.java
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
package ecoparasite.svg;
|
||||||
|
|
||||||
|
import ecoparasite.representation.ValeursXY;
|
||||||
|
import ecoparasite.svg.elements.ElementsFactory;
|
||||||
|
|
||||||
|
public class SVGResizing {
|
||||||
|
|
||||||
|
private double minX;
|
||||||
|
private double maxX;
|
||||||
|
private double minY;
|
||||||
|
private double maxY;
|
||||||
|
|
||||||
|
public SVGResizing(
|
||||||
|
double minXGrad,
|
||||||
|
double minYGrad,
|
||||||
|
double maxXGrad,
|
||||||
|
double maxYGrad
|
||||||
|
){
|
||||||
|
this.minX = minXGrad;
|
||||||
|
this.maxX = maxXGrad;
|
||||||
|
this.minY = minYGrad;
|
||||||
|
this.maxY = maxYGrad;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getMinX() {
|
||||||
|
return minX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getMaxX() {
|
||||||
|
return maxX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getMinY() {
|
||||||
|
return minY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getMaxY() {
|
||||||
|
return maxY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Coordonnees resize(ValeursXY vxy ){
|
||||||
|
return this.resize( vxy.getX(), vxy.getY() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public Coordonnees resize( double X, double Y ){
|
||||||
|
double surface = ElementsFactory.SVG_SIZE - 2 * ElementsFactory.SVG_OFFSET;
|
||||||
|
|
||||||
|
double convX = ( X - minX ) / ( maxX - minX );
|
||||||
|
double convY = ( Y - minY ) / ( maxY - minY );
|
||||||
|
|
||||||
|
double SVG_X = ElementsFactory.SVG_OFFSET + convX * surface;
|
||||||
|
double SVG_Y = ElementsFactory.SVG_SIZE - ElementsFactory.SVG_OFFSET - convY * surface;
|
||||||
|
|
||||||
|
return new Coordonnees(SVG_X, SVG_Y);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,6 +2,8 @@ package ecoparasite.svg.elements;
|
|||||||
|
|
||||||
import ecoparasite.svg.Coordonnees;
|
import ecoparasite.svg.Coordonnees;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
public class Circle extends Element {
|
public class Circle extends Element {
|
||||||
|
|
||||||
private int rayon;
|
private int rayon;
|
||||||
@@ -40,7 +42,7 @@ public class Circle extends Element {
|
|||||||
StringBuilder svg = new StringBuilder();
|
StringBuilder svg = new StringBuilder();
|
||||||
svg.append("<circle ");
|
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);
|
String str = String.format(Locale.US, "r=\"%d\" cx=\"%f\" cy=\"%f\" fill=\"%s\"", this.rayon, this.coordonnees.getX(), this.coordonnees.getY(), this.color);
|
||||||
svg.append( str );
|
svg.append( str );
|
||||||
svg.append(" />");
|
svg.append(" />");
|
||||||
|
|
||||||
|
|||||||
@@ -12,14 +12,12 @@ 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";
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* Permet de générer les éléments axes du fichier SVG.
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static ArrayList<Element> SVGAxes(String HName, String VName ){
|
public static ArrayList<Element> SVGAxes(String HName, String VName ){
|
||||||
|
|
||||||
final int begin = SVG_OFFSET + AXES_TEXT_SIZE + (AXES_TEXT_SIZE / 2);
|
final int begin = SVG_OFFSET + AXES_TEXT_SIZE + (AXES_TEXT_SIZE / 2);
|
||||||
@@ -65,4 +63,5 @@ public class ElementsFactory {
|
|||||||
return SVGAxes( "None", "None" );
|
return SVGAxes( "None", "None" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,8 @@ package ecoparasite.svg.elements;
|
|||||||
|
|
||||||
import ecoparasite.svg.Coordonnees;
|
import ecoparasite.svg.Coordonnees;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
public class Line extends Element {
|
public class Line extends Element {
|
||||||
|
|
||||||
private Coordonnees coordonneesB;
|
private Coordonnees coordonneesB;
|
||||||
@@ -59,7 +61,7 @@ public class Line extends Element {
|
|||||||
StringBuilder svg = new StringBuilder();
|
StringBuilder svg = new StringBuilder();
|
||||||
svg.append("<line ");
|
svg.append("<line ");
|
||||||
|
|
||||||
String params = String.format( "x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" style=\"stroke:%s;stroke-width:%d\"",
|
String params = String.format( Locale.US,"x1=\"%f\" y1=\"%f\" x2=\"%f\" y2=\"%f\" style=\"stroke:%s;stroke-width:%d\"",
|
||||||
this.coordonnees.getX(),
|
this.coordonnees.getX(),
|
||||||
this.coordonnees.getY(),
|
this.coordonnees.getY(),
|
||||||
this.coordonneesB.getX(),
|
this.coordonneesB.getX(),
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package ecoparasite.svg.elements;
|
|||||||
|
|
||||||
import ecoparasite.svg.Coordonnees;
|
import ecoparasite.svg.Coordonnees;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
public class Text extends Element {
|
public class Text extends Element {
|
||||||
|
|
||||||
private String text;
|
private String text;
|
||||||
@@ -51,7 +53,7 @@ public class Text extends Element {
|
|||||||
StringBuilder svg = new StringBuilder();
|
StringBuilder svg = new StringBuilder();
|
||||||
svg.append("<text ");
|
svg.append("<text ");
|
||||||
|
|
||||||
String params = String.format( "x=\"%d\" y=\"%d\" fill=\"%s\" font-size=\"%s\"", coordonnees.getX(), coordonnees.getY(), color, size);
|
String params = String.format(Locale.US,"x=\"%f\" y=\"%f\" fill=\"%s\" font-size=\"%s\"", coordonnees.getX(), coordonnees.getY(), color, size);
|
||||||
svg.append(params);
|
svg.append(params);
|
||||||
svg.append(" >");
|
svg.append(" >");
|
||||||
svg.append( this.text );
|
svg.append( this.text );
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ class SVGFactoryTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void generateSVGAxes(){
|
public void generateSVGAxes(){
|
||||||
SVGFactory.createSVG( ElementsFactory.SVGAxes() );
|
// SVGFactory.createSVG( ElementsFactory.SVGAxes() );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user