Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aggregations: multi-event, multi-field aggregator #58

Open
slint opened this issue Jun 15, 2018 · 0 comments
Open

aggregations: multi-event, multi-field aggregator #58

slint opened this issue Jun 15, 2018 · 0 comments

Comments

@slint
Copy link
Member

slint commented Jun 15, 2018

Design an Aggregator class that can aggregate different kind of events and fields into a single document. This satisfies the need to keep track of statistics on e.g. the record level (record views, record downloads, etc).

Example produced document:

# Index "stats-record-2018-06"
{
    '_id': "recid-1234-2018-06-01",  # one document for each recid and day
    'recid': '1234',
    'conceptrecid': 'C_1234',  # included for aggregated version queries
    'doi': '10.5555/1234',
    'conceptdoi': '10.5555/C_1234',
    
    # aggregated from "record-view" events
    'views': 100,
    'unique_views': 60,
    'machine_views': 100,
    'unique_machine_views': 60,
    
    # aggregated from counting "file-download" events
    'downloads': 100,
    'unique_downloads': 60,
    'machine_downloads': 100,
    'unique_machine_downloads': 60,
    # aggregated from summing up the "size" field from "file-download" events
    'download_volume': 100,
    'unique_download_volume': 60,
    'machine_download_volume': 100,
    'unique_machine_download_volume': 60,
}

Example config for the aggregation:

dict(
    aggregation_name='record-agg',
    templates='invenio_stats.contrib.aggregations.aggr_file_download',
    aggregator_class=StatAggregator,
    aggregator_config=dict(
        client=current_search_client,
        doc_id_field='recid',
        aggregations={
            'views': {
                'event': 'record-view',
                'field': 'recid',
                'filters': ['no_robots'],
            },
            'uq_views': {
                'event': 'record-view',
                'field': 'recid_session_id',
                'filters': ['no_robots'],
            },
            'machine_views': {
                'event': 'record-view',
                'field': 'recid',
                'filters': ['no_robots', 'is_machine'],
            },
            'uq_machine_views': {
                'event': 'record-view',
                'field': 'recid_session_id',
                'filters': ['no_robots', 'is_machine'],
            },
            'downloads': {
                'event': 'file-download',
                'field': 'recid',
                'metric': ('cardinality', 'recid + visitor_id'),
                'filters': ['no_robots'],
            },
            'uq_downloads': {
                'event': 'file-download',
                'field': 'recid',
                'metric': ('cardinality', 'recid + session_id'),
                'filters': ['no_robots'],
            },
            'download_volume': {
                'event': 'file-download',
                'metric': ('sum', 'size'),
                'field': 'recid',
                'filters': ['no_robots'],
            },
            'uq_download_volume': {
                'event': 'file-download',
                'metric': ('sum', 'size'),
                'field': 'recid + session_id',
                'filters': ['no_robots'],
            },
        },
        aggregation_interval='day',
        copy_fields=dict(
            file_key='file_key',
            bucket_id='bucket_id',
            file_id='file_id',
        )
)))
@slint slint changed the title aggreagations: multi-event, multi-field aggregator aggregations: multi-event, multi-field aggregator Jun 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant