Skip to content

Commit 97dbddf

Browse files
ddimensiaBrandonArp
authored andcommitted
Added support for 75th percentile statistic. (#71)
1 parent 2e89aaa commit 97dbddf

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
@@ -37,6 +37,7 @@ public class TPStatisticTest {
3737

3838
@Test
3939
public void testName() {
40+
Assert.assertEquals("tp75", TP75_STATISTIC.getName());
4041
Assert.assertEquals("tp90", TP90_STATISTIC.getName());
4142
Assert.assertEquals("tp95", TP95_STATISTIC.getName());
4243
Assert.assertEquals("tp99", TP99_STATISTIC.getName());
@@ -96,6 +97,10 @@ public void testTP999Stat() {
9697

9798
@Test
9899
public void testEquality() {
100+
Assert.assertFalse(TP75_STATISTIC.equals(null));
101+
Assert.assertFalse(TP75_STATISTIC.equals("ABC"));
102+
Assert.assertTrue(TP75_STATISTIC.equals(TP75_STATISTIC));
103+
99104
Assert.assertFalse(TP90_STATISTIC.equals(null));
100105
Assert.assertFalse(TP90_STATISTIC.equals("ABC"));
101106
Assert.assertTrue(TP90_STATISTIC.equals(TP90_STATISTIC));
@@ -115,12 +120,24 @@ public void testEquality() {
115120

116121
@Test
117122
public void testHashCode() {
123+
Assert.assertEquals(TP75_STATISTIC.hashCode(), TP75_STATISTIC.hashCode());
118124
Assert.assertEquals(TP90_STATISTIC.hashCode(), TP90_STATISTIC.hashCode());
119125
Assert.assertEquals(TP95_STATISTIC.hashCode(), TP95_STATISTIC.hashCode());
120126
Assert.assertEquals(TP99_STATISTIC.hashCode(), TP99_STATISTIC.hashCode());
121127
Assert.assertEquals(TP99P9_STATISTIC.hashCode(), TP99P9_STATISTIC.hashCode());
122128
}
123129

130+
@Test
131+
public void testTP75Accumulator() {
132+
final Accumulator<?> accumulator = (Accumulator<?>) HISTOGRAM_STATISTIC.createCalculator();
133+
for (int x = 1; x <= 10000; ++x) {
134+
accumulator.accumulate(new Quantity.Builder().setValue((double) x).build());
135+
}
136+
final CalculatedValue<Void> calculated = TP75_STATISTIC.createCalculator().calculate(
137+
Collections.singletonMap(HISTOGRAM_STATISTIC, accumulator));
138+
Assert.assertTrue(areClose(new Quantity.Builder().setValue(7500.0).build(), calculated.getValue()));
139+
}
140+
124141
@Test
125142
public void testTP90Accumulator() {
126143
final Accumulator<?> accumulator = (Accumulator<?>) HISTOGRAM_STATISTIC.createCalculator();
@@ -186,6 +203,7 @@ private boolean areClose(final Quantity expected, final Quantity actual) {
186203
private static final List<Double> ONE_TO_FIVE = Lists.newArrayList(1d, 2d, 3d, 4d, 5d);
187204
private static final StatisticFactory STATISTIC_FACTORY = new StatisticFactory();
188205
private static final Statistic HISTOGRAM_STATISTIC = STATISTIC_FACTORY.getStatistic("histogram");
206+
private static final TP75Statistic TP75_STATISTIC = (TP75Statistic) STATISTIC_FACTORY.getStatistic("tp75");
189207
private static final TP90Statistic TP90_STATISTIC = (TP90Statistic) STATISTIC_FACTORY.getStatistic("tp90");
190208
private static final TP95Statistic TP95_STATISTIC = (TP95Statistic) STATISTIC_FACTORY.getStatistic("tp95");
191209
private static final TP99Statistic TP99_STATISTIC = (TP99Statistic) STATISTIC_FACTORY.getStatistic("tp99");

0 commit comments

Comments
 (0)