1 package org.opentrafficsim.kpi.sampling.indicator;
2
3 import java.util.List;
4
5 import org.djunits.unit.DimensionlessUnit;
6 import org.djunits.value.vdouble.scalar.Dimensionless;
7 import org.djunits.value.vdouble.scalar.Time;
8 import org.opentrafficsim.kpi.interfaces.GtuDataInterface;
9 import org.opentrafficsim.kpi.sampling.Query;
10 import org.opentrafficsim.kpi.sampling.Trajectory;
11 import org.opentrafficsim.kpi.sampling.TrajectoryGroup;
12
13
14
15
16
17
18
19
20
21
22
23
24 public class TotalNumberOfStops extends AbstractIndicator<Dimensionless>
25 {
26
27
28 @Override
29 protected <G extends GtuDataInterface> Dimensionless calculate(final Query<G> query, final Time startTime,
30 final Time endTime, final List<TrajectoryGroup<G>> trajectoryGroups)
31 {
32 int sum = 0;
33 for (TrajectoryGroup<?> trajectoryGroup : trajectoryGroups)
34 {
35 for (Trajectory<?> trajectory : trajectoryGroup.getTrajectories())
36 {
37 float[] v = trajectory.getV();
38 for (int i = 1; i < v.length; i++)
39 {
40 if (v[i] == 0 && v[i - 1] > 0)
41 {
42 sum++;
43 }
44 }
45 }
46 }
47 return new Dimensionless(sum, DimensionlessUnit.SI);
48 }
49
50
51 @Override
52 @SuppressWarnings("checkstyle:designforextension")
53 public String toString()
54 {
55 return "TotalNumberOfStops []";
56 }
57
58 }