-
Notifications
You must be signed in to change notification settings - Fork 1
/
__init__.py
78 lines (61 loc) · 1.65 KB
/
__init__.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
68
69
70
71
72
73
74
75
76
77
78
# -*- coding: utf-8 -*-
import importlib
import cfg
import time
from threading import Lock
import copy
cache = {}
alloweddays = [1, 7, 30, 90, 180, 365]
#List of selectors
#(<api calling points>, <rank selector module>)
selectors = [
(['maps'], 'maps'),
(['servers'], 'servers'),
(['spm'], 'spx.spm'),
(['dpm'], 'spx.dpm'),
(['fpm'], 'spx.fpm'),
(['spf'], 'spx.spf'),
(['games'], 'single.games'),
(['captures'], 'single.captures'),
(['bombings'], 'single.bombings'),
(['mvp'], 'single.mvp'),
(['weapon'], 'weapon'),
(['winners'], 'winners'),
(["modes"], 'modes'),
(["muts", "mutators"], 'mutators'),
(["selections"], 'selections'),
]
class Selector:
def __init__(self, db, days, opts):
self.db = db
self.days = days
self.data = {}
self.lock = Lock()
self.opts = opts
def get(self):
with self.lock:
return copy.deepcopy(self.data)
def importselector(s):
c = importlib.import_module("rankselectors." + s).Selector
c.name = s
return c
ns = {}
for s in selectors:
for an in s[0]:
ns[an] = importselector(s[1])
selectors = ns
def get(selector, db, days, opts=None):
index = str([selector, days, opts])
if index in cache:
return cache[index][1]
s = selectors[selector](db, days, opts or {})
cache[index] = [time.time(), s]
s.update()
return s
def tick(db):
for index in cache:
if time.time() - cache[index][0] > cfg.get('cache_ranks'):
with db:
cache[index][0] = time.time()
cache[index][1].db = db
cache[index][1].update()