1 package org.opentrafficsim.kpi.sampling.indicator;
2
3 import org.djunits.unit.FrequencyUnit;
4 import org.djunits.value.vdouble.scalar.Frequency;
5 import org.djunits.value.vdouble.scalar.Time;
6 import org.opentrafficsim.kpi.sampling.Query;
7 import org.opentrafficsim.kpi.sampling.TrajectoryGroup;
8
9
10
11
12
13
14
15
16
17
18
19
20 public class MeanIntensity extends AbstractIndicator<Frequency>
21 {
22
23
24 private final TotalTravelDistance travelDistance;
25
26
27
28
29 public MeanIntensity(final TotalTravelDistance travelDistance)
30 {
31 this.travelDistance = travelDistance;
32 }
33
34
35 @Override
36 protected Frequency calculate(Query query, Time startTime, Time endTime)
37 {
38 double ttd = this.travelDistance.getValue(query, startTime, endTime).si;
39 double area = 0;
40 for (TrajectoryGroup trajectoryGroup : query.getTrajectoryGroups(startTime, endTime))
41 {
42 area += trajectoryGroup.getLength().si * (endTime.si - startTime.si);
43 }
44 return new Frequency(ttd / area, FrequencyUnit.SI);
45 }
46
47 }