async def get(self, *, doc_type: int=None, doc_id: str, page: int=1): if doc_type is None: node_or_dtuple = doc_id else: node_or_dtuple = (doc_type, document.convert_doc_id(doc_id)) nodes, vnode = await discussion.get_nodes_and_vnode(self.domain_id, node_or_dtuple) if not vnode: raise error.DiscussionNodeNotFoundError(self.domain_id, node_or_dtuple) if vnode['doc_type'] == document.TYPE_PROBLEM and vnode.get('hidden', False): self.check_perm(builtin.PERM_VIEW_PROBLEM_HIDDEN) # TODO(twd2): do more visibility check eg. contest # TODO(iceboy): continuation based pagination. ddocs, dpcount, _ = await pagination.paginate( discussion.get_multi(self.domain_id, parent_doc_type=vnode['doc_type'], parent_doc_id=vnode['doc_id']), page, self.DISCUSSIONS_PER_PAGE) uids = set(ddoc['owner_uid'] for ddoc in ddocs) if 'owner_uid' in vnode: uids.add(vnode['owner_uid']) udict, dudict = await asyncio.gather(user.get_dict(uids), domain.get_dict_user_by_uid(self.domain_id, uids)) vndict = {node_or_dtuple: vnode} vncontext = {} # TODO(twd2): eg. psdoc, tsdoc, ... path_components = self.build_path( (self.translate('discussion_main'), self.reverse_url('discussion_main')), (vnode['title'], None)) self.render('discussion_main_or_node.html', discussion_nodes=nodes, vnode=vnode, ddocs=ddocs, udict=udict, dudict=dudict, vndict=vndict, page=page, dpcount=dpcount, **vncontext, path_components=path_components)
async def get(self, *, did: document.convert_doc_id, page: int=1): ddoc = await discussion.inc_views(self.domain_id, did) if self.has_priv(builtin.PRIV_USER_PROFILE): dsdoc = await discussion.get_status(self.domain_id, ddoc['doc_id'], self.user['_id']) else: dsdoc = None vnode, (drdocs, pcount, drcount) = await asyncio.gather( discussion.get_vnode(self.domain_id, discussion.node_id(ddoc)), pagination.paginate(discussion.get_multi_reply(self.domain_id, ddoc['doc_id']), page, self.REPLIES_PER_PAGE)) if not vnode: vnode = builtin.VNODE_MISSING elif vnode['doc_type'] == document.TYPE_PROBLEM and vnode.get('hidden', False): self.check_perm(builtin.PERM_VIEW_PROBLEM_HIDDEN) # TODO(twd2): do more visibility check eg. contest uids = {ddoc['owner_uid']} uids.update(drdoc['owner_uid'] for drdoc in drdocs) for drdoc in drdocs: if 'reply' in drdoc: uids.update(drrdoc['owner_uid'] for drrdoc in drdoc['reply']) if 'owner_uid' in vnode: uids.add(vnode['owner_uid']) udict, dudict = await asyncio.gather(user.get_dict(uids), domain.get_dict_user_by_uid(self.domain_id, uids)) path_components = self.build_path( (self.translate('discussion_main'), self.reverse_url('discussion_main')), (vnode['title'], node_url(self, 'discussion_node', discussion.node_id(ddoc))), (ddoc['title'], None)) self.render('discussion_detail.html', page_title=ddoc['title'], path_components=path_components, ddoc=ddoc, dsdoc=dsdoc, drdocs=drdocs, page=page, pcount=pcount, drcount=drcount, vnode=vnode, udict=udict, dudict=dudict)
async def get(self, *, pid: document.convert_doc_id, page: int=1): uid = self.user['_id'] if self.has_priv(builtin.PRIV_USER_PROFILE) else None pdoc = await problem.get(self.domain_id, pid, uid) if pdoc.get('hidden', False): self.check_perm(builtin.PERM_VIEW_PROBLEM_HIDDEN) psdocs, pcount, pscount = await pagination.paginate( problem.get_multi_solution(self.domain_id, pdoc['doc_id']), page, self.SOLUTIONS_PER_PAGE) uids = {pdoc['owner_uid']} uids.update(psdoc['owner_uid'] for psdoc in psdocs) for psdoc in psdocs: if 'reply' in psdoc: uids.update(psrdoc['owner_uid'] for psrdoc in psdoc['reply']) udict, dudict, pssdict = await asyncio.gather( user.get_dict(uids), domain.get_dict_user_by_uid(self.domain_id, uids), problem.get_dict_solution_status( self.domain_id, (psdoc['doc_id'] for psdoc in psdocs), self.user['_id'])) dudict[self.user['_id']] = self.domain_user path_components = self.build_path( (self.translate('problem_main'), self.reverse_url('problem_main')), (pdoc['title'], self.reverse_url('problem_detail', pid=pdoc['doc_id'])), (self.translate('problem_solution'), None)) self.render('problem_solution.html', path_components=path_components, pdoc=pdoc, psdocs=psdocs, page=page, pcount=pcount, pscount=pscount, udict=udict, dudict=dudict, pssdict=pssdict)
async def get(self, *, uid_or_name: str = '', pid: str = '', tid: str = ''): query = await self.get_filter_query(uid_or_name, pid, tid) # TODO(iceboy): projection, pagination. rdocs = await record.get_all_multi( **query, get_hidden=self.has_priv(builtin.PRIV_VIEW_HIDDEN_RECORD)).sort([ ('_id', -1) ]).limit(50).to_list() # TODO(iceboy): projection. udict, pdict = await asyncio.gather( user.get_dict(rdoc['uid'] for rdoc in rdocs), problem.get_dict_multi_domain( (rdoc['domain_id'], rdoc['pid']) for rdoc in rdocs)) # statistics statistics = None if self.has_priv(builtin.PRIV_VIEW_JUDGE_STATISTICS): ts = calendar.timegm(datetime.datetime.utcnow().utctimetuple()) day_count, week_count, month_count, year_count, rcount = await asyncio.gather( record.get_count( objectid.ObjectId( struct.pack('>i', ts - 24 * 3600) + struct.pack('b', -1) * 8)), record.get_count( objectid.ObjectId( struct.pack('>i', ts - 7 * 24 * 3600) + struct.pack('b', -1) * 8)), record.get_count( objectid.ObjectId( struct.pack('>i', ts - 30 * 24 * 3600) + struct.pack('b', -1) * 8)), record.get_count( objectid.ObjectId( struct.pack('>i', ts - int(365.2425 * 24 * 3600)) + struct.pack('b', -1) * 8)), record.get_count()) statistics = { 'day': day_count, 'week': week_count, 'month': month_count, 'year': year_count, 'total': rcount } self.render('record_main.html', rdocs=rdocs, udict=udict, pdict=pdict, statistics=statistics, filter_uid_or_name=uid_or_name, filter_pid=pid, filter_tid=tid, socket_url='/records-conn?' + urllib.parse.urlencode([('uid_or_name', uid_or_name), ('pid', pid), ('tid', tid)]))
async def get(self, *, page: int=1): # TODO(iceboy): continuation based pagination. nodes, (ddocs, dpcount, _) = await asyncio.gather( discussion.get_nodes(self.domain_id), # TODO(twd2): exclude problem/contest discussions? pagination.paginate(discussion.get_multi(self.domain_id), page, self.DISCUSSIONS_PER_PAGE)) udict, vndict = await asyncio.gather( user.get_dict(ddoc['owner_uid'] for ddoc in ddocs), discussion.get_dict_vnodes(self.domain_id, map(discussion.node_id, ddocs))) self.render('discussion_main_or_node.html', discussion_nodes=nodes, ddocs=ddocs, udict=udict, vndict=vndict, page=page, dpcount=dpcount)
async def get(self, *, page: int=1): # TODO(iceboy): continuation based pagination. nodes, (ddocs, dpcount, _) = await asyncio.gather( discussion.get_nodes(self.domain_id), # TODO(twd2): exclude problem/contest discussions? pagination.paginate(discussion.get_multi(self.domain_id), page, self.DISCUSSIONS_PER_PAGE)) udict, dudict, vndict = await asyncio.gather( user.get_dict(ddoc['owner_uid'] for ddoc in ddocs), domain.get_dict_user_by_uid(domain_id=self.domain_id, uids=(ddoc['owner_uid'] for ddoc in ddocs)), discussion.get_dict_vnodes(self.domain_id, map(discussion.node_id, ddocs))) self.render('discussion_main_or_node.html', discussion_nodes=nodes, ddocs=ddocs, udict=udict, dudict=dudict, vndict=vndict, page=page, dpcount=dpcount)
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
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)
async def get(self): (tdocs, tsdict), (htdocs, htsdict),\ (trdocs, trsdict), (ddocs, vndict) = await asyncio.gather( self.prepare_contest(), self.prepare_homework(), self.prepare_training(), self.prepare_discussion()) udict, dudict = await asyncio.gather( user.get_dict(ddoc['owner_uid'] for ddoc in ddocs), domain.get_dict_user_by_uid(self.domain_id, (ddoc['owner_uid'] for ddoc in ddocs))) self.render('domain_main.html', discussion_nodes=await discussion.get_nodes(self.domain_id), tdocs=tdocs, tsdict=tsdict, htdocs=htdocs, htsdict=htsdict, trdocs=trdocs, trsdict=trsdict, training=training_handler.TrainingMixin(), ddocs=ddocs, vndict=vndict, udict=udict, dudict=dudict, datetime_stamp=self.datetime_stamp)
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
async def get(self): # TODO(iceboy): projection, pagination. rdocs = await record.get_all_multi( get_hidden=self.has_priv(builtin.PRIV_VIEW_HIDDEN_RECORD)).sort([ ('_id', -1) ]).to_list(50) # TODO(iceboy): projection. udict, pdict = await asyncio.gather( user.get_dict(rdoc['uid'] for rdoc in rdocs), problem.get_dict_multi_domain( (rdoc['domain_id'], rdoc['pid']) for rdoc in rdocs)) # statistics statistics = None if self.has_priv(builtin.PRIV_VIEW_JUDGE_STATISTICS): ts = calendar.timegm(datetime.datetime.utcnow().utctimetuple()) day_count, week_count, month_count, year_count, rcount = await asyncio.gather( record.get_count( objectid.ObjectId( struct.pack('>i', ts - 24 * 3600) + struct.pack('b', -1) * 8)), record.get_count( objectid.ObjectId( struct.pack('>i', ts - 7 * 24 * 3600) + struct.pack('b', -1) * 8)), record.get_count( objectid.ObjectId( struct.pack('>i', ts - 30 * 24 * 3600) + struct.pack('b', -1) * 8)), record.get_count( objectid.ObjectId( struct.pack('>i', ts - int(365.2425 * 24 * 3600)) + struct.pack('b', -1) * 8)), record.get_count()) statistics = { 'day': day_count, 'week': week_count, 'month': month_count, 'year': year_count, 'total': rcount } self.render('record_main.html', rdocs=rdocs, udict=udict, pdict=pdict, statistics=statistics)
async def get(self, *, start: str='', uid_or_name: str='', pid: str='', tid: str='', nopretest: str=None): if not self.has_perm(builtin.PERM_REJUDGE): start = '' if start: start = objectid.ObjectId(start) else: start = None ex_pretest = False if nopretest: if nopretest == 'on': ex_pretest = True query = await self.get_filter_query(uid_or_name, pid, tid, nopretest) # TODO(iceboy): projection, pagination. rdocs = await record.get_all_multi(**query, end_id=start, get_hidden=True).sort([('_id', -1)]).limit(50).to_list() # TODO(iceboy): projection. udict, pdict = await asyncio.gather( user.get_dict(rdoc['uid'] for rdoc in rdocs), problem.get_dict_multi_domain((rdoc['domain_id'], rdoc['pid']) for rdoc in rdocs)) # statistics statistics = None if self.has_priv(builtin.PRIV_VIEW_JUDGE_STATISTICS): ts = calendar.timegm(datetime.datetime.utcnow().utctimetuple()) day_count, week_count, month_count, year_count, rcount = await asyncio.gather( record.get_count(objectid.ObjectId( struct.pack('>i', ts - 24 * 3600) + struct.pack('b', -1) * 8)), record.get_count(objectid.ObjectId( struct.pack('>i', ts - 7 * 24 * 3600) + struct.pack('b', -1) * 8)), record.get_count(objectid.ObjectId( struct.pack('>i', ts - 30 * 24 * 3600) + struct.pack('b', -1) * 8)), record.get_count(objectid.ObjectId( struct.pack('>i', ts - int(365.2425 * 24 * 3600)) + struct.pack('b', -1) * 8)), record.get_count()) statistics = {'day': day_count, 'week': week_count, 'month': month_count, 'year': year_count, 'total': rcount} url_prefix = '/d/{}'.format(urllib.parse.quote(self.domain_id)) query_string = urllib.parse.urlencode( [('uid_or_name', uid_or_name), ('pid', pid), ('tid', tid), ('nopretest', nopretest)]) #_logger.error(self.has_perm(builtin.PERM_REJUDGE)) self.render('record_main.html', rdocs=rdocs, udict=udict, pdict=pdict, statistics=statistics, filter_uid_or_name=uid_or_name, filter_pid=pid, filter_tid=tid, filter_nopretest=ex_pretest, socket_url=url_prefix + '/records-conn?' + query_string, # FIXME(twd2): magic query_string=query_string)
async def get(self, *, start: str='', uid_or_name: str='', pid: str='', tid: str=''): if not self.has_priv(builtin.PRIV_VIEW_JUDGE_STATISTICS): start = '' if start: try: start = objectid.ObjectId(start) except Exception: raise error.InvalidArgumentError('start') else: start = None query = await self.get_filter_query(uid_or_name, pid, tid) # TODO(iceboy): projection, pagination. rdocs = await record.get_all_multi(**query, end_id=start, get_hidden=self.has_priv(builtin.PRIV_VIEW_HIDDEN_RECORD)).sort([('_id', -1)]).limit(50).to_list() # TODO(iceboy): projection. udict, dudict, pdict = await asyncio.gather( user.get_dict(rdoc['uid'] for rdoc in rdocs), domain.get_dict_user_by_uid(domain_id=self.domain_id, uids=(rdoc['uid'] for rdoc in rdocs)), problem.get_dict_multi_domain((rdoc['domain_id'], rdoc['pid']) for rdoc in rdocs)) # statistics statistics = None if self.has_priv(builtin.PRIV_VIEW_JUDGE_STATISTICS): ts = calendar.timegm(datetime.datetime.utcnow().utctimetuple()) day_count, week_count, month_count, year_count, rcount = await asyncio.gather( record.get_count(objectid.ObjectId( struct.pack('>i', ts - 24 * 3600) + struct.pack('b', -1) * 8)), record.get_count(objectid.ObjectId( struct.pack('>i', ts - 7 * 24 * 3600) + struct.pack('b', -1) * 8)), record.get_count(objectid.ObjectId( struct.pack('>i', ts - 30 * 24 * 3600) + struct.pack('b', -1) * 8)), record.get_count(objectid.ObjectId( struct.pack('>i', ts - int(365.2425 * 24 * 3600)) + struct.pack('b', -1) * 8)), record.get_count()) statistics = {'day': day_count, 'week': week_count, 'month': month_count, 'year': year_count, 'total': rcount} url_prefix = '/d/{}'.format(urllib.parse.quote(self.domain_id)) query_string = urllib.parse.urlencode( [('uid_or_name', uid_or_name), ('pid', pid), ('tid', tid)]) self.render( 'record_main.html', rdocs=rdocs, udict=udict, dudict=dudict, pdict=pdict, statistics=statistics, filter_uid_or_name=uid_or_name, filter_pid=pid, filter_tid=tid, socket_url=url_prefix + '/records-conn?' + query_string, # FIXME(twd2): magic query_string=query_string)
async def get(self, *, doc_type: int = None, doc_id: str, page: int = 1): if doc_type is None: node_or_dtuple = doc_id else: node_or_dtuple = (doc_type, document.convert_doc_id(doc_id)) nodes, vnode = await discussion.get_nodes_and_vnode( self.domain_id, node_or_dtuple) if not vnode: raise error.DiscussionNodeNotFoundError(self.domain_id, node_or_dtuple) if vnode['doc_type'] == document.TYPE_PROBLEM and vnode.get( 'hidden', False): self.check_perm(builtin.PERM_VIEW_PROBLEM_HIDDEN) # TODO(twd2): do more visibility check eg. contest # TODO(iceboy): continuation based pagination. ddocs, dpcount, _ = await pagination.paginate( discussion.get_multi(self.domain_id, parent_doc_type=vnode['doc_type'], parent_doc_id=vnode['doc_id']), page, self.DISCUSSIONS_PER_PAGE) uids = set(ddoc['owner_uid'] for ddoc in ddocs) if 'owner_uid' in vnode: uids.add(vnode['owner_uid']) udict, dudict = await asyncio.gather( user.get_dict(uids), domain.get_dict_user_by_uid(self.domain_id, uids)) vndict = {node_or_dtuple: vnode} vncontext = {} # TODO(twd2): eg. psdoc, tsdoc, ... path_components = self.build_path( (self.translate('discussion_main'), self.reverse_url('discussion_main')), (vnode['title'], None)) self.render('discussion_main_or_node.html', discussion_nodes=nodes, vnode=vnode, ddocs=ddocs, udict=udict, dudict=dudict, vndict=vndict, page=page, dpcount=dpcount, **vncontext, path_components=path_components)
async def get(self): (tdocs, tsdict), (trdocs, trsdict), (ddocs, vndict) = await asyncio.gather( self.prepare_contest(), self.prepare_training(), self.prepare_discussion()) udict, dudict = await asyncio.gather( user.get_dict(ddoc['owner_uid'] for ddoc in ddocs), domain.get_dict_user_by_uid(self.domain_id, (ddoc['owner_uid'] for ddoc in ddocs))) self.render('domain_main.html', discussion_nodes=await discussion.get_nodes(self.domain_id), tdocs=tdocs, tsdict=tsdict, trdocs=trdocs, trsdict=trsdict, ddocs=ddocs, vndict=vndict, udict=udict, dudict=dudict, datetime_stamp=self.datetime_stamp)
async def get(self, *, did: document.convert_doc_id, page: int = 1): ddoc = await discussion.inc_views(self.domain_id, did) if self.has_priv(builtin.PRIV_USER_PROFILE): dsdoc = await discussion.get_status(self.domain_id, ddoc['doc_id'], self.user['_id']) else: dsdoc = None vnode, (drdocs, pcount, drcount) = await asyncio.gather( discussion.get_vnode(self.domain_id, discussion.node_id(ddoc)), pagination.paginate( discussion.get_multi_reply(self.domain_id, ddoc['doc_id']), page, self.REPLIES_PER_PAGE)) uids = {ddoc['owner_uid']} uids.update(drdoc['owner_uid'] for drdoc in drdocs) for drdoc in drdocs: if 'reply' in drdoc: uids.update(drrdoc['owner_uid'] for drrdoc in drdoc['reply']) udict, dudict = await asyncio.gather( user.get_dict(uids), domain.get_dict_user_by_uid(self.domain_id, uids)) path_components = self.build_path( (self.translate('discussion_main'), self.reverse_url('discussion_main')), (vnode['title'], node_url(self, 'discussion_node', discussion.node_id(ddoc))), (ddoc['title'], None)) self.render('discussion_detail.html', page_title=ddoc['title'], path_components=path_components, ddoc=ddoc, dsdoc=dsdoc, drdocs=drdocs, page=page, pcount=pcount, drcount=drcount, vnode=vnode, udict=udict, dudict=dudict)
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))
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
async def get(self, *, uid_or_name: str = '', pid: str = '', tid: str = ''): query = {} if uid_or_name: try: query['uid'] = int(uid_or_name) except ValueError: udoc = await user.get_by_uname(uid_or_name) if not udoc: raise error.UserNotFoundError(uid_or_name) from None query['uid'] = udoc['_id'] if pid: pid = document.convert_doc_id(pid) query['domain_id'] = self.domain_id query['pid'] = pid if tid: tid = document.convert_doc_id(tid) query['domain_id'] = self.domain_id query['tid'] = tid # TODO(iceboy): projection, pagination. rdocs = await record.get_all_multi( **query, get_hidden=self.has_priv(builtin.PRIV_VIEW_HIDDEN_RECORD)).sort([ ('_id', -1) ]).limit(50).to_list(None) # TODO(iceboy): projection. udict, pdict = await asyncio.gather( user.get_dict(rdoc['uid'] for rdoc in rdocs), problem.get_dict_multi_domain( (rdoc['domain_id'], rdoc['pid']) for rdoc in rdocs)) # statistics statistics = None if self.has_priv(builtin.PRIV_VIEW_JUDGE_STATISTICS): ts = calendar.timegm(datetime.datetime.utcnow().utctimetuple()) day_count, week_count, month_count, year_count, rcount = await asyncio.gather( record.get_count( objectid.ObjectId( struct.pack('>i', ts - 24 * 3600) + struct.pack('b', -1) * 8)), record.get_count( objectid.ObjectId( struct.pack('>i', ts - 7 * 24 * 3600) + struct.pack('b', -1) * 8)), record.get_count( objectid.ObjectId( struct.pack('>i', ts - 30 * 24 * 3600) + struct.pack('b', -1) * 8)), record.get_count( objectid.ObjectId( struct.pack('>i', ts - int(365.2425 * 24 * 3600)) + struct.pack('b', -1) * 8)), record.get_count()) statistics = { 'day': day_count, 'week': week_count, 'month': month_count, 'year': year_count, 'total': rcount } self.render('record_main.html', rdocs=rdocs, udict=udict, pdict=pdict, statistics=statistics, filter_uid_or_name=uid_or_name, filter_pid=pid, filter_tid=tid)