Commit 6c627813 authored by Stefan Schuhbaeck's avatar Stefan Schuhbaeck
Browse files

Merge branch 'measurementAreaRefactorProcessors_rebased' into 'master'

Measurement area refactor processors rebased

See merge request !55
parents dcffc7d3 83cb5e48
Pipeline #103785 passed with stages
in 137 minutes and 9 seconds
......@@ -6,20 +6,26 @@ import org.vadere.annotation.factories.dataprocessors.DataProcessorClass;
import org.vadere.simulator.control.SimulationState;
import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.simulator.projects.dataprocessing.datakey.PedestrianIdKey;
import org.vadere.simulator.projects.dataprocessing.flags.UsesMeasurementArea;
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.factory.processors.Flag;
import org.vadere.util.geometry.shapes.VRectangle;
import org.vadere.util.logging.Logger;
import java.util.Collection;
import java.util.List;
//TODO
@DataProcessorClass()
public class PedestrianCrossingTimeProcessor extends DataProcessor<PedestrianIdKey, Pair<Double, Double>>{
public class PedestrianCrossingTimeProcessor extends DataProcessor<PedestrianIdKey, Pair<Double, Double>> implements UsesMeasurementArea {
private MeasurementArea measurementArea;
private VRectangle measurementAreaVRec;
private VRectangle measurementArea;
private static Logger logger = Logger.getLogger(PedestrianCrossingTimeProcessor.class);
public PedestrianCrossingTimeProcessor() {
......@@ -35,9 +41,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(measurementAreaVRec)) {
double intersectionTime = footStep.computeIntersectionTime(measurementArea);
double intersectionTime = footStep.computeIntersectionTime(measurementAreaVRec);
if(!hasCrossStartTime(key)) {
setStartTime(key, intersectionTime);
}
......@@ -75,7 +81,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.");
measurementAreaVRec = measurementArea.asVRectangle();
}
@Override
......@@ -91,4 +103,11 @@ public class PedestrianCrossingTimeProcessor extends DataProcessor<PedestrianIdK
Pair<Double, Double> times = getValue(key);
return new String[]{Double.toString(times.getLeft()), Double.toString(times.getRight())};
}
@Override
public int[] getReferencedMeasurementAreaId() {
AttributesCrossingTimeProcessor att = (AttributesCrossingTimeProcessor) this.getAttributes();
return new int[]{att.getWaitingAreaId(), att.getMeasurementAreaId()};
}
}
......@@ -4,20 +4,25 @@ import org.vadere.annotation.factories.dataprocessors.DataProcessorClass;
import org.vadere.simulator.control.SimulationState;
import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.simulator.projects.dataprocessing.datakey.PedestrianIdKey;
import org.vadere.simulator.projects.dataprocessing.flags.UsesMeasurementArea;
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.factory.processors.Flag;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VRectangle;
import java.util.Collection;
import java.util.List;
/**
* @author Mario Teixeira Parente
*/
@DataProcessorClass()
public class PedestrianWaitingEndTimeProcessor extends DataProcessor<PedestrianIdKey, Double> {
private VRectangle waitingArea;
public class PedestrianWaitingEndTimeProcessor extends DataProcessor<PedestrianIdKey, Double> implements UsesMeasurementArea {
private MeasurementArea waitingArea;
private VRectangle waitingAreaVRec;
public PedestrianWaitingEndTimeProcessor() {
super("waitingEndTime");
......@@ -31,7 +36,7 @@ public class PedestrianWaitingEndTimeProcessor extends DataProcessor<PedestrianI
int pedId = p.getId();
VPoint pos = p.getPosition();
if (this.waitingArea.contains(pos)) {
if (this.waitingAreaVRec.contains(pos)) {
PedestrianIdKey key = new PedestrianIdKey(pedId);
this.putValue(key, state.getSimTimeInSec());
}
......@@ -42,7 +47,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.");
waitingAreaVRec = waitingArea.asVRectangle();
}
@Override
......@@ -53,4 +63,11 @@ public class PedestrianWaitingEndTimeProcessor extends DataProcessor<PedestrianI
return super.getAttributes();
}
@Override
public int[] getReferencedMeasurementAreaId() {
AttributesPedestrianWaitingEndTimeProcessor att = (AttributesPedestrianWaitingEndTimeProcessor) this.getAttributes();
return new int[]{att.getWaitingAreaId()};
}
}
......@@ -4,21 +4,26 @@ import org.vadere.annotation.factories.dataprocessors.DataProcessorClass;
import org.vadere.simulator.control.SimulationState;
import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.simulator.projects.dataprocessing.datakey.PedestrianIdKey;
import org.vadere.simulator.projects.dataprocessing.flags.UsesMeasurementArea;
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.factory.processors.Flag;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VRectangle;
import java.util.Collection;
import java.util.List;
/**
* @author Mario Teixeira Parente
*/
@DataProcessorClass()
public class PedestrianWaitingTimeProcessor extends DataProcessor<PedestrianIdKey, Double> {
public class PedestrianWaitingTimeProcessor extends DataProcessor<PedestrianIdKey, Double> implements UsesMeasurementArea {
private double lastSimTime;
private VRectangle waitingArea;
private MeasurementArea waitingArea;
private VRectangle waitingAreaRec;
public PedestrianWaitingTimeProcessor() {
super("waitingTimeStart");
......@@ -36,7 +41,7 @@ public class PedestrianWaitingTimeProcessor extends DataProcessor<PedestrianIdKe
int pedId = p.getId();
VPoint pos = p.getPosition();
if (this.waitingArea.contains(pos)) {
if (this.waitingAreaRec.contains(pos)) {
PedestrianIdKey key = new PedestrianIdKey(pedId);
this.putValue(key, (this.hasValue(key) ? this.getValue(key) : 0.0) + dt);
}
......@@ -49,7 +54,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.");
waitingAreaRec = waitingArea.asVRectangle();
this.lastSimTime = 0.0;
}
......@@ -61,4 +71,10 @@ public class PedestrianWaitingTimeProcessor extends DataProcessor<PedestrianIdKe
return super.getAttributes();
}
@Override
public int[] getReferencedMeasurementAreaId() {
AttributesPedestrianWaitingTimeProcessor att = (AttributesPedestrianWaitingTimeProcessor) this.getAttributes();
return new int[]{att.getWaitingAreaId()};
}
}
......@@ -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.
* @return String representation (JSON) of the serialized scenario
* @throws MigrationException
*/
public abstract String migrateScenarioFile(Path scenarioFilePath, Version targetVersion) throws MigrationException;
/**
* Migrate a given serialized scenario file to the target version and save the result to a file.
* @param scenarioFilePath Path to scenario file
* @param targetVersion Version number to which it should be upgraded.
* @param outputFile If Null overwrite existing file. Backup as {filename}.legacy
* @throws MigrationException
*/
public abstract void migrateScenarioFile(Path scenarioFilePath, Version targetVersion, Path outputFile) throws MigrationException;
public abstract void migrateFile(Path scenarioFilePath, Version targetVersion, Path outputFile) throws MigrationException;
/**
* Search for existing backup files at default location.
* @param scenarioFile Path to scenario file
* @throws MigrationException
*/
public abstract void revertFile(Path scenarioFile) throws MigrationException;
}
package org.vadere.simulator.projects.migration;
import org.vadere.simulator.projects.migration.incidents.Incident;
import org.vadere.simulator.projects.migration.incident.incidents.Incident;
public class MigrationException extends Exception {
......@@ -13,6 +13,10 @@ public class MigrationException extends Exception {
super(message);
}
public MigrationException(Throwable throwable) {
super(throwable);
}
public MigrationException(String message, Throwable cause) {
super(message, cause);
}
......
package org.vadere.simulator.projects.migration;
package org.vadere.simulator.projects.migration.incident;
import java.util.ArrayList;
import java.util.Arrays;
......@@ -8,15 +8,15 @@ import java.util.List;
import java.util.Map;
import org.vadere.simulator.entrypoints.Version;
import org.vadere.simulator.projects.migration.incidents.AddTextNodeIncident;
import org.vadere.simulator.projects.migration.incidents.DeletionIncident;
import org.vadere.simulator.projects.migration.incidents.Incident;
import org.vadere.simulator.projects.migration.incidents.MissingMainModelIncident;
import org.vadere.simulator.projects.migration.incidents.RelocationIncident;
import org.vadere.simulator.projects.migration.incidents.RenameInArrayIncident;
import org.vadere.simulator.projects.migration.incidents.RenameIncident;
import org.vadere.simulator.projects.migration.incidents.specialized.AttributesPotentialCompactVSosmIncident;
import org.vadere.simulator.projects.migration.incidents.specialized.MoveSpawnDelayIntoDistributionParametersIncident;
import org.vadere.simulator.projects.migration.incident.incidents.AddTextNodeIncident;
import org.vadere.simulator.projects.migration.incident.incidents.DeletionIncident;
import org.vadere.simulator.projects.migration.incident.incidents.Incident;
import org.vadere.simulator.projects.migration.incident.incidents.MissingMainModelIncident;
import org.vadere.simulator.projects.migration.incident.incidents.RelocationIncident;
import org.vadere.simulator.projects.migration.incident.incidents.RenameInArrayIncident;
import org.vadere.simulator.projects.migration.incident.incidents.RenameIncident;
import org.vadere.simulator.projects.migration.incident.incidents.specialized.AttributesPotentialCompactVSosmIncident;
import org.vadere.simulator.projects.migration.incident.incidents.specialized.MoveSpawnDelayIntoDistributionParametersIncident;
import org.vadere.state.util.StateJsonConverter;
import static org.vadere.simulator.entrypoints.Version.*;
......
package org.vadere.simulator.projects.migration;
package org.vadere.simulator.projects.migration.incident;
import com.fasterxml.jackson.databind.JsonNode;
import org.vadere.simulator.entrypoints.Version;
import org.vadere.simulator.projects.migration.incidents.ExceptionIncident;
import org.vadere.simulator.projects.migration.incidents.Incident;
import org.vadere.simulator.projects.migration.incidents.VersionBumpIncident;
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.MigrationResult;
import org.vadere.simulator.projects.migration.incident.incidents.ExceptionIncident;
import org.vadere.simulator.projects.migration.incident.incidents.Incident;
import org.vadere.simulator.projects.migration.incident.incidents.VersionBumpIncident;
import org.vadere.state.util.StateJsonConverter;
import org.vadere.util.io.IOUtils;
import org.vadere.util.logging.Logger;
......@@ -70,12 +74,12 @@ public class IncidentMigrationAssistant extends MigrationAssistant {
}
@Override
public String convertFile(Path scenarioFilePath, Version targetVersion) {
public String migrateScenarioFile(Path scenarioFilePath, Version targetVersion) {
throw new RuntimeException("Not Implemented");
}
@Override
public void migrateFile(Path scenarioFilePath, Version targetVersion, Path outputFile) {
public void migrateScenarioFile(Path scenarioFilePath, Version targetVersion, Path outputFile) {
throw new RuntimeException("Not Implemented");
}
......
package org.vadere.simulator.projects.migration;
package org.vadere.simulator.projects.migration.incident;
import java.util.HashMap;
import java.util.Map;
......
package org.vadere.simulator.projects.migration;
package org.vadere.simulator.projects.migration.incident;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
......@@ -7,7 +7,8 @@ import java.util.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.vadere.simulator.projects.migration.incidents.Incident;
import org.vadere.simulator.projects.migration.MigrationException;
import org.vadere.simulator.projects.migration.incident.incidents.Incident;
/**
* A Tree that represents the json-tree. Note that JsonArrays are always leafs! Therefore it is
......
package org.vadere.simulator.projects.migration.helper;
package org.vadere.simulator.projects.migration.incident.helper;
import com.fasterxml.jackson.databind.JsonNode;
......
package org.vadere.simulator.projects.migration.helper;
package org.vadere.simulator.projects.migration.incident.helper;
import java.nio.file.Path;
......
package org.vadere.simulator.projects.migration.helper;
package org.vadere.simulator.projects.migration.incident.helper;
import org.vadere.simulator.entrypoints.Version;
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.jolttranformation.JoltTransformation;
import org.vadere.simulator.projects.migration.jsontranformation.JoltTransformation;
import org.vadere.util.io.IOUtils;
import org.vadere.util.logging.Logger;
......@@ -104,7 +104,7 @@ public class MigrationUtil {
MigrationAssistant ms = MigrationAssistant.getNewInstance(MigrationOptions.defaultOptions());
try {
logger.info("migrate: " + path.toString());
ms.migrateFile(path, Version.latest(), null);
ms.migrateScenarioFile(path, Version.latest(), null);
return true;
} catch (MigrationException e) {
logger.error("Error in MigrationUtil stop: " + e.getMessage());
......
package org.vadere.simulator.projects.migration.incidents;
package org.vadere.simulator.projects.migration.incident.incidents;
import org.vadere.simulator.projects.migration.Tree;
import org.vadere.simulator.projects.migration.incident.Tree;
import org.vadere.simulator.projects.migration.MigrationException;
import java.util.ArrayList;
......
package org.vadere.simulator.projects.migration.incidents;
package org.vadere.simulator.projects.migration.incident.incidents;
import org.jetbrains.annotations.NotNull;
import org.vadere.simulator.projects.migration.MigrationException;
import org.vadere.simulator.projects.migration.Tree;
import org.vadere.simulator.projects.migration.incident.Tree;
import java.util.List;
......
package org.vadere.simulator.projects.migration.incidents;
package org.vadere.simulator.projects.migration.incident.incidents;
import java.util.List;
import org.vadere.simulator.projects.migration.Tree;
import org.vadere.simulator.projects.migration.incident.Tree;
import org.vadere.simulator.projects.migration.MigrationException;
public class DeletionIncident extends Incident {
......
package org.vadere.simulator.projects.migration.incidents;
package org.vadere.simulator.projects.migration.incident.incidents;
import java.io.IOException;
import org.apache.commons.lang3.tuple.Pair;
import org.vadere.simulator.projects.io.JsonConverter;
import org.vadere.simulator.projects.migration.Tree;
import org.vadere.simulator.projects.migration.incident.Tree;
import org.vadere.simulator.projects.migration.MigrationException;
import com.fasterxml.jackson.databind.JsonNode;
......
package org.vadere.simulator.projects.migration.incidents;
package org.vadere.simulator.projects.migration.incident.incidents;
import java.util.List;
import java.util.stream.Collectors;
import org.vadere.simulator.projects.migration.Tree;
import org.vadere.simulator.projects.migration.incident.Tree;
import org.vadere.simulator.projects.migration.MigrationAssistant;
import org.vadere.simulator.projects.migration.MigrationException;
public abstract class Incident {
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.";
public abstract boolean applies(Tree graph);
public abstract void resolve(Tree graph, StringBuilder log) throws MigrationException;
protected void stillApplies(Tree graph) throws MigrationException {
if (!applies(graph))
throw new MigrationException(this, MigrationAssistant.INCIDENT_ORDER_ERROR);
throw new MigrationException(this, INCIDENT_ORDER_ERROR);
}
protected List<String> clone(List<String> list) {
......
package org.vadere.simulator.projects.migration.incidents;
package org.vadere.simulator.projects.migration.incident.incidents;
import java.util.List;
import org.vadere.simulator.projects.migration.Tree;
import org.vadere.simulator.projects.migration.LookupTables;
import org.vadere.simulator.projects.migration.incident.Tree;
import org.vadere.simulator.projects.migration.incident.LookupTables;
import org.vadere.simulator.projects.migration.MigrationException;
public class MissingMainModelIncident extends Incident {
......
package org.vadere.simulator.projects.migration.incidents;
package org.vadere.simulator.projects.migration.incident.incidents;
import java.util.List;
import org.vadere.simulator.projects.migration.Tree;
import org.vadere.simulator.projects.migration.incident.Tree;
import org.vadere.simulator.projects.migration.MigrationException;
public class RelocationIncident extends Incident {
......
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