def plot_histogram_metric(chart, sample_properties, sample_data, **kwargs):
""" Plot a HistogramMetric from the summary json """
summary_data = sample_data.summary
items = summary_data.get(kwargs['metric_name'], {}).items()
if len(items) < 1:
return None
ordering = kwargs.get('order_by', shared_constants.HISTOGRAM_METRIC_DEFAULT_ORDERING)
if ordering == shared_constants.HISTOGRAM_METRIC_ORDER_INTEGER_BIN:
items.sort(key=lambda x: convert_to_int_gracefully(x[0]))
elif ordering == shared_constants.HISTOGRAM_METRIC_ORDER_DECREASING_FREQUENCY:
items.sort(key=lambda x: -convert_to_int_gracefully(x[1]))
elif ordering == shared_constants.HISTOGRAM_METRIC_ORDER_DECREASING_PROPORTION:
items.sort(key=lambda x: -convert_to_float_gracefully(x[1]))
x, y = zip(*items)
chart['data'][0].update({'x': x, 'y': y})
return chart
评论列表
文章目录