Compare commits
2 Commits
bbe322db9a
...
8.04.26
| Author | SHA1 | Date | |
|---|---|---|---|
| a7dc3afaba | |||
| 9da4c38a03 |
30
data/test2.csv
Normal file
30
data/test2.csv
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
id,Especes,LT,Abdomen,Foie,Visceres,Autres,Total
|
||||||
|
1,Serra Spanish mackerel,257,7,1,0,18,26
|
||||||
|
2,Serra Spanish mackerel,252,263,5,0,356,624
|
||||||
|
3,Serra Spanish mackerel,254,51,1,12,76,140
|
||||||
|
4,Serra Spanish mackerel,242,158,6,0,222,386
|
||||||
|
5,Serra Spanish mackerel,254,67,1,10,94,172
|
||||||
|
6,Serra Spanish mackerel,251,140,1,0,159,300
|
||||||
|
7,Serra Spanish mackerel,258,281,5,0,310,596
|
||||||
|
8,Serra Spanish mackerel,250,113,2,6,153,274
|
||||||
|
9,Serra Spanish mackerel,244,81,2,0,89,172
|
||||||
|
10,Serra Spanish mackerel,244,,0,1,,247
|
||||||
|
11,Serra Spanish mackerel,-200,23,0,0,25,48
|
||||||
|
12,Serra Spanish mackerel,247,53,0,0,75,
|
||||||
|
13,Serra Spanish mackerel,250,11,0,0,19,30
|
||||||
|
14,Serra Spanish mackerel,264,72,7,0,105,184
|
||||||
|
15,Serra Spanish mackerel,258,18,2,0,38,58
|
||||||
|
16,Serra Spanish mackerel,268,3,0,2,7,12
|
||||||
|
17,Serra Spanish mackerel,244,5,0,0,5,10
|
||||||
|
18,Serra Spanish mackerel,236,18,0,0,22,40
|
||||||
|
19,Serra Spanish mackerel,,46,0,0,64,110
|
||||||
|
20,Serra Spanish mackerel,251,-5,0,0,162,268
|
||||||
|
21,Serra Spanish mackerel,166,0,0,0,0,0
|
||||||
|
22,Serra Spanish mackerel,166,1,0,0,1,2
|
||||||
|
23,Serra Spanish mackerel,162,4,1,0,7,12
|
||||||
|
24,Serra Spanish mackerel,169,0,0,0,0,0
|
||||||
|
25,Serra Spanish mackerel,170,0,0,0,0,0
|
||||||
|
26,Serra Spanish mackerel,176,0,0,,0,0
|
||||||
|
27,Serra Spanish mackerel,165,4,0,0,6,10
|
||||||
|
28,Serra Spanish mackerel,193,4,0,0,4,8
|
||||||
|
29,Serra Spanish mackerel,165,1,0,0,1,2
|
||||||
|
7
data/test3.csv
Normal file
7
data/test3.csv
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
Espèce,zone,N,Prevalence,LT mm,Masse g
|
||||||
|
Salmo salar,Atlantique Ouest,21,100,210,-3
|
||||||
|
Clupea harengus,Atlantique Nord,10,80,150,200
|
||||||
|
Merluccius,Atlantique Nord,5,90,750,
|
||||||
|
Dicentrarchus labrax,Atlantique Nord,12,65,680,
|
||||||
|
Scomber scombrus,Atlantique Nord,6,30,280,630
|
||||||
|
Merluccius,Atlantique Nord,2,100,720,1720
|
||||||
|
@@ -1,8 +1,13 @@
|
|||||||
package ecoparasite.nettoyage;
|
package ecoparasite.nettoyage;
|
||||||
|
|
||||||
|
import ecoparasite.completion.Completion;
|
||||||
import ecoparasite.poisson.Poisson;
|
import ecoparasite.poisson.Poisson;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Définissant les méthodes statics de Nettoyage des données
|
* Class Définissant les méthodes statics de Nettoyage des données
|
||||||
@@ -16,16 +21,31 @@ public class Nettoyage {
|
|||||||
*/
|
*/
|
||||||
public static HashSet<Poisson> nettoiePoissonMean(HashSet<Poisson> tablePoisson){
|
public static HashSet<Poisson> nettoiePoissonMean(HashSet<Poisson> tablePoisson){
|
||||||
|
|
||||||
Double mean = mean(tablePoisson); //Moyenne
|
Double mean = Completion.calculateMean(tablePoisson,Poisson::getInfestation); //Moyenne
|
||||||
Double ecart = ecartType(tablePoisson); // Ecart Type
|
|
||||||
|
|
||||||
Double z = 0.0;
|
ArrayList<Double> infest = new ArrayList<>();
|
||||||
|
for (Poisson p : tablePoisson) {
|
||||||
|
if (p.getInfestation() != null){ //Test des valeurs null pour les Tests Unitaires. Je ne devrais pas en avoir.
|
||||||
|
infest.add(p.getInfestation());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Collections.sort(infest);
|
||||||
|
|
||||||
|
int quartIndex = infest.size()/4;
|
||||||
|
Double firstQuart = infest.get(quartIndex);
|
||||||
|
Double thirdQuart = infest.get(quartIndex *3);
|
||||||
|
Double IQR = thirdQuart - firstQuart;
|
||||||
|
|
||||||
for (Poisson p : tablePoisson) {
|
for (Poisson p : tablePoisson) {
|
||||||
z = ( p.getInfestation() - mean ) / ecart;
|
|
||||||
|
|
||||||
if ( z >= 2.5 ) {
|
if (p.getInfestation() == null) {
|
||||||
p.setInfestation(mean);
|
p.setInfestation(mean); //Fonction codé en dur pour éviter des problèmes dans les Tests Unitaires : Completion devrais etre fait et valeur null ne devrait pas exister
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (p.getInfestation() < firstQuart - (IQR * 1.5) || p.getInfestation() > thirdQuart + (IQR * 1.5)) {
|
||||||
|
p.setInfestation(mean);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,48 +53,41 @@ public class Nettoyage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Methode Privée permettant de calculer la moyenne
|
* Permet de remplacer les valeurs inexistantes d'un paramètre d'un HashSet par la moyenne des autres valeurs (non nulles).
|
||||||
* @param tablePoisson Un Hashset de Poisson contenant nos données
|
* Exemple d'utilisation : T = Poisson, V = Double, getValue = Poisson::getInfestation, setValue = Poisson::setInfestation.
|
||||||
* @return Un Double correspondant à la moyenne
|
*
|
||||||
|
* @param list La liste de données cobaye.
|
||||||
|
* @param getValue La fonction (Getter) qui permet d'obtenir la valeur que l'on veut vérifier
|
||||||
|
* @param setValue La fonction (Setter) qui permet de remplacer la valeur si null.
|
||||||
|
* @return Le HashSet avec les valeurs remplacés.
|
||||||
|
* @param <T> Le type de données cobaye. Exemple : Poisson, Population
|
||||||
|
* @param <V> Le type de la donnée à vérifier, doit être un Wrapper Number. Exemple : Double.
|
||||||
*/
|
*/
|
||||||
private static Double mean(HashSet<Poisson> tablePoisson){
|
public static <T,V extends Number> HashSet<T> nettoieColumnsMoyenne(HashSet<T> list, Function<T,V> getValue, BiConsumer<T,V> setValue ){
|
||||||
|
|
||||||
Double mean = 0.0;
|
Double mean = Completion.calculateMean(list, getValue);
|
||||||
|
|
||||||
for (Poisson p : tablePoisson){
|
ArrayList<Double> array = new ArrayList<>();
|
||||||
mean += p.getInfestation();
|
for ( T item : list) {
|
||||||
|
if (getValue.apply(item)!= null){ //Test des valeurs null pour les Tests Unitaires. Je ne devrais pas en avoir.
|
||||||
|
array.add(getValue.apply(item));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return mean / tablePoisson.size();
|
Collections.sort(array);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
int quartIndex = array.size()/4;
|
||||||
* Methode Privée permettant de calculer la variance
|
Double firstQuart = array.get(quartIndex);
|
||||||
* @param tablePoisson Un Hashset de Poisson contenant nos données
|
Double thirdQuart = array.get(quartIndex *3);
|
||||||
* @return Un Double correspondant à la variance
|
Double IQR = thirdQuart - firstQuart;
|
||||||
*/
|
|
||||||
private static Double variance(HashSet<Poisson> tablePoisson){
|
|
||||||
|
|
||||||
Double vari = 0.0;
|
for(T item : list){
|
||||||
Double mean = mean(tablePoisson);
|
if( getValue.apply(item) < firstQuart - (IQR * 1.5) || getValue.apply(item) > thirdQuart + (IQR * 1.5)){
|
||||||
|
setValue.accept( item, (V) mean);
|
||||||
for (Poisson p : tablePoisson) {
|
}
|
||||||
vari += Math.pow( (p.getInfestation() - mean), 2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return vari / tablePoisson.size();
|
return list;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Methode Privée permettant de calculer l'écart-type
|
|
||||||
* @param tablePoisson Un Hashset de Poisson contenant nos données
|
|
||||||
* @return Un Double correspondant à l'écart-type
|
|
||||||
*/
|
|
||||||
private static Double ecartType(HashSet<Poisson> tablePoisson){
|
|
||||||
|
|
||||||
Double vari = variance(tablePoisson);
|
|
||||||
|
|
||||||
return Math.sqrt(vari);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
91
src/ecoparasite/poisson/MackerelSerra.java
Normal file
91
src/ecoparasite/poisson/MackerelSerra.java
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
package ecoparasite.poisson;
|
||||||
|
|
||||||
|
import ecoparasite.input.DataParsing;
|
||||||
|
import ecoparasite.input.InvalidParsingException;
|
||||||
|
import ecoparasite.input.RawData;
|
||||||
|
import ecoparasite.input.RawDataOverflow;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import static java.lang.Double.valueOf;
|
||||||
|
|
||||||
|
public class MackerelSerra extends Poisson implements DataParsing {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructeur de MackerelSerra
|
||||||
|
* @param length
|
||||||
|
* @param infestation
|
||||||
|
*/
|
||||||
|
public MackerelSerra(String id, Double length, Double infestation) {
|
||||||
|
super(id, length, null, infestation);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implémentation de la fonction parse de DataParsing.
|
||||||
|
* Renvoie un tableau de poissons à partir d'un RawData.
|
||||||
|
*
|
||||||
|
* @param data Notre RawData
|
||||||
|
* @param parseTypeId L'ID du type de parsing, ignoré ici.
|
||||||
|
* @return Le tableau de poissons.
|
||||||
|
* @throws RawDataOverflow Si on a un dépassement de données dans notre RawData.
|
||||||
|
* @throws InvalidParsingException
|
||||||
|
*/
|
||||||
|
public static HashSet<Poisson> parse(RawData data, int parseTypeId) throws RawDataOverflow, InvalidParsingException {
|
||||||
|
return MackerelSerra.parse(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implémentation de la fonction parse de Dataparsing
|
||||||
|
* @param data Notre RawData.
|
||||||
|
* @return tableau des poissons
|
||||||
|
* @throws RawDataOverflow Si on a un dépassement de données dans notre RawDataOverflow.
|
||||||
|
*/
|
||||||
|
public static HashSet<Poisson> parse(RawData data) throws RawDataOverflow {
|
||||||
|
|
||||||
|
HashMap<String,String> temp = new HashMap<>();
|
||||||
|
|
||||||
|
HashSet<Poisson> fishSet;
|
||||||
|
fishSet = new HashSet<>();
|
||||||
|
|
||||||
|
for (int i = 0; i < data.getData().getFirst().size(); i++) {
|
||||||
|
|
||||||
|
temp = data.getEntry(i);
|
||||||
|
|
||||||
|
String id = !Objects.equals(temp.get("id"), "") ? (temp.get("id")) : null;
|
||||||
|
Double size = !Objects.equals(temp.get("LT"), "") ? valueOf(temp.get("LT")) : null;
|
||||||
|
Double infes = !Objects.equals(temp.get("Total"), "") ? valueOf(temp.get("Total")) : null;
|
||||||
|
|
||||||
|
Poisson newP = new MackerelSerra(id,size,infes);
|
||||||
|
newP.setFishParts( MackerelSerra.parsePartiePoisson(temp) );
|
||||||
|
fishSet.add(newP);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return fishSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param entry
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private static HashSet<PartiePoisson> parsePartiePoisson(HashMap<String,String> entry){
|
||||||
|
|
||||||
|
HashSet<PartiePoisson> response = new HashSet<>();
|
||||||
|
|
||||||
|
|
||||||
|
for( String k: entry.keySet() ){
|
||||||
|
if( k.contains("Foie") || k.contains("Abdomen") || k.contains("Visceres") || k.contains("Autres")){
|
||||||
|
String bodyPart = k;
|
||||||
|
Double value = !Objects.equals(entry.get(k), "") ? valueOf(entry.get(k)) : null;
|
||||||
|
PartiePoisson p = new PartiePoisson(bodyPart, value);
|
||||||
|
response.add(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ import ecoparasite.input.InputFileException;
|
|||||||
import ecoparasite.input.RawData;
|
import ecoparasite.input.RawData;
|
||||||
import ecoparasite.input.RawDataOverflow;
|
import ecoparasite.input.RawDataOverflow;
|
||||||
import ecoparasite.poisson.Mackerel;
|
import ecoparasite.poisson.Mackerel;
|
||||||
|
import ecoparasite.poisson.MackerelSerra;
|
||||||
import ecoparasite.poisson.Poisson;
|
import ecoparasite.poisson.Poisson;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@@ -16,9 +17,9 @@ class NettoyageTest {
|
|||||||
@org.junit.jupiter.api.Test
|
@org.junit.jupiter.api.Test
|
||||||
void nettoiePoissonMean() throws InputFileException, RawDataOverflow {
|
void nettoiePoissonMean() throws InputFileException, RawDataOverflow {
|
||||||
|
|
||||||
RawData test = InputFactory.readData("testNettoie.csv");
|
RawData test = InputFactory.readData("test2.csv", ",");
|
||||||
|
|
||||||
HashSet<Poisson> testp = Mackerel.parse(test);
|
HashSet<Poisson> testp = MackerelSerra.parse(test);
|
||||||
|
|
||||||
System.out.println(testp);
|
System.out.println(testp);
|
||||||
|
|
||||||
|
|||||||
25
tests/ecoparasite/poisson/MackerelSerraTest.java
Normal file
25
tests/ecoparasite/poisson/MackerelSerraTest.java
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package ecoparasite.poisson;
|
||||||
|
|
||||||
|
import ecoparasite.input.InputFactory;
|
||||||
|
import ecoparasite.input.InputFileException;
|
||||||
|
import ecoparasite.input.RawData;
|
||||||
|
import ecoparasite.input.RawDataOverflow;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class MackerelSerraTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void parse() throws InputFileException, RawDataOverflow {
|
||||||
|
|
||||||
|
RawData test = InputFactory.readData( "test2.csv" , ",");
|
||||||
|
HashSet<Poisson> fishs = MackerelSerra.parse( test );
|
||||||
|
|
||||||
|
for( Poisson poisson : fishs){
|
||||||
|
System.out.println(poisson);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user