Exemplo n.º 1
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
Exemplo n.º 2
0
async def add(domain_id: str,
              pid: document.convert_doc_id,
              type: int,
              uid: int,
              lang: str,
              code: Union[str, objectid.ObjectId],
              data_id: objectid.ObjectId = None,
              tid: objectid.ObjectId = None,
              hidden=False,
              show_detail=False,
              code_type=constant.record.FILE_TYPE_TEXT,
              judge_category=[]):
    validator.check_lang(lang)
    coll = db.coll('record')
    doc = {
        'hidden': hidden,
        'show_detail': show_detail,
        'status': constant.record.STATUS_WAITING,
        'score': 0,
        'time_ms': 0,
        'memory_kb': 0,
        'domain_id': domain_id,
        'pid': pid,
        'uid': uid,
        'lang': lang,
        'code_type': code_type,
        'code': code,
        'tid': tid,
        'data_id': data_id,
        'type': type,
        'judge_category': judge_category
    }
    rid = (await coll.insert_one(doc)).inserted_id
    bus.publish_throttle('record_change', doc, rid)
    post_coros = [queue.publish('judge', rid=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