forked from cjdduarte/MDS_Time_Left
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mds_time_left.py
97 lines (85 loc) · 4.02 KB
/
mds_time_left.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# -*- coding: utf-8 -*-
#Copyright(C) | Carlos Duarte
#Based 1 on | Dmitry Mikheev code, in add-on "More decks overview stats"
#Based 2 on | calumkscode, in add-on https://github.com/calumks/anki-deck-stats
#License | GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
#Source in | https://github.com/cjdduarte/MDS_Time_Left
import anki
from anki.lang import _, ngettext
import aqt
from aqt import mw
from aqt.utils import tooltip
#-------------Configuration------------------
config = mw.addonManager.getConfig(__name__)
# The default steps for "New" Anki cards are 1min and 10min meaning that you see New cards actually a minimum of *TWO* times that day
# You can now configure how many times new cards will be counted.
# CountTimesNew = 1 (old version)
# Quantify '1' time the "new card" time | Example: Steps (10 1440)
# CountTimesNew = 2 (default)
# Quantify '2' times the "new card" time | Example: Steps (1 10)
# CountTimesNew = n
# Quantify 'n' times the "new card" time | Example: Steps (1 10 10 20 30...)
CountTimesNew = config['CountTimesNew']
#-------------Configuration------------------
def renderStats(self, _old):
# Get due and new cards
new = 0
lrn = 0
due = 0
for tree in self.mw.col.sched.deckDueTree():
new += tree[4]
lrn += tree[3]
due += tree[2]
#if CountTimesNew == 0: CountTimesNew = 2
total = (CountTimesNew*new) + lrn + due
totalDisplay = new + lrn + due
#total = new + lrn + due
# Get studdied cards
cards, thetime = self.mw.col.db.first(
"""select count(), sum(time)/1000 from revlog where id > ?""",
(self.mw.col.sched.dayCutoff - 86400) * 1000)
cards = cards or 0
thetime = thetime or 0
speed = cards * 60 / max(1, thetime)
minutes = int(total / max(1, speed))
NewColor = config['NewColor']
ReviewColor = config['ReviewColor']
LearnColor = config['LearnColor']
TotalDueColor = config['TotalDueColor']
TotalColor = config['TotalColor']
insert_style = "<style type=\"text/css\">" \
+ ".new-color { color:" + NewColor + ";}" \
+ ".review-color { color:" + ReviewColor + ";}" \
+ ".learn-color { color:" + LearnColor + ";}" \
+ ".totaldue-color { color:" + TotalDueColor + ";}" \
+ ".total-color { color:" + TotalColor + ";}" \
+ "</style>"
buf = insert_style \
+ "<div style='display:table;padding-top:1.5em;'>" \
+ "<div style='display:table-cell;'> " \
+ _old(self) + "<hr>" \
+ _("New Cards") \
+ ": <span class='new-color'> %(d)s</span>" % dict(d=new) \
+ " " + _("Learn") \
+ ": <span class='learn-color'>%(c)s</span>" % dict(c=lrn) \
+ " <span style='white-space:nowrap;'>" + _("To Review") \
+ ": <span class='review-color'>%(c)s</span>" % dict(c=due) \
+ "</span>" \
+ " <br><span style='white-space:nowrap;'>" + _("Due") \
+ ": <b class='totaldue-color'>%(c)s</b> " % dict(c=(lrn+due)) \
+ "</span> " \
+ " <span style='white-space:nowrap;'>" + _("Total") \
+ ": <b class='total-color'>%(c)s</b>" % dict(c=(totalDisplay)) \
+ "</span></div>" \
+ "<div style='display:table-cell;vertical-align:middle;" \
+ "padding-left:2em;'>" \
+ "<span style='white-space:nowrap;'>" + _("Average") \
+ ":<br> " + _("%.01f") % (speed) + " " + (_("Cards") + "/" + _("Minutes").replace("s", "")).lower() \
+ "</span><br><br>" \
+ str(ngettext("%s minute.", "%s minutes.", minutes) % (minutes)).replace(".", "") + " " + _("More").lower() \
+ "</div></div>"
return buf
#+ ":<br> " + _("%.01f cards/minute") % (speed) \
#+ _("More") + " " + ngettext("%s minute.", "%s minutes.", minutes) % (minutes) \
aqt.deckbrowser.DeckBrowser._renderStats = anki.hooks.wrap(
aqt.deckbrowser.DeckBrowser._renderStats, renderStats, 'around')