-
Notifications
You must be signed in to change notification settings - Fork 0
/
counters.py
38 lines (30 loc) · 1.05 KB
/
counters.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
from aqt.utils import showInfo
import codecs
class Counters:
_COUNTERS = {}
def increment(key, value=1):
if not key in Counters._COUNTERS:
Counters._COUNTERS[key] = 0
Counters._COUNTERS[key] += value
def get(key):
if not key in Counters._COUNTERS:
return str(0)
else :
return str(Counters._COUNTERS[key])
def printAll():
str = " "
for key in sorted(Counters._COUNTERS):
str += key + ":" + Counters.get(key) + "\n"
return str
def resetCounters():
Counters._COUNTERS = {}
def dump():
file = codecs.open("D:/Japanese/jap_anki/internal/.counters.txt", 'wb', 'utf-8')
file.write(Counters.printAll())
file.close()
def show():
Counters.dump()
showInfo("counters:\r\n" + Counters.printAll())
def sanityCheck():
if (int(Counters.get("dupe_cleaned")) != (int(Counters.get("new")))):
showInfo("SUSPICIOUS BEHAVIOUR IN COUNTERS, new != clean. Do check." + Counters.printAll())