Skip to content

Commit

Permalink
feat: extensive csv trip outputs (#172)
Browse files Browse the repository at this point in the history
Co-authored-by: Tarek Chouaki <tarek.chouaki@irt-systemx.fr>
  • Loading branch information
tkchouaki and Tarek Chouaki authored Dec 5, 2023
1 parent 7cbe85b commit 71b8e47
Showing 1 changed file with 12 additions and 20 deletions.
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);
}
});
}
}

0 comments on commit 71b8e47

Please sign in to comment.