Skip to content

Commit

Permalink
update activity dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
frievoe97 committed Dec 18, 2024
1 parent 47b1292 commit 0b0cd57
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,11 @@ public Integer call() throws Exception {

for (Row row : resultTable) {
Double value = row.getDouble("density");
row.setDouble("relative_density", (((value - averageDensity) / (averageDensity)) * 100));
if (averageDensity != 0) {
row.setDouble("relative_density", value / averageDensity);
} else {
row.setDouble("relative_density", 0.0);
}
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.matsim.simwrapper;

import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigGroup;
import org.matsim.core.config.ReflectiveConfigGroup;

Expand Down Expand Up @@ -28,6 +29,10 @@ public class SimWrapperConfigGroup extends ReflectiveConfigGroup {
@Comment("Set of simple class names or fully qualified class names of dashboards to exclude")
public Set<String> exclude = new HashSet<>();

@Parameter
@Comment("Set of simple class names or fully qualified class names of dashboards to include. Any none included dashboard will be excluded.")
public Set<String> include = new HashSet<>();

@Parameter
@Comment("Sample size of the run, which may be required by certain analysis functions.")
public Double sampleSize = 1.0d;
Expand Down Expand Up @@ -83,6 +88,15 @@ public void addParameterSet(ConfigGroup set) {
}
}

@Override
protected void checkConsistency(Config config) {
super.checkConsistency(config);

if (!include.isEmpty() && !exclude.isEmpty()) {
throw new IllegalStateException("Include and exclude option can't be set both.");
}
}

/**
* Mode how default dashboards are loaded.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public class SimWrapperListener implements StartupListener, ShutdownListener {
@Inject
public SimWrapperListener(SimWrapper simWrapper, Set<Dashboard> bindings, Config config) {
this.simWrapper = simWrapper;
this.bindings = bindings;
this.config = config;
this.bindings = bindings;
this.config = config;
}

/**
Expand Down Expand Up @@ -105,6 +105,9 @@ private void addFromProvider(SimWrapperConfigGroup config, Iterable<DashboardPro
if (config.exclude.contains(d.getClass().getSimpleName()) || config.exclude.contains(d.getClass().getName()))
continue;

if (!config.include.isEmpty() && (!config.include.contains(d.getClass().getSimpleName()) && !config.include.contains(d.getClass().getName())))
continue;

if (!simWrapper.hasDashboard(d.getClass(), d.context()) || d instanceof Dashboard.Customizable) {
log.info("Adding dashboard {}", d);
simWrapper.addDashboard(d);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public class SimWrapperRunner implements MATSimAppCommand {
@CommandLine.Option(names = "--exclude", split = ",", description = "Exclusion that will be added to the config.")
private Set<String> exclude;

@CommandLine.Option(names = "--include", split = ",", description = "Use only the dashboards which classnames match.")
private Set<String> include;

public static void main(String[] args) {
new SimWrapperRunner().execute(args);
}
Expand Down Expand Up @@ -58,6 +61,8 @@ public Integer call() throws Exception {
if (exclude != null)
simWrapperConfigGroup.exclude.addAll(exclude);

if (include != null)
simWrapperConfigGroup.include.addAll(include);

SimWrapperListener listener = new SimWrapperListener(SimWrapper.create(config), config);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

/**
* Dashboard to show activity related statistics aggregated by type and location.
*
* <p>
* Note that {@link #addActivityType(String, List, List, boolean, String)} needs to be called for each activity type.
* There is no default configuration.
*/
Expand Down Expand Up @@ -43,12 +43,13 @@ public ActivityDashboard addActivityType(String name, List<String> activities, L

/**
* Add an activity type to the dashboard.
* @param name name to show in the dashboard
* @param activities List of activity names to include in this type
* @param indicators List of indicators to show
*
* @param name name to show in the dashboard
* @param activities List of activity names to include in this type
* @param indicators List of indicators to show
* @param countMultipleOccurrences Whether multiple occurrences of the same activity for one person should be counted.
* Can be used to count home or workplaces only once.
* @param refCsv Reference CSV file to compare the activities to. Can be null.
* @param refCsv Reference CSV file to compare the activities to. Can be null.
*/
public ActivityDashboard addActivityType(String name, List<String> activities, List<Indicator> indicators,
boolean countMultipleOccurrences, @Nullable String refCsv) {
Expand Down Expand Up @@ -106,7 +107,7 @@ public void configure(Header header, Layout layout) {
viz.display.fill.dataset = "transit-trips";
viz.display.fill.join = REF_JOIN;
if (ind == Indicator.RELATIVE_DENSITY) {
viz.display.fill.setColorRamp(ColorScheme.RdBu, 12, false, "-80,-75,-67,-50,-33,50,100,200,300,400,500");
viz.display.fill.setColorRamp(ColorScheme.RdBu, 12, false, "0.2, 0.25, 0.33, 0.5, 0.67, 1.5, 2.0, 3.0, 4.0, 5.0, 6.0");
}
});

Expand All @@ -126,12 +127,11 @@ public void configure(Header header, Layout layout) {

if (ind == Indicator.RELATIVE_DENSITY) {
viz.display.fill.columnName = "relative_density";
viz.display.fill.setColorRamp(ColorScheme.RdBu, 12, false, "-80,-75,-67,-50,-33,50,100,200,300,400,500");
viz.display.fill.setColorRamp(ColorScheme.RdBu, 12, false, "0.2, 0.25, 0.33, 0.5, 0.67, 1.5, 2.0, 3.0, 4.0, 5.0, 6.0");
} else if (ind == Indicator.DENSITY) {
viz.display.fill.columnName = "density";
} else {
viz.display.fill.columnName = "count";
viz.display.fill.normalize = "transit-trips:area";
}
});
}
Expand Down

0 comments on commit 0b0cd57

Please sign in to comment.