61 lines
1.5 KiB
Java
61 lines
1.5 KiB
Java
package de.hsel.spm.baudas.analysis;
|
|
|
|
import weka.core.Instance;
|
|
import weka.core.Instances;
|
|
|
|
import java.io.File;
|
|
import java.util.HashMap;
|
|
import java.util.LinkedHashMap;
|
|
import java.util.Map;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Stream;
|
|
|
|
/**
|
|
* get sum for every article and sort them ascending.
|
|
*
|
|
* @author Karsten Eden
|
|
* @version 0.1
|
|
* @since 0.1
|
|
*/
|
|
|
|
|
|
public class TopFlopArticle implements Analysis<Map<String, Integer>> {
|
|
|
|
private Instances instances;
|
|
private Map<String, Integer> results;
|
|
|
|
public TopFlopArticle(File file) {
|
|
|
|
instances = load(file);
|
|
}
|
|
|
|
/**
|
|
* get result of analysis.
|
|
*
|
|
* @return Map of Name of Products and Sum of Values
|
|
*/
|
|
public Map<String, Integer> getResult() {
|
|
if (results != null) {
|
|
return results;
|
|
}
|
|
results = new HashMap<>();
|
|
String name;
|
|
double sum = 0.0;
|
|
for (int i = 11; i <= 25; i++) {
|
|
for (Instance instance : instances) {
|
|
sum += instance.value(i);
|
|
}
|
|
name = instances.attribute(i).name();
|
|
results.put(name, (int) sum);
|
|
sum = 0.0;
|
|
}
|
|
//Sort Map in ascending order
|
|
Stream<Map.Entry<String, Integer>> sorted = results.entrySet().stream().sorted(Map.Entry.comparingByValue());
|
|
results = sorted.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e2, LinkedHashMap::new));
|
|
return results;
|
|
}
|
|
|
|
}
|
|
|
|
|