<commit_before>#-*- coding: utf-8 -*-
import ujson

from django.http import HttpResponse, Http404
from django.core.cache import cache
from django.core.management import call_command
from django.db import connection

RACES_PER_VIEW = 25


def last_races(request):
    cursor = connection.cursor()
    query = "SELECT id, info, category, genre, link, location, discipline, raceId, date FROM rankings_races ORDER BY date DESC LIMIT " + \
        str(RACES_PER_VIEW) + ";"
    cursor.execute(query)
    races = dictfetchall(cursor)
    races = ujson.dumps(races, encode_html_chars=False, ensure_ascii=False)
    res = HttpResponse(
        races,
        content_type="application/json"
    )
    return res


def race(request, pk):
    pk = str(int(pk))
    cursor = connection.cursor()
    query = "SELECT id, info, category, genre, link, location, discipline, `table`, raceId, date FROM rankings_races WHERE id='" + \
        pk + "';"
    cursor.execute(query)
    races = dictfetchall(cursor)[0]
    races = ujson.dumps(races, encode_html_chars=False, ensure_ascii=False)
    res = HttpResponse(
        races,
        content_type="application/json"
    )
    return res


def race_category(request, category):
    if category not in ['WC', 'EC', 'FIS']:
        return Http404
    page = request.GET.get('page')
    page = 0 if page is None else (int(page) - 1)
    offset = RACES_PER_VIEW * page
    cursor = connection.cursor()
    query = "SELECT id, info, category, genre, link, location, discipline, raceId, date FROM rankings_races WHERE category='" + \
        category + "' ORDER BY date DESC LIMIT " + \
            str(offset) + ", " + str(RACES_PER_VIEW) + ";"
    cursor.execute(query)
    races = dictfetchall(cursor)
    races = ujson.dumps(races, encode_html_chars=False, ensure_ascii=False)
    res = HttpResponse(
        races,
        content_type="application/json"
    )
    return res


def update(request):
    call_command('updateraces', verbosity=3, interactive=False)
    return HttpResponse('1')<commit_msg>Change the api race_category to return twice more results when category is FIS<commit_after>#-*- coding: utf-8 -*-
import ujson

from django.http import HttpResponse, Http404
from django.core.cache import cache
from django.core.management import call_command
from django.db import connection

RACES_PER_VIEW = 25


def last_races(request):
    cursor = connection.cursor()
    query = "SELECT id, info, category, genre, link, location, discipline, raceId, date FROM rankings_races ORDER BY date DESC LIMIT " + \
        str(RACES_PER_VIEW) + ";"
    cursor.execute(query)
    races = dictfetchall(cursor)
    races = ujson.dumps(races, encode_html_chars=False, ensure_ascii=False)
    res = HttpResponse(
        races,
        content_type="application/json"
    )
    return res


def race(request, pk):
    pk = str(int(pk))
    cursor = connection.cursor()
    query = "SELECT id, info, category, genre, link, location, discipline, `table`, raceId, date FROM rankings_races WHERE id='" + \
        pk + "';"
    cursor.execute(query)
    races = dictfetchall(cursor)[0]
    races = ujson.dumps(races, encode_html_chars=False, ensure_ascii=False)
    res = HttpResponse(
        races,
        content_type="application/json"
    )
    return res


def race_category(request, category):
    if category not in ['WC', 'EC', 'FIS']:
        return Http404
    page = request.GET.get('page')
    page = 0 if page is None else (int(page) - 1)
    nb_races = RACES_PER_VIEW * 2 if 'FIS' in category else RACES_PER_VIEW
    offset = nb_races * page
    cursor = connection.cursor()
    query = "SELECT id, info, category, genre, link, location, discipline, raceId, date FROM rankings_races WHERE category='" + \
        category + "' ORDER BY date DESC LIMIT " + \
            str(offset) + ", " + str(nb_races) + ";"
    cursor.execute(query)
    races = dictfetchall(cursor)
    races = ujson.dumps(races, encode_html_chars=False, ensure_ascii=False)
    res = HttpResponse(
        races,
        content_type="application/json"
    )
    return res


def update(request):
    call_command('updateraces', verbosity=3, interactive=False)
    return HttpResponse('1')
{'fraction_non_alphanumeric': 0.11185149928605426, 'fraction_numerical': 0.006901475487862923, 'mean_word_length': 3.3329896907216496, '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': '1601754', 'n_tokens_mistral': 1340, 'n_tokens_neox': 1317, 'n_words': 356}