public double sum() { return list.sum(); }
public double sum() { synchronized( mutex ) { return list.sum(); } }
@Override public double sum() { synchronized( mutex ) { return list.sum(); } }
public double sum() { return list.sum(); }
@Override public double sum() { return list.sum(); }
public double sum() { synchronized( mutex ) { return list.sum(); } }
public double sum() { return list.sum(); }
public double sum() { synchronized( mutex ) { return list.sum(); } }
/** * Constructs a new {@code MovingAverage} * * @param historicalValues list of entry values * @param windowSize length over which to take the average */ public MovingAverage(TDoubleList historicalValues, double total, int windowSize) { if(windowSize <= 0) { throw new IllegalArgumentException("Window size must be > 0"); } this.windowSize = windowSize; calc = new Calculation(); calc.historicalValues = historicalValues == null || historicalValues.size() < 1 ? new TDoubleArrayList(windowSize) : historicalValues; calc.total = total != -1 ? total : calc.historicalValues.sum(); }
/** * Get total revenue distance (in meters) for set of trips. * @param trips * @return total trip distance (in meters) */ public double getTotalDistanceForTrips (Collection<Trip> trips) { TDoubleList distances = new TDoubleArrayList(); for (Trip trip : trips) { distances.add(feed.getTripDistance(trip.trip_id, false)); } return distances.sum(); }
/** * Get average speed for set of trips that begin within the time window in meters per second. * @param trips * @param from * @param to * @return avg. speed (meters per second) */ public double getAverageSpeedForTrips (Collection<Trip> trips, LocalTime from, LocalTime to) { TDoubleList speeds = new TDoubleArrayList(); for (Trip trip : trips) { StopTime firstStopTime = feed.stop_times.ceilingEntry(Fun.t2(trip.trip_id, null)).getValue(); LocalTime tripBeginTime = LocalTime.ofSecondOfDay(firstStopTime.departure_time % 86399); // convert 24hr+ seconds to 0 - 86399 // skip trip if begin time is before or after specified time period if (tripBeginTime.isAfter(to) || tripBeginTime.isBefore(from)) { continue; } // TODO: swap straight lines for actual geometry? double speed = feed.getTripSpeed(trip.trip_id, true); if (!Double.isNaN(speed)) { speeds.add(speed); } } if (speeds.isEmpty()) return -1; return speeds.sum() / speeds.size(); }
double mean = smoothedY.subList(i, i + span).sum() / span; for (int j = i; j < i + span; j++) { smoothedY.set(j, mean);
double mean = smoothedY.subList(i, i + span).sum() / span; for (int j = i; j < i + span; j++) { smoothedY.set(j, mean);