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 remote-tracking branch 'upstream/dev-2.x' into upstream-merge-2…
…023-11-14
- Loading branch information
Showing
74 changed files
with
967 additions
and
2,747 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
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
73 changes: 73 additions & 0 deletions
73
src/ext-test/java/org/opentripplanner/ext/emissions/EmissionsModuleTest.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,73 @@ | ||
package org.opentripplanner.ext.emissions; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.opentripplanner.datastore.api.FileType.GTFS; | ||
import static org.opentripplanner.standalone.config.framework.json.JsonSupport.jsonNodeFromResource; | ||
|
||
import com.google.common.collect.ArrayListMultimap; | ||
import com.google.common.collect.Multimap; | ||
import java.io.File; | ||
import java.util.Optional; | ||
import org.junit.jupiter.api.Test; | ||
import org.opentripplanner.datastore.api.DataSource; | ||
import org.opentripplanner.datastore.api.FileType; | ||
import org.opentripplanner.datastore.file.FileDataSource; | ||
import org.opentripplanner.framework.application.OtpFileNames; | ||
import org.opentripplanner.graph_builder.ConfiguredDataSource; | ||
import org.opentripplanner.gtfs.graphbuilder.GtfsFeedParameters; | ||
import org.opentripplanner.standalone.config.BuildConfig; | ||
import org.opentripplanner.test.support.ResourceLoader; | ||
import org.opentripplanner.transit.model.framework.FeedScopedId; | ||
|
||
public class EmissionsModuleTest { | ||
|
||
private final ResourceLoader RES = ResourceLoader.of(EmissionsModuleTest.class); | ||
private final File CO2_GTFS_ZIP = RES.file("emissions-test-gtfs.zip"); | ||
private final File CO2_GTFS = RES.file("emissions-test-gtfs/"); | ||
private final String CONFIG_PATH = "standalone/config/" + OtpFileNames.BUILD_CONFIG_FILENAME; | ||
private final BuildConfig buildConfig = new BuildConfig( | ||
jsonNodeFromResource(CONFIG_PATH), | ||
CONFIG_PATH, | ||
true | ||
); | ||
private final Multimap<FileType, DataSource> inputData = ArrayListMultimap.create(); | ||
|
||
@Test | ||
void testMultipleGtfsDataReading() { | ||
inputData.put(GTFS, new FileDataSource(CO2_GTFS_ZIP, GTFS)); | ||
inputData.put(GTFS, new FileDataSource(CO2_GTFS, GTFS)); | ||
Iterable<ConfiguredDataSource<GtfsFeedParameters>> configuredDataSource = getGtfsConfiguredDatasource(); | ||
EmissionsDataModel emissionsDataModel = new EmissionsDataModel(); | ||
EmissionsModule emissionsModule = new EmissionsModule( | ||
configuredDataSource, | ||
buildConfig, | ||
emissionsDataModel, | ||
null | ||
); | ||
emissionsModule.buildGraph(); | ||
assertEquals( | ||
Optional.of(0.006), | ||
emissionsDataModel.getCO2EmissionsById(new FeedScopedId("emissionstest", "1001")) | ||
); | ||
assertEquals( | ||
Optional.of(0.041), | ||
emissionsDataModel.getCO2EmissionsById(new FeedScopedId("emissionstest1", "1002")) | ||
); | ||
} | ||
|
||
private Iterable<ConfiguredDataSource<GtfsFeedParameters>> getGtfsConfiguredDatasource() { | ||
return inputData | ||
.get(GTFS) | ||
.stream() | ||
.map(it -> new ConfiguredDataSource<>(it, getGtfsFeedConfig(it))) | ||
.toList(); | ||
} | ||
|
||
private GtfsFeedParameters getGtfsFeedConfig(DataSource dataSource) { | ||
return buildConfig.transitFeeds | ||
.gtfsFeeds() | ||
.stream() | ||
.findFirst() | ||
.orElse(buildConfig.gtfsDefaults.copyOf().withSource(dataSource.uri()).build()); | ||
} | ||
} |
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
Binary file added
BIN
+323 Bytes
src/ext-test/resources/org/opentripplanner/ext/emissions/emissions-missing-test-gtfs.zip
Binary file not shown.
2 changes: 2 additions & 0 deletions
2
...est/resources/org/opentripplanner/ext/emissions/emissions-missing-test-gtfs/feed_info.txt
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,2 @@ | ||
feed_publisher_name,feed_publisher_url,feed_lang,feed_start_date,feed_end_date,feed_version,feed_id | ||
emissionstest,http://www.emissionstest.fi/,fi,20230623,20230806,2023-06-23 22:42:09,emissionstest |
2 changes: 1 addition & 1 deletion
2
src/ext-test/resources/org/opentripplanner/ext/emissions/emissions-test-gtfs/feed_info.txt
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
feed_publisher_name,feed_publisher_url,feed_lang,feed_start_date,feed_end_date,feed_version,feed_id | ||
emissionstest,http://www.emissionstest.fi/,fi,20230623,20230806,2023-06-23 22:42:09,emissionstest | ||
emissionstest,http://www.emissionstest.fi/,fi,20230623,20230806,2023-06-23 22:42:09,emissionstest1 |
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
Oops, something went wrong.