Commit 31358cef authored by Stefan Schuhbaeck's avatar Stefan Schuhbaeck

add SimulationResult Table Dialog with csv export of simulation run results.

parent d113b8f1
......@@ -7,6 +7,15 @@ import org.vadere.simulator.projects.ProjectFinishedListener;
import org.vadere.simulator.projects.SimulationResult;
import org.vadere.simulator.projects.VadereProject;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.LinkedList;
import javax.swing.*;
......@@ -38,16 +47,105 @@ public class ProjectRunResultDialog implements ProjectFinishedListener {
.append(" State: ").append(res.getState()).append("\n\n");
}
String title = simulationResultList.size() > 1 ? "Simulation Results" : "Simulation Result";
String infoMessage = sb.toString();
if (projectViewModel.isShowSimulationResultDialog()){
if (projectViewModel.isShowSimulationResultDialog()) {
SwingUtilities.invokeLater(() -> {
JOptionPane.showMessageDialog(projectView, infoMessage, title, JOptionPane.INFORMATION_MESSAGE);
JDialog dialog = new ResultDialog(projectView, simulationResultList);
dialog.setVisible(true);
});
} else {
logger.info(sb.toString());
}
}
class ResultDialog extends JDialog {
private final String[] columnNames = {"Scenario_Name",
"Runtime",
"Overlaps",
"State"};
Button btnOk, btnCsv;
private JTable table;
JPanel main;
JScrollPane scrollPane;
JPanel btnPane;
LinkedList<SimulationResult> data;
public ResultDialog(ProjectView projectView, LinkedList<SimulationResult> data) {
super(projectView);
this.data = data;
main = new JPanel();
main.setLayout(new BoxLayout(main, BoxLayout.PAGE_AXIS));
table = new JTable(getData(data), columnNames);
table.setFillsViewportHeight(true);
table.doLayout();
scrollPane = new JScrollPane(table);
main.add(scrollPane);
btnOk = new Button("Close");
btnOk.addActionListener(this::btnOKListener);
btnCsv = new Button("Export csv");
btnPane = new JPanel();
btnCsv.addActionListener(this::btnCsvListener);
btnPane.setLayout(new BoxLayout(btnPane, BoxLayout.LINE_AXIS));
btnPane.add(Box.createHorizontalGlue());
btnPane.add(btnOk);
btnPane.add(Box.createRigidArea(new Dimension(10, 0)));
btnPane.add(btnCsv);
Container c = getContentPane();
c.add(main, BorderLayout.CENTER);
c.add(btnPane, BorderLayout.PAGE_END);
setTitle("Simulation Result");
setSize(600, 200);
}
public Object[][] getData(LinkedList<SimulationResult> data) {
Object[][] res = new Object[data.size()][4];
int rowIdx = 0;
for (SimulationResult d : data) {
res[rowIdx] = d.getAsTableRow();
rowIdx++;
}
return res;
}
private void btnOKListener(ActionEvent actionEvent) {
setVisible(false);
}
private void btnCsvListener(ActionEvent actionEvent) {
StringBuilder sj = new StringBuilder();
SimulationResult.addCsvHeader(sj, ';');
data.forEach(i -> i.addCsvRow(sj, ';'));
FileDialog fd = new FileDialog(this, "Bitte eine Datei waehlen!", FileDialog.SAVE);
fd.setVisible(true);
Path p = (Paths.get(fd.getDirectory()).resolve(fd.getFile()));
fd.setVisible(false);
try (OutputStreamWriter writer =
new OutputStreamWriter(new FileOutputStream(p.toString(), false), StandardCharsets.UTF_8)) {
writer.write(sj.toString());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
setVisible(false);
}
}
}
......@@ -15,6 +15,10 @@
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestrianIdOverlapOutputFile",
"filename" : "out.txt",
"processors" : [ 3 ]
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.NoDataKeyOutputFile",
"filename" : "out1.txt",
"processors" : [ 4 ]
} ],
"processors" : [ {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianPositionProcessor",
......@@ -77,7 +81,7 @@
"stepLengthSlopeSpeed" : 0.2345,
"stepLengthSD" : 0.036,
"movementThreshold" : 0.0,
"optimizationType" : "DISCRETE",
"optimizationType" : "NELDER_MEAD",
"movementType" : "ARBITRARY",
"dynamicStepLength" : false,
"updateType" : "EVENT_DRIVEN",
......
......@@ -11,6 +11,14 @@
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.PedestrianIdOutputFile",
"filename" : "evacuationTimes.txt",
"processors" : [ 2 ]
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.NoDataKeyOutputFile",
"filename" : "out.txt",
"processors" : [ 5 ]
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestrianIdOverlapOutputFile",
"filename" : "out1.txt",
"processors" : [ 6 ]
} ],
"processors" : [ {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianWaitingTimeProcessor",
......@@ -38,6 +46,20 @@
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianStartTimeProcessor",
"id" : 4
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.NumberOverlapsProcessor",
"id" : 5,
"attributesType" : "org.vadere.state.attributes.processor.AttributesNumberOverlapsProcessor",
"attributes" : {
"pedestrianOverlapProcessorId" : 6
}
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianOverlapProcessor",
"id" : 6,
"attributesType" : "org.vadere.state.attributes.processor.AttributesPedestrianOverlapProcessor",
"attributes" : {
"pedRadius" : 0.2
}
} ],
"isTimestamped" : true
},
......
......@@ -7,6 +7,14 @@
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestrianIdOutputFile",
"filename" : "postvis.trajectories",
"processors" : [ 1, 2 ]
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.NoDataKeyOutputFile",
"filename" : "out.txt",
"processors" : [ 3 ]
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestrianIdOverlapOutputFile",
"filename" : "out1.txt",
"processors" : [ 4 ]
} ],
"processors" : [ {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianPositionProcessor",
......@@ -14,6 +22,20 @@
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianTargetIdProcessor",
"id" : 2
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.NumberOverlapsProcessor",
"id" : 3,
"attributesType" : "org.vadere.state.attributes.processor.AttributesNumberOverlapsProcessor",
"attributes" : {
"pedestrianOverlapProcessorId" : 4
}
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianOverlapProcessor",
"id" : 4,
"attributesType" : "org.vadere.state.attributes.processor.AttributesPedestrianOverlapProcessor",
"attributes" : {
"pedRadius" : 0.2
}
} ],
"isTimestamped" : true
},
......
......@@ -26,7 +26,7 @@ import java.util.Random;
public abstract class SourceController {
protected final double NO_EVENT = Double.MAX_VALUE;
public static final double SPAWN_BUFFER_SIZE = 0.001;
public static final double SPAWN_BUFFER_SIZE = 0.01;
protected final Source source;
private final DynamicElementFactory dynamicElementFactory;
......
package org.vadere.simulator.projects;
import org.lwjgl.system.CallbackI;
import org.vadere.simulator.projects.dataprocessing.datakey.DataKey;
import java.time.Duration;
import java.time.Instant;
import java.util.Date;
import java.util.Arrays;
public class SimulationResult {
......@@ -63,6 +60,30 @@ public class SimulationResult {
this.state = state;
}
public String[] getAsTableRow(){
String[] ret = new String[4];
ret[0] = scenarioName;
ret[1] = runTime.toString();
ret[2] = Integer.toString(totalOverlaps);
ret[3] = state;
return ret;
}
public void addCsvRow(StringBuilder sj, char dl){
Arrays.stream(getAsTableRow()).forEach(i -> sj.append(i).append(dl));
sj.setLength(sj.length() -1);
sj.append("\n");
}
public static void addCsvHeader(StringBuilder sj, char dl){
sj.append("Scenario_Name").append(dl);
sj.append("Runtime").append(dl);
sj.append("Overlaps").append(dl);
sj.append("State\n");
}
@Override
public String toString() {
return "SimulationResult{" +
......
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