Exemplo n.º 1
0
def done(request, pk):
    # NOTE: make it safe, some form of authentication
    #       we don't want stundets updating their score.
    log.debug(request.body)

    options = json.loads(request.body, strict=False) if request.body else {}

    submission = get_object_or_404(models.Submission,
                                   pk=pk,
                                   score__isnull=True)

    stdout = utils.decode(options['stdout'])
    stderr = utils.decode(options['stderr'])
    exit_code = int(options['exit_code'])

    score = re.search(r'.*TOTAL: (\d+)/(\d+)', stdout, re.MULTILINE)
    points = score.group(1) if score else 0
    if not score:
        log.warning('Score is None')

    submission.score = points
    submission.output = stdout + '\n' + stderr

    log.debug(f'Submission #{submission.id} has the output:\n{submission.output}')  # noqa: E501
    log.debug(f'Stderr:\n{stderr}')
    log.debug(f'Exit code:\n{exit_code}')

    submission.save()

    return JsonResponse({})
Exemplo n.º 2
0
def done(request, pk):
    log.debug("URL: %s", request.get_full_path())
    log.debug(pprint.pformat(request.body))

    options = json.loads(request.body, strict=False) if request.body else {}

    submission = get_object_or_404(models.Submission, pk=pk)

    if not submission.verify_jwt(request.GET.get("token")):
        return JsonResponse({"error": "Invalid JWT token"}, status=400)

    stdout = utils.decode(options["stdout"])
    exit_code = int(options["exit_code"])

    score = re.search(r".*TOTAL: (\d+\.?\d*)/(\d+)", stdout, re.MULTILINE)
    points = score.group(1) if score else 0
    if not score:
        log.warning("Score is None")

    if len(stdout) > 32768:
        stdout = stdout[:32730] + "... TRUNCATED BECAUSE TOO BIG ..."

    submission.score = decimal.Decimal(points)
    submission.total_score = calculate_total_score(submission)
    submission.stdout = stdout

    log.debug("Submission #%s:", submission.pk)
    log.debug("Stdout:\n%s", submission.stdout)
    log.debug("Exit code:\n%s", exit_code)

    submission.changeReason = "Evaluation"
    submission.save()

    return JsonResponse({})
Exemplo n.º 3
0
def done(request, pk):
    log.debug(f'URL: {request.get_full_path()}')
    log.debug(pprint.pformat(request.body))

    options = json.loads(request.body, strict=False) if request.body else {}

    submission = get_object_or_404(models.Submission, pk=pk)

    assert submission.verify_jwt(request.GET.get('token'))

    stdout = utils.decode(options['stdout'])
    exit_code = int(options['exit_code'])

    score = re.search(r'.*TOTAL: (\d+\.?\d*)/(\d+)', stdout, re.MULTILINE)
    points = score.group(1) if score else 0
    if not score:
        log.warning('Score is None')

    if len(stdout) > 32768:
        stdout = stdout[:32730] + '... TRUNCATED BECAUSE TOO BIG ...'

    submission.score = decimal.Decimal(points)
    submission.total_score = calculate_total_score(submission)
    submission.stdout = stdout
    submission.update_state()

    log.debug(f'Submission #{submission.pk}:')
    log.debug(f'Stdout:\n{submission.stdout}')
    log.debug(f'Exit code:\n{exit_code}')

    submission.changeReason = 'Evaluation'
    submission.save()

    return JsonResponse({})