def _update(self): if not self.dock or not self.dock.isVisible(): return if freezeMode and self.type>10: return card = mw.reviewer.card txt = _("No Current Card") if self.type<-10: txt = _("No Last Card") card = mw.reviewer.lastCard() cs = CollectionStats(mw.col) cs.wholeCollection=True if self.type<0 else False if self.type==0: #review count txt = "<center>%s</center>" % mw.reviewer._remaining() if mw.state=="review" else '? + ? + ?' elif abs(self.type)==1: #todayStats txt = "<center>%s</center>" % cs.todayStats() elif abs(self.type)==2: #forecast chart #no filtered decks did=mw.col.decks.selected() dyn=mw.col.decks.get(did) if dyn['dyn'] and self.type>0: txt="No data for filtered decks" elif ANKI21: p=mw.mediaServer.getPort() txt = """ <script src="http://localhost:%d/_anki/jquery.js"></script> <script src="http://localhost:%d/_anki/plot.js"></script> <center>%s</center> """ % (p,p,self.dueGraph(cs)) else: txt = "<script>%s\n</script><center>%s</center>" % ( anki.js.jquery+anki.js.plot, self.dueGraph(cs)) elif abs(self.type)>=90: txt = self.customViews(card) elif mw.state!='review' and self.type>10: txt = _("No Review Card") elif card: #left or right col cs = CardStats(mw.col, card) if abs(self.type)==12: #card rev log txt = self._revlogData(card, cs) else: #card stats txt = self.deckOptionsInfo(card) txt += _("<h3>Card Stats:</h3>") txt += self.mini_card_stats(card) txt += cs.report() did = card.odid if card.odid else card.did fdid = card.did if card.odid else 0 deckName = mw.col.decks.get(did)['name'] #in case of filtered decks sis=[i for i in mw.col.db.list("select id from cards where nid=?", card.nid)] tags=mw.col.getNote(card.nid).stringTags() txt += """<table width="100%%"><tr> <td><b>Deck ID:</b></td> <td>%d</td></tr><tr> <td><b>Fil DID:</b></td> <td>%d</td></tr><tr> <td><b>oDeck:</b></td> <td>%s</td></tr><tr> <td><b>SiblingCnt:</b></td> <td>%d</td></tr><tr> <td><b>Siblings:</b></td> <td>%s</td></tr><tr> <td><b>Tags:</b></td> <td>%s</td> </tr></table>""" % (did, fdid, deckName, len(sis), str(sis), tags) style = self._style() self.web.setHtml(""" <!doctype html><html><head><style>%s</style></head> <body class="night_mode">%s</body></html>""" % (style, txt))
def report(self, type=0): self.type = type self.data = {} try: title = self.col.decks.get(self.col.decks.active()[0])[u'name'] ws = upload(title) if ws is not None: lim = self._revlogLimit() if lim: lim = " and " + lim a,b,c,d,e,f,g = self.col.db.first(""" select count(), sum(time)/1000, sum(case when ease = 1 then 1 else 0 end), /* failed */ sum(case when type = 0 then 1 else 0 end), /* learning */ sum(case when type = 1 then 1 else 0 end), /* review */ sum(case when type = 2 then 1 else 0 end), /* relearn */ sum(case when type = 3 then 1 else 0 end) /* filter */ from revlog where id > ? """+lim, (self.col.sched.dayCutoff-86400)*1000) self.data["totalCardsStudied"] = a or 0 self.data["timeSpentStudying"] = b or 0 self.data["againCount"] = c or 0 self.data["learn"] = d or 0 self.data["review"] = e or 0 self.data["relearn"] = f or 0 self.data["filtered"] = g or 0 if self.data["totalCardsStudied"] > 0: self.data["percentCorrectAllCards"] = "{0:.2f}".format((1-self.data["againCount"]/float(self.data["totalCardsStudied"]))*100) else: self.data["percentCorrectAllCards"] = 0 mcnt, msum = self.col.db.first(""" select count(), sum(case when ease = 1 then 0 else 1 end) from revlog where lastIvl >= 21 and id > ?"""+lim, (self.col.sched.dayCutoff-86400)*1000) self.data["matureCardsStudied"] = msum or 0 if mcnt > 0: self.data["percentCorrectMatureCards"] = "{0:.2f}".format(self.data["matureCardsStudied"] / float(mcnt) * 100) else: self.data["percentCorrectMatureCards"] = 0 a,b,c,d = self.col.db.first(""" select sum(case when queue=2 and ivl >= 21 then 1 else 0 end), -- mtr sum(case when queue in (1,3) or (queue=2 and ivl < 21) then 1 else 0 end), -- yng/lrn sum(case when queue=0 then 1 else 0 end), -- new sum(case when queue<0 then 1 else 0 end) -- susp from cards where did in %s""" % self._limit()) self.data["totalMatureCards"] = a or 0 self.data["totalYoungLearnCards"] = b or 0 self.data["totalUnseenCards"] = c or 0 self.data["totalSuspendedCards"] = d or 0 for deck in self.col.sched.deckDueList(): if deck[0] == title: self.data["totalDueCards"] = deck[2] break s = '' for key,value in self.data.items(): s += '{0}:{1}\n'.format(key,value) from aqt import mw import datetime currentDay = (datetime.datetime.today() - datetime.datetime.fromtimestamp(mw.col.crt)).days from PyQt4 import QtGui QtGui.QMessageBox.information(mw,'Statistics Upload', s) col = startColumn if not dayInFirstRow: row = ws.row_count + 1 else: col = col + 1 if ws.cell(startRow,startColumn).value == "": row = startRow else: row = currentDay - int(ws.cell(startRow,startColumn).value) + 1 ws.update_cell(row,startColumn,str(currentDay)) if row > ws.row_count: ws.resize(rows = row) cell_list = [] for field in order: cell = self.cell(row, col) cell.value = self.data[field] cell_list.append(cell) col = col + 1 ws.update_cells(cell_list) except: pass return CollectionStats.report(self,type)