Skip to content

Commit

Permalink
Feat/add period_lim to Step Stats (open-spaced-repetition#498)
Browse files Browse the repository at this point in the history
  • Loading branch information
L-M-Sherlock authored Nov 25, 2024
1 parent e32c2a5 commit 0b8bb6d
Showing 2 changed files with 14 additions and 5 deletions.
11 changes: 9 additions & 2 deletions stats.py
Original file line number Diff line number Diff line change
@@ -117,8 +117,15 @@ def get_steps_stats(self: CollectionStats):
config.load()
if not config.show_steps_stats:
return ""
lim = self._revlogLimit()
results = steps_stats(lim)
start, days, chunk = self.get_start_end_chunk()
if days is not None:
period_lim = "first_id > %d" % (
(self.col.sched.day_cutoff - (days * chunk * 86400)) * 1000
)
else:
period_lim = ""
deck_lim = self._revlogLimit()
results = steps_stats(deck_lim, period_lim)

title = CollectionStats._title(
self,
8 changes: 5 additions & 3 deletions steps.py
Original file line number Diff line number Diff line change
@@ -28,14 +28,14 @@ def binary_search(points, low=1, high=86400 * 30, tolerance=1e-6):
return (low + high) / 2


def steps_stats(lim):
def steps_stats(deck_lim, period_lim):
learning_revlogs = 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 ""}
{"AND " + deck_lim if deck_lim else ""}
GROUP BY cid
),
second_review AS (
@@ -52,6 +52,7 @@ def steps_stats(lim):
FROM first_review fr
JOIN second_review sr ON fr.cid = sr.cid
WHERE sr.review_order = 1
{"AND " + period_lim if period_lim else ""}
)
SELECT first_rating, delta_t, recall
FROM review_stats
@@ -65,7 +66,7 @@ def steps_stats(lim):
SELECT cid, id AS first_id
FROM revlog
WHERE type = 1 AND ease = 1
{"AND " + lim if lim else ""}
{"AND " + deck_lim if deck_lim else ""}
),
next_review AS (
SELECT
@@ -85,6 +86,7 @@ def steps_stats(lim):
(nr.next_id - nr.first_id) / 1000.0 AS delta_t,
nr.recall
FROM next_review nr
{"WHERE " + period_lim if period_lim else ""}
)
SELECT
delta_t,

0 comments on commit 0b8bb6d

Please sign in to comment.