# Path: zenodo/modules/metrics/proxies.py



import calendar
import requests
from datetime import datetime, timedelta
from elasticsearch_dsl import Search
from flask import current_app
from invenio_accounts.models import User
from invenio_communities.models import Community
from invenio_files_rest.models import FileInstance
from invenio_search import current_search_client
from invenio_search.utils import build_alias_name
from .proxies import current_metrics
    @staticmethod
    def get_data_transfer():
        """Get file transfer volume in TB."""
        time_range = {'gte': current_metrics.metrics_start_date.isoformat()}

        search = Search(
            using=current_search_client,
            index=build_alias_name('stats-file-download-*')
        ).filter(
            'range', timestamp=time_range,
        ).filter(
            'term', is_parent=False,
        )
        search.aggs.metric('download_volume', 'sum', field='volume')
        result = search[:0].execute().aggregations.to_dict()
        download_volume = result.get('download_volume', {}).get('value', 0)

        search = Search(
            using=current_search_client,
            index=build_alias_name('records')
        ).filter('range', created=time_range)
        search.aggs.metric('upload_volume', 'sum', field='size')
        result = search[:0].execute().aggregations.to_dict()
        upload_volume = result.get('upload_volume', {}).get('value', 0)

        return int(download_volume + upload_volume)

    @staticmethod
    def get_visitors():
        """Get number of unique zenodo users."""

# Path: zenodo/modules/metrics/proxies.py



# Path: zenodo/modules/metrics/api.py
import calendar
import requests
from datetime import datetime, timedelta
from elasticsearch_dsl import Search
from flask import current_app
from invenio_accounts.models import User
from invenio_communities.models import Community
from invenio_files_rest.models import FileInstance
from invenio_search import current_search_client
from invenio_search.utils import build_alias_name
from .proxies import current_metrics

    @staticmethod
    def get_data_transfer():
        """Get file transfer volume in TB."""
        time_range = {'gte': current_metrics.metrics_start_date.isoformat()}

        search = Search(
            using=current_search_client,
            index=build_alias_name('stats-file-download-*')
        ).filter(
            'range', timestamp=time_range,
        ).filter(
            'term', is_parent=False,
        )
        search.aggs.metric('download_volume', 'sum', field='volume')
        result = search[:0].execute().aggregations.to_dict()
        download_volume = result.get('download_volume', {}).get('value', 0)

        search = Search(
            using=current_search_client,
            index=build_alias_name('records')
        ).filter('range', created=time_range)
        search.aggs.metric('upload_volume', 'sum', field='size')
        result = search[:0].execute().aggregations.to_dict()
        upload_volume = result.get('upload_volume', {}).get('value', 0)

        return int(download_volume + upload_volume)

    @staticmethod
    def get_visitors():
        """Get number of unique zenodo users."""

        time_range = {'gte': current_metrics.metrics_start_date.isoformat()}