64 lines
1.5 KiB
Java
64 lines
1.5 KiB
Java
package de.hsel.spm.baudas.analysis;
|
|
|
|
import weka.core.Instance;
|
|
import weka.core.Instances;
|
|
|
|
import java.io.File;
|
|
import java.util.AbstractMap;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* Week Overview Analysis.
|
|
*
|
|
* @author Julian Hinxlage
|
|
* @version 0.1
|
|
* @since 0.1
|
|
**/
|
|
public class WeekOverview implements Analysis<Map<String, Map.Entry<Double, Integer>>> {
|
|
|
|
private Instances instances;
|
|
private Map<String, Map.Entry<Double, Integer>> result;
|
|
|
|
public WeekOverview(File file) {
|
|
result = new HashMap<>();
|
|
instances = load(file);
|
|
}
|
|
|
|
@Override
|
|
public Map<String, Map.Entry<Double, Integer>> getResult() {
|
|
|
|
int dayIndex = 5;
|
|
int amountIndex = 10;
|
|
|
|
int startArticles = 11;
|
|
int endArticles = 25;
|
|
|
|
|
|
for (int i = 0; i < instances.numInstances(); i++) {
|
|
Instance instance = instances.get(i);
|
|
double amount = instance.value(amountIndex);
|
|
String day = instance.stringValue(dayIndex);
|
|
|
|
|
|
int count = 0;
|
|
for (int j = startArticles; j < endArticles; j++) {
|
|
count += (int) instance.value(j);
|
|
}
|
|
|
|
if (!result.containsKey(day)) {
|
|
result.put(day, new AbstractMap.SimpleEntry<>(0.0, 0));
|
|
}
|
|
result.put(day,
|
|
new AbstractMap.SimpleEntry<>(
|
|
result.get(day).getKey() + amount,
|
|
result.get(day).getValue() + count
|
|
)
|
|
);
|
|
}
|
|
|
|
|
|
return result;
|
|
}
|
|
}
|