Commit 8d2e0e34 authored by Julian Zobel's avatar Julian Zobel
Browse files

JSON Attraction Generator now takes in an upper limit for attraction points

parent 6906943a
...@@ -36,6 +36,7 @@ import de.tud.kom.p2psim.impl.topology.movement.modularosm.GPSCalculation; ...@@ -36,6 +36,7 @@ import de.tud.kom.p2psim.impl.topology.movement.modularosm.GPSCalculation;
import de.tud.kom.p2psim.impl.topology.util.PositionVector; import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.Binder; import de.tudarmstadt.maki.simonstrator.api.Binder;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint; import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
/** /**
* Generates attraction points out of real data from osm * Generates attraction points out of real data from osm
...@@ -43,13 +44,18 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Attraction ...@@ -43,13 +44,18 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Attraction
* *
* @author Martin Hellwig * @author Martin Hellwig
* @version 1.0, 02.07.2015 * @version 1.0, 02.07.2015
*
* Added an upper limit for the number of attraction points. Use 0 to allow all APs in the JSON file.
* @author Julian Zobel
* @version 1.1, November 2018
*
*
*/ */
public class JSONAttractionGenerator implements IAttractionGenerator { public class JSONAttractionGenerator implements IAttractionGenerator {
private PositionVector worldDimensions; private PositionVector worldDimensions;
private List<AttractionPoint> attractionPoints; private int numberOfAttractionPoints;
private String placementJsonFile; private String placementJsonFile;
private double latLeft; //Values from -90 to 90; always smaller than latRight private double latLeft; //Values from -90 to 90; always smaller than latRight
private double latRight; //Values from -90 to 90 private double latRight; //Values from -90 to 90
...@@ -61,11 +67,12 @@ public class JSONAttractionGenerator implements IAttractionGenerator { ...@@ -61,11 +67,12 @@ public class JSONAttractionGenerator implements IAttractionGenerator {
* Sample-query for "bar"-POIs in Darmstadt (Bounding Box from [49.4813, 8.5590] to [49.9088, 8,7736]: * Sample-query for "bar"-POIs in Darmstadt (Bounding Box from [49.4813, 8.5590] to [49.9088, 8,7736]:
http://overpass-api.de/api/interpreter?data=%5Bout:json%5D;node%5Bamenity=bar%5D%2849%2E4813%2C8%2E5590%2C49%2E9088%2C8%2E7736%29%3Bout%3B http://overpass-api.de/api/interpreter?data=%5Bout:json%5D;node%5Bamenity=bar%5D%2849%2E4813%2C8%2E5590%2C49%2E9088%2C8%2E7736%29%3Bout%3B
*/ */
public JSONAttractionGenerator() { @XMLConfigurableConstructor({"numberOfAttractionPoints"})
public JSONAttractionGenerator(int numberOfAttractionPoints) {
this.worldDimensions = Binder.getComponentOrNull(Topology.class) this.worldDimensions = Binder.getComponentOrNull(Topology.class)
.getWorldDimensions(); .getWorldDimensions();
attractionPoints = new LinkedList<AttractionPoint>();
this.numberOfAttractionPoints = numberOfAttractionPoints;
latLeft = GPSCalculation.getLatLower(); latLeft = GPSCalculation.getLatLower();
latRight = GPSCalculation.getLatUpper(); latRight = GPSCalculation.getLatUpper();
lonLeft = GPSCalculation.getLonLeft(); lonLeft = GPSCalculation.getLonLeft();
...@@ -105,7 +112,16 @@ public class JSONAttractionGenerator implements IAttractionGenerator { ...@@ -105,7 +112,16 @@ public class JSONAttractionGenerator implements IAttractionGenerator {
} }
if(allPOI != null) { if(allPOI != null) {
for(int i = 0; i < allPOI.length(); i++) {
int limit = 0;
if(numberOfAttractionPoints == 0) {
limit = allPOI.length();
}
else {
limit = numberOfAttractionPoints;
}
for(int i = 0; i < limit; i++) {
try { try {
String barname = allPOI.getJSONObject(i).getJSONObject("tags").getString("name"); String barname = allPOI.getJSONObject(i).getJSONObject("tags").getString("name");
double lat = allPOI.getJSONObject(i).getDouble("lat"); double lat = allPOI.getJSONObject(i).getDouble("lat");
...@@ -132,5 +148,9 @@ public class JSONAttractionGenerator implements IAttractionGenerator { ...@@ -132,5 +148,9 @@ public class JSONAttractionGenerator implements IAttractionGenerator {
public void setPlacementJsonFile(String placementJsonFile) { public void setPlacementJsonFile(String placementJsonFile) {
this.placementJsonFile = placementJsonFile; this.placementJsonFile = placementJsonFile;
//System.out.println(placementJsonFile);
if(attractionPoints.isEmpty()) {
this.getAttractionPoints();
}
} }
} }
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