Skip to content

Commit

Permalink
VGF-149 Add trips in past message
Browse files Browse the repository at this point in the history
  • Loading branch information
sdjacobs committed Feb 6, 2018
1 parent 78dd03e commit e3a32da
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 9 deletions.
Expand Up @@ -95,4 +95,8 @@ private void computeSummary() {
renderingTime = finishedRendering - finishedCalculating;
totalTime = finishedRendering - startedCalculating;
}

public long getStartedCalculating() {
return startedCalculating;
}
}
Expand Up @@ -35,6 +35,7 @@ the License, or (props, at your option) any later version.
import org.opentripplanner.routing.graph.Vertex;
import org.opentripplanner.routing.location.TemporaryStreetLocation;
import org.opentripplanner.routing.services.FareService;
import org.opentripplanner.routing.services.notes.PlanNotesService;
import org.opentripplanner.routing.spt.GraphPath;
import org.opentripplanner.routing.trippattern.TripTimes;
import org.opentripplanner.routing.vertextype.*;
Expand Down Expand Up @@ -125,8 +126,8 @@ public static TripPlan generatePlan(List<GraphPath> paths, RoutingRequest reques
}
}

if (request.rctx.graph.outOfAreaNotesService != null) {
addOutOfAreaWarnings(plan, request, requestedLocale);
for (PlanNotesService svc : request.rctx.graph.planNotesServices) {
addPlanNotes(svc, plan, request, requestedLocale);
}

request.rctx.debugOutput.finishedRendering();
Expand Down Expand Up @@ -1164,8 +1165,8 @@ private static List<P2<Double>> encodeElevationProfile(Edge edge, double distanc
return out;
}

private static void addOutOfAreaWarnings(TripPlan plan, RoutingRequest request, Locale locale) {
for (Alert alert : request.rctx.graph.outOfAreaNotesService.getAlerts(request)) {
private static void addPlanNotes(PlanNotesService svc, TripPlan plan, RoutingRequest request, Locale locale) {
for (Alert alert : svc.getAlerts(request, plan)) {
plan.addAlert(alert, locale);
}
}
Expand Down
Expand Up @@ -24,6 +24,7 @@ the License, or (at your option) any later version.
import org.opentripplanner.graph_builder.module.PruneFloatingIslands;
import org.opentripplanner.graph_builder.module.StreetLinkerModule;
import org.opentripplanner.graph_builder.module.TransitToTaggedStopsModule;
import org.opentripplanner.graph_builder.module.TripPlanInPastModule;
import org.opentripplanner.graph_builder.module.map.BusRouteStreetMatcher;
import org.opentripplanner.graph_builder.module.ned.DegreeGridNEDTileSource;
import org.opentripplanner.graph_builder.module.ned.ElevationModule;
Expand Down Expand Up @@ -329,6 +330,9 @@ public static GraphBuilder forDirectory(CommandLineParameters params, File dir)
if (boundaryFile != null) {
graphBuilder.addModule(new OutOfAreaModule(boundaryFile, builderParams.outOfAreaMessage));
}
if (builderParams.tripPlanInPastMessage != null) {
graphBuilder.addModule(new TripPlanInPastModule(builderParams.tripPlanInPastMessage));
}
graphBuilder.serializeGraph = ( ! params.inMemory ) || params.preFlight;
return graphBuilder;
}
Expand Down
Expand Up @@ -47,7 +47,7 @@ public void buildGraph(Graph graph, HashMap<Class<?>, Object> extra) {
OutOfAreaNotesService svc = new OutOfAreaNotesService();
svc.setArea(area);
svc.setOutOfAreaMessage(outOfAreaMessage);
graph.outOfAreaNotesService = svc;
graph.planNotesServices.add(svc);
}

@Override
Expand Down
@@ -0,0 +1,39 @@
/* This program is free software: you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
package org.opentripplanner.graph_builder.module;

import org.opentripplanner.graph_builder.services.GraphBuilderModule;
import org.opentripplanner.routing.graph.Graph;
import org.opentripplanner.routing.services.notes.TripPlanInPastNotesService;

import java.util.HashMap;

public class TripPlanInPastModule implements GraphBuilderModule {

private String message;

public TripPlanInPastModule(String message) {
this.message = message;
}

@Override
public void buildGraph(Graph graph, HashMap<Class<?>, Object> extra) {
TripPlanInPastNotesService svc = new TripPlanInPastNotesService();
svc.setMessage(message);
graph.planNotesServices.add(svc);
}

@Override
public void checkInputs() {
}
}
4 changes: 2 additions & 2 deletions src/main/java/org/opentripplanner/routing/graph/Graph.java
Expand Up @@ -49,7 +49,7 @@ the License, or (at your option) any later version.
import org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory;
import org.opentripplanner.routing.services.StreetVertexIndexFactory;
import org.opentripplanner.routing.services.StreetVertexIndexService;
import org.opentripplanner.routing.services.notes.OutOfAreaNotesService;
import org.opentripplanner.routing.services.notes.PlanNotesService;
import org.opentripplanner.routing.services.notes.StreetNotesService;
import org.opentripplanner.routing.trippattern.Deduplicator;
import org.opentripplanner.routing.vertextype.PatternArriveVertex;
Expand Down Expand Up @@ -117,7 +117,7 @@ public class Graph implements Serializable {

private transient SampleFactory sampleFactory;

public OutOfAreaNotesService outOfAreaNotesService;
public List<PlanNotesService> planNotesServices = new ArrayList<>();

public final Deduplicator deduplicator = new Deduplicator();

Expand Down
Expand Up @@ -14,6 +14,7 @@ the License, or (at your option) any later version.

import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.Point;
import org.opentripplanner.api.model.TripPlan;
import org.opentripplanner.common.geometry.GeometryUtils;
import org.opentripplanner.routing.alertpatch.Alert;
import org.opentripplanner.routing.core.RoutingRequest;
Expand All @@ -22,7 +23,7 @@ the License, or (at your option) any later version.
import java.util.ArrayList;
import java.util.Collection;

public class OutOfAreaNotesService implements Serializable {
public class OutOfAreaNotesService implements Serializable, PlanNotesService {

private static final long serialVersionUID = 1;

Expand All @@ -38,7 +39,8 @@ public void setOutOfAreaMessage(String outOfAreaMessage) {
this.outOfAreaMessage = outOfAreaMessage;
}

public Collection<Alert> getAlerts(RoutingRequest request) {
@Override
public Collection<Alert> getAlerts(RoutingRequest request, TripPlan plan) {
Point fromPoint = GeometryUtils.getGeometryFactory().createPoint(request.rctx.fromVertex.getCoordinate());
Point toPoint = GeometryUtils.getGeometryFactory().createPoint(request.rctx.toVertex.getCoordinate());
Collection<Alert> alerts = new ArrayList<>();
Expand Down
@@ -0,0 +1,11 @@
package org.opentripplanner.routing.services.notes;

import org.opentripplanner.api.model.TripPlan;
import org.opentripplanner.routing.alertpatch.Alert;
import org.opentripplanner.routing.core.RoutingRequest;

import java.util.Collection;

public interface PlanNotesService {
Collection<Alert> getAlerts(RoutingRequest request, TripPlan plan);
}
@@ -0,0 +1,44 @@
/* This program is free software: you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
package org.opentripplanner.routing.services.notes;

import org.opentripplanner.api.model.TripPlan;
import org.opentripplanner.routing.alertpatch.Alert;
import org.opentripplanner.routing.core.RoutingRequest;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;

public class TripPlanInPastNotesService implements Serializable, PlanNotesService {

private static final long serialVersionUID = 1;

private String message;

public void setMessage(String message) {
this.message = message;
}

@Override
public Collection<Alert> getAlerts(RoutingRequest request, TripPlan plan) {
Collection<Alert> alerts = new ArrayList<>();
long maxStartTime = plan.itinerary.stream()
.mapToLong(i -> i.startTime.getTimeInMillis())
.max().orElse(Long.MAX_VALUE);
if (maxStartTime < request.rctx.debugOutput.getStartedCalculating()) {
alerts.add(Alert.createSimpleAlerts(message));
}
return alerts;
}
}
Expand Up @@ -153,6 +153,10 @@ public class GraphBuilderParameters {
*/
public final String outOfAreaMessage;

/**
* Message for trip plan in past
*/
public final String tripPlanInPastMessage;

/**
* Set all parameters from the given Jackson JSON tree, applying defaults.
Expand Down Expand Up @@ -188,6 +192,7 @@ public GraphBuilderParameters(JsonNode config) {
banDiscouragedBiking = config.path("banDiscouragedBiking").asBoolean(false);
createFlexTransfers = config.path("createFlexTransfers").asBoolean(false);
outOfAreaMessage = config.path("outOfAreaMessage").asText("One or more endpoints is out of area.");
tripPlanInPastMessage = config.path("tripPlanInPastMessage").asText();
}

}

0 comments on commit e3a32da

Please sign in to comment.