@Test public void supportsDifferentAmountOfRatiosToAggregate() { final SimpleMovingAverageRatio cut = new SimpleMovingAverageRatio(4); final List<Optional<Ratio>> ratios = inputRatios.map(p -> cut.smooth(p)).collect(toList()); assertThat(ratios.get(0)).isEmpty(); assertThat(ratios.get(1)).isEmpty(); assertThat(ratios.get(2)).isEmpty(); assertThat(ratios.get(3).get()).isApproximatelyEqualTo(new Ratio(0.145), ALLOWED_OFFSET); assertThat(ratios.get(4).get()).isApproximatelyEqualTo(new Ratio(0.1825), ALLOWED_OFFSET); }
@Override public Optional<Ratio> smooth(final Ratio dataPoint) { ratios.add(dataPoint.asBasic()); if (ratios.size() < aggregationCount) { return Optional.empty(); } double sum = 0; for (final Double ratio : ratios) { sum += ratio; } final double returnVal = sum / aggregationCount; ratios.poll(); return Optional.of(new Ratio(returnVal)); }
SimpleMovingAverageRatio implements Smoother<Ratio> { @Override public Optional<Ratio> smooth(final Ratio dataPoint) { ratios.add(dataPoint.asBasic()); if (ratios.size() < aggregationCount) { return Optional.empty(); } double sum = 0; for (final Double ratio : ratios) { sum += ratio; } final double returnVal = sum / aggregationCount; ratios.poll(); return Optional.of(new Ratio(returnVal)); } }
SimpleMovingAverageRatio implements Smoother<Ratio> { @Override public Optional<Ratio> smooth(final Ratio dataPoint) { ratios.add(dataPoint.asBasic()); if (ratios.size() < aggregationCount) { return Optional.empty(); } double sum = 0; for (final Double ratio : ratios) { sum += ratio; } final double returnVal = sum / aggregationCount; ratios.poll(); return Optional.of(new Ratio(returnVal)); } SimpleMovingAverageRatio(final int aggregationCount); }
SimpleMovingAverageRatio implements Smoother<Ratio> { @Override public Optional<Ratio> smooth(final Ratio dataPoint) { ratios.add(dataPoint.asBasic()); if (ratios.size() < aggregationCount) { return Optional.empty(); } double sum = 0; for (final Double ratio : ratios) { sum += ratio; } final double returnVal = sum / aggregationCount; ratios.poll(); return Optional.of(new Ratio(returnVal)); } SimpleMovingAverageRatio(final int aggregationCount); @Override Optional<Ratio> smooth(final Ratio dataPoint); }
SimpleMovingAverageRatio implements Smoother<Ratio> { @Override public Optional<Ratio> smooth(final Ratio dataPoint) { ratios.add(dataPoint.asBasic()); if (ratios.size() < aggregationCount) { return Optional.empty(); } double sum = 0; for (final Double ratio : ratios) { sum += ratio; } final double returnVal = sum / aggregationCount; ratios.poll(); return Optional.of(new Ratio(returnVal)); } SimpleMovingAverageRatio(final int aggregationCount); @Override Optional<Ratio> smooth(final Ratio dataPoint);  }