1 package org.opentrafficsim.kpi.sampling.indicator;
2
3 import org.djunits.value.vdouble.scalar.Duration;
4 import org.djunits.value.vdouble.scalar.Length;
5 import org.djunits.value.vdouble.scalar.Speed;
6 import org.djunits.value.vdouble.scalar.Time;
7 import org.opentrafficsim.kpi.sampling.Query;
8 import org.opentrafficsim.kpi.sampling.Trajectory;
9 import org.opentrafficsim.kpi.sampling.TrajectoryGroup;
10
11
12
13
14
15
16
17
18
19
20
21
22
23 public class TotalDelay extends AbstractIndicator<Duration>
24 {
25
26
27 private final Speed referenceSpeed;
28
29
30
31
32 public TotalDelay(final Speed referenceSpeed)
33 {
34 this.referenceSpeed = referenceSpeed;
35 }
36
37
38 @Override
39 public final Duration calculate(final Query query, final Time startTime, final Time endTime)
40 {
41 Duration sumTime = Duration.ZERO;
42 Length sumDist = Length.ZERO;
43 for (TrajectoryGroup trajectoryGroup : query.getTrajectoryGroups(startTime, endTime))
44 {
45
46 for (Trajectory trajectory : trajectoryGroup.getTrajectories())
47 {
48 sumTime = sumTime.plus(trajectory.getTotalDuration());
49 sumDist = sumDist.plus(trajectory.getTotalLength());
50 }
51 }
52 return sumTime.minus(sumDist.divideBy(this.referenceSpeed));
53 }
54
55
56 @Override
57 @SuppressWarnings("checkstyle:designforextension")
58 public String toString()
59 {
60 return "TotalDelay [referenceSpeed=" + this.referenceSpeed + "]";
61 }
62
63 }