Commit d2b3758a authored by hm-schuhba1's avatar hm-schuhba1

Rework MigraionAssistant

MigrationAssistant
  |
  +-- IncidentMigrationAssistant (Deprecated)
  |
  +-- JsonMigrationAssistant
      |
      +--using JsonTransformation Interface

The JsonTransformation interface is implemented by in two
different ways:
AbstractJsonTransformation
  |              implements JsonTransformation, JsonNodeExplorer
  |
  +-- JoltTransformation --> relying on Jolt [1]
  |
  +-- SimpleJsonTransformation --> relying on Jackson JsonNode

The JsonTransformation interface provides a three step process
of to transform a given scenario File were each consumes a JsonNode
and returns the changed JsonNode.
1) preHooks
2) transformation
3) postHooks

The MigrationAssistant selects the correct implementation by
using the JsonTransformationFactory which map a given Version
to the corresponding implementation of some JsonTransformation.

1. Subclass either JoltTransformation or SimpeJsonTransformation.
  (a) If JoltTransformation is used, a specialized transformation syntax
      must be used. See [1] for Doc.
  (b) If SimpleJsonTransformation is used no additional input is needed.
       The transformation is done by manually manipulating the Jackson
       JsonNode-Tree
2. add annotation where X.X resembles the Version label i.e. "0.8"
   @MigrationTransformation(targetVersionLabel = "X.X")
3. add the default constructor with no arguments and the
   call super constructor passing the Version
4. Implement initDefaultHooks() and add the pre- and postHook
   LinkedList with JsonTransformationHooks
   (a) use add[Post|Pre][First|Last] methods.
   (b) add addPostHookLast(AbstractJsonTransformation::sort) to ensure
       the right sorting order within the scenario file.
5. (optional) overwrite any of applyPreHooks, applyTransformation,
   applyPostHooks if needed.
6. (optional) add generic JsonNode manipulations to JsonNodeExplorer

This interface contains useful default implementation to navigate a
JsonNode-Tree such as:

path(jsonNode, "some/path/within/the/json") <-- will return empty nodes
                                            with path das not exist
pathMustExist(jsonNode, "some/path/within/the/json") <-- will throw
                                                     MigrationException
renameField(node, "release", "version")  <-- rename keys

iteratorProcessorsByType(jsonRoot, "org...PedestrianVelocityProcessor )
  <-- returns an iterator of JsonNodes representing a
  PedestrianVelocityProcessor

[1]: https://github.com/bazaarvoice/joltSigned-off-by: hm-schuhba1's avatarhm-schuhba1 <stefan.schuhbaeck@hm.edu>
parent f3e5f552
......@@ -7,10 +7,10 @@ import java.lang.annotation.Target;
@Target(ElementType.TYPE)
@FactoryType(
factoryClassName = "JoltTransformationFactory",
extendedClassName = "JoltTransformationBaseFactory",
factoryImports = {"org.vadere.simulator.projects.migration.jolttranformation.JoltTransformationBaseFactory"},
factoryPackage = "org.vadere.simulator.projects.migration.jolttranformation"
factoryClassName = "JsonTransformationFactory",
extendedClassName = "JsonTransformationBaseFactory",
factoryImports = {"org.vadere.simulator.projects.migration.jsontranformation.JsonTransformationBaseFactory"},
factoryPackage = "org.vadere.simulator.projects.migration.jsontranformation"
)
public @interface MigrationTransformation {
......
package org.vadere.simulator.entrypoints;
import org.jetbrains.annotations.NotNull;
import org.vadere.simulator.projects.migration.incidents.VersionBumpIncident;
import java.util.Arrays;
import java.util.Optional;
import java.util.stream.Collectors;
/**
* Versions in strict order from oldest to newest.
......@@ -20,7 +18,8 @@ public enum Version {
V0_4("0.4"),
V0_5("0.5"),
V0_6("0.6"),
V0_7("0.7")
V0_7("0.7"),
V0_8("0.8"),
;
private String label;
......
......@@ -5,11 +5,11 @@ import net.sourceforge.argparse4j.inf.Namespace;
import org.vadere.simulator.entrypoints.Version;
import org.vadere.simulator.entrypoints.cmd.SubCommandRunner;
import org.vadere.simulator.projects.migration.JoltMigrationAssistant;
import org.vadere.simulator.projects.migration.jsontranformation.JsonMigrationAssistant;
import org.vadere.simulator.projects.migration.MigrationAssistant;
import org.vadere.simulator.projects.migration.MigrationException;
import org.vadere.simulator.projects.migration.MigrationOptions;
import org.vadere.simulator.projects.migration.helper.MigrationUtil;
import org.vadere.simulator.projects.migration.incident.helper.MigrationUtil;
import org.vadere.util.logging.Logger;
import java.io.IOException;
......@@ -94,7 +94,7 @@ public class MigrationSubCommand implements SubCommandRunner {
for (Path dir : dirs) {
logger.info("migrate directory to version(" + targetVersion.label() + "): " + dir.toAbsolutePath().toString());
if (projectOnly){
JoltMigrationAssistant migrationAssistant = new JoltMigrationAssistant();
JsonMigrationAssistant migrationAssistant = new JsonMigrationAssistant();
migrationAssistant.analyzeProject(dir.toString());
} else {
migrationUtil.migrateDirectoryTree(dir, targetVersion, recursive);
......@@ -147,7 +147,7 @@ public class MigrationSubCommand implements SubCommandRunner {
outputFile = Paths.get(outputPathString).resolve(scenarioFile.getFileName());
}
ma.migrateFile(scenarioFile, targetVersion, outputFile);
ma.migrateScenarioFile(scenarioFile, targetVersion, outputFile);
} catch (Exception e) {
......
......@@ -97,7 +97,7 @@ public class ScenarioRun implements Runnable {
// prepare processors and simulation data writer
if(scenarioStore.getAttributesSimulation().isWriteSimulationData()) {
processorManager = dataProcessingJsonManager.createProcessorManager(mainModel);
processorManager = dataProcessingJsonManager.createProcessorManager(mainModel, scenarioStore.getTopography());
processorManager.setSimulationResult(simulationResult);
}
......
......@@ -16,6 +16,7 @@ import org.vadere.simulator.projects.dataprocessing.processor.DataProcessorFacto
import org.vadere.simulator.projects.dataprocessing.store.DataProcessorStore;
import org.vadere.simulator.projects.dataprocessing.store.OutputFileStore;
import org.vadere.state.attributes.processor.AttributesProcessor;
import org.vadere.state.scenario.Topography;
import org.vadere.state.util.StateJsonConverter;
import java.io.IOException;
......@@ -281,14 +282,14 @@ public class DataProcessingJsonManager {
return main;
}
public ProcessorManager createProcessorManager(MainModel mainModel) {
public ProcessorManager createProcessorManager(MainModel mainModel, final Topography topography) {
// this function is called when the simulation starts running
for (OutputFile f : outputFiles) {
f.setWriteMetaData(isWriteMetaData()); // allow to write meta data
}
return new ProcessorManager(dataProcessors, outputFiles, mainModel);
return new ProcessorManager(dataProcessors, outputFiles, mainModel, topography);
}
......
......@@ -5,6 +5,8 @@ import org.vadere.simulator.models.MainModel;
import org.vadere.simulator.projects.SimulationResult;
import org.vadere.simulator.projects.dataprocessing.outputfile.OutputFile;
import org.vadere.simulator.projects.dataprocessing.processor.DataProcessor;
import org.vadere.state.scenario.MeasurementArea;
import org.vadere.state.scenario.Topography;
import java.io.File;
import java.nio.file.Paths;
......@@ -19,14 +21,17 @@ import java.util.Map;
public class ProcessorManager {
private MainModel mainModel;
private final Topography topography;
private Map<Integer, DataProcessor<?, ?>> processorMap;
private List<OutputFile<?>> outputFiles;
private SimulationResult simulationResult;
public ProcessorManager(List<DataProcessor<?, ?>> dataProcessors,
List<OutputFile<?>> outputFiles, MainModel mainModel) {
List<OutputFile<?>> outputFiles, MainModel mainModel,
final Topography topography) {
this.mainModel = mainModel;
this.topography = topography;
this.outputFiles = outputFiles;
......@@ -49,6 +54,10 @@ public class ProcessorManager {
return this.processorMap.getOrDefault(id, null);
}
public MeasurementArea getMeasurementArea(int measurementAreaId){
return topography.getMeasurementArea(measurementAreaId);
}
public MainModel getMainModel() {
return mainModel;
}
......
......@@ -3,6 +3,7 @@ package org.vadere.simulator.projects.dataprocessing.processor;
import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepKey;
import org.vadere.state.attributes.processor.AttributesAreaProcessor;
import org.vadere.state.scenario.MeasurementArea;
import org.vadere.util.geometry.shapes.VRectangle;
/**
......@@ -11,7 +12,7 @@ import org.vadere.util.geometry.shapes.VRectangle;
*/
public abstract class AreaDataProcessor<V> extends DataProcessor<TimestepKey, V> {
private VRectangle measurementArea;
private MeasurementArea measurementArea;
protected AreaDataProcessor(final String... headers) {
super(headers);
......@@ -21,10 +22,15 @@ public abstract class AreaDataProcessor<V> extends DataProcessor<TimestepKey, V>
public void init(final ProcessorManager manager) {
super.init(manager);
AttributesAreaProcessor att = (AttributesAreaProcessor) this.getAttributes();
this.measurementArea = att.getMeasurementArea();
this.measurementArea = manager.getMeasurementArea(att.getMeasurementAreaId());
if (measurementArea == null)
throw new RuntimeException(String.format("MeasurementArea with index %d does not exist.", att.getMeasurementAreaId()));
if (!measurementArea.isRectangular())
throw new RuntimeException("DataProcessor and IntegralVoronoiAlgorithm only supports Rectangular measurement areas.");
}
public VRectangle getMeasurementArea() {
public MeasurementArea getMeasurementArea() {
return this.measurementArea;
}
}
......@@ -3,6 +3,7 @@ package org.vadere.simulator.projects.dataprocessing.processor;
import org.jetbrains.annotations.NotNull;
import org.vadere.simulator.control.SimulationState;
import org.vadere.state.scenario.Agent;
import org.vadere.state.scenario.MeasurementArea;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VRectangle;
import org.vadere.util.voronoi.Face;
......@@ -21,11 +22,11 @@ public class AreaDensityVoronoiAlgorithm extends AreaDensityAlgorithm {
private VRectangle measurementArea;
private VRectangle voronoiArea;
public AreaDensityVoronoiAlgorithm(final VRectangle measurementArea, final VRectangle voronoiArea) {
public AreaDensityVoronoiAlgorithm(final MeasurementArea measurementArea, final MeasurementArea voronoiArea) {
super("areaVoronoi");
this.measurementArea = measurementArea;
this.voronoiArea = voronoiArea;
this.measurementArea = measurementArea.asVRectangle();
this.voronoiArea = voronoiArea.asVRectangle();
}
@Override
......
......@@ -5,6 +5,7 @@ import org.vadere.state.attributes.processor.AttributesAreaDensityVoronoiProcess
import org.vadere.state.attributes.processor.AttributesProcessor;
import org.vadere.annotation.factories.dataprocessors.DataProcessorClass;
import org.vadere.state.scenario.MeasurementArea;
/**
* @author Mario Teixeira Parente
......@@ -23,7 +24,13 @@ public class AreaDensityVoronoiProcessor extends AreaDensityProcessor {
super.init(manager);
AttributesAreaDensityVoronoiProcessor att = (AttributesAreaDensityVoronoiProcessor) this.getAttributes();
this.setAlgorithm(new AreaDensityVoronoiAlgorithm(this.getMeasurementArea(), att.getVoronoiArea()));
MeasurementArea measurementArea = manager.getMeasurementArea(att.getMeasurementAreaId());
if (measurementArea == null)
throw new RuntimeException(String.format("MeasurementArea with index %d does not exist.", att.getMeasurementAreaId()));
if (!measurementArea.isRectangular())
throw new RuntimeException("DataProcessor and IntegralVoronoiAlgorithm only supports Rectangular measurement areas.");
this.setAlgorithm(new AreaDensityVoronoiAlgorithm(this.getMeasurementArea(), measurementArea));
}
@Override
......
......@@ -43,7 +43,7 @@ public class AreaSpeedProcessor extends AreaDataProcessor<Double> {
final int pedId = entry.getKey().getPedestrianId();
final VPoint pos = entry.getValue();
if (getMeasurementArea().contains(pos)) {
if (getMeasurementArea().asVRectangle().contains(pos)) {
sumVelocities += this.pedVelProc.getValue(new TimestepPedestrianIdKey(step, pedId));
pedCount++;
}
......
......@@ -8,8 +8,10 @@ import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.simulator.projects.dataprocessing.datakey.PedestrianIdKey;
import org.vadere.state.attributes.processor.AttributesFundamentalDiagramBProcessor;
import org.vadere.state.attributes.processor.AttributesProcessor;
import org.vadere.state.scenario.MeasurementArea;
import org.vadere.state.scenario.Topography;
import org.vadere.state.simulation.VTrajectory;
import org.vadere.util.geometry.shapes.VRectangle;
import org.vadere.util.logging.Logger;
import java.util.HashMap;
import java.util.Map;
......@@ -32,7 +34,9 @@ import java.util.Map;
@DataProcessorClass()
public class FundamentalDiagramBProcessor extends DataProcessor<PedestrianIdKey, Pair<Double, Double>> {
private VRectangle measurementArea;
private static Logger logger = Logger.getLogger(Topography.class);
private MeasurementArea measurementArea;
private PedestrianTrajectoryProcessor pedestrianTrajectoryProcessor;
public FundamentalDiagramBProcessor() {
......@@ -44,7 +48,11 @@ public class FundamentalDiagramBProcessor extends DataProcessor<PedestrianIdKey,
super.init(manager);
AttributesFundamentalDiagramBProcessor att = (AttributesFundamentalDiagramBProcessor) this.getAttributes();
pedestrianTrajectoryProcessor = (PedestrianTrajectoryProcessor) manager.getProcessor(att.getPedestrianTrajectoryProcessorId());
measurementArea = att.getMeasurementArea();
measurementArea = manager.getMeasurementArea(att.getMeasurementAreaId());
if (measurementArea == null)
throw new RuntimeException(String.format("MeasurementArea with index %d does not exist.", att.getMeasurementAreaId()));
if (!measurementArea.isRectangular())
throw new RuntimeException("DataProcessor only supports Rectangular measurement areas.");
}
@Override
......@@ -78,7 +86,7 @@ public class FundamentalDiagramBProcessor extends DataProcessor<PedestrianIdKey,
for(Map.Entry<PedestrianIdKey, VTrajectory> trajectoryEntry : trajectoryMap.entrySet()) {
PedestrianIdKey key = trajectoryEntry.getKey();
VTrajectory trajectory = trajectoryEntry.getValue();
VTrajectory clone = trajectory.cut(measurementArea);
VTrajectory clone = trajectory.cut(measurementArea.asVRectangle());
cutTrajectoryMap.put(key, clone);
}
......@@ -109,7 +117,7 @@ public class FundamentalDiagramBProcessor extends DataProcessor<PedestrianIdKey,
.sum();
densityIntegral /= duration;
densityIntegral /= measurementArea.getArea();
densityIntegral /= measurementArea.asVRectangle().getArea();
return densityIntegral;
/*List<Triple<Double, Double, Integer>> integralValues = new LinkedList<>();
......
......@@ -9,6 +9,7 @@ import org.vadere.simulator.projects.dataprocessing.datakey.TimestepKey;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepPedestrianIdKey;
import org.vadere.state.attributes.processor.AttributesFundamentalDiagramCProcessor;
import org.vadere.state.attributes.processor.AttributesProcessor;
import org.vadere.state.scenario.MeasurementArea;
import org.vadere.util.geometry.shapes.VRectangle;
/**
......@@ -25,7 +26,8 @@ import org.vadere.util.geometry.shapes.VRectangle;
@DataProcessorClass()
public class FundamentalDiagramCProcessor extends AreaDataProcessor<Pair<Double, Double>> {
private VRectangle measurementArea;
private MeasurementArea measurementArea;
private APedestrianVelocityProcessor pedestrianVelocityProcessor;
public FundamentalDiagramCProcessor() {
......@@ -36,8 +38,12 @@ public class FundamentalDiagramCProcessor extends AreaDataProcessor<Pair<Double,
public void init(final ProcessorManager manager) {
super.init(manager);
AttributesFundamentalDiagramCProcessor att = (AttributesFundamentalDiagramCProcessor) this.getAttributes();
measurementArea = att.getMeasurementArea();
measurementArea = manager.getMeasurementArea(att.getMeasurementAreaId());
pedestrianVelocityProcessor = (APedestrianVelocityProcessor) manager.getProcessor(att.getPedestrianVelocityProcessorId());
if (measurementArea == null)
throw new RuntimeException(String.format("MeasurementArea with index %d does not exist.", att.getMeasurementAreaId()));
if (!measurementArea.isRectangular())
throw new RuntimeException("DataProcessor only supports Rectangular measurement areas.");
}
@Override
......@@ -58,11 +64,11 @@ public class FundamentalDiagramCProcessor extends AreaDataProcessor<Pair<Double,
pedestrianVelocityProcessor.update(state);
long N = state.getTopography().getPedestrianDynamicElements().getElements()
.stream()
.filter(pedestrian -> measurementArea.contains(pedestrian.getPosition()))
.filter(pedestrian -> measurementArea.asVRectangle().contains(pedestrian.getPosition()))
.count();
double velocity = state.getTopography().getPedestrianDynamicElements().getElements()
.stream()
.filter(pedestrian -> measurementArea.contains(pedestrian.getPosition()))
.filter(pedestrian -> measurementArea.asVRectangle().contains(pedestrian.getPosition()))
.mapToDouble(pedestrian ->
//pedestrian.getVelocity().getLength()
pedestrianVelocityProcessor.getValue(new TimestepPedestrianIdKey(state.getStep(), pedestrian.getId()))
......@@ -76,7 +82,7 @@ public class FundamentalDiagramCProcessor extends AreaDataProcessor<Pair<Double,
velocity /= N;
}
double density = N / measurementArea.getArea();
double density = N / measurementArea.asVRectangle().getArea();
putValue(new TimestepKey(state.getStep()), Pair.of(velocity, density));
}
......
......@@ -8,6 +8,7 @@ import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepKey;
import org.vadere.state.attributes.processor.AttributesFundamentalDiagramDProcessor;
import org.vadere.state.attributes.processor.AttributesProcessor;
import org.vadere.state.scenario.MeasurementArea;
import org.vadere.util.geometry.shapes.VRectangle;
/**
......@@ -38,7 +39,17 @@ public class FundamentalDiagramDProcessor extends AreaDataProcessor<Pair<Double,
super.init(manager);
AttributesFundamentalDiagramDProcessor att = (AttributesFundamentalDiagramDProcessor) this.getAttributes();
pedestrianVelocityProcessor = (APedestrianVelocityProcessor) manager.getProcessor(att.getPedestrianVelocityProcessorId());
integralVoronoiAlgorithm = new IntegralVoronoiAlgorithm(key -> pedestrianVelocityProcessor.getValue(key), att.getMeasurementArea(), att.getVoronoiArea());
MeasurementArea measurementArea = manager.getMeasurementArea(att.getMeasurementAreaId());
MeasurementArea voronoiMeasurementArea = manager.getMeasurementArea(att.getVoronoiMeasurementAreaId());
if (measurementArea == null || voronoiMeasurementArea == null)
throw new RuntimeException(String.format("MeasurementArea with index %d does not exist.", att.getMeasurementAreaId()));
if (!measurementArea.isRectangular() || !voronoiMeasurementArea.isRectangular())
throw new RuntimeException("DataProcessor and IntegralVoronoiAlgorithm only supports Rectangular measurement areas.");
integralVoronoiAlgorithm = new IntegralVoronoiAlgorithm(
key -> pedestrianVelocityProcessor.getValue(key),
measurementArea,
voronoiMeasurementArea);
}
@Override
......
......@@ -8,6 +8,7 @@ import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepKey;
import org.vadere.state.attributes.processor.AttributesFundamentalDiagramEProcessor;
import org.vadere.state.attributes.processor.AttributesProcessor;
import org.vadere.state.scenario.MeasurementArea;
/**
*
......@@ -28,7 +29,17 @@ public class FundamentalDiagramEProcessor extends AreaDataProcessor<Pair<Double,
super.init(manager);
AttributesFundamentalDiagramEProcessor att = (AttributesFundamentalDiagramEProcessor) this.getAttributes();
pedestrianVelocityProcessor = (APedestrianVelocityProcessor) manager.getProcessor(att.getPedestrianVelocityProcessorId());
sumVoronoiAlgorithm = new SumVoronoiAlgorithm(key -> pedestrianVelocityProcessor.getValue(key), att.getMeasurementArea(), att.getVoronoiArea());
MeasurementArea measurementArea = manager.getMeasurementArea(att.getMeasurementAreaId());
MeasurementArea voronoiMeasurementArea = manager.getMeasurementArea(att.getVoronoiMeasurementAreaId());
if (measurementArea == null || voronoiMeasurementArea == null)
throw new RuntimeException(String.format("MeasurementArea with index %d does not exist.", att.getMeasurementAreaId()));
if (!measurementArea.isRectangular() || !voronoiMeasurementArea.isRectangular())
throw new RuntimeException("DataProcessor and IntegralVoronoiAlgorithm only supports Rectangular measurement areas.");
sumVoronoiAlgorithm = new SumVoronoiAlgorithm(
key -> pedestrianVelocityProcessor.getValue(key),
measurementArea,
voronoiMeasurementArea);
}
@Override
......
......@@ -5,6 +5,7 @@ import org.vadere.meshing.WeilerAtherton;
import org.vadere.simulator.control.SimulationState;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepPedestrianIdKey;
import org.vadere.state.scenario.Agent;
import org.vadere.state.scenario.MeasurementArea;
import org.vadere.util.geometry.GeometryUtils;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VPolygon;
......@@ -32,12 +33,12 @@ public class IntegralVoronoiAlgorithm extends AreaDensityAlgorithm implements IA
private VRectangle voronoiArea;
private final Function<TimestepPedestrianIdKey, Double> agentVelocityFunc;
public IntegralVoronoiAlgorithm(@NotNull final Function<TimestepPedestrianIdKey, Double> agentVelocityFunc, @NotNull final VRectangle measurementArea, @NotNull final VRectangle voronoiArea) {
public IntegralVoronoiAlgorithm(@NotNull final Function<TimestepPedestrianIdKey, Double> agentVelocityFunc, @NotNull final MeasurementArea measurementArea, @NotNull final MeasurementArea voronoiMeasurementArea) {
super("areaVoronoi");
this.measurementArea = measurementArea;
this.measurementAreaPolygon = new VPolygon(measurementArea);
this.voronoiArea = voronoiArea;
this.measurementArea = measurementArea.asVRectangle();
this.measurementAreaPolygon = new VPolygon(measurementArea.getShape());
this.voronoiArea = voronoiMeasurementArea.asVRectangle();
this.agentVelocityFunc = agentVelocityFunc;
}
......
......@@ -8,9 +8,11 @@ import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.simulator.projects.dataprocessing.datakey.PedestrianIdKey;
import org.vadere.state.attributes.processor.AttributesCrossingTimeProcessor;
import org.vadere.state.attributes.processor.AttributesProcessor;
import org.vadere.state.scenario.MeasurementArea;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.simulation.FootStep;
import org.vadere.util.geometry.shapes.VRectangle;
import org.vadere.util.geometry.shapes.VShape;
import org.vadere.util.logging.Logger;
import java.util.Collection;
......@@ -19,7 +21,7 @@ import java.util.Collection;
@DataProcessorClass()
public class PedestrianCrossingTimeProcessor extends DataProcessor<PedestrianIdKey, Pair<Double, Double>>{
private VRectangle measurementArea;
private MeasurementArea measurementArea;
private static Logger logger = Logger.getLogger(PedestrianCrossingTimeProcessor.class);
public PedestrianCrossingTimeProcessor() {
......@@ -35,9 +37,9 @@ public class PedestrianCrossingTimeProcessor extends DataProcessor<PedestrianIdK
PedestrianIdKey key = new PedestrianIdKey(ped.getId());
for(FootStep footStep : ped.getFootSteps()) {
if(footStep.intersects(measurementArea)) {
if(footStep.intersects(measurementArea.asVRectangle())) {
double intersectionTime = footStep.computeIntersectionTime(measurementArea);
double intersectionTime = footStep.computeIntersectionTime(measurementArea.asVRectangle());
if(!hasCrossStartTime(key)) {
setStartTime(key, intersectionTime);
}
......@@ -75,7 +77,13 @@ public class PedestrianCrossingTimeProcessor extends DataProcessor<PedestrianIdK
public void init(final ProcessorManager manager) {
super.init(manager);
AttributesCrossingTimeProcessor att = (AttributesCrossingTimeProcessor) this.getAttributes();
this.measurementArea = att.getMeasurementArea();
this.measurementArea = manager.getMeasurementArea(att.getMeasurementAreaId());
if (measurementArea == null)
throw new RuntimeException(String.format("MeasurementArea with index %d does not exist.", att.getMeasurementAreaId()));
if (!measurementArea.isRectangular())
throw new RuntimeException("DataProcessor and IntegralVoronoiAlgorithm only supports Rectangular measurement areas.");
}
@Override
......
......@@ -6,6 +6,7 @@ import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.simulator.projects.dataprocessing.datakey.PedestrianIdKey;
import org.vadere.state.attributes.processor.AttributesPedestrianWaitingEndTimeProcessor;
import org.vadere.state.attributes.processor.AttributesProcessor;
import org.vadere.state.scenario.MeasurementArea;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VRectangle;
......@@ -17,7 +18,7 @@ import java.util.Collection;
*/
@DataProcessorClass()
public class PedestrianWaitingEndTimeProcessor extends DataProcessor<PedestrianIdKey, Double> {
private VRectangle waitingArea;
private MeasurementArea waitingArea;
public PedestrianWaitingEndTimeProcessor() {
super("waitingEndTime");
......@@ -31,7 +32,7 @@ public class PedestrianWaitingEndTimeProcessor extends DataProcessor<PedestrianI
int pedId = p.getId();
VPoint pos = p.getPosition();
if (this.waitingArea.contains(pos)) {
if (this.waitingArea.asVRectangle().contains(pos)) {
PedestrianIdKey key = new PedestrianIdKey(pedId);
this.putValue(key, state.getSimTimeInSec());
}
......@@ -42,7 +43,12 @@ public class PedestrianWaitingEndTimeProcessor extends DataProcessor<PedestrianI
public void init(final ProcessorManager manager) {
super.init(manager);
AttributesPedestrianWaitingEndTimeProcessor att = (AttributesPedestrianWaitingEndTimeProcessor) this.getAttributes();
this.waitingArea = att.getWaitingArea();
this.waitingArea = manager.getMeasurementArea(att.getWaitingAreaId());
if (waitingArea == null )
throw new RuntimeException(String.format("MeasurementArea with index %d does not exist.", att.getWaitingAreaId()));
if (!waitingArea.isRectangular())
throw new RuntimeException("DataProcessor and IntegralVoronoiAlgorithm only supports Rectangular measurement areas.");
}
@Override
......
......@@ -6,6 +6,7 @@ import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.simulator.projects.dataprocessing.datakey.PedestrianIdKey;
import org.vadere.state.attributes.processor.AttributesPedestrianWaitingTimeProcessor;
import org.vadere.state.attributes.processor.AttributesProcessor;
import org.vadere.state.scenario.MeasurementArea;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VRectangle;
......@@ -18,7 +19,7 @@ import java.util.Collection;
@DataProcessorClass()
public class PedestrianWaitingTimeProcessor extends DataProcessor<PedestrianIdKey, Double> {
private double lastSimTime;
private VRectangle waitingArea;
private MeasurementArea waitingArea;
public PedestrianWaitingTimeProcessor() {
super("waitingTimeStart");
......@@ -36,7 +37,7 @@ public class PedestrianWaitingTimeProcessor extends DataProcessor<PedestrianIdKe
int pedId = p.getId();
VPoint pos = p.getPosition();
if (this.waitingArea.contains(pos)) {
if (this.waitingArea.asVRectangle().contains(pos)) {
PedestrianIdKey key = new PedestrianIdKey(pedId);
this.putValue(key, (this.hasValue(key) ? this.getValue(key) : 0.0) + dt);
}
......@@ -49,7 +50,12 @@ public class PedestrianWaitingTimeProcessor extends DataProcessor<PedestrianIdKe
public void init(final ProcessorManager manager) {
super.init(manager);
AttributesPedestrianWaitingTimeProcessor att = (AttributesPedestrianWaitingTimeProcessor) this.getAttributes();
this.waitingArea = att.getWaitingArea();
this.waitingArea = manager.getMeasurementArea(att.getWaitingAreaId());
if (waitingArea == null)
throw new RuntimeException(String.format("MeasurementArea with index %d does not exist.", att.getWaitingAreaId()));
if (!waitingArea.isRectangular())
throw new RuntimeException("DataProcessor and IntegralVoronoiAlgorithm only supports Rectangular measurement areas.");
this.lastSimTime = 0.0;
}
......
......@@ -4,6 +4,7 @@ import org.jetbrains.annotations.NotNull;
import org.vadere.simulator.control.SimulationState;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepPedestrianIdKey;
import org.vadere.state.scenario.Agent;
import org.vadere.state.scenario.MeasurementArea;
import org.vadere.util.geometry.GeometryUtils;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VPolygon;
......@@ -25,12 +26,12 @@ public class SumVoronoiAlgorithm extends AreaDensityAlgorithm implements IAreaVe
private VRectangle voronoiArea;
private final Function<TimestepPedestrianIdKey, Double> agentVelocityFunc;
public SumVoronoiAlgorithm(@NotNull final Function<TimestepPedestrianIdKey, Double> agentVelocityFunc, @NotNull final VRectangle measurementArea, @NotNull final VRectangle voronoiArea) {
public SumVoronoiAlgorithm(@NotNull final Function<TimestepPedestrianIdKey, Double> agentVelocityFunc, @NotNull final MeasurementArea measurementArea, @NotNull final MeasurementArea voronoiArea) {
super("areaVoronoi");
this.measurementArea = measurementArea;
this.measurementAreaPolygon = new VPolygon(measurementArea);
this.voronoiArea = voronoiArea;
this.measurementArea = measurementArea.asVRectangle();
this.measurementAreaPolygon = new VPolygon(measurementArea.getShape());
this.voronoiArea = voronoiArea.asVRectangle();
this.agentVelocityFunc = agentVelocityFunc;
}
......
package org.vadere.simulator.projects.migration;
import org.vadere.simulator.entrypoints.Version;
import org.vadere.simulator.projects.migration.incident.IncidentMigrationAssistant;
import org.vadere.simulator.projects.migration.jsontranformation.JsonMigrationAssistant;
import org.vadere.util.io.IOUtils;
import java.io.IOException;
......@@ -8,9 +10,6 @@ import java.nio.file.Path;
import java.text.SimpleDateFormat;
public abstract class MigrationAssistant {
public static final String INCIDENT_ORDER_ERROR = "An incident that was found applicable couldn't be resolved. " +
"That means, that a previously resolved incident rendered this one no longer applicable. " +
"Check the order of the incidents in the IncidentDatabase for logical flaws.";
protected final MigrationOptions migrationOptions;
public MigrationAssistant(MigrationOptions migrationOptions) {
......@@ -21,7 +20,7 @@ public abstract class MigrationAssistant {
if (options.isUseDeprecatedAssistant()) {
return new IncidentMigrationAssistant(options);
} else {
return new JoltMigrationAssistant(options);
return new JsonMigrationAssistant(options);
}
}
......@@ -34,15 +33,37 @@ public abstract class MigrationAssistant {
public abstract void restLog();
public abstract MigrationResult analyzeProject(String projectFolderPath) throws IOException;
protected String getTimestamp() {
return new SimpleDateFormat("yyyyMMddHHmmss").format(new java.util.Date());
}
public abstract String convertFile(Path scenarioFilePath, Version targetVersion) throws MigrationException;
public abstract MigrationResult analyzeProject(String projectFolderPath) throws IOException;
/**
* Migrate a given serialized scenario file to the target version.
* @param scenarioFilePath Path to scenario file
* @param targetVersion Version number to which it should be upgraded.