-
Notifications
You must be signed in to change notification settings - Fork 0
/
rank.py
63 lines (61 loc) · 2.1 KB
/
rank.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import os
import json
import msgpack
import tornado.web
import psycopg2
from req import Service
from req import RequestHandler
from req import reqenv
from user import UserConst
from user import UserService
class RankService:
def __init__(self,db,rs):
self.db = db
self.rs = rs
RankService.inst = self
class RankHandler(RequestHandler):
@reqenv
def get(self,pro_id):
pro_id = int(pro_id)
cur = yield self.db.cursor()
# show best socre in rank
yield cur.execute(('SELECT *'
'FROM ('
'SELECT DISTINCT ON ("challenge"."acct_id")'
'"challenge"."chal_id",'
'"challenge"."acct_id",'
'"challenge"."timestamp",'
'"account"."name" AS "acct_name",'
'"challenge_state"."runtime",'
'"challenge_state"."memory" '
'FROM "challenge" '
'INNER JOIN "account" '
'ON "challenge"."acct_id"="account"."acct_id" '
'LEFT JOIN "challenge_state" '
'ON "challenge"."chal_id"="challenge_state"."chal_id" '
'WHERE "account"."acct_type">=%s AND "challenge"."pro_id"=%s '
'AND "challenge_state"."state"=1 '
'ORDER BY "challenge"."acct_id" ASC, '
'"challenge_state"."runtime" ASC, "challenge_state"."memory" ASC,'
'"challenge"."timestamp" ASC, "challenge"."acct_id" ASC'
') temp '
'ORDER BY "runtime" ASC, "memory" ASC,'
'"timestamp" ASC, "acct_id" ASC;'),
(self.acct['acct_type'],pro_id,))
chal_list = list()
for chal_id,acct_id,timestamp,acct_name,runtime,memory in cur:
runtime = int(runtime)
memory = int(memory)
chal_list.append({
'chal_id':chal_id,
'acct_id':acct_id,
'acct_name':acct_name,
'runtime':runtime,
'memory':memory,
'timestamp':timestamp,
})
self.render('rank',pro_id = pro_id,chal_list = chal_list)
return
@reqenv
def post(self):
return