Commit 450550be authored by Christina's avatar Christina

[WIP] add V14 to MigrationAssistant

parent b32529ce
Pipeline #301682 failed with stages
in 2 minutes and 5 seconds
{
"name" : "AbstractThreeCorridors",
"description" : "",
"release" : "1.13",
"release" : "1.14",
"processWriters" : {
"files" : [ {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.EventtimePedestrianIdOutputFile",
......@@ -73,11 +73,7 @@
"isWriteMetaData" : false
},
"scenario" : {
"attributesStrategy" : {
"useStrategyModel" : false,
"strategyModel" : "RouteChoiceThreeCorridors"
},
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesOSM" : {
"stepCircleResolution" : 4,
......@@ -151,6 +147,10 @@
"cognition" : "SimpleCognitionModel"
}
},
"attributesStrategy" : {
"useStrategyModel" : false,
"strategyModel" : "RouteChoiceThreeCorridors"
},
"topography" : {
"attributes" : {
"bounds" : {
......@@ -357,8 +357,8 @@
"id" : 5001,
"absorbing" : false,
"shape" : {
"x" : 64.6,
"y" : 10.2,
"x" : 64.5,
"y" : 14.0,
"width" : 5.0,
"height" : 5.0,
"type" : "RECTANGLE"
......@@ -413,8 +413,8 @@
}, {
"id" : 9,
"shape" : {
"x" : 60.1,
"y" : 4.2,
"x" : 60.0,
"y" : 10.0,
"width" : 14.1,
"height" : 4.0,
"type" : "RECTANGLE"
......
......@@ -306,4 +306,4 @@
},
"stimulusInfos" : [ ]
}
}
\ No newline at end of file
}
package org.vadere.gui.projectview.view;
public enum AttributeType {
SIMULATION, MODEL, PSYCHOLOGY, PEDESTRIAN, CAR, TOPOGRAPHY, OUTPUTPROCESSOR, PERCEPTION;
SIMULATION, MODEL, PSYCHOLOGY, PEDESTRIAN, CAR, TOPOGRAPHY, OUTPUTPROCESSOR, PERCEPTION, STRATEGY;
public final static String simulationAttributes = "simulation attributes";
public final static String modelAttributes = "panelModel attributes";
......@@ -10,6 +10,8 @@ public enum AttributeType {
public final static String scenarioAttributes = "scenario attributes";
public final static String carAttributes = "car attributes";
public final static String stimulusAttributes = "stimulus attributes";
public final static String strategyAttributes = "strategy attributes";
public static AttributeType fromName(String name) {
switch (name) {
......@@ -27,6 +29,8 @@ public enum AttributeType {
return CAR;
case stimulusAttributes:
return PERCEPTION;
case strategyAttributes:
return STRATEGY;
default:
throw new IllegalArgumentException("name " + name + " does not match any attribute type.");
}
......
......@@ -39,6 +39,7 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro
// tabs
private List<JMenu> menusInTabs = new ArrayList<>();
private TextView attributesSimulationView; // Simulation tab
private TextView attributesStrategyFileView; // Strategy tab
private TextView attributesModelView; // Model tab
private TextView attributesPsychologyView; // Psychology tab
private TextView topographyFileView; // Topography tab
......@@ -210,6 +211,7 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro
attributesPsychologyView.isEditable(true);
tabbedPane.addTab(Messages.getString("Tab.Psychology.title"), attributesPsychologyView);
topographyFileView = new TextView("ProjectView.defaultDirectoryScenarios", AttributeType.TOPOGRAPHY);
topographyFileView.setScenarioChecker(model);
tabbedPane.addTab(Messages.getString("Tab.Topography.title"), topographyFileView);
......@@ -218,6 +220,11 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro
perceptionFileView.isEditable(true);
tabbedPane.addTab(Messages.getString("Tab.Perception.title"), perceptionFileView);
attributesStrategyFileView =
new TextView("ProjectView.defaultDirectoryAttributes", AttributeType.STRATEGY);
attributesStrategyFileView.isEditable(true);
tabbedPane.addTab(Messages.getString("Tab.Strategy.title"), attributesStrategyFileView);
dataProcessingGUIview = new DataProcessingView(model);
tabbedPane.addTab(Messages.getString("Tab.OutputProcessors.title"), dataProcessingGUIview);
......@@ -311,6 +318,9 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro
this.perceptionFileView.setVadereScenario(scenario);
this.perceptionFileView.isEditable(isEditable);
this.attributesStrategyFileView.setVadereScenario(scenario);
this.attributesStrategyFileView.isEditable(isEditable);
this.dataProcessingGUIview.setVadereScenario(scenario);
this.dataProcessingGUIview.isEditable(isEditable);
}
......
......@@ -200,6 +200,10 @@ public class TextView extends JPanel implements IJsonView {
StimulusInfoStore stimulusInfoStore = StateJsonConverter.deserializeStimuli(json);
currentScenario.getScenarioStore().setStimulusInfoStore(stimulusInfoStore);
break;
case STRATEGY:
currentScenario
.setAttributesStrategy(StateJsonConverter.deserializeAttributesStrategyModel(json));
break;
default:
throw new RuntimeException("attribute type not implemented.");
}
......@@ -302,6 +306,10 @@ public class TextView extends JPanel implements IJsonView {
StimulusInfoStore stimulusInfoStore = scenario.getScenarioStore().getStimulusInfoStore();
textfileTextarea.setText(StateJsonConverter.serializeStimuli(stimulusInfoStore));
break;
case STRATEGY:
textfileTextarea
.setText(StateJsonConverter.serializeAttributesStrategyModel(scenario.getAttributesStrategyModel()));
break;
default:
throw new RuntimeException("attribute type not implemented.");
}
......
......@@ -10,6 +10,7 @@ import org.vadere.simulator.projects.io.JsonConverter;
import org.vadere.state.attributes.Attributes;
import org.vadere.state.attributes.AttributesPsychology;
import org.vadere.state.attributes.AttributesSimulation;
import org.vadere.state.attributes.AttributesStrategyModel;
import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.scenario.Topography;
import org.vadere.util.io.IOUtils;
......@@ -138,6 +139,10 @@ public class Scenario {
return scenarioStore.getAttributesPsychology();
}
public AttributesStrategyModel getAttributesStrategyModel() {
return scenarioStore.getAttributesStrategyModel();
}
public Topography getTopography() {
return scenarioStore.getTopography();
}
......@@ -158,6 +163,10 @@ public class Scenario {
this.scenarioStore.setAttributesPsychology(attributesPsychology);
}
public void setAttributesStrategy(@NotNull final AttributesStrategyModel attributesStrategyModel) {
this.scenarioStore.setAttributesStrategyModel(attributesStrategyModel);
}
public void setTopography(@NotNull final Topography topography) {
scenarioStore.setTopography(topography);
}
......
package org.vadere.simulator.projects.migration.jsontranformation;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import org.vadere.simulator.projects.migration.MigrationException;
......
package org.vadere.simulator.projects.migration.jsontranformation.json;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.vadere.annotation.factories.migrationassistant.MigrationTransformation;
import org.vadere.simulator.projects.migration.MigrationException;
import org.vadere.simulator.projects.migration.jsontranformation.SimpleJsonTransformation;
import org.vadere.state.attributes.AttributesPsychology;
import org.vadere.state.attributes.AttributesStrategyModel;
import org.vadere.state.util.StateJsonConverter;
import org.vadere.util.version.Version;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* Remove node "threatMemory" under "scenario.topography.dynamicElements.psychologyStatus"
*/
@MigrationTransformation(targetVersionLabel = "1.14")
public class TargetVersionV1_14 extends SimpleJsonTransformation {
public TargetVersionV1_14(){
super(Version.V1_14);
}
@Override
protected void initDefaultHooks() {
addPostHookFirst(this::addStrategyLayer);
addPostHookLast(this::sort);
}
public JsonNode addStrategyLayer(JsonNode node) throws MigrationException {
String useStrategyModelKey = "attributesStrategy";
JsonNode scenarioNode = path(node, "scenario");
JsonNode strategyModel = path(scenarioNode, useStrategyModelKey);
if (strategyModel.isMissingNode()) {
ObjectNode n = (ObjectNode) scenarioNode;
JsonNode attributesStrategyNode = StateJsonConverter.serializeAttributesStrategyModelToNode(new AttributesStrategyModel());
n.set(useStrategyModelKey, attributesStrategyNode );
}
return node;
}
}
......@@ -129,6 +129,10 @@ public abstract class StateJsonConverter {
return mapper.treeToValue(node, AttributesPsychology.class);
}
public static AttributesStrategyModel deserializeAttributesStrategyModel(String json) throws IOException {
return deserializeObjectFromJson(json, AttributesStrategyModel.class);
}
public static AttributesStrategyModel deserializeAttributesStrategyModelFromNode(JsonNode node)
throws JsonProcessingException {
return mapper.treeToValue(node, AttributesStrategyModel.class);
......@@ -358,6 +362,11 @@ public abstract class StateJsonConverter {
return prettyWriter.writeValueAsString(mapper.convertValue(attributesPsychology, JsonNode.class));
}
public static String serializeAttributesStrategyModel(AttributesStrategyModel attributesStrategyModel)
throws JsonProcessingException {
return prettyWriter.writeValueAsString(mapper.convertValue(attributesStrategyModel, JsonNode.class));
}
public static String serializeTopography(Topography topography) throws JsonProcessingException {
return prettyWriter.writeValueAsString(serializeTopographyToNode(topography));
}
......
......@@ -44,8 +44,8 @@ public enum Version {
V1_10(1, 10),
V1_11(1, 11),
V1_12(1, 12),
V1_13(1, 13);
V1_13(1, 13),
V1_14(1,14);
private static Logger logger = Logger.getLogger(Version.class);
......
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