Permalink
Browse files

refactoring the histograms un pocito, added some lower percentiles

  • Loading branch information...
1 parent 2ddc46f commit 44ab5281d457daef8870d67ae307ab7feee89ca9 @mikedanese mikedanese committed Jan 1, 2014
@@ -0,0 +1,114 @@
+package com.raskol.tradebot.dto;
+
+import com.codahale.metrics.Snapshot;
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+import com.raskol.tradebot.metrics.CompleteHistogram;
+import org.joda.time.DateTime;
+
+@JsonPropertyOrder({"label","time","count","min","max","mean","stdDev","median","01thPercentile","1thPercentile",
+ "5thPercentile","25thPercentile","75thPercentile","95thPercentile","99thPercentile","999thPercentile"})
+public class CompleteHistogramDTO {
+ private final String label;
+ private final DateTime time;
+ private final int count;
+ private final long min;
+ private final long max;
+ private final double mean;
+ private final double stdDev;
+ private final double median;
+ private final double _01thPercentile;
+ private final double _1thPercentile;
+ private final double _5thPercentile;
+ private final double _25thPercentile;
+ private final double _75thPercentile;
+ private final double _95thPercentile;
+ private final double _99thPercentile;
+ private final double _999thPercentile;
+
+ public CompleteHistogramDTO(String label, Snapshot snapshot) {
+ this.label = label;
+ this.time = new DateTime();
+ this.count = snapshot.size();
+ this.min = snapshot.getMin();
+ this.max = snapshot.getMax();
+ this.mean = snapshot.getMean();
+ this.stdDev = snapshot.getStdDev();
+ this.median = snapshot.getMedian();
+ this._01thPercentile = snapshot.getValue(0.001);
+ this._1thPercentile = snapshot.getValue(0.01);
+ this._5thPercentile = snapshot.getValue(0.05);
+ this._25thPercentile = snapshot.getValue(0.25);
+ this._75thPercentile = snapshot.getValue(0.75);
+ this._95thPercentile = snapshot.getValue(0.95);
+ this._99thPercentile = snapshot.getValue(0.99);
+ this._999thPercentile = snapshot.getValue(0.999);
+ }
+
+ public static CompleteHistogramDTO from(CompleteHistogram histogram) {
+ return new CompleteHistogramDTO(histogram.getLabel(), histogram.getSnapshot());
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public DateTime getTime() {
+ return time;
+ }
+
+ public int getCount() {
+ return count;
+ }
+
+ public long getMin() {
+ return min;
+ }
+
+ public long getMax() {
+ return max;
+ }
+
+ public double getMean() {
+ return mean;
+ }
+
+ public double getStdDev() {
+ return stdDev;
+ }
+
+ public double getMedian() {
+ return median;
+ }
+
+ public double get01thPercentile() {
+ return _01thPercentile;
+ }
+
+ public double get1thPercentile() {
+ return _1thPercentile;
+ }
+
+ public double get5thPercentile() {
+ return _5thPercentile;
+ }
+
+ public double get25thPercentile() {
+ return _25thPercentile;
+ }
+
+ public double get75thPercentile() {
+ return _75thPercentile;
+ }
+
+ public double get95thPercentile() {
+ return _95thPercentile;
+ }
+
+ public double get99thPercentile() {
+ return _99thPercentile;
+ }
+
+ public double get999thPercentile() {
+ return _999thPercentile;
+ }
+}
@@ -1,86 +0,0 @@
-package com.raskol.tradebot.dto;
-
-import com.fasterxml.jackson.annotation.JsonProperty;
-import org.joda.time.DateTime;
-
-import java.util.Date;
-
-public class HistogramDTO {
- private final String label;
- private final DateTime time;
- private final int count;
- private final long min;
- private final long max;
- private final double mean;
- private final double stdDev;
- private final double median;
- private final double _75thPercentile;
- private final double _95thPercentile;
- private final double _99thPercentile;
- private final double _999thPercentile;
-
- public HistogramDTO(String label, int count, long min, long max, double mean, double stdDev, double median,
- double _75thPercentile, double _95thPercentile, double _99thPercentile, double _999thPercentile) {
- this.label = label;
- this.time = new DateTime();
- this.count = count;
- this.min = min;
- this.max = max;
- this.mean = mean;
- this.stdDev = stdDev;
- this.median = median;
- this._75thPercentile = _75thPercentile;
- this._95thPercentile = _95thPercentile;
- this._99thPercentile = _99thPercentile;
- this._999thPercentile = _999thPercentile;
- }
-
- public String getLabel() {
- return label;
- }
-
- public DateTime getTime() {
- return time;
- }
-
- public int getCount() {
- return count;
- }
-
- public long getMin() {
- return min;
- }
-
- public long getMax() {
- return max;
- }
-
- public double getMean() {
- return mean;
- }
-
- public double getStdDev() {
- return stdDev;
- }
-
- public double getMedian() {
- return median;
- }
-
- public double get75thPercentile() {
- return _75thPercentile;
- }
-
- public double get95thPercentile() {
- return _95thPercentile;
- }
-
- public double get99thPercentile() {
- return _99thPercentile;
- }
-
- public double get999thPercentile() {
- return _999thPercentile;
- }
-
-}
@@ -5,7 +5,6 @@
import com.codahale.metrics.Sampling;
import com.codahale.metrics.Snapshot;
import com.google.common.base.Joiner;
-import com.raskol.tradebot.dto.HistogramDTO;
import java.util.ArrayList;
@@ -57,12 +56,5 @@ public String toString() {
return Joiner.on("</br>").join(sb);
}
-
- public HistogramDTO toDTO() {
- final Snapshot snapshot = reservoir.getSnapshot();
- return new HistogramDTO(getLabel(), snapshot.getValues().length, snapshot.getMin(), snapshot.getMax(), snapshot.getMean(),
- snapshot.getStdDev(), snapshot.getMedian(), snapshot.get75thPercentile(), snapshot.get95thPercentile(),
- snapshot.get99thPercentile(), snapshot.get999thPercentile());
- }
}
@@ -1,8 +1,6 @@
package com.raskol.tradebot.resource;
-import com.google.common.escape.Escaper;
-import com.google.common.html.HtmlEscapers;
-import com.raskol.tradebot.dto.HistogramDTO;
+import com.raskol.tradebot.dto.CompleteHistogramDTO;
import com.raskol.tradebot.metrics.CompleteHistogram;
import com.raskol.tradebot.service.TickerService;
import com.yammer.metrics.annotation.Timed;
@@ -15,20 +13,20 @@
@Path("/transaction")
public class TickerResource {
- public static final Escaper HTML_ESCAPER = HtmlEscapers.htmlEscaper();
private final TickerService tickerService;
public TickerResource(TickerService tickerService) {
this.tickerService = tickerService;
}
@GET
- @Produces("application/json") @Timed
- public List<HistogramDTO> getInfos() {
- final ArrayList<HistogramDTO> histograms = new ArrayList<HistogramDTO>();
- for (CompleteHistogram histogram : tickerService.getHistograms()) {
- histograms.add(histogram.toDTO());
+ @Produces("application/json")
+ @Timed
+ public List<CompleteHistogramDTO> getInfos() {
+ final ArrayList<CompleteHistogramDTO> completeHistograms = new ArrayList<>();
+ for (CompleteHistogram completeHistogram : tickerService.getHistograms()) {
+ completeHistograms.add(CompleteHistogramDTO.from(completeHistogram));
}
- return histograms;
+ return completeHistograms;
}
}

0 comments on commit 44ab528

Please sign in to comment.