Skip to content

Commit bd18be2

Browse files
ddimensiaBrandonArp
authored andcommitted
Adds P75 Statistic to list of available percentile statistics. (#71)
Added support for a 75th Percentile statistic
1 parent 6291bfb commit bd18be2

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Copyright 2017 Dropbox, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.arpnetworking.tsdcore.statistics;
17+
18+
import com.arpnetworking.logback.annotations.Loggable;
19+
20+
/**
21+
* Top 75th percentile statistic. Use <code>StatisticFactory</code> for construction.
22+
*
23+
* @author Gilligan Markham (gmarkham at dropbox dot com)
24+
*/
25+
@Loggable
26+
public final class TP75Statistic extends TPStatistic {
27+
28+
private TP75Statistic() {
29+
super(75d);
30+
}
31+
32+
private static final long serialVersionUID = 1;
33+
}

src/test/java/com/arpnetworking/tsdcore/statistics/StatisticFactoryTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public static Collection<Object[]> createParameters() {
4747
a(l("count", "n"), CountStatistic.class),
4848
a(l("p0", "tp0", "min"), MinStatistic.class),
4949
a(l("p50", "tp50", "median"), MedianStatistic.class),
50+
a(l("p75", "tp75"), TP75Statistic.class),
5051
a(l("p90", "tp90"), TP90Statistic.class),
5152
a(l("p95", "tp95"), TP95Statistic.class),
5253
a(l("p99", "tp99"), TP99Statistic.class),

src/test/java/com/arpnetworking/tsdcore/statistics/TPStatisticTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class TPStatisticTest {
3434

3535
@Test
3636
public void testName() {
37+
Assert.assertEquals("tp75", TP75_STATISTIC.getName());
3738
Assert.assertEquals("tp90", TP90_STATISTIC.getName());
3839
Assert.assertEquals("tp95", TP95_STATISTIC.getName());
3940
Assert.assertEquals("tp99", TP99_STATISTIC.getName());
@@ -42,6 +43,10 @@ public void testName() {
4243

4344
@Test
4445
public void testEquality() {
46+
Assert.assertFalse(TP75_STATISTIC.equals(null));
47+
Assert.assertFalse(TP75_STATISTIC.equals("ABC"));
48+
Assert.assertTrue(TP75_STATISTIC.equals(TP75_STATISTIC));
49+
4550
Assert.assertFalse(TP90_STATISTIC.equals(null));
4651
Assert.assertFalse(TP90_STATISTIC.equals("ABC"));
4752
Assert.assertTrue(TP90_STATISTIC.equals(TP90_STATISTIC));
@@ -61,12 +66,24 @@ public void testEquality() {
6166

6267
@Test
6368
public void testHashCode() {
69+
Assert.assertEquals(TP75_STATISTIC.hashCode(), TP75_STATISTIC.hashCode());
6470
Assert.assertEquals(TP90_STATISTIC.hashCode(), TP90_STATISTIC.hashCode());
6571
Assert.assertEquals(TP95_STATISTIC.hashCode(), TP95_STATISTIC.hashCode());
6672
Assert.assertEquals(TP99_STATISTIC.hashCode(), TP99_STATISTIC.hashCode());
6773
Assert.assertEquals(TP99P9_STATISTIC.hashCode(), TP99P9_STATISTIC.hashCode());
6874
}
6975

76+
@Test
77+
public void testTP75Accumulator() {
78+
final Accumulator<?> accumulator = (Accumulator<?>) HISTOGRAM_STATISTIC.createCalculator();
79+
for (int x = 1; x <= 10000; ++x) {
80+
accumulator.accumulate(new Quantity.Builder().setValue((double) x).build());
81+
}
82+
final CalculatedValue<Void> calculated = TP75_STATISTIC.createCalculator().calculate(
83+
Collections.singletonMap(HISTOGRAM_STATISTIC, accumulator));
84+
Assert.assertTrue(areClose(new Quantity.Builder().setValue(7500.0).build(), calculated.getValue()));
85+
}
86+
7087
@Test
7188
public void testTP90Accumulator() {
7289
final Accumulator<?> accumulator = (Accumulator<?>) HISTOGRAM_STATISTIC.createCalculator();
@@ -132,6 +149,7 @@ private boolean areClose(final Quantity expected, final Quantity actual) {
132149
private static final List<Double> ONE_TO_FIVE = Lists.newArrayList(1d, 2d, 3d, 4d, 5d);
133150
private static final StatisticFactory STATISTIC_FACTORY = new StatisticFactory();
134151
private static final Statistic HISTOGRAM_STATISTIC = STATISTIC_FACTORY.getStatistic("histogram");
152+
private static final TP75Statistic TP75_STATISTIC = (TP75Statistic) STATISTIC_FACTORY.getStatistic("tp75");
135153
private static final TP90Statistic TP90_STATISTIC = (TP90Statistic) STATISTIC_FACTORY.getStatistic("tp90");
136154
private static final TP95Statistic TP95_STATISTIC = (TP95Statistic) STATISTIC_FACTORY.getStatistic("tp95");
137155
private static final TP99Statistic TP99_STATISTIC = (TP99Statistic) STATISTIC_FACTORY.getStatistic("tp99");

0 commit comments

Comments
 (0)