Skip to content

Commit

Permalink
rename SpeedSample to SegmentSpeedSample to avoid clash with com.conv…
Browse files Browse the repository at this point in the history
…eyal.traffic class.
  • Loading branch information
mattwigway committed Jun 5, 2015
1 parent 1ebf794 commit 8e6c536
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 26 deletions.
21 changes: 10 additions & 11 deletions src/main/java/org/opentripplanner/api/resource/PlannerResource.java
Expand Up @@ -12,15 +12,6 @@ the License, or (at your option) any later version.
along with this program. If not, see <http://www.gnu.org/licenses/>. */ along with this program. If not, see <http://www.gnu.org/licenses/>. */
package org.opentripplanner.api.resource; package org.opentripplanner.api.resource;


import static org.opentripplanner.api.resource.ServerInfo.Q;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo;

import org.opentripplanner.api.common.RoutingResource; import org.opentripplanner.api.common.RoutingResource;
import org.opentripplanner.api.model.TripPlan; import org.opentripplanner.api.model.TripPlan;
import org.opentripplanner.api.model.error.PlannerError; import org.opentripplanner.api.model.error.PlannerError;
Expand All @@ -32,7 +23,15 @@ the License, or (at your option) any later version.
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;


import java.util.*; import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo;
import java.util.List;

import static org.opentripplanner.api.resource.ServerInfo.Q;


/** /**
* This is the primary entry point for the trip planning web service. * This is the primary entry point for the trip planning web service.
Expand All @@ -43,7 +42,7 @@ the License, or (at your option) any later version.
* rather than singleton-scoped (a single instance existing for the lifetime of the OTP server). * rather than singleton-scoped (a single instance existing for the lifetime of the OTP server).
*/ */
@Path("routers/{routerId}/plan") // final element needed here rather than on method to distinguish from routers API @Path("routers/{routerId}/plan") // final element needed here rather than on method to distinguish from routers API
public class PlannerResource extends RoutingResource { public class PlannerResource extends RoutingResource {


private static final Logger LOG = LoggerFactory.getLogger(PlannerResource.class); private static final Logger LOG = LoggerFactory.getLogger(PlannerResource.class);


Expand Down
Expand Up @@ -13,8 +13,8 @@
/** /**
* Represents speeds at particular times of day. * Represents speeds at particular times of day.
*/ */
public class SpeedSample implements Serializable { public class SegmentSpeedSample implements Serializable {
private static final Logger LOG = LoggerFactory.getLogger(SpeedSample.class); private static final Logger LOG = LoggerFactory.getLogger(SegmentSpeedSample.class);


private static final double KMH_TO_MS = 1000d / 3600d; private static final double KMH_TO_MS = 1000d / 3600d;


Expand Down Expand Up @@ -68,7 +68,7 @@ private short encodeSpeed (double speed) {
} }


/** Create a speed sample from an OpenTraffic stats object */ /** Create a speed sample from an OpenTraffic stats object */
public SpeedSample(ExchangeFormat.BaselineStats stats) { public SegmentSpeedSample(ExchangeFormat.BaselineStats stats) {
float avg = stats.getAverageSpeed(); float avg = stats.getAverageSpeed();


if (Float.isNaN(avg)) { if (Float.isNaN(avg)) {
Expand Down Expand Up @@ -101,7 +101,7 @@ public SpeedSample(ExchangeFormat.BaselineStats stats) {
} }


/** create a speed sample using a function */ /** create a speed sample using a function */
public SpeedSample (double averageSpeed, double[] hourBins) { public SegmentSpeedSample(double averageSpeed, double[] hourBins) {
this.average = encodeSpeed(averageSpeed); this.average = encodeSpeed(averageSpeed);
this.hourBins = new short[hourBins.length]; this.hourBins = new short[hourBins.length];


Expand Down
Expand Up @@ -9,22 +9,22 @@
* A source of speeds for traversing streets. * A source of speeds for traversing streets.
*/ */
public class StreetSpeedSource { public class StreetSpeedSource {
private Map<Segment, SpeedSample> samples; private Map<Segment, SegmentSpeedSample> samples;


/** Get the speed for traversing the given edge with the given mode at the given time. Returns NaN if there is no speed information available. */ /** Get the speed for traversing the given edge with the given mode at the given time. Returns NaN if there is no speed information available. */
public double getSpeed (StreetEdge edge, TraverseMode traverseMode, long timeMillis) { public double getSpeed (StreetEdge edge, TraverseMode traverseMode, long timeMillis) {
if (traverseMode != TraverseMode.CAR) if (traverseMode != TraverseMode.CAR)
return Double.NaN; return Double.NaN;


SpeedSample sample = samples.get(new Segment(edge)); SegmentSpeedSample sample = samples.get(new Segment(edge));


if (sample == null) return Double.NaN; if (sample == null) return Double.NaN;


return sample.getSpeed(timeMillis); return sample.getSpeed(timeMillis);
} }


/** Set the samples. For now this is a simple setter, in the future it may handle concurrency control, etc. */ /** Set the samples. For now this is a simple setter, in the future it may handle concurrency control, etc. */
public synchronized void setSamples (Map<Segment, SpeedSample> samples) { public synchronized void setSamples (Map<Segment, SegmentSpeedSample> samples) {
this.samples = samples; this.samples = samples;
} }
} }
Expand Up @@ -5,7 +5,7 @@
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import org.opentripplanner.routing.graph.Graph; import org.opentripplanner.routing.graph.Graph;
import org.opentripplanner.traffic.Segment; import org.opentripplanner.traffic.Segment;
import org.opentripplanner.traffic.SpeedSample; import org.opentripplanner.traffic.SegmentSpeedSample;
import org.opentripplanner.traffic.StreetSpeedSource; import org.opentripplanner.traffic.StreetSpeedSource;
import org.opentripplanner.updater.GraphUpdaterManager; import org.opentripplanner.updater.GraphUpdaterManager;
import org.opentripplanner.updater.PollingGraphUpdater; import org.opentripplanner.updater.PollingGraphUpdater;
Expand Down Expand Up @@ -45,7 +45,7 @@ protected void runPolling() throws Exception {


// Build a speed index now while we're running in our own thread. We'll swap it out // Build a speed index now while we're running in our own thread. We'll swap it out
// at the appropriate time with a graphwriterrunnable, but no need to synchronize yet. // at the appropriate time with a graphwriterrunnable, but no need to synchronize yet.
Map<Segment, SpeedSample> speedIndex = Maps.newHashMap(); Map<Segment, SegmentSpeedSample> speedIndex = Maps.newHashMap();


// search through the tile directory // search through the tile directory
for (File z : tileDirectory.listFiles()) { for (File z : tileDirectory.listFiles()) {
Expand All @@ -65,9 +65,9 @@ protected void runPolling() throws Exception {


for (int i = 0; i < tile.getSegmentsCount(); i++) { for (int i = 0; i < tile.getSegmentsCount(); i++) {
ExchangeFormat.BaselineStats stats = tile.getSegments(i); ExchangeFormat.BaselineStats stats = tile.getSegments(i);
SpeedSample sample; SegmentSpeedSample sample;
try { try {
sample = new SpeedSample(stats); sample = new SegmentSpeedSample(stats);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
continue; continue;
} }
Expand Down
Expand Up @@ -24,9 +24,9 @@ public void testMatching () {
se.wayId = 10; se.wayId = 10;


// create a speed sample // create a speed sample
SpeedSample s = getSpeedSample(); SegmentSpeedSample s = getSpeedSample();


Map<Segment, SpeedSample> speeds = Maps.newHashMap(); Map<Segment, SegmentSpeedSample> speeds = Maps.newHashMap();
Segment seg = new Segment(10l, 5l, 6l); Segment seg = new Segment(10l, 5l, 6l);
speeds.put(seg, s); speeds.put(seg, s);


Expand Down Expand Up @@ -58,7 +58,7 @@ public void testMatching () {
} }


/** Make a speed sample */ /** Make a speed sample */
private SpeedSample getSpeedSample() { private SegmentSpeedSample getSpeedSample() {
double[] hourBins = new double[7 * 24]; double[] hourBins = new double[7 * 24];
for (int i = 0; i < hourBins.length; i++) { for (int i = 0; i < hourBins.length; i++) {
if (i == 8) if (i == 8)
Expand All @@ -75,6 +75,6 @@ else if (i == 9)
// ~4km/h // ~4km/h
double avg = 1.33; double avg = 1.33;


return new SpeedSample(avg, hourBins); return new SegmentSpeedSample(avg, hourBins);
} }
} }

0 comments on commit 8e6c536

Please sign in to comment.