<commit_before># -*- coding: utf-8 -*-
from django.contrib.auth.models import User
from django.http import Http404, HttpResponseBadRequest
from django.utils import simplejson
from geography.models import Place, PlaceRelation, UserPlace, AveragePlace, ABEnvironment
from geography.utils import JsonResponse, QuestionService
from lazysignup.decorators import allow_lazy_user
from logging import getLogger
import geography.models.user
import math

LOGGER = getLogger(__name__)


@allow_lazy_user
def question(request, map_code, place_type_slug):
    try:
        map = PlaceRelation.objects.get(
            place__code=map_code,
            type=PlaceRelation.IS_ON_MAP)
    except PlaceRelation.DoesNotExist:
        raise Http404
    ABEnvironment.init_session(request.user, request.session)
    qs = QuestionService(user=request.user, map_place=map)
    question_index = 0
    if request.raw_post_data:
        LOGGER.debug("processing raw answer %s", request.raw_post_data)
        answer = simplejson.loads(request.raw_post_data)
        qs.answer(answer)
        question_index = answer['index'] + 1
    if should_get_questions(request, question_index):
        place_types = ([Place.PLACE_TYPE_SLUGS_LOWER_REVERSE[place_type_slug]]
                       if place_type_slug in Place.PLACE_TYPE_SLUGS_LOWER_REVERSE
                       else Place.CATEGORIES[place_type_slug]
                       if place_type_slug in Place.CATEGORIES
                       else [t[0] for t in Place.PLACE_TYPES])
        response = qs.get_questions(10 - question_index, place_types)
    else:
        response = []
    return JsonResponse(response)


def should_get_questions(request, question_index):
    points = geography.models.user.get_points(request.user)
    return ((points <= 10
            or question_index % math.ceil(math.log(points, 10)) == 0)
            and question_index != 9)


def average_users_places(request, map_code):

    response = {}
    return JsonResponse(response)


def users_places(request, map_code, user=None):

    try:
        map = PlaceRelation.objects.get(
            place__code=map_code,
            type=PlaceRelation.IS_ON_MAP)
        map_places = map.related_places.all()
    except PlaceRelation.DoesNotExist:
        raise Http404("Unknown map name: {0}".format(map_code))
    try:
        too_small_places = PlaceRelation.objects.get(
            place__code=map_code,
            type=PlaceRelation.IS_TOO_SMALL_ON_MAP)
        map_places = map_places | too_small_places.related_places.all()
    except PlaceRelation.DoesNotExist:
        pass
<commit_msg>remove blank newline<commit_after># -*- coding: utf-8 -*-
from django.contrib.auth.models import User
from django.http import Http404, HttpResponseBadRequest
from django.utils import simplejson
from geography.models import Place, PlaceRelation, UserPlace, AveragePlace, ABEnvironment
from geography.utils import JsonResponse, QuestionService
from lazysignup.decorators import allow_lazy_user
from logging import getLogger
import geography.models.user
import math

LOGGER = getLogger(__name__)


@allow_lazy_user
def question(request, map_code, place_type_slug):
    try:
        map = PlaceRelation.objects.get(
            place__code=map_code,
            type=PlaceRelation.IS_ON_MAP)
    except PlaceRelation.DoesNotExist:
        raise Http404
    ABEnvironment.init_session(request.user, request.session)
    qs = QuestionService(user=request.user, map_place=map)
    question_index = 0
    if request.raw_post_data:
        LOGGER.debug("processing raw answer %s", request.raw_post_data)
        answer = simplejson.loads(request.raw_post_data)
        qs.answer(answer)
        question_index = answer['index'] + 1
    if should_get_questions(request, question_index):
        place_types = ([Place.PLACE_TYPE_SLUGS_LOWER_REVERSE[place_type_slug]]
                       if place_type_slug in Place.PLACE_TYPE_SLUGS_LOWER_REVERSE
                       else Place.CATEGORIES[place_type_slug]
                       if place_type_slug in Place.CATEGORIES
                       else [t[0] for t in Place.PLACE_TYPES])
        response = qs.get_questions(10 - question_index, place_types)
    else:
        response = []
    return JsonResponse(response)


def should_get_questions(request, question_index):
    points = geography.models.user.get_points(request.user)
    return ((points <= 10
            or question_index % math.ceil(math.log(points, 10)) == 0)
            and question_index != 9)


def average_users_places(request, map_code):
    response = {}
    return JsonResponse(response)


def users_places(request, map_code, user=None):

    try:
        map = PlaceRelation.objects.get(
            place__code=map_code,
            type=PlaceRelation.IS_ON_MAP)
        map_places = map.related_places.all()
    except PlaceRelation.DoesNotExist:
        raise Http404("Unknown map name: {0}".format(map_code))
    try:
        too_small_places = PlaceRelation.objects.get(
            place__code=map_code,
            type=PlaceRelation.IS_TOO_SMALL_ON_MAP)
        map_places = map_places | too_small_places.related_places.all()
    except PlaceRelation.DoesNotExist:
        pass

{'fraction_non_alphanumeric': 0.08070714834742505, 'fraction_numerical': 0.008455034588777863, 'mean_word_length': 3.1573482428115014, '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': '3081695', 'n_tokens_mistral': 1627, 'n_tokens_neox': 1557, 'n_words': 316}