Compare commits
3 Commits
81e2079d78
...
18.03.26
| Author | SHA1 | Date | |
|---|---|---|---|
| f79e2f7d92 | |||
| 71250d8f79 | |||
| 9752aba641 |
@@ -4,11 +4,9 @@
|
|||||||
<exclude-output />
|
<exclude-output />
|
||||||
<content url="file://$MODULE_DIR$">
|
<content url="file://$MODULE_DIR$">
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
|
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
<orderEntry type="library" name="javafx-swt" level="application" />
|
<orderEntry type="library" name="javafx-swt" level="application" />
|
||||||
<orderEntry type="library" name="junit.jupiter" level="project" />
|
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
11
Projet.iml
Normal file
11
Projet.iml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
|
Can't render this file because it is too large.
|
|
Can't render this file because it contains an unexpected character in line 1 and column 1304.
|
10
src/ecoparasite/input/DataParsing.java
Normal file
10
src/ecoparasite/input/DataParsing.java
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package ecoparasite.input;
|
||||||
|
|
||||||
|
import ecoparasite.poisson.Poisson;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
public interface DataParsing {
|
||||||
|
|
||||||
|
public HashSet<Poisson> parse(RawData data);
|
||||||
|
}
|
||||||
@@ -1,105 +0,0 @@
|
|||||||
package ecoparasite.input;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public class InputFactory {
|
|
||||||
|
|
||||||
final private static String DATA_FOLDER = "data/";
|
|
||||||
|
|
||||||
final public static String DATA_MACKEREL = "Campagne/mackerel.97442.csv";
|
|
||||||
final public static String DATA_MERLU = "Campagne/merlu2018_75164.csv";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Construit le chemin vers le fichier de données voulu.
|
|
||||||
* @param data De préference via une constante DATA_... de notre classe actuelle.
|
|
||||||
* @return Le chemin complet vers le dossier
|
|
||||||
*/
|
|
||||||
public static String buildDataPath( String data ){
|
|
||||||
return InputFactory.DATA_FOLDER + data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Permet de lire les données brutes d'un fichier CSV.
|
|
||||||
* @param dataFileName Le chemin du fichier CSV, tiré des constantes DATA_... de notre classe actuelle.
|
|
||||||
* @return Une instance de RawData permettant de manipuler les données.
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
public static RawData readData( String dataFileName ) throws InputFileException {
|
|
||||||
return readData( dataFileName, ";" );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Permet de lire les données brutes d'un fichier CSV.
|
|
||||||
* @param dataFileName Le chemin du fichier CSV, tiré des constantes DATA_... de notre classe actuelle.
|
|
||||||
* @param separator Le séparateur du fichier CSV, par défaut : ;
|
|
||||||
* @return Une instance de RawData permettant de manipuler les données.
|
|
||||||
*
|
|
||||||
* @throws InputFileException - Une erreur durant la lecture du fichier.
|
|
||||||
*/
|
|
||||||
public static RawData readData( String dataFileName, String separator ) throws InputFileException {
|
|
||||||
|
|
||||||
Path path = Paths.get(InputFactory.buildDataPath(dataFileName));
|
|
||||||
|
|
||||||
BufferedReader reader;
|
|
||||||
try {
|
|
||||||
reader = Files.newBufferedReader(path, StandardCharsets.UTF_8);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new InputFileException(dataFileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
return createRawData(dataFileName, reader, separator);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fonction appellé par readData, permet de créer l'instance de RawData stockant les données.
|
|
||||||
*
|
|
||||||
* @param dataFileName Le nom du fichier.
|
|
||||||
* @param reader Le BufferedReader des données.
|
|
||||||
* @param separator Le séparateur du fichier CSV, par défaut ";"
|
|
||||||
* @return L'instance RawData.
|
|
||||||
*
|
|
||||||
* @throws InputFileException Si une erreur durant la lecture d'une ligne s'est produite.
|
|
||||||
*/
|
|
||||||
private static RawData createRawData( String dataFileName, BufferedReader reader, String separator ) throws InputFileException {
|
|
||||||
|
|
||||||
ArrayList<ArrayList<String>> data = new ArrayList<>();
|
|
||||||
String line;
|
|
||||||
|
|
||||||
// Lecture de la première ligne, le nom des colonnes.
|
|
||||||
try {
|
|
||||||
line = reader.readLine();
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new InputFileException( dataFileName );
|
|
||||||
}
|
|
||||||
String[] rowFields = line.split(separator);
|
|
||||||
|
|
||||||
for( int i = 0; i < rowFields.length; i++ ){
|
|
||||||
ArrayList<String> element = new ArrayList<>();
|
|
||||||
element.add(rowFields[i]);
|
|
||||||
data.add( element );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Lecture des autres lignes.
|
|
||||||
try {
|
|
||||||
while ((line = reader.readLine()) != null) {
|
|
||||||
rowFields = line.split(separator);
|
|
||||||
for (int i = 0; i < rowFields.length; i++) {
|
|
||||||
ArrayList<String> element = data.get(i);
|
|
||||||
element.add(rowFields[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new InputFileException( dataFileName );
|
|
||||||
}
|
|
||||||
|
|
||||||
return new RawData(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
package ecoparasite.input;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Est déclenché si une erreur est survenue lors de la lecture d'un fichier.
|
|
||||||
*/
|
|
||||||
public class InputFileException extends Exception {
|
|
||||||
|
|
||||||
final private String dataFilePath;
|
|
||||||
|
|
||||||
public InputFileException(String dataFilePath) {
|
|
||||||
this.dataFilePath = dataFilePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getMessage(){
|
|
||||||
return "Une erreur a été déclenché durant la lecture du fichier d'entrée : " + dataFilePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,122 +0,0 @@
|
|||||||
package ecoparasite.input;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Permet de stocker les données brutes d'un fichier chargé CSV, avant d'être changé en Classe plus spécifique.
|
|
||||||
*/
|
|
||||||
public class RawData {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stocke les données brutes sous formes de deux ArrayList.
|
|
||||||
*/
|
|
||||||
final private ArrayList<ArrayList<String>> data;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructeur.
|
|
||||||
* @param data ArrayList qui demande des ArrayList<String> pour faire des lignes/colonnes.
|
|
||||||
*/
|
|
||||||
public RawData(ArrayList<ArrayList<String>> data) {
|
|
||||||
this.data = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Getter des données brutes. À n'utiliser que pour des opérations compliquées non descriptibles par une fonction.
|
|
||||||
* @return ArrayList d'ArrayList de String qui contient les données brutes.
|
|
||||||
*/
|
|
||||||
public ArrayList<ArrayList<String>> getData() {
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Permet d'avoir un affichage debug du contenu de notre jeu de données.
|
|
||||||
* @return La string symbolisant nos données.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String toString()
|
|
||||||
{
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
for( int i = 0; i < data.size(); i++ )
|
|
||||||
{
|
|
||||||
ArrayList<String> row = data.get(i);
|
|
||||||
for( int j = 0; j < row.size(); j++ ){
|
|
||||||
sb.append(row.get(j)).append(" | ");
|
|
||||||
}
|
|
||||||
sb.append(System.lineSeparator());
|
|
||||||
}
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Permet d'obtenir le nom des colonnes de notre jeu de données.
|
|
||||||
*
|
|
||||||
* @return HashSet du nom des colonnes
|
|
||||||
*/
|
|
||||||
public HashSet<String> getColumnsNames(){
|
|
||||||
|
|
||||||
HashSet<String> columns = new HashSet<>();
|
|
||||||
for (ArrayList<String> row : data) {
|
|
||||||
for (String colName : row) {
|
|
||||||
columns.add(colName);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return columns;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Permet d'avoir toutes les valeurs associées à la colonne.
|
|
||||||
* @param colName Le nom de la colonne dans le fichier CSV
|
|
||||||
* @return HashSet des données brutes.
|
|
||||||
*/
|
|
||||||
public HashSet<String> getDataFromColumn( String colName ){
|
|
||||||
|
|
||||||
boolean goodColumn = false;
|
|
||||||
HashSet<String> rows = new HashSet<>();
|
|
||||||
|
|
||||||
for( ArrayList<String> row : data ){
|
|
||||||
for( String value : row ) {
|
|
||||||
if( !goodColumn ) {
|
|
||||||
if (colName.equals(value))
|
|
||||||
goodColumn = true;
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
} else { // Si on a trouvé la bonne colonne, on ajoute les éléments.
|
|
||||||
rows.add(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if( goodColumn )
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return rows;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Permet d'obtenir tous les champs d'une entrée.
|
|
||||||
* @param index Entrée que vous voulez obtenir, le minimum est l'entrée 1. Le maximum dépend du Dataframe.
|
|
||||||
* @return Une HashMap <colonne, valeur>.
|
|
||||||
* @throws RawDataOverflow Si vous avez dépasses le maximum d'entrées du DataFrame.
|
|
||||||
*/
|
|
||||||
public HashMap<String,String> getEntry(int index) throws RawDataOverflow {
|
|
||||||
|
|
||||||
if( index <= 0 ){
|
|
||||||
index = 1; // 0 = nombre de colonnes, fallback.
|
|
||||||
}
|
|
||||||
|
|
||||||
HashMap<String,String> entry = new HashMap<>();
|
|
||||||
|
|
||||||
for( ArrayList<String> row : data ){
|
|
||||||
if( index > row.size()){
|
|
||||||
throw new RawDataOverflow( index, row.size() );
|
|
||||||
}
|
|
||||||
entry.put( row.getFirst(), row.get( index ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
return entry;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
package ecoparasite.input;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Est déclenché lors du dépassement d'index lors de la récupération d'une entrée d'un RawData.
|
|
||||||
*/
|
|
||||||
public class RawDataOverflow extends Exception {
|
|
||||||
|
|
||||||
final private int excepted;
|
|
||||||
final private int limit;
|
|
||||||
|
|
||||||
public RawDataOverflow( int excepted, int limit ) {
|
|
||||||
this.excepted = excepted;
|
|
||||||
this.limit = limit;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getMessage()
|
|
||||||
{
|
|
||||||
return "Dépassement d'index : " + this.excepted + " voulu, " + this.limit + " maximum autorisé par le RawData.";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
22
src/ecoparasite/poisson/Mackerel.java
Normal file
22
src/ecoparasite/poisson/Mackerel.java
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package ecoparasite.poisson;
|
||||||
|
|
||||||
|
import ecoparasite.input.DataParsing;
|
||||||
|
import ecoparasite.input.RawData;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
public class Mackerel extends Poisson implements DataParsing {
|
||||||
|
public Mackerel(String species, Double length, Double infestation) {
|
||||||
|
super(species, length, null, infestation);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HashSet<Poisson> parse(RawData data) {
|
||||||
|
|
||||||
|
HashSet<Poisson> fishSet;
|
||||||
|
fishSet = new HashSet<>();
|
||||||
|
|
||||||
|
|
||||||
|
return fishSet;
|
||||||
|
}
|
||||||
|
}
|
||||||
33
src/ecoparasite/poisson/Merlu.java
Normal file
33
src/ecoparasite/poisson/Merlu.java
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
package ecoparasite.poisson;
|
||||||
|
|
||||||
|
import ecoparasite.input.DataParsing;
|
||||||
|
import ecoparasite.input.RawData;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
public class Merlu extends Poisson implements DataParsing {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construteur d'un merlu
|
||||||
|
* @param length Un Wrapper Double representant la longueur/taille du poisson
|
||||||
|
* @param infestation Un Wrapper Double representant le taux de parasite du poisson
|
||||||
|
*/
|
||||||
|
public Merlu(Double length, Double infestation) {
|
||||||
|
super("Merlu", length, null, infestation);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implémentation de la fonction parse de Dataparsing
|
||||||
|
* @param data
|
||||||
|
* @return tableau des poissons
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public HashSet<Poisson> parse(RawData data) { //TODO
|
||||||
|
|
||||||
|
HashSet<Poisson> fishSet;
|
||||||
|
fishSet = new HashSet<>();
|
||||||
|
|
||||||
|
|
||||||
|
return fishSet;
|
||||||
|
}
|
||||||
|
}
|
||||||
4
src/ecoparasite/poisson/PartiePoisson.java
Normal file
4
src/ecoparasite/poisson/PartiePoisson.java
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
package ecoparasite.poisson;
|
||||||
|
|
||||||
|
public abstract class PartiePoisson {
|
||||||
|
}
|
||||||
69
src/ecoparasite/poisson/Poisson.java
Normal file
69
src/ecoparasite/poisson/Poisson.java
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
package ecoparasite.poisson;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
public class Poisson{
|
||||||
|
|
||||||
|
private String specie;
|
||||||
|
private Double length;
|
||||||
|
private Double weight;
|
||||||
|
private Double infestation;
|
||||||
|
protected HashSet<PartiePoisson> fishParts;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructeur de l'objet Poisson
|
||||||
|
* @param specie Une String representant l'espece du poisson
|
||||||
|
* @param length Un Wrapper Double representant la longueur/taille du poisson
|
||||||
|
* @param weight Un Wrapper Double representant le poids du poisson
|
||||||
|
* @param infestation Un Wrapper Double representant le taux de parasite du poisson
|
||||||
|
*/
|
||||||
|
public Poisson(String specie, Double length, Double weight, Double infestation){
|
||||||
|
this.specie = specie;
|
||||||
|
this.length = length;
|
||||||
|
this.weight = weight;
|
||||||
|
this.infestation = infestation;
|
||||||
|
this.fishParts = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter de l'attribut specie
|
||||||
|
* @return La string de l'attribut specie
|
||||||
|
*/
|
||||||
|
public String getSpecie() {
|
||||||
|
return specie;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter de l'attribut length
|
||||||
|
* @return Le Double de l'attribut length
|
||||||
|
*/
|
||||||
|
public Double getLength() {
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter de l'attribut weight
|
||||||
|
* @return Le Double de l'attribut weight
|
||||||
|
*/
|
||||||
|
public Double getWeight() {
|
||||||
|
return weight;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter de l'attribut infestation
|
||||||
|
* @return Le Double de l'attribut infestation
|
||||||
|
*/
|
||||||
|
public Double getInfestation() {
|
||||||
|
return infestation;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Permet d'afficher les informations de notre poisson
|
||||||
|
* @return La string contenant les informations
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String toString(){
|
||||||
|
String result = "[ %5s : %4d mm, %4d g, %4d taux d'infestation ]";
|
||||||
|
return String.format(result, this.getClass().getSimpleName(), this.getLength(), this.getWeight(), this.getInfestation());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
package ecoparasite.input;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
class InputFactoryTest {
|
|
||||||
|
|
||||||
// TODO : Test a être effectué par Sébastien.
|
|
||||||
@Test
|
|
||||||
void readFile() throws InputFileException, RawDataOverflow {
|
|
||||||
RawData r = InputFactory.readData( InputFactory.DATA_MACKEREL );
|
|
||||||
System.out.println( r );
|
|
||||||
System.out.println( r.getColumnsNames() );
|
|
||||||
System.out.println( r.getDataFromColumn( "Sample_codE" ) );
|
|
||||||
System.out.println( r.getEntry( 2 ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user