Fix dumb nettoyage
This commit is contained in:
@@ -27,8 +27,8 @@ public class Application {
|
||||
Function<Poisson,Double> getInfes = Poisson::getInfestation;
|
||||
BiConsumer<Poisson,Double> setInfes = Poisson::setInfestation;
|
||||
|
||||
mackerelSet = Nettoyage.nettoieColumns( mackerelSet, getInfes, setInfes, false );
|
||||
mackerelSet = Completion.completeColumnsLinear( mackerelSet, getLength, getInfes, setInfes );
|
||||
mackerelSet = Nettoyage.nettoieColumnsLinear( mackerelSet, getLength, getInfes, setInfes, false );
|
||||
|
||||
HashSet<ValeursXY> mackerelXY = ValeursXY.convertToXY( mackerelSet, getLength, getInfes );
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ public class LectureEval {
|
||||
|
||||
public static void main(String[] args) throws RawDataOverflow {
|
||||
|
||||
RawData popRaw;
|
||||
RawData popRaw; int index;
|
||||
try {
|
||||
popRaw = InputFactory.readData("test3.csv", "," );
|
||||
} catch(InputFileException e) {
|
||||
@@ -91,30 +91,32 @@ public class LectureEval {
|
||||
|
||||
// System.out.println( popRaw.getEntry(1) );
|
||||
|
||||
index = 1;
|
||||
for( Population p: pop){
|
||||
System.out.println(p);
|
||||
System.out.println(String.valueOf(index++) + p);
|
||||
}
|
||||
|
||||
// Complétion de la masse.
|
||||
// Nettoyage de la masse.
|
||||
Function<Population,Double> getWeight = population -> {
|
||||
return population.getTotal().getWidth() != null ? population.getTotal().getWidth().transformToDouble() : null;
|
||||
};
|
||||
BiConsumer<Population,Double> setWeight = (population, aDouble) -> {
|
||||
population.getTotal().setWidth(new PopulationArgInterval(aDouble,aDouble));
|
||||
population.getTotal().setWidth(aDouble != null ? new PopulationArgInterval(aDouble,aDouble) : null);
|
||||
};
|
||||
|
||||
pop = Nettoyage.nettoieColumns(pop, getWeight, setWeight, false);
|
||||
System.out.println("---");
|
||||
index = 1;
|
||||
for( Population p: pop){
|
||||
System.out.println(String.valueOf(index++) + p);
|
||||
}
|
||||
|
||||
// Complétion de la masse.
|
||||
pop = Completion.completeColumnsMoyenne(pop, getWeight, setWeight);
|
||||
System.out.println("---");
|
||||
index = 1;
|
||||
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);
|
||||
System.out.println(String.valueOf(index++) + p);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,6 +14,31 @@ import java.util.function.Function;
|
||||
*/
|
||||
public class Nettoyage {
|
||||
|
||||
public static <T,V extends Number> HashSet<T> nettoieColumns(HashSet<T> list, Function<T,V> getValue, BiConsumer<T,V> setValue, boolean allowNegative ){
|
||||
|
||||
ArrayList<Double> array = new ArrayList<>();
|
||||
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).doubleValue());
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(array);
|
||||
|
||||
int quartIndex = array.size()/4;
|
||||
Double firstQuart = array.get(quartIndex);
|
||||
Double thirdQuart = array.get(quartIndex *3);
|
||||
Double IQR = thirdQuart - firstQuart;
|
||||
|
||||
for(T item : list){
|
||||
if( getValue.apply(item) == null || getValue.apply(item).doubleValue() < firstQuart - (IQR * 1.5) || getValue.apply(item).doubleValue() > thirdQuart + (IQR * 1.5) || ( !allowNegative && getValue.apply(item).doubleValue() < 0 ) ){
|
||||
setValue.accept( item, null);
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Permet de remplacer les valeurs abérrantes 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.
|
||||
@@ -26,6 +51,7 @@ public class Nettoyage {
|
||||
* @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> nettoieColumnsMoyenne(HashSet<T> list, Function<T,V> getValue, BiConsumer<T,V> setValue, boolean allowNegative ){
|
||||
|
||||
Double mean = Completion.calculateMean(list, getValue);
|
||||
@@ -52,6 +78,7 @@ public class Nettoyage {
|
||||
|
||||
return list;
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Polymorphisme de la fonction précédente. Autorise les valeurs abérrantes à être négative.
|
||||
@@ -62,10 +89,10 @@ public class Nettoyage {
|
||||
* @param <T>
|
||||
* @param <V>
|
||||
*
|
||||
* @see Nettoyage::nettoieColumnsMoyenne
|
||||
* @see Nettoyage::nettoieColumns
|
||||
*/
|
||||
public static <T,V extends Number> HashSet<T> nettoieColumnsMoyenne(HashSet<T> list, Function<T,V> getValue, BiConsumer<T,V> setValue){
|
||||
return nettoieColumnsMoyenne(list, getValue, setValue, true);
|
||||
public static <T,V extends Number> HashSet<T> nettoieColumns(HashSet<T> list, Function<T,V> getValue, BiConsumer<T,V> setValue){
|
||||
return nettoieColumns(list, getValue, setValue, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,6 +108,7 @@ public class Nettoyage {
|
||||
* @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> nettoieColumnsLinear(HashSet<T> list, Function<T,V> getX, Function<T,V> getY, BiConsumer<T,V> setY, boolean allowNegative ){
|
||||
|
||||
double meanX = Completion.calculateMean(list, getX);
|
||||
@@ -112,6 +140,7 @@ public class Nettoyage {
|
||||
|
||||
return list;
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Polymorphisme de la fonction nettoyage de colonne linéaire avec par défaut, l'autorisation des valeurs négatives.
|
||||
@@ -123,7 +152,9 @@ public class Nettoyage {
|
||||
* @param <T>
|
||||
* @param <V>
|
||||
*/
|
||||
/*
|
||||
public static <T,V extends Number> HashSet<T> nettoieColumnsLinear(HashSet<T> list, Function<T,V> getX, Function<T,V> getY, BiConsumer<T,V> setY){
|
||||
return nettoieColumnsLinear(list, getX, getY, setY, true);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -36,4 +36,11 @@ public class ValeursXY {
|
||||
return xy;
|
||||
}
|
||||
|
||||
/*
|
||||
public static ValeursXY getMinX( HashSet<ValeursXY> list ){
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user