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