def handle(self, **options):
        def check_option(name, val):
            try:
                val = int(val)
                if val < 0:
                    raise ValueError()
                return val
            except ValueError:
                raise CommandError(
                    'Invalid value for %s %r' % (name, val)
                )
            except TypeError:
                pass

        limit = check_option('-t', options['limit'])
        max_duration = check_option('-m', options['max_duration'])

        after = options['after']
        if after:
            try:
                after = int(time.time()) - parse_interval(after)
            except ValueError:
                raise CommandError(after % 'Invalid interval %r')

        order = options['order']
        if order not in ('at', 'count', 'average'):
            raise CommandError('Invalid sort order %r' % options['order'])

        client = redis.Redis(
            host=settings.REDIS_HOST,
            port=settings.REDIS_PORT,
        )

        data = {}
        totals = {}
        hits = {}
        results = client.zrangebyscore(
            getattr(settings, 'DUMPSLOW_REDIS_KEY', 'dumpslow'), after, '+inf',
        )

        for line in results:
            view, duration = line.split('\n', 1)

            duration = float(duration)

            if max_duration and duration >= max_duration:
                continue

            if order == 'at':
                try:
                    data[view] += duration
                except KeyError:
                    data[view] = duration

            elif order == 'count':
                try:
                    data[view] += 1
                except KeyError:
                    data[view] = 1

            elif order == 'average':
                try:
                    totals[view] += duration
                    hits[view] += 1
                except KeyError:
                    totals[view] = duration
                    hits[view] = 1

                data[view] = totals[view] / hits[view]


        items = data.items()
        del data
        items.sort(key=itemgetter(1), reverse=not options['reverse'])

        if limit is not None:
            items = items[:limit]

        print "", "View",
        print {
            'count': 'Count',
            'at': 'Accumulated time',
            'average': 'Average time',
        }[order].rjust(66)
        print "", "=" * 71

        for view, value in items:
            pad = 70 - len(view)

            print "", view,
            if order == 'at':
                print ("%2.2f" % value).rjust(pad)
            elif order == 'count':
                print str(value).rjust(pad)
            elif order == 'average':
                print ("%2.2f" % value).rjust(pad)
dataset/ETHPy150Open lamby/django-dumpslow/django_dumpslow/management/commands/dumpslow.py/Command.handle/swapped operands of `%`