21 package org.matsim.analysis;
23 import org.apache.logging.log4j.LogManager;
24 import org.apache.logging.log4j.Logger;
39 import jakarta.inject.Inject;
40 import java.io.BufferedWriter;
41 import java.io.IOException;
42 import java.io.UncheckedIOException;
44 import java.util.TreeMap;
64 private final Map<String, int[]>
legStats =
new TreeMap<>();
80 this.previousActivityTypes.
put(event.
getPersonId(),
event.getActType());
98 if (depTime != null) {
99 double travTime = arrTime - depTime;
101 String toActType =
event.getActType();
102 String legType = fromActType +
"---" + toActType;
103 int[] stats = this.legStats.get(legType);
105 stats =
new int[MAXINDEX + 1];
106 for (
int i = 0; i <=
MAXINDEX; i++) {
109 this.legStats.put(legType, stats);
113 this.sumLegDurations += travTime;
120 public void reset(
final int iteration) {
121 this.previousActivityTypes.
clear();
122 this.agentDepartures.
clear();
123 this.legStats.clear();
124 this.sumLegDurations = 0;
133 int idx = (int) (time_s / SLOT_SIZE);
139 return (this.sumLegDurations / this.sumLegs);
145 }
catch (IOException e) {
150 public void writeStats(
final java.io.Writer out)
throws UncheckedIOException {
152 boolean first =
true;
153 for (Map.Entry<String,
int[]> entry :
this.legStats.entrySet()) {
154 String key = entry.getKey();
155 int[] counts = entry.getValue();
158 out.write(
"pattern");
159 for (
int i = 0; i < counts.length; i++) {
160 out.write(
"\t" + (i * SLOT_SIZE / 60) +
"+");
165 for (
int count : counts) {
166 out.write(
"\t" + count);
171 if (this.sumLegs == 0) {
172 out.write(
"average legs duration: no legs!");
174 out.write(
"average leg duration: " 175 + (this.sumLegDurations / this.sumLegs)
177 +
Time.
writeTime(((
int) (
this.sumLegDurations /
this.sumLegs))));
180 }
catch (IOException e) {
181 throw new UncheckedIOException(e);
185 }
catch (IOException e) {
final IdMap< Person, Double > agentDepartures
void handleEvent(ActivityStartEvent event)
static int getTimeslotIndex(final double time_s)
void handleEvent(final PersonDepartureEvent event)
void writeStats(final String filename)
Id< Person > getPersonId()
static final int SLOT_SIZE
void addHandler(final EventHandler handler)
double getAverageLegDuration()
static BufferedWriter getBufferedWriter(URL url, Charset charset, boolean append)
Id< Person > getPersonId()
final IdMap< Person, String > previousActivityTypes
Id< Person > getPersonId()
void writeStats(final java.io.Writer out)
void handleEvent(ActivityEndEvent event)
void handleEvent(final PersonArrivalEvent event)
static final int MAXINDEX
Id< Person > getPersonId()
static final String writeTime(final double seconds, final String timeformat)
Map< String, int[]> getLegStats()
final IdMap< Person, Double > agentArrivals
void reset(final int iteration)
V put(Id< T > key, V value)
final Map< String, int[]> legStats