def related_attrs_scan_count(request, cls, attr_names): """ Renders a view that displays the scan counts for the combinations of attributes specified via ``attr_names``. That is, all existing values of all ``attr_names`` are extracted from the objects of ``cls``. For all possible combinations of those values (think n-dimensional matrix), the number of existing scans with that particular combination of values is counted. Currently, ``attr_names`` can only contain one or two attribute names: For one attribute name, the scan counts are displayed relatively (pie chart) and absolutely (bar chart). For two attribute names, the scan counts are displayed in a table/heatmap. """ datetime_range_form, queryset = _get_form_and_queryset(request, cls) attr_verbose_names = [ get_friendly_name_for_attr(cls, n) for n in attr_names ] attrs_scan_count = cls.get_related_attrs_scan_count(attr_names, queryset=queryset) attrs_count = len(attr_names) if attrs_count == 1: attrs_scan_count = OrderedDict( sorted( attrs_scan_count.iteritems(), key=lambda t: t[1], reverse=True ) ) template = 'scan_count_1_attr.html' elif attrs_count == 2: template = 'scan_count_2_attrs.html' else: raise NotImplementedError("View can only handle one or two attributes.") context = { "cls_name": cls._meta.verbose_name_plural, "attr_names": attr_verbose_names, "attrs_scan_count": attrs_scan_count, "datetime_range_form": datetime_range_form, } return render(request, template, context)
def related_attr_scan_intervals(request, cls, attr_name): """ View renders a line chart that displays the scan interval for objects of ``cls``. The scan intervals are grouped by all possible values of ``attr_name`` (i.e. made to "data series"). See ``related_attrs_scan_count`` for details about the grouping. """ datetime_range_form, queryset = _get_form_and_queryset(request, cls) context = { "cls_name": cls._meta.verbose_name_plural, "attr_name": get_friendly_name_for_attr(cls, attr_name), "series": cls.get_related_attr_scan_intervals(attr_name, queryset=queryset), "datetime_range_form": datetime_range_form, } return render(request, "scan_intervals.html", context)