From 7305393f6c1819b127a4c16301fdae0cbee6891d Mon Sep 17 00:00:00 2001 From: Lycano Date: Mon, 20 Apr 2026 16:39:00 +0200 Subject: [PATCH] JavaDoc --- src/ecoparasite/LectureEval.java | 122 ---------------------------- src/ecoparasite/svg/SVGFactory.java | 44 +++++++++- 2 files changed, 41 insertions(+), 125 deletions(-) delete mode 100644 src/ecoparasite/LectureEval.java diff --git a/src/ecoparasite/LectureEval.java b/src/ecoparasite/LectureEval.java deleted file mode 100644 index ba1cf62..0000000 --- a/src/ecoparasite/LectureEval.java +++ /dev/null @@ -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 parseEval( RawData popRaw ){ - - HashSet popEspece = new HashSet<>(); - - int index = 1; - try { - while(true){ - HashMap 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 pop = parseEval(popRaw); - - // System.out.println( popRaw.getEntry(1) ); - - for( Population p: pop){ - System.out.println(p); - } - - // Complétion de la masse. - Function getWeight = population -> { - return population.getTotal().getWidth() != null ? population.getTotal().getWidth().transformToDouble() : null; - }; - BiConsumer 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); - } - - } - -} diff --git a/src/ecoparasite/svg/SVGFactory.java b/src/ecoparasite/svg/SVGFactory.java index d65e2e2..9076133 100644 --- a/src/ecoparasite/svg/SVGFactory.java +++ b/src/ecoparasite/svg/SVGFactory.java @@ -107,16 +107,54 @@ public class SVGFactory { } - double step_x = (max_x - min_x); //TODO - double step_y = (max_y - min_y); //TODO + double range_x = max_x-min_x; + double range_y = max_y-min_y; + int target = 10; // Ideal Number of Gradation - //TODO + 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); + + HashSet axe_x = new HashSet<>(); + HashSet axe_y = new HashSet<>(); return null; } + /** + * 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