Advertisement
Guest User

True Autism

a guest
Jun 30th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.06 KB | None | 0 0
  1. # Change the value of the intervals in the table: Row ~40. Change the names of the displayed interval brackets: Row ~139
  2.  
  3. import anki.stats
  4.  
  5. todayStats_old = anki.stats.CollectionStats.todayStats
  6.  
  7. # Types: 0 - new today; 1 - review; 2 - relearn; 3 - (cram?) [before the answer was pressed]
  8. # "Learning" corresponds to New|Relearn. "Review" corresponds to Young|Mature.
  9. # Ease: 1 - failed button; 2 - second; 3 - third; 4 - fourth (easy) [which button was pressed]
  10. # Intervals: -60 <1m -600 10m etc; otherwise days (>=21 is mature)
  11. def _line_now(self, i, a, b, bold=True):
  12. colon = _(":")
  13. if bold:
  14. i.append(("<tr><td align=right>%s%s</td><td><b>%s</b></td></tr>") % (a,colon,b))
  15. else:
  16. i.append(("<tr><td align=right>%s%s</td><td>%s</td></tr>") % (a,colon,b))
  17.  
  18. def _line_every(self, i, c, d, e, f, g, bold=True):
  19. colon = _(":")
  20. if bold:
  21. 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))
  22. else:
  23. 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))
  24.  
  25. def _line_empty(self, i):
  26. i.append("<tr><td><br></td></tr>")
  27.  
  28. def _lineTbl_now(self, i):
  29. return "<table>" + "".join(i) + "</table>"
  30.  
  31. def statList(self, lim, span):
  32. 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("""
  33. select
  34. sum(case when ease > 1 and type == 1 then 1 else 0 end), /* passed */
  35. sum(case when ease = 1 and type == 1 then 1 else 0 end), /* failed */
  36. sum(case when ease > 1 and type == 1 and lastivl < 21 then 1 else 0 end), /* passed_young */
  37. sum(case when ease = 1 and type == 1 and lastivl < 21 then 1 else 0 end), /* failed_young */
  38. sum(case when ease > 1 and type == 1 and lastivl >= 21 then 1 else 0 end), /* passed_mature */
  39. sum(case when ease = 1 and type == 1 and lastivl >= 21 then 1 else 0 end), /* failed_mature */
  40. sum(case when ease > 1 and type == 1 and lastivl BETWEEN 21 AND 39 then 1 else 0 end), /* passed_span1 */
  41. sum(case when ease = 1 and type == 1 and lastivl BETWEEN 21 AND 39 then 1 else 0 end), /* failed_span1 */
  42. sum(case when ease > 1 and type == 1 and lastivl BETWEEN 40 AND 69 then 1 else 0 end), /* passed_span2 */
  43. sum(case when ease = 1 and type == 1 and lastivl BETWEEN 40 AND 69 then 1 else 0 end), /* failed_span2 */
  44. sum(case when ease > 1 and type == 1 and lastivl BETWEEN 70 AND 99 then 1 else 0 end), /* passed_span3 */
  45. sum(case when ease = 1 and type == 1 and lastivl BETWEEN 70 AND 99 then 1 else 0 end), /* failed_span3 */
  46. sum(case when ease > 1 and type == 1 and lastivl BETWEEN 100 AND 179 then 1 else 0 end), /* passed_span4 */
  47. sum(case when ease = 1 and type == 1 and lastivl BETWEEN 100 AND 179 then 1 else 0 end), /* failed_span4 */
  48. sum(case when ease > 1 and type == 1 and lastivl >= 180 then 1 else 0 end), /* passed_end */
  49. sum(case when ease = 1 and type == 1 and lastivl >= 180 then 1 else 0 end), /* failed_end */
  50. sum(case when ivl > 0 and type == 0 then 1 else 0 end), /* learned */
  51. sum(case when ivl > 0 and type == 2 then 1 else 0 end) /* relearned */
  52. from revlog where id > ? """+lim, span)
  53. passed = passed or 0
  54. failed = failed or 0
  55. passed_young = passed_young or 0
  56. failed_young = failed_young or 0
  57. passed_mature = passed_mature or 0
  58. failed_mature = failed_mature or 0
  59. passed_span1 = passed_span1 or 0
  60. failed_span1 = failed_span1 or 0
  61. passed_span2 = passed_span2 or 0
  62. failed_span2 = failed_span2 or 0
  63. passed_span3 = passed_span3 or 0
  64. failed_span3 = failed_span3 or 0
  65. passed_span4 = passed_span4 or 0
  66. failed_span4 = failed_span4 or 0
  67. passed_end = passed_end or 0
  68. failed_end = failed_end or 0
  69. learned = learned or 0
  70. relearned = relearned or 0
  71. try:
  72. temp = "%0.1f%%" %(passed/float(passed+failed)*100)
  73. except ZeroDivisionError:
  74. temp = "N/A"
  75. try:
  76. temp_young = "%0.1f%%" %(passed_young/float(passed_young+failed_young)*100)
  77. except ZeroDivisionError:
  78. temp_young = "N/A"
  79. try:
  80. temp_mature = "%0.1f%%" %(passed_mature/float(passed_mature+failed_mature)*100)
  81. except ZeroDivisionError:
  82. temp_mature = "N/A"
  83. try:
  84. temp_span1 = "%0.1f%%" %(passed_span1/float(passed_span1+failed_span1)*100)
  85. except ZeroDivisionError:
  86. temp_span1 = "N/A"
  87. try:
  88. temp_span2 = "%0.1f%%" %(passed_span2/float(passed_span2+failed_span2)*100)
  89. except ZeroDivisionError:
  90. temp_span2 = "N/A"
  91. try:
  92. temp_span3 = "%0.1f%%" %(passed_span3/float(passed_span3+failed_span3)*100)
  93. except ZeroDivisionError:
  94. temp_span3 = "N/A"
  95. try:
  96. temp_span4 = "%0.1f%%" %(passed_span4/float(passed_span4+failed_span4)*100)
  97. except ZeroDivisionError:
  98. temp_span4 = "N/A"
  99. try:
  100. temp_end = "%0.1f%%" %(passed_end/float(passed_end+failed_end)*100)
  101. except ZeroDivisionError:
  102. temp_end = "N/A"
  103. try:
  104. total_reviews = (passed+failed)
  105. except ZeroDivisionError:
  106. total_reviews = "N/A"
  107. try:
  108. total_young = (passed_young+failed_young)
  109. except ZeroDivisionError:
  110. total_young = "N/A"
  111. try:
  112. total_mature = (passed_mature+failed_mature)
  113. except ZeroDivisionError:
  114. total_mature = "N/A"
  115. try:
  116. total_span1 = (passed_span1+failed_span1)
  117. except ZeroDivisionError:
  118. total_span1 = "N/A"
  119. try:
  120. total_span2 = (passed_span2+failed_span2)
  121. except ZeroDivisionError:
  122. total_span2 = "N/A"
  123. try:
  124. total_span3 = (passed_span3+failed_span3)
  125. except ZeroDivisionError:
  126. total_span3 = "N/A"
  127. try:
  128. total_span4 = (passed_span4+failed_span4)
  129. except ZeroDivisionError:
  130. total_span4 = "N/A"
  131. try:
  132. total_end = (passed_end+failed_end)
  133. except ZeroDivisionError:
  134. total_end = "N/A"
  135.  
  136. i = []
  137.  
  138. ### =========== LISTS: pass / fail; (total); [percent]; new cards; relearn ===========
  139. _line_every(self, i, "Overall", passed, failed, total_reviews, temp)
  140. _line_empty(self, i)
  141. _line_every(self, i, "Young", passed_young, failed_young, total_young, temp_young)
  142. # _line_empty(self, i)
  143. _line_every(self, i, "Mature", passed_mature, failed_mature, total_mature, temp_mature)
  144. _line_empty(self, i)
  145. _line_every(self, i, "21-39 Days", passed_span1, failed_span1, total_span1, temp_span1)
  146. _line_every(self, i, "40-69 Days", passed_span2, failed_span2, total_span2, temp_span2)
  147. _line_every(self, i, "70-99 Days", passed_span3, failed_span3, total_span3, temp_span3)
  148. _line_every(self, i, "100-179 Days", passed_span4, failed_span4, total_span4, temp_span4)
  149. _line_every(self, i, "180+ Days", passed_end, failed_end, total_end, temp_end)
  150. _line_empty(self, i)
  151. _line_now(self, i, "New Cards Learned", learned)
  152. _line_now(self, i, "Cards Relearned", relearned)
  153. return _lineTbl_now(self, i)
  154.  
  155. def todayStats_new(self):
  156. lim = self._revlogLimit()
  157. if lim:
  158. lim = " and " + lim
  159.  
  160. pastDay = statList(self, lim, (self.col.sched.dayCutoff-86400)*1000)
  161. pastWeek = statList(self, lim, (self.col.sched.dayCutoff-86400*7)*1000)
  162.  
  163. if self.type == 0:
  164. period = 31; name = "Past month:"
  165. elif self.type == 1:
  166. period = 365; name = "Past year:"
  167. elif self.type == 2:
  168. period = float('inf'); name = "All time:"
  169.  
  170. pastPeriod = statList(self, lim, (self.col.sched.dayCutoff-86400*period)*1000)
  171.  
  172. return todayStats_old(self) + "<br><br><table style='text-align: center'><tr><td style='padding: 5px'>" \
  173. + "<span>Past day:</span>" + pastDay + "</td><td style='padding: 5px'>" \
  174. + "<span>Past week:</span>" + pastWeek + "</td><td style='padding: 5px'>" \
  175. + "<span>" + name + "</span>" + pastPeriod + "</td></tr></table>"
  176.  
  177. anki.stats.CollectionStats.todayStats = todayStats_new
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement