Skip to content

Commit

Permalink
Merge pull request #5569 from HSLdevcom/co2
Browse files Browse the repository at this point in the history
Emissions data validation and reporting improvements
  • Loading branch information
optionsome authored Dec 14, 2023
2 parents 31260ca + 09c386a commit 00db8f4
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.opentripplanner.datastore.file.FileDataSource;
import org.opentripplanner.framework.application.OtpFileNames;
import org.opentripplanner.graph_builder.ConfiguredDataSource;
import org.opentripplanner.graph_builder.issue.api.DataImportIssueStore;
import org.opentripplanner.gtfs.graphbuilder.GtfsFeedParameters;
import org.opentripplanner.standalone.config.BuildConfig;
import org.opentripplanner.test.support.ResourceLoader;
Expand Down Expand Up @@ -42,7 +43,7 @@ void testMultipleGtfsDataReading() {
configuredDataSource,
buildConfig,
emissionsDataModel,
null
DataImportIssueStore.NOOP
);
emissionsModule.buildGraph();
assertEquals(
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ route_id,avg_co2_per_vehicle_per_km,avg_passenger_count
1004,0.0,0.0
1005,0,-1
1006,0,1
1007,,
,1,
,,2
,,
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.opentripplanner.framework.lang.Sandbox;
import org.opentripplanner.framework.lang.StringUtils;
import org.opentripplanner.graph_builder.issue.api.DataImportIssueStore;
import org.opentripplanner.transit.model.framework.FeedScopedId;
import org.slf4j.Logger;
Expand Down Expand Up @@ -92,30 +93,44 @@ private Map<FeedScopedId, Double> readEmissions(InputStream stream, String feedI
String avgCo2PerVehiclePerKmString = reader.get("avg_co2_per_vehicle_per_km");
String avgPassengerCountString = reader.get("avg_passenger_count");

if (avgCo2PerVehiclePerKmString.isEmpty()) {
if (!StringUtils.hasValue(routeId)) {
issueStore.add(
"InvalidEmissionData",
"Value for avg_co2_per_vehicle_per_km is missing in the Emissions.txt for route %s",
"Value for routeId is missing in the emissions.txt for line: %s.",
reader.getRawRecord()
);
}
if (!StringUtils.hasValue(avgCo2PerVehiclePerKmString)) {}
{
issueStore.add(
"InvalidEmissionData",
"Value for avg_co2_per_vehicle_per_km is missing in the emissions.txt for route %s",
routeId
);
}
if (avgPassengerCountString.isEmpty()) {
if (!StringUtils.hasValue(avgPassengerCountString)) {
issueStore.add(
"InvalidEmissionData",
"Value for avg_passenger_count is missing in the Emissions.txt for route %s",
"Value for avg_passenger_count is missing in the emissions.txt for route %s",
routeId
);
}

Double avgCo2PerVehiclePerMeter = Double.parseDouble(avgCo2PerVehiclePerKmString) / 1000;
Double avgPassengerCount = Double.parseDouble(reader.get("avg_passenger_count"));
Optional<Double> emissions = calculateEmissionsPerPassengerPerMeter(
routeId,
avgCo2PerVehiclePerMeter,
avgPassengerCount
);
if (emissions.isPresent()) {
emissionsData.put(new FeedScopedId(feedId, routeId), emissions.get());
if (
StringUtils.hasValue(feedId) &&
StringUtils.hasValue(routeId) &&
StringUtils.hasValue(avgCo2PerVehiclePerKmString) &&
StringUtils.hasValue(avgPassengerCountString)
) {
Double avgCo2PerVehiclePerMeter = Double.parseDouble(avgCo2PerVehiclePerKmString) / 1000;
Double avgPassengerCount = Double.parseDouble(reader.get("avg_passenger_count"));
Optional<Double> emissions = calculateEmissionsPerPassengerPerMeter(
routeId,
avgCo2PerVehiclePerMeter,
avgPassengerCount
);
if (emissions.isPresent()) {
emissionsData.put(new FeedScopedId(feedId, routeId), emissions.get());
}
}
}
return emissionsData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public void buildGraph() {
}
this.emissionsDataModel.setCo2Emissions(emissionsData);
this.emissionsDataModel.setCarAvgCo2PerMeter(carAvgEmissionsPerMeter);
LOG.info(
"Emissions building finished. Number of CO2 emission records saved: " + emissionsData.size()
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ public static GraphBuilder create(
graphBuilder.addModule(factory.graphCoherencyCheckerModule());
}

if (OTPFeature.Co2Emissions.isOn()) {
graphBuilder.addModule(factory.emissionsModule());
}

if (config.dataImportReport) {
graphBuilder.addModule(factory.dataImportIssueReporter());
}
Expand All @@ -168,10 +172,6 @@ public static GraphBuilder create(
graphBuilder.addModuleOptional(factory.dataOverlayFactory());
}

if (OTPFeature.Co2Emissions.isOn()) {
graphBuilder.addModule(factory.emissionsModule());
}

graphBuilder.addModule(factory.calculateWorldEnvelopeModule());

return graphBuilder;
Expand Down

0 comments on commit 00db8f4

Please sign in to comment.