diff --git a/src/main/java/de/hsel/spm/baudas/analysis/Attribute.java b/src/main/java/de/hsel/spm/baudas/analysis/Attribute.java new file mode 100644 index 0000000..375714b --- /dev/null +++ b/src/main/java/de/hsel/spm/baudas/analysis/Attribute.java @@ -0,0 +1,39 @@ +package de.hsel.spm.baudas.analysis; + +/** + * @author Johannes Theiner + * @version 0.1 + * @since 0.1 + **/ +public class Attribute { + + static final int SEX = 0; + static final int AGE = 1; + static final int KIDS = 2; + static final int MARITAL_STATUS = 3; + static final int EMPLOYED = 4; + static final int SHOPPING_DAY = 5; + static final int SHOPPING_HOUR = 6; + static final int RESIDENCE = 7; + static final int HOUSEHOLD_INCOME = 8; + static final int REGULAR = 9; + static final int PURCHASE_AMOUNT = 10; + static final int POWER_TOOLS = 11; + static final int HARDWARE = 12; + static final int HAND_TOOLS = 13; + static final int SANITARY = 14; + static final int LOCKING = 15; + static final int TILES = 16; + static final int COLORS = 17; + static final int FITTINGS = 18; + static final int RENOVATION = 19; + static final int ELECTRICAL = 20; + static final int BUILDING_MATERIAL = 21; + static final int WOOD = 22; + static final int FLOORING = 23; + static final int LIGHTS = 24; + static final int GARDENING_TOOLS = 25; + + + +} \ No newline at end of file diff --git a/src/main/java/de/hsel/spm/baudas/analysis/DayHour.java b/src/main/java/de/hsel/spm/baudas/analysis/DayHour.java new file mode 100644 index 0000000..52f7793 --- /dev/null +++ b/src/main/java/de/hsel/spm/baudas/analysis/DayHour.java @@ -0,0 +1,20 @@ +package de.hsel.spm.baudas.analysis; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * @author Johannes Theiner + * @version 0.1 + * @since 0.1 + **/ + +@Data +@EqualsAndHashCode +@AllArgsConstructor +public class DayHour { + + private String day; + private String hour; +} \ No newline at end of file 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..865517f --- /dev/null +++ b/src/main/java/de/hsel/spm/baudas/analysis/ShoppingTimes.java @@ -0,0 +1,48 @@ +package de.hsel.spm.baudas.analysis; + +import weka.core.Instance; +import weka.core.Instances; + +import java.io.File; +import java.util.HashMap; +import java.util.Map; + +/** + * Shopping Times Analysis. + * + * @author Johannes Theiner + * @version 0.1 + * @since 0.1 + **/ +public class ShoppingTimes implements Analysis> { + + private Instances instances; + private Map result; + + public ShoppingTimes(File file) { + instances = load(file); + } + + + /** + * get customer count at specific times. + * + * @return Map of Day-Hour Combinations and the corresponding customer count + */ + @Override + public Map getResult() { + if (result == null) { + result = new HashMap<>(); + + for(Instance instance : instances) { + DayHour dayHour = new DayHour(instance.stringValue(Attribute.SHOPPING_DAY), instance.stringValue(Attribute.SHOPPING_HOUR)); + int tmp = 1; + if(result.containsKey(dayHour)) + tmp = result.get(dayHour) + 1; + + result.put(dayHour, tmp); + } + } + 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..f6f572f --- /dev/null +++ b/src/test/java/de/hsel/spm/baudas/analysis/ShoppingTimesTest.java @@ -0,0 +1,71 @@ +package de.hsel.spm.baudas.analysis; + +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.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTimeout; + +/** + * @author Karsten Eden + * @version 0.1 + * @since 0.1 + **/ +class ShoppingTimesTest { + + @Test + void test100() { + URL url = getClass().getClassLoader().getResource("kd100.csv"); + assert url != null; + ShoppingTimes overview = new ShoppingTimes(new File(url.getFile())); + + AtomicReference> results = new AtomicReference<>(); + + assertTimeout(Duration.ofMillis(1700), () -> results.set(overview.getResult())); + + assertEquals(4, results.get().get(new DayHour("Montag", "10-12 Uhr"))); + assertEquals(9, results.get().get(new DayHour("Samstag", "12-14 Uhr"))); + assertEquals(1, results.get().get(new DayHour("Donnerstag", "14-17 Uhr"))); + assertEquals(3, results.get().get(new DayHour("Mittwoch", ">17 Uhr"))); + assertEquals(6, results.get().get(new DayHour("Dienstag", "<10 Uhr"))); + } + + @Test + void test1000(){ + URL url = getClass().getClassLoader().getResource("kd1000.csv"); + assert url != null; + ShoppingTimes overview = new ShoppingTimes(new File(url.getFile())); + + AtomicReference> results = new AtomicReference<>(); + + assertTimeout(Duration.ofMillis(3000), () -> results.set(overview.getResult())); + + assertEquals(37, results.get().get(new DayHour("Montag", "10-12 Uhr"))); + assertEquals(87, results.get().get(new DayHour("Samstag", "12-14 Uhr"))); + assertEquals(23, results.get().get(new DayHour("Donnerstag", "14-17 Uhr"))); + assertEquals(18, results.get().get(new DayHour("Mittwoch", ">17 Uhr"))); + assertEquals(18, results.get().get(new DayHour("Dienstag", "<10 Uhr"))); + } + + @Test + void test10000() { + URL url = getClass().getClassLoader().getResource("kd10000.csv"); + assert url != null; + ShoppingTimes overview = new ShoppingTimes(new File(url.getFile())); + + AtomicReference> results = new AtomicReference<>(); + + assertTimeout(Duration.ofMillis(3000), () -> results.set(overview.getResult())); + + assertEquals(303, results.get().get(new DayHour("Montag", "10-12 Uhr"))); + assertEquals(737, results.get().get(new DayHour("Samstag", "12-14 Uhr"))); + assertEquals(192, results.get().get(new DayHour("Donnerstag", "14-17 Uhr"))); + assertEquals(199, results.get().get(new DayHour("Mittwoch", ">17 Uhr"))); + assertEquals(149, results.get().get(new DayHour("Dienstag", "<10 Uhr"))); + } +} \ No newline at end of file