View Javadoc
1   package org.opentrafficsim.kpi.sampling.indicator;
2   
3   import org.djunits.value.vdouble.scalar.Duration;
4   import org.djunits.value.vdouble.scalar.Time;
5   import org.opentrafficsim.kpi.sampling.Query;
6   import org.opentrafficsim.kpi.sampling.Trajectory;
7   import org.opentrafficsim.kpi.sampling.TrajectoryGroup;
8   
9   /**
10   * Sum of trajectory durations.
11   * <p>
12   * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
13   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
14   * <p>
15   * @version $Revision$, $LastChangedDate$, by $Author$, initial version Sep 22, 2016 <br>
16   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
17   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
18   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
19   */
20  public class TotalTravelTime extends AbstractIndicator<Duration>
21  {
22  
23      /** {@inheritDoc} */
24      @Override
25      public final Duration calculate(final Query query, final Time startTime, final Time endTime)
26      {
27          Duration sum = Duration.ZERO;
28          for (TrajectoryGroup trajectoryGroup : query.getTrajectoryGroups(startTime, endTime))
29          {
30              for (Trajectory trajectory : trajectoryGroup.getTrajectories())
31              {
32                  sum = sum.plus(trajectory.getTotalDuration());
33              }
34          }
35          return sum;
36      }
37  
38      /** {@inheritDoc} */
39      @Override
40      @SuppressWarnings("checkstyle:designforextension")
41      public String toString()
42      {
43          return "TotalTravelTime []";
44      }
45  
46  }