Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve graph builder start up #5484

Merged
merged 3 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,10 @@ public void run() {

new DataImportIssueSummary(issueStore.listIssues()).logSummary();

validate();

// Log before we validate, this way we have more information if the validation fails
logGraphBuilderCompleteStatus(startTime, graph, transitModel);

validate();
}

private void addModule(GraphBuilderModule module) {
Expand Down Expand Up @@ -208,9 +209,9 @@ public DataImportIssueSummary issueSummary() {
private void validate() {
if (hasTransitData() && !transitModel.hasTransit()) {
throw new OtpAppException(
"The provided transit data have no trips within the configured transit " +
"service period. See build config 'transitServiceStart' and " +
"'transitServiceEnd'"
"The provided transit data have no trips within the configured transit service period. " +
"There is something wrong with your data - see the log above. Another possibility is that the " +
"'transitServiceStart' and 'transitServiceEnd' are not correctly configured."
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ public class WorldEnvelopeBuilder {
private static final Double MIN_NOT_SET = 9999d;
private static final Double MAX_NOT_SET = -9999d;

/**
* We need to set a centroid for the WorldEnvelope when there is no data. So, we choose a random
* place in europe for this - not in the middle of the see outside Africa (0.0, 0.0). This might
* be confusing to some, but if you read the logs it should be obvious that you have bigger
* problems ... no stops exist.
*/
private static final WgsCoordinate A_PLACE_IN_EUROPE = new WgsCoordinate(47.101, 9.611);

private double minLat = MIN_NOT_SET;
private double maxLat = MAX_NOT_SET;
private double minLonWest = MIN_NOT_SET;
Expand Down Expand Up @@ -62,21 +70,25 @@ public <T> WorldEnvelopeBuilder expandToIncludeTransitEntities(
}

public WorldEnvelope build() {
if (minLonWest == MIN_NOT_SET && minLonEast == MIN_NOT_SET) {
return new WorldEnvelope(-90.0, -180, 90, 180, A_PLACE_IN_EUROPE);
}
if (minLonWest == MIN_NOT_SET) {
return new WorldEnvelope(minLat, minLonEast, maxLat, maxLonEast, transitMedianCenter);
} else if (minLonEast == MIN_NOT_SET) {
}
if (minLonEast == MIN_NOT_SET) {
return new WorldEnvelope(minLat, minLonWest, maxLat, maxLonWest, transitMedianCenter);
}
// Envelope intersects with either 0º or 180º
double dist0 = minLonEast - minLonWest;
double dist180 = 360d - maxLonEast + minLonWest;

// A small gap between the east and west longitude at 0 degrees implies that the Envelope
// should include the 0 degrees longitude(meridian), and be split at 180 degrees.
if (dist0 < dist180) {
return new WorldEnvelope(minLat, maxLonWest, maxLat, maxLonEast, transitMedianCenter);
} else {
double dist0 = minLonEast - minLonWest;
double dist180 = 360d - maxLonEast + minLonWest;

// A small gap between the east and west longitude at 0 degrees implies that the Envelope
// should include the 0 degrees longitude(meridian), and be split at 180 degrees.
if (dist0 < dist180) {
return new WorldEnvelope(minLat, maxLonWest, maxLat, maxLonEast, transitMedianCenter);
} else {
return new WorldEnvelope(minLat, minLonEast, maxLat, minLonWest, transitMedianCenter);
}
return new WorldEnvelope(minLat, minLonEast, maxLat, minLonWest, transitMedianCenter);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ class CalculateWorldEnvelopeModuleTest {
stop("1").withCoordinate(22d, 24d).build()
);

@Test
void buildEmptyEnvelope() {
var subject = CalculateWorldEnvelopeModule.build(List.of(), List.of());

assertEquals(
"WorldEnvelope{lowerLeft: (-90.0, -180.0), upperRight: (90.0, 180.0), meanCenter: (0.0, 0.0), transitMedianCenter: (47.101, 9.611)}",
subject.toString()
);
}

@Test
void buildVertexesOnly() {
var subject = CalculateWorldEnvelopeModule.build(vertexes, List.of());
Expand Down
Loading