Created
June 16, 2015 19:11
-
-
Save jsanda/726b2151704638841b53 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void findAvg() throws Exception { | |
DateTime start = now().minusMinutes(30); | |
DateTime end = start.plusMinutes(20); | |
String tenantId = "t1"; | |
metricsService.createTenant(new Tenant(tenantId)).toBlocking().lastOrDefault(null); | |
Metric<Double> m1 = new Metric<>(tenantId, GAUGE, new MetricId("m1"), asList( | |
new DataPoint<>(start.getMillis(), 1.1), | |
new DataPoint<>(start.plusMinutes(2).getMillis(), 2.2), | |
new DataPoint<>(start.plusMinutes(4).getMillis(), 3.3), | |
new DataPoint<>(end.getMillis(), 4.4) | |
)); | |
Observable<Void> insertObservable = metricsService.addGaugeData(Observable.just(m1)); | |
insertObservable.toBlocking().lastOrDefault(null); | |
Observable<DataPoint<Double>> observable = metricsService.findGaugeData("t1", new MetricId("m1"), | |
start.getMillis(), end.getMillis()); | |
// Double avg = MathObservable.averageDouble(observable.map(DataPoint::getValue)).toBlocking().last(); | |
List<Double> values = toList(observable.map(DataPoint::getValue)); | |
double sum = 0.0; | |
for (double value : values) { | |
sum += value; | |
} | |
double avg = sum / values.size(); | |
assertEquals(avg, (1.1 + 2.2 + 3.3 + 4.4) / 4, "The data does not match the expected values"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment