Skip to content

Commit

Permalink
Separate walk from non-transit time
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Jan 29, 2024
1 parent 9e7c9bf commit bb2e753
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ public DataFetcher<Long> waitingTime() {

@Override
public DataFetcher<Double> walkDistance() {
return environment -> getSource(environment).getNonTransitDistanceMeters();
return environment -> getSource(environment).walkDistanceMeters();
}

@Override
public DataFetcher<Long> walkTime() {
return environment -> (long) getSource(environment).getNonTransitDuration().toSeconds();
return environment -> (long) getSource(environment).walkDuration().toSeconds();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public static GraphQLObjectType create(
.name("walkDistance")
.deprecate("Replaced by `streetDistance`.")
.type(Scalars.GraphQLFloat)
.dataFetcher(env -> itinerary(env).getNonTransitDistanceMeters())
.dataFetcher(env -> itinerary(env).walkDistanceMeters())
.build()
)
.field(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class ItinerariesCalculateLegTotals {
int nTransitLegs = 0;
Duration nonTransitDuration = Duration.ZERO;
double nonTransitDistanceMeters = 0.0;
Duration walkDuration = Duration.ZERO;
double walkDistanceMeters = 0.0;
Duration waitingDuration = Duration.ZERO;
boolean walkOnly = true;
boolean streetOnly = true;
Expand Down Expand Up @@ -42,9 +44,14 @@ private void calculate(List<Leg> legs) {
if (!leg.isInterlinedWithPreviousLeg()) {
++nTransitLegs;
}
} else if (leg.isStreetLeg()) {
} else if (leg instanceof StreetLeg streetLeg){
nonTransitDuration = nonTransitDuration.plus(dt);
nonTransitDistanceMeters += leg.getDistanceMeters();

if(streetLeg.isWalkingLeg()){
walkDuration = walkDuration.plus(streetLeg.getDuration());
walkDistanceMeters = walkDistanceMeters + streetLeg.getDistanceMeters();
}
} else if (leg instanceof UnknownTransitPathLeg unknownTransitPathLeg) {
nTransitLegs += unknownTransitPathLeg.getNumberOfTransfers() + 1;
}
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/org/opentripplanner/model/plan/Itinerary.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public class Itinerary implements ItinerarySortKey {
private final boolean walkOnly;
private final boolean streetOnly;
private final Duration nonTransitDuration;
private final Duration walkDuration;
private final double walkDistanceMeters;


/* mutable primitive properties */
private Double elevationLost = 0.0;
Expand Down Expand Up @@ -75,6 +78,8 @@ public Itinerary(List<Leg> legs) {
this.transitDuration = totals.transitDuration;
this.nonTransitDuration = totals.nonTransitDuration;
this.nonTransitDistanceMeters = DoubleUtils.roundTo2Decimals(totals.nonTransitDistanceMeters);
this.walkDuration = totals.walkDuration;
this.walkDistanceMeters = totals.walkDistanceMeters;
this.waitingDuration = totals.waitingDuration;
this.walkOnly = totals.walkOnly;
this.streetOnly = totals.streetOnly;
Expand Down Expand Up @@ -663,4 +668,18 @@ public void setEmissionsPerPerson(Emissions emissionsPerPerson) {
public Emissions getEmissionsPerPerson() {
return this.emissionsPerPerson;
}

/**
* How much walking this itinerary contains, in meters.
*/
public double walkDistanceMeters() {
return walkDistanceMeters;
}

/**
* How long the walking is contained in this itinerary.
*/
public Duration walkDuration() {
return walkDuration;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"co2" : 123.0
},
"numberOfTransfers" : 1,
"walkDistance" : 28.0,
"walkTime" : 20,
"legs" : [
{
"mode" : "WALK",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
co2
}
numberOfTransfers
walkDistance
walkTime
legs {
mode
from {
Expand Down

0 comments on commit bb2e753

Please sign in to comment.