Commit 1e4807f3 authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier
Browse files

Implemented "FootStepPsychologyStatusProcessor" and process output in "TableTrajectoryFootStep"

Added also test scenario "TestPsychology/ScenarioElements/scenarios/07-Test-FootStepPsychologyStatusProcessor.scenario"
parent fc9050b5
......@@ -7,6 +7,7 @@ import org.vadere.gui.postvisualization.utils.PotentialFieldContainer;
import org.vadere.simulator.projects.Scenario;
import org.vadere.state.attributes.AttributesSimulation;
import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.psychology.cognition.GroupMembership;
import org.vadere.state.psychology.cognition.SelfCategory;
import org.vadere.state.psychology.perception.types.StimulusFactory;
import org.vadere.state.scenario.Agent;
......@@ -246,6 +247,11 @@ public class PostvisualizationModel extends SimulationModel<PostvisualizationCon
pedestrian.setSelfCategory(SelfCategory.valueOf(selfCategoryString));
}
if(trajectories.groupMembershipCol != -1) {
String groupMembershipString = row.getString(trajectories.groupMembershipCol);
pedestrian.setGroupMembership(GroupMembership.valueOf(groupMembershipString));
}
return pedestrian;
}
......
......@@ -6,6 +6,7 @@ import it.unimi.dsi.fastutil.ints.Int2IntMap;
import org.jetbrains.annotations.NotNull;
import org.vadere.simulator.projects.io.ColumnNames;
import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.psychology.cognition.GroupMembership;
import org.vadere.state.psychology.cognition.SelfCategory;
import org.vadere.state.psychology.perception.types.Stimulus;
import org.vadere.state.psychology.perception.types.StimulusFactory;
......@@ -56,6 +57,7 @@ public class TableTrajectoryFootStep {
public final int mostImportantStimulusCol;
public final int selfCategoryCol;
public final int groupMembershipCol;
public static final int agentDFPedIdCol = 0;
public static final int birthTimeCol = 1;
......@@ -86,6 +88,7 @@ public class TableTrajectoryFootStep {
groupSizeCol = columnNames.getGroupSizeCol(dataFrame);
mostImportantStimulusCol = columnNames.getMostImportantStimulusCol(dataFrame);
selfCategoryCol = columnNames.getSelfCategoryCol(dataFrame);
groupMembershipCol = columnNames.getGroupMembershipCol(dataFrame);
this.trajectoryDataFrame = dataFrame;
......@@ -149,6 +152,12 @@ public class TableTrajectoryFootStep {
pedestrian.setSelfCategory(selfCategory);
}
if(groupMembershipCol != ColumnNames.NOT_SET_COLUMN_INDEX_IDENTIFIER) {
String groupMembershipEnumName = row.getString(groupMembershipCol);
GroupMembership groupMembership = GroupMembership.valueOf(groupMembershipEnumName);
pedestrian.setGroupMembership(groupMembership);
}
return pedestrian;
}
......
package org.vadere.simulator.projects.dataprocessing.processor;
import org.vadere.annotation.factories.dataprocessors.DataProcessorClass;
import org.vadere.simulator.control.simulation.SimulationState;
import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.simulator.projects.dataprocessing.datakey.EventtimePedestrianIdKey;
import org.vadere.state.psychology.PsychologyStatus;
import org.vadere.state.psychology.perception.ThreatMemory;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.simulation.FootStep;
import java.util.LinkedList;
/**
* Log {@link Pedestrian}'s current {@link PsychologyStatus} except its {@link ThreatMemory}.
*/
@DataProcessorClass()
public class FootStepPsychologyStatusProcessor extends DataProcessor<EventtimePedestrianIdKey, String> {
public static String[] HEADERS = { "mostImportantStimulus", "selfCategory", "groupMembership" };
public FootStepPsychologyStatusProcessor() {
super(HEADERS);
}
@Override
protected void doUpdate(final SimulationState state) {
for (Pedestrian pedestrian : state.getTopography().getElements(Pedestrian.class)) {
LinkedList<FootStep> footSteps = pedestrian.getTrajectory().clone().getFootSteps();
String psychologyStatus = psychologyStatusToString(pedestrian);
for (FootStep footStep : footSteps) {
putValue(new EventtimePedestrianIdKey(footStep.getStartTime(), pedestrian.getId()), psychologyStatus);
}
}
}
private String psychologyStatusToString(Pedestrian pedestrian) {
String statusAsString = String.format("%s %s %s",
pedestrian.getMostImportantStimulus().toStringForOutputProcessor(),
pedestrian.getSelfCategory().toString(),
pedestrian.getGroupMembership().toString()
);
return statusAsString;
}
@Override
public void init(final ProcessorManager manager) {
super.init(manager);
}
}
\ No newline at end of file
......@@ -22,6 +22,7 @@ public final class ColumnNames {
private Set<String> endTimeKeys;
private Set<String> mostImportantStimulusKeys;
private Set<String> selfCategoryKeys;
private Set<String> groupMembershipKeys;
private List<Set<String>> keys;
public static final int NOT_SET_COLUMN_INDEX_IDENTIFIER = -1;
......@@ -47,6 +48,7 @@ public final class ColumnNames {
groupSizeKeys = new HashSet<>();
mostImportantStimulusKeys = new HashSet<>();
selfCategoryKeys = new HashSet<>();
groupMembershipKeys = new HashSet<>();
startTimeKeys = new HashSet<>();
endTimeKeys = new HashSet<>();
......@@ -69,6 +71,7 @@ public final class ColumnNames {
groupSizeKeys.add("groupSize");
mostImportantStimulusKeys.add("mostImportantStimulus");
selfCategoryKeys.add("selfCategory");
groupMembershipKeys.add("groupMembership");
keys.add(pedestrianIdKeys);
keys.add(startX);
......@@ -80,18 +83,24 @@ public final class ColumnNames {
keys.add(groupSizeKeys);
keys.add(mostImportantStimulusKeys);
keys.add(selfCategoryKeys);
keys.add(groupMembershipKeys);
keys.add(startTimeKeys);
keys.add(endTimeKeys);
}
public int getMostImportantStimulusCol(@NotNull final Table dataFrame) {
return getColId(dataFrame, mostImportantStimulusKeys);
}
public int getSelfCategoryCol(@NotNull final Table dataFrame) {
return getColId(dataFrame, selfCategoryKeys);
}
public int getMostImportantStimulusCol(@NotNull final Table dataFrame) {
return getColId(dataFrame, mostImportantStimulusKeys);
public int getGroupMembershipCol(@NotNull final Table dataFrame) {
return getColId(dataFrame, groupMembershipKeys);
}
public int getPedestrianIdCol(@NotNull final Table dataFrame) {
return getColId(dataFrame, pedestrianIdKeys);
}
......
......@@ -12,7 +12,9 @@ public class StimulusFactory {
public static Stimulus stringToStimulus(@NotNull String stimulusAsString) {
Stimulus stimulusObject = null;
if (stimulusAsString.matches(Threat.class.getSimpleName())) {
if (stimulusAsString.matches(ChangeTarget.class.getSimpleName())) {
stimulusObject = new ChangeTarget();
} else if (stimulusAsString.matches(Threat.class.getSimpleName())) {
stimulusObject = new Threat();
} else if (stimulusAsString.matches(ElapsedTime.class.getSimpleName())) {
stimulusObject = new ElapsedTime();
......
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