Commit db12ac1c authored by Mario Teixeira Parente's avatar Mario Teixeira Parente
Browse files

Merge branch 'dev/processors' into develop

parents 1709d0cd 8de07160
...@@ -112,7 +112,7 @@ protected abstract void doUpdate(final SimulationState state) { ...@@ -112,7 +112,7 @@ protected abstract void doUpdate(final SimulationState state) {
int timeStep = state.getStep(); int timeStep = state.getStep();
int amountPeds = state.getTopography().getElements(Pedestrian.class).size(); int amountPeds = state.getTopography().getElements(Pedestrian.class).size();
this.addValue(new TimestepDataKey(timeStep), amountPeds); this.setValue(new TimestepDataKey(timeStep), amountPeds);
} }
``` ```
......
...@@ -20,6 +20,14 @@ ...@@ -20,6 +20,14 @@
"type": "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestrianIdOutputFile", "type": "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestrianIdOutputFile",
"filename": "postvis.trajectories", "filename": "postvis.trajectories",
"processors": [ 1, 18 ] "processors": [ 1, 18 ]
}, {
"type": "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepRowOutputFile",
"filename": "output_ts_row.txt",
"processors": [ 20 ]
}, {
"type": "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPositionOutputFile",
"filename": "output_ts_pos.txt",
"processors": [ 21 ]
} ], } ],
"processors": [ { "processors": [ {
"type": "org.vadere.simulator.projects.dataprocessing.processor.PedestrianPositionProcessor", "type": "org.vadere.simulator.projects.dataprocessing.processor.PedestrianPositionProcessor",
...@@ -165,5 +173,19 @@ ...@@ -165,5 +173,19 @@
}, { }, {
"type": "org.vadere.simulator.projects.dataprocessing.processor.PedestrianSourceIdProcessor", "type": "org.vadere.simulator.projects.dataprocessing.processor.PedestrianSourceIdProcessor",
"id": 19 "id": 19
}, {
"type": "org.vadere.simulator.projects.dataprocessing.processor.FloorFieldGridProcessor",
"id": 20,
"attributesType": "org.vadere.state.attributes.processor.AttributesFloorFieldProcessor",
"attributes": {
"targetId": 1
}
}, {
"type": "org.vadere.simulator.projects.dataprocessing.processor.FloorFieldProcessor",
"id": 21,
"attributesType": "org.vadere.state.attributes.processor.AttributesFloorFieldProcessor",
"attributes": {
"targetId": 1
}
} ] } ]
} }
...@@ -5,10 +5,10 @@ package org.vadere.simulator.projects.dataprocessing.datakey; ...@@ -5,10 +5,10 @@ package org.vadere.simulator.projects.dataprocessing.datakey;
* *
*/ */
public class PedestrianIdDataKey implements DataKey<PedestrianIdDataKey> { public class PedestrianIdKey implements DataKey<PedestrianIdKey> {
private final int pedestrianId; private final int pedestrianId;
public PedestrianIdDataKey(int pedestrianId) { public PedestrianIdKey(int pedestrianId) {
this.pedestrianId = pedestrianId; this.pedestrianId = pedestrianId;
} }
...@@ -36,14 +36,14 @@ public class PedestrianIdDataKey implements DataKey<PedestrianIdDataKey> { ...@@ -36,14 +36,14 @@ public class PedestrianIdDataKey implements DataKey<PedestrianIdDataKey> {
return false; return false;
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; return false;
PedestrianIdDataKey other = (PedestrianIdDataKey) obj; PedestrianIdKey other = (PedestrianIdKey) obj;
if (pedestrianId != other.pedestrianId) if (pedestrianId != other.pedestrianId)
return false; return false;
return true; return true;
} }
@Override @Override
public int compareTo(PedestrianIdDataKey o) { public int compareTo(PedestrianIdKey o) {
return Integer.compare(pedestrianId, o.pedestrianId); return Integer.compare(pedestrianId, o.pedestrianId);
} }
......
...@@ -5,14 +5,14 @@ package org.vadere.simulator.projects.dataprocessing.datakey; ...@@ -5,14 +5,14 @@ package org.vadere.simulator.projects.dataprocessing.datakey;
* *
*/ */
public class TimestepDataKey implements DataKey<TimestepDataKey> { public class TimestepKey implements DataKey<TimestepKey> {
private final int timestep; private final int timestep;
public TimestepDataKey(int timestep) { public TimestepKey(int timestep) {
this.timestep = timestep; this.timestep = timestep;
} }
@Override @Override
public int compareTo(final TimestepDataKey o) { public int compareTo(final TimestepKey o) {
return Integer.compare(timestep, o.timestep); return Integer.compare(timestep, o.timestep);
} }
...@@ -36,7 +36,7 @@ public class TimestepDataKey implements DataKey<TimestepDataKey> { ...@@ -36,7 +36,7 @@ public class TimestepDataKey implements DataKey<TimestepDataKey> {
return false; return false;
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; return false;
TimestepDataKey other = (TimestepDataKey) obj; TimestepKey other = (TimestepKey) obj;
if (timestep != other.timestep) if (timestep != other.timestep)
return false; return false;
return true; return true;
......
...@@ -5,11 +5,11 @@ package org.vadere.simulator.projects.dataprocessing.datakey; ...@@ -5,11 +5,11 @@ package org.vadere.simulator.projects.dataprocessing.datakey;
* *
*/ */
public class TimestepPedestrianIdDataKey implements DataKey<TimestepPedestrianIdDataKey> { public class TimestepPedestrianIdKey implements DataKey<TimestepPedestrianIdKey> {
private final int timestep; private final int timestep;
private final int pedestrianId; private final int pedestrianId;
public TimestepPedestrianIdDataKey(int timestep, int pedestrianId) { public TimestepPedestrianIdKey(int timestep, int pedestrianId) {
this.timestep = timestep; this.timestep = timestep;
this.pedestrianId = pedestrianId; this.pedestrianId = pedestrianId;
} }
...@@ -23,7 +23,7 @@ public class TimestepPedestrianIdDataKey implements DataKey<TimestepPedestrianId ...@@ -23,7 +23,7 @@ public class TimestepPedestrianIdDataKey implements DataKey<TimestepPedestrianId
} }
@Override @Override
public int compareTo(TimestepPedestrianIdDataKey o) { public int compareTo(TimestepPedestrianIdKey o) {
int result = Integer.compare(timestep, o.timestep); int result = Integer.compare(timestep, o.timestep);
if (result == 0) { if (result == 0) {
return Integer.compare(pedestrianId, o.pedestrianId); return Integer.compare(pedestrianId, o.pedestrianId);
...@@ -32,7 +32,7 @@ public class TimestepPedestrianIdDataKey implements DataKey<TimestepPedestrianId ...@@ -32,7 +32,7 @@ public class TimestepPedestrianIdDataKey implements DataKey<TimestepPedestrianId
} }
public static String[] getHeaders() { public static String[] getHeaders() {
return new String[] { TimestepDataKey.getHeader(), PedestrianIdDataKey.getHeader() }; return new String[] { TimestepKey.getHeader(), PedestrianIdKey.getHeader() };
} }
@Override @Override
...@@ -52,7 +52,7 @@ public class TimestepPedestrianIdDataKey implements DataKey<TimestepPedestrianId ...@@ -52,7 +52,7 @@ public class TimestepPedestrianIdDataKey implements DataKey<TimestepPedestrianId
return false; return false;
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; return false;
TimestepPedestrianIdDataKey other = (TimestepPedestrianIdDataKey) obj; TimestepPedestrianIdKey other = (TimestepPedestrianIdKey) obj;
if (pedestrianId != other.pedestrianId) if (pedestrianId != other.pedestrianId)
return false; return false;
if (timestep != other.timestep) if (timestep != other.timestep)
......
package org.vadere.simulator.projects.dataprocessing.datakey;
import org.jetbrains.annotations.NotNull;
import org.vadere.util.geometry.shapes.VPoint;
/**
* @author Mario Teixeira Parente
*/
public class TimestepPositionKey implements DataKey<TimestepPositionKey> {
private int timeStep;
private VPoint position;
public TimestepPositionKey(int timeStep, VPoint position) {
this.timeStep = timeStep;
this.position = position;
}
public int getTimeStep() {
return this.timeStep;
}
public VPoint getPosition() {
return this.position;
}
@Override
public int compareTo(@NotNull TimestepPositionKey o) {
int result = Integer.compare(this.timeStep, o.timeStep);
if (result == 0) {
result = Double.compare(this.position.x, o.position.x);
if (result == 0) {
result = Double.compare(this.position.y, o.position.y);
}
}
return result;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
TimestepPositionKey that = (TimestepPositionKey) o;
if (timeStep != that.timeStep) return false;
return position.equals(that.position);
}
@Override
public int hashCode() {
int result = timeStep;
result = 31 * result + position.hashCode();
return result;
}
public static String[] getHeaders() {
return new String[] { "timeStep", "x", "y" };
}
}
package org.vadere.simulator.projects.dataprocessing.datakey;
import org.jetbrains.annotations.NotNull;
/**
* @author Mario Teixeira Parente
*
*/
public class TimestepRowKey implements DataKey<TimestepRowKey> {
private int timeStep;
private int row;
public TimestepRowKey(int timeStep, int row) {
this.timeStep = timeStep;
this.row = row;
}
public int getTimeStep() {
return this.timeStep;
}
public int getRow() {
return this.row;
}
@Override
public int compareTo(@NotNull TimestepRowKey o) {
int result = Integer.compare(this.timeStep, o.timeStep);
if (result == 0) {
return Integer.compare(this.row, o.row);
}
return result;
}
}
package org.vadere.simulator.projects.dataprocessing.outputfile; package org.vadere.simulator.projects.dataprocessing.outputfile;
import org.vadere.simulator.projects.dataprocessing.datakey.PedestrianIdDataKey; import org.vadere.simulator.projects.dataprocessing.datakey.PedestrianIdKey;
/** /**
* @author Mario Teixeira Parente * @author Mario Teixeira Parente
* *
*/ */
public class PedestrianIdOutputFile extends OutputFile<PedestrianIdDataKey> { public class PedestrianIdOutputFile extends OutputFile<PedestrianIdKey> {
public PedestrianIdOutputFile() { public PedestrianIdOutputFile() {
super(PedestrianIdDataKey.getHeader()); super(PedestrianIdKey.getHeader());
} }
} }
package org.vadere.simulator.projects.dataprocessing.outputfile; package org.vadere.simulator.projects.dataprocessing.outputfile;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepDataKey; import org.vadere.simulator.projects.dataprocessing.datakey.TimestepKey;
/** /**
* @author Mario Teixeira Parente * @author Mario Teixeira Parente
* *
*/ */
public class TimestepOutputFile extends OutputFile<TimestepDataKey> { public class TimestepOutputFile extends OutputFile<TimestepKey> {
public TimestepOutputFile() { public TimestepOutputFile() {
super("hdfkh"); super("hdfkh");
......
package org.vadere.simulator.projects.dataprocessing.outputfile; package org.vadere.simulator.projects.dataprocessing.outputfile;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepPedestrianIdDataKey; import org.vadere.simulator.projects.dataprocessing.datakey.TimestepPedestrianIdKey;
/** /**
* @author Mario Teixeira Parente * @author Mario Teixeira Parente
* *
*/ */
public class TimestepPedestrianIdOutputFile extends OutputFile<TimestepPedestrianIdDataKey> { public class TimestepPedestrianIdOutputFile extends OutputFile<TimestepPedestrianIdKey> {
public TimestepPedestrianIdOutputFile() { public TimestepPedestrianIdOutputFile() {
super(TimestepPedestrianIdDataKey.getHeaders()); super(TimestepPedestrianIdKey.getHeaders());
} }
@Override @Override
public String[] toStrings(final TimestepPedestrianIdDataKey key) { public String[] toStrings(final TimestepPedestrianIdKey key) {
return new String[] { Integer.toString(key.getTimestep()), Integer.toString(key.getPedestrianId()) }; return new String[] { Integer.toString(key.getTimestep()), Integer.toString(key.getPedestrianId()) };
} }
} }
package org.vadere.simulator.projects.dataprocessing.outputfile;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepPositionKey;
public class TimestepPositionOutputFile extends OutputFile<TimestepPositionKey> {
public TimestepPositionOutputFile() {
super(TimestepPositionKey.getHeaders());
}
@Override
public String[] toStrings(TimestepPositionKey key) {
return new String[] { Integer.toString(key.getTimeStep()), Double.toString(key.getPosition().x), Double.toString(key.getPosition().y) };
}
}
package org.vadere.simulator.projects.dataprocessing.outputfile;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepRowKey;
public class TimestepRowOutputFile extends OutputFile<TimestepRowKey> {
public TimestepRowOutputFile() {
super("timeStep", "row");
}
@Override
public String[] toStrings(TimestepRowKey key) {
return new String[] { Integer.toString(key.getTimeStep()), Integer.toString(key.getRow()) };
}
}
package org.vadere.simulator.projects.dataprocessing.processor; package org.vadere.simulator.projects.dataprocessing.processor;
import org.vadere.simulator.projects.dataprocessing.ProcessorManager; import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepDataKey; import org.vadere.simulator.projects.dataprocessing.datakey.TimestepKey;
import org.vadere.state.attributes.processor.AttributesAreaProcessor; import org.vadere.state.attributes.processor.AttributesAreaProcessor;
import org.vadere.util.geometry.shapes.VRectangle; import org.vadere.util.geometry.shapes.VRectangle;
...@@ -10,7 +10,7 @@ import org.vadere.util.geometry.shapes.VRectangle; ...@@ -10,7 +10,7 @@ import org.vadere.util.geometry.shapes.VRectangle;
* *
*/ */
public abstract class AreaDataProcessor<V> extends DataProcessor<TimestepDataKey, V> { public abstract class AreaDataProcessor<V> extends DataProcessor<TimestepKey, V> {
private VRectangle measurementArea; private VRectangle measurementArea;
protected AreaDataProcessor(final String... headers) { protected AreaDataProcessor(final String... headers) {
......
package org.vadere.simulator.projects.dataprocessing.processor; package org.vadere.simulator.projects.dataprocessing.processor;
import org.vadere.simulator.control.SimulationState; import org.vadere.simulator.control.SimulationState;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepDataKey; import org.vadere.simulator.projects.dataprocessing.datakey.TimestepKey;
/** /**
* @author Mario Teixeira Parente * @author Mario Teixeira Parente
...@@ -18,6 +18,6 @@ public abstract class AreaDensityProcessor extends AreaDataProcessor<Double> { ...@@ -18,6 +18,6 @@ public abstract class AreaDensityProcessor extends AreaDataProcessor<Double> {
@Override @Override
protected void doUpdate(final SimulationState state) { protected void doUpdate(final SimulationState state) {
this.addValue(new TimestepDataKey(state.getStep()), this.densAlg.getDensity(state)); this.setValue(new TimestepKey(state.getStep()), this.densAlg.getDensity(state));
} }
} }
...@@ -2,9 +2,9 @@ package org.vadere.simulator.projects.dataprocessing.processor; ...@@ -2,9 +2,9 @@ package org.vadere.simulator.projects.dataprocessing.processor;
import org.vadere.simulator.control.SimulationState; import org.vadere.simulator.control.SimulationState;
import org.vadere.simulator.projects.dataprocessing.ProcessorManager; import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.simulator.projects.dataprocessing.datakey.PedestrianIdDataKey; import org.vadere.simulator.projects.dataprocessing.datakey.PedestrianIdKey;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepDataKey; import org.vadere.simulator.projects.dataprocessing.datakey.TimestepKey;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepPedestrianIdDataKey; import org.vadere.simulator.projects.dataprocessing.datakey.TimestepPedestrianIdKey;
import org.vadere.state.attributes.processor.AttributesAreaSpeedProcessor; import org.vadere.state.attributes.processor.AttributesAreaSpeedProcessor;
import org.vadere.util.geometry.shapes.VPoint; import org.vadere.util.geometry.shapes.VPoint;
...@@ -30,22 +30,22 @@ public class AreaSpeedProcessor extends AreaDataProcessor<Double> { ...@@ -30,22 +30,22 @@ public class AreaSpeedProcessor extends AreaDataProcessor<Double> {
this.pedPosProc.update(state); this.pedPosProc.update(state);
this.pedVelProc.update(state); this.pedVelProc.update(state);
Map<PedestrianIdDataKey, VPoint> positionMap = this.pedPosProc.getPositions(new TimestepDataKey(step)); Map<PedestrianIdKey, VPoint> positionMap = this.pedPosProc.getPositions(new TimestepKey(step));
int pedCount = 0; int pedCount = 0;
double sumVelocities = 0.0; double sumVelocities = 0.0;
for (Map.Entry<PedestrianIdDataKey, VPoint> entry : positionMap.entrySet()) { for (Map.Entry<PedestrianIdKey, VPoint> entry : positionMap.entrySet()) {
final int pedId = entry.getKey().getPedestrianId(); final int pedId = entry.getKey().getPedestrianId();
final VPoint pos = entry.getValue(); final VPoint pos = entry.getValue();
if (getMeasurementArea().contains(pos)) { if (getMeasurementArea().contains(pos)) {
sumVelocities += this.pedVelProc.getValue(new TimestepPedestrianIdDataKey(step, pedId)); sumVelocities += this.pedVelProc.getValue(new TimestepPedestrianIdKey(step, pedId));
pedCount++; pedCount++;
} }
} }
this.addValue(new TimestepDataKey(step), sumVelocities / pedCount); this.setValue(new TimestepKey(step), sumVelocities / pedCount);
} }
@Override @Override
......
...@@ -20,7 +20,7 @@ import java.util.TreeMap; ...@@ -20,7 +20,7 @@ import java.util.TreeMap;
* *
* The method <tt>doUpdate</tt> gets called after every simulation step with the current <tt>SimulationState</tt>. * The method <tt>doUpdate</tt> gets called after every simulation step with the current <tt>SimulationState</tt>.
* Here, one gets the opportunity to compute a new value or to update the state for a computation in <tt>postLoop</tt>. * Here, one gets the opportunity to compute a new value or to update the state for a computation in <tt>postLoop</tt>.
* The computed value can be stored afterwards in the data by using the <tt>addValue</tt> method. * The computed value can be stored afterwards in the data by using the <tt>setValue</tt> method.
* *
* To get specific attributes defined in JSON or access to the <tt>MainModel</tt>, one has to use the <tt>init</tt> method which * To get specific attributes defined in JSON or access to the <tt>MainModel</tt>, one has to use the <tt>init</tt> method which
* gives access to all significant things via the argument <tt>manager</tt> of type <tt>ProcessorManager</tt>. * gives access to all significant things via the argument <tt>manager</tt> of type <tt>ProcessorManager</tt>.
...@@ -96,7 +96,7 @@ public abstract class DataProcessor<K extends DataKey<K>, V> { ...@@ -96,7 +96,7 @@ public abstract class DataProcessor<K extends DataKey<K>, V> {