From 094e539c7639dd0e23d984dd424571521513003a Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Thu, 18 Apr 2019 21:34:24 +0200 Subject: [PATCH] + erste Versuche mit Weka Signed-off-by: Johannes Theiner --- .../spm/baudas/analysis/ShoppingTimes.java | 58 +++++++++++++++++++ .../baudas/analysis/ShoppingTimesTest.java | 40 +++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 src/main/java/de/hsel/spm/baudas/analysis/ShoppingTimes.java create mode 100644 src/test/java/de/hsel/spm/baudas/analysis/ShoppingTimesTest.java diff --git a/src/main/java/de/hsel/spm/baudas/analysis/ShoppingTimes.java b/src/main/java/de/hsel/spm/baudas/analysis/ShoppingTimes.java new file mode 100644 index 0000000..bca82b1 --- /dev/null +++ b/src/main/java/de/hsel/spm/baudas/analysis/ShoppingTimes.java @@ -0,0 +1,58 @@ +package de.hsel.spm.baudas.analysis; + +import javafx.util.Pair; +import weka.core.Instances; +import weka.filters.Filter; +import weka.filters.unsupervised.attribute.Remove; + +import java.io.File; +import java.util.Map; + +/** + * @author Johannes Theiner + * @version 0.1 + * @since 0.1 + **/ +public class ShoppingTimes implements Analysis, Integer>>{ + + private Instances instances; + private Map, Integer> result; + + public ShoppingTimes(File file) { + instances = load(file); + } + + + @Override + public Map, Integer> getResult() { + if(result == null) { + int dayIndex = 0; + int hourIndex = 1; + int[] keepIndexes = new int[]{5, 6}; + + Remove remove = new Remove(); + try { + remove.setAttributeIndicesArray(keepIndexes); + remove.setInvertSelection(true); + remove.setInputFormat(instances); + instances = Filter.useFilter(instances, remove); + } catch (Exception ex) { + ex.printStackTrace(); + } + + + + + /*Map, Integer> hours = new HashMap<>(); + AttributeStats stats = instances.attributeStats(hourIndex); + for(int i = 0; i <= instances.attribute(hourIndex).numValues() - 1; i++) { + Pair pair = new Pair<>(instances.attribute(hourIndex).value(i), instances.attribute(0).value(i)); + hours.put(pair, stats.nominalCounts[i]); + } + result = hours;*/ + + + } + return result; + } +} \ No newline at end of file diff --git a/src/test/java/de/hsel/spm/baudas/analysis/ShoppingTimesTest.java b/src/test/java/de/hsel/spm/baudas/analysis/ShoppingTimesTest.java new file mode 100644 index 0000000..c0d419b --- /dev/null +++ b/src/test/java/de/hsel/spm/baudas/analysis/ShoppingTimesTest.java @@ -0,0 +1,40 @@ +package de.hsel.spm.baudas.analysis; + +import javafx.util.Pair; +import org.junit.jupiter.api.Test; + +import java.io.File; +import java.net.URL; +import java.time.Duration; +import java.util.Map; +import java.util.concurrent.atomic.AtomicReference; + +import static org.junit.jupiter.api.Assertions.assertTimeout; + +/** + * @author Johannes Theiner + * @version 0.1 + * @since 0.1 + **/ +public class ShoppingTimesTest { + + //TODO: mehr Tests + + @Test + public void test100() { + URL url = getClass().getClassLoader().getResource("kd100.csv"); + assert url != null; + ShoppingTimes overview = new ShoppingTimes(new File(url.getFile())); + + AtomicReference, Integer>> results = new AtomicReference<>(); + + assertTimeout(Duration.ofMillis(450), () -> results.set(overview.getResult())); + /*for(Pair pair : results.get().keySet()) { + System.out.println(pair); + }*/ + + + //assertEquals(21, results.get().get(new Pair<>("Montag", ">17 Uhr"))); + //TODO: mehr Tests + } +} \ No newline at end of file