Remove old processors and replace them by the new ones

parent 9260a9e6
{
"files": [ {
"type": "org.vadere.simulator.projects.dataprocessing_mtp.TimestepPedestrianIdOutputFile",
"type": "org.vadere.simulator.projects.dataprocessing.TimestepPedestrianIdOutputFile",
"filename": "output_ts_pid.txt",
"processors": [ 1, 2, 3, 5, 13, 14, 17 ],
"separator": ";"
}, {
"type": "org.vadere.simulator.projects.dataprocessing_mtp.PedestrianIdOutputFile",
"type": "org.vadere.simulator.projects.dataprocessing.PedestrianIdOutputFile",
"filename": "output_pid.txt",
"processors": [ 4, 8, 9, 10, 15, 16 ]
}, {
"type": "org.vadere.simulator.projects.dataprocessing_mtp.TimestepOutputFile",
"type": "org.vadere.simulator.projects.dataprocessing.TimestepOutputFile",
"filename": "output_ts.txt",
"processors": [ 6, 7 ]
}, {
"type": "org.vadere.simulator.projects.dataprocessing_mtp.NoDataKeyOutputFile",
"type": "org.vadere.simulator.projects.dataprocessing.NoDataKeyOutputFile",
"filename": "output_nokey.txt",
"processors": [ 11, 12 ]
}, {
"type": "org.vadere.simulator.projects.dataprocessing_mtp.TimestepPedestrianIdOutputFile",
"type": "org.vadere.simulator.projects.dataprocessing.TimestepPedestrianIdOutputFile",
"filename": "postvis.trajectories",
"processors": [ 1, 18 ]
} ],
"processors": [ {
"type": "org.vadere.simulator.projects.dataprocessing_mtp.PedestrianPositionProcessor",
"type": "org.vadere.simulator.projects.dataprocessing.PedestrianPositionProcessor",
"id": 1
}, {
"type": "org.vadere.simulator.projects.dataprocessing_mtp.PedestrianVelocityProcessor",
"type": "org.vadere.simulator.projects.dataprocessing.PedestrianVelocityProcessor",
"id": 2
}, {
"type": "org.vadere.simulator.projects.dataprocessing_mtp.PedestrianDensityCountingProcessor",
"type": "org.vadere.simulator.projects.dataprocessing.PedestrianDensityCountingProcessor",
"id": 3
}, {
"type": "org.vadere.simulator.projects.dataprocessing_mtp.PedestrianLastPositionProcessor",
"type": "org.vadere.simulator.projects.dataprocessing.PedestrianLastPositionProcessor",
"id": 4
}, {
"type": "org.vadere.simulator.projects.dataprocessing_mtp.PedestrianDensityGaussianProcessor",
"type": "org.vadere.simulator.projects.dataprocessing.PedestrianDensityGaussianProcessor",
"id": 5
}, {
"type": "org.vadere.simulator.projects.dataprocessing_mtp.AreaDensityVoronoiProcessor",
"type": "org.vadere.simulator.projects.dataprocessing.AreaDensityVoronoiProcessor",
"id": 6
}, {
"type": "org.vadere.simulator.projects.dataprocessing_mtp.AreaSpeedProcessor",
"type": "org.vadere.simulator.projects.dataprocessing.AreaSpeedProcessor",
"id": 7
}, {
"type": "org.vadere.simulator.projects.dataprocessing_mtp.PedestrianStartTimeProcessor",
"type": "org.vadere.simulator.projects.dataprocessing.PedestrianStartTimeProcessor",
"id": 8
}, {
"type": "org.vadere.simulator.projects.dataprocessing_mtp.PedestrianEndTimeProcessor",
"type": "org.vadere.simulator.projects.dataprocessing.PedestrianEndTimeProcessor",
"id": 9
}, {
"type": "org.vadere.simulator.projects.dataprocessing_mtp.PedestrianEvacuationTimeProcessor",
"type": "org.vadere.simulator.projects.dataprocessing.PedestrianEvacuationTimeProcessor",
"id": 10
}, {
"type": "org.vadere.simulator.projects.dataprocessing_mtp.MeanPedestrianEvacuationTimeProcessor",
"type": "org.vadere.simulator.projects.dataprocessing.MeanPedestrianEvacuationTimeProcessor",
"id": 11
}, {
"type": "org.vadere.simulator.projects.dataprocessing_mtp.EvacuationTimeProcessor",
"type": "org.vadere.simulator.projects.dataprocessing.EvacuationTimeProcessor",
"id": 12
}, {
"type": "org.vadere.simulator.projects.dataprocessing_mtp.PedestrianFlowProcessor",
"type": "org.vadere.simulator.projects.dataprocessing.PedestrianFlowProcessor",
"id": 13
}, {
"type": "org.vadere.simulator.projects.dataprocessing_mtp.PedestrianOverlapProcessor",
"type": "org.vadere.simulator.projects.dataprocessing.PedestrianOverlapProcessor",
"id": 14
}, {
"type": "org.vadere.simulator.projects.dataprocessing_mtp.PedestrianWaitingTimeProcessor",
"type": "org.vadere.simulator.projects.dataprocessing.PedestrianWaitingTimeProcessor",
"id": 15
}, {
"type": "org.vadere.simulator.projects.dataprocessing_mtp.PedestrianWaitingEndTimeProcessor",
"type": "org.vadere.simulator.projects.dataprocessing.PedestrianWaitingEndTimeProcessor",
"id": 16
}, {
"type": "org.vadere.simulator.projects.dataprocessing_mtp.PedestrianOSMStrideLengthProcessor",
"type": "org.vadere.simulator.projects.dataprocessing.PedestrianOSMStrideLengthProcessor",
"id": 17
}, {
"type": "org.vadere.simulator.projects.dataprocessing_mtp.PedestrianTargetIdProcessor",
"type": "org.vadere.simulator.projects.dataprocessing.PedestrianTargetIdProcessor",
"id": 18
}, {
"type": "org.vadere.simulator.projects.dataprocessing_mtp.PedestrianSourceIdProcessor",
"type": "org.vadere.simulator.projects.dataprocessing.PedestrianSourceIdProcessor",
"id": 19
} ],
"attributes": {
"org.vadere.simulator.projects.dataprocessing_mtp.AttributesVelocityProcessor": {
"org.vadere.simulator.projects.dataprocessing.AttributesVelocityProcessor": {
"processorId": 2,
"pedestrianPositionProcessorId": 1
},
"org.vadere.simulator.projects.dataprocessing_mtp.AttributesPedestrianDensityCountingProcessor": {
"org.vadere.simulator.projects.dataprocessing.AttributesPedestrianDensityCountingProcessor": {
"processorId": 3,
"pedestrianPositionProcessorId": 1,
"radius": 1.5
},
"org.vadere.simulator.projects.dataprocessing_mtp.AttributesPedestrianLastPositionProcessor": {
"org.vadere.simulator.projects.dataprocessing.AttributesPedestrianLastPositionProcessor": {
"processorId": 4,
"pedestrianPositionProcessorId": 1
},
"org.vadere.simulator.projects.dataprocessing_mtp.AttributesPedestrianDensityGaussianProcessor": {
"org.vadere.simulator.projects.dataprocessing.AttributesPedestrianDensityGaussianProcessor": {
"processorId": 5,
"pedestrianPositionProcessorId": 1
},
"org.vadere.simulator.projects.dataprocessing_mtp.AttributesAreaDensityVoronoiProcessor": {
"org.vadere.simulator.projects.dataprocessing.AttributesAreaDensityVoronoiProcessor": {
"processorId": 6,
"measurementArea": {
"x" : 5.0,
......@@ -114,7 +114,7 @@
"type" : "RECTANGLE"
}
},
"org.vadere.simulator.projects.dataprocessing_mtp.AttributesAreaSpeedProcessor": {
"org.vadere.simulator.projects.dataprocessing.AttributesAreaSpeedProcessor": {
"processorId": 7,
"measurementArea": {
"x" : 5.0,
......@@ -126,28 +126,28 @@
"pedestrianPositionProcessorId": 1,
"pedestrianVelocityProcessorId": 2
},
"org.vadere.simulator.projects.dataprocessing_mtp.AttributesPedestrianEvacuationTimeProcessor": {
"org.vadere.simulator.projects.dataprocessing.AttributesPedestrianEvacuationTimeProcessor": {
"processorId": 10,
"pedestrianStartTimeProcessorId": 8
},
"org.vadere.simulator.projects.dataprocessing_mtp.AttributesMeanPedestrianEvacuationTimeProcessor": {
"org.vadere.simulator.projects.dataprocessing.AttributesMeanPedestrianEvacuationTimeProcessor": {
"processorId": 11,
"pedestrianEvacuationTimeProcessorId": 10
},
"org.vadere.simulator.projects.dataprocessing_mtp.AttributesEvacuationTimeProcessor": {
"org.vadere.simulator.projects.dataprocessing.AttributesEvacuationTimeProcessor": {
"processorId": 12,
"pedestrianEvacuationTimeProcessorId": 10
},
"org.vadere.simulator.projects.dataprocessing_mtp.AttributesPedestrianFlowProcessor": {
"org.vadere.simulator.projects.dataprocessing.AttributesPedestrianFlowProcessor": {
"processorId": 13,
"pedestrianVelocityProcessorId": 2,
"pedestrianDensityProcessorId": 3
},
"org.vadere.simulator.projects.dataprocessing_mtp.AttributesPedestrianOverlapProcessor": {
"org.vadere.simulator.projects.dataprocessing.AttributesPedestrianOverlapProcessor": {
"processorId": 14,
"pedRadius": 0.21
},
"org.vadere.simulator.projects.dataprocessing_mtp.AttributesPedestrianWaitingTimeProcessor": {
"org.vadere.simulator.projects.dataprocessing.AttributesPedestrianWaitingTimeProcessor": {
"processorId": 15,
"waitingArea": {
"x" : 5.0,
......@@ -157,7 +157,7 @@
"type" : "RECTANGLE"
}
},
"org.vadere.simulator.projects.dataprocessing_mtp.AttributesPedestrianWaitingEndTimeProcessor": {
"org.vadere.simulator.projects.dataprocessing.AttributesPedestrianWaitingEndTimeProcessor": {
"processorId": 16,
"waitingArea": {
"x" : 5.0,
......
......@@ -5,7 +5,7 @@ import org.apache.log4j.Logger;
import org.vadere.gui.components.utils.Messages;
import org.vadere.gui.projectview.model.ProjectViewModel;
import org.vadere.simulator.projects.ScenarioRunManager;
import org.vadere.simulator.projects.dataprocessing.ProjectWriter;
import org.vadere.simulator.projects.ProjectWriter;
import org.vadere.util.io.IOUtils;
import javax.swing.*;
......
......@@ -4,7 +4,7 @@ import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.vadere.gui.projectview.model.ProjectViewModel;
import org.vadere.simulator.projects.ScenarioRunManager;
import org.vadere.simulator.projects.dataprocessing_mtp.DataProcessingJsonManager;
import org.vadere.simulator.projects.dataprocessing.DataProcessingJsonManager;
import org.vadere.state.scenario.Topography;
import java.io.IOException;
......
......@@ -4,13 +4,14 @@ import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.vadere.gui.components.utils.Messages;
import org.vadere.gui.projectview.model.ProjectViewModel;
import org.vadere.simulator.projects.ProjectWriter;
import org.vadere.simulator.projects.ScenarioRunManager;
import org.vadere.simulator.projects.dataprocessing.ProjectWriter;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.io.IOException;
import javax.swing.*;
public class ActionCloneScenario extends AbstractAction {
private static final long serialVersionUID = 1L;
......
......@@ -3,7 +3,7 @@ package org.vadere.gui.projectview.control;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.vadere.gui.projectview.model.ProjectViewModel;
import org.vadere.simulator.projects.dataprocessing.ProjectWriter;
import org.vadere.simulator.projects.ProjectWriter;
import org.vadere.util.io.IOUtils;
import javax.swing.*;
......
......@@ -6,9 +6,8 @@ import org.vadere.gui.components.utils.Messages;
import org.vadere.gui.projectview.model.ProjectViewModel;
import org.vadere.gui.projectview.model.VadereScenarioTableModel;
import org.vadere.gui.projectview.model.VadereState;
import org.vadere.gui.projectview.view.ProjectView;
import org.vadere.simulator.projects.ScenarioRunManager;
import org.vadere.simulator.projects.dataprocessing.ProjectWriter;
import org.vadere.simulator.projects.ProjectWriter;
import javax.swing.*;
import java.awt.*;
......
......@@ -11,7 +11,7 @@ import org.vadere.gui.projectview.view.VDialogManager;
import org.vadere.gui.projectview.view.VTable;
import org.vadere.simulator.projects.ScenarioRunManager;
import org.vadere.simulator.projects.VadereProject;
import org.vadere.simulator.projects.dataprocessing.ProjectWriter;
import org.vadere.simulator.projects.ProjectWriter;
import org.vadere.simulator.projects.io.IOOutput;
import javax.swing.*;
......
......@@ -6,7 +6,7 @@ import org.vadere.gui.components.utils.Resources;
import org.vadere.gui.projectview.VadereApplication;
import org.vadere.gui.projectview.control.ActionLoadProject;
import org.vadere.simulator.projects.VadereProject;
import org.vadere.simulator.projects.dataprocessing.ProjectWriter;
import org.vadere.simulator.projects.ProjectWriter;
import org.vadere.util.io.IOUtils;
import java.io.IOException;
......
......@@ -2,8 +2,8 @@ package org.vadere.gui.projectview.utils;
import org.vadere.simulator.models.MainModel;
import org.vadere.simulator.models.Model;
import org.vadere.simulator.projects.dataprocessing_mtp.OutputFile;
import org.vadere.simulator.projects.dataprocessing_mtp.Processor;
import org.vadere.simulator.projects.dataprocessing.OutputFile;
import org.vadere.simulator.projects.dataprocessing.Processor;
import org.vadere.state.attributes.Attributes;
import org.vadere.state.attributes.models.AttributesOSM;
......
package org.vadere.gui.projectview.view;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.vadere.simulator.projects.dataprocessing.processors.ProcessorFactory;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.*;
import java.util.Collection;
public class ChooseProcessorTypeDialog extends JDialog {
private Logger logger = LogManager.getLogger(getClass());
/**
* generated uid
*/
private static final long serialVersionUID = -1805248549919350762L;
private final JPanel contentPanel = new JPanel();
private JComboBox<String> comboBoxProcessorType;
private ChooseProcessorTypeDialog thisFrame;
private JTextPane txtpnProcessordescription;
private String selectedProcessor = "";
private boolean aborted;
public String getSelectedProcessorSimpleName() {
return selectedProcessor;
}
private void setProcText(final String simpleProcName) {
// Processor proc;
// proc =
// ProcessorManager.getInstance().createProcessor(ProcessorManager.getInstance().toProcessorType(simpleProcName));
txtpnProcessordescription.setText("missing description");
}
/**
* Create the dialog.
*/
public ChooseProcessorTypeDialog(Frame owner) {
super(owner, true);
thisFrame = this;
this.aborted = false;
setTitle("Choose Processor Type");
setBounds(100, 100, 450, 300);
getContentPane().setLayout(new BorderLayout());
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
getContentPane().add(contentPanel, BorderLayout.CENTER);
// change the processor description when the user selected a new
// processor
contentPanel.setLayout(new BorderLayout(0, 0));
{
comboBoxProcessorType = new JComboBox<>();
Collection<String> simpleProcessorNames = ProcessorFactory.getInstance().getSimpleProcessorNamesForGui();
comboBoxProcessorType
.setModel(new DefaultComboBoxModel<String>(simpleProcessorNames.toArray(new String[] {})));
comboBoxProcessorType.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent arg0) {
String simpleProcName = (String) (arg0.getItem());
setProcText(simpleProcName);
}
});
contentPanel.add(comboBoxProcessorType, BorderLayout.NORTH);
}
// the text pane with the processor description
{
txtpnProcessordescription = new JTextPane();
contentPanel.add(txtpnProcessordescription, BorderLayout.CENTER);
setProcText((String) comboBoxProcessorType.getSelectedItem());
}
// the panel where you can actually click ok after having selected an
// IOutputProcessor type
{
JPanel buttonPane = new JPanel();
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
getContentPane().add(buttonPane, BorderLayout.SOUTH);
{
JButton okButton = new JButton("OK");
okButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
selectedProcessor =
(String) ChooseProcessorTypeDialog.this.comboBoxProcessorType.getSelectedItem();
ChooseProcessorTypeDialog.this.dispose();
}
});
okButton.setActionCommand("OK");
buttonPane.add(okButton);
getRootPane().setDefaultButton(okButton);
}
}
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
aborted = true;
}
});
}
public boolean isAborted() {
return aborted;
}
}
......@@ -10,7 +10,7 @@ import org.fife.ui.rsyntaxtextarea.Theme;
import org.vadere.gui.components.utils.Messages;
import org.vadere.gui.projectview.VadereApplication;
import org.vadere.simulator.projects.ScenarioRunManager;
import org.vadere.simulator.projects.dataprocessing_mtp.DataProcessingJsonManager;
import org.vadere.simulator.projects.dataprocessing.DataProcessingJsonManager;
import org.vadere.simulator.projects.io.JsonConverter;
import org.vadere.state.attributes.ModelDefinition;
import org.vadere.state.scenario.Topography;
......
......@@ -6,7 +6,7 @@ import org.vadere.simulator.models.osm.OptimalStepsModel;
import org.vadere.simulator.projects.ScenarioRunManager;
import org.vadere.simulator.projects.ScenarioStore;
import org.vadere.simulator.projects.VadereProject;
import org.vadere.simulator.projects.dataprocessing.ProjectWriter;
import org.vadere.simulator.projects.ProjectWriter;
import org.vadere.simulator.projects.io.IOVadere;
import org.vadere.simulator.projects.io.JsonConverter;
import org.vadere.state.attributes.Attributes;
......@@ -15,7 +15,6 @@ import org.vadere.state.attributes.models.AttributesFloorField;
import org.vadere.state.attributes.models.AttributesOSM;
import org.vadere.state.attributes.models.AttributesPotentialCompact;
import org.vadere.state.attributes.models.AttributesPotentialOSM;
import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.scenario.Topography;
import org.xml.sax.SAXException;
......@@ -25,8 +24,6 @@ import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.LinkedList;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.stream.Collectors;
import static org.junit.Assert.assertEquals;
......
......@@ -3,19 +3,12 @@ package org.vadere.simulator.control;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.vadere.simulator.projects.ScenarioRunManager;
import org.vadere.simulator.projects.dataprocessing.writer.ProcessorWriter;
import org.vadere.state.scenario.Agent;
import org.vadere.state.scenario.Topography;
import org.vadere.state.simulation.Step;
import org.vadere.state.simulation.Trajectory;
import org.vadere.util.io.IOUtils;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.nio.file.Path;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
......@@ -26,7 +19,6 @@ public class OfflineSimulation {
private final Map<Integer, Trajectory> trajectories;
private final ScenarioRunManager vadere;
private final List<SimulationState> simulationStates;
private final List<ProcessorWriter> writers;
private static Logger logger = LogManager.getLogger(OfflineSimulation.class);
private final Path outputDir;
private final OfflineTopographyController topographyController;
......@@ -53,8 +45,6 @@ public class OfflineSimulation {
topographyController.prepareTopography();
simulationStates = pedestriansByStep.keySet().stream().sorted().map(step -> generateSimulationState(step))
.collect(Collectors.toList());
writers = vadere.getAllWriters();
}
private SimulationState generateSimulationState(final Step step) {
......@@ -65,27 +55,11 @@ public class OfflineSimulation {
.filter(t -> t.isPedestrianAlive(step))
.map(t -> t.getAgent(step))
.filter(opt -> opt.isPresent()).forEach(opt -> topography.addElement(opt.get()));
return new SimulationState(vadere.getName(), topography, vadere.getScenarioStore(), vadere.getAllWriters(),
return new SimulationState(vadere.getName(), topography, vadere.getScenarioStore(),
step.getSimTimeInSec().orElse(Double.NaN), step.getStepNumber(), vadere.getProcessorManager());
}
private void prepareOutput() {
DateFormat format = new SimpleDateFormat(IOUtils.DATE_FORMAT);
int writerCounter = 0; // needed to distinguish writers with the same name
String dateString = format.format(new Date());
for (ProcessorWriter writer : writers) {
Path processorOutputPath = outputDir;
String filename = String.format("%s_%s_%d_%s%s", vadere.getName(), writer.getProcessor().getName(),
(writerCounter++), dateString, writer.getProcessor().getFileExtension());
String procFileName = IOUtils.getPath(processorOutputPath.toString(), filename).toAbsolutePath().toString();
try {
writer.setOutputStream(new FileOutputStream(procFileName, false));
} catch (FileNotFoundException e) {
logger.error(e);
}
}
}
public void run() {
......@@ -93,20 +67,9 @@ public class OfflineSimulation {
prepareOutput();
if (!simulationStates.isEmpty()) {
for (ProcessorWriter writer : writers) {
writer.preLoop(simulationStates.get(0));
}
for (int index = 0; index < simulationStates.size(); index++) {
SimulationState state = simulationStates.get(index);
topographyController.update(state.getSimTimeInSec());
for (ProcessorWriter writer : writers) {
writer.update(state);
}
}
for (ProcessorWriter writer : writers) {
writer.postLoop(simulationStates.get(simulationStates.size() - 1));
}
}
}
......
......@@ -6,9 +6,7 @@ import org.vadere.simulator.models.DynamicElementFactory;
import org.vadere.simulator.models.MainModel;
import org.vadere.simulator.models.Model;
import org.vadere.simulator.projects.ScenarioStore;
import org.vadere.simulator.projects.dataprocessing.writer.ProcessorWriter;
import org.vadere.simulator.projects.dataprocessing.writer.Writer;
import org.vadere.simulator.projects.dataprocessing_mtp.ProcessorManager;
import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.state.attributes.AttributesSimulation;
import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.scenario.Source;
......@@ -36,7 +34,6 @@ public class Simulation {
private final List<PassiveCallback> passiveCallbacks;
private List<ActiveCallback> activeCallbacks;
private List<ProcessorWriter> processorWriter;
private ProcessorManager processorManager;
private boolean runSimulation = false;
......@@ -62,7 +59,7 @@ public class Simulation {
private Model model;
public Simulation(MainModel mainModel, double startTimeInSec, final String name, ScenarioStore scenarioStore,
List<PassiveCallback> passiveCallbacks, List<ProcessorWriter> processorWriter, Random random, ProcessorManager processorManager) {
List<PassiveCallback> passiveCallbacks, Random random, ProcessorManager processorManager) {
this.name = name;
this.model = mainModel;
this.scenarioStore = scenarioStore;
......@@ -81,7 +78,6 @@ public class Simulation {
// TODO [priority=normal] [task=bugfix] - the attributesCar are missing in initialize' parameters
this.dynamicElementFactory = mainModel;
this.processorWriter = processorWriter;
this.processorManager = processorManager;
this.passiveCallbacks = passiveCallbacks;
......@@ -121,10 +117,6 @@ public class Simulation {
ac.preLoop(simTimeInSec);
}
for (Writer ac : processorWriter) {
ac.preLoop(simulationState);
}