<commit_before>from django.http import HttpResponse
from railroad.viewhosts import views
import itertools
import json

def autocomplete(request, context):
    query = request.GET.get('term', '')
    limit = int(request.GET.get('limit', 10))


    stat, obj = views.parse()

    choices = []
    queries = []
    q_results = []
    res = {}

    if len(query.split(',')) > 1:
        queries = query.split(',')
    else:
        queries = [query]

    queries = [q.strip() for q in queries if q.strip()]

    if context == 'host':
        choices = views.hostnames(stat)
    elif context == 'group':
        choices = [x['alias'] for x in views.grouplist(obj)]
    elif context == 'service':
        # servicesnames will return services with the sane name for different hosts, so
        # we make it a set to get rid of duplicate names
        choices = set(views.servicenames(stat))

    for q in queries:
        matching_names = [x for x in choices if x.lower().startswith(q)]
        q_results.append(matching_names)
    results = itertools.product(*q_results)
    results = [','.join(result) for result in results]
    result = [ { "value" : r, "id": r, "label": r } for r in results ] 
    return HttpResponse(json.dumps(result))<commit_msg>Don't need id or label, if they dont exist value is used<commit_after>from django.http import HttpResponse
from railroad.viewhosts import views
import itertools
import json

def autocomplete(request, context):
    query = request.GET.get('term', '')
    limit = int(request.GET.get('limit', 10))


    stat, obj = views.parse()

    choices = []
    queries = []
    q_results = []
    res = {}

    if len(query.split(',')) > 1:
        queries = query.split(',')
    else:
        queries = [query]

    queries = [q.strip() for q in queries if q.strip()]

    if context == 'host':
        choices = views.hostnames(stat)
    elif context == 'group':
        choices = [x['alias'] for x in views.grouplist(obj)]
    elif context == 'service':
        # servicesnames will return services with the sane name for different hosts, so
        # we make it a set to get rid of duplicate names
        choices = set(views.servicenames(stat))

    for q in queries:
        matching_names = [x for x in choices if x.lower().startswith(q)]
        q_results.append(matching_names)
    results = itertools.product(*q_results)
    results = [','.join(result) for result in results]
    result = [ { "value" : r } for r in results ] 
    return HttpResponse(json.dumps(result))
{'fraction_non_alphanumeric': 0.12639109697933226, 'fraction_numerical': 0.0023847376788553257, 'mean_word_length': 2.836890243902439, 'pattern_counts': {'":': 2, '<': 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': '5301572', 'n_tokens_mistral': 771, 'n_tokens_neox': 757, 'n_words': 244}