<commit_before># -*- coding: utf-8 -*-
from django.shortcuts import get_object_or_404, render_to_response
from codespeed.models import Revision, Result, Interpreter, Benchmark, Environment
from django.http import HttpResponse, Http404, HttpResponseNotAllowed, HttpResponseBadRequest, HttpResponseNotFound
from codespeed import settings
import json

def resultstable(request):
    result_list = Result.objects.order_by('-date')[:300]
    return render_to_response('codespeed/results_table.html', locals())

def results(request):
    return render_to_response('codespeed/results.html')

def compare(request):
    return render_to_response('codespeed/comparison.html')
    
def gettimelinedata(request):
    if request.method != 'GET':
        return HttpResponseNotAllowed('GET')
    data = request.GET
    
    result_list = {}    
    baseline = Interpreter.objects.get(id=1)
    baselinerev = lastbase = Revision.objects.filter(
        tag__isnull=False
    ).filter(
        project='cpython'
    ).order_by('-number')[0]
    if data["baseline"] == "true":
        result_list["baseline"] = Result.objects.get(
            interpreter=baseline, benchmark=data["benchmark"], revision=baselinerev
        ).value
    
    result_list["error"] = "None"
    interpreters = data["interpreters"].split(",")
    if interpreters[0] == "":
        result_list["error"] = "No interpreters selected"
        return HttpResponse(json.dumps( result_list ))
    for interpreter in interpreters:
        resultquery = Result.objects.filter(
                revision__project=settings.PROJECT_NAME
            ).filter(
                benchmark=data["benchmark"]
            ).filter(
                interpreter=interpreter
            ).order_by('-revision__number')[:data["revisions"]]
        results = []
        for res in resultquery:
            results.append([res.revision.number, res.value])
        result_list[interpreter] = results
    return HttpResponse(json.dumps( result_list ))

def timeline(request):
    if request.method != 'GET':
        return HttpResponseNotAllowed('GET')
    data = request.GET
    
    # Configuration of default parameters
    baseline = Interpreter.objects.get(id=1)
    lastbaserev = Revision.objects.filter(
        tag__isnull=False
    ).filter(
        project='cpython'
    ).order_by('-number')[0]
    baselinetag = lastbaserev.tag
    baselinerev = lastbaserev.number

    defaultbaseline = True
    if data.has_key("baseline"):
        if data["baseline"] == "false":
            defaultbaseline = False
    
    defaulthost = 1
    defaultbenchmark = 2
    if data.has_key("benchmark"):
        try:
            defaultbenchmark = int(data["benchmark"])
        except ValueError:
            defaultbenchmark = get_object_or_404(Benchmark, name=data["benchmark"]).id
    
    defaultinterpreters = [2, 3]
    if data.has_key("interpreters"):
        defaultinterpreters = []
        for i in data["interpreters"].split(","):
            selected = Interpreter.objects.filter(id=int(i))
            if len(selected): defaultinterpreters.append(selected[0].id)
    if not len(defaultinterpreters): defaultinterpreters = [2]

    lastrevisions = [50, 200, 1000]
    defaultlast = 200
    if data.has_key("revisions"):
        if int(data["revisions"]) in lastrevisions:
            defaultlast = data["revisions"]
    
    # Information for template
    interpreters = Interpreter.objects.filter(name__startswith=settings.PROJECT_NAME)
    benchmarks = Benchmark.objects.all()
    hostlist = Environment.objects.all()
    return render_to_response('codespeed/timeline.html', {
        'defaultinterpreters': defaultinterpreters,
        'defaultbaseline': defaultbaseline,
        'baseline': baseline,
        'baselinetag': baselinetag,<commit_msg>added an extra lastrevisions option to timeline<commit_after># -*- coding: utf-8 -*-
from django.shortcuts import get_object_or_404, render_to_response
from codespeed.models import Revision, Result, Interpreter, Benchmark, Environment
from django.http import HttpResponse, Http404, HttpResponseNotAllowed, HttpResponseBadRequest, HttpResponseNotFound
from codespeed import settings
import json

def resultstable(request):
    result_list = Result.objects.order_by('-date')[:300]
    return render_to_response('codespeed/results_table.html', locals())

def results(request):
    return render_to_response('codespeed/results.html')

def compare(request):
    return render_to_response('codespeed/comparison.html')
    
def gettimelinedata(request):
    if request.method != 'GET':
        return HttpResponseNotAllowed('GET')
    data = request.GET
    
    result_list = {}    
    baseline = Interpreter.objects.get(id=1)
    baselinerev = lastbase = Revision.objects.filter(
        tag__isnull=False
    ).filter(
        project='cpython'
    ).order_by('-number')[0]
    if data["baseline"] == "true":
        result_list["baseline"] = Result.objects.get(
            interpreter=baseline, benchmark=data["benchmark"], revision=baselinerev
        ).value
    
    result_list["error"] = "None"
    interpreters = data["interpreters"].split(",")
    if interpreters[0] == "":
        result_list["error"] = "No interpreters selected"
        return HttpResponse(json.dumps( result_list ))
    for interpreter in interpreters:
        resultquery = Result.objects.filter(
                revision__project=settings.PROJECT_NAME
            ).filter(
                benchmark=data["benchmark"]
            ).filter(
                interpreter=interpreter
            ).order_by('-revision__number')[:data["revisions"]]
        results = []
        for res in resultquery:
            results.append([res.revision.number, res.value])
        result_list[interpreter] = results
    return HttpResponse(json.dumps( result_list ))

def timeline(request):
    if request.method != 'GET':
        return HttpResponseNotAllowed('GET')
    data = request.GET
    
    # Configuration of default parameters
    baseline = Interpreter.objects.get(id=1)
    lastbaserev = Revision.objects.filter(
        tag__isnull=False
    ).filter(
        project='cpython'
    ).order_by('-number')[0]
    baselinetag = lastbaserev.tag
    baselinerev = lastbaserev.number

    defaultbaseline = True
    if data.has_key("baseline"):
        if data["baseline"] == "false":
            defaultbaseline = False
    
    defaulthost = 1
    defaultbenchmark = 2
    if data.has_key("benchmark"):
        try:
            defaultbenchmark = int(data["benchmark"])
        except ValueError:
            defaultbenchmark = get_object_or_404(Benchmark, name=data["benchmark"]).id
    
    defaultinterpreters = [2, 3]
    if data.has_key("interpreters"):
        defaultinterpreters = []
        for i in data["interpreters"].split(","):
            selected = Interpreter.objects.filter(id=int(i))
            if len(selected): defaultinterpreters.append(selected[0].id)
    if not len(defaultinterpreters): defaultinterpreters = [2]

    lastrevisions = [10, 50, 200, 1000]
    defaultlast = 200
    if data.has_key("revisions"):
        if int(data["revisions"]) in lastrevisions:
            defaultlast = data["revisions"]
    
    # Information for template
    interpreters = Interpreter.objects.filter(name__startswith=settings.PROJECT_NAME)
    benchmarks = Benchmark.objects.all()
    hostlist = Environment.objects.all()
    return render_to_response('codespeed/timeline.html', {
        'defaultinterpreters': defaultinterpreters,
        'defaultbaseline': defaultbaseline,
        'baseline': baseline,
        'baselinetag': baselinetag,
{'fraction_non_alphanumeric': 0.11322487536079769, 'fraction_numerical': 0.009708737864077669, 'mean_word_length': 3.1339479392624727, 'pattern_counts': {'":': 6, '<': 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': '2244415', 'n_tokens_mistral': 2265, 'n_tokens_neox': 2192, 'n_words': 428}