def get(self, request, name): '''Retrieves the plot values for metrics and return them in JSON form :param request: the HTTP GET request :type request: :class:`rest_framework.request.Request` :rtype: :class:`rest_framework.response.Response` :returns: the HTTP response to send back to the user ''' started = rest_util.parse_timestamp(request, 'started', required=False) ended = rest_util.parse_timestamp(request, 'ended', required=False) rest_util.check_time_range(started, ended) choice_ids = rest_util.parse_string_list(request, 'choice_id', required=False) column_names = rest_util.parse_string_list(request, 'column', required=False) group_names = rest_util.parse_string_list(request, 'group', required=False) try: provider = registry.get_provider(name) metrics_type = provider.get_metrics_type(include_choices=False) except MetricsTypeError: raise Http404 # Build a unique set of column names from groups columns = metrics_type.get_column_set(column_names, group_names) # Get the actual plot values metrics_values = provider.get_plot_data(started, ended, choice_ids, columns) page = rest_util.perform_paging(request, metrics_values) if len(choice_ids) > 1: serializer = MetricsPlotMultiListSerializer(page, context={'request': request}) else: serializer = MetricsPlotListSerializer(page, context={'request': request}) return Response(serializer.data, status=status.HTTP_200_OK)
def list_impl(self, request, name): """Retrieves the plot values for metrics and return them in JSON form :param request: the HTTP GET request :type request: :class:`rest_framework.request.Request` :param name: the name of the metrics detail to retrieve. :type name: string :rtype: :class:`rest_framework.response.Response` :returns: the HTTP response to send back to the user """ started = rest_util.parse_timestamp(request, 'started', required=False) ended = rest_util.parse_timestamp(request, 'ended', required=False) rest_util.check_time_range(started, ended) choice_ids = rest_util.parse_string_list(request, 'choice_id', required=False) column_names = rest_util.parse_string_list(request, 'column', required=False) group_names = rest_util.parse_string_list(request, 'group', required=False) try: provider = registry.get_provider(name) metrics_type = provider.get_metrics_type(include_choices=False) except MetricsTypeError: raise Http404 # Build a unique set of column names from groups columns = metrics_type.get_column_set(column_names, group_names) # Get the actual plot values metrics_values = provider.get_plot_data(started, ended, choice_ids, columns) page = self.paginate_queryset(metrics_values) if len(choice_ids) > 1: serializer = MetricsPlotMultiSerializer(page, many=True) else: serializer = MetricsPlotSerializer(page, many=True) return self.get_paginated_response(serializer.data)
def list(self, request, name): """Retrieves the plot values for metrics and return them in JSON form :param request: the HTTP GET request :type request: :class:`rest_framework.request.Request` :param name: the name of the metrics detail to retrieve. :type name: string :rtype: :class:`rest_framework.response.Response` :returns: the HTTP response to send back to the user """ started = rest_util.parse_timestamp(request, 'started', required=False) ended = rest_util.parse_timestamp(request, 'ended', required=False) rest_util.check_time_range(started, ended) choice_ids = rest_util.parse_string_list(request, 'choice_id', required=False) column_names = rest_util.parse_string_list(request, 'column', required=False) group_names = rest_util.parse_string_list(request, 'group', required=False) try: provider = registry.get_provider(name) metrics_type = provider.get_metrics_type(include_choices=False) except MetricsTypeError: raise Http404 # Build a unique set of column names from groups columns = metrics_type.get_column_set(column_names, group_names) # Get the actual plot values metrics_values = provider.get_plot_data(started, ended, choice_ids, columns) page = self.paginate_queryset(metrics_values) if len(choice_ids) > 1: serializer = MetricsPlotMultiSerializer(page, many=True) else: serializer = MetricsPlotSerializer(page, many=True) return self.get_paginated_response(serializer.data)