Skip to content

Commit

Permalink
prepare new CommandRunner
Browse files Browse the repository at this point in the history
  • Loading branch information
frievoe97 committed Dec 18, 2024
1 parent 52f6c33 commit 1d9af0f
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
* Other commands that produce the input needed by this command.
*/
Class<? extends MATSimAppCommand>[] dependsOn() default {};
// Dependency[] dependsOn() default {};

/**
* Group name / identifier. Will use the package name if this is not changed here.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.matsim.application;

public @interface Dependency {

Class<? extends MATSimAppCommand> value();

String[] files() default {};

boolean required() default false;

}
Original file line number Diff line number Diff line change
@@ -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<Id<Vehicle>, 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

public class DashboardTests {
@RegisterExtension
private MatsimTestUtils utils = new MatsimTestUtils();
private final MatsimTestUtils utils = new MatsimTestUtils();

private void run(Dashboard... dashboards) {

Expand Down Expand Up @@ -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);
}
}

0 comments on commit 1d9af0f

Please sign in to comment.