1 package org.opentrafficsim.kpi.sampling.indicator;
2
3 import java.util.HashSet;
4 import java.util.List;
5 import java.util.Set;
6
7 import org.djunits.value.vdouble.scalar.Length;
8 import org.djunits.value.vdouble.scalar.Time;
9 import org.opentrafficsim.kpi.interfaces.GtuDataInterface;
10 import org.opentrafficsim.kpi.sampling.Query;
11 import org.opentrafficsim.kpi.sampling.Trajectory;
12 import org.opentrafficsim.kpi.sampling.TrajectoryGroup;
13
14
15
16
17
18
19
20
21
22
23
24
25 public class MeanTripLength extends AbstractIndicator<Length>
26 {
27
28
29 @Override
30 protected <G extends GtuDataInterface> Length calculate(final Query<G> query, final Time startTime, final Time endTime,
31 final List<TrajectoryGroup<G>> trajectoryGroups)
32 {
33 Length sum = Length.ZERO;
34 Set<String> gtuIds = new HashSet<>();
35 for (TrajectoryGroup<?> trajectoryGroup : trajectoryGroups)
36 {
37 for (Trajectory<?> trajectory : trajectoryGroup.getTrajectories())
38 {
39 sum = sum.plus(trajectory.getTotalLength());
40 gtuIds.add(trajectory.getGtuId());
41 }
42 }
43 return sum.divideBy(gtuIds.size());
44 }
45
46
47 @Override
48 @SuppressWarnings("checkstyle:designforextension")
49 public String toString()
50 {
51 return "MeanTripLength []";
52 }
53
54 }