diff --git a/contribs/application/src/main/java/org/matsim/application/CommandSpec.java b/contribs/application/src/main/java/org/matsim/application/CommandSpec.java index d7acfc227f4..de07cfe7f8a 100644 --- a/contribs/application/src/main/java/org/matsim/application/CommandSpec.java +++ b/contribs/application/src/main/java/org/matsim/application/CommandSpec.java @@ -51,6 +51,7 @@ * Other commands that produce the input needed by this command. */ Class[] dependsOn() default {}; +// Dependency[] dependsOn() default {}; /** * Group name / identifier. Will use the package name if this is not changed here. diff --git a/contribs/application/src/main/java/org/matsim/application/Dependency.java b/contribs/application/src/main/java/org/matsim/application/Dependency.java new file mode 100644 index 00000000000..1743874681f --- /dev/null +++ b/contribs/application/src/main/java/org/matsim/application/Dependency.java @@ -0,0 +1,11 @@ +package org.matsim.application; + +public @interface Dependency { + + Class value(); + + String[] files() default {}; + + boolean required() default false; + +} diff --git a/contribs/application/src/main/java/org/matsim/application/analysis/impact/ImpactAnalysis.java b/contribs/application/src/main/java/org/matsim/application/analysis/impact/ImpactAnalysis.java index 0cf5f0911f1..9171ae75e2e 100644 --- a/contribs/application/src/main/java/org/matsim/application/analysis/impact/ImpactAnalysis.java +++ b/contribs/application/src/main/java/org/matsim/application/analysis/impact/ImpactAnalysis.java @@ -1,12 +1,92 @@ package org.matsim.application.analysis.impact; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.application.ApplicationUtils; +import org.matsim.application.CommandSpec; import org.matsim.application.MATSimAppCommand; +import org.matsim.application.analysis.population.TripAnalysis; +import org.matsim.application.options.InputOptions; +import org.matsim.application.options.OutputOptions; +import org.matsim.core.config.Config; +import org.matsim.core.config.ConfigUtils; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.Vehicles; +import picocli.CommandLine; +import tech.tablesaw.api.Table; +import tech.tablesaw.io.csv.CsvReadOptions; +import java.util.Map; + +@CommandLine.Command( + name = "impact" +) +@CommandSpec(requireRunDirectory = true, + requires = {"trip_stats.csv"}, + dependsOn = {TripAnalysis.class}, +// dependsOn = { +// @Dependency(value = TripAnalysis.class, files = "trip_stats.csv") +// // @Dependency(value = AirPollutionAnalysis.class, files = "...") +// }, + produces = { + "data.csv", + } +) public class ImpactAnalysis implements MATSimAppCommand { + @CommandLine.Mixin + private final InputOptions input = InputOptions.ofCommand(ImpactAnalysis.class); + + @CommandLine.Mixin + private final OutputOptions output = OutputOptions.ofCommand(ImpactAnalysis.class); + @Override public Integer call() throws Exception { + + Config config = prepareConfig(); + Scenario scenario = ScenarioUtils.loadScenario(config); + + Vehicles vehicles = scenario.getVehicles(); + + System.out.println("Vehicles: "); + + for (Map.Entry, Vehicle> vehicleEntry : vehicles.getVehicles().entrySet()) { + System.out.println(vehicleEntry.getKey()); + System.out.println(vehicleEntry.getValue()); + } + + + String tripStatsPath = input.getPath("trip_stats.csv"); + System.out.println("Path: " + tripStatsPath); + + + CsvReadOptions options = CsvReadOptions.builder(tripStatsPath) + .header(true) + .separator(',') + .build(); + + + Table tripStatsTable = Table.read().usingOptions(options); + System.out.println("TABLE"); + System.out.println(tripStatsTable.print()); + return 0; } + private Config prepareConfig() { + Config config = ConfigUtils.loadConfig(ApplicationUtils.matchInput("config.xml", input.getRunDirectory()).toAbsolutePath().toString()); + + config.vehicles().setVehiclesFile(ApplicationUtils.matchInput("vehicles", input.getRunDirectory()).toAbsolutePath().toString()); + config.network().setInputFile(ApplicationUtils.matchInput("network", input.getRunDirectory()).toAbsolutePath().toString()); + config.transit().setTransitScheduleFile(ApplicationUtils.matchInput("transitSchedule", input.getRunDirectory()).toAbsolutePath().toString()); + config.transit().setVehiclesFile(ApplicationUtils.matchInput("transitVehicles", input.getRunDirectory()).toAbsolutePath().toString()); + config.plans().setInputFile(null); + config.facilities().setInputFile(null); + config.eventsManager().setNumberOfThreads(null); + config.eventsManager().setEstimatedNumberOfEvents(null); + config.global().setNumberOfThreads(1); + + return config; + } } diff --git a/contribs/simwrapper/src/test/java/org/matsim/simwrapper/dashboard/DashboardTests.java b/contribs/simwrapper/src/test/java/org/matsim/simwrapper/dashboard/DashboardTests.java index e3e92fa87a7..2c798feff26 100644 --- a/contribs/simwrapper/src/test/java/org/matsim/simwrapper/dashboard/DashboardTests.java +++ b/contribs/simwrapper/src/test/java/org/matsim/simwrapper/dashboard/DashboardTests.java @@ -24,7 +24,7 @@ public class DashboardTests { @RegisterExtension - private MatsimTestUtils utils = new MatsimTestUtils(); + private final MatsimTestUtils utils = new MatsimTestUtils(); private void run(Dashboard... dashboards) { @@ -153,4 +153,10 @@ void ptCustom() { Assertions.assertThat(out) .isDirectoryContaining("glob:**pt_pax_volumes.csv.gz"); } + + @Test + void impactAnalysis() { + ImpactAnalysisDashboard impactAnalysisDashboard = new ImpactAnalysisDashboard(); + run(impactAnalysisDashboard); + } }