-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_rank.py
56 lines (54 loc) · 1.84 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
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 TotalRankService:
def __init__(self,db,rs):
self.db = db
self.rs = rs
RankService.inst = self
class TotalRankHandler(RequestHandler):
@reqenv
def get(self,pro_id):
pro_id = int(pro_id)
cur = yield self.db.cursor()
yield cur.execute(('SELECT '
'"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_state"."runtime" ASC,"challenge_state"."memory" ASC,'
'"challenge"."timestamp" ASC,"account"."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