+ Documentation

#SPM-17: add work documentation 30m Dokumentation
This commit is contained in:
Johannes Theiner 2019-04-23 15:36:22 +02:00
parent e6f0a9ce6f
commit feec46ecad
3 changed files with 21 additions and 5 deletions

View File

@ -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<T> {
/**
* 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<T> {
}
/**
* result of the analysis
* result of the analysis.
*
* @return result as T
*/

View File

@ -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<Map<DayHour, Integer>> {
}
/**
* 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) {
@ -34,6 +41,7 @@ public class ShoppingTimes implements Analysis<Map<DayHour, Integer>> {
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<Map<DayHour, Integer>> {
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));

View File

@ -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<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")));
//TODO: mehr Tests