-
Notifications
You must be signed in to change notification settings - Fork 452
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
99 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
contribs/application/src/main/java/org/matsim/application/Dependency.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} |
80 changes: 80 additions & 0 deletions
80
...ribs/application/src/main/java/org/matsim/application/analysis/impact/ImpactAnalysis.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters