Skip to content

Commit

Permalink
feat: Set box to -1 for new positions
Browse files Browse the repository at this point in the history
  • Loading branch information
Cash Weaver committed Oct 13, 2022
1 parent 36fea91 commit 11df3b5
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 19 deletions.
25 changes: 19 additions & 6 deletions org-fc-algo-sm2.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)))
Expand Down
33 changes: 20 additions & 13 deletions org-fc-dashboard.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions org-fc-position.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 11df3b5

Please sign in to comment.