<commit_before># -*- coding: utf-8 -*-
import framework
from website.util.permissions import reduce_permissions
from website.filters import gravatar
from website import settings


def get_projects(user):
    '''Return a list of user's projects, excluding registrations and folders.'''
    return [
        node
        for node in user.node__contributed
        if node.category == 'project'
        and not node.is_registration
        and not node.is_deleted
        and not node.is_folder
    ]


def get_public_projects(user):
    '''Return a list of a user's public projects.'''
    return [p for p in get_projects(user) if p.is_public]


def get_gravatar(user, size=None):
    if size is None:
        size = settings.GRAVATAR_SIZE_PROFILE
    return gravatar(
        user, use_ssl=True,
        size=size
    )


def serialize_user(user, node=None, admin=False, full=False):
    """Return a dictionary representation of a registered user.

    :param User user: A User object
    :param bool full: Include complete user properties

    """
    fullname = user.display_full_name(node=node)
    rv = {
        'id': str(user._primary_key),
        'registered': user.is_registered,
        'surname': user.family_name,
        'fullname': fullname,
        'shortname': fullname if len(fullname) < 50 else fullname[:23] + "..." + fullname[-23:],
        'gravatar_url': gravatar(
            user, use_ssl=True,
            size=settings.GRAVATAR_SIZE_ADD_CONTRIBUTOR
        ),
        'active': user.is_active,
    }
    if node is not None:
        if admin:
            flags = {
                'visible': False,
                'permission': 'read',
            }
        else:
            flags = {
                'visible': user._id in node.visible_contributor_ids,
                'permission': reduce_permissions(node.get_permissions(user)),
            }
        rv.update(flags)
    if user.is_registered:
        rv.update({
            'url': user.url,
            'absolute_url': user.absolute_url,
            'display_absolute_url': user.display_absolute_url,
            'date_registered': user.date_registered.strftime("%Y-%m-%d"),
        })

    if full:
        if user.is_merged:
            merger = user.merged_by
            merged_by = {
                'id': str(merger._primary_key),
                'url': merger.url,
                'absolute_url': merger.absolute_url
            }
        else:
            merged_by = None
        rv.update({
            'number_projects': len(get_projects(user)),
            'number_public_projects': len(get_public_projects(user)),
            'activity_points': user.get_activity_points(),
            'gravatar_url': gravatar(
                user, use_ssl=True,
                size=settings.GRAVATAR_SIZE_PROFILE
            ),
            'is_merged': user.is_merged,
            'merged_by': merged_by,
        })

    return rv


def serialize_contributors(contribs, node, **kwargs):
    return [
        serialize_user(contrib, node, **kwargs)
        for contrib in contribs
    ]


def add_contributor_json(user, current_user=None):

    # get shared projects
    if current_user:
        n_projects_in_common = current_user.n_projects_in_common(user)
    else:
        n_projects_in_common = 0

    current_employment = None
    education = None

    if user.jobs:
        current_employment = user.jobs[0]['institution']
<commit_msg>Rename return variable.<commit_after># -*- coding: utf-8 -*-
import framework
from website.util.permissions import reduce_permissions
from website.filters import gravatar
from website import settings


def get_projects(user):
    '''Return a list of user's projects, excluding registrations and folders.'''
    return [
        node
        for node in user.node__contributed
        if node.category == 'project'
        and not node.is_registration
        and not node.is_deleted
        and not node.is_folder
    ]


def get_public_projects(user):
    '''Return a list of a user's public projects.'''
    return [p for p in get_projects(user) if p.is_public]


def get_gravatar(user, size=None):
    if size is None:
        size = settings.GRAVATAR_SIZE_PROFILE
    return gravatar(
        user, use_ssl=True,
        size=size
    )


def serialize_user(user, node=None, admin=False, full=False):
    """Return a dictionary representation of a registered user.

    :param User user: A User object
    :param bool full: Include complete user properties
    """
    fullname = user.display_full_name(node=node)
    ret = {
        'id': str(user._primary_key),
        'registered': user.is_registered,
        'surname': user.family_name,
        'fullname': fullname,
        'shortname': fullname if len(fullname) < 50 else fullname[:23] + "..." + fullname[-23:],
        'gravatar_url': gravatar(
            user, use_ssl=True,
            size=settings.GRAVATAR_SIZE_ADD_CONTRIBUTOR
        ),
        'active': user.is_active,
    }
    if node is not None:
        if admin:
            flags = {
                'visible': False,
                'permission': 'read',
            }
        else:
            flags = {
                'visible': user._id in node.visible_contributor_ids,
                'permission': reduce_permissions(node.get_permissions(user)),
            }
        ret.update(flags)
    if user.is_registered:
        ret.update({
            'url': user.url,
            'absolute_url': user.absolute_url,
            'display_absolute_url': user.display_absolute_url,
            'date_registered': user.date_registered.strftime("%Y-%m-%d"),
        })

    if full:
        if user.is_merged:
            merger = user.merged_by
            merged_by = {
                'id': str(merger._primary_key),
                'url': merger.url,
                'absolute_url': merger.absolute_url
            }
        else:
            merged_by = None
        ret.update({
            'number_projects': len(get_projects(user)),
            'number_public_projects': len(get_public_projects(user)),
            'activity_points': user.get_activity_points(),
            'gravatar_url': gravatar(
                user, use_ssl=True,
                size=settings.GRAVATAR_SIZE_PROFILE
            ),
            'is_merged': user.is_merged,
            'merged_by': merged_by,
        })

    return ret


def serialize_contributors(contribs, node, **kwargs):
    return [
        serialize_user(contrib, node, **kwargs)
        for contrib in contribs
    ]


def add_contributor_json(user, current_user=None):

    # get shared projects
    if current_user:
        n_projects_in_common = current_user.n_projects_in_common(user)
    else:
        n_projects_in_common = 0

    current_employment = None
    education = None

    if user.jobs:
        current_employment = user.jobs[0]['institution']

{'fraction_non_alphanumeric': 0.09985422740524781, 'fraction_numerical': 0.0026239067055393588, 'mean_word_length': 2.1343079031521244, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3795315', 'n_tokens_mistral': 2077, 'n_tokens_neox': 1967, 'n_words': 462}