Skip to content

Commit

Permalink
Merge pull request #58 from ibi-group/commtrans-fares
Browse files Browse the repository at this point in the history
Commtrans fares
  • Loading branch information
evansiroky authored Jul 30, 2021
2 parents abc2761 + 2939e3c commit 691e7a1
Show file tree
Hide file tree
Showing 10 changed files with 837 additions and 74 deletions.
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,13 @@
<artifactId>bsf</artifactId>
<version>2.4.0</version>
</dependency>
<!-- Unit testing -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.5.2</version>
<scope>test</scope>
</dependency>
<!-- Error reporting -->
<dependency>
<groupId>com.bugsnag</groupId>
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/opentripplanner/routing/core/Fare.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
*/
public class Fare {

public static enum FareType implements Serializable {
regular, student, senior, tram, special, youth
public enum FareType implements Serializable {
regular, student, senior, tram, special, youth,
electronicRegular, electronicYouth, electronicSpecial, electronicSenior
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ public static FareServiceFactory fromConfig(JsonNode config) {
case "dutch":
retval = new DutchFareServiceFactory();
break;
case "orca":
retval = new OrcaFareServiceFactory();
break;
case "pdx":
retval = new PdxFareServiceFactory();
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import org.opentripplanner.model.FeedScopedId;
import org.opentripplanner.model.FareAttribute;
import org.opentripplanner.model.Route;
import org.opentripplanner.model.Stop;
import org.opentripplanner.routing.core.Fare;
import org.opentripplanner.routing.core.Fare.FareType;
Expand All @@ -29,75 +30,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/** A set of edges on a single route, with associated information for calculating fares */
class Ride {

String feedId;

String agency; // route agency

FeedScopedId route;

FeedScopedId trip;

Set<String> zones;

String startZone;

String endZone;

long startTime;

long endTime;

// in DefaultFareServiceImpl classifier is just the TraverseMode
// it can be used differently in custom fare services
public Object classifier;

public Stop firstStop;

public Stop lastStop;

public Ride() {
zones = new HashSet<String>();
}

public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("Ride");
if (startZone != null) {
builder.append("(from zone ");
builder.append(startZone);
}
if (endZone != null) {
builder.append(" to zone ");
builder.append(endZone);
}
builder.append(" on route ");
builder.append(route);
if (zones.size() > 0) {
builder.append(" through zones ");
boolean first = true;
for (String zone : zones) {
if (first) {
first = false;
} else {
builder.append(",");
}
builder.append(zone);
}
}
builder.append(" at ");
builder.append(startTime);
if (classifier != null) {
builder.append(", classified by ");
builder.append(classifier.toString());
}
builder.append(")");
return builder.toString();
}
}

/** Holds information for doing the graph search on fares */
class FareSearch {
// Cell [i,j] holds the best (lowest) cost for a trip from rides[i] to rides[j]
Expand Down Expand Up @@ -175,6 +107,7 @@ protected List<Ride> createRides(GraphPath path) {
ride.startZone = hEdge.getBeginStop().getZoneId();
ride.zones.add(ride.startZone);
ride.agency = state.getBackTrip().getRoute().getAgency().getId();
ride.routeData = state.getBackTrip().getRoute();
ride.route = state.getRoute();
ride.startTime = state.getBackState().getTimeSeconds();
ride.firstStop = hEdge.getBeginStop();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.opentripplanner.routing.impl;

import com.fasterxml.jackson.databind.JsonNode;
import org.opentripplanner.model.FeedScopedId;
import org.opentripplanner.model.OtpTransitService;
import org.opentripplanner.routing.core.FareRuleSet;
import org.opentripplanner.routing.services.FareService;

import java.util.HashMap;
import java.util.Map;

public class OrcaFareServiceFactory extends DefaultFareServiceFactory {
protected Map<FeedScopedId, FareRuleSet> regularFareRules = new HashMap<>();

@Override
public FareService makeFareService() {
return new OrcaFareServiceImpl(regularFareRules.values());
}

/**
* This step ensures that the fares in the source GTFS data are accounted for correctly.
*/
@Override
public void processGtfs(OtpTransitService transitService) {
fillFareRules(null, transitService.getAllFareAttributes(), transitService.getAllFareRules(), regularFareRules);
}

/**
* There is no configuration code in DefaultFareServiceFactory. We override the super class's method just in case it changes.
*/
@Override
public void configure(JsonNode config) {
// No configuration at the moment.
}
}
Loading

0 comments on commit 691e7a1

Please sign in to comment.