-
Notifications
You must be signed in to change notification settings - Fork 9
/
medals.py
67 lines (54 loc) · 1.76 KB
/
medals.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
64
65
66
67
from commons import *
from api import *
@stale_cache(ttr=15, ttl=1800)
def get_medals():
medals = QueryString('''
let doc = document('counters/medals')
let doc_medals = doc.medals
let pgpmedalists = (for i in users
filter i.pgp_login==true
sort i.t_c asc
return i)
let high_ts = (for i in users filter i.trust_score>(1600/1000000)
sort i.trust_score desc
return i)
let custom_medals_merged = [
{name:'非对称奖章', brief:"成功使用PGP签名登录2047的用户", listusers:pgpmedalists},
{name:'SAT满分', brief:"信用分大于1600的用户", listusers:high_ts},
]
let doc_medals_merged = (
for medal in doc_medals
let listusers = (
for name in medal.list
let u = (for i in users filter i.name==name return i)[0]
sort u.t_c asc
return u
)
return merge(medal, {listusers})
)
let combined_medals = append(doc_medals_merged, custom_medals_merged)
for medal in combined_medals
return medal
''', silent=True)
medals = aql(medals)
for medald in medals:
medald['uids'] = []
for user in medald['listusers']:
medald['uids'].append(user['uid'])
return medals
@stale_cache(ttr=3, ttl=1800)
def get_user_medals(uid):
medals = get_medals()
u = get_user_by_id(uid)
res = []
uname = key(u, 'name')
for medal in medals:
if key(medal, 'list'):
for name in medal['list']:
if name==uname:
res.append(medal['name'])
elif key(medal, 'listusers'):
for name in medal['listusers'].map(lambda k:k['name']):
if name==uname:
res.append(medal['name'])
return res