Skip to content

Commit

Permalink
Set routing instantiator input as seconds
Browse files Browse the repository at this point in the history
Plus, better code and UI documentation
  • Loading branch information
inigo-cobian committed Nov 28, 2024
1 parent a9bf5a0 commit 1dcd9a7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public class RoutingRelationshipInstantiator extends AbstractContextualizer impl
private String sourceArtifact = null;
private String targetArtifact = null;

private Double timeThreshold = null;
private Double distanceThreshold = null;
private Double timeThresholdInSeconds = null;
private Double distanceThresholdInKilometers = null;

private TransportType transportType = TransportType.Auto;
private GeometryCollapser geometryCollapser = GeometryCollapser.Centroid;
Expand Down Expand Up @@ -91,8 +91,8 @@ public RoutingRelationshipInstantiator(IParameters<String> parameters, IContextu
this.scope = scope;
this.sourceArtifact = parameters.get("source", String.class);
this.targetArtifact = parameters.get("target", String.class);
this.timeThreshold = parameters.get("time_limit", Double.class);
this.distanceThreshold = parameters.get("distance_limit", Double.class);
this.timeThresholdInSeconds = parameters.get("time_limit", Double.class);
this.distanceThresholdInKilometers = parameters.get("distance_limit", Double.class);

if (parameters.containsKey("transport")) {
this.transportType = TransportType.fromValue(Utils.removePrefix(parameters.get("transport", String.class)));
Expand Down Expand Up @@ -201,7 +201,7 @@ private boolean connectSourceToTarget(IArtifact source, IArtifact target) {

private Geometry getIsochrone(IDirectObservation node, boolean isReverse) {
double[] coordinates = Valhalla.getCoordinates(node, geometryCollapser);
String isochroneRequest = Valhalla.buildValhallaIsochroneInput(coordinates, transportType.getType(), "time", timeThreshold, isReverse);
String isochroneRequest = Valhalla.buildValhallaIsochroneInput(coordinates, transportType.getType(), "time", timeThresholdInSeconds, isReverse);
return valhalla.isochrone(isochroneRequest);
}

Expand All @@ -218,7 +218,7 @@ private void connectSourcesToTargets(IContextualizationScope context, List<IObse
}

List<IObservation> inRangeNodes = secondNodes;
if (timeThreshold != null) {
if (timeThresholdInSeconds != null) {
// Filter those nodes that are not inside the range
inRangeNodes = filterNodesInRange((IDirectObservation) node1, secondNodes, useReverseIsochrones);
}
Expand Down Expand Up @@ -248,9 +248,8 @@ private List<IObservation> filterNodesInRange(IDirectObservation sourceNode, Lis
}

private boolean isRouteInsideTheThresholds(Map<String, Object> stats) {
// We define the time using minutes, but receive the stats in seconds
return (timeThreshold == null || ((Double) stats.get("time") < timeThreshold * 60))
&& (distanceThreshold == null || ((Double) stats.get("length") < distanceThreshold));
return (timeThresholdInSeconds == null || ((Double) stats.get("time") < timeThresholdInSeconds))
&& (distanceThresholdInKilometers == null || ((Double) stats.get("length") < distanceThresholdInKilometers));
}

private List<IObjectArtifact> instantiateRelationships(IObservable observable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export object connect

export object route
"Connects subjects through routes computed along a specified spatial configuration. Relationships are only
created if a route exists."
created if a route exists. Output values are given in kilometers and seconds."
{
optional import object source
"Semantics for the type of the subjects used as source for the relationships"
Expand Down

0 comments on commit 1dcd9a7

Please sign in to comment.