def thumbjson(): # TODO: Add support for 'calc of calcs' instead of max all_json = get_graph_data_from_request(request, THUMBNAIL_DAYS) all_results = {} for benchname, entries in all_json['results'].items(): dtToEntries = {} for entry in entries: roundedDt = round_date(entry['key']) dtToEntries.setdefault(roundedDt, []).append(entry['value']) dtToSingleEntry = {dt: dbmath.mean(items) for dt, items in dtToEntries.iteritems()} newresult = [{'key': k, 'value': v} for k, v in sorted(dtToSingleEntry.iteritems())] all_results[benchname] = newresult # Just mutate the original results since we're throwing them away. result = all_json result['results'] = all_results return jsonify(result)
def append_aggregated_data(resultdata): """ Appends an aggregated metrics key onto a result set. :param resultdata: The resultdata should be a dictionary consistent with the dbmodel :return: The result set with aggregated data appended. """ resultdata['AggregateData'] = dict(resultdata['metrics']) for key, entryTimesAndValues in resultdata['AggregateData'].items(): metricvals = [item[1] for item in entryTimesAndValues] resultdata['AggregateData'][key] = { 'mean': dbmath.mean(metricvals), 'median': dbmath.median(metricvals), 'stddev': dbmath.standard_deviation(metricvals), 'min': min(metricvals), 'max': max(metricvals) } return resultdata