human
Solve the following python programming problem given the following code:
@query.command()
@click.argument('metrics', nargs=(-1), type=click.Choice(['organization_total_received', 'organization_total_rejected', 'organization_total_blacklisted']))
@click.option('--since', callback=DateTimeParamType())
@click.option('--until', callback=DateTimeParamType())
@configuration
def organizations(metrics, since, until):
assistant
#Here is the Python code you requested.

    """Fetch metrics for organizations.
    """
    from django.utils import timezone
    from sentry.app import tsdb
    from sentry.models import Organization
    stdout = click.get_text_stream('stdout')
    stderr = click.get_text_stream('stderr')
    def aggregate(series):
        return sum((value for (timestamp, value) in series))
    metrics = OrderedDict(((name, getattr(tsdb.models, name)) for name in metrics))
    if (not metrics):
        return
    if (until is None):
        until = timezone.now()
    if (since is None):
        since = (until - timedelta(minutes=60))
    if (until < since):
        raise click.ClickException('invalid    time    range    provided:    {}    to    {}'.format(since, until))
    stderr.write('Dumping    {}    from    {}    to    {}...\n'.format(',    '.join(metrics.keys()), since, until))
    objects = Organization.objects.all()
    for chunk in chunked(objects, 100):
        instances = OrderedDict(((instance.pk, instance) for instance in chunk))
        results = {}
        for metric in metrics.values():
            results[metric] = tsdb.get_range(metric, instances.keys(), since, until)
        for (key, instance) in six.iteritems(instances):
            values = []
            for metric in metrics.values():
                values.append(aggregate(results[metric][key]))
            stdout.write('{}    {}    {}\n'.format(instance.id, instance.slug, '    '.join(map(six.binary_type, values))))