<commit_before>from db import session
import model
import util

def fake_profile():
	return { 'profile': { 'id': 0, 'signed_in': False } }

def to_json(user, profile):
	task_scores = { task: points for task, points in util.user.points_per_task(user.id).items() if points is not None }
	tasks = { task.id: task for task in session.query(model.Task) }

	return {
		'profile': [ _profile_to_json(user, profile, task_scores) ],
		'tasks': [ util.task.to_json(task) for task in task_scores.keys() ],
		'taskScores': [ task_score_to_json(task, points, user) for task, points in task_scores.items() ]
	}

def _profile_to_json(user, profile, task_scores):
	points = util.user.sum_points(user.id)
	summary = sum(util.task.max_points_dict().values())
	successful = round((float(points)/summary) * 100) if summary != 0 else 0

	return {
		'id': user.id,
		'signed_in': True,
		'first_name': user.first_name,
		'last_name': user.last_name,
		'profile_picture': util.user.get_profile_picture(user),
		'short_info': user.short_info,
		'email': user.email,
		'gender': user.sex,
		'addr_street': profile.addr_street,
		'addr_city': profile.addr_city,
		'addr_zip': profile.addr_zip,
		'addr_country': profile.addr_country,
		'school_name': profile.school_name,
		'school_street': profile.school_street,
		'school_city': profile.school_city,
		'school_zip': profile.school_zip,
		'school_country': profile.school_country,
		'school_finish': profile.school_finish,
		'tshirt_size': profile.tshirt_size,
		'achievements': list(util.achievement.ids_set(user.achievements)),
		'percentile': util.user.percentile(user.id),
		'score': points,
		'seasons': 1,
		'successful': int(successful),
		'results': [ task.id for task in task_scores.keys() ]
	}


def task_score_to_json(task, points, user):
	return {
		'id': task.id,
		'task': task.id,
		'achievements': [ achievement.achievement_id for achievement in session.query(model.UserAchievement).filter(model.UserAchievement.user_id == user.id, model.UserAchievement.task_id == task.id).all()],
		'score': points
	}<commit_msg>Add user role.<commit_after>from db import session
import model
import util

def fake_profile():
        return { 'profile': { 'id': 0, 'signed_in': False } }

def to_json(user, profile):
        task_scores = { task: points for task, points in util.user.points_per_task(user.id).items() if points is not None }
        tasks = { task.id: task for task in session.query(model.Task) }

        return {
                'profile': [ _profile_to_json(user, profile, task_scores) ],
                'tasks': [ util.task.to_json(task) for task in task_scores.keys() ],
                'taskScores': [ task_score_to_json(task, points, user) for task, points in task_scores.items() ]
        }

def _profile_to_json(user, profile, task_scores):
        points = util.user.sum_points(user.id)
        summary = sum(util.task.max_points_dict().values())
        successful = round((float(points)/summary) * 100) if summary != 0 else 0

        return {
                'id': user.id,
                'signed_in': True,
                'first_name': user.first_name,
                'last_name': user.last_name,
                'profile_picture': util.user.get_profile_picture(user),
                'short_info': user.short_info,
                'email': user.email,
                'gender': user.sex,
                'addr_street': profile.addr_street,
                'addr_city': profile.addr_city,
                'addr_zip': profile.addr_zip,
                'addr_country': profile.addr_country,
                'school_name': profile.school_name,
                'school_street': profile.school_street,
                'school_city': profile.school_city,
                'school_zip': profile.school_zip,
                'school_country': profile.school_country,
                'school_finish': profile.school_finish,
                'tshirt_size': profile.tshirt_size,
                'achievements': list(util.achievement.ids_set(user.achievements)),
                'percentile': util.user.percentile(user.id),
                'score': points,
                'seasons': 1,
                'successful': int(successful),
                'results': [ task.id for task in task_scores.keys() ],
                'role': user.role
        }


def task_score_to_json(task, points, user):
        return {
                'id': task.id,
                'task': task.id,
                'achievements': [ achievement.achievement_id for achievement in session.query(model.UserAchievement).filter(model.UserAchievement.user_id == user.id, model.UserAchievement.task_id == task.id).all()],
                'score': points
        }
{'fraction_non_alphanumeric': 0.13210773834972211, 'fraction_numerical': 0.002992731936725096, 'mean_word_length': 2.902418682235196, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1597579', 'n_tokens_mistral': 1560, 'n_tokens_neox': 1461, 'n_words': 304}