コード例 #1
0
ファイル: Ride.java プロジェクト: hannesj/OpenTripPlanner
 /**
  * Produce stats about boarding an initial Ride, which has no previous ride. This assumes arrival
  * times are uniformly distributed during the window. The Ride must contain some trips, and the
  * window must have a positive duration.
  */
 public Stats calcStatsForBoarding(TimeWindow window) {
   Stats stats = new Stats();
   stats.min = 0; // You can always arrive just before a train departs.
   List<Integer> departures = getSortedStoptimes(window, false);
   int last = window.from;
   double avgAccumulated = 0.0;
   /* All departures in the list are known to be running and within the window. */
   for (int dep : departures) {
     int maxWait = dep - last;
     if (maxWait > stats.max) stats.max = maxWait;
     /* Weight the average of each interval by the number of seconds it contains. */
     avgAccumulated += (maxWait / 2.0) * maxWait;
     stats.num += maxWait;
     last = dep;
   }
   if (stats.num > 0) {
     stats.avg = (int) (avgAccumulated / stats.num);
   }
   return stats;
 }