Top Flop Articles Analysis Done

This commit is contained in:
Karsten 2019-05-05 18:25:05 +02:00
parent 691481dbc5
commit 4a4fd1c681

View File

@ -0,0 +1,53 @@
package de.hsel.spm.baudas.analysis;
import java.io.*;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.HashMap;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import weka.core.Instance;
import weka.core.Instances;
/**
* @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){
results = new HashMap<>();
instances = load(file);
}
/**
* get sum for every article and sort them asending
* @return Map of Name of Products and Sum of Values
*/
public Map<String, Integer> getResult() {
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, sum.intValue());
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(e -> e.getKey(), e -> e.getValue(), (e1, e2) -> e2, LinkedHashMap::new));
return results;
}
}