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;
|
package de.hsel.spm.baudas.analysis;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Johannes Theiner
|
* @author Johannes Theiner
|
||||||
|
@ -9,6 +11,8 @@ import lombok.Data;
|
||||||
**/
|
**/
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
@EqualsAndHashCode
|
||||||
|
@AllArgsConstructor
|
||||||
public class DayHour {
|
public class DayHour {
|
||||||
|
|
||||||
private String day;
|
private String day;
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
package de.hsel.spm.baudas.analysis;
|
package de.hsel.spm.baudas.analysis;
|
||||||
|
|
||||||
|
import weka.core.AttributeStats;
|
||||||
|
import weka.core.Instance;
|
||||||
import weka.core.Instances;
|
import weka.core.Instances;
|
||||||
import weka.filters.Filter;
|
import weka.filters.Filter;
|
||||||
import weka.filters.unsupervised.attribute.Remove;
|
import weka.filters.unsupervised.attribute.Remove;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -25,6 +28,7 @@ public class ShoppingTimes implements Analysis<Map<DayHour, Integer>> {
|
||||||
@Override
|
@Override
|
||||||
public Map<DayHour, Integer> getResult() {
|
public Map<DayHour, Integer> getResult() {
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
|
result = new HashMap<>();
|
||||||
int[] keepIndexes = new int[]{Attribute.SHOPPING_DAY, Attribute.SHOPPING_HOUR};
|
int[] keepIndexes = new int[]{Attribute.SHOPPING_DAY, Attribute.SHOPPING_HOUR};
|
||||||
int dayIndex = 0;
|
int dayIndex = 0;
|
||||||
int hourIndex = 1;
|
int hourIndex = 1;
|
||||||
|
@ -39,40 +43,21 @@ public class ShoppingTimes implements Analysis<Map<DayHour, Integer>> {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < instances.attribute(dayIndex).numValues(); i++) {
|
||||||
|
String day = instances.attribute(dayIndex).value(i);
|
||||||
/*try {
|
Instances instancesCopy = new Instances(instances, 0, instances.numInstances());
|
||||||
SubsetByExpression byExpression = new SubsetByExpression();
|
for (int j = instancesCopy.numInstances() - 1; j >= 0; j--) {
|
||||||
byExpression.setExpression("(1 == Montag)");
|
Instance instance = instancesCopy.get(j);
|
||||||
byExpression.setInputFormat(instances);
|
if(!instance.stringValue(dayIndex).equals(day))
|
||||||
instances = Filter.useFilter(instances, byExpression);
|
instancesCopy.delete(j);
|
||||||
} catch (Exception e) {
|
}
|
||||||
e.printStackTrace();
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import java.time.Duration;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTimeout;
|
import static org.junit.jupiter.api.Assertions.assertTimeout;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -27,13 +28,9 @@ public class ShoppingTimesTest {
|
||||||
|
|
||||||
AtomicReference<Map<DayHour, Integer>> results = new AtomicReference<>();
|
AtomicReference<Map<DayHour, Integer>> results = new AtomicReference<>();
|
||||||
|
|
||||||
assertTimeout(Duration.ofMillis(500), () -> results.set(overview.getResult()));
|
assertTimeout(Duration.ofMillis(1300), () -> results.set(overview.getResult()));
|
||||||
/*for(Pair<String, String> pair : results.get().keySet()) {
|
|
||||||
System.out.println(pair);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
assertEquals(4, results.get().get(new DayHour("Montag", "10-12 Uhr")));
|
||||||
//assertEquals(21, results.get().get(new Pair<>("Montag", ">17 Uhr")));
|
|
||||||
//TODO: mehr Tests
|
//TODO: mehr Tests
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue