Skip to content
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

feat: extensive csv trip outputs #172

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.name.Names;
import org.eqasim.core.analysis.DistanceUnit;
import org.eqasim.core.analysis.PersonAnalysisFilter;
import org.eqasim.core.analysis.trips.TripItem;
import org.eqasim.core.analysis.trips.TripReaderFromPopulation;
import org.eqasim.core.analysis.trips.TripWriter;
import org.eqasim.core.misc.InjectorBuilder;
import org.eqasim.core.scenario.validation.ScenarioValidator;
import org.eqasim.core.simulation.analysis.EqasimAnalysisModule;
Expand Down Expand Up @@ -184,7 +186,11 @@ public void install() {
cmd.getOption("base-csv-path").ifPresent(s -> {
//We write the initial trip modes
Collection<TripItem> trips = tripReader.readTrips(population);
writeTripModesToCsv(trips, s);
try {
new TripWriter(trips, DistanceUnit.meter, DistanceUnit.meter).write(s);
} catch (IOException e) {
throw new RuntimeException(e);
}
});


Expand All @@ -202,25 +208,11 @@ public void install() {
outputPlansPath.ifPresent(s -> new PopulationWriter(population).write(s));
outputCsvPath.ifPresent(s -> {
Collection<TripItem> trips = tripReader.readTrips(population);
writeTripModesToCsv(trips, s);
});
}

public static void writeTripModesToCsv(Collection<TripItem> trips, String outputPath) {
try {
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputPath)));

writer.write( "personId;tripId;mode\n");
writer.flush();

for (TripItem trip : trips) {
writer.write( String.join(";", trip.personId.toString(), trip.personTripId+"", trip.mode) + "\n");
writer.flush();
try {
new TripWriter(trips, DistanceUnit.meter, DistanceUnit.meter).write(s);
} catch (IOException e) {
throw new RuntimeException(e);
}
writer.flush();
writer.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
});
}
}
Loading