-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Optional stop clustering by parent station or geography #2383
Conversation
@@ -78,6 +78,9 @@ | |||
|
|||
/** maximum distance to walk after leaving transit in Analyst */ | |||
public static final int MAX_WALK_METERS = 3500; | |||
|
|||
/** Should stop clusters be created by parent stations instead of by proximity? */ | |||
public static final boolean CLUSTER_BY_PARENT_STATIONS = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems sort of funny - it's a final variable with a fixed value, so all of the other code you're adding is dead. Do you mean to make this configurable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to make it configurable, yes, and took a shortcut by making this constant. But I see now how I can put it in the router-config, so I will do that instead.
cluster.computeCenter(); | ||
stopClusterForId.put(cluster.id, cluster); | ||
} | ||
if (!CLUSTER_BY_PARENT_STATIONS) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to use a separate class with multiple implementations, if possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I will move it to a separate class.
for (Stop s0 : stopForId.values()) { | ||
String ps = s0.getParentStation(); | ||
parentStopsMap.put(ps, new StopCluster(ps, s0.getName())); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
formatting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will fix.
} | ||
for (Stop s0 : stopForId.values()) { | ||
String ps = s0.getParentStation(); | ||
if(!parentStopsMap.containsKey(ps)) continue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
formatting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also this if is unnecessary; it will never be true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, will have a look at the logic.
} | ||
for (Map.Entry<String, StopCluster> cluster : parentStopsMap.entrySet()) { | ||
cluster.getValue().computeCenter(); | ||
stopClusterForId.put(cluster.getKey(), cluster.getValue()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this just mean that stopClusterForId is a duplicate of parentStopsMap?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may be right. I was staring myself blind on the code...
The two new commits do the folllowing:
Please review! |
Most of your comments are about issues already corrected in the second commit (c377195). But I'll fix the cluster name (in our data, parent stations always have the same name as their children, but of course that isn't always the case. Sorry about text formatting. 1: I am used to .NET formatting, 2: Indentation looks OK in Eclipse... |
I looked a bit more at using the parent stop's name, and it seems a bit difficult to extract it in this context. As using the child stop's name works perfect for us, and most agencies use similar names for child/parent(??), I suggest that we leave it as it is, and fix it later if anyone else has a need for explicitly using the parent's name? |
Ok, sorry about the duplicate comments. It's easier to read if you rebase/amend. I'll take a look at the new version soon. |
} | ||
} | ||
|
||
private void clusterByParentStation() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This indentation is still not right. It's indented by a single tab, while the rest of this file has four spaces. Can you please double-check all of the indentation? Thanks.
cluster.computeCenter(); | ||
stopClusterForId.put(cluster.id, cluster); | ||
} | ||
if (graph.clusterByParentStation) clusterByParentStation(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
newline before clusterByParentStation();
StopCluster cluster; | ||
if (stopClusterForId.containsKey(ps)) { | ||
cluster = stopClusterForId.get(ps); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No newline between } and else.
} | ||
cluster.children.add(stop); | ||
stopClusterForStop.put(stop, cluster); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete blank line
} | ||
for (Map.Entry<String, StopCluster> cluster : stopClusterForId.entrySet()) { | ||
cluster.getValue().computeCenter(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also delete this blank line
cluster.getValue().computeCenter(); | ||
|
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix indent
@@ -151,7 +151,11 @@ public void startup(JsonNode config) { | |||
} | |||
} | |||
} | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't replace a blank line with a line containing only trailing whitespace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(this one seems to still be there)
|
||
JsonNode clusterByParentStation = config.get("clusterByParentStation"); | ||
if (clusterByParentStation != null && clusterByParentStation.isBoolean()) | ||
graph.clusterByParentStation = clusterByParentStation.asBoolean(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... and if it's not a boolean, throw an exception or something.
But actually, it should be a string called something like "clusterMode", with values "parentStation" and "geographic" -- maybe later someone will add something that clusters by name or something.
What a hassle with the formatting ;-). At least, I have now installed the preferred text formatter for Eclipse, so I hope these problems will be reduced for the future. I also added some logging for cases when the parameter is falsely set to a string value. Of course the whole logic could be rewritten to facilitate additional clustering methods, but I would prefer not having to do that at the moment. |
I think it would not be hard to do the parameter as a string, and I think it would be much cleaner. |
OK. Figured it out in the shower. Will update today. |
Thanks for all your hard work on this. I've gone ahead and merged it even though Travis is failing, since when I test locally, the tests pass. |
Thanks, I also wonder what happened, as the tests pass locally here as well. |
As discussed in #2364, this PR introduces the possibility to cluster stops based on parent stations, rather than by geographical proximity. This has proved to work well in our test environment here in Oslo.