Skip to content

Commit

Permalink
style: Apply prettier.
Browse files Browse the repository at this point in the history
  • Loading branch information
binh-dam-ibigroup committed Aug 8, 2024
1 parent 5a3fdd7 commit a6f4ee1
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,10 @@ private StreetEdge getEdgeForStreet(
I18NString name = params.edgeNamer().getNameForWay(way, label);
float carSpeed = way.getOsmProvider().getOsmTagMapper().getCarSpeedForWay(way, back);

StreetTraversalPermission perms = MobilityProfileRouting.adjustPedestrianPermissions(way, permissions);
StreetTraversalPermission perms = MobilityProfileRouting.adjustPedestrianPermissions(
way,
permissions
);
String startId = startEndpoint.getLabel().toString();
String endId = endEndpoint.getLabel().toString();
String profileKey = "";
Expand Down Expand Up @@ -618,16 +621,12 @@ private StreetEdge getEdgeForStreet(
}

// For testing, indicate the OSM node ids (remove prefixes).
String nameWithNodeIds = String.format(
"%s (%s)",
editedName,
profileKey
);
String nameWithNodeIds = String.format("%s (%s)", editedName, profileKey);
if (DEBUG_STREET_NAMES) {
seb.withName(nameWithNodeIds);
}

/*
/*
// Lookup costs by mobility profile, if any were defined.
// Note that edges are bidirectional, so we check that mobility data exist in both directions.
if (mobilityProfileData != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import static org.opentripplanner.standalone.config.framework.json.OtpVersion.V1_5;
import static org.opentripplanner.standalone.config.framework.json.OtpVersion.V2_2;
import static org.opentripplanner.standalone.config.routerconfig.UpdatersConfig.Type.BIKE_RENTAL;
import static org.opentripplanner.standalone.config.routerconfig.UpdatersConfig.Type.OSM_IMPEDANCE_UPDATER;
import static org.opentripplanner.standalone.config.routerconfig.UpdatersConfig.Type.MQTT_GTFS_RT_UPDATER;
import static org.opentripplanner.standalone.config.routerconfig.UpdatersConfig.Type.OSM_IMPEDANCE_UPDATER;
import static org.opentripplanner.standalone.config.routerconfig.UpdatersConfig.Type.REAL_TIME_ALERTS;
import static org.opentripplanner.standalone.config.routerconfig.UpdatersConfig.Type.SIRI_AZURE_ET_UPDATER;
import static org.opentripplanner.standalone.config.routerconfig.UpdatersConfig.Type.SIRI_AZURE_SX_UPDATER;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.opentripplanner.updater.impedance.OsmImpedanceUpdaterParameters;

public class OsmImpedanceUpdaterConfig {

public static OsmImpedanceUpdaterParameters create(String configRef, NodeAdapter c) {
return new OsmImpedanceUpdaterParameters(
configRef,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ public void update(Graph graph, Map<String, MobilityProfileData> impedances) {
.toList();

for (StreetEdge se : walkableEdges) {
if (se.getFromVertex() instanceof OsmVertex osmFrom && se.getToVertex() instanceof OsmVertex osmTo) {
if (
se.getFromVertex() instanceof OsmVertex osmFrom &&
se.getToVertex() instanceof OsmVertex osmTo
) {
var impedance = impedances.get(se.profileKey);
if (impedance != null) {
String symbol = "★";
Expand All @@ -46,7 +49,8 @@ public void update(Graph graph, Map<String, MobilityProfileData> impedances) {
// Create pro-rated impedance data for split edges.
if (osmFrom.nodeId != impedance.fromNode() || osmTo.nodeId != impedance.toNode()) {
double ratio = se.getDistanceMeters() / impedance.lengthInMeters();
proRatedCosts = MobilityProfileRouting.getProRatedProfileCosts(impedance.costs(), (float)ratio);
proRatedCosts =
MobilityProfileRouting.getProRatedProfileCosts(impedance.costs(), (float) ratio);
symbol = "☆";
}

Expand All @@ -60,6 +64,10 @@ public void update(Graph graph, Map<String, MobilityProfileData> impedances) {
}
}

LOG.info("{} new impedance entries imported into graph in {} seconds.", count, (System.currentTimeMillis() - start) / 1000);
LOG.info(
"{} new impedance entries imported into graph in {} seconds.",
count,
(System.currentTimeMillis() - start) / 1000
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ public class OsmImpedanceUpdater extends PollingGraphUpdater {
private WriteToGraphCallback saveResultOnGraph;
private Map<String, MobilityProfileData> previousImpedances = Map.of();

public OsmImpedanceUpdater(
OsmImpedanceUpdaterParameters config
) {
public OsmImpedanceUpdater(OsmImpedanceUpdaterParameters config) {
super(config);
this.url = config.url();
this.headers = HttpHeaders.of().add(config.headers()).build();
Expand Down Expand Up @@ -61,12 +59,17 @@ protected void runPolling() {
);

// Filter out which rows have been updated since previous poll.
Map<String, MobilityProfileData> changedImpedances = getChangedImpedances(impedances, previousImpedances);
Map<String, MobilityProfileData> changedImpedances = getChangedImpedances(
impedances,
previousImpedances
);
previousImpedances = impedances;

// Handle update in graph writer runnable
if (!changedImpedances.isEmpty()) {
saveResultOnGraph.execute((graph, transitModel) -> updateHandler.update(graph, changedImpedances));
saveResultOnGraph.execute((graph, transitModel) ->
updateHandler.update(graph, changedImpedances)
);
} else {
LOG.error("Impedance data unchanged (not updating graph).");
}
Expand Down Expand Up @@ -111,11 +114,14 @@ public static Map<String, MobilityProfileData> getChangedImpedances(
// Include entries that were removed in newImpedances, but mark them as empty map.
if (!newImpedances.containsKey(key)) {
MobilityProfileData removedData = entry.getValue();
result.put(key, new MobilityProfileData(
removedData.lengthInMeters(),
removedData.fromNode(),
removedData.toNode(),
Map.of())
result.put(
key,
new MobilityProfileData(
removedData.lengthInMeters(),
removedData.fromNode(),
removedData.toNode(),
Map.of()
)
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,32 @@
import org.opentripplanner.ext.mobilityprofile.MobilityProfileData;

class OsmImpedanceUpdaterTest {
private MobilityProfileData profileData(long from, long to, float impNone, float impWChairE, float impBlind) {
return new MobilityProfileData(10, from, to, Map.of(
MobilityProfile.NONE, impNone,
MobilityProfile.WCHAIRE, impWChairE,
MobilityProfile.BLIND, impBlind
));

private MobilityProfileData profileData(
long from,
long to,
float impNone,
float impWChairE,
float impBlind
) {
return new MobilityProfileData(
10,
from,
to,
Map.of(
MobilityProfile.NONE,
impNone,
MobilityProfile.WCHAIRE,
impWChairE,
MobilityProfile.BLIND,
impBlind
)
);
}

@Test
void areSameImpedances() {
MobilityProfileData profileData1 = profileData(1001, 1002,1.2F, 5.0F, 3.4F);
MobilityProfileData profileData1 = profileData(1001, 1002, 1.2F, 5.0F, 3.4F);
MobilityProfileData profileData2 = profileData(1002, 1003, 1.6F, 5.0F, 3.4F);
MobilityProfileData profileData3 = profileData(1001, 1002, 1.2F, 5.0F, 3.4F);
MobilityProfileData profileData4 = profileData(1003, 1004, 1.2F, 5.0F, 3.4F);
Expand All @@ -39,26 +54,42 @@ void areSameImpedances() {
@Test
void getChangedImpedances() {
Map<String, MobilityProfileData> newImpedances = Map.of(
"Street1", profileData(1001, 1002, 1.2F, 5.0F, 3.4F),
"Street2", profileData(1002, 1003, 2.1F, 7.0F, 4.4F),
"Street3", profileData(1003, 1004, 0.6F, 1.1F, 1.5F),
"Street4", profileData(1004, 1005, 1.4F, 1.6F, 1.8F),
"Street6", profileData(1006, 1007, 1.2F, 5.0F, 3.4F)
"Street1",
profileData(1001, 1002, 1.2F, 5.0F, 3.4F),
"Street2",
profileData(1002, 1003, 2.1F, 7.0F, 4.4F),
"Street3",
profileData(1003, 1004, 0.6F, 1.1F, 1.5F),
"Street4",
profileData(1004, 1005, 1.4F, 1.6F, 1.8F),
"Street6",
profileData(1006, 1007, 1.2F, 5.0F, 3.4F)
);
Map<String, MobilityProfileData> oldImpedances = Map.of(
"Street1", profileData(1001, 1002, 1.2F, 5.0F, 3.4F),
"Street2", profileData(1002, 1003, 2.1F, 3.0F, 4.4F),
"Street3", profileData(1003, 1004, 0.6F, 1.1F, 1.5F),
"Street4", profileData(1004, 1005, 1.4F, 1.6F, 1.8F),
"Street5", profileData(1005, 1006, 2.3F, 2.5F, 3.0F)
"Street1",
profileData(1001, 1002, 1.2F, 5.0F, 3.4F),
"Street2",
profileData(1002, 1003, 2.1F, 3.0F, 4.4F),
"Street3",
profileData(1003, 1004, 0.6F, 1.1F, 1.5F),
"Street4",
profileData(1004, 1005, 1.4F, 1.6F, 1.8F),
"Street5",
profileData(1005, 1006, 2.3F, 2.5F, 3.0F)
);

Map<String, MobilityProfileData> changedImpedances = Map.of(
"Street6", profileData(1006, 1007, 1.2F, 5.0F, 3.4F),
"Street5", new MobilityProfileData(10, 1005, 1006, Map.of()),
"Street2", profileData(1002, 1003, 2.1F, 7.0F, 4.4F)
"Street6",
profileData(1006, 1007, 1.2F, 5.0F, 3.4F),
"Street5",
new MobilityProfileData(10, 1005, 1006, Map.of()),
"Street2",
profileData(1002, 1003, 2.1F, 7.0F, 4.4F)
);

assertEquals(changedImpedances, OsmImpedanceUpdater.getChangedImpedances(newImpedances, oldImpedances));
assertEquals(
changedImpedances,
OsmImpedanceUpdater.getChangedImpedances(newImpedances, oldImpedances)
);
}
}

0 comments on commit a6f4ee1

Please sign in to comment.