-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils.py
33 lines (29 loc) · 872 Bytes
/
utils.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
from typing import Any, Iterable
def rank2num(rankStr: str) -> int:
ranks = [
"Iron",
"Bronze",
"Silver",
"Gold",
"Platinum",
"Diamond",
"Ascendant",
"Immortal",
"Radiant",
]
if rankStr is None or rankStr in ["Unranked", "Unrated"]:
return 0
rank, level = rankStr.split(" ")
return ranks.index(rank) * 10 + int(level)
def get_rank_order(
val_users: dict[str, Any], rank_key: str, limit: int
) -> tuple[Iterable[str], Iterable[str]]:
keys = list(val_users.keys())
keys.sort(
key=lambda x: rank2num(val_users[x].__getattribute__(rank_key)), reverse=True
)
if limit > 0:
keys = keys[:limit]
return map(lambda x: val_users[x].fullname, keys), map(
lambda x: val_users[x].__getattribute__(rank_key) or "Unranked", keys
)