Merge branch 'SPM-21' of Studium/Softwareprojektmanagement into master
This commit is contained in:
commit
1e076050d6
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
package de.hsel.spm.baudas.analysis;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
public class TopFlopArticlesTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test100() {
|
||||||
|
URL url = getClass().getClassLoader().getResource("kd100.csv");
|
||||||
|
assert url != null;
|
||||||
|
TopFlopArticle tfArticle = new TopFlopArticle(new File(url.getFile()));
|
||||||
|
Map<String, Integer> results = tfArticle.getResult();
|
||||||
|
|
||||||
|
assertEquals(529, results.get("Farben"));
|
||||||
|
assertEquals(2403, results.get("Elektrowerkzeuge"));
|
||||||
|
assertEquals(8055, results.get("Baustoffe"));
|
||||||
|
assertEquals(5414, results.get("Fliesen"));
|
||||||
|
assertEquals(1466, results.get("Holz"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test1000() {
|
||||||
|
URL url = getClass().getClassLoader().getResource("kd1000.csv");
|
||||||
|
assert url != null;
|
||||||
|
TopFlopArticle tfArticle = new TopFlopArticle(new File(url.getFile()));
|
||||||
|
Map<String, Integer> results = tfArticle.getResult();
|
||||||
|
|
||||||
|
assertEquals(5643, results.get("Eisenwaren"));
|
||||||
|
assertEquals(9339, results.get("Bodenbelag"));
|
||||||
|
assertEquals(12824, results.get("Gartengeraete"));
|
||||||
|
assertEquals(29055, results.get("Sanitaermaterial"));
|
||||||
|
assertEquals(50067, results.get("Armaturen"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test10000() {
|
||||||
|
URL url = getClass().getClassLoader().getResource("kd10000.csv");
|
||||||
|
assert url != null;
|
||||||
|
TopFlopArticle tfArticle = new TopFlopArticle(new File(url.getFile()));
|
||||||
|
Map<String, Integer> results = tfArticle.getResult();
|
||||||
|
|
||||||
|
assertEquals(101665, results.get("Handwerkzeuge"));
|
||||||
|
assertEquals(151920, results.get("Leuchten"));
|
||||||
|
assertEquals(231881, results.get("Schliesstechnik"));
|
||||||
|
assertEquals(294053, results.get("Elektromaterial"));
|
||||||
|
assertEquals(543613, results.get("Renovierung"));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue