예제 #1
0
파일: training.py 프로젝트: sevenwang/vj4
 async def get(self, tid: objectid.ObjectId):
     tdoc = await training.get(self.domain_id, tid)
     pids = self.get_pids(tdoc)
     # TODO(twd2): check status, eg. test, hidden problem, ...
     owner_udoc, pdict, psdict = await asyncio.gather(
         user.get_by_uid(tdoc['owner_uid']),
         problem.get_dict(self.domain_id, pids),
         problem.get_dict_status(self.domain_id, self.user['_id'], pids))
     done_pids = set()
     prog_pids = set()
     for pid, psdoc in psdict.items():
         if 'status' in psdoc:
             if psdoc['status'] == constant.record.STATUS_ACCEPTED:
                 done_pids.add(pid)
             else:
                 prog_pids.add(pid)
     nsdict = {}
     ndict = {}
     done_nids = set()
     for node in tdoc['dag']:
         ndict[node['_id']] = node
         total_count = len(node['pids'])
         done_count = len(set(node['pids']) & set(done_pids))
         nsdoc = {
             'progress':
             int(100 * done_count / total_count) if total_count else 100,
             'is_done':
             self.is_done(node, done_nids, done_pids),
             'is_progress':
             self.is_progress(node, done_nids, done_pids, prog_pids),
             'is_open':
             self.is_open(node, done_nids, done_pids, prog_pids),
             'is_invalid':
             self.is_invalid(node, done_nids)
         }
         if nsdoc['is_done']:
             done_nids.add(node['_id'])
         nsdict[node['_id']] = nsdoc
     tsdoc = await training.set_status(self.domain_id,
                                       tdoc['doc_id'],
                                       self.user['_id'],
                                       done_nids=list(done_nids),
                                       done_pids=list(done_pids),
                                       done=len(done_nids) == len(
                                           tdoc['dag']))
     path_components = self.build_path((self.translate('training_main'),
                                        self.reverse_url('training_main')),
                                       (tdoc['title'], None))
     self.render('training_detail.html',
                 tdoc=tdoc,
                 tsdoc=tsdoc,
                 pids=pids,
                 pdict=pdict,
                 psdict=psdict,
                 ndict=ndict,
                 nsdict=nsdict,
                 owner_udoc=owner_udoc,
                 page_title=tdoc['title'],
                 path_components=path_components)
예제 #2
0
파일: contest.py 프로젝트: imxieyi/vj4
 async def get(self, *, tid: objectid.ObjectId, page: int = 1):
     # contest
     tdoc = await contest.get(self.domain_id, tid)
     tsdoc, pdict = await asyncio.gather(
         contest.get_status(self.domain_id, tdoc['doc_id'],
                            self.user['_id']),
         problem.get_dict(self.domain_id, tdoc['pids']))
     psdict = dict()
     rdict = dict()
     if tsdoc:
         attended = tsdoc.get('attend') == 1
         for pdetail in tsdoc.get('detail', []):
             psdict[pdetail['pid']] = pdetail
         if self.can_show_record(tdoc):
             rdict = await record.get_dict(
                 (psdoc['rid'] for psdoc in psdict.values()),
                 get_hidden=True)
         else:
             rdict = dict((psdoc['rid'], {
                 '_id': psdoc['rid']
             }) for psdoc in psdict.values())
     else:
         attended = False
     # discussion
     ddocs, dpcount, dcount = await pagination.paginate(
         discussion.get_multi(self.domain_id,
                              parent_doc_type=tdoc['doc_type'],
                              parent_doc_id=tdoc['doc_id']), page,
         self.DISCUSSIONS_PER_PAGE)
     uids = set(ddoc['owner_uid'] for ddoc in ddocs)
     uids.add(tdoc['owner_uid'])
     udict = await user.get_dict(uids)
     dudict = await domain.get_dict_user_by_uid(domain_id=self.domain_id,
                                                uids=uids)
     path_components = self.build_path(
         (self.translate('contest_main'), self.reverse_url('contest_main')),
         (tdoc['title'], None))
     self.render('contest_detail.html',
                 tdoc=tdoc,
                 tsdoc=tsdoc,
                 attended=attended,
                 udict=udict,
                 dudict=dudict,
                 pdict=pdict,
                 psdict=psdict,
                 rdict=rdict,
                 ddocs=ddocs,
                 page=page,
                 dpcount=dpcount,
                 dcount=dcount,
                 datetime_stamp=self.datetime_stamp,
                 page_title=tdoc['title'],
                 path_components=path_components)
예제 #3
0
파일: contest.py 프로젝트: SimpleOJ/vj4
 async def get_scoreboard(self,
                          tid: objectid.ObjectId,
                          is_export: bool = False):
     tdoc, tsdocs = await contest.get_and_list_status(self.domain_id, tid)
     if not self.can_show_scoreboard(tdoc):
         raise error.ContestScoreboardHiddenError(self.domain_id, tid)
     udict, pdict = await asyncio.gather(
         user.get_dict([tsdoc['uid'] for tsdoc in tsdocs]),
         problem.get_dict(self.domain_id, tdoc['pids']))
     ranked_tsdocs = contest.RULES[tdoc['rule']].rank_func(tsdocs)
     rows = contest.RULES[tdoc['rule']].scoreboard_func(
         is_export, self.translate, tdoc, ranked_tsdocs, udict, pdict)
     return tdoc, rows
예제 #4
0
 async def get(self, *, tid: objectid.ObjectId):
   tdoc, tsdocs = await contest.get_and_list_status(self.domain_id, tid)
   if (not contest.RULES[tdoc['rule']].show_func(tdoc, self.now)
       and not self.has_perm(builtin.PERM_VIEW_CONTEST_HIDDEN_STATUS)):
     raise error.ContestStatusHiddenError()
   udict, pdict = await asyncio.gather(user.get_dict([tsdoc['uid'] for tsdoc in tsdocs]),
                                       problem.get_dict(self.domain_id, tdoc['pids']))
   ranked_tsdocs = contest.RULES[tdoc['rule']].rank_func(tsdocs)
   path_components = self.build_path(
       (self.translate('contest_main'), self.reverse_url('contest_main')),
       (tdoc['title'], self.reverse_url('contest_detail', tid=tdoc['doc_id'])),
       (self.translate('contest_status'), None))
   self.render('contest_status.html', tdoc=tdoc, ranked_tsdocs=ranked_tsdocs, dict=dict,
               udict=udict, pdict=pdict, path_components=path_components)
예제 #5
0
파일: training.py 프로젝트: vijos/vj4
 async def get(self, tid: objectid.ObjectId):
   tdoc = await training.get(self.domain_id, tid)
   pids = self.get_pids(tdoc)
   # TODO(twd2): check status, eg. test, hidden problem, ...
   if not self.has_perm(builtin.PERM_VIEW_PROBLEM_HIDDEN):
     f = {'hidden': False}
   else:
     f = {}
   owner_udoc, owner_dudoc, pdict = await asyncio.gather(
       user.get_by_uid(tdoc['owner_uid']),
       domain.get_user(domain_id=self.domain_id, uid=tdoc['owner_uid']),
       problem.get_dict(self.domain_id, pids, **f))
   psdict = await problem.get_dict_status(self.domain_id,
                                          self.user['_id'], pdict.keys())
   done_pids = set()
   prog_pids = set()
   for pid, psdoc in psdict.items():
     if 'status' in psdoc:
       if psdoc['status'] == constant.record.STATUS_ACCEPTED:
         done_pids.add(pid)
       else:
         prog_pids.add(pid)
   nsdict = {}
   ndict = {}
   done_nids = set()
   for node in tdoc['dag']:
     ndict[node['_id']] = node
     total_count = len(node['pids'])
     done_count = len(set(node['pids']) & set(done_pids))
     nsdoc = {'progress': int(100 * done_count / total_count) if total_count else 100,
              'is_done': self.is_done(node, done_nids, done_pids),
              'is_progress': self.is_progress(node, done_nids, done_pids, prog_pids),
              'is_open': self.is_open(node, done_nids, done_pids, prog_pids),
              'is_invalid': self.is_invalid(node, done_nids)}
     if nsdoc['is_done']:
       done_nids.add(node['_id'])
     nsdict[node['_id']] = nsdoc
   tsdoc = await training.set_status(self.domain_id, tdoc['doc_id'], self.user['_id'],
                                     done_nids=list(done_nids), done_pids=list(done_pids),
                                     done=len(done_nids) == len(tdoc['dag']))
   path_components = self.build_path(
       (self.translate('training_main'), self.reverse_url('training_main')),
       (tdoc['title'], None))
   self.render('training_detail.html', tdoc=tdoc, tsdoc=tsdoc, pids=pids,
               pdict=pdict, psdict=psdict, ndict=ndict, nsdict=nsdict,
               owner_udoc=owner_udoc, owner_dudoc=owner_dudoc,
               page_title=tdoc['title'], path_components=path_components)
예제 #6
0
 async def get_scoreboard(self, doc_type: int, tid: objectid.ObjectId, is_export: bool=False):
   if doc_type not in [document.TYPE_CONTEST, document.TYPE_HOMEWORK]:
     raise error.InvalidArgumentError('doc_type')
   tdoc, tsdocs = await get_and_list_status(self.domain_id, doc_type, tid)
   if not self.can_show_scoreboard(tdoc):
     if doc_type == document.TYPE_CONTEST:
       raise error.ContestScoreboardHiddenError(self.domain_id, tid)
     elif doc_type == document.TYPE_HOMEWORK:
       raise error.HomeworkScoreboardHiddenError(self.domain_id, tid)
   udict, dudict, pdict = await asyncio.gather(
       user.get_dict([tsdoc['uid'] for tsdoc in tsdocs]),
       domain.get_dict_user_by_uid(self.domain_id, [tsdoc['uid'] for tsdoc in tsdocs]),
       problem.get_dict(self.domain_id, tdoc['pids']))
   ranked_tsdocs = RULES[tdoc['rule']].rank_func(tsdocs)
   rows = RULES[tdoc['rule']].scoreboard_func(is_export, self.translate, tdoc,
                                                      ranked_tsdocs, udict, dudict, pdict)
   return tdoc, rows, udict
예제 #7
0
파일: contest.py 프로젝트: vijos/vj4
 async def get_scoreboard(self, doc_type: int, tid: objectid.ObjectId, is_export: bool=False):
   if doc_type not in [document.TYPE_CONTEST, document.TYPE_HOMEWORK]:
     raise error.InvalidArgumentError('doc_type')
   tdoc, tsdocs = await get_and_list_status(self.domain_id, doc_type, tid)
   if not self.can_show_scoreboard(tdoc):
     if doc_type == document.TYPE_CONTEST:
       raise error.ContestScoreboardHiddenError(self.domain_id, tid)
     elif doc_type == document.TYPE_HOMEWORK:
       raise error.HomeworkScoreboardHiddenError(self.domain_id, tid)
   udict, dudict, pdict = await asyncio.gather(
       user.get_dict([tsdoc['uid'] for tsdoc in tsdocs]),
       domain.get_dict_user_by_uid(self.domain_id, [tsdoc['uid'] for tsdoc in tsdocs]),
       problem.get_dict(self.domain_id, tdoc['pids']))
   ranked_tsdocs = RULES[tdoc['rule']].rank_func(tsdocs)
   rows = RULES[tdoc['rule']].scoreboard_func(is_export, self.translate, tdoc,
                                                      ranked_tsdocs, udict, dudict, pdict)
   return tdoc, rows, udict
예제 #8
0
 async def get(self, *, tid: objectid.ObjectId, ext: str):
   get_content = {
     'csv': self.get_csv_content,
     'html': self.get_html_content,
   }
   if ext not in get_content:
     raise error.ValidationError('ext')
   tdoc, tsdocs = await contest.get_and_list_status(self.domain_id, tid)
   if (not contest.RULES[tdoc['rule']].show_func(tdoc, self.now)
       and not self.has_perm(builtin.PERM_VIEW_CONTEST_HIDDEN_STATUS)):
     raise error.ContestStatusHiddenError()
   udict, pdict = await asyncio.gather(user.get_dict([tsdoc['uid'] for tsdoc in tsdocs]),
                                       problem.get_dict(self.domain_id, tdoc['pids']))
   ranked_tsdocs = contest.RULES[tdoc['rule']].rank_func(tsdocs)
   get_status = {
     constant.contest.RULE_ACM: self.get_acm_status,
     constant.contest.RULE_OI: self.get_oi_status,
   }
   rows = get_status[tdoc['rule']](tdoc, ranked_tsdocs, udict, pdict)
   data = get_content[ext](rows)
   file_name = tdoc['title']
   for char in '/<>:\"\'\\|?* ':
     file_name = file_name.replace(char, '')
   await self.binary(data, file_name='{0}.{1}'.format(file_name, ext))
예제 #9
0
파일: contest.py 프로젝트: vijos/vj4
 async def get(self, *, tid: objectid.ObjectId, page: int=1):
   tdoc = await contest.get(self.domain_id, document.TYPE_CONTEST, tid)
   tsdoc, pdict = await asyncio.gather(
       contest.get_status(self.domain_id, document.TYPE_CONTEST, tdoc['doc_id'], self.user['_id']),
       problem.get_dict(self.domain_id, tdoc['pids']))
   psdict = dict()
   rdict = dict()
   if tsdoc:
     attended = tsdoc.get('attend') == 1
     for pdetail in tsdoc.get('detail', []):
       psdict[pdetail['pid']] = pdetail
     if self.can_show_record(tdoc):
       rdict = await record.get_dict((psdoc['rid'] for psdoc in psdict.values()),
                                     get_hidden=True)
     else:
       rdict = dict((psdoc['rid'], {'_id': psdoc['rid']}) for psdoc in psdict.values())
   else:
     attended = False
   # discussion
   ddocs, dpcount, dcount = await pagination.paginate(
       discussion.get_multi(self.domain_id,
                            parent_doc_type=tdoc['doc_type'],
                            parent_doc_id=tdoc['doc_id']),
       page, self.DISCUSSIONS_PER_PAGE)
   uids = set(ddoc['owner_uid'] for ddoc in ddocs)
   uids.add(tdoc['owner_uid'])
   udict = await user.get_dict(uids)
   dudict = await domain.get_dict_user_by_uid(domain_id=self.domain_id, uids=uids)
   path_components = self.build_path(
     (self.translate('contest_main'), self.reverse_url('contest_main')),
     (tdoc['title'], None))
   self.render('contest_detail.html', tdoc=tdoc, tsdoc=tsdoc, attended=attended, udict=udict,
               dudict=dudict, pdict=pdict, psdict=psdict, rdict=rdict,
               ddocs=ddocs, page=page, dpcount=dpcount, dcount=dcount,
               datetime_stamp=self.datetime_stamp,
               page_title=tdoc['title'], path_components=path_components)
예제 #10
0
파일: contest.py 프로젝트: imxieyi/vj4
 async def get_scoreboard(self,
                          tid: objectid.ObjectId,
                          is_export: bool = False):
     tdoc, tsdocs = await contest.get_and_list_status(self.domain_id, tid)
     if not self.can_show_scoreboard(tdoc):
         raise error.ContestScoreboardHiddenError(self.domain_id, tid)
     udict, dudict, pdict = await asyncio.gather(
         user.get_dict([tsdoc['uid'] for tsdoc in tsdocs]),
         domain.get_dict_user_by_uid(self.domain_id,
                                     [tsdoc['uid'] for tsdoc in tsdocs]),
         problem.get_dict(self.domain_id, tdoc['pids']))
     for pkey in pdict:
         p = pdict[pkey]
         p['dataUploadTime'] = await fs.get_datetime(p['data'])
     #_logger.error(pdict)
     #_logger.error(tsdocs)
     for ts in tsdocs:
         #_logger.error(type(ts))
         if not 'journal' in ts:
             continue
         journal = ts['journal']
         ts['submit_count_highest'] = {}
         ts['submit_count_total'] = {}
         ts['highest_score'] = {}
         ts['highest_score_rid'] = {}
         ts['highest_penalized_score'] = {}
         ts['highest_penalized_score_rid'] = {}
         # Initialize counter to 0
         for p in pdict:
             ts['submit_count_total'][p] = 0
             ts['highest_score'][p] = 0
             ts['highest_penalized_score'][p] = 0
         # Journal records all submissions related to the contest
         jdocs = []
         for j in journal:
             jdocs.append(await record.get(j['rid']))
         #jdocs = sorted(jdocs, key=lambda k: k['judge_at'])
         #if ts['uid'] == -3:
         #  _logger.error(jdocs)
         for jdoc in jdocs:
             p = jdoc['pid']
             #_logger.error(p)
             #_logger.error(jdoc['_id'])
             #_logger.error(pdict[p]['dataUploadTime'])
             #_logger.error(jdoc['judge_at'])
             # If judge time is after data upload time, add the counter
             if 'judge_at' in jdoc:
                 if jdoc['judge_at'] >= pdict[p]['dataUploadTime']:
                     #_logger.error('gg')
                     penalized_score = jdoc[
                         'score'] - ts['submit_count_total'][
                             p] * builtin.RULE_PENALTY_SCORE_PER_SUBMISSION
                     if penalized_score < 0:
                         penalized_score = 0
                     ts['submit_count_total'][p] += 1
                     if penalized_score > ts['highest_penalized_score'][p]:
                         ts['highest_penalized_score'][p] = penalized_score
                         ts['highest_penalized_score_rid'][p] = jdoc['_id']
                     if ts['highest_score'][p] < jdoc['score']:
                         #if ts['uid'] == -3:
                         #  _logger.error(highest)
                         #  _logger.error(jdoc['score'])
                         ts['highest_score'][p] = jdoc['score']
                         ts['submit_count_highest'][p] = ts[
                             'submit_count_total'][p]
                         ts['highest_score_rid'][p] = jdoc['_id']
         sum_score = 0
         for p in pdict:
             sum_score += ts['highest_penalized_score'][p]
         ts['sum_score'] = sum_score
     tsdocs = sorted(tsdocs,
                     key=lambda k: k.get('sum_score', 0),
                     reverse=True)
     #_logger.error([ts['highest_penalized_score'] for ts in tsdocs])
     ranked_tsdocs = contest.RULES[tdoc['rule']].rank_func(tsdocs)
     rows = contest.RULES[tdoc['rule']].scoreboard_func(
         is_export, self.translate, tdoc, ranked_tsdocs, udict, dudict,
         pdict)
     #_logger.error(tdoc)
     return tdoc, rows, udict