Skip to content

Commit

Permalink
add steps stats table
Browse files Browse the repository at this point in the history
  • Loading branch information
L-M-Sherlock committed Nov 9, 2024
1 parent 1d0260e commit 6efa404
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 7 deletions.
4 changes: 0 additions & 4 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from .schedule.remedy import remedy_hard_misuse, undo_remedy
from .schedule import init_review_hook
from .stats import init_stats
from .steps_optimizer import steps_optimizer
from .browser.browser import init_browser
from .configuration import Config, run_on_configuration_change

Expand Down Expand Up @@ -182,8 +181,6 @@ def reschedule_recent(did):

menu_disperse_siblings = build_action(disperse_siblings, "Disperse all siblings")

menu_steps_optimizer = build_action(steps_optimizer, "Steps Optimizer")

menu_remedy_hard_misuse = build_action(remedy_hard_misuse, "Remedy")

menu_undo_remedy = build_action(undo_remedy, "Undo")
Expand Down Expand Up @@ -249,7 +246,6 @@ def sponsor(did=None):
menu_for_helper.addAction(menu_flatten)
menu_for_helper.addAction(menu_reset)
menu_for_helper.addAction(menu_disperse_siblings)
menu_for_helper.addAction(menu_steps_optimizer)
menu_for_helper.addSeparator()
menu_for_remedy = menu_for_helper.addMenu("Remedy Hard Misuse")
menu_for_remedy.addAction(menu_remedy_hard_misuse)
Expand Down
67 changes: 67 additions & 0 deletions stats.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from anki.stats import CollectionStats
from .configuration import Config
from .utils import *
from .steps import steps_stats


def _line_now(i, a, b, bold=True):
Expand Down Expand Up @@ -107,9 +108,75 @@ def todayStats_new(self):
+ get_true_retention(self)
+ get_fsrs_stats(self)
+ get_retention_graph(self)
+ get_steps_stats(self)
)


def get_steps_stats(self: CollectionStats):
lim = self._revlogLimit()
results = steps_stats(lim)

title = CollectionStats._title(
self, "Steps Stats", "Statistics for different ratings during learning steps"
)

html = """
<style>
td.trl { border: 1px solid; text-align: left; padding: 5px }
td.trr { border: 1px solid; text-align: right; padding: 5px }
td.trc { border: 1px solid; text-align: center; padding: 5px }
span.again { color: #f00 }
span.hard { color: #ff8c00 }
span.good { color: #008000 }
</style>
<table style="border-collapse: collapse;" cellspacing="0" cellpadding="2">
<tr>
<td class="trl" rowspan=2><b>Rating</b></td>
<td class="trc" colspan=3><b>Review Timing Distribution</b></td>
<td class="trc" colspan=2><b>Performance</b></td>
</tr>
<tr>
<td class="trc"><b>25%</b></td>
<td class="trc"><b>50%</b></td>
<td class="trc"><b>75%</b></td>
<td class="trc"><b>Retention</b></td>
<td class="trc"><b>Stability</b></td>
</tr>"""

ratings = {1: "again", 2: "hard", 3: "good"}
for rating, style in ratings.items():
stats = results["stats"].get(rating, {})
if not stats:
html += f"""
<tr>
<td class="trl"><span class="{style}"><b>{style.title()}</b></span></td>
<td class="trr">N/A</td>
<td class="trr">N/A</td>
<td class="trr">N/A</td>
<td class="trr">N/A</td>
<td class="trr">N/A</td>
</tr>"""
continue

html += f"""
<tr>
<td class="trl"><span class="{style}"><b>{style.title()}</b></span></td>
<td class="trr">{stats['delay_q1'] / 60:.2f} min</td>
<td class="trr">{stats['delay_q2'] / 60:.2f} min</td>
<td class="trr">{stats['delay_q3'] / 60:.2f} min</td>
<td class="trr">{stats['retention']}</td>
<td class="trr">{results['stability'][rating] / 60:.2f} min</td>
</tr>"""

html += "</table>"
html += (
"<p>This table shows how long students typically wait before reviewing cards for each rating, "
"and the resulting retention and stability.</p>"
)

return self._section(title + html)


def get_fsrs_stats(self: CollectionStats):
lim = self._limit()
if lim:
Expand Down
7 changes: 4 additions & 3 deletions steps_optimizer.py → steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ def binary_search(points, low=1, high=86400, tolerance=1e-6):
return (low + high) / 2


def steps_optimizer(did=None):
def steps_stats(lim):
results = mw.col.db.all(
"""
f"""
WITH first_review AS (
SELECT cid, MIN(id) AS first_id, ease AS first_rating
FROM revlog
WHERE ease BETWEEN 1 AND 4
{"AND " + lim if lim else ""}
GROUP BY cid
),
second_review AS (
Expand Down Expand Up @@ -113,4 +114,4 @@ def steps_optimizer(did=None):
points = list(filter(lambda x: LOWER <= x[0] <= UPPER, points))
rating2stability[rating] = round(binary_search(points))
display_dict["stability"] = rating2stability
showInfo(json.dumps(display_dict, indent=4))
return display_dict

0 comments on commit 6efa404

Please sign in to comment.