예제 #1
0
파일: judge.py 프로젝트: sevenwang/vj4
async def _post_judge(rdoc):
  await opcount.force_inc(**opcount.OPS['run_code'], ident=opcount.PREFIX_USER + str(rdoc['uid']),
                          operations=rdoc['time_ms'])
  accept = rdoc['status'] == constant.record.STATUS_ACCEPTED
  post_coros = [bus.publish('record_change', rdoc['_id'])]
  # TODO(twd2): ignore no effect statuses like system error, ...
  if rdoc['type'] == constant.record.TYPE_SUBMISSION:
    if accept:
      # TODO(twd2): send ac mail
      pass
    if rdoc['tid']:
      post_coros.append(contest.update_status(rdoc['domain_id'], rdoc['tid'], rdoc['uid'],
                                              rdoc['_id'], rdoc['pid'], accept, rdoc['score']))
    if not rdoc.get('rejudged'):
      if await problem.update_status(rdoc['domain_id'], rdoc['pid'], rdoc['uid'],
                                     rdoc['_id'], rdoc['status']):
        post_coros.append(problem.inc(rdoc['domain_id'], rdoc['pid'], 'num_accept', 1))
        post_coros.append(domain.inc_user(rdoc['domain_id'], rdoc['uid'], num_accept=1))
      if accept:
        # TODO(twd2): enqueue rdoc['pid'] to recalculate rp.
        pass
    else:
      # TODO(twd2): enqueue rdoc['pid'] to recalculate rp.
      await job.record.user_in_problem(rdoc['uid'], rdoc['domain_id'], rdoc['pid'])
  await asyncio.gather(*post_coros)
예제 #2
0
파일: problem.py 프로젝트: JoshOY/vj4
 async def post(self, *, pid: document.convert_doc_id, lang: str, code: str, data_input: str, data_output: str):
   tid = await document.add(self.domain_id, None, self.user['_id'], document.TYPE_PRETEST_DATA,
                            data_input = self.request.POST.getall('data_input'),
                            data_output = self.request.POST.getall('data_output'))
   rid = await record.add(self.domain_id, pid, record.TYPE_PRETEST, self.user['_id'], lang, code, tid)
   await asyncio.gather(queue.publish('judge', rid=rid), bus.publish('record_change', rid))
   self.json_or_redirect(self.reverse_url('record_main'))
예제 #3
0
async def add(domain_id: str, pid: document.convert_doc_id, type: int, uid: int,
              lang: str, code: str, data_id: objectid.ObjectId=None, tid: objectid.ObjectId=None,
              hidden=False):
  validator.check_lang(lang)
  coll = db.Collection('record')
  rid = (await coll.insert_one({'hidden': hidden,
                                'status': constant.record.STATUS_WAITING,
                                'score': 0,
                                'time_ms': 0,
                                'memory_kb': 0,
                                'domain_id': domain_id,
                                'pid': pid,
                                'uid': uid,
                                'lang': lang,
                                'code': code,
                                'tid': tid,
                                'data_id': data_id,
                                'type': type})).inserted_id
  post_coros = [queue.publish('judge', rid=rid),
                bus.publish('record_change', rid)]
  if type == constant.record.TYPE_SUBMISSION:
    post_coros.extend([problem.inc_status(domain_id, pid, uid, 'num_submit', 1),
                       problem.inc(domain_id, pid, 'num_submit', 1),
                       domain.inc_user(domain_id, uid, num_submit=1)])
  await asyncio.gather(*post_coros)
  return rid
예제 #4
0
async def rejudge(record_id: objectid.ObjectId, enqueue: bool = True):
    coll = db.Collection('record')
    doc = await coll.find_one_and_update(
        filter={'_id': record_id},
        update={
            '$unset': {
                'judge_uid': '',
                'judge_token': '',
                'judge_at': '',
                'compiler_texts': '',
                'judge_texts': '',
                'cases': ''
            },
            '$set': {
                'status': constant.record.STATUS_WAITING,
                'score': 0,
                'time_ms': 0,
                'memory_kb': 0,
                'rejudged': True
            }
        },
        return_document=ReturnDocument.BEFORE)
    post_coros = [bus.publish('record_change', doc['_id'])]
    if enqueue:
        post_coros.append(queue.publish('judge', rid=doc['_id']))
    await asyncio.gather(*post_coros)
예제 #5
0
파일: judge.py 프로젝트: JoshOY/vj4
 async def close():
   await asyncio.gather(*[record.end_judge(rid, self.user['_id'], self.id,
                                           record.STATUS_CANCELED, 0, 0, 0)
                          for rid in self.rids.values()])
   await asyncio.gather(*[bus.publish('record_change', rid)
                          for rid in self.rids.values()])
   # There is a bug in current version's aioamqp and we cannot use no_wait=True here.
   await self.channel.close()
예제 #6
0
파일: judge.py 프로젝트: sevenwang/vj4
 async def close():
   await asyncio.gather(*[record.end_judge(rid, self.user['_id'], self.id,
                                           constant.record.STATUS_CANCELED, 0, 0, 0)
                          for rid in self.rids.values()])
   await asyncio.gather(*[bus.publish('record_change', rid)
                          for rid in self.rids.values()])
   # There is a bug in current version's aioamqp and we cannot use no_wait=True here.
   await self.channel.close()
예제 #7
0
 async def post(self, *, pid: document.convert_doc_id, lang: str,
                code: str):
     pdoc = await problem.get(self.domain_id, pid)
     rid = await record.add(self.domain_id, pdoc['doc_id'],
                            record.TYPE_SUBMISSION, self.user['_id'], lang,
                            code)
     await asyncio.gather(queue.publish('judge', rid=rid),
                          bus.publish('record_change', rid))
     self.json_or_redirect(self.reverse_url('record_main'))
예제 #8
0
 async def post(self, *, pid: document.convert_doc_id, lang: str, code: str,
                data_input: str, data_output: str):
     tid = await document.add(
         self.domain_id,
         None,
         self.user['_id'],
         document.TYPE_PRETEST_DATA,
         data_input=self.request.POST.getall('data_input'),
         data_output=self.request.POST.getall('data_output'))
     rid = await record.add(self.domain_id, pid, record.TYPE_PRETEST,
                            self.user['_id'], lang, code, tid)
     await asyncio.gather(queue.publish('judge', rid=rid),
                          bus.publish('record_change', rid))
     self.json_or_redirect(self.reverse_url('record_main'))
예제 #9
0
 async def on_message(self, *, key, tag, **kwargs):
     if key == 'next':
         rid = self.rids[tag]
         update = {}
         if 'status' in kwargs:
             update.setdefault('$set', {})['status'] = int(kwargs['status'])
         if 'compiler_text' in kwargs:
             update.setdefault('$push', {})['compiler_texts'] = str(
                 kwargs['compiler_text'])
         if 'judge_text' in kwargs:
             update.setdefault('$push', {})['judge_texts'] = str(
                 kwargs['judge_text'])
         if 'case' in kwargs:
             update.setdefault('$push', {})['cases'] = {
                 'status': int(kwargs['case']['status']),
                 'score': int(kwargs['case']['score']),
                 'time_ms': int(kwargs['case']['time_ms']),
                 'memory_kb': int(kwargs['case']['memory_kb']),
             }
         await record.next_judge(rid, self.user['_id'], self.id, **update)
         await bus.publish('record_change', rid)
     elif key == 'end':
         rid = self.rids.pop(tag)
         rdoc, _ = await asyncio.gather(
             record.end_judge(rid, self.user['_id'], self.id,
                              int(kwargs['status']), int(kwargs['score']),
                              int(kwargs['time_ms']),
                              int(kwargs['memory_kb'])),
             self.channel.basic_client_ack(tag))
         accept = True if rdoc['status'] == record.STATUS_ACCEPTED else False
         # TODO(twd2): update problem
         post_coros = [
             problem.update_status(rdoc['domain_id'], rdoc['pid'],
                                   rdoc['uid'], rdoc['_id'],
                                   rdoc['status']),
             bus.publish('record_change', rid)
         ]
         if rdoc['tid']:
             post_coros.append(
                 contest.update_status(rdoc['domain_id'], rdoc['tid'],
                                       rdoc['uid'], rdoc['_id'],
                                       rdoc['pid'], accept, rdoc['score']))
         if accept:
             post_coros.append(
                 training.update_status_by_pid(rdoc['domain_id'],
                                               rdoc['uid'], rdoc['pid']))
         await asyncio.gather(*post_coros)
     elif key == 'nack':
         await self.channel.basic_client_nack(tag)
예제 #10
0
파일: judge.py 프로젝트: JoshOY/vj4
 async def on_message(self, *, key, tag, **kwargs):
   if key == 'next':
     rid = self.rids[tag]
     update = {}
     if 'status' in kwargs:
       update.setdefault('$set', {})['status'] = int(kwargs['status'])
     if 'compiler_text' in kwargs:
       update.setdefault('$push', {})['compiler_texts'] = str(kwargs['compiler_text'])
     if 'judge_text' in kwargs:
       update.setdefault('$push', {})['judge_texts'] = str(kwargs['judge_text'])
     if 'case' in kwargs:
       update.setdefault('$push', {})['cases'] = {
         'status': int(kwargs['case']['status']),
         'score': int(kwargs['case']['score']),
         'time_ms': int(kwargs['case']['time_ms']),
         'memory_kb': int(kwargs['case']['memory_kb']),
       }
     await record.next_judge(rid, self.user['_id'], self.id, **update)
     await bus.publish('record_change', rid)
   elif key == 'end':
     rid = self.rids.pop(tag)
     rdoc, _ = await asyncio.gather(record.end_judge(rid, self.user['_id'], self.id,
                                                     int(kwargs['status']),
                                                     int(kwargs['score']),
                                                     int(kwargs['time_ms']),
                                                     int(kwargs['memory_kb'])),
                                    self.channel.basic_client_ack(tag))
     accept = True if rdoc['status'] == record.STATUS_ACCEPTED else False
     # TODO(twd2): update problem
     post_coros = [problem.update_status(rdoc['domain_id'], rdoc['pid'], rdoc['uid'],
                                         rdoc['_id'], rdoc['status']),
                   bus.publish('record_change', rid)]
     if rdoc['tid']:
       post_coros.append(contest.update_status(rdoc['domain_id'], rdoc['tid'], rdoc['uid'],
                                               rdoc['_id'], rdoc['pid'], accept, rdoc['score']))
     if accept:
       post_coros.append(training.update_status_by_pid(rdoc['domain_id'],
                                                       rdoc['uid'], rdoc['pid']))
     await asyncio.gather(*post_coros)
   elif key == 'nack':
     await self.channel.basic_client_nack(tag)
예제 #11
0
파일: problem.py 프로젝트: JoshOY/vj4
 async def post(self, *, pid: document.convert_doc_id, lang: str, code: str):
   pdoc = await problem.get(self.domain_id, pid)
   rid = await record.add(self.domain_id, pdoc['doc_id'], record.TYPE_SUBMISSION, self.user['_id'], lang, code)
   await asyncio.gather(queue.publish('judge', rid=rid), bus.publish('record_change', rid))
   self.json_or_redirect(self.reverse_url('record_main'))