Skip to content

Commit

Permalink
write trip analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
rakow committed Mar 25, 2024
1 parent cdf15b3 commit ffa2f7f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
@CommandLine.Command(name = "trips", description = "Calculates various trip related metrics.")
@CommandSpec(
requires = {"trips.csv", "persons.csv"},
produces = {"mode_share.csv", "mode_share_per_dist.csv", "mode_users.csv", "trip_stats.csv", "population_trip_stats.csv", "trip_purposes_by_hour.csv"}
produces = {"mode_share.csv", "mode_share_per_dist.csv", "mode_users.csv", "trip_stats.csv",
"mode_share_per_%s.csv", "population_trip_stats.csv", "trip_purposes_by_hour.csv"}
)
public class TripAnalysis implements MATSimAppCommand {

Expand Down Expand Up @@ -189,7 +190,7 @@ public Integer call() throws Exception {
writeModeShare(joined, labels);

if (groups != null) {
groups.analyzeModeShare(joined, labels);
groups.analyzeModeShare(joined, labels, (g) -> output.getPath("mode_share_per_%s.csv", g));
}

writePopulationStats(persons, joined);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

import java.io.BufferedReader;
import java.io.IOException;
import java.nio.file.Path;
import java.util.*;
import java.util.function.Function;

import static tech.tablesaw.aggregate.AggregateFunctions.count;

Expand Down Expand Up @@ -82,7 +84,7 @@ final class TripByGroupAnalysis {
}
}

void analyzeModeShare(Table trips, List<String> dists) {
void analyzeModeShare(Table trips, List<String> dists, Function<String, Path> output) {

for (Group group : groups) {

Expand Down Expand Up @@ -114,9 +116,8 @@ void analyzeModeShare(Table trips, List<String> dists) {
.toArray(String[]::new)
);

// TODO: write trip analysis, obtain output path from TripAnalysis
// aggr.write().csv(output.getPath("mode_share_per_dist.csv").toFile());

String name = String.join("_", group.columns);
aggr.write().csv(output.apply(name).toFile());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class TripDashboard implements Dashboard {
@Nullable
private final String modeUsersRefCsv;

private String groupedRefData;

private String[] args;

/**
Expand All @@ -51,6 +53,14 @@ public TripDashboard(@Nullable String modeShareRefCsv, @Nullable String modeShar
args = new String[0];
}

/**
* Set grouped reference data. Will enable additional tab with analysis for subgroups of the population.
*/
public TripDashboard withGroupedRefData(String groupedRefData) {
this.groupedRefData = groupedRefData;
return this;
}

/**
* Set argument that will be passed to the analysis script. See {@link TripAnalysis}.
*/
Expand All @@ -65,6 +75,15 @@ public void configure(Header header, Layout layout) {
header.title = "Trips";
header.description = "General information about modal share and trip distributions.";

String[] args = new String[this.groupedRefData == null ? this.args.length: this.args.length + 2];
System.arraycopy(this.args, 0, args, 0, this.args.length);

// Add ref data to the argument if set
if (groupedRefData != null) {
args[this.args.length] = "--input-ref-data";
args[this.args.length + 1] = groupedRefData;
}

Layout.Row first = layout.row("first");
first.el(Plotly.class, (viz, data) -> {
viz.title = "Modal split";
Expand Down Expand Up @@ -226,5 +245,10 @@ public void configure(Header header, Layout layout) {

});

if (groupedRefData != null) {

// TODO create the additional tab

}
}
}

0 comments on commit ffa2f7f

Please sign in to comment.