forked from opentripplanner/OpenTripPlanner
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev-2.x' into gmap-mobility-profile
- Loading branch information
Showing
8 changed files
with
125 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
src/ext/java/org/opentripplanner/ext/reportapi/model/TransitGroupPriorityReport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package org.opentripplanner.ext.reportapi.model; | ||
|
||
import java.util.Collection; | ||
import java.util.TreeMap; | ||
import java.util.TreeSet; | ||
import java.util.stream.Collectors; | ||
import org.opentripplanner.routing.algorithm.raptoradapter.transit.request.PriorityGroupConfigurator; | ||
import org.opentripplanner.routing.api.request.request.TransitRequest; | ||
import org.opentripplanner.transit.model.network.TripPattern; | ||
|
||
/** | ||
* This class is used to report all transit-groups used for transit-group-priority. The report is | ||
* useful when configuring/debugging this functionality. | ||
* <p> | ||
* The format is pure text. | ||
*/ | ||
public class TransitGroupPriorityReport { | ||
|
||
public static String build(Collection<TripPattern> patterns, TransitRequest request) { | ||
var c = PriorityGroupConfigurator.of( | ||
request.priorityGroupsByAgency(), | ||
request.priorityGroupsGlobal() | ||
); | ||
|
||
var map = new TreeMap<Integer, DebugEntity>(); | ||
for (var it : patterns) { | ||
int groupId = c.lookupTransitGroupPriorityId(it); | ||
var de = map.computeIfAbsent(groupId, DebugEntity::new); | ||
de.add( | ||
it.getRoute().getAgency().getId().toString(), | ||
it.getMode().name(), | ||
it.getNetexSubmode().name() | ||
); | ||
} | ||
return ( | ||
"TRANSIT GROUPS PRIORITY" + | ||
map.values().stream().map(DebugEntity::toString).sorted().collect(Collectors.joining("")) | ||
); | ||
} | ||
|
||
private static class DebugEntity { | ||
|
||
private final int groupId; | ||
private final TreeMap<String, AgencyEntry> agencies = new TreeMap<>(); | ||
|
||
public DebugEntity(int groupId) { | ||
this.groupId = groupId; | ||
} | ||
|
||
void add(String agency, String mode, String submode) { | ||
agencies.computeIfAbsent(agency, AgencyEntry::new).add(mode, submode); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
var buf = new StringBuilder("\n %#010x".formatted(groupId)); | ||
for (var it : agencies.values()) { | ||
buf.append("\n ").append(it.toString()); | ||
} | ||
return buf.toString(); | ||
} | ||
} | ||
|
||
private record AgencyEntry(String agency, TreeMap<String, TreeSet<String>> modes) { | ||
private AgencyEntry(String agency) { | ||
this(agency, new TreeMap<>()); | ||
} | ||
|
||
void add(String mode, String submode) { | ||
modes.computeIfAbsent(mode, m -> new TreeSet<>()).add(submode); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
var buf = new StringBuilder(); | ||
for (var it : modes.entrySet()) { | ||
buf.append(", "); | ||
buf.append(it.getKey()); | ||
if (!it.getValue().isEmpty()) { | ||
buf.append(" (").append(String.join(", ", it.getValue())).append(")"); | ||
} | ||
} | ||
return agency + " ~ " + buf.substring(2); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters