Finish UML and Completion Moyenne. #8
BIN
UML/classes.png
BIN
UML/classes.png
Binary file not shown.
|
Before Width: | Height: | Size: 133 KiB After Width: | Height: | Size: 232 KiB |
@@ -117,6 +117,12 @@ namespace ecoparasite {
|
||||
}
|
||||
}
|
||||
|
||||
namespace ecoparasite.completion {
|
||||
class Completion {
|
||||
+ {static} completeColumnsMoyenne
|
||||
}
|
||||
}
|
||||
|
||||
namespace ecoparasite.unknown {
|
||||
|
||||
note top of ecoparasite.unknown : Ce paquet est temporaire pour des classes / interfaces qui devront avoir plus de déclinaisons.
|
||||
|
||||
@@ -1,41 +1,67 @@
|
||||
package ecoparasite.completion;
|
||||
|
||||
import ecoparasite.input.InputFactory;
|
||||
import ecoparasite.input.InputFileException;
|
||||
import ecoparasite.input.RawData;
|
||||
import ecoparasite.input.RawDataOverflow;
|
||||
import ecoparasite.poisson.Mackerel;
|
||||
import ecoparasite.poisson.Poisson;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.function.*;
|
||||
|
||||
/**
|
||||
* Class incluant des méthodes Statiques de Completion des données
|
||||
* Permet de faire de la complétion de données.
|
||||
* Si une valeur est manquante, elle sera remplacé par la moyenne ou par regression linéaire.
|
||||
*/
|
||||
public class Completion {
|
||||
|
||||
/**
|
||||
* Permet de remplacer les valeurs inexistantes d'un paramètre d'un HashSet par la moyenne des autres valeurs (non nulles).
|
||||
* Exemple d'utilisation : T = Poisson, V = Double, getValue = Poisson::getInfestation, setValue = Poisson::setInfestation.
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
public static <T,V extends Number> HashSet<T> completeColumnsMoyenne(HashSet<T> list, Function<T,V> getValue, BiConsumer<T,V> setValue ){
|
||||
|
||||
public static HashSet<Poisson> completePoissonMean(HashSet<Poisson> tablePoisson){
|
||||
|
||||
Double mean = mean(tablePoisson);
|
||||
|
||||
for (Poisson p : tablePoisson) {
|
||||
if ( p.getInfestation() == null ) {
|
||||
p.setInfestation(mean);
|
||||
Double mean = calculateMean(list, getValue);
|
||||
for(T item : list){
|
||||
if( getValue.apply(item) == null ){
|
||||
setValue.accept( item, (V) mean);
|
||||
}
|
||||
}
|
||||
|
||||
return tablePoisson;
|
||||
return list;
|
||||
}
|
||||
|
||||
private static Double mean(HashSet<Poisson> tablePoisson){
|
||||
/**
|
||||
* Permet de calculer la moyenne d'une donnée des valeurs non nulles.
|
||||
* @param list La liste de données cobaye.
|
||||
* @param getValue La fonction qui permet d'obtenir la valeur de notre champ.
|
||||
* @return La moyenne calculé.
|
||||
* @param <T> Le type de données cobaye/ Exemple : Poisson
|
||||
* @param <V> Le type de la donnée à vérifier, doit être un wrapper Number. Exemple : Double.
|
||||
*/
|
||||
public static <T,V extends Number> double calculateMean(HashSet<T> list, Function<T,V> getValue ){
|
||||
|
||||
Double mean = 0.0;
|
||||
double mean = 0.0;
|
||||
int i = 0;
|
||||
|
||||
for (Poisson p : tablePoisson){
|
||||
if (p.getInfestation() != null) {
|
||||
mean += p.getInfestation();
|
||||
for( T item : list ){
|
||||
V value = getValue.apply(item);
|
||||
if( value != null) {
|
||||
mean += value.doubleValue();
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
return mean / tablePoisson.size();
|
||||
return mean / i;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ import ecoparasite.poisson.Poisson;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@@ -23,8 +25,10 @@ class CompletionTest {
|
||||
|
||||
System.out.println(testp);
|
||||
|
||||
testp = Completion.completePoissonMean(testp);
|
||||
Function<Poisson,Double> getInfes = Poisson::getInfestation;
|
||||
BiConsumer<Poisson,Double> setInfes = Poisson::setInfestation;
|
||||
|
||||
testp = Completion.completeColumnsMoyenne(testp,getInfes,setInfes);
|
||||
System.out.println(testp);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user