Created
August 22, 2017 20:33
-
-
Save ebernhardson/9e8119727ea6d6e053c0877773a678d3 to your computer and use it in GitHub Desktop.
This file contains 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
// The LatencyStat object is a POJO with three fields: bucket, percentile and latency | |
// The goal is to get a new List<LatencyStat> with one object per (bucket, percentile) combination | |
// averaging the latency value between them. | |
Map<String, Map<Double, List<SearchLatencyProbe.LatencyStat>>> foo = nodes.stream() | |
.flatMap(n -> n.statDetails.latencies.stream()) | |
.collect(Collectors.groupingBy(LatencyStat::getBucket, | |
Collectors.groupingBy(LatencyStat::getPercentile))); | |
List<LatencyStat> allNodes = new ArrayList<>(); | |
for (Map.Entry<String, Map<Double, List<LatencyStat>>> bucketEntry : foo.entrySet()) { | |
for (Map.Entry<Double, List<LatencyStat>> percentileEntry : bucketEntry.getValue().entrySet()) { | |
double latency = percentileEntry.getValue().stream().mapToDouble(LatencyStat::getLatencyMs).average().orElse(0D); | |
allNodes.add(new LatencyStat(bucketEntry.getKey(), percentileEntry.getKey(), latency)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment