Funktionierende Version über kleinen Umweg
Signed-off-by: Johannes Theiner <j.theiner@live.de> #SPM-17: add work development 1h 30m funktionierende Version
This commit is contained in:
parent
6ebf46b65c
commit
e6f0a9ce6f
|
@ -1,6 +1,8 @@
|
|||
package de.hsel.spm.baudas.analysis;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* @author Johannes Theiner
|
||||
|
@ -9,6 +11,8 @@ import lombok.Data;
|
|||
**/
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode
|
||||
@AllArgsConstructor
|
||||
public class DayHour {
|
||||
|
||||
private String day;
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
package de.hsel.spm.baudas.analysis;
|
||||
|
||||
import weka.core.AttributeStats;
|
||||
import weka.core.Instance;
|
||||
import weka.core.Instances;
|
||||
import weka.filters.Filter;
|
||||
import weka.filters.unsupervised.attribute.Remove;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
@ -25,6 +28,7 @@ public class ShoppingTimes implements Analysis<Map<DayHour, Integer>> {
|
|||
@Override
|
||||
public Map<DayHour, Integer> getResult() {
|
||||
if (result == null) {
|
||||
result = new HashMap<>();
|
||||
int[] keepIndexes = new int[]{Attribute.SHOPPING_DAY, Attribute.SHOPPING_HOUR};
|
||||
int dayIndex = 0;
|
||||
int hourIndex = 1;
|
||||
|
@ -39,39 +43,20 @@ public class ShoppingTimes implements Analysis<Map<DayHour, Integer>> {
|
|||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*try {
|
||||
SubsetByExpression byExpression = new SubsetByExpression();
|
||||
byExpression.setExpression("(1 == Montag)");
|
||||
byExpression.setInputFormat(instances);
|
||||
instances = Filter.useFilter(instances, byExpression);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
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);
|
||||
}
|
||||
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));
|
||||
result.put(dayHour, stats.nominalCounts[j]);
|
||||
}
|
||||
|
||||
|
||||
Enumeration<Object> dayValues = instances.attribute(dayIndex).enumerateValues();
|
||||
int i = 0;
|
||||
while (dayValues.hasMoreElements()) {
|
||||
System.out.println(dayValues.nextElement() + " " + instances.attributeStats(dayIndex).nominalCounts[i]);
|
||||
i++;
|
||||
}
|
||||
|
||||
Enumeration<Object> hourValues = instances.attribute(hourIndex).enumerateValues();
|
||||
i = 0;
|
||||
while (hourValues.hasMoreElements()) {
|
||||
System.out.println(hourValues.nextElement() + " " + instances.attributeStats(hourIndex).nominalCounts[i]);
|
||||
i++;
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
/* AttributeStats stats = instances.attributeStats(hourIndex);
|
||||
for (i = 0; i <= instances.attribute(hourIndex).numValues() - 1; i++) {
|
||||
System.out.println(instances.attribute(hourIndex).value(i) + " " + stats.nominalCounts[i]);
|
||||
}*/
|
||||
|
||||
|
||||
}
|
||||
return result;
|
||||
|
|
|
@ -8,6 +8,7 @@ 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;
|
||||
|
||||
/**
|
||||
|
@ -27,13 +28,9 @@ public class ShoppingTimesTest {
|
|||
|
||||
AtomicReference<Map<DayHour, Integer>> results = new AtomicReference<>();
|
||||
|
||||
assertTimeout(Duration.ofMillis(500), () -> results.set(overview.getResult()));
|
||||
/*for(Pair<String, String> pair : results.get().keySet()) {
|
||||
System.out.println(pair);
|
||||
}*/
|
||||
assertTimeout(Duration.ofMillis(1300), () -> results.set(overview.getResult()));
|
||||
|
||||
|
||||
//assertEquals(21, results.get().get(new Pair<>("Montag", ">17 Uhr")));
|
||||
assertEquals(4, results.get().get(new DayHour("Montag", "10-12 Uhr")));
|
||||
//TODO: mehr Tests
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue