# Path: invenio_stats/proxies.py

# 
# Path: invenio_stats/tasks.py
# @shared_task
# def aggregate_events(aggregations, start_date=None, end_date=None,
#                      update_bookmark=True):
#     """Aggregate indexed events."""
#     start_date = dateutil_parse(start_date) if start_date else None
#     end_date = dateutil_parse(end_date) if end_date else None
#     results = []
#     for aggr_name in aggregations:
#         aggr_cfg = current_stats.aggregations[aggr_name]
#         aggregator = aggr_cfg.cls(name=aggr_cfg.name, **aggr_cfg.params)
#         results.append(aggregator.run(start_date, end_date, update_bookmark))
#     return results
# 
# @shared_task
# def process_events(event_types):
#     """Index statistics events."""
#     results = []
#     for event_name in event_types:
#         event_cfg = current_stats.events[event_name]
#         processor = event_cfg.cls(**event_cfg.params)
#         results.append((event_name, processor.run()))
#     return results


from functools import wraps
from dateutil.parser import parse as dateutil_parse
from flask.cli import with_appcontext
from werkzeug.local import LocalProxy
from .proxies import current_stats
from .tasks import aggregate_events, process_events
import click
        raise click.BadParameter(
            'Invalid aggregation type(s): {}. Valid values: {}'.format(
                ', '.join(invalid_values),
                ', '.join(current_stats.aggregations)))
    return value


aggr_arg = click.argument(
    'aggregation-types', nargs=-1, callback=_validate_aggregation_type)


@click.group()
def stats():
    """Statistics commands."""


@stats.group()
def events():
    """Event management commands."""


@events.command('process')
@click.argument('event-types', nargs=-1, callback=_validate_event_type)
@click.option('--eager', '-e', is_flag=True)
@with_appcontext
def _events_process(event_types=None, eager=False):
    """Process stats events."""
    # NOTE: event_types is a LocalProxy so it needs to be casted to be passed
    # to celery
    event_types = list(event_types or current_stats.events)

# Path: invenio_stats/proxies.py

# 
# Path: invenio_stats/tasks.py
# @shared_task
# def aggregate_events(aggregations, start_date=None, end_date=None,
#                      update_bookmark=True):
#     """Aggregate indexed events."""
#     start_date = dateutil_parse(start_date) if start_date else None
#     end_date = dateutil_parse(end_date) if end_date else None
#     results = []
#     for aggr_name in aggregations:
#         aggr_cfg = current_stats.aggregations[aggr_name]
#         aggregator = aggr_cfg.cls(name=aggr_cfg.name, **aggr_cfg.params)
#         results.append(aggregator.run(start_date, end_date, update_bookmark))
#     return results
# 
# @shared_task
# def process_events(event_types):
#     """Index statistics events."""
#     results = []
#     for event_name in event_types:
#         event_cfg = current_stats.events[event_name]
#         processor = event_cfg.cls(**event_cfg.params)
#         results.append((event_name, processor.run()))
#     return results


# Path: invenio_stats/cli.py
from functools import wraps
from dateutil.parser import parse as dateutil_parse
from flask.cli import with_appcontext
from werkzeug.local import LocalProxy
from .proxies import current_stats
from .tasks import aggregate_events, process_events
import click

        raise click.BadParameter(
            'Invalid aggregation type(s): {}. Valid values: {}'.format(
                ', '.join(invalid_values),
                ', '.join(current_stats.aggregations)))
    return value


aggr_arg = click.argument(
    'aggregation-types', nargs=-1, callback=_validate_aggregation_type)


@click.group()
def stats():
    """Statistics commands."""


@stats.group()
def events():
    """Event management commands."""


@events.command('process')
@click.argument('event-types', nargs=-1, callback=_validate_event_type)
@click.option('--eager', '-e', is_flag=True)
@with_appcontext
def _events_process(event_types=None, eager=False):
    """Process stats events."""
    # NOTE: event_types is a LocalProxy so it needs to be casted to be passed
    # to celery
    event_types = list(event_types or current_stats.events)

    process_task = process_events.si(event_types)