public Optional<IndexInfo> build() { List<Integer> partitions = partitionsSizes.build(); if (partitions.size() == 0) { return Optional.empty(); } double avgSize = partitions.stream().mapToLong(Integer::longValue).average().getAsDouble(); double squaredDifferences = partitions.stream().mapToDouble(size -> Math.pow(size - avgSize, 2)).sum(); checkState(partitions.stream().mapToLong(Integer::longValue).sum() == rowsNumber, "Total number of rows in index does not match number of rows in partitions within that index"); return Optional.of(new IndexInfo(rowsNumber, sizeInBytes, squaredDifferences, partitions.size())); } }
@VisibleForTesting static OptionalDouble calculateAverageRowsPerPartition(Collection<PartitionStatistics> statistics) { return statistics.stream() .map(PartitionStatistics::getBasicStatistics) .map(HiveBasicStatistics::getRowCount) .filter(OptionalLong::isPresent) .mapToLong(OptionalLong::getAsLong) .peek(count -> verify(count >= 0, "count must be greater than or equal to zero")) .average(); }
private static void printStats(Map<String, List<Long>> results) { for (Map.Entry<String, List<Long>> entry : results.entrySet()) { System.out.printf("Results for %s%n", entry.getKey()); System.out.printf("Min merge time=%d%n", entry.getValue().stream().min(Long::compare).get()); System.out.printf("Max merge time=%d%n", entry.getValue().stream().max(Long::compare).get()); System.out.printf("Avg merge time=%s%n", entry.getValue().stream().mapToLong(x -> x).average().getAsDouble()); System.out.printf("===================================================================%n"); } } }
@Override public OptionalDouble getAvgStoreFileAge() { return getStoreFileAgeStream().average(); }
double averageIndexSize = indexInfos.stream() .mapToLong(IndexInfo::getSizeInBytes) .average() .getAsDouble(); double squaredDifferencesSizeOfIndex = indexInfos.stream()
@Override public void run() { for (int i = 0; i < ITERATIONS; i++) { try { iterations.add(runIteration()); } catch (Exception e) { e.printStackTrace(); return; } } System.out.println("Completed " + ITERATIONS + " iterations"); long averageRunTime = (long) iterations.stream().mapToLong(v -> v).average().getAsDouble(); System.out.println(String.format("averageRunTime: %dms", averageRunTime)); try { shutdown(); } catch (Exception e) { e.printStackTrace(); } }
@Override public void run() { for (int i = 0; i < ITERATIONS; i++) { try { iterations.add(runIteration()); } catch (Exception e) { e.printStackTrace(); return; } } System.out.println("Completed " + ITERATIONS + " iterations"); long averageRunTime = (long) iterations.stream().mapToLong(v -> v).average().getAsDouble(); System.out.println(String.format("averageRunTime: %dms", averageRunTime)); try { shutdown(); } catch (Exception e) { e.printStackTrace(); } }
default OptionalDouble average(LongPipeline pipeline) { requireNonNull(pipeline); return optimize(pipeline).getAsLongStream().average(); }
StageStats stageStats = stageInfo.get().getStageStats(); double avgPositionsPerTask = stageInfo.get().getTasks().stream().mapToLong(task -> task.getStats().getProcessedInputPositions()).average().orElse(Double.NaN); double squaredDifferences = stageInfo.get().getTasks().stream().mapToDouble(task -> Math.pow(task.getStats().getProcessedInputPositions() - avgPositionsPerTask, 2)).sum(); double sdAmongTasks = Math.sqrt(squaredDifferences / stageInfo.get().getTasks().size());
/** * The average time in milliseconds between all shards that discord took to respond to our last heartbeat. * This roughly represents the WebSocket ping of this session. If there is no shard running this wil return {@code -1}. * * <p><b>{@link net.dv8tion.jda.core.requests.RestAction RestAction} request times do not * correlate to this value!</b> * * @return The average time in milliseconds between heartbeat and the heartbeat ack response */ default double getAveragePing() { return this.getShardCache() .stream() .mapToLong(JDA::getPing) .filter(ping -> ping != -1) .average() .orElse(-1D); }
private void report(final EndpointStatus endpointStatus) { final int previousStatusCode = rule.endpoint().getStatus().code(); final String previousStatusName = rule.endpoint().getStatus().name(); this.endpointStatus.updateStatus(endpointStatus.isSuccess()); endpointStatus.setState(rule.endpoint().getStatus().code()); endpointStatus.setAvailable(!rule.endpoint().getStatus().isDown()); endpointStatus.setResponseTime((long) endpointStatus.getSteps().stream().mapToLong(Step::getResponseTime).average().getAsDouble()); final boolean transition = previousStatusCode != rule.endpoint().getStatus().code(); endpointStatus.setTransition(transition); if (transition && alertEngineService != null) { final Event.Builder event = new Event.Builder() .timestamp(currentTimeMillis()) .context("Gateway", node.id()) .context("Hostname", node.hostname()) .context("Port", port) .type("HEALTH_CHECK") .prop("API", rule.api()) .prop("Endpoint name", rule.endpoint().getName()) .prop("Old status", previousStatusName) .prop("New status", rule.endpoint().getStatus().name()) .prop("Success", endpointStatus.isSuccess()); final Object tenant = node.metadata().get("tenant"); if (tenant != null) { event.context("Tenant", (String) tenant); } alertEngineService.send(event.build()); } statusHandler.handle(endpointStatus); }
private static void printStats(Map<String, List<Long>> results) { for (Map.Entry<String, List<Long>> entry : results.entrySet()) { System.out.printf("Results for %s%n", entry.getKey()); System.out.printf("Min merge time=%d%n", entry.getValue().stream().min(Long::compare).get()); System.out.printf("Max merge time=%d%n", entry.getValue().stream().max(Long::compare).get()); System.out.printf("Avg merge time=%s%n", entry.getValue().stream().mapToLong(x -> x).average().getAsDouble()); System.out.printf("===================================================================%n"); } } }
public Optional<IndexInfo> build() { List<Integer> partitions = partitionsSizes.build(); if (partitions.size() == 0) { return Optional.empty(); } double avgSize = partitions.stream().mapToLong(Integer::longValue).average().getAsDouble(); double squaredDifferences = partitions.stream().mapToDouble(size -> Math.pow(size - avgSize, 2)).sum(); checkState(partitions.stream().mapToLong(Integer::longValue).sum() == rowsNumber, "Total number of rows in index does not match number of rows in partitions within that index"); return Optional.of(new IndexInfo(rowsNumber, sizeInBytes, squaredDifferences, partitions.size())); } }
public Optional<IndexInfo> build() { List<Integer> partitions = partitionsSizes.build(); if (partitions.size() == 0) { return Optional.empty(); } double avgSize = partitions.stream().mapToLong(Integer::longValue).average().getAsDouble(); double squaredDifferences = partitions.stream().mapToDouble(size -> Math.pow(size - avgSize, 2)).sum(); checkState(partitions.stream().mapToLong(Integer::longValue).sum() == rowsNumber, "Total number of rows in index does not match number of rows in partitions within that index"); return Optional.of(new IndexInfo(rowsNumber, sizeInBytes, squaredDifferences, partitions.size())); } }
private double calcStdDev() { mean = durations.stream().mapToLong(d->d).average().orElse(0.0); double squareDiffSum = 0; for (long dur : durations) { squareDiffSum += Math.pow((dur-mean),2); } return Math.sqrt((squareDiffSum/(durations.size()-1.0))); }
public long toAverageSessionLength() { OptionalDouble average = sessions.stream().map(Session::getLength) .mapToLong(i -> i) .average(); if (average.isPresent()) { return (long) average.getAsDouble(); } return 0L; }
@VisibleForTesting static OptionalDouble calculateAverageRowsPerPartition(Collection<PartitionStatistics> statistics) { return statistics.stream() .map(PartitionStatistics::getBasicStatistics) .map(HiveBasicStatistics::getRowCount) .filter(OptionalLong::isPresent) .mapToLong(OptionalLong::getAsLong) .peek(count -> verify(count >= 0, "count must be greater than or equal to zero")) .average(); }
@Override public OptionalDouble average() { if (context.fjp != null) return context.terminate(stream()::average); return stream().average(); }
/** * Perform an asynchronous average operation * @see java.util.stream.Stream#mapToLong(ToLongFunction) * @see java.util.stream.LongStream#average() * */ default CompletableFuture<OptionalDouble> averageLong(ToLongFunction<? super T> fn){ return CompletableFuture.supplyAsync(()->getStream() .flatMapToLong(t-> LongStream.of(fn.applyAsLong(t))) .average(),getExec()); } /**