From 4a4fd1c6817f629ce38f9831dbc232ce614699df Mon Sep 17 00:00:00 2001 From: Karsten Date: Sun, 5 May 2019 18:25:05 +0200 Subject: [PATCH] Top Flop Articles Analysis Done --- .../spm/baudas/analysis/TopFlopArticle.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/main/java/de/hsel/spm/baudas/analysis/TopFlopArticle.java diff --git a/src/main/java/de/hsel/spm/baudas/analysis/TopFlopArticle.java b/src/main/java/de/hsel/spm/baudas/analysis/TopFlopArticle.java new file mode 100644 index 0000000..b8a24dc --- /dev/null +++ b/src/main/java/de/hsel/spm/baudas/analysis/TopFlopArticle.java @@ -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> { + + private Instances instances; + private Map 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 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> 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; + } + +} + +