From cab0b80d9cbfc0da9cc3b824ddd05b30fd755636 Mon Sep 17 00:00:00 2001 From: rakow Date: Tue, 11 Jun 2024 21:51:58 +0200 Subject: [PATCH] add plots for distance distributions --- .../analysis/population/TripAnalysis.java | 2 +- .../population/TripByGroupAnalysis.java | 4 +- .../simwrapper/dashboard/TripDashboard.java | 74 +++++++++++++------ 3 files changed, 55 insertions(+), 25 deletions(-) diff --git a/contribs/application/src/main/java/org/matsim/application/analysis/population/TripAnalysis.java b/contribs/application/src/main/java/org/matsim/application/analysis/population/TripAnalysis.java index ef2c70e726a..fb21949caf3 100644 --- a/contribs/application/src/main/java/org/matsim/application/analysis/population/TripAnalysis.java +++ b/contribs/application/src/main/java/org/matsim/application/analysis/population/TripAnalysis.java @@ -217,7 +217,7 @@ public Integer call() throws Exception { writeModeShare(joined, labels); if (groups != null) { - groups.analyzeModeShare(joined, labels, (g) -> output.getPath("mode_share_per_%s.csv", g)); + groups.analyzeModeShare(joined, labels, modeOrder, (g) -> output.getPath("mode_share_per_%s.csv", g)); } if (persons.containsColumn(ATTR_REF_MODES)) { diff --git a/contribs/application/src/main/java/org/matsim/application/analysis/population/TripByGroupAnalysis.java b/contribs/application/src/main/java/org/matsim/application/analysis/population/TripByGroupAnalysis.java index 7a0787767cf..47edfec0824 100644 --- a/contribs/application/src/main/java/org/matsim/application/analysis/population/TripByGroupAnalysis.java +++ b/contribs/application/src/main/java/org/matsim/application/analysis/population/TripByGroupAnalysis.java @@ -84,7 +84,7 @@ final class TripByGroupAnalysis { } } - void analyzeModeShare(Table trips, List dists, Function output) { + void analyzeModeShare(Table trips, List dists, List modeOrder, Function output) { for (Group group : groups) { @@ -101,7 +101,7 @@ void analyzeModeShare(Table trips, List dists, Function ou // Sort by dist_group and mode Comparator cmp = Comparator.comparingInt(row -> dists.indexOf(row.getString("dist_group"))); - aggr = aggr.sortOn(cmp.thenComparing(row -> row.getString("main_mode"))); + aggr = aggr.sortOn(cmp.thenComparingInt(row -> modeOrder.indexOf(row.getString("main_mode")))); // Norm each group to 1 String norm = group.columns.get(0); diff --git a/contribs/simwrapper/src/main/java/org/matsim/simwrapper/dashboard/TripDashboard.java b/contribs/simwrapper/src/main/java/org/matsim/simwrapper/dashboard/TripDashboard.java index 1900daa6c34..a248f9c298d 100644 --- a/contribs/simwrapper/src/main/java/org/matsim/simwrapper/dashboard/TripDashboard.java +++ b/contribs/simwrapper/src/main/java/org/matsim/simwrapper/dashboard/TripDashboard.java @@ -364,32 +364,62 @@ private void createGroupedTab(Layout layout, String[] args) { for (String cat : Objects.requireNonNull(categories, "Categories not set")) { - layout.row("category_" + cat, "By Groups").el(Plotly.class, (viz, data) -> { + layout.row("category_" + cat, "By Groups") + .el(Plotly.class, (viz, data) -> { + + viz.title = "Mode share"; + viz.description = "by " + cat; + viz.layout = tech.tablesaw.plotly.components.Layout.builder() + .xAxis(Axis.builder().title("share").build()) + .barMode(tech.tablesaw.plotly.components.Layout.BarMode.STACK) + .build(); + + Plotly.DataMapping ds = viz.addDataset(data.computeWithPlaceholder(TripAnalysis.class, "mode_share_per_%s.csv", cat)) + .pivot(List.of("main_mode", "dist_group", cat), "source", "share") + .aggregate(List.of("main_mode", "source", cat), "share", Plotly.AggrFunc.SUM) + .rename("sim_share", "Sim") + .rename("ref_share", "Ref") + .mapping() + .facetCol(cat) + .name("main_mode") + .x("source") + .y("share"); + + + viz.addTrace(BarTrace.builder(Plotly.OBJ_INPUT, Plotly.INPUT) + .orientation(BarTrace.Orientation.VERTICAL) + .build(), ds); + + }).el(Plotly.class, (viz, data) -> { + viz.title = "Modal distance distribution"; + viz.description = "by " + cat; + viz.layout = tech.tablesaw.plotly.components.Layout.builder() + .xAxis(Axis.builder().title("Distance group").build()) + .yAxis(Axis.builder().title("Share").build()) + .barMode(tech.tablesaw.plotly.components.Layout.BarMode.STACK) + .build(); + + // TODO: should use facet row, but does not work yet + // TODO: hard to see, because too many bars + Plotly.DataMapping ds = viz.addDataset(data.computeWithPlaceholder(TripAnalysis.class, "mode_share_per_%s.csv", cat)) + .pivot(List.of("main_mode", "dist_group", cat), "source", "share") + .normalize(List.of("dist_group", "source", cat), "share") + .rename("sim_share", "Sim") + .rename("ref_share", "Ref") + .mapping() + .facetCol(cat) + .name("main_mode") + .x("dist_group") + .y("share"); - viz.title = "Mode share"; - viz.description = "by " + cat; - viz.layout = tech.tablesaw.plotly.components.Layout.builder() - .xAxis(Axis.builder().title("share").build()) - .barMode(tech.tablesaw.plotly.components.Layout.BarMode.STACK) - .build(); + viz.multiIndex = Map.of("dist_group", "source"); - // TODO: Still in testing - Plotly.DataMapping ds = viz.addDataset(data.computeWithPlaceholder(TripAnalysis.class, "mode_share_per_%s.csv", cat)) - .pivot(List.of("main_mode", "dist_group", cat), "source", "share") - .aggregate(List.of("main_mode", "source", cat), "share", Plotly.AggrFunc.SUM) - .rename("sim_share", "Sim") - .rename("ref_share", "Ref") - .mapping() - .facetCol(cat) - .name("main_mode") - .x("share") - .y("source"); + viz.addTrace(BarTrace.builder(Plotly.OBJ_INPUT, Plotly.INPUT) + .orientation(BarTrace.Orientation.VERTICAL) + .build(), ds); - viz.addTrace(BarTrace.builder(Plotly.OBJ_INPUT, Plotly.INPUT) - .orientation(BarTrace.Orientation.HORIZONTAL) - .build(), ds); - }); + }); } }