Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Change the value of the intervals in the table: Row ~40. Change the names of the displayed interval brackets: Row ~139
- import anki.stats
- todayStats_old = anki.stats.CollectionStats.todayStats
- # Types: 0 - new today; 1 - review; 2 - relearn; 3 - (cram?) [before the answer was pressed]
- # "Learning" corresponds to New|Relearn. "Review" corresponds to Young|Mature.
- # Ease: 1 - failed button; 2 - second; 3 - third; 4 - fourth (easy) [which button was pressed]
- # Intervals: -60 <1m -600 10m etc; otherwise days (>=21 is mature)
- def _line_now(self, i, a, b, bold=True):
- colon = _(":")
- if bold:
- i.append(("<tr><td align=right>%s%s</td><td><b>%s</b></td></tr>") % (a,colon,b))
- else:
- i.append(("<tr><td align=right>%s%s</td><td>%s</td></tr>") % (a,colon,b))
- def _line_every(self, i, c, d, e, f, g, bold=True):
- colon = _(":")
- if bold:
- i.append(("<tr><td align=right>%s%s</td><td><b>%s / %s (%s)</b></td><td><b>[%s]</b></td></tr>") % (c,colon,d,e,f,g))
- else:
- i.append(("<tr><td align=right>%s%s</td><td>%s / %s (%s)</b></td><td>[%s]</td></td></tr>") % (c,colon,d,e,f,g))
- def _line_empty(self, i):
- i.append("<tr><td><br></td></tr>")
- def _lineTbl_now(self, i):
- return "<table>" + "".join(i) + "</table>"
- def statList(self, lim, span):
- passed, failed, passed_young, failed_young, passed_mature, failed_mature, passed_span1, failed_span1, passed_span2, failed_span2, passed_span3, failed_span3, passed_span4, failed_span4, passed_end, failed_end, learned, relearned = self.col.db.first("""
- select
- sum(case when ease > 1 and type == 1 then 1 else 0 end), /* passed */
- sum(case when ease = 1 and type == 1 then 1 else 0 end), /* failed */
- sum(case when ease > 1 and type == 1 and lastivl < 21 then 1 else 0 end), /* passed_young */
- sum(case when ease = 1 and type == 1 and lastivl < 21 then 1 else 0 end), /* failed_young */
- sum(case when ease > 1 and type == 1 and lastivl >= 21 then 1 else 0 end), /* passed_mature */
- sum(case when ease = 1 and type == 1 and lastivl >= 21 then 1 else 0 end), /* failed_mature */
- sum(case when ease > 1 and type == 1 and lastivl BETWEEN 21 AND 39 then 1 else 0 end), /* passed_span1 */
- sum(case when ease = 1 and type == 1 and lastivl BETWEEN 21 AND 39 then 1 else 0 end), /* failed_span1 */
- sum(case when ease > 1 and type == 1 and lastivl BETWEEN 40 AND 69 then 1 else 0 end), /* passed_span2 */
- sum(case when ease = 1 and type == 1 and lastivl BETWEEN 40 AND 69 then 1 else 0 end), /* failed_span2 */
- sum(case when ease > 1 and type == 1 and lastivl BETWEEN 70 AND 99 then 1 else 0 end), /* passed_span3 */
- sum(case when ease = 1 and type == 1 and lastivl BETWEEN 70 AND 99 then 1 else 0 end), /* failed_span3 */
- sum(case when ease > 1 and type == 1 and lastivl BETWEEN 100 AND 179 then 1 else 0 end), /* passed_span4 */
- sum(case when ease = 1 and type == 1 and lastivl BETWEEN 100 AND 179 then 1 else 0 end), /* failed_span4 */
- sum(case when ease > 1 and type == 1 and lastivl >= 180 then 1 else 0 end), /* passed_end */
- sum(case when ease = 1 and type == 1 and lastivl >= 180 then 1 else 0 end), /* failed_end */
- sum(case when ivl > 0 and type == 0 then 1 else 0 end), /* learned */
- sum(case when ivl > 0 and type == 2 then 1 else 0 end) /* relearned */
- from revlog where id > ? """+lim, span)
- passed = passed or 0
- failed = failed or 0
- passed_young = passed_young or 0
- failed_young = failed_young or 0
- passed_mature = passed_mature or 0
- failed_mature = failed_mature or 0
- passed_span1 = passed_span1 or 0
- failed_span1 = failed_span1 or 0
- passed_span2 = passed_span2 or 0
- failed_span2 = failed_span2 or 0
- passed_span3 = passed_span3 or 0
- failed_span3 = failed_span3 or 0
- passed_span4 = passed_span4 or 0
- failed_span4 = failed_span4 or 0
- passed_end = passed_end or 0
- failed_end = failed_end or 0
- learned = learned or 0
- relearned = relearned or 0
- try:
- temp = "%0.1f%%" %(passed/float(passed+failed)*100)
- except ZeroDivisionError:
- temp = "N/A"
- try:
- temp_young = "%0.1f%%" %(passed_young/float(passed_young+failed_young)*100)
- except ZeroDivisionError:
- temp_young = "N/A"
- try:
- temp_mature = "%0.1f%%" %(passed_mature/float(passed_mature+failed_mature)*100)
- except ZeroDivisionError:
- temp_mature = "N/A"
- try:
- temp_span1 = "%0.1f%%" %(passed_span1/float(passed_span1+failed_span1)*100)
- except ZeroDivisionError:
- temp_span1 = "N/A"
- try:
- temp_span2 = "%0.1f%%" %(passed_span2/float(passed_span2+failed_span2)*100)
- except ZeroDivisionError:
- temp_span2 = "N/A"
- try:
- temp_span3 = "%0.1f%%" %(passed_span3/float(passed_span3+failed_span3)*100)
- except ZeroDivisionError:
- temp_span3 = "N/A"
- try:
- temp_span4 = "%0.1f%%" %(passed_span4/float(passed_span4+failed_span4)*100)
- except ZeroDivisionError:
- temp_span4 = "N/A"
- try:
- temp_end = "%0.1f%%" %(passed_end/float(passed_end+failed_end)*100)
- except ZeroDivisionError:
- temp_end = "N/A"
- try:
- total_reviews = (passed+failed)
- except ZeroDivisionError:
- total_reviews = "N/A"
- try:
- total_young = (passed_young+failed_young)
- except ZeroDivisionError:
- total_young = "N/A"
- try:
- total_mature = (passed_mature+failed_mature)
- except ZeroDivisionError:
- total_mature = "N/A"
- try:
- total_span1 = (passed_span1+failed_span1)
- except ZeroDivisionError:
- total_span1 = "N/A"
- try:
- total_span2 = (passed_span2+failed_span2)
- except ZeroDivisionError:
- total_span2 = "N/A"
- try:
- total_span3 = (passed_span3+failed_span3)
- except ZeroDivisionError:
- total_span3 = "N/A"
- try:
- total_span4 = (passed_span4+failed_span4)
- except ZeroDivisionError:
- total_span4 = "N/A"
- try:
- total_end = (passed_end+failed_end)
- except ZeroDivisionError:
- total_end = "N/A"
- i = []
- ### =========== LISTS: pass / fail; (total); [percent]; new cards; relearn ===========
- _line_every(self, i, "Overall", passed, failed, total_reviews, temp)
- _line_empty(self, i)
- _line_every(self, i, "Young", passed_young, failed_young, total_young, temp_young)
- # _line_empty(self, i)
- _line_every(self, i, "Mature", passed_mature, failed_mature, total_mature, temp_mature)
- _line_empty(self, i)
- _line_every(self, i, "21-39 Days", passed_span1, failed_span1, total_span1, temp_span1)
- _line_every(self, i, "40-69 Days", passed_span2, failed_span2, total_span2, temp_span2)
- _line_every(self, i, "70-99 Days", passed_span3, failed_span3, total_span3, temp_span3)
- _line_every(self, i, "100-179 Days", passed_span4, failed_span4, total_span4, temp_span4)
- _line_every(self, i, "180+ Days", passed_end, failed_end, total_end, temp_end)
- _line_empty(self, i)
- _line_now(self, i, "New Cards Learned", learned)
- _line_now(self, i, "Cards Relearned", relearned)
- return _lineTbl_now(self, i)
- def todayStats_new(self):
- lim = self._revlogLimit()
- if lim:
- lim = " and " + lim
- pastDay = statList(self, lim, (self.col.sched.dayCutoff-86400)*1000)
- pastWeek = statList(self, lim, (self.col.sched.dayCutoff-86400*7)*1000)
- if self.type == 0:
- period = 31; name = "Past month:"
- elif self.type == 1:
- period = 365; name = "Past year:"
- elif self.type == 2:
- period = float('inf'); name = "All time:"
- pastPeriod = statList(self, lim, (self.col.sched.dayCutoff-86400*period)*1000)
- return todayStats_old(self) + "<br><br><table style='text-align: center'><tr><td style='padding: 5px'>" \
- + "<span>Past day:</span>" + pastDay + "</td><td style='padding: 5px'>" \
- + "<span>Past week:</span>" + pastWeek + "</td><td style='padding: 5px'>" \
- + "<span>" + name + "</span>" + pastPeriod + "</td></tr></table>"
- anki.stats.CollectionStats.todayStats = todayStats_new
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement