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
package org.vadere.simulator.projects.migration.jolttranformation;
package org.vadere.simulator.projects.migration.jsontranformation.jolt;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
......@@ -6,12 +6,13 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
import org.vadere.annotation.factories.migrationassistant.MigrationTransformation;
import org.vadere.simulator.entrypoints.Version;
import org.vadere.simulator.projects.migration.MigrationException;
import org.vadere.simulator.projects.migration.jsontranformation.JoltTransformation;
import org.vadere.state.attributes.models.AttributesOSM;
import java.util.ArrayList;
@MigrationTransformation(targetVersionLabel = "0.7")
public class JoltTransformV6toV7 extends JoltTransformation{
public class JoltTransformV6toV7 extends JoltTransformation {
public JoltTransformV6toV7() {
......@@ -19,10 +20,10 @@ public class JoltTransformV6toV7 extends JoltTransformation{
}
@Override
protected void initPostHooks() {
postTransformHooks.add(this::setDefaultValues);
postTransformHooks.add(this::renameProcessorAttribute);
postTransformHooks.add(JoltTransformV1toV2::sort); // <-- allways last to ensure json order
protected void initDefaultHooks() {
addPostHookLast(this::setDefaultValues);
addPostHookLast(this::renameProcessorAttribute);
addPostHookLast(this::sort);
}
// postHookStep
......@@ -54,4 +55,5 @@ public class JoltTransformV6toV7 extends JoltTransformation{
return scenarioFile;
}
}
package org.vadere.simulator.projects.migration.jsontranformation.json;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.vadere.annotation.factories.migrationassistant.MigrationTransformation;
import org.vadere.simulator.entrypoints.Version;
import org.vadere.simulator.projects.migration.MigrationException;
import org.vadere.simulator.projects.migration.jsontranformation.SimpleJsonTransformation;
import org.vadere.state.util.StateJsonConverter;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.stream.Collectors;
@MigrationTransformation(targetVersionLabel = "0.8")
public class JsonTransformV7ToV8 extends SimpleJsonTransformation {
ObjectMapper mapper;
public JsonTransformV7ToV8() {
super(Version.V0_8);
this.mapper = StateJsonConverter.getMapper();
}
@Override
protected void initDefaultHooks() {
addPostHookLast(this::applyMeasurementAreaType1);
addPostHookLast(this::applyMeasurementAreaType2);
addPostHookLast(this::applyMeasurementAreaType4);
addPostHookLast(this::applyMeasurementAreaType5);
addPostHookLast(this::addCommitHashWarningIfMissing);
addPostHookLast(this::sort);
}
@Override
public JsonNode applyTransformation(JsonNode node) throws MigrationException {
return super.applyTransformation(node);
}
private void migrate_measurementArea(JsonNode scenarioFile, JsonNode p) throws MigrationException {
JsonNode attr = pathMustExist(p, "attributes");
// find old field name
JsonNode measurementArea = path(attr, "measurementArea");
if (!measurementArea.isMissingNode()){
// search existing or create new MeasurementArea and link processor to id.
int measurementAreaId = transformShapeToMeasurementArea(scenarioFile, measurementArea, mapper);
remove(attr, "measurementArea");
addIntegerField(attr, "measurementAreaId", measurementAreaId);
}
}
private void migrate_voronoiArea(JsonNode scenarioFile, JsonNode p) throws MigrationException{
JsonNode attr = pathMustExist(p, "attributes");
JsonNode measurementArea = path(attr, "voronoiArea");
if (!measurementArea.isMissingNode()){
// search existing or create new MeasurementArea and link processor to id.
int measurementAreaId = transformShapeToMeasurementArea(scenarioFile, measurementArea, mapper);
remove(attr, "voronoiArea");
addIntegerField(attr, "voronoiMeasurementAreaId", measurementAreaId);
}
}
private void migrate_waitingArea(JsonNode scenarioFile, JsonNode p) throws MigrationException{
JsonNode attr = pathMustExist(p, "attributes");
JsonNode measurementArea = path(attr, "waitingArea");
if (!measurementArea.isMissingNode()){
// search existing or create new MeasurementArea and link processor to id.
int measurementAreaId = transformShapeToMeasurementArea(scenarioFile, measurementArea, mapper);
remove(attr, "waitingArea");
addIntegerField(attr, "waitingAreaId", measurementAreaId);
}
}
public JsonNode applyMeasurementAreaType1(JsonNode scenarioFile) throws MigrationException{
String[] processorTypes = {
"org.vadere.simulator.projects.dataprocessing.processor.FundamentalDiagramBProcessor", // type 1 (measurementArea -> measurementAreaId)
"org.vadere.simulator.projects.dataprocessing.processor.FundamentalDiagramCProcessor", // type 1 (measurementArea -> measurementAreaId)
};
for (String type : processorTypes) {
ArrayList<JsonNode> processor =
getProcessorsByType(scenarioFile, type);
for (JsonNode p : processor) {
//
migrate_measurementArea(scenarioFile, p);
//
}
}
return scenarioFile;
}
public JsonNode applyMeasurementAreaType2(JsonNode scenarioFile) throws MigrationException{
String[] processorTypes = {
"org.vadere.simulator.projects.dataprocessing.processor.FundamentalDiagramDProcessor", // type 2 (measurementArea -> measurementAreaId, voronoiArea -> voronoiMeasurementAreaId)
"org.vadere.simulator.projects.dataprocessing.processor.FundamentalDiagramEProcessor", // type 2 (measurementArea -> measurementAreaId, voronoiArea -> voronoiMeasurementAreaId)
"org.vadere.simulator.projects.dataprocessing.processor.AreaDensityVoronoiProcessor", // type 2 (voronoiArea -> voronoiMeasurementAreaId)
};
for (String type : processorTypes) {
ArrayList<JsonNode> processor =
getProcessorsByType(scenarioFile, type);
for (JsonNode p : processor) {
//
migrate_measurementArea(scenarioFile, p);
//
migrate_voronoiArea(scenarioFile, p);
//
}
}
return scenarioFile;
}
public JsonNode applyMeasurementAreaType4(JsonNode scenarioFile) throws MigrationException{
String[] processorTypes = {
"org.vadere.simulator.projects.dataprocessing.processor.PedestrianWaitingEndTimeProcessor", // type 3 (waitingArea -> waitingAreaId)
"org.vadere.simulator.projects.dataprocessing.processor.PedestrianWaitingTimeProcessor" // type 3 (waitingArea -> waitingAreaId)
};
for (String type : processorTypes) {
ArrayList<JsonNode> processor =
getProcessorsByType(scenarioFile, type);
for (JsonNode p : processor) {
//
migrate_waitingArea(scenarioFile, p);
//
}
}
return scenarioFile;
}
public JsonNode applyMeasurementAreaType5(JsonNode scenarioFile) throws MigrationException{
String[] processorTypes = {
"org.vadere.simulator.projects.dataprocessing.processor.PedestrianCrossingTimeProcessor", // type 3 (waitingArea -> waitingAreaId, measurementArea -> measurementAreaId)
};
for (String type : processorTypes) {
ArrayList<JsonNode> processor =
getProcessorsByType(scenarioFile, type);
for (JsonNode p : processor) {
//
migrate_waitingArea(scenarioFile, p);
//
migrate_measurementArea(scenarioFile, p);
}
}
return scenarioFile;
}
private JsonNode removeShapeFromDataProcessors(JsonNode scenarioFile) throws MigrationException {
return scenarioFile;
}
public static void main(String[] arg) throws Exception {
BufferedReader r = new BufferedReader(
new FileReader("/home/lphex/hm.d/vadere/VadereModelTests/TestOSM/scenarios/rimea_04_flow_osm1_125_h.scenario"));
String jsonStr = r.lines().collect(Collectors.joining("\n"));
ObjectMapper mapper = StateJsonConverter.getMapper();
JsonNode jsonNode = StateJsonConverter.deserializeToNode(jsonStr);
JsonTransformV7ToV8 transformation = new JsonTransformV7ToV8();
JsonNode newScenario = transformation.applyAll(jsonNode);
System.out.print(StateJsonConverter.getPrettyWriter().writeValueAsString(newScenario));
}
}
......@@ -3,6 +3,7 @@ package org.vadere.simulator.utils.scenariochecker;
import org.jetbrains.annotations.NotNull;
import org.vadere.simulator.projects.Scenario;
import org.vadere.simulator.utils.scenariochecker.checks.ScenarioCheckerTest;
import org.vadere.simulator.utils.scenariochecker.checks.dataProcessors.DataProcessorsLinkedToMeasurementArea;
import org.vadere.simulator.utils.scenariochecker.checks.simulation.SimulationTimeStepLengthCheck;
import org.vadere.simulator.utils.scenariochecker.checks.topography.PedestrianSpeedSetupCheck;
import org.vadere.simulator.utils.scenariochecker.checks.topography.SourceMinRadiusCheck;
......@@ -67,6 +68,7 @@ public class ScenarioChecker {
ret.addAll(checkSourceSpawnSetting());
ret.addAll(checkMinSourceRadius());
ret.addAll(runCheck(new TopographyOffsetCheck()));
ret.addAll(runCheck(new DataProcessorsLinkedToMeasurementArea()));
return ret;
}
......
......@@ -40,7 +40,9 @@ public enum ScenarioCheckerReason {
PEDESTRIAN_SPEED_NEGATIVE("ScenarioChecker.pedestrian.speedIsNegative"),
// Simulation attribute reasons
SIM_TIME_STEP_WRONG("ScenarioChecker.simAttr.simTimeStepWrong");
SIM_TIME_STEP_WRONG("ScenarioChecker.simAttr.simTimeStepWrong"),
PROCESSOR_MEASUREMENT_AREA("ScenarioChecker.processor.measuremetarea.doesNotExist");
private String msgId;
......
package org.vadere.simulator.utils.scenariochecker.checks.dataProcessors;
import org.vadere.simulator.projects.Scenario;
import org.vadere.simulator.projects.dataprocessing.flags.UsesMeasurementArea;
import org.vadere.simulator.projects.dataprocessing.processor.DataProcessor;
import org.vadere.simulator.projects.dataprocessing.processor.DataProcessorFactory;
import org.vadere.simulator.utils.scenariochecker.ScenarioCheckerMessage;
import org.vadere.simulator.utils.scenariochecker.ScenarioCheckerReason;
import org.vadere.simulator.utils.scenariochecker.checks.AbstractScenarioCheck;
import org.vadere.state.scenario.MeasurementArea;
import org.vadere.util.factory.processors.Flag;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.PriorityQueue;
import java.util.stream.Collectors;
public class DataProcessorsLinkedToMeasurementArea extends AbstractScenarioCheck {
@Override
public PriorityQueue<ScenarioCheckerMessage> runScenarioCheckerTest(Scenario scenario) {
PriorityQueue<ScenarioCheckerMessage> ret = new PriorityQueue<>();
List<DataProcessor<?, ?>> processors
= scenario.getDataProcessingJsonManager().getDataProcessors();
List<Integer> measurementAreas = scenario.getTopography().getMeasurementAreas()
.stream()
.map(MeasurementArea::getId)
.collect(Collectors.toList());
processors.stream().filter(UsesMeasurementArea.class::isInstance).forEach( p -> {
UsesMeasurementArea pArea = (UsesMeasurementArea)p;
for (int areaId : pArea.getReferencedMeasurementAreaId()) {
if (!measurementAreas.contains(areaId)) {
ret.add(msgBuilder.dataProcessorAttrError()
.reason(ScenarioCheckerReason.PROCESSOR_MEASUREMENT_AREA,
String.format(" [Processor id: %d]", p.getId()))
.build()
);
}
}
});
return ret;
}
}
{
"name" : "TopographyCheckerTest",
"description" : "",
"release" : "0.7",
"release" : "0.8",
"commithash" : "warning: no commit hash",
"processWriters" : {
"files" : [ {
......
{
"name" : "Test1",
"description" : "",
"release" : "0.7",
"release" : "0.8",
"commithash" : "c45f1d26328baaec22418c15e6351a059e910f5f",
"processWriters" : {
"files" : [ {
......
{
"name" : "Test1",
"description" : "",
"release" : "0.7",
"release" : "0.8",
"commithash" : "c45f1d26328baaec22418c15e6351a059e910f5f",
"processWriters" : {
"files" : [ {
......
{
"name" : "Test2",
"description" : "",
"release" : "0.7",
"release" : "0.8",
"commithash" : "c45f1d26328baaec22418c15e6351a059e910f5f",
"processWriters" : {
"files" : [ {
......
{
"name" : "Test1",
"description" : "",
"release" : "0.7",
"release" : "0.8",
"commithash" : "c45f1d26328baaec22418c15e6351a059e910f5f",
"processWriters" : {
"files" : [ {
......
{
"name" : "Test1",
"description" : "",
"release" : "0.7",
"release" : "0.8",
"commithash" : "c45f1d26328baaec22418c15e6351a059e910f5f",
"processWriters" : {
"files" : [ {
......
{
"name" : "Test2",
"description" : "",
"release" : "0.7",
"release" : "0.8",
"commithash" : "c45f1d26328baaec22418c15e6351a059e910f5f",
"processWriters" : {
"files" : [ {
......
{
"name" : "basic_1_chicken_osm1",
"description" : "",
"release" : "0.7",
"release" : "0.8",
"commithash" : "warning: no commit hash",
"processWriters" : {
"files" : [ {
......@@ -172,4 +172,4 @@
"attributesCar" : null
}
}
}
}
\ No newline at end of file
{
"name" : "test_postvis",
"description" : "",
"release" : "0.7",
"release" : "0.8",
"commithash" : "warning: no commit hash",
"processWriters" : {
"files" : [ {
......
{
"name" : "test_postvis",
"description" : "",
"release" : "0.7",
"release" : "0.8",
"commithash" : "warning: no commit hash",
"processWriters" : {
"files" : [ {
......
{
"name" : "test_postvis",
"description" : "",
"release" : "0.7",
"release" : "0.8",
"commithash" : "warning: no commit hash",
"processWriters" : {
"files" : [ {
......
{
"name" : "test_postvis",
"description" : "",
"release" : "0.7",
"release" : "0.8",
"commithash" : "warning: no commit hash",
"processWriters" : {
"files" : [ {
......
{
"name" : "test_postvis",
"description" : "",
"release" : "0.7",
"release" : "0.8",
"commithash" : "warning: no commit hash",
"processWriters" : {
"files" : [ {
......
{
"name" : "test_postvis",
"description" : "",
"release" : "0.7",
"release" : "0.8",
"commithash" : "warning: no commit hash",
"processWriters" : {
"files" : [ {
......
{
"name" : "test_postvis",
"description" : "",
"release" : "0.7",
"release" : "0.8",
"commithash" : "warning: no commit hash",
"processWriters" : {
"files" : [ {
......
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