1 package org.opentrafficsim.kpi.sampling.indicator;
2
3 import java.util.List;
4
5 import org.djunits.value.vdouble.scalar.Speed;
6 import org.djunits.value.vdouble.scalar.Time;
7 import org.opentrafficsim.kpi.interfaces.GtuDataInterface;
8 import org.opentrafficsim.kpi.sampling.Query;
9 import org.opentrafficsim.kpi.sampling.TrajectoryGroup;
10
11
12
13
14
15
16
17
18
19
20
21
22 public class MeanSpeed extends AbstractIndicator<Speed>
23 {
24
25
26 private final TotalTravelDistance travelDistance;
27
28
29 private final TotalTravelTime travelTime;
30
31
32
33
34
35 public MeanSpeed(final TotalTravelDistance travelDistance, final TotalTravelTime travelTime)
36 {
37 this.travelDistance = travelDistance;
38 this.travelTime = travelTime;
39 }
40
41
42 @Override
43 protected <G extends GtuDataInterface> Speed calculate(final Query<G> query, final Time startTime, final Time endTime,
44 final List<TrajectoryGroup<G>> trajectoryGroups)
45 {
46 return this.travelDistance.getValue(query, startTime, endTime, trajectoryGroups)
47 .divideBy(this.travelTime.getValue(query, startTime, endTime, trajectoryGroups));
48 }
49
50
51 @Override
52 @SuppressWarnings("checkstyle:designforextension")
53 public String toString()
54 {
55 return "MeanSpeed [travelDistance=" + this.travelDistance + ", travelTime=" + this.travelTime + "]";
56 }
57
58 }