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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
|
import time
from datetime import date, timedelta
from aqt import mw
from copy import deepcopy
from aqt.utils import shortcut, showInfo, tr
from anki import version
anki_version = int(version.replace('.', ''))
if anki_version > 2119:
from aqt.deckbrowser import DeckBrowserBottomBar
from aqt.overview import OverviewBottomBar
from aqt.deckbrowser import DeckBrowser
from aqt.overview import Overview
from . import styles
config = mw.addonManager.getConfig(__name__)
studyNow_label = config['Button Label_ Study Now']
more_overviewStats = config[' More Overview Stats']
bottombarButtons_style = config[' Review_ Bottombar Buttons Style']
style_mainScreenButtons = config[' Style Main Screen Buttons']
bottombar_neon1 = styles.bottombar_neon1
bottombar_neon2 = styles.bottombar_neon2
bottombar_fill1 = styles.bottombar_fill1
bottombar_fill2 = styles.bottombar_fill2
#// Chosing stylinhg for review other buttons in reviewer bottombar based on chosen style
if bottombarButtons_style == 0:
bottomHTML_style = "<style></style>"
elif bottombarButtons_style == 1:
bottomHTML_style = bottombar_neon1
elif bottombarButtons_style == 2:
bottomHTML_style = bottombar_neon2
elif bottombarButtons_style == 3:
bottomHTML_style = bottombar_fill1
elif bottombarButtons_style == 4:
bottomHTML_style = bottombar_fill2
#// Main Screen Bottombar Buttons
def _drawButtons(self):
buf = "{}".format(bottomHTML_style)
if style_mainScreenButtons:
#// style='height: px' -> to prevent changing main screen buttons heights
# based on height defined in #main {}
mainScreen_style = """id=main style='height: px' """
else:
mainScreen_style = ""
drawLinks = deepcopy(self.drawLinks)
for b in drawLinks:
b.insert(0, "{}".format(mainScreen_style))
if b[0]:
b[0] = ("Shortcut key: %s") % shortcut(b[0])
buf += """
<button %s title='%s' onclick='pycmd(\"%s\");'>%s</button>""" % (tuple(b))
if anki_version > 2121:
self.bottom.draw(
buf=buf,
link_handler=self._linkHandler,
web_context=DeckBrowserBottomBar(self),
)
else:
self.bottom.draw(buf)
self.bottom.web.onBridgeCmd = self._linkHandler
#// Deck Overview Bottombar Buttons
def _renderBottom(self):
links = [
["O", "opts", tr.actions_options()],
]
if self.mw.col.decks.current()["dyn"]:
links.append(["R", "refresh", tr.actions_rebuild()])
links.append(["E", "empty", tr.studying_empty()])
else:
links.append(["C", "studymore", tr.actions_custom_study()])
# links.append(["F", "cram", ("Filter/Cram")])
if self.mw.col.sched.haveBuried():
links.append(["U", "unbury", tr.studying_unbury()])
links.append(["", "description", tr.scheduling_description()])
buf = "{}".format(bottomHTML_style)
if style_mainScreenButtons:
#// style='height: px' -> to prevent changing main screen buttons heights
# based on height defined in #main {}
mainScreen_style = """id=main style='height: px' """
else:
mainScreen_style = ""
for b in links:
b.insert(0, "{}".format(mainScreen_style))
if b[0]:
b[0] = ("Shortcut key: %s") % shortcut(b[0])
buf += """
<button %s title="%s" onclick='pycmd("%s")'>%s</button>""" % tuple(b)
if anki_version > 2121:
self.bottom.draw(
buf=buf,
link_handler=self._linkHandler,
web_context=OverviewBottomBar(self)
)
else:
self.bottom.draw(buf)
self.bottom.web.onBridgeCmd = self._linkHandler
#// Deck Overview Study Now Button | code from more overview stats to add more overview stats, OBVIOUSLY
if more_overviewStats == 1:
def _table(self):
"""Returns html table with more statistics than before."""
sched = self.mw.col.sched
deck = self.mw.col.decks.current()
dconf = self.mw.col.decks.confForDid(deck.get('id'))
but = self.mw.button
# Get default counts
# 0 = new, 1 = learn, 2 = review
counts = list(sched.counts())
finished = not sum(counts)
counts = _limit(counts)
totals = [
#new
sched.col.db.scalar("""
select count() from (select id from cards where did = %s
and queue = 0)""" % deck.get('id')),
# learn
sched.col.db.scalar("""
select count() from (select id from cards where did = %s
and queue in (1,3))""" % deck.get('id')),
# review
sched.col.db.scalar("""
select count() from (select id from cards where did = %s
and queue = 2)""" % deck.get('id')),
# suspended
sched.col.db.scalar("""
select count() from (select id from cards where did = %s
and queue = -1)""" % deck.get('id')),
# buried
sched.col.db.scalar("""
select count() from (select id from cards where did = %s
and queue = -2)""" % deck.get('id')),
]
if (dconf.get('new')):
dueTomorrow = _limit([
# new
min(dconf.get('new').get('perDay'), totals[0]),
# review
sched.col.db.scalar("""
select count() from cards where did = %s and queue = 3
and due = ?""" % deck.get('id'), sched.today + 1),
sched.col.db.scalar("""
select count() from cards where did = %s and queue = 2
and due = ?""" % deck.get('id'), sched.today + 1)
])
html = ''
# Style if less than 2.1.20
if (int(version.replace('.', '')) < 2120):
html += '''
<style>
.new-count {color: #00a}
.learn-count {color: #C35617}
.review-count {color: #0a0}
</style>'''
# No need to show due if we have finished collection today
if finished:
mssg = sched.finishedMsg()
html += '''
<div style="white-space: pre-wrap;">%s</div>
<table cellspacing=5>''' % mssg
else:
html +='''%s
<table cellpadding=5>
<tr><td align=center valign=top nowrap="nowrap">
<table cellspacing=5>
<tr><td nowrap="nowrap">%s:</td><td align=right>
<span title="new" class="new-count">%s</span>
<span title="learn" class="learn-count">%s</span>
<span title="review" class="review-count">%s</span>
</td></tr>''' % (bottomHTML_style, tr.browsing_sidebar_due_today(), counts[0], counts[1], counts[2])
if (dconf.get('new')):
html += '''
<tr><td nowrap="nowrap">%s:</td><td align=right>
<span title="new" class="new-count">%s</span>
<span title="learn" class="learn-count">%s</span>
<span title="review" class="review-count">%s</span>
</td></tr>''' % (tr.statistics_due_tomorrow(), dueTomorrow[0],
dueTomorrow[1], dueTomorrow[2])
html += '''
<tr>
<td nowrap="nowrap">%s:</td>
<td align=right nowrap="nowrap">
<span title="new" class="new-count">%s</span>
<span title="learn" class="learn-count">%s</span>
<span title="review" class="review-count">%s</span>
<span title="buried" style="color:#ffa500">%s</span>
<span title="suspended" style="color:#adb300">%s</span>
</td>
</tr>
</table>''' % (tr.statistics_counts_total_cards(), totals[0], totals[1], totals[2], totals[4],
totals[3])
if not finished:
if style_mainScreenButtons:
#// style='height: px' -> to prevent changing main screen buttons heights
# based on height defined in #main {}
mainScreen_style = """id=main style='height: px' """
else:
mainScreen_style = ""
if style_mainScreenButtons:
studyButton_id = "main"
else:
studyButton_id = "study"
html += '''</td>
<td align=center nowrap="nowrap">%s</td>
</tr></table>''' % (but("study", ("{}".format(studyNow_label)), id="{}".format(studyButton_id), extra="autofocus"))
return html
elif more_overviewStats == 2:
def _table(self):
stat_colors = {
"New" : "#00a",
"Learning" : "#a00",
"Review" : "#080",
"Percent" : "#888",
"Mature" : "#0051ff",
"Young" : "#0051ff",
"Learned" : "#080",
"Unseen" : "#a00",
"Suspended" : "#e7a100",
"Done on Date" : "#ddd",
"Days until done" : "#ddd",
"Total" : "#ddd",
}
date_format = "%d.%m.%Y"
correction_for_notes = 1
last_match_length = 0
current_deck_name = self.mw.col.decks.current()['name']
date_format = "%m/%d/%Y"
try:
learn_per_day = self.mw.col.decks.confForDid(self.mw.col.decks.current()['id'])['new']['perDay']
except:
learn_per_day = 0
total, mature, young, unseen, suspended, due = self.mw.col.db.first(
u'''
select
-- total
count(id),
-- mature
sum(case when queue = 2 and ivl >= 21
then 1 else 0 end),
-- young / learning
sum(case when queue in (1, 3) or (queue = 2 and ivl < 21)
then 1 else 0 end),
-- unseen
sum(case when queue = 0
then 1 else 0 end),
-- suspended
sum(case when queue < 0
then 1 else 0 end),
-- due
sum(case when queue = 1 and due <= ?
then 1 else 0 end)
from cards where did in {:s}
'''.format(self.mw.col.sched._deckLimit()), round(time.time())
)
if not total:
return u'<p> No Cards Found.</p>'
scheduled_counts = list(self.mw.col.sched.counts())
deck_is_finished = not sum(scheduled_counts)
cards = {}
cards['mature'] = mature // int(correction_for_notes)
cards['young'] = young // int(correction_for_notes)
cards['unseen'] = unseen // int(correction_for_notes)
cards['suspended'] = suspended // int(correction_for_notes)
cards['total'] = total // int(correction_for_notes)
cards['learned'] = cards['mature'] + cards['young']
cards['unlearned'] = cards['total'] - cards['learned']
cards['new'] = scheduled_counts[0]
cards['learning'] = scheduled_counts[1]
cards['review'] = scheduled_counts[2]
# cards['due'] = due + cards['review']
cards['total_without_suspended'] = cards['total'] - cards['suspended']
try:
daysUntilDone = math.ceil(cards['unseen'] / learn_per_day)
except:
daysUntilDone = 0
try:
cards['doneDate'] = (date.today()+timedelta(days=daysUntilDone)).strftime(date_format)
except:
showInfo("Unsupported date format. Defaulting to Day.Month.Year instead. Use one of the shorthands: \"us\", \"asia\" or \"eu\", or specify the date like \"\%d.\%m.\%Y\", \"\%m/\%d/\%Y\" etc.\n For more information check the table at: https://docs.python.org/2/library/datetime.html#strftime-and-strptime-behavior", type="warning", title="More Overview Stats 2.1 Warning")
print(date_format)
cards['doneDate'] = (date.today()+timedelta(days=daysUntilDone)).strftime("%d.%m.%Y")
cards['daysLeft'] = daysUntilDone
if(daysUntilDone == 1):
cards['daysLeft'] = '{} day'.format(daysUntilDone)
else:
cards['daysLeft'] = '{} days'.format(daysUntilDone)
cards_percent = {}
cards_percent['mature'] = cards['mature'] * 1.0 / cards['total']
cards_percent['young'] = cards['young'] * 1.0 / cards['total']
cards_percent['unseen'] = cards['unseen'] * 1.0 / cards['total']
cards_percent['suspended'] = cards['suspended'] * 1.0 / cards['total']
cards_percent['total'] = 1.0
cards_percent['learned'] = cards['learned'] * 1.0 / cards['total']
cards_percent['unlearned'] = cards['unlearned'] * 1.0 / cards['total']
cards_percent['new'] = cards['new'] * 1.0 / cards['total']
cards_percent['learning'] = cards['learning'] * 1.0 / cards['total']
cards_percent['review'] = cards['review'] * 1.0 / cards['total']
# cards_percent['due'] = cards['due'] * 1.0 / cards['total']
cards_percent_without_suspended = {}
if(cards['total_without_suspended'] != 0):
cards_percent_without_suspended['mature'] = cards['mature'] * 1.0 / cards['total_without_suspended']
cards_percent_without_suspended['young'] = cards['young'] * 1.0 / cards['total_without_suspended']
cards_percent_without_suspended['unseen'] = cards['unseen'] * 1.0 / cards['total_without_suspended']
cards_percent_without_suspended['suspended'] = cards['suspended'] * 1.0 / cards['total_without_suspended']
cards_percent_without_suspended['total'] = 1.0
cards_percent_without_suspended['learned'] = cards['learned'] * 1.0 / cards['total_without_suspended']
cards_percent_without_suspended['unlearned'] = cards['unlearned'] * 1.0 / cards['total_without_suspended']
cards_percent_without_suspended['new'] = cards['new'] * 1.0 / cards['total_without_suspended']
cards_percent_without_suspended['learning'] = cards['learning'] * 1.0 / cards['total_without_suspended']
cards_percent_without_suspended['review'] = cards['review'] * 1.0 / cards['total_without_suspended']
else:
cards_percent_without_suspended['mature'] = 0
cards_percent_without_suspended['young'] = 0
cards_percent_without_suspended['unseen'] = 0
cards_percent_without_suspended['suspended'] = 0
cards_percent_without_suspended['total'] = 1.0
cards_percent_without_suspended['learned'] = 0
cards_percent_without_suspended['unlearned'] = 0
cards_percent_without_suspended['new'] = 0
cards_percent_without_suspended['learning'] = 0
cards_percent_without_suspended['review'] = 0
labels = {}
labels['mature'] = tr.statistics_counts_mature_cards()
labels['young'] = tr.statistics_counts_young_cards()
labels['unseen'] = ('Unseen')
labels['suspended'] = tr.statistics_counts_suspended_cards()
labels['total'] = tr.statistics_counts_total_cards()
labels['learned'] = ('Learned')
labels['unlearned'] = ('Unlearned')
labels['new'] = tr.statistics_counts_new_cards()
labels['learning'] = tr.statistics_counts_learning_cards()
labels['review'] = ('Review')
# labels['due'] = ('Due')
labels['doneDate'] = ('Done in')
for key in labels:
labels[key] = u'{:s}:'.format(labels[key])
button = self.mw.button
output_table = u'''
<style type="text/css">
<!--
hr {
height: 1px;
border: none;
border-top: 1px solid #aaa;
}
td {
vertical-align: top;
}
td.row1 {
text-align: left;
}
td.row2 {
text-align: right;
padding-left: 1.2em;
padding-right: 1.2em;
}
td.row3 {
text-align: left;
padding-left: 1.2em;
padding-right: 1.2em;
}
td.row4 {
text-align: right;
}
td.new {
font-weight: bold;
color: ''' + stat_colors["New"] + ''';
}
td.learning {
font-weight: bold;
color: ''' + stat_colors["Learning"] + ''';
}
td.review {
font-weight: bold;
color: ''' + stat_colors["Review"] + ''';
}
td.percent {
font-weight: normal;
color: ''' + stat_colors["Percent"] + ''';
}
td.mature {
font-weight: normal;
color: ''' + stat_colors["Mature"] + ''';
}
td.young {
font-weight: normal;
color: ''' + stat_colors["Young"] + ''';
}
td.learned {
font-weight: normal;
color: ''' + stat_colors["Learned"] + ''';
}
td.unseen {
font-weight: normal;
color: ''' + stat_colors["Unseen"] + ''';
}
td.suspended {
font-weight: normal;
color: ''' + stat_colors["Suspended"] + ''';
}
td.doneDate {
font-weight: bold;
color: ''' + stat_colors["Done on Date"] + ''';
}
td.daysLeft {
font-weight: bold;
color: ''' + stat_colors["Days until done"] + ''';
}
td.total {
font-weight: bold;
color: ''' + stat_colors["Total"] + ''';
}
-->
</style>
<table cellspacing="2">
'''
if not deck_is_finished:
output_table += u'''
<tr>
<td class="row1">{label[new]:s}</td>
<td class="row2 new">{cards[new]:d}</td>
<td class="row3 percent">{percent[new]:.0%}</td>
<td class="row4 percent">{percent2[new]:.0%}</td>
</tr>
<tr>
<td class="row1">{label[learning]:s}</td>
<td class="row2 learning">{cards[learning]:d}</td>
<td class="row3 percent">{percent[learning]:.0%}</td>
<td class="row4 percent">{percent2[learning]:.0%}</td>
</tr>
<tr>
<td class="row1">{label[review]:s}</td>
<td class="row2 review">{cards[review]:d}</td>
<td class="row3 percent">{percent[review]:.0%}</td>
<td class="row4 percent">{percent2[review]:.0%}</td>
</tr>
<tr>
<td colspan="4"><hr /></td>
</tr>
'''.format(label=labels, cards=cards, percent=cards_percent, percent2=cards_percent_without_suspended)
output_table += u'''
<tr>
<td class="row1">{label[mature]:s}</td>
<td class="row2 mature">{cards[mature]:d}</td>
<td class="row3 percent">{percent[mature]:.0%}</td>
<td class="row4 percent">{percent2[mature]:.0%}</td>
</tr>
<tr>
<td class="row1">{label[young]:s}</td>
<td class="row2 young">{cards[young]:d}</td>
<td class="row3 percent">{percent[young]:.0%}</td>
<td class="row4 percent">{percent2[young]:.0%}</td>
</tr>
<tr>
<td colspan="4"><hr /></td>
</tr>
<tr>
<td class="row1">{label[learned]:s}</td>
<td class="row2 learned">{cards[learned]:d}</td>
<td class="row3 percent">{percent[learned]:.0%}</td>
<td class="row4 percent">{percent2[learned]:.0%}</td>
</tr>
<tr>
<td class="row1">{label[unseen]:s}</td>
<td class="row2 unseen">{cards[unseen]:d}</td>
<td class="row3 percent">{percent[unseen]:.0%}</td>
<td class="row4 percent">{percent2[unseen]:.0%}</td>
</tr>
<tr>
<td class="row1">{label[suspended]:s}</td>
<td class="row2 suspended">{cards[suspended]:d}</td>
<td class="row3 percent">{percent[suspended]:.0%}</td>
<td class="row4 percent">ignored</td>
</tr>
<tr>
<td colspan="4"><hr /></td>
</tr>
<tr>
<td class="row1">{label[total]:s}</td>
<td class="row2 total">{cards[total]:d}</td>
<td class="row3 percent">{percent[total]:.0%}</td>
<td class="row4 percent">{percent2[total]:.0%}</td>
</tr>
<td colspan="4"><hr /></td>
<tr>
<td class="row1">{label[doneDate]:s}</td>
<td class="row2 daysLeft">{cards[daysLeft]:s}</td>
<td class="row3">on:</td>
<td class="row4 doneDate">{cards[doneDate]:s}</td>
</tr>
'''.format(label=labels, cards=cards, percent=cards_percent, percent2=cards_percent_without_suspended)
output = ''
if deck_is_finished:
if (config == None or not 'options' in config) or (config['options'].get('Show table for finished decks', True)):
output += output_table
output += u'''
</table>
<hr style="margin: 1.5em 0; border-top: 1px dotted #888;" />
'''
output += u'''
<div style="white-space: pre-wrap;">{:s}</div>
'''.format(self.mw.col.sched.finishedMsg())
else:
if style_mainScreenButtons:
#// style='height: px' -> to prevent changing main screen buttons heights
# based on height defined in #main {}
mainScreen_style = """id=main style='height: px' """
else:
mainScreen_style = ""
if style_mainScreenButtons:
studyButton_id = "main"
else:
studyButton_id = "study"
output += output_table
output += bottomHTML_style
output += u'''
<tr>
<td colspan="4" style="text-align: center; padding-top: 0.6em;">{button:s}</td>
</tr>
</table>
'''.format(button=button('study', tr.studying_study_now(), id='{}'.format(studyButton_id), extra="autofocus"))
return output
else:
def _table(self):
counts = list(self.mw.col.sched.counts())
finished = not sum(counts)
if self.mw.col.sched_ver() == 1:
for n in range(len(counts)):
if counts[n] >= 1000:
counts[n] = "1000+"
but = self.mw.button
if finished:
return '<div style="white-space: pre-wrap;">%s</div>' % (
self.mw.col.sched.finishedMsg()
)
else:
if style_mainScreenButtons:
#// style='height: px' -> to prevent changing main screen buttons heights
# based on height defined in #main {}
mainScreen_style = """id=main style='height: px' """
else:
mainScreen_style = ""
if style_mainScreenButtons:
studyButton_id = "main"
else:
studyButton_id = "study"
return """%s
<table width=400 cellpadding=5>
<tr><td align=center valign=top>
<table cellspacing=5>
<tr><td>%s:</td><td><b><span class=new-count>%s</span></b></td></tr>
<tr><td>%s:</td><td><b><span class=learn-count>%s</span></b></td></tr>
<tr><td>%s:</td><td><b><span class=review-count>%s</span></b></td></tr>
</table>
</td><td align=center>
%s</td></tr></table>""" % (
bottomHTML_style,
tr.actions_new(),
counts[0],
tr.scheduling_learning(),
counts[1],
tr.studying_to_review(),
counts[2],
but("study", tr.studying_study_now(), id="{}".format(studyButton_id), extra="autofocus"),
)
def _limit(counts):
for i, count in enumerate(counts):
if count >= 1000:
counts[i] = "1000+"
return counts
Overview._renderBottom = _renderBottom
DeckBrowser._drawButtons = _drawButtons
Overview._table = _table
|