10.12., 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Commit 6ecd3422 authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier

Added two new output processors ("PedestrianMostImportantEventProcessor" and...

Added two new output processors ("PedestrianMostImportantEventProcessor" and "PedestrianEventProcessor") and use them in "TrajectoryReader".
parent 1a477fa7
......@@ -6,7 +6,7 @@
"files" : [ {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestrianIdOutputFile",
"filename" : "postvis.trajectories",
"processors" : [ 1, 2 ]
"processors" : [ 1, 2, 5 ]
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestrianIdOverlapOutputFile",
"filename" : "overlaps.csv",
......@@ -32,6 +32,9 @@
"attributes" : {
"pedestrianOverlapProcessorId" : 3
}
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianSalientBehaviorProcessor",
"id" : 5
} ],
"isTimestamped" : true,
"isWriteMetaData" : false
......
package org.vadere.simulator.projects.dataprocessing.processor;
import org.vadere.annotation.factories.dataprocessors.DataProcessorClass;
import org.vadere.simulator.control.SimulationState;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepPedestrianIdKey;
import org.vadere.state.scenario.Pedestrian;
import java.util.Collection;
/**
* Save most important event of a pedestrian in each time step in an own column.
*/
@DataProcessorClass()
public class PedestrianMostImportantEventProcessor extends DataProcessor<TimestepPedestrianIdKey, String> {
public PedestrianMostImportantEventProcessor() {
super("mostImportantEvent");
}
@Override
public void doUpdate(final SimulationState state) {
Collection<Pedestrian> pedestrians = state.getTopography().getElements(Pedestrian.class);
pedestrians.forEach(pedestrian -> this.putValue(
new TimestepPedestrianIdKey(state.getStep(), pedestrian.getId()),
pedestrian.getMostImportantEvent().toStringForOutputProcessor())
);
}
}
package org.vadere.simulator.projects.dataprocessing.processor;
import org.vadere.annotation.factories.dataprocessors.DataProcessorClass;
import org.vadere.simulator.control.SimulationState;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepPedestrianIdKey;
import org.vadere.state.scenario.Pedestrian;
import java.util.Collection;
/**
* Save salient behavior of a pedestrian in each time step in an own column.
*/
@DataProcessorClass()
public class PedestrianSalientBehaviorProcessor extends DataProcessor<TimestepPedestrianIdKey, String> {
public PedestrianSalientBehaviorProcessor() {
super("salientBehavior");
}
@Override
public void doUpdate(final SimulationState state) {
Collection<Pedestrian> pedestrians = state.getTopography().getElements(Pedestrian.class);
pedestrians.forEach(pedestrian -> this.putValue(
new TimestepPedestrianIdKey(state.getStep(), pedestrian.getId()),
pedestrian.getSalientBehavior().toString())
);
}
}
......@@ -5,6 +5,7 @@ import org.jetbrains.annotations.NotNull;
import org.vadere.simulator.projects.Scenario;
import org.vadere.simulator.projects.dataprocessing.processor.PedestrianPositionProcessor;
import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.behavior.SalientBehavior;
import org.vadere.state.scenario.Agent;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.simulation.FootStep;
......@@ -44,6 +45,7 @@ public class TrajectoryReader {
private static final String SPLITTER = " ";
private static Logger logger = Logger.getLogger(IOVadere.class);
private Path trajectoryFilePath;
private AttributesAgent attributesPedestrian;
private Set<String> pedestrianIdKeys;
......@@ -54,7 +56,8 @@ public class TrajectoryReader {
private Set<String> groupIdKeys;
private Set<String> groupSizeKeys;
private Set<String> stridesKeys;
private Set<String> mostImportantEventKeys;
private Set<String> salientBehaviorKeys;
private int pedIdIndex;
private int stepIndex;
......@@ -64,6 +67,8 @@ public class TrajectoryReader {
private int groupIdIndex;
private int groupSizeIndex;
private int stridesIndex;
private int mostImportantEventIndex;
private int salientBehaviorIndex;
public TrajectoryReader(final Path trajectoryFilePath, final Scenario scenario) {
this(trajectoryFilePath, scenario.getAttributesPedestrian());
......@@ -84,6 +89,8 @@ public class TrajectoryReader {
groupIdKeys = new HashSet<>();
groupSizeKeys = new HashSet<>();
stridesKeys = new HashSet<>();
mostImportantEventKeys = new HashSet<>();
salientBehaviorKeys = new HashSet<>();
//should be set via Processor.getHeader
pedestrianIdKeys.add("id");
......@@ -97,6 +104,8 @@ public class TrajectoryReader {
groupSizeKeys.add("groupSize");
stridesKeys.add("strides");
stridesKeys.add("footSteps");
mostImportantEventKeys.add("mostImportantEvent");
salientBehaviorKeys.add("salientBehavior");
pedIdIndex = -1;
stepIndex = -1;
......@@ -106,7 +115,8 @@ public class TrajectoryReader {
groupIdIndex = -1;
groupSizeIndex = -1;
stridesIndex = -1;
mostImportantEventIndex = -1;
salientBehaviorIndex = -1;
}
public Map<Step, List<Agent>> readFile() throws IOException {
......@@ -131,12 +141,14 @@ public class TrajectoryReader {
targetIdIndex = index;
} else if (groupIdKeys.contains(columns[index])){
groupIdIndex = index;
}
else if (groupSizeKeys.contains(columns[index])){
} else if (groupSizeKeys.contains(columns[index])){
groupSizeIndex = index;
}
else if(stridesKeys.contains(columns[index])) {
} else if(stridesKeys.contains(columns[index])) {
stridesIndex = index;
} else if (mostImportantEventKeys.contains(columns[index])) {
mostImportantEventIndex = index;
} else if (salientBehaviorKeys.contains(columns[index])) {
salientBehaviorIndex = index;
}
}
try {
......@@ -158,7 +170,7 @@ public class TrajectoryReader {
try (BufferedReader in = IOUtils.defaultBufferedReader(this.trajectoryFilePath)) {
return in.lines() // a stream of lines
.skip(1) // skip the first line i.e. the header
.map(line -> split(line)) // split the line into string tokens
.map(line -> split(line)) // split the line into string tokens
.map(rowTokens -> parseRowTokens(rowTokens)) // transform those tokens into a pair of java objects (step, agent)
.collect(Collectors.groupingBy(Pair::getKey, // group all agent objects by the step.
Collectors.mapping(Pair::getValue, Collectors.toList())));
......@@ -233,6 +245,15 @@ public class TrajectoryReader {
}
}
if (mostImportantEventIndex != -1) {
// TODO: Convert string (in column) to event object (this requires a factory) and call ped.setMostImportantEvent(...).
}
if (salientBehaviorIndex != -1) {
SalientBehavior salientBehavior = SalientBehavior.valueOf(rowTokens[salientBehaviorIndex]);
ped.setSalientBehavior(salientBehavior);
}
return Pair.create(new Step(step), ped);
}
}
......@@ -98,4 +98,8 @@ public abstract class Event {
return string;
}
public String toStringForOutputProcessor() {
return this.getClass().getSimpleName();
}
}
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