21 package org.matsim.analysis;
23 import java.io.BufferedWriter;
24 import java.io.IOException;
25 import java.nio.file.Files;
26 import java.nio.file.Paths;
27 import java.util.AbstractMap;
29 import java.util.TreeMap;
30 import java.util.TreeSet;
31 import java.util.stream.Collectors;
32 import jakarta.inject.Inject;
33 import org.apache.commons.csv.CSVFormat;
34 import org.apache.commons.csv.CSVPrinter;
35 import org.apache.logging.log4j.LogManager;
36 import org.jfree.chart.axis.CategoryLabelPositions;
54 private final static String
FILENAME =
"pkm_modestats";
63 Map<String,Double> pmtbyMode = map.
values()
65 .flatMap(plan -> plan.getPlanElements().stream())
66 .filter(
Leg.class::isInstance)
70 if (Double.isNaN(dist)) {dist = 0.0; }
71 return new AbstractMap.SimpleEntry<>(leg.getMode(),dist);
73 .collect(Collectors.toMap(AbstractMap.SimpleEntry::getKey, AbstractMap.SimpleEntry::getValue, Double::sum));
74 pmtPerIteration.put(iteration,pmtbyMode);
80 new Thread(this::writePng).start();
89 CSVPrinter csvPrinter =
new CSVPrinter(writer, CSVFormat.Builder.create().setDelimiter((this.
delimiter.charAt(0))).build());
93 }
catch (IOException e) {
94 LogManager.getLogger(getClass()).error(
"Could not write PKM Modestats.");
98 private void writeHeader(CSVPrinter csvPrinter, TreeSet<String> allModes)
throws IOException {
99 csvPrinter.print(
"Iteration");
100 csvPrinter.printRecord(allModes);
103 private void writeValues(CSVPrinter csvPrinter, TreeSet<String> allModes)
throws IOException {
104 for (Map.Entry<Integer,Map<String,Double>> e :
pmtPerIteration.entrySet()){
105 csvPrinter.print(e.getKey());
106 for (String mode : allModes){
107 csvPrinter.print((
int) Math.round(e.getValue().getOrDefault(mode, 0.0) / 1000.0));
109 csvPrinter.println();
117 categories[i++] = it.toString();
122 chart.
getChart().getCategoryPlot().getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_90);
126 .mapToDouble(k->k.getOrDefault(mode,0.0)/1000.0)
140 .flatMap(i -> i.keySet().stream())
141 .collect(Collectors.toCollection(TreeSet::new));
void writeValues(CSVPrinter csvPrinter, TreeSet< String > allModes)
void addSeries(final String title, final double[] values)
final Map< Integer, Map< String, Double > > pmtPerIteration
final OutputDirectoryHierarchy controllerIO
static final String FILENAME
void saveAsPng(final String filename, final int width, final int height)
void writeHeader(CSVPrinter csvPrinter, TreeSet< String > allModes)
final String getOutputFilename(final String filename)
TreeSet< String > getAllModes()
String getDefaultDelimiter()