From 35b2fc2660dd9db1538b665daafad7687dacef08 Mon Sep 17 00:00:00 2001 From: Lycano Date: Wed, 29 Apr 2026 10:43:13 +0200 Subject: [PATCH] JavaDoc et Gradation des axes Dones --- src/ecoparasite/Application.java | 179 ++++++++++++++++++++++++++++++- 1 file changed, 176 insertions(+), 3 deletions(-) diff --git a/src/ecoparasite/Application.java b/src/ecoparasite/Application.java index f92ed4a..da367b6 100644 --- a/src/ecoparasite/Application.java +++ b/src/ecoparasite/Application.java @@ -6,27 +6,85 @@ import ecoparasite.input.InputFileException; import ecoparasite.input.RawData; import ecoparasite.input.RawDataOverflow; import ecoparasite.nettoyage.Nettoyage; +import ecoparasite.poisson.Mackerel; import ecoparasite.poisson.MackerelSerra; +import ecoparasite.poisson.Merlu; import ecoparasite.poisson.Poisson; +import ecoparasite.population.Population; +import ecoparasite.population.PopulationArgInterval; +import ecoparasite.population.PopulationParsing; import ecoparasite.representation.ValeursXY; import ecoparasite.svg.IncorrectAxesPointsException; import ecoparasite.svg.SVGBuilder; import ecoparasite.svg.SVGFactory; import ecoparasite.svg.elements.Element; +import java.io.File; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; +import java.util.Scanner; import java.util.function.BiConsumer; import java.util.function.Function; public class Application { - public static void main(String[] args) throws InputFileException, RawDataOverflow { + static final String[] VALID_FILES = {"mackerel.97442.csv", "merlu2018_75164.csv","ParasitesPeru2021.csv"}; - RawData rawMackerel = InputFactory.readData("test2.csv", ","); + public static void validFileName(File dir, HashSet listeName){ - HashSet mackerelSet = MackerelSerra.parse(rawMackerel); + File[] liste = dir.listFiles(); + + for (File item : liste) { + if (!item.isDirectory()){ + listeName.add(item.getName()); + } else { + validFileName(new File(dir.getName()+ "/" + item.getName()), listeName); + } + } + + } + + public static String validFile(){ + + Scanner sc = new Scanner(System.in); + String name = ""; + boolean isValid = false; + + File dir = new File("data"); + + HashSet listeName = new HashSet<>(); + + Application.validFileName(dir,listeName); + + while (!isValid) { + System.out.println("Veuillez rentrez le nom du fichier :"); + name = sc.nextLine(); + + if (listeName.contains(name)){ + for (int i = 0; i < 3; i++) { + if (VALID_FILES[i] == name){ + isValid = true; + break; + } + } + if (!isValid){ + System.out.println("Ce Fichier existe mais n'est pas valide"); + } + } else { + System.out.println("Ce Fichier n'existe pas dans le dossier data."); + } + + } + + return name; + } + + public static void MackerelFile(String name) throws InputFileException, RawDataOverflow { + + RawData rawMackerel = InputFactory.readData(name); + + HashSet mackerelSet = Mackerel.parse(rawMackerel); System.out.println( mackerelSet ); @@ -54,6 +112,121 @@ public class Application { ArrayList SVGElements = axesInstance.buildAll( "Length", "Infestation", mackerelXY, ABCoef[0], ABCoef[1] ); SVGFactory.createSVG( SVGElements ); + } + + public static void MerluFile(String name) throws InputFileException, RawDataOverflow { + + RawData rawMerlu = InputFactory.readData(name); + + HashSet merluSet = Merlu.parse(rawMerlu); + + System.out.println( merluSet ); + + Function getLength = Poisson::getLength; + Function getInfes = Poisson::getInfestation; + BiConsumer setInfes = Poisson::setInfestation; + + merluSet = Nettoyage.nettoieColumns( merluSet, getInfes, setInfes, false ); + merluSet = Completion.completeColumnsLinear( merluSet, getLength, getInfes, setInfes ); + + HashSet merluXY = ValeursXY.convertToXY( merluSet, getLength, getInfes ); + HashMap> axes = SVGBuilder.calcPointAxes( merluXY ); + 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(merluSet, getLength, getInfes); + + ArrayList SVGElements = axesInstance.buildAll( "Length", "Infestation", merluXY, ABCoef[0], ABCoef[1] ); + SVGFactory.createSVG( SVGElements ); + } + + public static void PopPeru(String name) throws InputFileException,RawDataOverflow{ + + RawData popRaw; int index; + try { + popRaw = InputFactory.readData(name , "," ); + } catch(InputFileException e) { + System.out.println(e.getMessage()); + return; + } + + HashSet popSet = PopulationParsing.parseParasitesPeru(popRaw); + + index = 1; + for( Population p: popSet){ + System.out.println(String.valueOf(index++) + p); + } + + // Nettoyage de la taille. + Function getWeight = population -> { + return population.getTotal().getLength() != null ? population.getTotal().getLength().transformToDouble() : null; + }; + BiConsumer setWeight = (population, aDouble) -> { + population.getTotal().setLength(aDouble != null ? new PopulationArgInterval(aDouble,aDouble) : null); + }; + + Function getInfes = population -> { + return population.getTotal().getAbondance() != null ? population.getTotal().getPrevalence().transformToDouble() : null; + }; + BiConsumer setInfes = (population, aDouble) -> { + population.getTotal().setAbondance(aDouble != null ? new PopulationArgInterval(aDouble,aDouble) : null); + }; + + popSet = Nettoyage.nettoieColumns(popSet, getWeight, setWeight, false); + System.out.println("---"); + index = 1; + for( Population p: popSet){ + System.out.println(String.valueOf(index++) + p); + } + + // Complétion de la masse. + popSet = Completion.completeColumnsMoyenne(popSet, getWeight, setWeight); + System.out.println("---"); + for( Population p: popSet){ + System.out.println(String.valueOf(index++) + p); + } + + HashSet merluXY = ValeursXY.convertToXY( popSet, getLength, getInfes ); + HashMap> axes = SVGBuilder.calcPointAxes( merluXY ); + System.out.println( axes ); + + SVGBuilder axesInstance; + try { + axesInstance = new SVGBuilder(axes); + } catch (IncorrectAxesPointsException e) { + System.out.println( "Mauvais format communiqué" ); + return; + } + + + ArrayList elements = new ArrayList<>(); + + elements.addAll(buildAxes(XLabel, YLabel)); + elements.addAll(buildXTicks()); + elements.addAll(buildYTicks()); + elements.addAll(buildPoints(points)); + } + + public static void main(String[] args) throws InputFileException, RawDataOverflow { + + String nameFile = Application.validFile(); + + if (nameFile.contains("mackerel")) { + MackerelFile(nameFile); + } else if (nameFile.contains("merlu")){ + MerluFile(nameFile); + } else if (nameFile.contains("Peru")) { + PopPeru(nameFile); + } + } } \ No newline at end of file