# Path: yithlibraryserver/user/accounts.py
# def get_available_providers():
#     return ('facebook', 'google', 'twitter', 'persona')
# 
# Path: yithlibraryserver/user/accounts.py
# def get_provider_key(provider):
#     return '%s_id' % provider
# 
# def get_n_passwords(db, user):
#     return db.passwords.find({
#             'owner': user.get('_id', None),
#             }, safe=True).count()
# 
# Path: yithlibraryserver/scripts/utils.py
# def safe_print(value):
#     if PY3:  # pragma: no cover
#         print(value)
#     else:  # pragma: no cover
#         print(value.encode('utf-8'))
# 
# def setup_simple_command(name, description):
#     usage = name + ": %prog config_uri"
#     parser = optparse.OptionParser(
#         usage=usage,
#         description=textwrap.dedent(description)
#         )
#     options, args = parser.parse_args(sys.argv[1:])
#     if not len(args) >= 1:
#         safe_print('You must provide at least one argument')
#         return 2
#     config_uri = args[0]
#     env = bootstrap(config_uri)
#     settings, closer = env['registry'].settings, env['closer']
# 
#     return settings, closer, env, args[1:]
# 
# Path: yithlibraryserver/scripts/utils.py
# def get_user_display_name(user):
#     return '%s %s <%s>' % (user.get('first_name', ''),
#                            user.get('last_name', ''),
#                            user.get('email', ''))


import operator
from yithlibraryserver.user.accounts import get_available_providers
from yithlibraryserver.user.accounts import get_provider_key, get_n_passwords
from yithlibraryserver.scripts.utils import safe_print, setup_simple_command
from yithlibraryserver.scripts.utils import get_user_display_name
        # How many users allow the analytics cookie
        n_allow_cookie = db.users.find({'allow_google_analytics': True}).count()

        all_users = list(db.users.find())

        # Identity providers
        by_identity = group_by_identity_provider(all_users)

        # Email providers
        by_email, without_email = group_by_email_provider(all_users, 1)
        with_email = n_users - without_email

        # Top ten users
        all_passwords = list(db.passwords.find())
        most_active_users, users_with_passwords = users_with_most_passwords(
            all_users, all_passwords, 10)

        # print the statistics
        safe_print('Number of users: %d' % n_users)
        safe_print('Number of passwords: %d' % n_passwords)
        safe_print('Verified users: %.2f%% (%d)' % (
                (100.0 * n_verified) / n_users, n_verified))
        safe_print('Users that allow Google Analytics cookie: %.2f%% (%d)' % (
                (100.0 * n_allow_cookie) / n_users, n_allow_cookie))

        safe_print('Identity providers:')
        for provider, amount in by_identity:
            safe_print('\t%s: %.2f%% (%d)' % (
                    provider, (100.0 * amount) / n_users, amount))


# Path: yithlibraryserver/user/accounts.py
# def get_available_providers():
#     return ('facebook', 'google', 'twitter', 'persona')
# 
# Path: yithlibraryserver/user/accounts.py
# def get_provider_key(provider):
#     return '%s_id' % provider
# 
# def get_n_passwords(db, user):
#     return db.passwords.find({
#             'owner': user.get('_id', None),
#             }, safe=True).count()
# 
# Path: yithlibraryserver/scripts/utils.py
# def safe_print(value):
#     if PY3:  # pragma: no cover
#         print(value)
#     else:  # pragma: no cover
#         print(value.encode('utf-8'))
# 
# def setup_simple_command(name, description):
#     usage = name + ": %prog config_uri"
#     parser = optparse.OptionParser(
#         usage=usage,
#         description=textwrap.dedent(description)
#         )
#     options, args = parser.parse_args(sys.argv[1:])
#     if not len(args) >= 1:
#         safe_print('You must provide at least one argument')
#         return 2
#     config_uri = args[0]
#     env = bootstrap(config_uri)
#     settings, closer = env['registry'].settings, env['closer']
# 
#     return settings, closer, env, args[1:]
# 
# Path: yithlibraryserver/scripts/utils.py
# def get_user_display_name(user):
#     return '%s %s <%s>' % (user.get('first_name', ''),
#                            user.get('last_name', ''),
#                            user.get('email', ''))


# Path: yithlibraryserver/scripts/reports.py
import operator
from yithlibraryserver.user.accounts import get_available_providers
from yithlibraryserver.user.accounts import get_provider_key, get_n_passwords
from yithlibraryserver.scripts.utils import safe_print, setup_simple_command
from yithlibraryserver.scripts.utils import get_user_display_name

        # How many users allow the analytics cookie
        n_allow_cookie = db.users.find({'allow_google_analytics': True}).count()

        all_users = list(db.users.find())

        # Identity providers
        by_identity = group_by_identity_provider(all_users)

        # Email providers
        by_email, without_email = group_by_email_provider(all_users, 1)
        with_email = n_users - without_email

        # Top ten users
        all_passwords = list(db.passwords.find())
        most_active_users, users_with_passwords = users_with_most_passwords(
            all_users, all_passwords, 10)

        # print the statistics
        safe_print('Number of users: %d' % n_users)
        safe_print('Number of passwords: %d' % n_passwords)
        safe_print('Verified users: %.2f%% (%d)' % (
                (100.0 * n_verified) / n_users, n_verified))
        safe_print('Users that allow Google Analytics cookie: %.2f%% (%d)' % (
                (100.0 * n_allow_cookie) / n_users, n_allow_cookie))

        safe_print('Identity providers:')
        for provider, amount in by_identity:
            safe_print('\t%s: %.2f%% (%d)' % (
                    provider, (100.0 * amount) / n_users, amount))


        safe_print('Email providers:')