Exemplo n.º 1
0
def _post_update_submission(submission, done=False):
    if submission.problem.is_public:
        event.post('submissions', {'type': 'done-submission' if done else 'update-submission',
                                   'id': submission.id,
                                   'contest': submission.contest_key,
                                   'user': submission.user_id, 'problem': submission.problem_id,
                                   'status': submission.status, 'language': submission.language.key})
Exemplo n.º 2
0
def judge_submission(submission):
    from .models import SubmissionTestCase
    submission.time = None
    submission.memory = None
    submission.points = None
    submission.result = None
    submission.save()
    SubmissionTestCase.objects.filter(submission=submission).delete()
    try:
        response = judge_request({
            'name': 'submission-request',
            'submission-id': submission.id,
            'problem-id': submission.problem.code,
            'language': submission.language.key,
            'source': submission.source,
        })
    except BaseException:
        logger.exception('Failed to send request to judge')
        submission.status = 'IE'
        success = False
    else:
        submission.status = 'QU' if (response['name'] == 'submission-received' and
                                     response['submission-id'] == submission.id) else 'IE'
        if submission.problem.is_public:
            event.post('submissions', {'type': 'update-submission', 'id': submission.id})
        success = True
    submission.save()
    return success
Exemplo n.º 3
0
def abort_submission(submission):
    from .models import Submission
    response = judge_request({'name': 'terminate-submission', 'submission-id': submission.id})
    # This defaults to true, so that in the case the judgelist fails to remove the submission from the queue,
    # and returns a bad-request, the submission is not falsely shown as "Aborted" when it will still be judged.
    if not response.get('judge-aborted', True):
        Submission.objects.filter(id=submission.id).update(status='AB', result='AB')
        event.post('sub_%s' % Submission.get_id_secret(submission.id), {'type': 'aborted-submission'})
        _post_update_submission(submission, done=True)
Exemplo n.º 4
0
 def on_compile_message(self, packet):
     super(DjangoJudgeHandler, self).on_compile_message(packet)
     try:
         submission = Submission.objects.get(id=packet['submission-id'])
     except Submission.DoesNotExist:
         logger.warning('Unknown submission: %d', packet['submission-id'])
         return
     submission.error = packet['log']
     submission.save()
     event.post('sub_%d' % submission.id, {
         'type': 'compile-message'
     })
Exemplo n.º 5
0
Arquivo: ticket.py Projeto: DMOJ/site
 def form_valid(self, form):
     message = TicketMessage(user=self.request.user.profile,
                             body=form.cleaned_data['body'],
                             ticket=self.object)
     message.save()
     if event.real:
         event.post('tickets', {
             'type': 'ticket-message', 'id': self.object.id,
             'message': message.id, 'user': self.object.user_id,
             'assignees': list(self.object.assignees.values_list('id', flat=True)),
         })
     return HttpResponseRedirect('%s#message-%d' % (reverse('ticket', args=[self.object.id]), message.id))
Exemplo n.º 6
0
Arquivo: ticket.py Projeto: DMOJ/site
 def form_valid(self, form):
     ticket = Ticket(user=self.request.user.profile, title=form.cleaned_data['title'])
     ticket.linked_item = self.object
     ticket.save()
     message = TicketMessage(ticket=ticket, user=ticket.user, body=form.cleaned_data['body'])
     message.save()
     ticket.assignees.set(self.get_assignees())
     if event.real:
         event.post('tickets', {
             'type': 'new-ticket', 'id': ticket.id,
             'message': message.id, 'user': ticket.user_id,
             'assignees': list(ticket.assignees.values_list('id', flat=True)),
         })
     return HttpResponseRedirect(reverse('ticket', args=[ticket.id]))
Exemplo n.º 7
0
 def on_submission_processing(self, packet):
     try:
         submission = Submission.objects.get(id=packet['submission-id'])
     except Submission.DoesNotExist:
         logger.warning('Unknown submission: %d', packet['submission-id'])
         return
     submission.status = 'P'
     submission.save()
     event.post('sub_%d' % submission.id, {'type': 'processing'})
     if not submission.problem.is_public:
         return
     event.post('submissions', {'type': 'update-submission', 'id': submission.id,
                                'state': 'processing', 'contest': submission.contest_key,
                                'user': submission.user_id, 'problem': submission.problem_id})
Exemplo n.º 8
0
 def on_test_case(self, packet):
     super(DjangoJudgeHandler, self).on_test_case(packet)
     try:
         submission = Submission.objects.get(id=packet['submission-id'])
     except Submission.DoesNotExist:
         logger.warning('Unknown submission: %d', packet['submission-id'])
         return
     test_case = SubmissionTestCase(submission=submission, case=packet['position'])
     status = packet['status']
     if status & 4:
         test_case.status = 'TLE'
     elif status & 8:
         test_case.status = 'MLE'
     elif status & 64:
         test_case.status = 'OLE'
     elif status & 2:
         test_case.status = 'RTE'
     elif status & 16:
         test_case.status = 'IR'
     elif status & 1:
         test_case.status = 'WA'
     elif status & 32:
         test_case.status = 'SC'
     else:
         test_case.status = 'AC'
     test_case.time = packet['time']
     test_case.memory = packet['memory']
     test_case.points = packet['points']
     test_case.total = packet['total-points']
     test_case.batch = self.batch_id if self.in_batch else None
     test_case.feedback = packet.get('feedback', None) or ''
     test_case.output = packet['output']
     submission.current_testcase = packet['position'] + 1
     submission.save()
     test_case.save()
     event.post('sub_%d' % submission.id, {
         'type': 'test-case',
         'id': packet['position'],
         'status': test_case.status,
         'time': "%.3f" % round(float(packet['time']), 3),
         'memory': packet['memory'],
         'points': float(test_case.points),
         'total': float(test_case.total),
         'output': packet['output']
     })
     if not submission.problem.is_public:
         return
     event.post('submissions', {'type': 'update-submission', 'id': submission.id,
                                'state': 'test-case', 'contest': submission.contest_key,
                                'user': submission.user_id, 'problem': submission.problem_id})
Exemplo n.º 9
0
 def judge(self):
     from judge.rabbitmq.dispatch import judge_submission
     self.time = None
     self.memory = None
     self.points = None
     self.status = 'QU'
     self.result = None
     self.error = None
     self.save()
     SubmissionTestCase.objects.filter(submission=self).delete()
     judge_submission(self)
     if self.problem.is_public:
         event.post('submissions', {'type': 'update-submission', 'id': self.id,
                                    'contest': self.contest_key,
                                    'user': self.user_id, 'problem': self.problem_id})
Exemplo n.º 10
0
 def on_submission_terminated(self, packet):
     super(DjangoJudgeHandler, self).on_submission_terminated(packet)
     try:
         submission = Submission.objects.get(id=packet['submission-id'])
     except Submission.DoesNotExist:
         logger.warning('Unknown submission: %d', packet['submission-id'])
         return
     submission.status = submission.result = 'AB'
     submission.save()
     if not submission.problem.is_public:
         return
     event.post('sub_%d' % submission.id, {
         'type': 'aborted-submission'
     })
     event.post('submissions', {'type': 'update-submission', 'id': submission.id,
                                'state': 'terminated', 'contest': submission.contest_key})
Exemplo n.º 11
0
    def on_compile_error(self, packet):
        logger.info('%s: Submission failed to compile: %s', self.name, packet['submission-id'])
        self._free_self(packet)

        if Submission.objects.filter(id=packet['submission-id']).update(status='CE', result='CE', error=packet['log']):
            event.post('sub_%s' % Submission.get_id_secret(packet['submission-id']), {
                'type': 'compile-error',
                'log': packet['log'],
            })
            self._post_update_submission(packet['submission-id'], 'compile-error', done=True)
            json_log.info(self._make_json_log(packet, action='compile-error', log=packet['log'],
                                              finish=True, result='CE'))
        else:
            logger.warning('Unknown submission: %s', packet['submission-id'])
            json_log.error(self._make_json_log(packet, action='compile-error', info='unknown submission',
                                               log=packet['log'], finish=True, result='CE'))
Exemplo n.º 12
0
    def on_submission_processing(self, packet):
        _ensure_connection()

        id = packet['submission-id']
        if Submission.objects.filter(id=id).update(status='P',
                                                   judged_on=self.judge):
            event.post('sub_%s' % Submission.get_id_secret(id),
                       {'type': 'processing'})
            self._post_update_submission(id, 'processing')
            json_log.info(self._make_json_log(packet, action='processing'))
        else:
            logger.warning('Unknown submission: %s', id)
            json_log.error(
                self._make_json_log(packet,
                                    action='processing',
                                    info='unknown submission'))
Exemplo n.º 13
0
 def on_grading_begin(self, packet):
     try:
         submission = Submission.objects.get(id=packet['id'])
     except Submission.DoesNotExist:
         logger.warning('Unknown submission: %d', packet['id'])
         return
     submission.status = 'G'
     submission.current_testcase = 1
     submission.batch = False
     submission.save()
     SubmissionTestCase.objects.filter(submission_id=submission.id).delete()
     event.post('sub_%d' % submission.id, {'type': 'grading-begin'})
     if not submission.problem.is_public:
         return
     event.post('submissions', {'type': 'update-submission', 'id': submission.id,
                                'state': 'grading-begin', 'contest': submission.contest_key,
                                'user': submission.user_id, 'problem': submission.problem_id})
Exemplo n.º 14
0
    def on_internal_error(self, packet):
        try:
            raise ValueError('\n\n' + packet['message'])
        except ValueError:
            logger.exception('Judge %s failed while handling submission %s', self.name, packet['submission-id'])
        self._free_self(packet)

        id = packet['submission-id']
        if Submission.objects.filter(id=id).update(status='IE', result='IE', error=packet['message']):
            event.post('sub_%s' % Submission.get_id_secret(id), {'type': 'internal-error'})
            self._post_update_submission(id, 'internal-error', done=True)
            json_log.info(self._make_json_log(packet, action='internal-error', message=packet['message'],
                                              finish=True, result='IE'))
        else:
            logger.warning('Unknown submission: %s', id)
            json_log.error(self._make_json_log(packet, action='internal-error', info='unknown submission',
                                               message=packet['message'], finish=True, result='IE'))
Exemplo n.º 15
0
 def on_bad_problem(self, packet):
     super(DjangoJudgeHandler, self).on_bad_problem(packet)
     try:
         submission = Submission.objects.get(id=packet['submission-id'])
     except Submission.DoesNotExist:
         logger.warning('Unknown submission: %d', packet['submission-id'])
         return
     submission.status = submission.result = 'IE'
     submission.save()
     event.post('sub_%d' % submission.id, {
         'type': 'internal-error'
     })
     if not submission.problem.is_public:
         return
     event.post('submissions', {'type': 'update-submission', 'id': submission.id,
                                'state': 'internal-error', 'contest': submission.contest_key,
                                'user': submission.user_id, 'problem': submission.problem_id})
Exemplo n.º 16
0
 def on_submission_terminated(self, packet):
     super(DjangoJudgeHandler, self).on_submission_terminated(packet)
     try:
         submission = Submission.objects.get(id=packet['submission-id'])
     except Submission.DoesNotExist:
         logger.warning('Unknown submission: %d', packet['submission-id'])
         return
     submission.status = submission.result = 'AB'
     submission.save()
     if not submission.problem.is_public:
         return
     event.post('sub_%d' % submission.id, {
         'type': 'aborted-submission'
     })
     event.post('submissions', {'type': 'update-submission', 'id': submission.id,
                                'state': 'terminated', 'contest': submission.contest_key,
                                'user': submission.user_id, 'problem': submission.problem_id})
Exemplo n.º 17
0
    def on_acknowledged(self, packet):
        super(AMQPJudgeResponseDaemon, self).on_acknowledged(packet)
        _ensure_connection()

        try:
            submission = Submission.objects.get(id=packet['id'])
        except Submission.DoesNotExist:
            logger.warning('Unknown submission: %d', packet['id'])
            return
        submission.status = 'P'
        submission.save()
        event.post('sub_%d' % submission.id, {'type': 'processing'})
        if not submission.problem.is_public:
            return
        event.post('submissions', {'type': 'update-submission', 'id': submission.id,
                                   'state': 'processing', 'contest': submission.contest_key,
                                   'user': submission.user_id, 'problem': submission.problem_id})
Exemplo n.º 18
0
 def on_aborted(self, packet):
     super(AMQPJudgeResponseDaemon, self).on_aborted(packet)
     try:
         submission = Submission.objects.get(id=packet['id'])
     except Submission.DoesNotExist:
         logger.warning('Unknown submission: %d', packet['id'])
         return
     submission.status = submission.result = 'AB'
     submission.save()
     if not submission.problem.is_public:
         return
     event.post('sub_%d' % submission.id, {
         'type': 'aborted-submission'
     })
     event.post('submissions', {'type': 'update-submission', 'id': submission.id,
                                'state': 'terminated', 'contest': submission.contest_key,
                                'user': submission.user_id, 'problem': submission.problem_id})
Exemplo n.º 19
0
    def on_compile_message(self, packet):
        super(DjangoJudgeHandler, self).on_compile_message(packet)

        if Submission.objects.filter(id=packet['submission-id']).update(
                error=packet['log']):
            event.post('sub_%d' % packet['submission-id'],
                       {'type': 'compile-message'})
            json_log.info(
                self._make_json_log(packet,
                                    action='compile-message',
                                    log=packet['log']))
        else:
            logger.warning('Unknown submission: %d', packet['submission-id'])
            json_log.error(
                self._make_json_log(packet,
                                    action='compile-message',
                                    info='unknown submission',
                                    log=packet['log']))
Exemplo n.º 20
0
 def form_valid(self, form):
     message = TicketMessage(user=self.request.profile,
                             body=form.cleaned_data['body'],
                             ticket=self.object)
     message.save()
     if event.real:
         event.post('tickets', {
             'type': 'ticket-message', 'id': self.object.id,
             'message': message.id, 'user': self.object.user_id,
             'assignees': list(self.object.assignees.values_list('id', flat=True)),
         })
         event.post('ticket-%d' % self.object.id, {
             'type': 'ticket-message', 'message': message.id,
         })
     if self.request.profile == self.object.user:
         logger.info('New ticket message for %s by the ticket creator',
                     self.request.build_absolute_uri(reverse('ticket', args=[self.object.id])))
     return HttpResponseRedirect('%s#message-%d' % (reverse('ticket', args=[self.object.id]), message.id))
Exemplo n.º 21
0
Arquivo: ticket.py Projeto: DMOJ/site
 def post(self, request, *args, **kwargs):
     if self.open is None:
         raise ImproperlyConfigured('Need to define open')
     ticket = self.get_object()
     if ticket.is_open != self.open:
         ticket.is_open = self.open
         ticket.save()
         if event.real:
             event.post('tickets', {
                 'type': 'ticket-status', 'id': ticket.id,
                 'open': self.open, 'user': ticket.user_id,
                 'assignees': list(ticket.assignees.values_list('id', flat=True)),
                 'title': ticket.title
             })
             event.post('ticket-%d' % ticket.id, {
                 'type': 'ticket-status', 'open': self.open
             })
     return HttpResponse(status=204)
Exemplo n.º 22
0
 def on_grading_begin(self, packet):
     super(DjangoJudgeHandler, self).on_grading_begin(packet)
     try:
         submission = Submission.objects.get(id=packet['submission-id'])
     except Submission.DoesNotExist:
         logger.warning('Unknown submission: %d', packet['submission-id'])
         return
     submission.status = 'G'
     submission.current_testcase = 1
     submission.batch = False
     submission.save()
     SubmissionTestCase.objects.filter(submission_id=submission.id).delete()
     event.post('sub_%d' % submission.id, {'type': 'grading-begin'})
     if not submission.problem.is_public:
         return
     event.post('submissions', {'type': 'update-submission', 'id': submission.id,
                                'state': 'grading-begin', 'contest': submission.contest_key,
                                'user': submission.user_id, 'problem': submission.problem_id})
Exemplo n.º 23
0
    def _post_update_submission(self, id, state, done=False):
        if self._submission_cache_id == id:
            data = self._submission_cache
        else:
            self._submission_cache = data = Submission.objects.filter(id=id).values(
                'problem__is_public', 'contest__participation__contest__key',
                'user_id', 'problem_id', 'status', 'language__key'
            ).get()
            self._submission_cache_id = id

        if data['problem__is_public']:
            event.post('submissions', {
                'type': 'done-submission' if done else 'update-submission',
                'state': state, 'id': id,
                'contest': data['contest__participation__contest__key'],
                'user': data['user_id'], 'problem': data['problem_id'],
                'status': data['status'], 'language': data['language__key'],
            })
Exemplo n.º 24
0
 def on_compile_error(self, packet):
     super(DjangoJudgeHandler, self).on_compile_error(packet)
     try:
         submission = Submission.objects.get(id=packet['submission-id'])
     except Submission.DoesNotExist:
         logger.warning('Unknown submission: %d', packet['submission-id'])
         return
     submission.status = submission.result = 'CE'
     submission.error = packet['log']
     submission.save()
     event.post('sub_%d' % submission.id, {
         'type': 'compile-error',
         'log': packet['log']
     })
     if not submission.problem.is_public:
         return
     event.post('submissions', {'type': 'update-submission', 'id': submission.id,
                                'state': 'compile-error', 'contest': submission.contest_key})
Exemplo n.º 25
0
 def post(self, request, *args, **kwargs):
     if self.open is None:
         raise ImproperlyConfigured('Need to define open')
     ticket = self.get_object()
     if ticket.is_open != self.open:
         ticket.is_open = self.open
         ticket.save()
         if event.real:
             event.post('tickets', {
                 'type': 'ticket-status', 'id': ticket.id,
                 'open': self.open, 'user': ticket.user_id,
                 'assignees': list(ticket.assignees.values_list('id', flat=True)),
                 'title': ticket.title
             })
             event.post('ticket-%d' % ticket.id, {
                 'type': 'ticket-status', 'open': self.open
             })
     return HttpResponse(status=204)
Exemplo n.º 26
0
    def form_valid(self, form):
        ticket = Ticket(user=self.request.profile, title=form.cleaned_data['title'])
        ticket.linked_item = self.object
        ticket.save()
        message = TicketMessage(ticket=ticket, user=ticket.user, body=form.cleaned_data['body'])
        message.save()
        ticket.assignees.set(self.get_assignees())
        if event.real:
            event.post('tickets', {
                'type': 'new-ticket', 'id': ticket.id,
                'message': message.id, 'user': ticket.user_id,
                'assignees': list(ticket.assignees.values_list('id', flat=True)),
            })
        if isinstance(ticket.linked_item, Problem):
            logger.info('New ticket for %s: %s',
                        ticket.linked_item.code,
                        self.request.build_absolute_uri(reverse('ticket', args=[ticket.id])))

        return HttpResponseRedirect(reverse('ticket', args=[ticket.id]))
Exemplo n.º 27
0
 def on_compile_error(self, packet):
     super(DjangoJudgeHandler, self).on_compile_error(packet)
     try:
         submission = Submission.objects.get(id=packet['submission-id'])
     except Submission.DoesNotExist:
         logger.warning('Unknown submission: %d', packet['submission-id'])
         return
     submission.status = submission.result = 'CE'
     submission.error = packet['log']
     submission.save()
     event.post('sub_%d' % submission.id, {
         'type': 'compile-error',
         'log': packet['log']
     })
     if not submission.problem.is_public:
         return
     event.post('submissions', {'type': 'update-submission', 'id': submission.id,
                                'state': 'compile-error', 'contest': submission.contest_key,
                                'user': submission.user_id, 'problem': submission.problem_id})
Exemplo n.º 28
0
 def on_internal_error(self, packet):
     super(AMQPJudgeResponseDaemon, self).on_internal_error(packet)
     try:
         submission = Submission.objects.get(id=packet['id'])
     except Submission.DoesNotExist:
         logger.warning('Unknown submission: %d', packet['id'])
         return
     submission.error = packet['message']
     submission.status = submission.result = 'IE'
     submission.is_being_rejudged = False
     submission.save()
     event.post('sub_%d' % submission.id, {
         'type': 'internal-error'
     })
     if not submission.problem.is_public:
         return
     event.post('submissions', {'type': 'update-submission', 'id': submission.id,
                                'state': 'internal-error', 'contest': submission.contest_key,
                                'user': submission.user_id, 'problem': submission.problem_id})
Exemplo n.º 29
0
def abort_submission(submission):
    from .models import Submission
    # We only want to try to abort a submission if it's still grading, otherwise this can lead to fully graded
    # submissions marked as aborted.
    if submission.status == 'D':
        return
    response = judge_request({
        'name': 'terminate-submission',
        'submission-id': submission.id
    })
    # This defaults to true, so that in the case the JudgeList fails to remove the submission from the queue,
    # and returns a bad-request, the submission is not falsely shown as "Aborted" when it will still be judged.
    if not response.get('judge-aborted', True):
        Submission.objects.filter(id=submission.id).update(status='AB',
                                                           result='AB',
                                                           points=0)
        event.post('sub_%s' % Submission.get_id_secret(submission.id),
                   {'type': 'aborted-submission'})
        _post_update_submission(submission, done=True)
Exemplo n.º 30
0
 def on_grading_begin(self, packet):
     super(DjangoJudgeHandler, self).on_grading_begin(packet)
     if Submission.objects.filter(id=packet['submission-id']).update(
             status='G',
             is_pretested=packet['pretested'],
             current_testcase=1,
             batch=False):
         SubmissionTestCase.objects.filter(
             submission_id=packet['submission-id']).delete()
         event.post('sub_%d' % packet['submission-id'],
                    {'type': 'grading-begin'})
         self._post_update_submission(packet['submission-id'],
                                      'grading-begin')
         json_log.info(self._make_json_log(packet, action='grading-begin'))
     else:
         logger.warning('Unknown submission: %d', packet['submission-id'])
         json_log.error(
             self._make_json_log(packet,
                                 action='grading-begin',
                                 info='unknown submission'))
Exemplo n.º 31
0
    def on_compile_message(self, packet):
        logger.info('%s: Submission generated compiler messages: %s',
                    self.name, packet['submission-id'])

        if Submission.objects.filter(id=packet['submission-id']).update(
                error=packet['log']):
            event.post(
                'sub_%s' % Submission.get_id_secret(packet['submission-id']),
                {'type': 'compile-message'})
            json_log.info(
                self._make_json_log(packet,
                                    action='compile-message',
                                    log=packet['log']))
        else:
            logger.warning('Unknown submission: %s', packet['submission-id'])
            json_log.error(
                self._make_json_log(packet,
                                    action='compile-message',
                                    info='unknown submission',
                                    log=packet['log']))
Exemplo n.º 32
0
 def on_submission_processing(self, packet):
     try:
         submission = Submission.objects.get(id=packet['submission-id'])
     except Submission.DoesNotExist:
         logger.warning('Unknown submission: %d', packet['submission-id'])
         return
     submission.status = 'P'
     submission.save()
     event.post('sub_%d' % submission.id, {'type': 'processing'})
     if not submission.problem.is_public:
         return
     event.post(
         'submissions', {
             'type': 'update-submission',
             'id': submission.id,
             'state': 'processing',
             'contest': submission.contest_key,
             'user': submission.user_id,
             'problem': submission.problem_id
         })
Exemplo n.º 33
0
    def on_submission_processing(self, packet):
        try:
            submission = Submission.objects.get(id=packet['submission-id'])
        except Submission.DoesNotExist:
            logger.warning('Unknown submission: %d', packet['submission-id'])
            return

        try:
            submission.judged_on = Judge.objects.get(name=self.name)
        except Judge.DoesNotExist:
            # Just in case. Is not necessary feature and is not worth the crash.
            pass

        submission.status = 'P'
        submission.save()
        event.post('sub_%d' % submission.id, {'type': 'processing'})
        if not submission.problem.is_public:
            return
        event.post('submissions', {'type': 'update-submission', 'id': submission.id,
                                   'state': 'processing', 'contest': submission.contest_key,
                                   'user': submission.user_id, 'problem': submission.problem_id})
Exemplo n.º 34
0
    def post(self, request, *args, **kwargs):
        if self.open is None and self.contributive is None:
            raise ImproperlyConfigured('Need to define open or contributive')
        ticket = self.get_object()
        if self.open is not None and ticket.is_open != self.open:
            ticket.is_open = self.open
            ticket.save()
            if event.real:
                event.post(
                    'tickets', {
                        'type':
                        'ticket-status',
                        'id':
                        ticket.id,
                        'open':
                        self.open,
                        'user':
                        ticket.user_id,
                        'assignees':
                        list(ticket.assignees.values_list('id', flat=True)),
                        'title':
                        ticket.title,
                    })
                event.post('ticket-%d' % ticket.id, {
                    'type': 'ticket-status',
                    'open': self.open,
                })

        if self.contributive is not None and ticket.is_contributive != self.contributive:
            if not request.user.has_perm(
                    'change_ticket') and self.request.profile == ticket.user:
                return HttpResponseBadRequest(
                    _('You cannot vote your own ticket.'),
                    content_type='text/plain')
            ticket.user.update_contribution_points(
                settings.VNOJ_CP_TICKET *
                (self.contributive - ticket.is_contributive))
            ticket.is_contributive = self.contributive
            ticket.save()
        return HttpResponse(status=204)
Exemplo n.º 35
0
def judge_submission(submission):
    from .models import SubmissionTestCase, ContestSubmission
    submission.time = None
    submission.memory = None
    submission.points = None
    submission.result = None
    submission.error = None
    try:
        # This is set proactively; it might get unset in judgecallback's on_grading_begin if the problem doesn't
        # actually have pretests stored on the judge.
        submission.is_pretested = ContestSubmission.objects.filter(submission=submission) \
            .values_list('problem__contest__run_pretests_only', flat=True)[0]
    except IndexError:
        pass
    submission.save()
    SubmissionTestCase.objects.filter(submission=submission).delete()

    try:
        response = judge_request({
            'name': 'submission-request',
            'submission-id': submission.id,
            'problem-id': submission.problem.code,
            'language': submission.language.key,
            'source': submission.source,
        })
    except BaseException:
        logger.exception('Failed to send request to judge')
        submission.status = 'IE'
        success = False
    else:
        submission.status = 'QU' if (response['name'] == 'submission-received' and
                                     response['submission-id'] == submission.id) else 'IE'
        if submission.problem.is_public:
            event.post('submissions', {'type': 'update-submission', 'id': submission.id,
                                       'contest': submission.contest_key,
                                       'user': submission.user_id, 'problem': submission.problem_id,
                                       'status': submission.status, 'language': submission.language.key})
        success = True
    submission.save()
    return success
Exemplo n.º 36
0
 def form_valid(self, form):
     message = TicketMessage(user=self.request.user.profile,
                             body=form.cleaned_data['body'],
                             ticket=self.object)
     message.save()
     if event.real:
         event.post(
             'tickets', {
                 'type':
                 'ticket-message',
                 'id':
                 self.object.id,
                 'message':
                 message.id,
                 'user':
                 self.object.user_id,
                 'assignees':
                 list(self.object.assignees.values_list('id', flat=True)),
             })
     return HttpResponseRedirect(
         '%s#message-%d' %
         (reverse('ticket', args=[self.object.id]), message.id))
Exemplo n.º 37
0
def post_message(request):
    ret = {'msg': 'posted'}
    if request.method != 'POST':
        return HttpResponseBadRequest()

    room = None
    if request.POST['room']:
        room = Room.objects.get(id=request.POST['room'])

    if not can_access_room(request, room) or request.profile.mute:
        return HttpResponseBadRequest()

    new_message = Message(author=request.profile,
                          body=request.POST['body'],
                          room=room)
    new_message.save()

    if not room:
        event.post(
            'chat_lobby', {
                'type': 'lobby',
                'author_id': request.profile.id,
                'message': new_message.id,
                'room': 'None',
                'tmp_id': request.POST.get('tmp_id')
            })
    else:
        for user in room.users():
            event.post(
                'chat_' + str(user.id), {
                    'type': 'private',
                    'author_id': request.profile.id,
                    'message': new_message.id,
                    'room': room.id,
                    'tmp_id': request.POST.get('tmp_id')
                })

    return JsonResponse(ret)
Exemplo n.º 38
0
 def on_internal_error(self, packet):
     super(AMQPJudgeResponseDaemon, self).on_internal_error(packet)
     try:
         submission = Submission.objects.get(id=packet['id'])
     except Submission.DoesNotExist:
         logger.warning('Unknown submission: %d', packet['id'])
         return
     submission.error = packet['message']
     submission.status = submission.result = 'IE'
     submission.is_being_rejudged = False
     submission.save()
     event.post('sub_%d' % submission.id, {'type': 'internal-error'})
     if not submission.problem.is_public:
         return
     event.post(
         'submissions', {
             'type': 'update-submission',
             'id': submission.id,
             'state': 'internal-error',
             'contest': submission.contest_key,
             'user': submission.user_id,
             'problem': submission.problem_id
         })
Exemplo n.º 39
0
def _post_update_submission(submission, done=False):
    if submission.problem.is_public:
        event.post(
            'submissions', {
                'type':
                'done-submission' if done else 'update-submission',
                'id':
                submission.id,
                'contest':
                submission.contest_key,
                'user':
                submission.user_id,
                'problem':
                submission.problem_id,
                'status':
                submission.status,
                'language':
                submission.language.key,
                'organizations': [
                    x[0] for x in submission.user.organizations.get_queryset().
                    values_list('id')
                ],
            })
Exemplo n.º 40
0
 def form_valid(self, form):
     ticket = Ticket(user=self.request.profile,
                     title=form.cleaned_data['title'])
     issue_object = GeneralIssue(issue_url=form.cleaned_data['issue_url'])
     issue_object.save()
     ticket.linked_item = issue_object
     ticket.save()
     message = TicketMessage(ticket=ticket,
                             user=ticket.user,
                             body=form.cleaned_data['body'])
     message.save()
     if event.real:
         event.post(
             'tickets', {
                 'type': 'new-ticket',
                 'id': ticket.id,
                 'message': message.id,
                 'user': ticket.user_id,
                 'assignees': [],
             })
     on_new_ticket.delay(ticket.pk, ticket.content_type.pk,
                         ticket.object_id, form.cleaned_data['body'])
     return HttpResponseRedirect(reverse('ticket', args=[ticket.id]))
Exemplo n.º 41
0
    def on_submission_terminated(self, packet):
        super(DjangoJudgeHandler, self).on_submission_terminated(packet)

        if Submission.objects.filter(id=packet['submission-id']).update(
                status='AB', result='AB'):
            event.post('sub_%d' % packet['submission-id'],
                       {'type': 'aborted-submission'})
            self._post_update_submission(packet['submission-id'],
                                         'terminated',
                                         done=True)
            json_log.info(
                self._make_json_log(packet,
                                    action='aborted',
                                    finish=True,
                                    result='AB'))
        else:
            logger.warning('Unknown submission: %d', packet['submission-id'])
            json_log.error(
                self._make_json_log(packet,
                                    action='aborted',
                                    info='unknown submission',
                                    finish=True,
                                    result='AB'))
Exemplo n.º 42
0
def judge_submission(submission):
    from .models import SubmissionTestCase
    submission.time = None
    submission.memory = None
    submission.points = None
    submission.result = None
    submission.error = None
    submission.save()
    SubmissionTestCase.objects.filter(submission=submission).delete()
    try:
        response = judge_request({
            'name': 'submission-request',
            'submission-id': submission.id,
            'problem-id': submission.problem.code,
            'language': submission.language.key,
            'source': submission.source,
        })
    except BaseException:
        logger.exception('Failed to send request to judge')
        submission.status = 'IE'
        success = False
    else:
        submission.status = 'QU' if (
            response['name'] == 'submission-received'
            and response['submission-id'] == submission.id) else 'IE'
        if submission.problem.is_public:
            event.post(
                'submissions', {
                    'type': 'update-submission',
                    'id': submission.id,
                    'contest': submission.contest_key,
                    'user': submission.user_id,
                    'problem': submission.problem_id
                })
        success = True
    submission.save()
    return success
Exemplo n.º 43
0
    def on_internal_error(self, packet):
        super(DjangoJudgeHandler, self).on_internal_error(packet)

        id = packet['submission-id']
        if Submission.objects.filter(id=id).update(status='IE',
                                                   result='IE',
                                                   error=packet['message']):
            event.post('sub_%d' % id, {'type': 'internal-error'})
            self._post_update_submission(id, 'internal-error', done=True)
            json_log.info(
                self._make_json_log(packet,
                                    action='internal-error',
                                    message=packet['message'],
                                    finish=True,
                                    result='IE'))
        else:
            logger.warning('Unknown submission: %d', id)
            json_log.error(
                self._make_json_log(packet,
                                    action='internal-error',
                                    info='unknown submission',
                                    message=packet['message'],
                                    finish=True,
                                    result='IE'))
Exemplo n.º 44
0
            contest = submission.contest
            contest.points = round(
                points / total * contest.problem.points if total > 0 else 0, 3)
            if not contest.problem.partial and contest.points != contest.problem.points:
                contest.points = 0
            contest.save()
            submission.contest.participation.recalculate_score()
            submission.contest.participation.update_cumtime()

        finished_submission(submission)

        event.post(
            'sub_%d' % submission.id, {
                'type': 'grading-end',
                'time': time,
                'memory': memory,
                'points': float(points),
                'total': float(submission.problem.points),
                'result': submission.result
            })
        if hasattr(submission, 'contest'):
            participation = submission.contest.participation
            event.post('contest_%d' % participation.contest_id,
                       {'type': 'update'})
        self._post_update_submission(submission.id, 'grading-end', done=True)

    def on_compile_error(self, packet):
        super(DjangoJudgeHandler, self).on_compile_error(packet)

        if Submission.objects.filter(id=packet['submission-id']).update(
                status='CE', result='CE', error=packet['log']):
Exemplo n.º 45
0
        if hasattr(submission, 'contest'):
            contest = submission.contest
            contest.points = round(points / total * contest.problem.points if total > 0 else 0, 3)
            if not contest.problem.partial and contest.points != contest.problem.points:
                contest.points = 0
            contest.save()
            submission.contest.participation.recalculate_score()
            submission.contest.participation.update_cumtime()

        finished_submission(submission)

        event.post('sub_%d' % submission.id, {
            'type': 'grading-end',
            'time': time,
            'memory': memory,
            'points': float(points),
            'total': float(problem.points),
            'result': submission.result
        })
        if hasattr(submission, 'contest'):
            participation = submission.contest.participation
            event.post('contest_%d' % participation.contest_id, {'type': 'update'})
        self._post_update_submission(submission.id, 'grading-end', done=True)

    def on_compile_error(self, packet):
        super(DjangoJudgeHandler, self).on_compile_error(packet)

        if Submission.objects.filter(id=packet['submission-id']).update(status='CE', result='CE', error=packet['log']):
            event.post('sub_%d' % packet['submission-id'], {
                'type': 'compile-error',
                'log': packet['log']
Exemplo n.º 46
0
    def on_test_case(self,
                     packet,
                     max_feedback=SubmissionTestCase._meta.get_field(
                         'feedback').max_length):
        super(DjangoJudgeHandler, self).on_test_case(packet)
        try:
            submission = Submission.objects.get(id=packet['submission-id'])
        except Submission.DoesNotExist:
            logger.warning('Unknown submission: %d', packet['submission-id'])
            return
        test_case = SubmissionTestCase(submission=submission,
                                       case=packet['position'])
        status = packet['status']
        if status & 4:
            test_case.status = 'TLE'
        elif status & 8:
            test_case.status = 'MLE'
        elif status & 64:
            test_case.status = 'OLE'
        elif status & 2:
            test_case.status = 'RTE'
        elif status & 16:
            test_case.status = 'IR'
        elif status & 1:
            test_case.status = 'WA'
        elif status & 32:
            test_case.status = 'SC'
        else:
            test_case.status = 'AC'
        test_case.time = packet['time']
        test_case.memory = packet['memory']
        test_case.points = packet['points']
        test_case.total = packet['total-points']
        test_case.batch = self.batch_id if self.in_batch else None
        test_case.feedback = (packet.get('feedback', None)
                              or '')[:max_feedback]
        test_case.output = packet['output']
        submission.current_testcase = packet['position'] + 1
        submission.save()
        test_case.save()

        do_post = True

        if submission.id in self.update_counter:
            cnt, reset = self.update_counter[submission.id]
            cnt += 1
            if TIMER() - reset > UPDATE_RATE_TIME:
                del self.update_counter[submission.id]
            else:
                self.update_counter[submission.id] = (cnt, reset)
                if cnt > UPDATE_RATE_LIMIT:
                    do_post = False
        if submission.id not in self.update_counter:
            self.update_counter[submission.id] = (1, TIMER())

        if do_post:
            event.post(
                'sub_%d' % submission.id, {
                    'type': 'test-case',
                    'id': packet['position'],
                    'status': test_case.status,
                    'time': "%.3f" % round(float(packet['time']), 3),
                    'memory': packet['memory'],
                    'points': float(test_case.points),
                    'total': float(test_case.total),
                    'output': packet['output']
                })
            if not submission.problem.is_public:
                return
            event.post(
                'submissions', {
                    'type': 'update-submission',
                    'id': submission.id,
                    'state': 'test-case',
                    'contest': submission.contest_key,
                    'user': submission.user_id,
                    'problem': submission.problem_id,
                    'status': submission.status,
                    'language': submission.language.key
                })
Exemplo n.º 47
0
    def on_test_case(self, packet, max_feedback=SubmissionTestCase._meta.get_field('feedback').max_length):
        logger.info('%s: %d test case(s) completed on: %s', self.name, len(packet['cases']), packet['submission-id'])

        id = packet['submission-id']
        updates = packet['cases']
        max_position = max(map(itemgetter('position'), updates))

        if not Submission.objects.filter(id=id).update(current_testcase=max_position + 1):
            logger.warning('Unknown submission: %s', id)
            json_log.error(self._make_json_log(packet, action='test-case', info='unknown submission'))
            return

        bulk_test_case_updates = []
        for result in updates:
            test_case = SubmissionTestCase(submission_id=id, case=result['position'])
            status = result['status']
            if status & 4:
                test_case.status = 'TLE'
            elif status & 8:
                test_case.status = 'MLE'
            elif status & 64:
                test_case.status = 'OLE'
            elif status & 2:
                test_case.status = 'RTE'
            elif status & 16:
                test_case.status = 'IR'
            elif status & 1:
                test_case.status = 'WA'
            elif status & 32:
                test_case.status = 'SC'
            else:
                test_case.status = 'AC'
            test_case.time = result['time']
            test_case.memory = result['memory']
            test_case.points = result['points']
            test_case.total = result['total-points']
            test_case.batch = self.batch_id if self.in_batch else None
            test_case.feedback = (result.get('feedback') or '')[:max_feedback]
            test_case.extended_feedback = result.get('extended-feedback') or ''
            test_case.output = result['output']
            bulk_test_case_updates.append(test_case)

            json_log.info(self._make_json_log(
                packet, action='test-case', case=test_case.case, batch=test_case.batch,
                time=test_case.time, memory=test_case.memory, feedback=test_case.feedback,
                extended_feedback=test_case.extended_feedback, output=test_case.output,
                points=test_case.points, total=test_case.total, status=test_case.status,
            ))

        do_post = True

        if id in self.update_counter:
            cnt, reset = self.update_counter[id]
            cnt += 1
            if time.monotonic() - reset > UPDATE_RATE_TIME:
                del self.update_counter[id]
            else:
                self.update_counter[id] = (cnt, reset)
                if cnt > UPDATE_RATE_LIMIT:
                    do_post = False
        if id not in self.update_counter:
            self.update_counter[id] = (1, time.monotonic())

        if do_post:
            event.post('sub_%s' % Submission.get_id_secret(id), {
                'type': 'test-case',
                'id': max_position,
            })
            self._post_update_submission(id, state='test-case')

        SubmissionTestCase.objects.bulk_create(bulk_test_case_updates)
Exemplo n.º 48
0
 def on_test_case(self, packet):
     super(AMQPJudgeResponseDaemon, self).on_test_case(packet)
     try:
         submission = Submission.objects.get(id=packet['id'])
     except Submission.DoesNotExist:
         logger.warning('Unknown submission: %d', packet['id'])
         return
     test_case = SubmissionTestCase(submission=submission, case=packet['position'])
     status = packet['status']
     if status & 4:
         test_case.status = 'TLE'
     elif status & 8:
         test_case.status = 'MLE'
     elif status & 64:
         test_case.status = 'OLE'
     elif status & 2:
         test_case.status = 'RTE'
     elif status & 16:
         test_case.status = 'IR'
     elif status & 1:
         test_case.status = 'WA'
     elif status & 32:
         test_case.status = 'SC'
     else:
         test_case.status = 'AC'
     test_case.time = packet['time']
     test_case.memory = packet['memory']
     test_case.points = packet['points']
     test_case.total = packet['total-points']
     test_case.batch = packet['batch']
     test_case.feedback = packet.get('feedback', None) or ''
     test_case.output = packet['output']
     submission.current_testcase = packet['position'] + 1
     submission.save()
     test_case.save()
     
     do_post = True
     
     if submission.id in self.update_counter:
         cnt, reset = self.update_counter[submission.id]
         cnt += 1
         if time.time() - reset > UPDATE_RATE_TIME:
             del self.update_counter[submission.id]
         else:
             self.update_counter[submission.id] = (cnt, reset)
             if cnt > UPDATE_RATE_LIMIT:
                 do_post = False
     if submission.id not in self.update_counter:
         self.update_counter[submission.id] = (1, time.time())
     
     if do_post:
         event.post('sub_%d' % submission.id, {
             'type': 'test-case',
             'id': packet['position'],
             'status': test_case.status,
             'time': "%.3f" % round(float(packet['time']), 3),
             'memory': packet['memory'],
             'points': float(test_case.points),
             'total': float(test_case.total),
             'output': packet['output']
         })
     if not submission.problem.is_public or not do_post:
         return
     event.post('submissions', {'type': 'update-submission', 'id': submission.id,
                                'state': 'test-case', 'contest': submission.contest_key,
                                'user': submission.user_id, 'problem': submission.problem_id})
Exemplo n.º 49
0
    def on_test_case(self,
                     packet,
                     max_feedback=SubmissionTestCase._meta.get_field(
                         'feedback').max_length):
        super(DjangoJudgeHandler, self).on_test_case(packet)
        id = packet['submission-id']

        if not Submission.objects.filter(id=id).update(
                current_testcase=packet['position'] + 1):
            logger.warning('Unknown submission: %d', id)
            return

        test_case = SubmissionTestCase(submission_id=id,
                                       case=packet['position'])
        status = packet['status']
        if status & 4:
            test_case.status = 'TLE'
        elif status & 8:
            test_case.status = 'MLE'
        elif status & 64:
            test_case.status = 'OLE'
        elif status & 2:
            test_case.status = 'RTE'
        elif status & 16:
            test_case.status = 'IR'
        elif status & 1:
            test_case.status = 'WA'
        elif status & 32:
            test_case.status = 'SC'
        else:
            test_case.status = 'AC'
        test_case.time = packet['time']
        test_case.memory = packet['memory']
        test_case.points = packet['points']
        test_case.total = packet['total-points']
        test_case.batch = self.batch_id if self.in_batch else None
        test_case.feedback = (packet.get('feedback', None)
                              or '')[:max_feedback]
        test_case.output = packet['output']
        test_case.save()

        do_post = True

        if id in self.update_counter:
            cnt, reset = self.update_counter[id]
            cnt += 1
            if TIMER() - reset > UPDATE_RATE_TIME:
                del self.update_counter[id]
            else:
                self.update_counter[id] = (cnt, reset)
                if cnt > UPDATE_RATE_LIMIT:
                    do_post = False
        if id not in self.update_counter:
            self.update_counter[id] = (1, TIMER())

        if do_post:
            event.post(
                'sub_%d' % id, {
                    'type': 'test-case',
                    'id': packet['position'],
                    'status': test_case.status,
                    'time': '%.3f' % round(float(packet['time']), 3),
                    'memory': packet['memory'],
                    'points': float(test_case.points),
                    'total': float(test_case.total),
                    'output': packet['output']
                })
            self._post_update_submission(id, state='test-case')
Exemplo n.º 50
0
            contest = submission.contest
            contest.points = round(
                points / total * contest.problem.points if total > 0 else 0, 3)
            if not contest.problem.partial and contest.points != contest.problem.points:
                contest.points = 0
            contest.save()
            submission.contest.participation.recalculate_score()
            submission.contest.participation.update_cumtime()

        finished_submission(submission)

        event.post(
            'sub_%d' % submission.id, {
                'type': 'grading-end',
                'time': time,
                'memory': memory,
                'points': float(points),
                'total': float(submission.problem.points),
                'result': submission.result
            })
        if hasattr(submission, 'contest'):
            participation = submission.contest.participation
            event.post('contest_%d' % participation.contest_id,
                       {'type': 'update'})
        if not submission.problem.is_public:
            return
        event.post(
            'submissions', {
                'type': 'done-submission',
                'id': submission.id,
                'contest': submission.contest_key,
Exemplo n.º 51
0
    def on_grading_end(self, packet):
        super(DjangoJudgeHandler, self).on_grading_end(packet)
        try:
            submission = Submission.objects.get(id=packet['submission-id'])
        except Submission.DoesNotExist:
            logger.warning('Unknown submission: %d', packet['submission-id'])
            return

        time = 0
        memory = 0
        points = 0.0
        total = 0
        status = 0
        status_codes = ['SC', 'AC', 'WA', 'MLE', 'TLE', 'IR', 'RTE', 'OLE']
        batches = {}  # batch number: (points, total)

        for case in SubmissionTestCase.objects.filter(submission=submission):
            time += case.time
            if not case.batch:
                points += case.points
                total += case.total
            else:
                if case.batch in batches:
                    batches[case.batch][0] = min(batches[case.batch][0], case.points)
                    batches[case.batch][1] = max(batches[case.batch][1], case.total)
                else:
                    batches[case.batch] = [case.points, case.total]
            memory = max(memory, case.memory)
            i = status_codes.index(case.status)
            if i > status:
                status = i

        for i in batches:
            points += batches[i][0]
            total += batches[i][1]

        points = round(points, 1)
        total = round(total, 1)
        submission.case_points = points
        submission.case_total = total

        sub_points = round(points / total * submission.problem.points if total > 0 else 0, 1)
        if not submission.problem.partial and sub_points != submission.problem.points:
            sub_points = 0

        submission.status = 'D'
        submission.time = time
        submission.memory = memory
        submission.points = sub_points
        submission.result = status_codes[status]
        submission.save()

        submission.user.calculate_points()

        if hasattr(submission, 'contest'):
            contest = submission.contest
            contest.points = round(points / total * contest.problem.points if total > 0 else 0, 1)
            if not contest.problem.partial and contest.points != contest.problem.points:
                contest.points = 0
            contest.save()
            submission.contest.participation.recalculate_score()
            submission.contest.participation.update_cumtime()

        finished_submission(submission)

        event.post('sub_%d' % submission.id, {
            'type': 'grading-end',
            'time': time,
            'memory': memory,
            'points': float(points),
            'total': float(submission.problem.points),
            'result': submission.result
        })
        if hasattr(submission, 'contest'):
            participation = submission.contest.participation
            event.post('contest_%d' % participation.contest_id, {'type': 'update'})
        if not submission.problem.is_public:
            return
        event.post('submissions', {'type': 'update-submission', 'id': submission.id,
                                   'state': 'grading-end', 'contest': submission.contest_key,
                                   'user': submission.user_id, 'problem': submission.problem_id})
        event.post('submissions', {'type': 'done-submission', 'id': submission.id,
                                   'contest': submission.contest_key,
                                   'user': submission.user_id, 'problem': submission.problem_id})