added WeekOverview
This commit is contained in:
parent
0c3b480023
commit
713d972953
|
@ -0,0 +1,73 @@
|
|||
package de.hsel.spm.baudas.analysis;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Week Overview Analysis
|
||||
*
|
||||
* @author Julian Hinxlage
|
||||
* @version 0.1
|
||||
* @since 0.1
|
||||
**/
|
||||
public class WeekOverview implements Analysis<Map<String, Integer>> {
|
||||
|
||||
private Instances instances;
|
||||
private Map<String, Integer> result;
|
||||
|
||||
public WeekOverview(File file) {
|
||||
result = new HashMap<String, Integer>();
|
||||
instances = load(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Integer> getResult() {
|
||||
|
||||
int[] keepIndexes = new int[]{5, 10};
|
||||
int dayIndex = 0;
|
||||
int amountIndex = 1;
|
||||
|
||||
|
||||
try {
|
||||
//Remove all other attributes
|
||||
Remove remove = new Remove();
|
||||
remove.setAttributeIndicesArray(keepIndexes);
|
||||
remove.setInvertSelection(true);
|
||||
remove.setInputFormat(instances);
|
||||
instances = Filter.useFilter(instances, remove);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < instances.attribute(dayIndex).numValues(); i++) {
|
||||
String day = instances.attribute(dayIndex).value(i);
|
||||
|
||||
System.out.println(day);
|
||||
|
||||
|
||||
for (int j = 0; j < instances.attribute(amountIndex).numValues(); j++) {
|
||||
String amount = instances.attribute(amountIndex).value(j);
|
||||
|
||||
System.out.println(amount);
|
||||
|
||||
int x = Integer.parseInt(amount);
|
||||
|
||||
if(!result.containsKey(day)){
|
||||
result.put(day,0);
|
||||
}
|
||||
result.put(day,result.get(day) + x);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package de.hsel.spm.baudas;
|
||||
|
||||
import de.hsel.spm.baudas.analysis.WeekOverview;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* Week Overview Analysis Test
|
||||
*
|
||||
* @author Julian Hinxlage
|
||||
* @version 0.1
|
||||
* @since 0.1
|
||||
**/
|
||||
public class WeekOverviewTest {
|
||||
|
||||
@Test
|
||||
public void test(){
|
||||
WeekOverview overview = new WeekOverview(new File(getClass().getClassLoader().getResource("kd100.csv").getFile()));
|
||||
|
||||
Map<String, Integer> result = overview.getResult();
|
||||
|
||||
for(Map.Entry<String, Integer> i : result.entrySet()){
|
||||
System.out.println(i.getKey() + " = " + i.getValue());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue