@detail_route()
    def calculated_usage(self, request, uuid):
        """
        Find max or min utilization of cpu, memory and storage of the instance within timeframe.
        """
        # XXX: Hack. Should be removed after zabbix refactoring
        if not ZABBIX_ENABLED:
            raise Http404()

        instance = self.get_object()
        if not instance.backend_id:
            return Response({'detail': 'calculated usage is not available for instance without backend_id'},
                            status=status.HTTP_409_CONFLICT)

        default_start = datetime.timedelta(hours=1) - timezone.now()
        timestamp_interval_serializer = core_serializers.TimestampIntervalSerializer(data={
            'start': request.query_params.get('from', datetime_to_timestamp(default_start)),
            'end': request.query_params.get('to', datetime_to_timestamp(timezone.now()))
        })
        timestamp_interval_serializer.is_valid(raise_exception=True)

        filter_data = timestamp_interval_serializer.get_filter_data()
        start = datetime_to_timestamp(filter_data['start'])
        end = datetime_to_timestamp(filter_data['end'])

        mapped = {
            'items': request.query_params.getlist('item'),
            'method': request.query_params.get('method'),
        }
        serializer = serializers.CalculatedUsageSerializer(data={k: v for k, v in mapped.items() if v})
        serializer.is_valid(raise_exception=True)
        results = serializer.get_stats(instance, start, end)
        return Response(results, status=status.HTTP_200_OK)
dataset/ETHPy150Open opennode/nodeconductor/nodeconductor/iaas/views.py/InstanceViewSet.calculated_usage/swapped operands of `-`