/** * Return the average of the histogram. */ public Optional<Double> avg() { if (isEmpty()) return Optional.empty(); return Optional.of(sum() / getEventCount()); }
@Override public String configString() { return value_.toString(); } @Override
/** * Get the value at the given percentile. */ public double percentile(double percentile) { return get(percentile * getEventCount() / 100); }
((HistogramContext)_localctx).s = new Histogram(elems.stream());
@Override protected AvgAgg map_(MetricValue x) { final Optional<AvgAgg> hist_params = x.histogram().map(h -> new AvgAgg(h.sum(), h.getEventCount())); if (hist_params.isPresent()) return hist_params.get(); return x.value() .map(Number::doubleValue) .map(x_number -> new AvgAgg(x_number, 1)) .orElseGet(() -> new AvgAgg(0, 0)); } @Override
private MetricValue interpolate(MetricValue a, MetricValue b) { if ((a.getBoolValue() != null || a.getIntValue() != null || a.getFltValue() != null) && (b.getBoolValue() != null || b.getIntValue() != null || b.getFltValue() != null)) return MetricValue.fromDblValue(backWeight * a.value().get().doubleValue() + forwWeight * b.value().get().doubleValue()); if (a.getStrValue() != null && b.getStrValue() != null) return a; if (a.getHistValue() != null && b.getHistValue() != null) { return MetricValue.fromHistValue(Histogram.add( Histogram.multiply(a.getHistValue(), backWeight), Histogram.multiply(b.getHistValue(), forwWeight))); } // Mismatched types, return empty metric value. return MetricValue.EMPTY; } }
@Override public boolean equals(Object other) { if (other == null) return false; if (!(other instanceof HistogramMetricValue)) return false; return value_.equals(((HistogramMetricValue)other).value_); } @Override
@Override public int compareTo(MetricValue o) { if (__type_comparison_index() < o.__type_comparison_index()) return -1; if (__type_comparison_index() > o.__type_comparison_index()) return 1; return value_.compareTo(((HistogramMetricValue)o).value_); } }
/** * Create a histogram from a set of ranges with associated event counters. * * @throws IllegalArgumentException If the items contain mixed signs. */ public Histogram(Stream<RangeWithCount> items) { final List<RangeWithCount> iter = cleanup_(items.map(RangeWithCount::clone).collect(Collectors.toList())); if (iter.isEmpty()) { buckets_ = EMPTY_LIST; return; } if (iter.stream() .map(RangeWithCount::getCount) .map(Math::signum) .distinct() .count() > 1) { throw new IllegalArgumentException("mixed sign"); } final List<Bucket> buckets = new ArrayList<>(iter.size()); double running_total = 0; for (RangeWithCount rwc : iter) { running_total += rwc.getCount(); buckets.add(new Bucket(rwc.getRange(), rwc.getCount(), running_total)); } buckets_ = unmodifiableList(buckets); }
((HistogramContext)_localctx).s = new Histogram(elems.stream());
/** * Get the value at the given percentile. */ public double percentile(double percentile) { return get(percentile * getEventCount() / 100); }
@Override public boolean equals(Object other) { if (other == null) return false; if (!(other instanceof HistogramMetricValue)) return false; return value_.equals(((HistogramMetricValue)other).value_); } @Override
@Override public int compareTo(MetricValue o) { if (__type_comparison_index() < o.__type_comparison_index()) return -1; if (__type_comparison_index() > o.__type_comparison_index()) return 1; return value_.compareTo(((HistogramMetricValue)o).value_); } }
/** * Create a histogram from a set of ranges with associated event counters. * * @throws IllegalArgumentException If the items contain mixed signs. */ public Histogram(Stream<RangeWithCount> items) { final List<RangeWithCount> iter = cleanup_(items.map(RangeWithCount::clone).collect(Collectors.toList())); if (iter.isEmpty()) { buckets_ = EMPTY_LIST; return; } if (iter.stream() .map(RangeWithCount::getCount) .map(Math::signum) .distinct() .count() > 1) { throw new IllegalArgumentException("mixed sign"); } final List<Bucket> buckets = new ArrayList<>(iter.size()); double running_total = 0; for (RangeWithCount rwc : iter) { running_total += rwc.getCount(); buckets.add(new Bucket(rwc.getRange(), rwc.getCount(), running_total)); } buckets_ = unmodifiableList(buckets); }
/** * Return the average of the histogram. */ public Optional<Double> avg() { if (isEmpty()) return Optional.empty(); return Optional.of(sum() / getEventCount()); }
((HistogramContext)_localctx).s = new Histogram(elems.stream());
@Override public String configString() { return value_.toString(); } @Override