Ejemplo n.º 1
0
Archivo: record.py Proyecto: vijos/vj4
async def user_in_problem(uid: int, domain_id: str, pid: document.convert_doc_id):
  psdoc = await document.rev_init_status(domain_id, document.TYPE_PROBLEM, pid, uid)
  rdocs = record.get_multi(uid=uid, domain_id=domain_id, pid=pid,
                           type=constant.record.TYPE_SUBMISSION,
                           fields={'_id': 1, 'uid': 1,
                                   'status': 1, 'score': 1}).sort('_id', 1)
  new_psdoc = {'num_submit': 0, 'status': 0}
  async for rdoc in rdocs:
    new_psdoc['num_submit'] += 1
    if new_psdoc['status'] != constant.record.STATUS_ACCEPTED:
      new_psdoc['status'] = rdoc['status']
      new_psdoc['rid'] = rdoc['_id']
  _logger.info(repr(new_psdoc))
  if await document.rev_set_status(domain_id, document.TYPE_PROBLEM, pid, uid,
                                   psdoc['rev'], **new_psdoc):
    delta_submit = new_psdoc['num_submit'] - psdoc.get('num_submit', 0)
    if new_psdoc['status'] == constant.record.STATUS_ACCEPTED \
       and psdoc.get('status', 0) != constant.record.STATUS_ACCEPTED:
      delta_accept = 1
    elif new_psdoc['status'] != constant.record.STATUS_ACCEPTED \
         and psdoc.get('status', 0) == constant.record.STATUS_ACCEPTED:
      delta_accept = -1
    else:
      delta_accept = 0
    post_coros = []
    if delta_submit != 0:
      post_coros.append(problem.inc(domain_id, pid, 'num_submit', delta_submit))
      post_coros.append(domain.inc_user(domain_id, uid, num_submit=delta_submit))
    if delta_accept != 0:
      post_coros.append(problem.inc(domain_id, pid, 'num_accept', delta_accept))
      post_coros.append(domain.inc_user(domain_id, uid, num_accept=delta_accept))
    if post_coros:
      await asyncio.gather(*post_coros)
Ejemplo n.º 2
0
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)
Ejemplo n.º 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
Ejemplo n.º 4
0
async def user_in_problem(uid: int, domain_id: str,
                          pid: document.convert_doc_id):
    psdoc = await document.rev_init_status(domain_id, document.TYPE_PROBLEM,
                                           pid, uid)
    rdocs = record.get_multi(uid=uid,
                             domain_id=domain_id,
                             pid=pid,
                             type=constant.record.TYPE_SUBMISSION,
                             fields={
                                 '_id': 1,
                                 'uid': 1,
                                 'status': 1,
                                 'score': 1
                             }).sort('_id', 1)
    new_psdoc = {'num_submit': 0, 'status': 0}
    async for rdoc in rdocs:
        new_psdoc['num_submit'] += 1
        if new_psdoc['status'] != constant.record.STATUS_ACCEPTED:
            new_psdoc['status'] = rdoc['status']
            new_psdoc['rid'] = rdoc['_id']
    _logger.info(repr(new_psdoc))
    if await document.rev_set_status(domain_id, document.TYPE_PROBLEM, pid,
                                     uid, psdoc['rev'], **new_psdoc):
        delta_submit = new_psdoc['num_submit'] - psdoc.get('num_submit', 0)
        if new_psdoc['status'] == constant.record.STATUS_ACCEPTED \
           and psdoc.get('status', 0) != constant.record.STATUS_ACCEPTED:
            delta_accept = 1
        elif new_psdoc['status'] != constant.record.STATUS_ACCEPTED \
             and psdoc.get('status', 0) == constant.record.STATUS_ACCEPTED:
            delta_accept = -1
        else:
            delta_accept = 0
        post_coros = []
        if delta_submit != 0:
            post_coros.append(
                problem.inc(domain_id, pid, 'num_submit', delta_submit))
            post_coros.append(
                domain.inc_user(domain_id, uid, num_submit=delta_submit))
        if delta_accept != 0:
            post_coros.append(
                problem.inc(domain_id, pid, 'num_accept', delta_accept))
            post_coros.append(
                domain.inc_user(domain_id, uid, num_accept=delta_accept))
        if post_coros:
            await asyncio.gather(*post_coros)
Ejemplo n.º 5
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