Merge branch 'SPM-14' of Studium/Softwareprojektmanagement into master

This commit is contained in:
Johannes Theiner 2019-05-06 13:50:05 +00:00 committed by Gitea
commit f5fe0d74cc
4 changed files with 172 additions and 4 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
*.iml *.iml
.idea .idea
.project .project
target

View File

@ -8,7 +8,7 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
/** /**
* base interface for analysis * base interface for analysis.
* *
* @author Johannes Theiner * @author Johannes Theiner
* @version 0.1 * @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 * @param file File to analyze
* @return loaded data in weka format * @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 * @return result as T
*/ */

View File

@ -0,0 +1,63 @@
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() {
//TODO: replace values when #SPM-17 is merged
int dayIndex = 5;
int amountIndex = 10;
int startArticles = 11;
int endArticles = 26;
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;
}
}

View File

@ -0,0 +1,104 @@
package de.hsel.spm.baudas.analysis;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.net.URL;
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;
/**
* Week Overview Analysis Test.
*
* @author Johannes Theiner
* @version 0.1
* @since 0.1
**/
class WeekOverviewTest {
@Test
void test100() {
URL url = getClass().getClassLoader().getResource("kd100.csv");
assert url != null;
WeekOverview overview = new WeekOverview(new File(url.getFile()));
AtomicReference<Map<String, Map.Entry<Double, Integer>>> result = new AtomicReference<>();
assertTimeout(Duration.ofMillis(1), () -> result.set(overview.getResult()));
assertEquals(2477, result.get().get("Montag").getKey());
assertEquals(3359, result.get().get("Dienstag").getKey());
assertEquals(1436, result.get().get("Mittwoch").getKey());
assertEquals(2472, result.get().get("Donnerstag").getKey());
assertEquals(2399, result.get().get("Freitag").getKey());
assertEquals(18273, result.get().get("Samstag").getKey());
assertEquals(3216, result.get().get("Montag").getValue());
assertEquals(5503, result.get().get("Dienstag").getValue());
assertEquals(1888, result.get().get("Mittwoch").getValue());
assertEquals(3568, result.get().get("Donnerstag").getValue());
assertEquals(2953, result.get().get("Freitag").getValue());
assertEquals(26243, result.get().get("Samstag").getValue());
}
@Test
void test1000() {
URL url = getClass().getClassLoader().getResource("kd1000.csv");
assert url != null;
WeekOverview overview = new WeekOverview(new File(url.getFile()));
AtomicReference<Map<String, Map.Entry<Double, Integer>>> result = new AtomicReference<>();
assertTimeout(Duration.ofMillis(3), () -> result.set(overview.getResult()));
assertEquals(26273, result.get().get("Montag").getKey());
assertEquals(23345, result.get().get("Dienstag").getKey());
assertEquals(25203, result.get().get("Mittwoch").getKey());
assertEquals(26332, result.get().get("Donnerstag").getKey());
assertEquals(26413, result.get().get("Freitag").getKey());
assertEquals(146279, result.get().get("Samstag").getKey());
assertEquals(39839, result.get().get("Montag").getValue());
assertEquals(34992, result.get().get("Dienstag").getValue());
assertEquals(37299, result.get().get("Mittwoch").getValue());
assertEquals(35005, result.get().get("Donnerstag").getValue());
assertEquals(38911, result.get().get("Freitag").getValue());
assertEquals(214051, result.get().get("Samstag").getValue());
}
@Test
void test10000() {
URL url = getClass().getClassLoader().getResource("kd10000.csv");
assert url != null;
WeekOverview overview = new WeekOverview(new File(url.getFile()));
AtomicReference<Map<String, Map.Entry<Double, Integer>>> result = new AtomicReference<>();
assertTimeout(Duration.ofMillis(15), () -> result.set(overview.getResult()));
assertEquals(295688, result.get().get("Montag").getKey());
assertEquals(267269, result.get().get("Dienstag").getKey());
assertEquals(269610, result.get().get("Mittwoch").getKey());
assertEquals(254510, result.get().get("Donnerstag").getKey());
assertEquals(330907, result.get().get("Freitag").getKey());
assertEquals(1410789, result.get().get("Samstag").getKey());
assertEquals(426952, result.get().get("Montag").getValue());
assertEquals(379125, result.get().get("Dienstag").getValue());
assertEquals(373891, result.get().get("Mittwoch").getValue());
assertEquals(356996, result.get().get("Donnerstag").getValue());
assertEquals(480062, result.get().get("Freitag").getValue());
assertEquals(2015766, result.get().get("Samstag").getValue());
}
}