<commit_before>import os
import datetime
import json
from django.shortcuts import render, get_object_or_404
from django.conf import settings
from . import models, graph


def dashboard(request):
    """Shows the latest results for each minion"""
    minions = {}
    for check in models.Check.objects.filter(active=True):
        latest_results = models.Result.objects.filter(check=check,
                                                      timestamp=check.last_run)
        for result in latest_results:
            minions.setdefault(result.minion, []).append(result)
    if request.META.get('HTTP_X_PJAX', False):
        parent_template = 'pjax.html'
    else:
        parent_template = 'base.html'
    return render(request, 'monitor/dashboard.html', {
        'minions': minions,
        'parent_template': parent_template
    })


def history(request, name):
    minion = get_object_or_404(models.Minion, name=name)
    since = datetime.datetime.now() - datetime.timedelta(hours=12)
    graphs = []
    # FIXME: this is a horrible way to get all the results for a minion
    for check in models.Check.objects.filter(active=True):
        result = check.result_set.filter(minion=minion,
                                         timestamp=check.last_run)
        if result:
            # create test databases
            #db_file = os.path.join(settings.SALMON_WHISPER_DB_PATH,
            #                       result[0].whisper_filename)
            #graph.create_test_database(db_file)
            #history = result[0].get_history(from_date=since)
            # javascript uses milliseconds since epoch
            js_data = map(lambda x: (x[0] * 1000, x[1]), history)
            graphs.append({
                'name': result[0].check.name,
                'data': json.dumps(js_data),
            })

    return render(request, 'monitor/history.html', {
        'minion': minion,
        'graphs': graphs,
    })<commit_msg>Too much commenting<commit_after>import os
import datetime
import json
from django.shortcuts import render, get_object_or_404
from django.conf import settings
from . import models, graph


def dashboard(request):
    """Shows the latest results for each minion"""
    minions = {}
    for check in models.Check.objects.filter(active=True):
        latest_results = models.Result.objects.filter(check=check,
                                                      timestamp=check.last_run)
        for result in latest_results:
            minions.setdefault(result.minion, []).append(result)
    if request.META.get('HTTP_X_PJAX', False):
        parent_template = 'pjax.html'
    else:
        parent_template = 'base.html'
    return render(request, 'monitor/dashboard.html', {
        'minions': minions,
        'parent_template': parent_template
    })


def history(request, name):
    minion = get_object_or_404(models.Minion, name=name)
    since = datetime.datetime.now() - datetime.timedelta(hours=12)
    graphs = []
    # FIXME: this is a horrible way to get all the results for a minion
    for check in models.Check.objects.filter(active=True):
        result = check.result_set.filter(minion=minion,
                                         timestamp=check.last_run)
        if result:
            # create test databases
            #db_file = os.path.join(settings.SALMON_WHISPER_DB_PATH,
            #                       result[0].whisper_filename)
            #graph.create_test_database(db_file)
            history = result[0].get_history(from_date=since)
            # javascript uses milliseconds since epoch
            js_data = map(lambda x: (x[0] * 1000, x[1]), history)
            graphs.append({
                'name': result[0].check.name,
                'data': json.dumps(js_data),
            })

    return render(request, 'monitor/history.html', {
        'minion': minion,
        'graphs': graphs,
    })
{'fraction_non_alphanumeric': 0.10321750321750321, 'fraction_numerical': 0.008751608751608752, 'mean_word_length': 2.2356369691923397, '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': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4796040', 'n_tokens_mistral': 1123, 'n_tokens_neox': 1079, 'n_words': 248}