# 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
    # make a password dict keyed by users_id
    passwords_map = {}
    for password in passwords:
        owner = password['owner']
        if owner in passwords_map:
            passwords_map[owner] += 1
        else:
            passwords_map[owner] = 1

    return passwords_map


def users_with_most_passwords(users, passwords, amount):
    passwords_map = get_passwords_map(passwords)
    users_map = dict([(user['_id'], user) for user in users])

    passwords_list = sorted(
        passwords_map.items(),
        key=operator.itemgetter(1),
        reverse=True,
        )[:amount]

    result = []
    for password_owner, amount in passwords_list:
        result.append((users_map[password_owner], amount))

    return result, len(passwords_map)


def statistics():

# 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

    # make a password dict keyed by users_id
    passwords_map = {}
    for password in passwords:
        owner = password['owner']
        if owner in passwords_map:
            passwords_map[owner] += 1
        else:
            passwords_map[owner] = 1

    return passwords_map


def users_with_most_passwords(users, passwords, amount):
    passwords_map = get_passwords_map(passwords)
    users_map = dict([(user['_id'], user) for user in users])

    passwords_list = sorted(
        passwords_map.items(),
        key=operator.itemgetter(1),
        reverse=True,
        )[:amount]

    result = []
    for password_owner, amount in passwords_list:
        result.append((users_map[password_owner], amount))

    return result, len(passwords_map)


def statistics():

    result = setup_simple_command(