-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Cleanup CO₂ emissions #6558
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
Cleanup CO₂ emissions #6558
Conversation
not in GraphBuild only there should be a "OTP Global" scope name-space or FeedInfo.
- I used inheritance to do this, delegation would probably be at least as good. - We can now do proper validation of the required source parameter.
- This add support for using all data-sources, not just the file system
I see that there is a problem with the data-fetchers for |
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 tested this but the emissions building failed with the following stack trace:
16:46:00.173 ERROR [main] (OTPMain.java:61) An uncaught error occurred inside OTP: Cannot invoke "java.util.zip.ZipFile.getInputStream(java.util.zip.ZipEntry)" because "this.zipFile" is null java.lang.NullPointerException: Cannot invoke "java.util.zip.ZipFile.getInputStream(java.util.zip.ZipEntry)" because "this.zipFile" is null at org.opentripplanner.datastore.file.ZipFileDataSource.entryStream(ZipFileDataSource.java:75) at org.opentripplanner.datastore.file.ZipFileEntryDataSource.asInputStream(ZipFileEntryDataSource.java:56) at org.opentripplanner.gtfs.graphbuilder.GtfsBundle$1.getResource(GtfsBundle.java:63) at org.opentripplanner.gtfs.graphbuilder.GtfsFeedIdResolver.fromGtfsFeed(GtfsFeedIdResolver.java:39) at org.opentripplanner.gtfs.graphbuilder.GtfsBundle.getFeedId(GtfsBundle.java:95) at org.opentripplanner.ext.emissions.EmissionsGraphBuilder.buildGraph(EmissionsGraphBuilder.java:49) at org.opentripplanner.graph_builder.GraphBuilder.run(GraphBuilder.java:202) at org.opentripplanner.standalone.OTPMain.startOTPServer(OTPMain.java:144) at org.opentripplanner.standalone.OTPMain.main(OTPMain.java:56)
The GTFS data I used can be downloaded from here
application/src/ext/java/org/opentripplanner/ext/emissions/Co2EmissionsDataReader.java
Outdated
Show resolved
Hide resolved
application/src/ext/java/org/opentripplanner/ext/emissions/Co2EmissionsDataReader.java
Outdated
Show resolved
Hide resolved
/** | ||
* This class allows updating the graph with emissions data from external emissions data files. | ||
*/ | ||
public class EmissionsGraphBuilder implements GraphBuilderModule { |
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.
On this Gram vs Grams dicussion. Should we call all these classes EmissionSomething or EmissionsSomething?
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 created an issue for this #6571. I think we should use EmissionSomeThing and not EmissionsSomeThing. I would like to do it in a separate PR.
application/src/main/java/org/opentripplanner/datastore/api/DataSource.java
Outdated
Show resolved
Hide resolved
...ion/src/main/java/org/opentripplanner/graph_builder/model/ConfiguredCompositeDataSource.java
Outdated
Show resolved
Hide resolved
application/src/main/java/org/opentripplanner/gtfs/graphbuilder/GtfsFeedIdResolver.java
Outdated
Show resolved
Hide resolved
.../src/main/java/org/opentripplanner/routing/algorithm/filterchain/ext/EmissionsDecorator.java
Outdated
Show resolved
Hide resolved
application/src/ext/java/org/opentripplanner/ext/emissions/Co2EmissionsDataReader.java
Outdated
Show resolved
Hide resolved
application/src/main/java/org/opentripplanner/routing/algorithm/filterchain/ext/package-info.md
Outdated
Show resolved
Hide resolved
...ation/src/main/java/org/opentripplanner/standalone/configure/ConstructApplicationModule.java
Outdated
Show resolved
Hide resolved
application/src/ext/java/org/opentripplanner/ext/emissions/Co2EmissionsDataReader.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Joel Lappalainen <[email protected]>
The failure (stacktrace) is caused by the zip-file being closed after the GTFS data is read, before the emissions data is loaded. I will look into how this should be resolved. The best solution is probably to clone and open DataSource, but we need to be careful - opening two connections to a connection based data-source (Google Cloud) might cause problems. |
The failure was a bug in the |
…odule The ZipFileDataSource did not cleanup its internal state when it was closed, so opening it a second time failed. The OTP DataSource framework is tailored to address this kind of features, so the fix is simple. None of the other composite data sources has the same bug.
d63570a
to
6c5d37a
Compare
application/src/ext/java/org/opentripplanner/ext/emissions/Co2EmissionsDataReader.java
Outdated
Show resolved
Hide resolved
return store.stopConsolidation(); | ||
} | ||
|
||
private ConfiguredDataSource<OsmExtractParameters> mapOsmData(DataSource dataSource) { |
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 method should be lower in the file as it's private. The diff is already difficult to read so it shouldn't matter much if you move one more method a bit.
…EmissionsDataReader.java Co-authored-by: Joel Lappalainen <[email protected]>
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.
Looks good, just fix the formatting issue.
@t2gran you need to merge dev-2.x because a test has moved and the merge of your branch and dev-2.x doesn't compile anymore. |
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.
Looks good, no additional comment from my side.
Summary
This PR refactor the GTFS GraphBuilder and clean up the code. If contains a few bug fixes, the most important is
to make the emission sandbox module work with other data sources than just the file system. At Entur we uses Google Storage.
Some of the main changes:
EmissionService
or theDecorateWithEmission
.GtfsFeedParameters
andGtfsDefaultParameters
. I used inheritance here, but delegation might have beed equally good. The nice thing about inheritance is that the parameters align with the structure of the build-config.Issue
🟥 No issue for this, this is mostly cleanup code and a few bug fixes
Closes #45
Unit tests
✅ Some new tests are added, while emission tests no focus on business - test-coverage should be higher.
Documentation
✅ Relevant JavaDoc is updated
Changelog
🟥 Not relevant.
Bumping the serialization version id
✅ Needed, the emission repository is changed.