<commit_before>import json
from django.http import HttpResponse
from django.shortcuts import render
from .models import Article, Communes
from unidecode import unidecode
import re


# Create your views here.
def index(request):
    return render(request, 'mc_frontend/homepage.html', {})


def entity(request, qid, title):
    return render(request, 'mc_frontend/homepage.html', {})


def item_api(request, qid):
    commune = Article(qid)
    data = commune.get_data()
    return HttpResponse(json.dumps(data), content_type='application/json')


def autocomplete(request, snak):
    snak = unidecode(snak).lower().replace('-', ' ')
    snak = re.sub('\W+', ' ', snak).strip()

    data = Communes.objects.filter(suggest_str__istartswith=snak)
    values = {'snak': snak,
              'values': list(data.values('wp_title', 'qid'))}
    return HttpResponse(json.dumps(values), content_type='application/json')


def geo_api(request, min_lat, max_lat, min_lng, max_lng):
    SEARCH_MARGIN = 0.06
    MAX_AREA = 1
    
    min_lat = float(min_lat) - SEARCH_MARGIN
    max_lat = float(max_lat) + SEARCH_MARGIN
    min_lng = float(min_lng) - SEARCH_MARGIN
    max_lng = float(max_lng) + SEARCH_MARGIN
    
    #Check if the area is not to big
    if (max_lat - min_lat) * (max_lng - min_lng) > MAX_AREA:
        values = {
            'type': 'FeatureCollection',
            'features': [],
        }
        return HttpResponse(json.dumps(values), content_type='application/json')
    
    #Fetch the geoshape of all cities in the given area
    data = Communes.objects.filter(latitude__range=[min_lat, max_lat], longitude__range=[min_lng, max_lng])
    dataset = data.values('wp_title', 'qid', 'geoshape')
    
    #Build the geoJSON response
    features = []
    for commune in dataset:
        features += [{
            "type": "Feature",
            "properties": {
                "title": commune['wp_title'],
                "qid": commune['qid']
            },
            "geometry": json.loads(commune['geoshape']),
        }]
    
    values = {
        'type': 'FeatureCollection',
        'features': features,
    }
    
    return HttpResponse(json.dumps(values), content_type='application/json')<commit_msg>[api] geoshape: tweak api parameters<commit_after>import json
from django.http import HttpResponse
from django.shortcuts import render
from .models import Article, Communes
from unidecode import unidecode
import re


# Create your views here.
def index(request):
    return render(request, 'mc_frontend/homepage.html', {})


def entity(request, qid, title):
    return render(request, 'mc_frontend/homepage.html', {})


def item_api(request, qid):
    commune = Article(qid)
    data = commune.get_data()
    return HttpResponse(json.dumps(data), content_type='application/json')


def autocomplete(request, snak):
    snak = unidecode(snak).lower().replace('-', ' ')
    snak = re.sub('\W+', ' ', snak).strip()

    data = Communes.objects.filter(suggest_str__istartswith=snak)
    values = {'snak': snak,
              'values': list(data.values('wp_title', 'qid'))}
    return HttpResponse(json.dumps(values), content_type='application/json')


def geo_api(request, min_lat, max_lat, min_lng, max_lng):
    SEARCH_MARGIN = 0.06
    MAX_AREA = 0.8
    
    min_lat = float(min_lat) - SEARCH_MARGIN
    max_lat = float(max_lat) + SEARCH_MARGIN
    min_lng = float(min_lng) - SEARCH_MARGIN
    max_lng = float(max_lng) + SEARCH_MARGIN
    
    #Check if the area is not to big
    if (max_lat - min_lat) * (max_lng - min_lng) > MAX_AREA:
        values = {
            'type': 'FeatureCollection',
            'features': [],
        }
        return HttpResponse(json.dumps(values), content_type='application/json')
    
    #Fetch the geoshape of all cities in the given area
    data = Communes.objects.filter(latitude__range=[min_lat, max_lat], longitude__range=[min_lng, max_lng])
    dataset = data.values('title', 'qid', 'geoshape')
    
    #Build the geoJSON response
    features = []
    for commune in dataset:
        features += [{
            "type": "Feature",
            "properties": {
                "title": commune['title'],
                "qid": commune['qid']
            },
            "geometry": json.loads(commune['geoshape']),
        }]
    
    values = {
        'type': 'FeatureCollection',
        'features': features,
    }
    
    return HttpResponse(json.dumps(values), content_type='application/json')
{'fraction_non_alphanumeric': 0.12984105663756437, 'fraction_numerical': 0.0020147750167897917, 'mean_word_length': 3.003584229390681, 'pattern_counts': {'":': 10, '<': 3, '<?xml version=': 0, '>': 5, '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': '7109126', 'n_tokens_mistral': 1475, 'n_tokens_neox': 1436, 'n_words': 313}