Example #1
0
    def __init__(self, obj=None, **kwargs):
        self.data = kwargs

        if isinstance(obj, Result):
            self.obj = obj
            self._populate_by_obj()
        elif obj is None:
            self.obj = Result()
        else:
            raise ValueError("obj has to be an instance of models.Result")

        if self.data:
            self._check_data()
        self.__data_validated = False  # not used for now
        super(ResultBundle, self).__init__(data=self.data, obj=self.obj)
Example #2
0
    def make_result(self, value, rev=None, benchmark=None):
        from uuid import uuid4

        if not benchmark:
            benchmark = self.bench

        if not rev:
            commitdate = self.starttime + timedelta(days=self.days)
            cid = str(uuid4())
            Revision(commitid=cid,
                     date=commitdate,
                     branch=self.b,
                     project=self.pro).save()
            rev = Revision.objects.get(commitid=cid)

        Result(value=value,
               revision=rev,
               executable=self.exe,
               environment=self.env,
               benchmark=benchmark).save()
        self.days += 1
        return rev
Example #3
0
def addresult(request):
    if request.method != 'POST':
        return HttpResponseNotAllowed('POST')
    data = request.POST
    
    mandatory_data = [
        'commitid',
        'project',
        'executable',
        'benchmark',
        'environment',
        'result_value',
    ]
    
    for key in mandatory_data:
        if not key in data:
            return HttpResponseBadRequest('Key "' + key + '" missing from request')
        elif key in data and data[key] == "":
            return HttpResponseBadRequest('Key "' + key + '" empty in request')

    # Check that Environment exists
    try:
        e = get_object_or_404(Environment, name=data['environment'])
    except Http404:
        return HttpResponseNotFound("Environment " + data["environment"] + " not found")
    
    p, created = Project.objects.get_or_create(name=data["project"])
    b, created = Benchmark.objects.get_or_create(name=data["benchmark"])
    
    rev, created = Revision.objects.get_or_create(
        commitid=data['commitid'],
        project=p,
    )
    if created:
        if 'revision_date' in data: rev.date = data["revision_date"]
        else:
            try:
                saverevisioninfo(rev)
            except:
                pass
        if not rev.date:
            temp = datetime.today()
            rev.date = datetime(temp.year, temp.month, temp.day, temp.hour, temp.minute, temp.second)

        rev.save()
    
    exe, created = Executable.objects.get_or_create(
        name=data['executable'],
        project=p
    )
    
    try:
        r = Result.objects.get(revision=rev,executable=exe,benchmark=b,environment=e)
    except Result.DoesNotExist:
        r = Result(revision=rev,executable=exe,benchmark=b,environment=e)
    r.value = data["result_value"]    
    if 'result_date' in data: r.date = data["result_date"]
    else: r.date = rev.date
    if 'std_dev' in data: r.std_dev = data['std_dev']
    if 'min' in data: r.val_min = data['min']
    if 'max' in data: r.val_max = data['max']
    r.save()
    
    return HttpResponse("Result data saved succesfully")
Example #4
0
def save_result(data):
    try:
        data = json.loads(data.keys()[0])
    except:
        pass
    res, error = validate_result(data)
    if error:
        return res, True
    else:
        assert(isinstance(res, Environment))
        env = res

    p, created = Project.objects.get_or_create(name=data["project"])
    branch, created = Branch.objects.get_or_create(name=data["branch"],
                                                   project=p)
    b, created = Benchmark.objects.get_or_create(name=data["benchmark"])

    if created:
        if "description" in data:
            b.description = data["description"]
        if "units" in data:
            b.units = data["units"]
        if "units_title" in data:
            b.units_title = data["units_title"]
        if "lessisbetter" in data:
            b.lessisbetter = data["lessisbetter"]
        b.full_clean()
        b.save()

    try:
        rev = branch.revisions.get(commitid=data['commitid'])
    except Revision.DoesNotExist:
        rev_date = data.get("revision_date")
        # "None" (as string) can happen when we urlencode the POST data
        if not rev_date or rev_date in ["", "None"]:
            rev_date = datetime.today()
        rev = Revision(branch=branch, project=p, commitid=data['commitid'],
                       date=rev_date)
        try:
            rev.full_clean()
        except ValidationError as e:
            return str(e), True
        if p.repo_type not in ("N", ""):
            try:
                saverevisioninfo(rev)
            except RuntimeError as e:
                logger.warning("unable to save revision %s info: %s", rev, e,
                               exc_info=True)
        rev.save()

    exe, created = Executable.objects.get_or_create(
        name=data['executable'],
        project=p
    )

    try:
        r = Result.objects.get(
            revision=rev, executable=exe, benchmark=b, environment=env)
    except Result.DoesNotExist:
        r = Result(revision=rev, executable=exe, benchmark=b, environment=env)

    r.value = data["result_value"]
    if 'result_date' in data:
        r.date = data["result_date"]
    elif rev.date:
        r.date = rev.date
    else:
        r.date = datetime.now()

    r.std_dev = data.get('std_dev')
    r.val_min = data.get('min')
    r.val_max = data.get('max')

    r.full_clean()
    r.save()

    return (rev, exe, env), False
Example #5
0
def addresult(request):
    if request.method != 'POST':
        return HttpResponseNotAllowed('POST')
    data = request.POST

    mandatory_data = [
        'commitid',
        'project',
        'executable_name',
        'benchmark',
        'environment',
        'result_value',
    ]

    for key in mandatory_data:
        if not key in data:
            return HttpResponseBadRequest('Key "' + key +
                                          '" missing from request')
        elif key in data and data[key] == "":
            return HttpResponseBadRequest('Key "' + key + '" empty in request')
    # Check that Environment exists
    try:
        e = get_object_or_404(Environment, name=data['environment'])
    except Http404:
        return HttpResponseNotFound("Environment " + data["environment"] +
                                    " not found")

    p, created = Project.objects.get_or_create(name=data["project"])
    b, created = Benchmark.objects.get_or_create(name=data["benchmark"])

    rev, created = Revision.objects.get_or_create(
        commitid=data['commitid'],
        project=p,
    )
    if created:
        if 'revision_date' in data: rev.date = data["revision_date"]
        else:
            try:
                saverevisioninfo(rev)
            except:
                pass
        if not rev.date:
            temp = datetime.today()
            rev.date = datetime(temp.year, temp.month, temp.day, temp.hour,
                                temp.minute, temp.second)

        rev.save()

    coptions = ""
    if 'executable_coptions' in data: coptions = data['executable_coptions']
    exe, created = Executable.objects.get_or_create(
        name=data['executable_name'], coptions=coptions, project=p)

    try:
        r = Result.objects.get(revision=rev,
                               executable=exe,
                               benchmark=b,
                               environment=e)
    except Result.DoesNotExist:
        r = Result(revision=rev, executable=exe, benchmark=b, environment=e)
    r.value = data["result_value"]
    if 'result_date' in data: r.date = data["result_date"]
    else: r.date = rev.date
    if 'std_dev' in data: r.std_dev = data['std_dev']
    if 'min' in data: r.val_min = data['min']
    if 'max' in data: r.val_max = data['max']
    r.save()

    return HttpResponse("Result data saved succesfully")
Example #6
0
def save_result(data):
    res, error = validate_result(data)
    if error:
        return res, True
    else:
        assert (isinstance(res, Environment))
        env = res

    p, created = Project.objects.get_or_create(name=data["project"])
    branch, created = Branch.objects.get_or_create(name=data["branch"],
                                                   project=p)
    b, created = Benchmark.objects.get_or_create(name=data["benchmark"])

    if created:
        if "description" in data:
            b.description = data["description"]
        if "units" in data:
            b.units = data["units"]
        if "units_title" in data:
            b.units_title = data["units_title"]
        if "lessisbetter" in data:
            b.lessisbetter = data["lessisbetter"]
        b.full_clean()
        b.save()

    try:
        rev = branch.revisions.get(commitid=data['commitid'])
    except Revision.DoesNotExist:
        rev_date = data.get("revision_date")
        # "None" (as string) can happen when we urlencode the POST data
        if not rev_date or rev_date in ["", "None"]:
            rev_date = datetime.today()
        rev = Revision(branch=branch,
                       project=p,
                       commitid=data['commitid'],
                       date=rev_date)
        try:
            rev.full_clean()
        except ValidationError as e:
            return str(e), True
        if p.repo_type not in ("N", ""):
            try:
                saverevisioninfo(rev)
            except RuntimeError as e:
                logger.warning("unable to save revision %s info: %s",
                               rev,
                               e,
                               exc_info=True)
        rev.save()

    exe, created = Executable.objects.get_or_create(name=data['executable'],
                                                    project=p)

    try:
        r = Result.objects.get(revision=rev,
                               executable=exe,
                               benchmark=b,
                               environment=env)
    except Result.DoesNotExist:
        r = Result(revision=rev, executable=exe, benchmark=b, environment=env)

    r.value = data["result_value"]
    if 'result_date' in data:
        r.date = data["result_date"]
    elif rev.date:
        r.date = rev.date
    else:
        r.date = datetime.now()

    r.std_dev = data.get('std_dev')
    r.val_min = data.get('min')
    r.val_max = data.get('max')

    r.full_clean()
    r.save()

    return (rev, exe, env), False
Example #7
0
            try:
                saverevisioninfo(rev)
            except StandardError, e:
                logging.warning("unable to save revision %s info: %s", rev, e,
                                exc_info=True)
        rev.save()
    exe, created = Executable.objects.get_or_create(
        name=data['executable'],
        project=p
    )

    try:
        r = Result.objects.get(
            revision=rev,executable=exe,benchmark=b,environment=e)
    except Result.DoesNotExist:
        r = Result(revision=rev,executable=exe,benchmark=b,environment=e)

    r.value = data["result_value"]
    if 'result_date' in data:
        r.date = data["result_date"]
    elif rev.date:
        r.date = rev.date
    else:
        r.date = datetime.now()

    r.std_dev = data.get('std_dev')
    r.val_min = data.get('min')
    r.val_max = data.get('max')

    r.full_clean()
    r.save()
Example #8
0
def save_result(data):
    res, error = validate_result(data)
    if error:
        return res, True
    else:
        assert isinstance(res, Environment)
        env = res

    p, created = Project.objects.get_or_create(name=data["project"])
    branch, created = Branch.objects.get_or_create(name=data["branch"], project=p)
    b, created = Benchmark.objects.get_or_create(name=data["benchmark"])
    try:
        rev = branch.revisions.get(commitid=data["commitid"])
    except Revision.DoesNotExist:
        rev_date = data.get("revision_date")
        # "None" (as string) can happen when we urlencode the POST data
        if not rev_date or rev_date in ["", "None"]:
            rev_date = datetime.today()
        rev = Revision(branch=branch, project=p, commitid=data["commitid"], date=rev_date)
        try:
            rev.full_clean()
        except ValidationError as e:
            return str(e), True
        if p.repo_type not in ("N", ""):
            try:
                saverevisioninfo(rev)
            except RuntimeError as e:
                logger.warning("unable to save revision %s info: %s", rev, e, exc_info=True)
        rev.save()

    exe, created = Executable.objects.get_or_create(name=data["executable"], project=p)

    try:
        r = Result.objects.get(revision=rev, executable=exe, benchmark=b, environment=env)
    except Result.DoesNotExist:
        r = Result(revision=rev, executable=exe, benchmark=b, environment=env)

    r.value = data["result_value"]
    if "result_date" in data:
        r.date = data["result_date"]
    elif rev.date:
        r.date = rev.date
    else:
        r.date = datetime.now()

    r.std_dev = data.get("std_dev")
    r.val_min = data.get("min")
    r.val_max = data.get("max")

    r.full_clean()
    r.save()

    return (rev, exe, env), False
Example #9
0
def addresult(request):
    if request.method != 'POST':
        return HttpResponseNotAllowed('POST')
    data = request.POST
    
    mandatory_data = [
        'commitid',
        'project',
        'executable',
        'benchmark',
        'environment',
        'result_value',
    ]
    
    for key in mandatory_data:
        if not key in data:
            return HttpResponseBadRequest('Key "' + key + '" missing from request')
        elif key in data and data[key] == "":
            return HttpResponseBadRequest('Key "' + key + '" empty in request')

    # Check that Environment exists
    try:
        e = get_object_or_404(Environment, name=data['environment'])
    except Http404:
        return HttpResponseNotFound("Environment " + data["environment"] + " not found")
    
    p, created = Project.objects.get_or_create(name=data["project"])
    b, created = Benchmark.objects.get_or_create(name=data["benchmark"])
    
    rev, created = Revision.objects.get_or_create(
        commitid=data['commitid'],
        project=p,
    )
    if created:
        if 'revision_date' in data:
            rev.date = data["revision_date"]
        else:
            try:
                saverevisioninfo(rev)
            except:
                pass
        if not rev.date:
            temp = datetime.today()
            rev.date = datetime(temp.year, temp.month, temp.day, temp.hour, temp.minute, temp.second)

        rev.save()
    
    exe, created = Executable.objects.get_or_create(
        name=data['executable'],
        project=p
    )
    
    try:
        r = Result.objects.get(revision=rev,executable=exe,benchmark=b,environment=e)
    except Result.DoesNotExist:
        r = Result(revision=rev,executable=exe,benchmark=b,environment=e)
    
    r.value = data["result_value"]    
    if 'result_date' in data:
        r.date = data["result_date"]
    else:
        r.date = rev.date
    
    r.std_dev = data.get('std_dev')
    r.val_min = data.get('min')
    r.val_max = data.get('max')
    r.save()
    
    # Trigger Report creation when there are enough results
    last_revs = Revision.objects.order_by('-date')[:2]
    if len(last_revs) > 1:
        current_results = rev.result_set.filter(
            executable=exe).filter(environment=e)
        last_results = last_revs[1].result_set.filter(
            executable=exe).filter(environment=e)
        # If there is are at least as many results as in the last revision,
        # create new report
        if len(current_results) >= len(last_results):
            report, created = Report.objects.get_or_create(
                executable=exe, environment=e, revision=rev
            )
            report.save()
    
    return HttpResponse("Result data saved succesfully")