public JSONObject getAverages(int minutes, Graph graph, Authorizations authorizations) {
Date minutesAgo = new Date(System.currentTimeMillis() - minutes * 60 * 1000);
Query q = graph.query(authorizations)
.has(VisalloProperties.CONCEPT_TYPE.getPropertyName(), PingOntology.IRI_CONCEPT_PING)
.has(PingOntology.CREATE_DATE.getPropertyName(), Compare.GREATER_THAN, minutesAgo)
.limit(0);
q.addAggregation(new StatisticsAggregation(PingOntology.SEARCH_TIME_MS.getPropertyName(), PingOntology.SEARCH_TIME_MS.getPropertyName()));
q.addAggregation(new StatisticsAggregation(PingOntology.RETRIEVAL_TIME_MS.getPropertyName(), PingOntology.RETRIEVAL_TIME_MS.getPropertyName()));
q.addAggregation(new StatisticsAggregation(PingOntology.GRAPH_PROPERTY_WORKER_WAIT_TIME_MS.getPropertyName(), PingOntology.GRAPH_PROPERTY_WORKER_WAIT_TIME_MS.getPropertyName()));
q.addAggregation(new StatisticsAggregation(PingOntology.LONG_RUNNING_PROCESS_WAIT_TIME_MS.getPropertyName(), PingOntology.LONG_RUNNING_PROCESS_WAIT_TIME_MS.getPropertyName()));
QueryResultsIterable<Vertex> vertices = q.vertices();
StatisticsResult searchTimeAgg = vertices.getAggregationResult(PingOntology.SEARCH_TIME_MS.getPropertyName(), StatisticsResult.class);
StatisticsResult retrievalTimeAgg = vertices.getAggregationResult(PingOntology.RETRIEVAL_TIME_MS.getPropertyName(), StatisticsResult.class);
StatisticsResult gpwWaitTimeAgg = vertices.getAggregationResult(PingOntology.GRAPH_PROPERTY_WORKER_WAIT_TIME_MS.getPropertyName(), StatisticsResult.class);
StatisticsResult lrpWaitTimeAgg = vertices.getAggregationResult(PingOntology.LONG_RUNNING_PROCESS_WAIT_TIME_MS.getPropertyName(), StatisticsResult.class);
JSONObject json = new JSONObject();
json.put("pingCount", searchTimeAgg.getCount());
json.put("averageSearchTime", searchTimeAgg.getAverage());
json.put("averageRetrievalTime", retrievalTimeAgg.getAverage());
json.put("graphPropertyWorkerCount", gpwWaitTimeAgg.getCount());
json.put("averageGraphPropertyWorkerWaitTime", gpwWaitTimeAgg.getAverage());
json.put("longRunningProcessCount", lrpWaitTimeAgg.getCount());
json.put("averageLongRunningProcessWaitTime", lrpWaitTimeAgg.getAverage());
return json;
}