Merge branch 'SPM-17'
This commit is contained in:
commit
a10f5f141c
|
@ -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;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
|
@ -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<Map<DayHour, Integer>> {
|
||||||
|
|
||||||
|
private Instances instances;
|
||||||
|
private Map<DayHour, Integer> 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<DayHour, Integer> 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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<Map<DayHour, Integer>> 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<Map<DayHour, Integer>> 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<Map<DayHour, Integer>> 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")));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue