1 package org.opentrafficsim.kpi.sampling.indicator;
2
3 import java.util.List;
4
5 import org.djunits.value.vdouble.scalar.Duration;
6 import org.djunits.value.vdouble.scalar.Length;
7 import org.djunits.value.vdouble.scalar.Speed;
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
26 public class TotalDelay extends AbstractIndicator<Duration>
27 {
28
29
30 private final Speed referenceSpeed;
31
32
33
34
35 public TotalDelay(final Speed referenceSpeed)
36 {
37 this.referenceSpeed = referenceSpeed;
38 }
39
40
41 @Override
42 protected <G extends GtuDataInterface> Duration calculate(final Query<G> query, final Time startTime, final Time endTime,
43 final List<TrajectoryGroup<G>> trajectoryGroups)
44 {
45 Duration sumTime = Duration.ZERO;
46 Length sumDist = Length.ZERO;
47 for (TrajectoryGroup<?> trajectoryGroup : trajectoryGroups)
48 {
49
50 for (Trajectory<?> trajectory : trajectoryGroup.getTrajectories())
51 {
52 sumTime = sumTime.plus(trajectory.getTotalDuration());
53 sumDist = sumDist.plus(trajectory.getTotalLength());
54 }
55 }
56 return sumTime.minus(sumDist.divideBy(this.referenceSpeed));
57 }
58
59
60 @Override
61 @SuppressWarnings("checkstyle:designforextension")
62 public String toString()
63 {
64 return "TotalDelay [referenceSpeed=" + this.referenceSpeed + "]";
65 }
66
67 }