Commit 4a8b7a9a authored by Daniel Lehmberg's avatar Daniel Lehmberg
Browse files

minor changes: change comment type for meta data, improve code

parent ba0da28c
Pipeline #85573 failed with stages
in 33 seconds
......@@ -26,9 +26,9 @@ import org.vadere.util.io.IOUtils;
/**
* Manages single simulation runs.
*
*
* @author Jakob Schöttl
*
*
*/
public class ScenarioRun implements Runnable {
......@@ -130,7 +130,7 @@ public class ScenarioRun implements Runnable {
// MDC.remove("scenario.Name");
}
}
public void simulationFailed(Throwable e) {
e.printStackTrace();
logger.error(e);
......
......@@ -24,7 +24,8 @@ public class ProcessorManager {
private List<OutputFile<?>> outputFiles;
private SimulationResult simulationResult;
public ProcessorManager(List<DataProcessor<?, ?>> dataProcessors, List<OutputFile<?>> outputFiles, MainModel mainModel) {
public ProcessorManager(List<DataProcessor<?, ?>> dataProcessors,
List<OutputFile<?>> outputFiles, MainModel mainModel) {
this.mainModel = mainModel;
this.outputFiles = outputFiles;
......@@ -65,8 +66,12 @@ public class ProcessorManager {
this.processorMap.values().forEach(proc -> proc.postLoopAddResultInfo(state, simulationResult));
}
public void setOutputPath(String directory) {
this.outputFiles.forEach(file -> file.setAbsoluteFileName(Paths.get(directory, String.format("%s", new File(file.getFileName()).getName())).toString()));
public void setOutputFiles(String directory) {
// for each file
this.outputFiles.forEach(file ->
file.setAbsoluteFileName(
Paths.get(directory, String.format("%s",
new File(file.getFileName()).getName())).toString()));
}
public void writeOutput() {
......@@ -87,4 +92,4 @@ public class ProcessorManager {
public void sealAllAttributes() {
processorMap.values().forEach(p -> p.sealAttributes());
}
}
}
\ No newline at end of file
package org.vadere.simulator.projects.dataprocessing.outputfile;
import org.vadere.simulator.projects.dataprocessing.datakey.DataKey;
......@@ -101,17 +103,17 @@ public abstract class OutputFile<K extends DataKey<K>> {
if (!isEmpty()) {
try (VadereWriter out = writerFactory.create(absoluteFileName)) {
writer = out;
this.writer = out;
if(this.isWriteMetaData){
printMetaData(out);
}
if(this.isWriteMetaData){
printMetaData();
}
printHeader(out);
printHeader();
this.dataProcessors.stream().flatMap(p -> p.getKeys().stream())
.distinct().sorted()
.forEach(key -> printRow(out, key));
.forEach(key -> printRow(key));
out.flush();
} catch (IOException e) {
......@@ -124,18 +126,30 @@ public abstract class OutputFile<K extends DataKey<K>> {
return this.dataProcessors.isEmpty();
}
private void printHeader(VadereWriter out) {
writeLine(out, this.getEntireHeader());
}
private void printMetaData(VadereWriter out){
String md = "//ROW=" + dataIndices.length + ",COL="+getEntireHeader().size(); // leave Java-style comment also for output
private void printMetaData(){
// use '#' symbol for comment -- the Java-style comment '//' is not appropriate because it requires two
// characters
String md = "#IDXCOL=" + dataIndices.length +
",DATACOL="+(getEntireHeader().size()-dataIndices.length)+","+
"SEP=\'"+ this.separator+"\'";
//Make a list with element to reuse writeLine function
//Make a list with one element to reuse 'writeLine' function
List<String> line = new LinkedList<>();
line.add(md);
writeLine(out, line);
writeLine(this.writer, line);
}
private void printHeader() {
writeLine(this.writer, this.getEntireHeader());
}
private void printRow(final K key) {
// Info: 'key' are the indices values (such as timeStep=3), can be more than one
@SuppressWarnings("unchecked")
final List<String> fields = composeLine(toStrings(key), p ->
Arrays.stream(p.toStrings(key)));
writeLine(this.writer, fields);
}
private List<String> getIndices(){
......@@ -161,13 +175,6 @@ public abstract class OutputFile<K extends DataKey<K>> {
return String.join(this.separator, this.getIndices());
}
private void printRow(final VadereWriter out, final K key) {
// Info: 'key' are the indices values (such as timeStep=3), can be more than one
@SuppressWarnings("unchecked")
final List<String> fields = composeLine(toStrings(key), p -> Arrays.stream(p.toStrings(key)));
writeLine(out, fields);
}
private List<String> headersWithNameMangling(){
LinkedList<String> headers = new LinkedList<>();
boolean isNameMangle = false; // assume there is no nameing conflict
......@@ -187,7 +194,7 @@ public abstract class OutputFile<K extends DataKey<K>> {
}
if(isNameMangle){
headers.clear(); //start from new...
headers.clear(); //start from new...
for (DataProcessor l: dataProcessors) {
List<String> list = Arrays.asList(l.getHeaders());
......@@ -210,8 +217,10 @@ public abstract class OutputFile<K extends DataKey<K>> {
return allHeaders;
}
private List<String> composeLine(String[] keyFieldArray, @SuppressWarnings("rawtypes") Function<DataProcessor, Stream<String>> valueFields) {
final List<String> fields = new LinkedList<>(Arrays.asList(keyFieldArray));
private List<String> composeLine(String[] keyFieldArray,
@SuppressWarnings("rawtypes") Function<DataProcessor, Stream<String>> valueFields){
final List<String> fields = new
LinkedList<>(Arrays.asList(keyFieldArray));
final List<String> processorFields = dataProcessors.stream()
.flatMap(valueFields)
......@@ -254,4 +263,4 @@ public abstract class OutputFile<K extends DataKey<K>> {
public void setVadereWriterFactory(VadereWriterFactory writerFactory) {
this.writerFactory = writerFactory;
}
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment