diff --git a/src/main/java/de/hsel/spm/baudas/analysis/Analysis.java b/src/main/java/de/hsel/spm/baudas/analysis/Analysis.java index b8bc054..3f8f86a 100644 --- a/src/main/java/de/hsel/spm/baudas/analysis/Analysis.java +++ b/src/main/java/de/hsel/spm/baudas/analysis/Analysis.java @@ -8,7 +8,7 @@ import java.io.File; import java.io.IOException; /** - * base interface for analysis + * base interface for analysis. * * @author Johannes Theiner * @version 0.1 @@ -19,7 +19,7 @@ public interface Analysis { /** - * loads data from csv file + * loads data from csv file. * * @param file File to analyze * @return loaded data in weka format @@ -37,7 +37,7 @@ public interface Analysis { } /** - * result of the analysis + * result of the analysis. * * @return result as T */ diff --git a/src/main/java/de/hsel/spm/baudas/analysis/ShoppingTimes.java b/src/main/java/de/hsel/spm/baudas/analysis/ShoppingTimes.java index 3a97155..b904cb4 100644 --- a/src/main/java/de/hsel/spm/baudas/analysis/ShoppingTimes.java +++ b/src/main/java/de/hsel/spm/baudas/analysis/ShoppingTimes.java @@ -11,6 +11,8 @@ import java.util.HashMap; import java.util.Map; /** + * Shopping Times Analysis. + * * @author Johannes Theiner * @version 0.1 * @since 0.1 @@ -25,6 +27,11 @@ public class ShoppingTimes implements Analysis> { } + /** + * get customer count at specific times. + * + * @return Map of Day-Hour Combinations and the corresponding customer count + */ @Override public Map getResult() { if (result == null) { @@ -34,6 +41,7 @@ public class ShoppingTimes implements Analysis> { int hourIndex = 1; try { + //Remove all other attributes Remove remove = new Remove(); remove.setAttributeIndicesArray(keepIndexes); remove.setInvertSelection(true); @@ -43,14 +51,22 @@ public class ShoppingTimes implements Analysis> { ex.printStackTrace(); } + /* + remove all days except one and get the stats + needed because weka has no other way to combine attributes + */ for (int i = 0; i < instances.attribute(dayIndex).numValues(); i++) { String day = instances.attribute(dayIndex).value(i); Instances instancesCopy = new Instances(instances, 0, instances.numInstances()); + + for (int j = instancesCopy.numInstances() - 1; j >= 0; j--) { Instance instance = instancesCopy.get(j); if(!instance.stringValue(dayIndex).equals(day)) instancesCopy.delete(j); } + + //get customer count and put into map AttributeStats stats = instancesCopy.attributeStats(hourIndex); for (int j = 0; j < instancesCopy.attribute(hourIndex).numValues(); j++) { DayHour dayHour = new DayHour(day, instancesCopy.attribute(hourIndex).value(j)); diff --git a/src/test/java/de/hsel/spm/baudas/analysis/ShoppingTimesTest.java b/src/test/java/de/hsel/spm/baudas/analysis/ShoppingTimesTest.java index 14fad53..b5651cc 100644 --- a/src/test/java/de/hsel/spm/baudas/analysis/ShoppingTimesTest.java +++ b/src/test/java/de/hsel/spm/baudas/analysis/ShoppingTimesTest.java @@ -12,7 +12,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTimeout; /** - * @author Johannes Theiner + * @author hier Namen eintragen * @version 0.1 * @since 0.1 **/ @@ -28,7 +28,7 @@ public class ShoppingTimesTest { AtomicReference> results = new AtomicReference<>(); - assertTimeout(Duration.ofMillis(1300), () -> results.set(overview.getResult())); + assertTimeout(Duration.ofMillis(1700), () -> results.set(overview.getResult())); assertEquals(4, results.get().get(new DayHour("Montag", "10-12 Uhr"))); //TODO: mehr Tests