示例#1
0
def make_report(env, kind='NORMAL', **kwargs):
    """Builds entities for tests results in a database.

       Used ``environ`` keys:
           * ``tests``
           * ``test_results``
           * ``group_results``
           * ``status``
           * ``score``
           * ``compilation_result``
           * ``compilation_message``

       Produced ``environ`` keys:
           * ``report_id``: id of the produced
             :class:`~oioioi.contests.models.SubmissionReport`
    """
    submission, submission_report = _make_base_report(env, kind)

    if env['compilation_result'] != 'OK':
        return env

    tests = env['tests']
    test_results = env.get('test_results', {})
    for test_name, result in test_results.iteritems():
        test = tests[test_name]
        if 'report_id' in result:
            continue
        test_report = TestReport(submission_report=submission_report)
        test_report.test_id = test.get('id')
        test_report.test_name = test_name
        test_report.test_group = test['group']
        test_report.test_time_limit = test.get('exec_time_limit')
        test_report.test_max_score = test['max_score']
        test_report.score = result['score']
        test_report.status = result['status']
        test_report.time_used = result['time_used']
        comment = result.get('result_string', '')
        if comment.lower() == 'ok':  # Annoying
            comment = ''
        test_report.comment = \
            slice_str(comment, TestReport._meta.get_field('comment').max_length)
        test_report.save()
        result['report_id'] = test_report.id

    group_results = env.get('group_results', {})
    for group_name, group_result in group_results.iteritems():
        if 'report_id' in group_result:
            continue
        group_report = GroupReport(submission_report=submission_report)
        group_report.group = group_name
        group_report.score = group_result['score']
        group_report.status = group_result['status']
        group_report.save()
        group_result['result_id'] = group_report.id

    return env
示例#2
0
def make_report(env, kind='NORMAL', **kwargs):
    """Builds entities for tests results in a database.

       Used ``environ`` keys:
           * ``tests``
           * ``test_results``
           * ``group_results``
           * ``status``
           * ``score``
           * ``compilation_result``
           * ``compilation_message``

       Produced ``environ`` keys:
           * ``report_id``: id of the produced
             :class:`~oioioi.contests.models.SubmissionReport`
    """
    submission, submission_report = _make_base_report(env, kind)

    if env['compilation_result'] != 'OK':
        return env

    tests = env['tests']
    test_results = env.get('test_results', {})
    for test_name, result in test_results.iteritems():
        test = tests[test_name]
        if 'report_id' in result:
            continue
        test_report = TestReport(submission_report=submission_report)
        test_report.test_id = test.get('id')
        test_report.test_name = test_name
        test_report.test_group = test['group']
        test_report.test_time_limit = test.get('exec_time_limit')
        test_report.test_max_score = test['max_score']
        test_report.score = result['score']
        test_report.status = result['status']
        test_report.time_used = result['time_used']
        comment = result.get('result_string', '')
        if comment.lower() == 'ok':  # Annoying
            comment = ''
        test_report.comment = \
            slice_str(comment, TestReport._meta.get_field('comment').max_length)
        test_report.save()
        result['report_id'] = test_report.id

    group_results = env.get('group_results', {})
    for group_name, group_result in group_results.iteritems():
        if 'report_id' in group_result:
            continue
        group_report = GroupReport(submission_report=submission_report)
        group_report.group = group_name
        group_report.score = group_result['score']
        group_report.status = group_result['status']
        group_report.save()
        group_result['result_id'] = group_report.id

    return env
示例#3
0
def make_report(env, kind='NORMAL', save_scores=True, **kwargs):
    """Builds entities for tests results in a database.

       Used ``environ`` keys:
           * ``tests``
           * ``test_results``
           * ``group_results``
           * ``status``
           * ``score``
           * ``compilation_result``
           * ``compilation_message``
           * ``submission_id``

       Produced ``environ`` keys:
           * ``report_id``: id of the produced
             :class:`~oioioi.contests.models.SubmissionReport`
    """
    submission, submission_report = _make_base_report(env, kind)

    if env['compilation_result'] != 'OK':
        return env
    tests = env['tests']
    test_results = env.get('test_results', {})
    for test_name, result in six.iteritems(test_results):
        test = tests[test_name]
        if 'report_id' in result:
            continue
        test_report = TestReport(submission_report=submission_report)
        test_report.test_id = test.get('id')
        test_report.test_name = test_name
        test_report.test_group = test['group']
        test_report.test_time_limit = test.get('exec_time_limit')
        test_report.max_score = result['max_score']
        test_report.score = result['score'] if save_scores else None
        test_report.status = result['status']
        test_report.time_used = result['time_used']

        comment = result.get('result_string', '')
        if comment.lower() in ['ok', 'time limit exceeded']:  # Annoying
            comment = ''
        test_report.comment = Truncator(comment).chars(
            TestReport._meta.get_field('comment').max_length)
        if env.get('save_outputs', False):
            test_report.output_file = filetracker_to_django_file(
                result['out_file'])
        test_report.save()
        result['report_id'] = test_report.id

    group_results = env.get('group_results', {})
    for group_name, group_result in six.iteritems(group_results):
        if 'report_id' in group_result:
            continue
        group_report = GroupReport(submission_report=submission_report)
        group_report.group = group_name
        group_report.score = group_result['score'] if save_scores else None
        group_report.max_score = \
                group_result['max_score'] if save_scores else None
        group_report.status = group_result['status']
        group_report.save()
        group_result['result_id'] = group_report.id

    if kind == 'INITIAL':
        if submission.user is not None and not env.get('is_rejudge', False):
            logger.info(
                "Submission %(submission_id)d by user %(username)s"
                " for problem %(short_name)s got initial result.", {
                    'submission_id': submission.pk,
                    'username': submission.user.username,
                    'short_name': submission.problem_instance.short_name
                },
                extra={
                    'notification': 'initial_results',
                    'user': submission.user,
                    'submission': submission
                })

    return env
示例#4
0
def make_report(env, kind='NORMAL', save_scores=True, **kwargs):
    """Builds entities for tests results in a database.

       Used ``environ`` keys:
           * ``tests``
           * ``test_results``
           * ``group_results``
           * ``status``
           * ``score``
           * ``compilation_result``
           * ``compilation_message``
           * ``submission_id``

       Produced ``environ`` keys:
           * ``report_id``: id of the produced
             :class:`~oioioi.contests.models.SubmissionReport`
    """
    submission, submission_report = _make_base_report(env, kind)

    if env['compilation_result'] != 'OK':
        return env
    tests = env['tests']
    test_results = env.get('test_results', {})
    for test_name, result in test_results.iteritems():
        test = tests[test_name]
        if 'report_id' in result:
            continue
        test_report = TestReport(submission_report=submission_report)
        test_report.test_id = test.get('id')
        test_report.test_name = test_name
        test_report.test_group = test['group']
        test_report.test_time_limit = test.get('exec_time_limit')
        test_report.test_max_score = test['max_score']
        test_report.score = result['score'] if save_scores else None
        test_report.status = result['status']
        test_report.time_used = result['time_used']
        comment = result.get('result_string', '')
        if comment.lower() in ['ok', 'time limit exceeded']:  # Annoying
            comment = ''
        test_report.comment = Truncator(comment).chars(TestReport.
                _meta.get_field('comment').max_length)
        if env.get('save_outputs', False):
            test_report.output_file = filetracker_to_django_file(
                                                            result['out_file'])
        test_report.save()
        result['report_id'] = test_report.id

    group_results = env.get('group_results', {})
    for group_name, group_result in group_results.iteritems():
        if 'report_id' in group_result:
            continue
        group_report = GroupReport(submission_report=submission_report)
        group_report.group = group_name
        group_report.score = group_result['score'] if save_scores else None
        group_report.max_score = \
                group_result['max_score'] if save_scores else None
        group_report.status = group_result['status']
        group_report.save()
        group_result['result_id'] = group_report.id

    if kind == 'INITIAL':
        if submission.user is not None and not env.get('is_rejudge', False):
            logger.info("Submission %(submission_id)d by user %(username)s"
                        " for problem %(short_name)s got initial result.",
                        {'submission_id': submission.pk,
                         'username': submission.user.username,
                         'short_name': submission.problem_instance
                                    .short_name},
                            extra={'notification': 'initial_results',
                                   'user': submission.user,
                                   'submission': submission})

    return env
示例#5
0
def make_report(env, kind="NORMAL", **kwargs):
    """Builds entities for tests results in a database.

       Used ``environ`` keys:
           * ``tests``
           * ``test_results``
           * ``group_results``
           * ``status``
           * ``score``

       Produced ``environ`` keys:
           * ``report_id``: id of the produced
             :class:`~oioioi.contests.models.SubmissionReport`
    """

    submission = Submission.objects.get(id=env["submission_id"])
    submission_report = SubmissionReport(submission=submission)
    submission_report.kind = kind
    submission_report.save()

    status_report = ScoreReport(submission_report=submission_report)
    status_report.status = env["status"]
    status_report.score = env["score"]
    status_report.save()

    compilation_report = CompilationReport(submission_report=submission_report)
    compilation_report.status = env["compilation_result"]
    compilation_message = env["compilation_message"]
    if not isinstance(compilation_message, unicode):
        compilation_message = compilation_message.decode("utf8")
    compilation_report.compiler_output = compilation_message
    compilation_report.save()

    if env["compilation_result"] != "OK":
        return env

    tests = env["tests"]
    test_results = env.get("test_results", {})
    for test_name, result in test_results.iteritems():
        test = tests[test_name]
        if "report_id" in result:
            continue
        test_report = TestReport(submission_report=submission_report)
        test_report.test_id = test.get("id")
        test_report.test_name = test_name
        test_report.test_group = test["group"]
        test_report.test_time_limit = test.get("exec_time_limit")
        test_report.test_max_score = test["max_score"]
        test_report.score = result["score"]
        test_report.status = result["status"]
        test_report.time_used = result["time_used"]
        comment = result.get("result_string", "")
        if comment == "ok":  # Annoying
            comment = ""
        test_report.comment = comment
        test_report.save()
        result["report_id"] = test_report.id

    group_results = env.get("group_results", {})
    for group_name, group_result in group_results.iteritems():
        if "report_id" in group_result:
            continue
        group_report = GroupReport(submission_report=submission_report)
        group_report.group = group_name
        group_report.score = group_result["score"]
        group_report.status = group_result["status"]
        group_report.save()
        group_result["result_id"] = group_report.id

    return env
示例#6
0
def make_report(env, kind='NORMAL', **kwargs):
    """Builds entities for tests results in a database.

       Used ``environ`` keys:
           * ``tests``
           * ``test_results``
           * ``group_results``
           * ``status``
           * ``score``

       Produced ``environ`` keys:
           * ``report_id``: id of the produced
             :class:`~oioioi.contests.models.SubmissionReport`
    """

    submission = Submission.objects.get(id=env['submission_id'])
    submission_report = SubmissionReport(submission=submission)
    submission_report.kind = kind
    submission_report.save()

    status_report = ScoreReport(submission_report=submission_report)
    status_report.status = env['status']
    status_report.score = env['score']
    status_report.save()

    compilation_report = CompilationReport(submission_report=submission_report)
    compilation_report.status = env['compilation_result']
    compilation_message = env['compilation_message']
    if not isinstance(compilation_message, unicode):
        compilation_message = compilation_message.decode('utf8')
    compilation_report.compiler_output = compilation_message
    compilation_report.save()

    if env['compilation_result'] != 'OK':
        return env

    tests = env['tests']
    test_results = env.get('test_results', {})
    for test_name, result in test_results.iteritems():
        test = tests[test_name]
        if 'report_id' in result:
            continue
        test_report = TestReport(submission_report=submission_report)
        test_report.test_id = test.get('id')
        test_report.test_name = test_name
        test_report.test_group = test['group']
        test_report.test_time_limit = test.get('exec_time_limit')
        test_report.test_max_score = test['max_score']
        test_report.score = result['score']
        test_report.status = result['status']
        test_report.time_used = result['time_used']
        comment = result.get('result_string', '')
        if comment == 'ok':  # Annoying
            comment = ''
        test_report.comment = comment
        test_report.save()
        result['report_id'] = test_report.id

    group_results = env.get('group_results', {})
    for group_name, group_result in group_results.iteritems():
        if 'report_id' in group_result:
            continue
        group_report = GroupReport(submission_report=submission_report)
        group_report.group = group_name
        group_report.score = group_result['score']
        group_report.status = group_result['status']
        group_report.save()
        group_result['result_id'] = group_report.id

    return env
示例#7
0
文件: handlers.py 项目: mahrud/oioioi
def make_report(env, kind='NORMAL', **kwargs):
    """Builds entities for tests results in a database.

       Used ``environ`` keys:
           * ``tests``
           * ``test_results``
           * ``group_results``
           * ``status``
           * ``score``

       Produced ``environ`` keys:
           * ``report_id``: id of the produced
             :class:`~oioioi.contests.models.SubmissionReport`
    """

    submission = Submission.objects.get(id=env['submission_id'])
    submission_report = SubmissionReport(submission=submission)
    submission_report.kind = kind
    submission_report.save()

    status_report = ScoreReport(submission_report=submission_report)
    status_report.status = env['status']
    status_report.score = env['score']
    status_report.save()

    compilation_report = CompilationReport(submission_report=submission_report)
    compilation_report.status = env['compilation_result']
    compilation_message = env['compilation_message']
    if not isinstance(compilation_message, unicode):
        compilation_message = compilation_message.decode('utf8')
    compilation_report.compiler_output = compilation_message
    compilation_report.save()

    if env['compilation_result'] != 'OK':
        return env

    tests = env['tests']
    test_results = env.get('test_results', {})
    for test_name, result in test_results.iteritems():
        test = tests[test_name]
        if 'report_id' in result:
            continue
        test_report = TestReport(submission_report=submission_report)
        test_report.test_id = test.get('id')
        test_report.test_name = test_name
        test_report.test_group = test['group']
        test_report.test_time_limit = test.get('exec_time_limit')
        test_report.test_max_score = test['max_score']
        test_report.score = result['score']
        test_report.status = result['status']
        test_report.time_used = result['time_used']
        comment = result.get('result_string', '')
        if comment == 'ok':  # Annoying
            comment = ''
        test_report.comment = comment
        test_report.save()
        result['report_id'] = test_report.id

    group_results = env.get('group_results', {})
    for group_name, group_result in group_results.iteritems():
        if 'report_id' in group_result:
            continue
        group_report = GroupReport(submission_report=submission_report)
        group_report.group = group_name
        group_report.score = group_result['score']
        group_report.status = group_result['status']
        group_report.save()
        group_result['result_id'] = group_report.id

    return env
示例#8
0
def make_report(env, kind="NORMAL", save_scores=True, **kwargs):
    """Builds entities for tests results in a database.

       Used ``environ`` keys:
           * ``tests``
           * ``test_results``
           * ``group_results``
           * ``status``
           * ``score``
           * ``compilation_result``
           * ``compilation_message``
           * ``submission_id``

       Produced ``environ`` keys:
           * ``report_id``: id of the produced
             :class:`~oioioi.contests.models.SubmissionReport`
    """
    submission, submission_report = _make_base_report(env, kind)

    if env["compilation_result"] != "OK":
        return env
    tests = env["tests"]
    test_results = env.get("test_results", {})
    for test_name, result in test_results.iteritems():
        test = tests[test_name]
        if "report_id" in result:
            continue
        test_report = TestReport(submission_report=submission_report)
        test_report.test_id = test.get("id")
        test_report.test_name = test_name
        test_report.test_group = test["group"]
        test_report.test_time_limit = test.get("exec_time_limit")
        test_report.test_max_score = test["max_score"]
        test_report.score = result["score"] if save_scores else None
        test_report.status = result["status"]
        test_report.time_used = result["time_used"]
        comment = result.get("result_string", "")
        if comment.lower() in ["ok", "time limit exceeded"]:  # Annoying
            comment = ""
        test_report.comment = Truncator(comment).chars(TestReport._meta.get_field("comment").max_length)
        if env.get("save_outputs", False):
            test_report.output_file = filetracker_to_django_file(result["out_file"])
        test_report.save()
        result["report_id"] = test_report.id

    group_results = env.get("group_results", {})
    for group_name, group_result in group_results.iteritems():
        if "report_id" in group_result:
            continue
        group_report = GroupReport(submission_report=submission_report)
        group_report.group = group_name
        group_report.score = group_result["score"] if save_scores else None
        group_report.max_score = group_result["max_score"] if save_scores else None
        group_report.status = group_result["status"]
        group_report.save()
        group_result["result_id"] = group_report.id

    if kind == "INITIAL":
        if submission.user is not None and not env.get("is_rejudge", False):
            logger.info(
                "Submission %(submission_id)d by user %(username)s" " for problem %(short_name)s got initial result.",
                {
                    "submission_id": submission.pk,
                    "username": submission.user.username,
                    "short_name": submission.problem_instance.short_name,
                },
                extra={"notification": "initial_results", "user": submission.user, "submission": submission},
            )

    return env