山东大学-VirtualJudge-总结7

在过去的几天时间里面,我主要集中精力实现Contest 的的Rank以及Status功能

Rank实现代码####

###前端

###后台 def contest_rank(req, cid): if req.is_ajax(): contest = Contest.objects.get(id = cid) if contest.private: if req.user.is_superuser==False and req.user.info not in contest.accounts.all() : return JsonResponse("{}") rank_cache = contest.rank # print("rank_cache:") # print(rank_cache) status_list = Status.objects.filter(cid = cid).filter(runid__gt = contest.last_submit_id).order_by("time") # print("status_list") # print(status_list) rank_dict = json.loads(rank_cache) # print("rank_dict") # print(rank_dict) statsinfo = {} pos = 0 problem_list = contest.get_problem_list() length = len(problem_list) if contest.last_submit_id==0: rank_dict["statsinfo"] = [{} for i in range(length)] for item in problem_list: rank_dict["statsinfo"][pos] = {"probid" : chr(pos + 65) ,"acNum" : 0, "tryNum" : 0} statsinfo[item[2].title] = {"pos" : pos} pos += 1 else: for item in problem_list: statsinfo[item[2].title] = {"pos" : pos} pos += 1 for item in status_list: if item.user.is_staff : continue name = item.user.username contest.last_submit_id = max(contest.last_submit_id, item.runid) if name not in rank_dict.keys(): rank_dict[name] = {"name" : name, "solved":0, "penalty":0, "probs" : [{"failNum" : 0, "acNum" : 0, "acTime" : 0} for i in range(length)]} pos = statsinfo[item.pro.title]["pos"] if item.result == 3: #Waiting break if item.result == 0: #Accepted rank_dict["statsinfo"][pos]["acNum"] += 1 rank_dict["statsinfo"][pos]["tryNum"] += 1 if rank_dict[name]["probs"][pos]["acNum"] == 0: if item.result == 0: rank_dict[name]["probs"][pos]["acNum"] += 1 rank_dict[name]["probs"][pos]["acTime"] = dateToInt(item.timec - contest.start_time, 1) rank_dict[name]["penalty"] += 20 * rank_dict[name]["probs"][pos]["failNum"] + dateToInt(item.timec - contest.start_time, 0) rank_dict[name]["solved"] += 1 else: rank_dict[name]["probs"][pos]["failNum"] += 1 contest.rank = json.dumps(rank_dict) # print("contest.rank") # print(contest.rank) contest.save() return JsonResponse(rank_dict)

Status实现代码####

###前端

{% for item in status_list %} {% ifequal item.pro.isCCF True %} {% else %} {% ifequal item.result "Compilation Error"%} {% else %} {% endifequal %} {% endifequal %} {% ifequal item.user.id user.id %} {% else %} {% ifequal user.is_staff True %} {% else %} {% endifequal %} {% endifequal %} {% endfor %}
RunID Problem Status Language User SubmitTime
{{ item.runid }} {{ item.pro.title }}{{ item.score }}{{ item.result }}{{ item.result }}{{ item.result }}{{ item.result }}{{ item.lang }}{{ item.user.username }} {{ item.time | date:"Y-m-d H:i:s" }}
    {% for id in page %}
  • {{ id }}
  • {% endfor %}
###后台 def contest_status(req, cid):#has understood if req.is_ajax(): contest = Contest.objects.get(id=cid) t = loader.get_template('contest/contest_status.html') status_list = Status.objects.filter(cid=cid).order_by('-time')#need change if contest.private: if req.user.is_superuser==False and req.user.info not in contest.accounts.all() : status_list = [] pg = req.GET.get('pg') if not pg: pg = 1 pg = int(pg) max_cnt = status_list.count() // 20 + 1 start = max(pg - PAGE_NUMBER_EVERY_PAGE, 1) end = min(pg + PAGE_NUMBER_EVERY_PAGE, max_cnt) lst = status_list[(pg - 1) * LIST_NUMBER_EVERY_PAGE:pg * LIST_NUMBER_EVERY_PAGE] # content_html = t.render(Context({'status_list': lst, 'page': range(start, end + 1), 'contest_id': cid, 'user': req.user})) # return HttpResponse(content_html) return render(req,'contest/contest_status.html',{'status_list': lst, 'page': range(start, end + 1), 'contest_id': cid, 'user': req.user}) else: raise Http404

功能效果截图####

山东大学-VirtualJudge-总结7_第1张图片
contest-status
山东大学-VirtualJudge-总结7_第2张图片
contest-rank

你可能感兴趣的:(山东大学-VirtualJudge-总结7)