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

Merge remote-tracking branch 'origin/jz/dev-monitor' into jz/master

parents d8bfa8aa bab9cc2c
......@@ -38,8 +38,9 @@ import de.tudarmstadt.maki.simonstrator.api.component.network.NetworkComponent.N
* @author Bjoern Richerzhagen
* @version 1.0, 25.02.2012
*
* @changes:
* Louis Neumann - setting LORA to "unlimited" bandwith
* @author Julian Zobel
* added LoRa PHY
*
*/
public enum PhyType {
......@@ -95,7 +96,7 @@ public enum PhyType {
* Assuming the following defaults: zero link-layer packet loss, 0.3 kbit/s BW,
* 500us latency, 1kByte MTU
*/
LORA(NetInterfaceName.LORA, 0, 1 * Rate.Gbit_s,
LORA(NetInterfaceName.LORA, 0, 300 * Rate.bit_s,
500 * Time.MICROSECOND, 1024, true);
......
......@@ -42,8 +42,9 @@ public interface TopologyComponent extends SimHostComponent,
* Binder-class.
*
* @return
* use Binder.getComponent(Topology.class) instead!
*/
* @deprecated use Binder.getComponent(Topology.class) instead!
*/
@Deprecated
public Topology getTopology();
}
......@@ -92,17 +92,7 @@ public class MetricAnalyzer implements Analyzer {
}
for (MetricOutput outputChannel : outputs) {
outputChannel.onStop();
}
System.out.println(" 0..2 >> " + TracefileMovementModel.ZERO_TO_2);
System.out.println(" 2..5 >> " + TracefileMovementModel._2_to_5);
System.out.println(" 5..10 >> " + TracefileMovementModel._5_to_10);
System.out.println(" 10..30 >> " + TracefileMovementModel.TEN_TO_THIRTY);
System.out.println(" 30..60 >> " + TracefileMovementModel.THIRTY_TO_SIXTY);
System.out.println(" 60..120 >> " + TracefileMovementModel.SIXTY_TO_120);
System.out.println(" 120..300 >> " + TracefileMovementModel._120_TO_300);
System.out.println(" 300..600 >> " + TracefileMovementModel._300_TO_600);
System.out.println(" 600 ++ >> " + TracefileMovementModel.ABOVE_600);
}
}
/**
......
......@@ -873,21 +873,23 @@ public abstract class AbstractMacLayer implements MacLayer {
messageDropped(DropReason.QUEUE_FULL, message);
// FIXME BR DEBUG Print it
// int idx = 0;
// for (QueueEntry qe : queue) {
// Message msg = qe.getMessage();
// while (msg.getPayload() != null) {
// msg = msg.getPayload();
// }
// System.out.println(idx + " "
// + msg.getClass().getSimpleName() + " "
// + msg.toString());
// idx++;
// }
// System.out.println("[AbstractMacLayer] debug output");
// int idx = 0;
// for (QueueEntry qe : queue) {
// Message msg = qe.getMessage();
// while (msg.getPayload() != null) {
// msg = msg.getPayload();
// }
// System.out.println(idx + " "
// + msg.getClass().getSimpleName() + " "
// + msg.toString());
// idx++;
// }
} else {
// still a spot in the queue, add message and notify MAC
queue.add(new QueueEntry(receiver, message));
handleNewQueueEntry();
handleNewQueueEntry();
}
}
}
......
......@@ -27,7 +27,6 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
import de.tud.kom.p2psim.api.churn.ChurnGenerator;
import de.tud.kom.p2psim.api.network.SimNetInterface;
import de.tud.kom.p2psim.api.network.SimNetworkComponent;
import de.tud.kom.p2psim.api.scenario.ConfigurationException;
......@@ -36,7 +35,7 @@ import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.impl.topology.DefaultTopology;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.IAttractionBasedMovementAnalyzer;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.AttractionPointViz;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.IAttractionGenerator;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.IAttractionProvider;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.mapvisualization.IMapVisualization;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.VisualizationInjector;
......@@ -69,7 +68,7 @@ public class TracefileMovementModel implements MovementModel, EventHandler {
protected long timeBetweenMoveOperations;
protected IMapVisualization mapVisualization;
protected IAttractionGenerator attractionGenerator;
protected IAttractionProvider attractionGenerator;
protected AttractionPointViz attractionpointVisualization;
protected boolean initialized = false;
......@@ -106,6 +105,8 @@ public class TracefileMovementModel implements MovementModel, EventHandler {
}
if (attractionpointVisualization != null) {
attractionpointVisualization.setAttractionPoints(new LinkedList<>(attractionGenerator.getAttractionPoints()));
VisualizationInjector.injectComponent(attractionpointVisualization);
}
......@@ -363,7 +364,7 @@ public class TracefileMovementModel implements MovementModel, EventHandler {
this.attractionpointVisualization = viz;
}
public void setIAttractionGenerator(IAttractionGenerator attractionGenerator) {
public void setIAttractionGenerator(IAttractionProvider attractionGenerator) {
if (attractionGenerator == null) {
throw new ConfigurationException(
"AttractionGenerator is missing in ModularMovementModel!");
......
......@@ -21,7 +21,6 @@
package de.tud.kom.p2psim.impl.topology.movement.modularosm;
import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.AttractionPointImpl;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.VisualizationInjector;
import de.tudarmstadt.maki.simonstrator.api.Binder;
......
......@@ -38,7 +38,8 @@ import de.tud.kom.p2psim.impl.simengine.Simulator;
import de.tud.kom.p2psim.impl.topology.DefaultTopology;
import de.tud.kom.p2psim.impl.topology.TopologyFactory;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.AttractionPointViz;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.IAttractionGenerator;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.IAttractionProvider;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.MobileAttractionPoint;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.mapvisualization.IMapVisualization;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.transition.IAttractionAssigmentStrategy;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.transition.IAttractionAssigmentStrategy.AttractionAssignmentListener;
......@@ -104,7 +105,7 @@ public class ModularMovementModel implements MovementModel, EventHandler, Attrac
protected IAttractionAssigmentStrategy attractionAssigment;
protected IAttractionGenerator attractionGenerator;
protected IAttractionProvider attractionProvider;
protected LocalMovementStrategy localMovementStrategy;
......@@ -114,11 +115,11 @@ public class ModularMovementModel implements MovementModel, EventHandler, Attrac
protected AttractionPointViz attractionPointViz;
protected Set<SimLocationActuator> moveableHosts = new LinkedHashSet<SimLocationActuator>();
protected LinkedHashSet<SimLocationActuator> moveableHosts = new LinkedHashSet<SimLocationActuator>();
protected Map<SimLocationActuator, PositionVector> currentTargets = new LinkedHashMap<>();
protected LinkedHashMap<SimLocationActuator, PositionVector> currentTargets = new LinkedHashMap<>();
protected Map<SimLocationActuator, RouteSensorComponent> routeSensorComponents = new LinkedHashMap<>();
protected LinkedHashMap<SimLocationActuator, RouteSensorComponent> routeSensorComponents = new LinkedHashMap<>();
protected boolean initialized = false;
......@@ -175,6 +176,7 @@ public class ModularMovementModel implements MovementModel, EventHandler, Attrac
.setScaleFactor(timeBetweenMoveOperation / (double) Time.SECOND);
attractionAssigment.addAttractionAssignmentListener(this);
attractionAssigment.setAttractionProvider(attractionProvider);
// This adds the mobile hosts (smartphones/users) to the transition
// strategy
......@@ -274,6 +276,12 @@ public class ModularMovementModel implements MovementModel, EventHandler, Attrac
doLocalMovement(component, currentTargets.get(component));
}
for (IAttractionPoint aps : getAttractionPoints()) {
if(aps instanceof MobileAttractionPoint) {
((MobileAttractionPoint) aps).move();
}
}
Event.scheduleWithDelay(timeBetweenMoveOperation, this, null,
EVENT_MOVE);
}
......@@ -358,7 +366,7 @@ public class ModularMovementModel implements MovementModel, EventHandler, Attrac
* === GETTER AND SETTER FUNCTIONS
* =====================================================================================================
*/
public Set<SimLocationActuator> getAllLocationActuators() {
public LinkedHashSet<SimLocationActuator> getAllLocationActuators() {
return moveableHosts;
}
......@@ -373,12 +381,12 @@ public class ModularMovementModel implements MovementModel, EventHandler, Attrac
}
public void setIAttractionGenerator(IAttractionGenerator attractionGenerator) {
if (attractionGenerator == null) {
public void setIAttractionProvider(IAttractionProvider attractionProvider) {
if (attractionProvider == null) {
throw new ConfigurationException(
"AttractionGenerator is missing in ModularMovementModel!");
"AttractionProvider is missing in ModularMovementModel!");
}
this.attractionGenerator = attractionGenerator;
this.attractionProvider = attractionProvider;
}
public void setLocalMovementStrategy(LocalMovementStrategy localMovementStrategy) {
......@@ -418,7 +426,7 @@ public class ModularMovementModel implements MovementModel, EventHandler, Attrac
* @return
*/
public List<IAttractionPoint> getAttractionPoints() {
return new Vector<IAttractionPoint>(IAttractionGenerator.attractionPoints);
return new Vector<IAttractionPoint>(attractionProvider.getAttractionPoints());
}
public void setAttractionPointViz(AttractionPointViz viz) {
......
......@@ -43,7 +43,7 @@ import com.graphhopper.util.shapes.GHPoint3D;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.impl.topology.movement.local.AbstractLocalMovementStrategy;
import de.tud.kom.p2psim.impl.topology.movement.local.RealWorldStreetsMovement;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.IAttractionGenerator;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.IAttractionProvider;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView;
import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.VisualizationInjector;
......@@ -186,20 +186,20 @@ public class ModularMovementModelViz extends JComponent
}
}
g2.setColor(Color.black);
PositionVector p1 = GPSCalculation.transformGPSWindowToOwnWorld(51.813680,8.783510);
PositionVector p2 = GPSCalculation.transformGPSWindowToOwnWorld(51.806795,8.804239);
g2.fillRect(VisualizationInjector.scaleValue(p1.getX()), VisualizationInjector.scaleValue(p1.getX()),
VisualizationInjector.scaleValue(p2.getX()) - VisualizationInjector.scaleValue(p1.getX()),
VisualizationInjector.scaleValue(p2.getY())- VisualizationInjector.scaleValue(p1.getY()));
p1 = GPSCalculation.transformGPSWindowToOwnWorld(51.821036,8.771151);
p2 = GPSCalculation.transformGPSWindowToOwnWorld(51.814987, 8.779090);
g2.fillRect(VisualizationInjector.scaleValue(p1.getX()), VisualizationInjector.scaleValue(p1.getX()),
VisualizationInjector.scaleValue(p2.getX() - p1.getX()),
VisualizationInjector.scaleValue(p2.getY() - p1.getY()));
// g2.setColor(Color.black);
// PositionVector p1 = GPSCalculation.transformGPSWindowToOwnWorld(51.813680,8.783510);
// PositionVector p2 = GPSCalculation.transformGPSWindowToOwnWorld(51.806795,8.804239);
//
// g2.fillRect(VisualizationInjector.scaleValue(p1.getX()), VisualizationInjector.scaleValue(p1.getX()),
// VisualizationInjector.scaleValue(p2.getX()) - VisualizationInjector.scaleValue(p1.getX()),
// VisualizationInjector.scaleValue(p2.getY())- VisualizationInjector.scaleValue(p1.getY()));
//
// p1 = GPSCalculation.transformGPSWindowToOwnWorld(51.821036,8.771151);
// p2 = GPSCalculation.transformGPSWindowToOwnWorld(51.814987, 8.779090);
//
// g2.fillRect(VisualizationInjector.scaleValue(p1.getX()), VisualizationInjector.scaleValue(p1.getX()),
// VisualizationInjector.scaleValue(p2.getX() - p1.getX()),
// VisualizationInjector.scaleValue(p2.getY() - p1.getY()));
......@@ -304,7 +304,7 @@ public class ModularMovementModelViz extends JComponent
{
Composite gc = g2.getComposite();
for (IAttractionPoint aPoint : IAttractionGenerator.attractionPoints) {
for (IAttractionPoint aPoint : movementModel.getAttractionPoints()) {
Point point = ((PositionVector) aPoint).asPoint();
// draw border
g2.setColor(Color.BLACK);
......
......@@ -20,17 +20,13 @@
package de.tud.kom.p2psim.impl.topology.movement.modularosm;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Vector;
import de.tud.kom.p2psim.api.scenario.ConfigurationException;
import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.api.topology.movement.local.LocalMovementStrategy;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.IAttractionGenerator;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.groups.MovementGroupContainer;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.groups.SocialMovementGroup;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.groups.groupencounter.IGroupEncounterBehavior;
......@@ -58,7 +54,7 @@ public class SocialGroupMovementModel extends ModularMovementModel {
protected IGroupFormingBehavior groupFormingBehavior;
protected IGroupEncounterBehavior groupEncounterBehavior;
private Set<SimLocationActuator> singleHosts = new LinkedHashSet<SimLocationActuator>();
private LinkedHashSet<SimLocationActuator> singleHosts = new LinkedHashSet<SimLocationActuator>();
private int numberOfSingleHosts;
......@@ -106,6 +102,7 @@ public class SocialGroupMovementModel extends ModularMovementModel {
.setScaleFactor(timeBetweenMoveOperation / (double) Time.SECOND);
attractionAssigment.addAttractionAssignmentListener(this);
attractionAssigment.setAttractionProvider(attractionProvider);
// This adds the mobile hosts (smartphones/users) to the transition
// strategy
......@@ -191,6 +188,9 @@ public class SocialGroupMovementModel extends ModularMovementModel {
}
// TODO Move each group
Event.scheduleWithDelay(timeBetweenMoveOperation, this, null, EVENT_MOVE);
}
......@@ -246,7 +246,20 @@ public class SocialGroupMovementModel extends ModularMovementModel {
Monitor.getOrNull(ISocialGroupMovementAnalyzer.class).onGroupMovesToAttractionPoint(group);
}
doLocalMovement(host, destination);
doLocalMovement(host, destination);
PositionVector leaderPos = host.getRealPosition();
LinkedHashSet<SimLocationActuator> groupMembers = groupContainer.getGroupMembers(host);
groupMembers.remove(host); // remove leader
for (SimLocationActuator groupMember : groupMembers) {
// Assign small offset to the host depending on the leaders position.
PositionVector offset = new PositionVector(rand.nextDouble() * LEADER_GROUP_DISTANCE, rand.nextDouble() * LEADER_GROUP_DISTANCE);
PositionVector newPos = leaderPos.plus(offset);
// Update location of host, which will be around the leaders location.
groupMember.updateCurrentLocation(newPos);
}
}
else {
// inform analyzer of waiting group
......@@ -255,10 +268,6 @@ public class SocialGroupMovementModel extends ModularMovementModel {
}
}
}
else {
// while other nodes just follow the group leader
followLeader(host);
}
}
}
......@@ -382,11 +391,11 @@ public class SocialGroupMovementModel extends ModularMovementModel {
this.numberOfSingleHosts = numberOfSingleHosts;
}
public Set<SimLocationActuator> getSingleHosts(){
public LinkedHashSet<SimLocationActuator> getSingleHosts(){
return singleHosts;
}
public Map<SimLocationActuator, PositionVector> getCurrentTargets(){
public LinkedHashMap<SimLocationActuator, PositionVector> getCurrentTargets(){
return currentTargets;
}
}
......@@ -22,32 +22,48 @@ package de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction;
import java.util.LinkedList;
import java.util.List;
import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tud.kom.p2psim.impl.util.oracle.GlobalOracle;
import de.tudarmstadt.maki.simonstrator.api.Binder;
import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Monitor.Level;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.IAttractionPoint;
/**
* Interface for {@link IAttractionPoint} generators. Will generate a given amount of attraction points.
*
* @author Christoph Muenker, Julian Zobel
* @version 1.1, 09 2018
*/
public interface IAttractionGenerator {
static LinkedList<IAttractionPoint> attractionPoints = new LinkedList<>();
public class AbstractAttractionProvider implements IAttractionProvider {
public List<IAttractionPoint> getAttractionPoints();
private LinkedList<AttractionPoint> attractionPoints = new LinkedList<>();
protected PositionVector worldDimension;
public AbstractAttractionProvider() {
this.worldDimension = Binder.getComponentOrNull(Topology.class).getWorldDimensions();
}
public LinkedList<AttractionPoint> getAttractionPoints() {
return new LinkedList<AttractionPoint>(attractionPoints);
}
protected void clearAttractionPoints() {
attractionPoints.clear();
}
protected boolean hasAttractionPoint(AttractionPoint ap) {
return attractionPoints.contains(ap);
}
/**
* Remove an {@link IAttractionPoint} from the list
* @param ap
*/
default void removeAttractionPoint(IAttractionPoint ap) {
public void removeAttractionPoint(AttractionPoint ap) {
if(Monitor.hasAnalyzer(AttractionPointMonitor.class)) {
Monitor.getOrNull(AttractionPointMonitor.class).removedAttractionPoint(ap);
}
GlobalOracle.removeAttractionPoint(ap);
attractionPoints.remove(ap);
}
......@@ -55,18 +71,19 @@ public interface IAttractionGenerator {
* Add an {@link IAttractionPoint} to the list
* @param ap
*/
default void addAttractionPoint(IAttractionPoint ap) {
public void addAttractionPoint(AttractionPoint ap) {
if(ap == null) {
Monitor.log(IAttractionGenerator.class, Level.ERROR, "IAttractionGenerator: Tried to add NULL as Attraction Point");
Monitor.log(IAttractionProvider.class, Level.ERROR, "IAttractionGenerator: Tried to add NULL as Attraction Point");
return;
}
}
if(Monitor.hasAnalyzer(AttractionPointMonitor.class)) {
Monitor.getOrNull(AttractionPointMonitor.class).addedAttractionPoint(ap);
}
GlobalOracle.addAttractionPoint(ap);
attractionPoints.add(ap);
}
}
......@@ -21,15 +21,11 @@
package de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Random;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.IAttractionBasedMovementAnalyzer;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.ISocialGroupMovementAnalyzer;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.IAttractionPoint;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
/**
* In the current implementation, {@link IAttractionPoint}s cannot move anymore.
......@@ -41,17 +37,21 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.IAttractio
* @version 1.1, 26.10.2018 - since the class was very similar to {@link BasicAttractionPoint}, made this class an extension
* @version 1.2, 24.01.2020 - added pause time interval, weight, and radius exclusively to this class, because {@link BasicAttractionPoint} should be just a named point.
*/
public class AttractionPointImpl extends BasicAttractionPoint {
protected static Random rnd = Randoms.getRandom(IAttractionPoint.class);
protected static Map<String, AttractionPointImpl> instances = new LinkedHashMap<>();
public class AttractionPoint extends BasicAttractionPoint {
protected static LinkedHashMap<String, AttractionPoint> instances = new LinkedHashMap<>();
protected long pauseTimeMin = -1;
protected long pauseTimeMax = -1;
protected double weight = 0;
protected double radius = 0;
protected double area = 1;
public AttractionPointImpl(String name, PositionVector posVec) {
@XMLConfigurableConstructor({ "name", "x", "y" })
public AttractionPoint(String name, double x, double y) {
this(name, new PositionVector(x, y));
}
public AttractionPoint(String name, PositionVector posVec) {
super(name, posVec);
if (instances.containsKey(name)) {
......@@ -64,7 +64,7 @@ public class AttractionPointImpl extends BasicAttractionPoint {
}
}
public AttractionPointImpl(String name, PositionVector posVec, double weight, double radius, long pauseTimeMin, long pauseTimeMax) {
public AttractionPoint(String name, PositionVector posVec, double weight, double radius, long pauseTimeMin, long pauseTimeMax) {
this(name, posVec);
assert weight >= 0 && weight <= 1.0;
......@@ -72,12 +72,16 @@ public class AttractionPointImpl extends BasicAttractionPoint {
this.weight = weight;
this.radius = radius;
this.setPauseTime(pauseTimeMin, pauseTimeMax);
this.setPauseTime(pauseTimeMin, pauseTimeMax);
if(radius > 0) {
this.area = Math.PI * Math.pow(radius, 2);
}
}
@Override
public IAttractionPoint clone(String newName) {
return new AttractionPointImpl(name, this, weight, radius, pauseTimeMin, pauseTimeMax);
return new AttractionPoint(name, this, weight, radius, pauseTimeMin, pauseTimeMax);
}
@Override
......@@ -100,7 +104,7 @@ public class AttractionPointImpl extends BasicAttractionPoint {
return true;
if (getClass() != obj.getClass())
return false;
AttractionPointImpl other = (AttractionPointImpl) obj;
AttractionPoint other = (AttractionPoint) obj;
if (name == null) {
if (other.name != null)
return false;
......@@ -136,6 +140,10 @@ public class AttractionPointImpl extends BasicAttractionPoint {
@Override
public void setRadius(double radius) {
this.radius = radius;
if(radius > 0) {
this.area = Math.PI * Math.pow(radius, 2);
}
}
@Override
......@@ -180,4 +188,8 @@ public class AttractionPointImpl extends BasicAttractionPoint {
public String toString() {
return getName() + " (" + getX() + ", " + getY() + ")" + " <" + getRadius() + "> ";
}
public double getArea() {
return area;
}
}
......@@ -56,10 +56,15 @@ public class AttractionPointViz extends JComponent
public static LinkedList<LinkedList<SimHost>> clusters = new LinkedList<LinkedList<SimHost>>();
public static LinkedList<Color> colors = new LinkedList<Color>();
public LinkedList<IAttractionPoint> aps;
public AttractionPointViz() {
init();
}
public void setAttractionPoints(LinkedList<IAttractionPoint> aps) {
this.aps = aps;
}
protected void init() {
setBounds(0, 0, VisualizationInjector.getWorldX(),
......@@ -141,9 +146,13 @@ public class AttractionPointViz extends JComponent
*/
protected void drawAttractionPoints(Graphics2D g2)
{
if(aps == null || aps.size() == 0) {
return;
}
Composite gc = g2.getComposite();
for (IAttractionPoint aPoint : IAttractionGenerator.attractionPoints) {
for (IAttractionPoint aPoint : aps) {
Point point = ((PositionVector) aPoint).asPoint();
// draw border
g2.setColor(Color.BLACK);
......
......@@ -19,8 +19,6 @@
*/
package de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction;
import java.util.List;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.IAttractionPoint;
/**
* For simple scenarios: add attraction points by specifying a coordinate.
......@@ -28,16 +26,10 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.IAttractio
* @author Bjoern Richerzhagen
* @version 1.0, Dec 11, 2015
*/
public class ConfigAttractionGenerator implements IAttractionGenerator {
public class ConfigAttractionGenerator extends AbstractAttractionProvider {
@Override
public List<IAttractionPoint> getAttractionPoints() {
return attractionPoints;
}
public void setAttractionPoint(IAttractionPoint point) {
attractionPoints.add(point);
public void setAttractionPoint(AttractionPoint point) {
addAttractionPoint(point);
}
}
......@@ -20,18 +20,8 @@
package de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import de.tud.kom.p2psim.api.scenario.ConfigurationException;
import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.Binder;
import de.tudarmstadt.maki.simonstrator.api.Event;
import de.tudarmstadt.maki.simonstrator.api.EventHandler;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.IAttractionPoint;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
/**
* Implementation of the interface {@link AttractionGenerator}.
......@@ -40,43 +30,41 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
* @author Julian Zobel
* @version 1.0, April 2019
*/
public class ConfigDynamicAttractionGenerator implements IAttractionGenerator {
public class ConfigDynamicAttractionGenerator extends AbstractAttractionProvider {
private LinkedList<TemporalAttractionPoint> allAPs = new LinkedList<>();
@Override
public List<IAttractionPoint> getAttractionPoints() {
return attractionPoints;
}
//private LinkedList<TemporalAttractionPoint> temporalAttractionPoints = new LinkedList<>();
public void setAttractionPoint(TemporalAttractionPoint ap) {
allAPs.add(ap);
Event.scheduleWithDelay(ap.getPlacementTime(), new EventHandler() {
@Override
public void eventOccurred(Object content, int type) {
placeAP(ap);
}
}, null, 0);
public void setAttractionPoint(AttractionPoint ap) {
addAttractionPoint(ap);
}
private void placeAP(TemporalAttractionPoint ap) {
attractionPoints.add(ap);
public void setTemporalAttractionPoint(TemporalAttractionPoint ap) {
//temporalAttractionPoints.add(ap);
if(ap.getPlacementTime() == 0) {
placeAP(ap);
}
else {
Event.scheduleWithDelay(ap.getPlacementTime(), new EventHandler() {
@Override
public void eventOccurred(Object content, int type) {
placeAP(ap);
}
}, null, 0);
}
}
void placeAP(TemporalAttractionPoint ap) {
addAttractionPoint(ap);
Event.scheduleWithDelay(ap.getRemovalTime(), new EventHandler() {
@Override
public void eventOccurred(Object content, int type) {
removeAP(ap);
removeAttractionPoint(ap);
}
}, null, 0);
}
private void removeAP(TemporalAttractionPoint ap) {
attractionPoints.remove(ap);
}
}
......@@ -39,9 +39,7 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
* @author Nils Richerzhagen
* @version 1.0, 16.07.2014
*/
public class CsvAttractionGenerator implements IAttractionGenerator {
private PositionVector worldDimensions;
public class CsvAttractionGenerator extends AbstractAttractionProvider {
private String file;
......@@ -55,8 +53,7 @@ public class CsvAttractionGenerator implements IAttractionGenerator {
*/
@XMLConfigurableConstructor({ "placementFile" })
public CsvAttractionGenerator(String placementFile) {
this.worldDimensions = Binder.getComponentOrNull(Topology.class)
.getWorldDimensions();
super();
this.file = placementFile;
readData();
......@@ -67,11 +64,11 @@ public class CsvAttractionGenerator implements IAttractionGenerator {
}
@Override
public List<IAttractionPoint> getAttractionPoints() {
if (attractionPoints == null) {
public LinkedList<AttractionPoint> getAttractionPoints() {
if (super.getAttractionPoints().isEmpty()) {
readData();
}
return attractionPoints;
return super.getAttractionPoints();
}
private void readData() {
......@@ -91,14 +88,14 @@ public class CsvAttractionGenerator implements IAttractionGenerator {
Double x = Double.parseDouble(parts[0]);
Double y = Double.parseDouble(parts[1]);
if (x > worldDimensions.getX()
|| y > worldDimensions.getY() || x < 0
if (x > worldDimension.getX()
|| y > worldDimension.getY() || x < 0
|| y < 0) {
System.err.println("Skipped entry " + x + ";"
+ y);
continue;
}
IAttractionPoint ap = new AttractionPointImpl("AP"+i, new PositionVector(x, y));
AttractionPoint ap = new AttractionPoint("AP"+i, new PositionVector(x, y));
ap.setRadius(radius);
addAttractionPoint(ap);
......@@ -117,15 +114,15 @@ public class CsvAttractionGenerator implements IAttractionGenerator {
Double y = Double.parseDouble(parts[1]);
Double r = Double.parseDouble(parts[2]);
if (x > worldDimensions.getX()
|| y > worldDimensions.getY() || x < 0
if (x > worldDimension.getX()
|| y > worldDimension.getY() || x < 0
|| y < 0) {
System.err.println("Skipped entry " + x + ";"
+ y);
continue;
}
IAttractionPoint ap = new AttractionPointImpl("AP"+i, new PositionVector(x, y));
AttractionPoint ap = new AttractionPoint("AP"+i, new PositionVector(x, y));
ap.setRadius(r);
addAttractionPoint(ap);
......
......@@ -20,43 +20,34 @@
package de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction;
import java.util.LinkedList;
import java.util.List;
import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.Binder;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.IAttractionPoint;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
/**
* Implementation of the interface {@link AttractionGenerator}.
*
* Generates the given number of {@link IAttractionPoint}s and sets the
* position randomly within the world dimensions.
* Attraction Generator, providing 4 equidistant attraction points, i.e., in a square
*
* @author Julian Zobel
* @version 1.0, Nov 2018
*/
public class EquidistantSquareAttractionGenerator implements IAttractionGenerator {
public class EquidistantSquareAttractionGenerator extends AbstractAttractionProvider {
private PositionVector worldDimension;
private double squareSize;
@XMLConfigurableConstructor({ "squareSize" })
public EquidistantSquareAttractionGenerator(double squareSize) {
this.worldDimension = Binder.getComponentOrNull(Topology.class)
.getWorldDimensions();
this.squareSize = squareSize;
createAttractionPoints();
}
@Override
public List<IAttractionPoint> getAttractionPoints() {
if(attractionPoints.isEmpty())
public LinkedList<AttractionPoint> getAttractionPoints() {
if(super.getAttractionPoints().isEmpty())
createAttractionPoints();
return attractionPoints;
return super.getAttractionPoints();
}
private void createAttractionPoints() {
......@@ -64,21 +55,17 @@ public class EquidistantSquareAttractionGenerator implements IAttractionGenerato
double x = worldDimension.getX() / 2;
double y = worldDimension.getY() / 2;
PositionVector p1 = new PositionVector(x - squareSize, y - squareSize);
IAttractionPoint ap1 = new AttractionPointImpl("AP1", p1);
attractionPoints.add(ap1);
PositionVector p1 = new PositionVector(x - squareSize, y - squareSize);
this.addAttractionPoint(new AttractionPoint("AP1", p1));
PositionVector p2 = new PositionVector(x - squareSize, y + squareSize);
IAttractionPoint ap2 = new AttractionPointImpl("AP2", p2);
attractionPoints.add(ap2);
this.addAttractionPoint(new AttractionPoint("AP2", p2));
PositionVector p3 = new PositionVector(x + squareSize, y - squareSize);
IAttractionPoint ap3 = new AttractionPointImpl("AP3", p3);
attractionPoints.add(ap3);
this.addAttractionPoint(new AttractionPoint("AP3", p3));
PositionVector p4 = new PositionVector(x + squareSize, y + squareSize);
IAttractionPoint ap4 = new AttractionPointImpl("AP4", p4);
attractionPoints.add(ap4);
this.addAttractionPoint(new AttractionPoint("AP4", p4));
}
......
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction;
import java.util.List;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.IAttractionPoint;
/**
* Interface for {@link IAttractionPoint} generators. Will generate a given amount of attraction points.
*
* @author Christoph Muenker, Julian Zobel
* @version 1.1, 09 2018
*/
public interface IAttractionProvider {
public List<AttractionPoint> getAttractionPoints();
}
\ No newline at end of file
......@@ -23,16 +23,13 @@ package de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import org.apache.commons.io.IOUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.GPSCalculation;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.Binder;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.IAttractionPoint;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
/**
......@@ -52,115 +49,117 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
*
*
*/
public class JSONAttractionGenerator implements IAttractionGenerator {
public class JSONAttractionGenerator extends AbstractAttractionProvider {
private int numberOfAttractionPoints;
private String placementJsonFile;
protected int numberOfAttractionPoints;
protected String placementJsonFile = "";
private double maximumRadius = -1; // Values >= 0, or -1 if radius taken from file
protected double maximumRadius = -1; // Values >= 0, or -1 if radius taken from file
/**
* You have to set a json-file, which has set some POIs
* 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
*/
@XMLConfigurableConstructor({"numberOfAttractionPoints"})
public JSONAttractionGenerator(int numberOfAttractionPoints) {
@XMLConfigurableConstructor({"numberOfAttractionPoints", "maximumRadius", "placementJsonFile"})
public JSONAttractionGenerator(int numberOfAttractionPoints, double maximumRadius, String placementJsonFile) {
this.numberOfAttractionPoints = numberOfAttractionPoints;
this.maximumRadius = maximumRadius;
this.placementJsonFile = placementJsonFile;
createAttractionPoints();
}
@Override
public List<IAttractionPoint> getAttractionPoints() {
if(attractionPoints.size() == 0) {
String poiString = "";
JSONArray allPOI = null;
FileInputStream inputStream;
try {
inputStream = new FileInputStream(placementJsonFile);
poiString = IOUtils.toString(inputStream);
JSONObject poiData = new JSONObject(poiString);
allPOI = poiData.getJSONArray("elements");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
if(allPOI != null) {
int limit = 0;
if(numberOfAttractionPoints == 0 || numberOfAttractionPoints > allPOI.length()) {
limit = allPOI.length();
}
else {
limit = numberOfAttractionPoints;
}
for(int i = 0; i < limit; i++) {
try {
String barname = allPOI.getJSONObject(i).getJSONObject("tags").getString("name");
double lat = allPOI.getJSONObject(i).getDouble("lat");
double lon = allPOI.getJSONObject(i).getDouble("lon");
AttractionPointImpl ap;
// check that the point is within the simulation boundaries
if(GPSCalculation.isWithinGPSBoundaries(lat, lon)) {
// initialize the attraction point with basic information, will be filled now...
ap = new AttractionPointImpl(barname, GPSCalculation.transformGPSWindowToOwnWorld(lat, lon));
attractionPoints.add(ap);
// the following setters are allowed to fail
// AP weight
if(allPOI.getJSONObject(i).getJSONObject("tags").has("weight")) {
ap.setWeight(allPOI.getJSONObject(i).getJSONObject("tags").getDouble("weight"));
}
// AP radius
if(allPOI.getJSONObject(i).getJSONObject("tags").has("radius")) {
double radius = allPOI.getJSONObject(i).getJSONObject("tags").getDouble("radius");
if(maximumRadius == -1) {
ap.setRadius(radius);
}
else {
ap.setRadius(Math.min(maximumRadius, radius));
}
}
if(allPOI.getJSONObject(i).getJSONObject("tags").has("pauseTimeMin") && allPOI.getJSONObject(i).getJSONObject("tags").has("pauseTimeMax")) {
ap.setPauseTime( allPOI.getJSONObject(i).getJSONObject("tags").getLong("pauseTimeMin"), allPOI.getJSONObject(i).getJSONObject("tags").getLong("pauseTimeMax"));
}
System.out.println(ap);
}
}
catch (JSONException e) {
//This bar had no name defined, so there was an error. Not so bad
System.out.println(e);
}
}
}
public LinkedList<AttractionPoint> getAttractionPoints() {
if(super.getAttractionPoints().size() == 0) {
createAttractionPoints();
}
return attractionPoints;
return super.getAttractionPoints();
}
protected JSONArray getPOIArray() {
assert !placementJsonFile.equals("");
public void setPlacementJsonFile(String placementJsonFile) {
this.placementJsonFile = placementJsonFile;
//System.out.println(placementJsonFile);
if(attractionPoints.isEmpty()) {
this.getAttractionPoints();
String poiString = "";
JSONArray allPOI = null;
FileInputStream inputStream;
try {
inputStream = new FileInputStream(placementJsonFile);
poiString = IOUtils.toString(inputStream);
JSONObject poiData = new JSONObject(poiString);
allPOI = poiData.getJSONArray("elements");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return allPOI;
}
/**
* Set a maximum radius that an attraction point can have. Minimum is 10 meters.
* @param radius
*/
public void setMaximumRadius(double radius) {
this.maximumRadius = radius;
}
private void createAttractionPoints() {
assert super.getAttractionPoints().size() == 0;
JSONArray allPOI = getPOIArray();
if(allPOI == null) {
throw new UnsupportedOperationException("[JSONAttractionGenerator] POI Data Array cannot be NULL.");
}
int limit = 0;
if(numberOfAttractionPoints == 0 || numberOfAttractionPoints > allPOI.length()) {
limit = allPOI.length();
}
else {
limit = numberOfAttractionPoints;
}
for(int i = 0; i < limit; i++) {
try {
String barname = allPOI.getJSONObject(i).getJSONObject("tags").getString("name");
double lat = allPOI.getJSONObject(i).getDouble("lat");
double lon = allPOI.getJSONObject(i).getDouble("lon");
AttractionPoint ap;
// check that the point is within the simulation boundaries
if(GPSCalculation.isWithinGPSBoundaries(lat, lon)) {
// initialize the attraction point with basic information, will be filled now...
ap = new AttractionPoint(barname, GPSCalculation.transformGPSWindowToOwnWorld(lat, lon));
// the following setters are allowed to fail
// AP weight
if(allPOI.getJSONObject(i).getJSONObject("tags").has("weight")) {
ap.setWeight(allPOI.getJSONObject(i).getJSONObject("tags").getDouble("weight"));
}
// AP radius
if(allPOI.getJSONObject(i).getJSONObject("tags").has("radius")) {
double radius = allPOI.getJSONObject(i).getJSONObject("tags").getDouble("radius");
if(maximumRadius == -1) {
ap.setRadius(radius);
}
else {
ap.setRadius(Math.min(maximumRadius, radius));
}
}
if(allPOI.getJSONObject(i).getJSONObject("tags").has("pauseTimeMin") && allPOI.getJSONObject(i).getJSONObject("tags").has("pauseTimeMax")) {
ap.setPauseTime( allPOI.getJSONObject(i).getJSONObject("tags").getLong("pauseTimeMin"), allPOI.getJSONObject(i).getJSONObject("tags").getLong("pauseTimeMax"));
}
addAttractionPoint(ap);
}
}
catch (JSONException e) {
//This bar had no name defined, so there was an error. Not so bad
System.out.println(e);
}
}
}
}
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction;
import java.util.LinkedList;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
public class MobileAttractionPoint extends AttractionPoint {
private LinkedList<PositionVector> waypoints;
private double speed = 0.5;
private boolean move = false;
private long pausetime = Time.MINUTE * 10;
private long timer = 0L;
@XMLConfigurableConstructor({ "name", "x", "y" })
public MobileAttractionPoint(String name, double x, double y) {
super(name, x, y);
waypoints = new LinkedList<PositionVector>();
waypoints.add(new PositionVector(250,250));
waypoints.add(new PositionVector(250,400));
waypoints.add(new PositionVector(750,400));
waypoints.add(new PositionVector(750,250));
}
public void move() {
if(move) {
PositionVector destination = waypoints.getFirst();
if (destination.distanceTo(this) > speed) {
this.set(this.moveStep(destination, speed));
}
else {
this.set(destination);
waypoints.add(waypoints.removeFirst());
timer = 0;
move = false;
}
}
else {
timer += Time.SECOND;
if(timer >= pausetime) {
timer = 0;
move = true;
}
}
}
}
......@@ -21,26 +21,18 @@
package de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.LinkedList;
import java.util.List;
import org.apache.commons.io.IOUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.GPSCalculation;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.Binder;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.IAttractionPoint;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
/**
* Generates attraction points out of real data from osm
......@@ -49,150 +41,58 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.IAttractio
* @author Martin Hellwig
* @version 1.0, 02.07.2015
*/
public class OnlineJSONAttractionGenerator implements IAttractionGenerator {
private PositionVector worldDimensions;
public class OnlineJSONAttractionGenerator extends JSONAttractionGenerator {
private List<IAttractionPoint> attractionPoints;
private int maxNumberOfAttractionPoints;
private String placementJsonFile;
private String placementJsonPath;
private String amenity;
private double latLeft; //Values from -90 to 90; always smaller than latRight
private double latRight; //Values from -90 to 90
private double lonLeft; //Values from -180 to 180; Always smaller than lonRight
private double lonRight; //Values from -180 to 180
public OnlineJSONAttractionGenerator() {
this.worldDimensions = Binder.getComponentOrNull(Topology.class)
.getWorldDimensions();
attractionPoints = new LinkedList<IAttractionPoint>();
latLeft = GPSCalculation.getLatLower();
latRight = GPSCalculation.getLatUpper();
lonLeft = GPSCalculation.getLonLeft();
lonRight = GPSCalculation.getLonRight();
}
@XMLConfigurableConstructor({"numberOfAttractionPoints", "maximumRadius", "placementJsonPath", "amenity"})
public OnlineJSONAttractionGenerator(int numberOfAttractionPoints, double maximumRadius,
String placementJsonPath, String amenity) {
/**
* Projects the gps coordinates in the given gps window to the world-coordinates given in world-dimensions
* @param lat
* @param lon
* @return The projected position in world-dimensions
*/
private PositionVector transformGPSWindowToOwnWorld(double lat, double lon) {
double x = worldDimensions.getX() * (lon - lonLeft)/(lonRight - lonLeft);
//Invert the y value, because in Java Swing we start drawing in the upper left corner instead in the lower left one
double y = worldDimensions.getY() - worldDimensions.getY() * (lat - latLeft)/(latRight - latLeft);
return new PositionVector(x, y);
}
public void setNumberOfAttractionPoints(int numberOfAttractionPoints) {
this.maxNumberOfAttractionPoints = numberOfAttractionPoints;
}
super(numberOfAttractionPoints, maximumRadius, placementJsonPath +
"pois" +
GPSCalculation.getLatCenter() +
GPSCalculation.getLonCenter() +
GPSCalculation.getZoom() +
amenity + ".json");
this.amenity = amenity;
}
@Override
public List<IAttractionPoint> getAttractionPoints() {
if(attractionPoints.size() == 0) {
placementJsonFile = placementJsonPath +
"pois" +
GPSCalculation.getLatCenter() +
GPSCalculation.getLonCenter() +
GPSCalculation.getZoom() +
amenity + ".json";
//Check if the file with same properties (same location) already exists
File f = new File(placementJsonFile);
if(!f.exists()) {
String poiString = "";
JSONArray allPOI = null;
InputStream in;
try {
in = new URL( "http://overpass-api.de/api/interpreter?data=%5Bout:json%5D;node%5Bamenity=" + amenity + "%5D%28" + latLeft + "%2C" + lonLeft + "%2C" + latRight + "%2C" + lonRight + "%29%3Bout%3B" ).openStream();
poiString = IOUtils.toString(in);
//Save the json data in file
PrintWriter out = new PrintWriter(placementJsonFile);
out.print(poiString);
out.close();
JSONObject poiData = new JSONObject(poiString);
allPOI = poiData.getJSONArray("elements");
} catch (JSONException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(allPOI != null) {
for(int i = 0; i < allPOI.length(); i++) {
try {
String barname = allPOI.getJSONObject(i).getJSONObject("tags").getString("name");
double lat = allPOI.getJSONObject(i).getDouble("lat");
double lon = allPOI.getJSONObject(i).getDouble("lon");
if(lat > latLeft && lat < latRight &&
lon > lonLeft && lon < lonRight) {
attractionPoints.add(new AttractionPointImpl(barname, transformGPSWindowToOwnWorld(lat, lon)));
}
}
catch (JSONException e) {
//This bar had no name defined, so there was an error. Not so bad
}
}
}
protected JSONArray getPOIArray() {
//Check if the file with same properties (same location) already exists
File f = new File(placementJsonFile);
if(!f.exists()) {
String poiString = "";
JSONArray allPOI = null;
InputStream in;
try {
in = new URL( "http://overpass-api.de/api/interpreter?data=%5Bout:json%5D;node%5Bamenity=" + amenity + "%5D%28"
+ GPSCalculation.getLatUpper() + "%2C" + GPSCalculation.getLonLeft() + "%2C"
+ GPSCalculation.getLatLower() + "%2C" + GPSCalculation.getLonRight() + "%29%3Bout%3B" ).openStream();
poiString = IOUtils.toString(in);
//Save the json data in file
PrintWriter out = new PrintWriter(placementJsonFile);
out.print(poiString);
out.close();
JSONObject poiData = new JSONObject(poiString);
allPOI = poiData.getJSONArray("elements");
} catch (JSONException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
else {
//File already exists, now we have to parse this file
String poiString = "";
JSONArray allPOI = null;
FileInputStream inputStream;
try {
inputStream = new FileInputStream(placementJsonFile);
poiString = IOUtils.toString(inputStream);
JSONObject poiData = new JSONObject(poiString);
allPOI = poiData.getJSONArray("elements");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
if(allPOI != null) {
for(int i = 0; i < allPOI.length(); i++) {
try {
String barname = allPOI.getJSONObject(i).getJSONObject("tags").getString("name");
double lat = allPOI.getJSONObject(i).getDouble("lat");
double lon = allPOI.getJSONObject(i).getDouble("lon");
attractionPoints.add(new AttractionPointImpl(barname, transformGPSWindowToOwnWorld(lat, lon)));
}
catch (JSONException e) {
//This bar had no name defined, so there was an error. Not so bad
}
}
}
}
}
if(maxNumberOfAttractionPoints == 0) maxNumberOfAttractionPoints = Integer.MAX_VALUE;
List<IAttractionPoint> result = new LinkedList<IAttractionPoint>();
for (int i = 0; (i < attractionPoints.size() && i < maxNumberOfAttractionPoints); i++) {
result.add(attractionPoints.get(i));
return allPOI;
}
return result;
}
public void setAmenity(String amenity) {
this.amenity = amenity;
}
public void setPlacementJsonPath(String placementJsonPath) {
this.placementJsonPath = placementJsonPath;
else {
return super.getPOIArray();
}
}
}
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