Skip to content

Commit

Permalink
refactor(MobilityProfileParser): Adjust CSV headers and improve loggi…
Browse files Browse the repository at this point in the history
…ng of CSV parsing outcome
  • Loading branch information
binh-dam-ibigroup committed Jan 24, 2024
1 parent fd07c16 commit cdb152d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ public enum MobilityProfile {
WCHAIRM("WChairM"),
WCHAIRE("WChairE"),
MSCOOTER("MScooter"),
VISION("Vision"),
VISIONPLUS("Vision+"),
SOME_VISION("Some-Vision"),
DEVICE_VISION("Device-Vision"),
WCHAIRM_VISION("WChairM-Vision"),
WCHAIRE_VISION("WChairE-Vision"),
MSCOOTER_VISION("MScooter-Vision"),
SOME_VISIONPLUS("Some-Vision+"),
DEVICE_VISIONPLUS("Device-Vision+"),
WCHAIRM_VISIONPLUS("WChairM-Vision+"),
WCHAIRE_VISIONPLUS("WChairE-Vision+"),
MSCOOTER_VISIONPLUS("MScooter-Vision+");
LOW_VISION("LowVision"),
BLIND("Blind"),
SOME_LOW_VISION("Some-LowVision"),
DEVICE_LOW_VISION("Device-LowVision"),
WCHAIRM_LOW_VISION("WChairM-LowVIsion"), // Typo in CSV header
WCHAIRE_LOW_VISION("WChairE-LowVision"),
MSCOOTER_LOW_VISION("Mscooter-LowVision"), // Typo in the CSV header
SOME_BLIND("Some-Blind"),
DEVICE_BLIND("Device-Blind"),
WCHAIRM_BLIND("WChairM-Blind"),
WCHAIRE_BLIND("WChairE-Blind"),
MSCOOTER_BLIND("Mscooter-Blind"); // Typo in the CSV header

private final String text;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ private static void parseRow(
CsvReader reader,
ImmutableTable.Builder<String, String, Map<MobilityProfile, Float>> tableBuilder
) throws IOException {
String currentColumnHeader = "";
try {
long fromNode = Long.parseLong(reader.get("Upstream Node"), 10);
long toNode = Long.parseLong(reader.get("Downstream Node"), 10);

var weightMap = new HashMap<MobilityProfile, Float>();
for (var profile : MobilityProfile.values()) {
weightMap.put(profile, Float.parseFloat(reader.get(profile.getText())));
currentColumnHeader = profile.getText();
weightMap.put(profile, Float.parseFloat(reader.get(currentColumnHeader)));
}

tableBuilder.put(
Expand All @@ -65,7 +67,11 @@ private static void parseRow(
weightMap
);
} catch (NumberFormatException | NullPointerException e) {
LOG.warn("Skipping mobility profile data at line {}: missing/invalid data", lineNumber);
LOG.warn(
"Skipping mobility profile data at line {}: missing/invalid data in column {}.",
lineNumber,
currentColumnHeader
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@
import static org.opentripplanner.datastore.api.FileType.NETEX;
import static org.opentripplanner.datastore.api.FileType.OSM;

import com.google.common.collect.ImmutableTable;
import jakarta.inject.Inject;
import java.io.IOException;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.opentripplanner.datastore.api.DataSource;
import org.opentripplanner.ext.emissions.EmissionsDataModel;
import org.opentripplanner.ext.mobilityprofile.MobilityProfile;
import org.opentripplanner.ext.mobilityprofile.MobilityProfileParser;
import org.opentripplanner.ext.stopconsolidation.StopConsolidationRepository;
import org.opentripplanner.framework.application.OTPFeature;
Expand Down Expand Up @@ -106,7 +109,10 @@ public static GraphBuilder create(
if (mobilityDataSource.isPresent()) {
// Parse stuff from the mobility profile CSV
try (var inputStream = mobilityDataSource.get().asInputStream()) {
osmModule.setMobilityProfileData(MobilityProfileParser.parseData(inputStream));
ImmutableTable<String, String, Map<MobilityProfile, Float>> mobilityProfileData =
MobilityProfileParser.parseData(inputStream);
LOG.info("Imported {} rows from mobility-profile.csv", mobilityProfileData.rowKeySet().size());
osmModule.setMobilityProfileData(mobilityProfileData);
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down

0 comments on commit cdb152d

Please sign in to comment.