+ Documentation
#SPM-17: add work documentation 30m Dokumentation
This commit is contained in:
parent
e6f0a9ce6f
commit
feec46ecad
|
@ -8,7 +8,7 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* base interface for analysis
|
* base interface for analysis.
|
||||||
*
|
*
|
||||||
* @author Johannes Theiner
|
* @author Johannes Theiner
|
||||||
* @version 0.1
|
* @version 0.1
|
||||||
|
@ -19,7 +19,7 @@ public interface Analysis<T> {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* loads data from csv file
|
* loads data from csv file.
|
||||||
*
|
*
|
||||||
* @param file File to analyze
|
* @param file File to analyze
|
||||||
* @return loaded data in weka format
|
* @return loaded data in weka format
|
||||||
|
@ -37,7 +37,7 @@ public interface Analysis<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* result of the analysis
|
* result of the analysis.
|
||||||
*
|
*
|
||||||
* @return result as T
|
* @return result as T
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -11,6 +11,8 @@ import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Shopping Times Analysis.
|
||||||
|
*
|
||||||
* @author Johannes Theiner
|
* @author Johannes Theiner
|
||||||
* @version 0.1
|
* @version 0.1
|
||||||
* @since 0.1
|
* @since 0.1
|
||||||
|
@ -25,6 +27,11 @@ public class ShoppingTimes implements Analysis<Map<DayHour, Integer>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get customer count at specific times.
|
||||||
|
*
|
||||||
|
* @return Map of Day-Hour Combinations and the corresponding customer count
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Map<DayHour, Integer> getResult() {
|
public Map<DayHour, Integer> getResult() {
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
|
@ -34,6 +41,7 @@ public class ShoppingTimes implements Analysis<Map<DayHour, Integer>> {
|
||||||
int hourIndex = 1;
|
int hourIndex = 1;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
//Remove all other attributes
|
||||||
Remove remove = new Remove();
|
Remove remove = new Remove();
|
||||||
remove.setAttributeIndicesArray(keepIndexes);
|
remove.setAttributeIndicesArray(keepIndexes);
|
||||||
remove.setInvertSelection(true);
|
remove.setInvertSelection(true);
|
||||||
|
@ -43,14 +51,22 @@ public class ShoppingTimes implements Analysis<Map<DayHour, Integer>> {
|
||||||
ex.printStackTrace();
|
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++) {
|
for (int i = 0; i < instances.attribute(dayIndex).numValues(); i++) {
|
||||||
String day = instances.attribute(dayIndex).value(i);
|
String day = instances.attribute(dayIndex).value(i);
|
||||||
Instances instancesCopy = new Instances(instances, 0, instances.numInstances());
|
Instances instancesCopy = new Instances(instances, 0, instances.numInstances());
|
||||||
|
|
||||||
|
|
||||||
for (int j = instancesCopy.numInstances() - 1; j >= 0; j--) {
|
for (int j = instancesCopy.numInstances() - 1; j >= 0; j--) {
|
||||||
Instance instance = instancesCopy.get(j);
|
Instance instance = instancesCopy.get(j);
|
||||||
if(!instance.stringValue(dayIndex).equals(day))
|
if(!instance.stringValue(dayIndex).equals(day))
|
||||||
instancesCopy.delete(j);
|
instancesCopy.delete(j);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//get customer count and put into map
|
||||||
AttributeStats stats = instancesCopy.attributeStats(hourIndex);
|
AttributeStats stats = instancesCopy.attributeStats(hourIndex);
|
||||||
for (int j = 0; j < instancesCopy.attribute(hourIndex).numValues(); j++) {
|
for (int j = 0; j < instancesCopy.attribute(hourIndex).numValues(); j++) {
|
||||||
DayHour dayHour = new DayHour(day, instancesCopy.attribute(hourIndex).value(j));
|
DayHour dayHour = new DayHour(day, instancesCopy.attribute(hourIndex).value(j));
|
||||||
|
|
|
@ -12,7 +12,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTimeout;
|
import static org.junit.jupiter.api.Assertions.assertTimeout;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Johannes Theiner
|
* @author hier Namen eintragen
|
||||||
* @version 0.1
|
* @version 0.1
|
||||||
* @since 0.1
|
* @since 0.1
|
||||||
**/
|
**/
|
||||||
|
@ -28,7 +28,7 @@ public class ShoppingTimesTest {
|
||||||
|
|
||||||
AtomicReference<Map<DayHour, Integer>> results = new AtomicReference<>();
|
AtomicReference<Map<DayHour, Integer>> 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")));
|
assertEquals(4, results.get().get(new DayHour("Montag", "10-12 Uhr")));
|
||||||
//TODO: mehr Tests
|
//TODO: mehr Tests
|
||||||
|
|
Loading…
Reference in New Issue