<commit_before>from django.core.exceptions import ObjectDoesNotExist
from django.shortcuts import *

import json
from judge.models import Contest, Problem, Profile
from judge.templatetags.timedelta import nice_repr


def api_contest_list(request):
    js = {}
    for c in Contest.objects.filter(is_public=True):
        js[c.key] = {
            'name': c.name,
            'free_start': c.free_start,
            'start_time': c.start_time.isoformat() if c.start_time is not None else None,
            'time_limit': nice_repr(c.time_limit, 'concise'),
            'ongoing': c.ongoing
        }
    jso = json.dumps(js)
    return HttpResponse(jso, mimetype='application/json')


def api_problem_list(request):
    js = {}
    for p in Problem.objects.filter(is_public=True):
        js[p.code] = {
            'points': p.points,
            'partial': p.partial,
            'name': p.name,
            'group': p.group.full_name
        }
    jso = json.dumps(js)
    return HttpResponse(jso, mimetype='application/json')


def api_problem_info(request, problem):
    js = {}
    try:
        p = Problem.objects.get(code=problem)
        js = {
            'name': p.name,
            'authors': [a.user.username for a in p.authors.all()],
            'types': [t.full_name for t in p.types.all()],
            'group': p.group.full_name,
            'time_limit': p.time_limit,
            'memory_limit': p.memory_limit,
            'points': p.points,
            'partial': p.partial,
            'languages': list(p.allowed_languages.values_list('key', flat=True)),
        }
    except ObjectDoesNotExist:
        pass
    jso = json.dumps(js)
    return HttpResponse(jso, mimetype='application/json')


def api_user_list(request):
    js = {}
    for p in Profile.objects.all():
        js[p.user.username] = {
            'display_name': p.name,
            'points': p.points,
            'rank': p.display_rank
        }
    jso = json.dumps(js)
    return HttpResponse(jso, mimetype='application/json')


def api_user_info(request, user):
    js = {}
    try:
        p = Profile.objects.get(user__username=user)
        js = {
            'display_name': p.name,
            'points': p.points,
            'rank': p.display_rank,
            'solved_problems': [],  # TODO
        }
    except ObjectDoesNotExist:
        pass
    jso = json.dumps(js)
    return HttpResponse(jso, mimetype='application/json')<commit_msg>Please don't eat changes.<commit_after>from django.core.exceptions import ObjectDoesNotExist
from django.shortcuts import *

import json
from judge.models import Contest, Problem, Profile
from judge.templatetags.timedelta import nice_repr


def api_contest_list(request):
    js = {}
    for c in Contest.objects.filter(is_public=True):
        js[c.key] = {
            'name': c.name,
            'free_start': c.free_start,
            'start_time': c.start_time.isoformat() if c.start_time is not None else None,
            'time_limit': nice_repr(c.time_limit, 'concise'),
            'ongoing': c.ongoing
        }
    return HttpResponse(json.dumps(js), mimetype='application/json')


def api_problem_list(request):
    js = {}
    for p in Problem.objects.filter(is_public=True):
        js[p.code] = {
            'points': p.points,
            'partial': p.partial,
            'name': p.name,
            'group': p.group.full_name
        }
    return HttpResponse(json.dumps(js), mimetype='application/json')


def api_problem_info(request, problem):
    try:
        p = Problem.objects.get(code=problem)
        js = {
            'name': p.name,
            'authors': list(p.authors.values_list('user__username', flat=True)),
            'types': list(p.types.values_list('full_name', flat=True)),
            'group': p.group.full_name,
            'time_limit': p.time_limit,
            'memory_limit': p.memory_limit,
            'points': p.points,
            'partial': p.partial,
            'languages': list(p.allowed_languages.values_list('key', flat=True)),
        }
    except ObjectDoesNotExist:
        raise Http404()
    return HttpResponse(json.dumps(js), mimetype='application/json')


def api_user_list(request):
    js = {}
    for p in Profile.objects.select_related('user'):
        js[p.user.username] = {
            'display_name': p.name,
            'points': p.points,
            'rank': p.display_rank
        }
    return HttpResponse(json.dumps(js), mimetype='application/json')


def api_user_info(request, user):
    try:
        p = Profile.objects.get(user__username=user)
        js = {
            'display_name': p.name,
            'points': p.points,
            'rank': p.display_rank,
            'solved_problems': [],  # TODO
        }
    except ObjectDoesNotExist:
        raise Http404()
    return HttpResponse(json.dumps(js), mimetype='application/json')
{'fraction_non_alphanumeric': 0.12946979038224415, 'fraction_numerical': 0.0012330456226880395, 'mean_word_length': 2.28186109238031, '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': '6466920', 'n_tokens_mistral': 1570, 'n_tokens_neox': 1534, 'n_words': 300}