From acb08ba18ec5ebf081b9becf1ac15a2d0eeded3d Mon Sep 17 00:00:00 2001 From: Yoshi Date: Sat, 10 Sep 2022 13:29:05 +0200 Subject: [PATCH 1/2] Update Extended Card Stats During Review Manual formatting of stats because it's what was easiest for me. --- .../reviewer_card_stats.py | 59 ++++++++++++------- 1 file changed, 37 insertions(+), 22 deletions(-) mode change 100644 => 100755 src/reviewer_card_stats/reviewer_card_stats.py diff --git a/src/reviewer_card_stats/reviewer_card_stats.py b/src/reviewer_card_stats/reviewer_card_stats.py old mode 100644 new mode 100755 index c8611a6..68af7a3 --- a/src/reviewer_card_stats/reviewer_card_stats.py +++ b/src/reviewer_card_stats/reviewer_card_stats.py @@ -23,9 +23,6 @@ from aqt.webview import AnkiWebView import aqt.stats import time -import datetime -from anki.lang import _ -from anki.utils import fmtTimeSpan from anki.stats import CardStats @@ -45,12 +42,13 @@ def closeEvent(self, evt): QDockWidget.closeEvent(self, evt) dock = DockableWithClose(title, mw) dock.setObjectName(title) - dock.setAllowedAreas(Qt.LeftDockWidgetArea | Qt.RightDockWidgetArea) - dock.setFeatures(QDockWidget.DockWidgetClosable) + dock.setAllowedAreas(Qt.DockWidgetArea.LeftDockWidgetArea | + Qt.DockWidgetArea.RightDockWidgetArea) + dock.setFeatures(QDockWidget.DockWidgetFeature.DockWidgetClosable) dock.setWidget(w) if mw.width() < 600: mw.resize(QSize(600, mw.height())) - mw.addDockWidget(Qt.RightDockWidgetArea, dock) + mw.addDockWidget(Qt.DockWidgetArea.RightDockWidgetArea, dock) return dock def _remDockable(self, dock): @@ -62,7 +60,7 @@ class ThinAnkiWebView(AnkiWebView): def sizeHint(self): return QSize(200, 100) self.web = ThinAnkiWebView() - self.shown = self._addDockable(_("Card Info"), self.web) + self.shown = self._addDockable("Card Info", self.web) self.shown.closed.connect(self._onClosed) self._update() @@ -91,16 +89,15 @@ def _revlogData(self, card, cs): "from revlog where cid = ?", card.id) if not entries: return "" - s = "" % _("Date") + s = "
%s
" % "Date" s += ("" * 6) % ( - _("Type"), _("Rating"), _("Interval"), "IntDate", _("Ease"), _("Time")) + "Type", "Rating", "Interval", "IntDate", "Ease", "Time") cnt = 0 for (date, ease, ivl, factor, taken, type) in reversed(entries): cnt += 1 - s += "" % time.strftime(_("%Y-%m-%d @ %H:%M"), + s += "" % time.strftime("%Y-%m-%d @ %H:%M", time.localtime(date)) - tstr = [_("Learn"), _("Review"), _("Relearn"), _("Filtered"), - _("Resched")][type] + tstr = ["Learn", "Review", "Relearn", "Filtered", "Resched"][type] import anki.stats as st fmt = "%s" @@ -120,12 +117,12 @@ def _revlogData(self, card, cs): int_due = "na" if ivl > 0: int_due_date = time.localtime(date + (ivl * 24 * 60 * 60)) - int_due = time.strftime(_("%Y-%m-%d"), int_due_date) + int_due = time.strftime("%Y-%m-%d", int_due_date) #################### if ivl == 0: - ivl = _("0d") + ivl = "0d" elif ivl > 0: - ivl = fmtTimeSpan(ivl * 86400, short=True) + ivl = mw.col.format_timespan(ivl * 86400, short=True) else: ivl = cs.time(-ivl) @@ -138,11 +135,29 @@ def _revlogData(self, card, cs): cs.time(taken)) + "" s += "
%s%s
%s
%s
" if cnt < card.reps: - s += _("""\ + s += """\ Note: Some of the history is missing. For more information, \ -please see the browser documentation.""") +please see the browser documentation.""" return s + def _format_date(self, secs): + return time.strftime("%Y-%m-%d", time.localtime(secs)) + + def _format_card_stats(self, data): + txt = f"Card Type: {data.card_type}
" + txt += f"Note Type: {data.notetype}
" + txt += f"Deck: {data.deck}
" + txt += f"Date Added: {self._format_date(data.added)}
" + txt += f"First Reviewed: {self._format_date(data.first_review)}
" + txt += f"Last Reviewed: {self._format_date(data.latest_review)}
" + txt += f"Due Date: {self._format_date(data.latest_review)}
" + txt += f"Ease: {data.ease}
" + txt += f"Reviews: {data.reviews}
" + txt += f"Card Id: {data.card_id}
" + txt += f"Note Id: {data.note_id}" + + return txt + def _update(self): if not self.shown: return @@ -152,18 +167,18 @@ def _update(self): cs = CardStats(d, r.card) cc = r.card if cc: - txt += _("

Current

") - txt += d.cardStats(cc) + txt += "

Current

" + txt += self._format_card_stats(d.card_stats_data(cc.id)) txt += "

" txt += self._revlogData(cc, cs) lc = r.lastCard() if lc: - txt += _("

Last

") - txt += d.cardStats(lc) + txt += "

Last

" + txt += self._format_card_stats(d.card_stats_data(lc.id)) txt += "

" txt += self._revlogData(lc, cs) if not txt: - txt = _("No current card or last card.") + txt = "No current card or last card." style = self._style() self.web.setHtml(""" From 4f9d4a224cd1dbba3a57519ff2180e80130bc766 Mon Sep 17 00:00:00 2001 From: Yoshi Date: Tue, 8 Nov 2022 12:55:59 +0100 Subject: [PATCH 2/2] Remove obsolete argument from format_timespan --- src/reviewer_card_stats/reviewer_card_stats.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/reviewer_card_stats/reviewer_card_stats.py b/src/reviewer_card_stats/reviewer_card_stats.py index 68af7a3..0d001d3 100755 --- a/src/reviewer_card_stats/reviewer_card_stats.py +++ b/src/reviewer_card_stats/reviewer_card_stats.py @@ -122,7 +122,7 @@ def _revlogData(self, card, cs): if ivl == 0: ivl = "0d" elif ivl > 0: - ivl = mw.col.format_timespan(ivl * 86400, short=True) + ivl = mw.col.format_timespan(ivl * 86400) else: ivl = cs.time(-ivl)