use of java.util.LongSummaryStatistics in project accumulo by apache.
the class SummaryIT method getTimestampStats.
private LongSummaryStatistics getTimestampStats(final String table, Connector c, String startRow, String endRow) throws TableNotFoundException {
try (Scanner scanner = c.createScanner(table, Authorizations.EMPTY)) {
scanner.setRange(new Range(startRow, false, endRow, true));
Stream<Entry<Key, Value>> stream = StreamSupport.stream(scanner.spliterator(), false);
LongSummaryStatistics stats = stream.mapToLong(e -> e.getKey().getTimestamp()).summaryStatistics();
return stats;
}
}
use of java.util.LongSummaryStatistics in project MindsEye by SimiaCryptus.
the class TestUtil method plotTime.
/**
* Plot plot canvas.
*
* @param history the history
* @return the plot canvas
*/
public static PlotCanvas plotTime(@Nonnull final List<StepRecord> history) {
try {
final LongSummaryStatistics timeStats = history.stream().mapToLong(x -> x.epochTime).summaryStatistics();
final DoubleSummaryStatistics valueStats = history.stream().mapToDouble(x -> x.fitness).filter(x -> x > 0).summaryStatistics();
@Nonnull final PlotCanvas plot = ScatterPlot.plot(history.stream().map(step -> new double[] { (step.epochTime - timeStats.getMin()) / 1000.0, Math.log10(Math.max(valueStats.getMin(), step.fitness)) }).filter(x -> Arrays.stream(x).allMatch(Double::isFinite)).toArray(i -> new double[i][]));
plot.setTitle("Convergence Plot");
plot.setAxisLabels("Time", "log10(Fitness)");
plot.setSize(600, 400);
return plot;
} catch (@Nonnull final Exception e) {
e.printStackTrace(System.out);
return null;
}
}
use of java.util.LongSummaryStatistics in project pravega by pravega.
the class PeriodicWatermarking method computeWatermark.
/**
* This method takes marks (time + position) of active writers and finds greatest lower bound on time and
* least upper bound on positions and returns the watermark object composed of the two.
* The least upper bound computed from positions may not result in a consistent and complete stream cut.
* So, a positional upper bound is then converted into a stream cut by including segments from higher epoch.
* Also, it is possible that in an effort to fill missing range, we may end up creating an upper bound that
* is composed of segments from highest epoch. In next iteration, from new writer positions, we may be able to
* compute a tighter upper bound. But since watermark has to advance position and time, we will take the upper bound
* of previous stream cut and new stream cut.
*
* @param scope scope
* @param streamName stream name
* @param context operation context
* @param activeWriters marks for all active writers.
* @param previousWatermark previous watermark that was emitted.
* @return CompletableFuture which when completed will contain watermark to be emitted.
*/
private CompletableFuture<Watermark> computeWatermark(String scope, String streamName, OperationContext context, List<Map.Entry<String, WriterMark>> activeWriters, Watermark previousWatermark) {
long requestId = context.getRequestId();
Watermark.WatermarkBuilder builder = Watermark.builder();
ConcurrentHashMap<SegmentWithRange, Long> upperBound = new ConcurrentHashMap<>();
// We are deliberately making two passes over writers - first to find lowest time. Second loop will convert writer
// positions to StreamSegmentRecord objects by retrieving ranges from store. And then perform computation on those
// objects.
LongSummaryStatistics summarized = activeWriters.stream().collect(Collectors.summarizingLong(x -> x.getValue().getTimestamp()));
long lowerBoundOnTime = summarized.getMin();
long upperBoundOnTime = summarized.getMax();
if (lowerBoundOnTime > previousWatermark.getLowerTimeBound()) {
CompletableFuture<List<Map<SegmentWithRange, Long>>> positionsFuture = Futures.allOfWithResults(activeWriters.stream().map(x -> {
return Futures.keysAllOfWithResults(x.getValue().getPosition().entrySet().stream().collect(Collectors.toMap(y -> getSegmentWithRange(scope, streamName, context, y.getKey()), Entry::getValue)));
}).collect(Collectors.toList()));
log.debug(requestId, "Emitting watermark for stream {}/{} with time {}", scope, streamName, lowerBoundOnTime);
return positionsFuture.thenAccept(listOfPositions -> listOfPositions.forEach(position -> {
// add writer positions to upperBound map.
addToUpperBound(position, upperBound);
})).thenCompose(v -> computeStreamCut(scope, streamName, context, upperBound, previousWatermark).thenApply(streamCut -> builder.lowerTimeBound(lowerBoundOnTime).upperTimeBound(upperBoundOnTime).streamCut(ImmutableMap.copyOf(streamCut)).build()));
} else {
// new time is not advanced. No watermark to be emitted.
return CompletableFuture.completedFuture(null);
}
}
use of java.util.LongSummaryStatistics in project j2objc by google.
the class LongSummaryStatisticsTest method test_getMax.
public void test_getMax() {
LongSummaryStatistics lss1 = getLongSummaryStatisticsData1();
assertEquals(100L, lss1.getMax());
}
use of java.util.LongSummaryStatistics in project j2objc by google.
the class LongSummaryStatisticsTest method test_combine.
public void test_combine() {
LongSummaryStatistics lss1 = getLongSummaryStatisticsData2();
LongSummaryStatistics lssCombined = getLongSummaryStatisticsData1();
lssCombined.combine(lss1);
assertEquals(12, lssCombined.getCount());
assertEquals(118L, lssCombined.getSum());
assertEquals(100L, lssCombined.getMax());
assertEquals(-5L, lssCombined.getMin());
assertEquals(9.833333, lssCombined.getAverage(), 1E-6);
}
Aggregations