From 11df3b52a01ba453a3b22b21406cbf424ff55f6b Mon Sep 17 00:00:00 2001 From: Cash Weaver Date: Thu, 13 Oct 2022 07:45:18 -0700 Subject: [PATCH] feat: Set box to -1 for new positions --- org-fc-algo-sm2.el | 25 +++++++++++++++++++------ org-fc-dashboard.el | 33 ++++++++++++++++++++------------- org-fc-position.el | 4 ++++ 3 files changed, 43 insertions(+), 19 deletions(-) diff --git a/org-fc-algo-sm2.el b/org-fc-algo-sm2.el index 62199f9..32f7276 100644 --- a/org-fc-algo-sm2.el +++ b/org-fc-algo-sm2.el @@ -140,6 +140,9 @@ INTERVAL is by a random factor between `org-fc-algo-sm2-fuzz-min' and EASE, BOX and INTERVAL are the current parameters of the card." (let* ((intervals (org-fc-algo-sm2-intervals)) (changes (org-fc-algo-sm2-changes)) + (box + ;; Treat a negative box value (i.e. a new position) as if it were 0. + (max box 0)) (next-ease (if (< box 2) ease @@ -151,21 +154,31 @@ EASE, BOX and INTERVAL are the current parameters of the card." (next-box (cond ;; If a card is rated easy, skip the learning phase - ((and (eq box 0) (eq rating 'easy)) 2) + ((and (eq box 0) + (eq rating 'easy)) + 2) ;; If the review failed, go back to box 0 - ((eq rating 'again) 0) + ((eq rating 'again) + 0) + ;; If it's a new position, skip forward as if we were at box 0 + ((eq box -1) + 1) ;; Otherwise, move forward one box - (t (1+ box)))) + (t + (1+ box)))) (next-interval (cond ((< next-box (length intervals)) (nth next-box intervals)) - ((and (eq org-fc-algorithm 'sm2-v2) (eq rating 'hard)) (* 1.2 interval)) - (t (org-fc-algo-sm2-fuzz (* next-ease interval)))))) + ((and (eq org-fc-algorithm 'sm2-v2) + (eq rating 'hard)) + (* 1.2 interval)) + (t + (org-fc-algo-sm2-fuzz (* next-ease interval)))))) (list next-ease next-box next-interval))) (defun org-fc-algo-sm2-initial-review-data (position) "Initial SM2 review data for POSITION." - (let* ((box 0) + (let* ((box -1) (ease (org-fc-algo-sm2-ease-initial)) (interval 0) (due (org-fc-timestamp-in interval))) diff --git a/org-fc-dashboard.el b/org-fc-dashboard.el index 9165d5a..0a29bcc 100644 --- a/org-fc-dashboard.el +++ b/org-fc-dashboard.el @@ -75,9 +75,13 @@ environment without svg support." (defun org-fc-dashboard-stats (index) "Compute statistics for an INDEX of cards and positions." - (let* ((total 0) (suspended 0) + (let* ((total 0) + (suspended 0) (by-type (make-hash-table)) - (avg-ease 0.0) (avg-box 0.0) (avg-interval 0.0) + (ease-sum 0.0) + (box-sum 0.0) + (interval-sum 0.0) + (new 0) (n-pos 0) ;; NOTE: This has to use `list' so incf + getf works as ;; expected @@ -116,19 +120,22 @@ environment without svg support." (if (time-less-p pos-due plus-month) (cl-incf (cl-getf due :month) 1))) - (cl-incf avg-ease (plist-get pos :ease)) - (cl-incf avg-box (plist-get pos :box)) - (cl-incf avg-interval (plist-get pos :interval))))) + (cl-incf ease-sum (plist-get pos :ease)) + (cl-incf box-sum (plist-get pos :box)) + (cl-incf interval-sum (plist-get pos :interval)) + + (if (eq (plist-get pos :box) -1) + (cl-incf new 1))))) (cl-incf (gethash (plist-get card :type) by-type 0) 1)) (list :total total - :total-positions n-pos :suspended suspended :due due :by-type (org-fc-dashboard--hashtable-to-alist by-type) :created created - :avg-ease (/ avg-ease n-pos) - :avg-box (/ avg-box n-pos) - :avg-interval (/ avg-interval n-pos)))) + :new new + :avg-ease (/ ease-sum n-pos) + :avg-box (/ box-sum n-pos) + :avg-interval (/ interval-sum n-pos)))) ;;; Bar Chart Generation @@ -195,11 +202,13 @@ environment without svg support." (insert (propertize "Card Statistics\n\n" 'face 'org-level-1)) - (insert (format " New: %d (day) %d (week) %d (month) \n" + (insert (format " New: %d \n" + (plist-get stats :new))) + (insert "\n") + (insert (format " Created: %d (day) %d (week) %d (month) \n" (plist-get created-stats :day) (plist-get created-stats :week) (plist-get created-stats :month))) - (insert "\n") (insert (format " %6d Cards, %d suspended\n" @@ -211,8 +220,6 @@ environment without svg support." (insert (propertize "Position Statistics\n\n" 'face 'org-level-1)) - (insert (format " Total: %d\n\n" - (plist-get stats :total-positions))) (insert (format " Due: %d (now) %d (day) %d (week) %d (month)\n\n" (plist-get due-stats :now) (plist-get due-stats :day) diff --git a/org-fc-position.el b/org-fc-position.el index 59f7be9..ea9d63b 100644 --- a/org-fc-position.el +++ b/org-fc-position.el @@ -59,6 +59,10 @@ "Return t if POS is due; else nil." (time-less-p (oref pos due) (current-time))) +(cl-defmethod org-fc-position-new-p ((pos org-fc-position)) + "Return t if the provided POS ition is new; nil otherwise." + (eq -1 (oref pos box))) + (defun org-fc-positions--filter-due (positions) "Filter POSITIONS to include only enabled and due positions." (let ((due-enabled-positions (cl-loop for pos in positions