From cbc2d4e95c7ba8584f6e3d5c6c45b79c9c4cd492 Mon Sep 17 00:00:00 2001 From: Marek Paśnikowski Date: Sun, 14 Jan 2024 11:23:24 +0100 Subject: Apply ORG-FC-TN patches --- org-fc-algo-tn.el | 41 +++++++++++++++++++++++++++++++++++++++++ org-fc-core.el | 4 +++- org-fc-review.el | 33 ++++++++++++++++++++++++++------- org-fc.el | 1 + 4 files changed, 71 insertions(+), 8 deletions(-) create mode 100644 org-fc-algo-tn.el diff --git a/org-fc-algo-tn.el b/org-fc-algo-tn.el new file mode 100644 index 0000000..7b4f1bc --- /dev/null +++ b/org-fc-algo-tn.el @@ -0,0 +1,41 @@ +(require 'org-fc-core) + +;;; Main Algorithm + +(defun nth-tn (n) + "The mathematical formula for the Nth triangular number." + (/ (* n + (1+ n)) + 2)) + +(defun org-fc-algo-tn-next-parameters (ease box interval rating) + "Calculate the next parameters of a card, based on the review RATING. +EASE, BOX and INTERVAL are the current parameters of the card." + (let* ((incorrect-at-edge (and (eq rating 'incorrect) + (eq box 1))) + (incorrect (eq rating 'incorrect)) + (correct t) + (next-ease (cond (incorrect-at-edge (- ease 0.01)) + (incorrect (- ease 0.01)) + (correct ease))) + (next-box (cond (incorrect-at-edge box) + (incorrect (1- box)) + (correct 1+ box))) + (next-interval (cond (incorrect-at-edge 1) + (incorrect (nth-tn next-box)) + (correct (nth-tn next-box))))) + (list next-ease next-box next-interval))) + +(defun org-fc-algo-tn-initial-review-data (position) + "Initial TN review data for POSITION." + (let ((box 1) + (ease 1) + (interval 1) + (due (org-fc-timestamp-in 0))) + (list position ease box interval due))) + +;;; Footer + +(provide 'org-fc-algo-tn) + +;; org-fc-algo-tn.el ends here. diff --git a/org-fc-core.el b/org-fc-core.el index 1033cf1..1ed2508 100644 --- a/org-fc-core.el +++ b/org-fc-core.el @@ -125,7 +125,9 @@ types." (defcustom org-fc-algorithm 'sm2-v1 "Algorithm for spacing reviews of cards." - :type '(choice (const sm2-v1) (const sm2-v2)) + :type '(choice (const sm2-v1) + (const sm2-v2) + (const tn)) :group 'org-fc) (defcustom org-fc-bury-siblings nil diff --git a/org-fc-review.el b/org-fc-review.el index eaa29cf..e0e882b 100644 --- a/org-fc-review.el +++ b/org-fc-review.el @@ -238,6 +238,16 @@ same ID as the current card in the session." (org-fc-review-quit) (signal (car err) (cdr err))))) +(defun org-fc-review-rate-incorrect () + "Rate the card at point with 'incorrect'." + (interactive) + (org-fc-review-rate 'incorrect)) + +(defun org-fc-review-rate-correct () + "Rate the card at point with 'correct'." + (interactive) + (org-fc-review-rate 'correct)) + (defun org-fc-review-rate-again () "Rate the card at point with 'again'." (interactive) @@ -301,7 +311,9 @@ rating the card." (format "%.2f" delta) (symbol-name org-fc-algorithm))) (cl-destructuring-bind (next-ease next-box next-interval) - (org-fc-algo-sm2-next-parameters ease box interval rating) + (if (eq org-fc-algorithm 'tn) + (org-fc-algo-tn-next-parameters ease box interval rating) + (org-fc-algo-sm2-next-parameters ease box interval rating)) (setcdr current (list (format "%.2f" next-ease) @@ -403,7 +415,8 @@ END is the start of the line with :END: on it." "Default review data for position POSITION." (cl-case org-fc-algorithm ('sm2-v1 (org-fc-algo-sm2-initial-review-data position)) - ('sm2-v2 (org-fc-algo-sm2-initial-review-data position)))) + ('sm2-v2 (org-fc-algo-sm2-initial-review-data position)) + ('tn (org-fc-algo-tn-initial-review-data position)))) (defun org-fc-review-data-update (positions) "Update review data to POSITIONS. @@ -464,11 +477,15 @@ removed." (defun org-fc-review-add-rating (session rating) "Store RATING in the review history of SESSION." (with-slots (ratings) session - (cl-case rating - ('again (cl-incf (cl-getf ratings :again) 1)) - ('hard (cl-incf (cl-getf ratings :hard) 1)) - ('good (cl-incf (cl-getf ratings :good) 1)) - ('easy (cl-incf (cl-getf ratings :easy) 1))) + (if (eq org-fc-algorithm 'tn) + (cl-case rating + ('incorrect (cl-incf (cl-getf ratings :incorrect) 1)) + ('correct (cl-incf (cl-getf ratings :correct) 1))) + (cl-case rating + ('again (cl-incf (cl-getf ratings :again) 1)) + ('hard (cl-incf (cl-getf ratings :hard) 1)) + ('good (cl-incf (cl-getf ratings :good) 1)) + ('easy (cl-incf (cl-getf ratings :easy) 1)))) (cl-incf (cl-getf ratings :total 1)))) ;;; Header Line @@ -527,6 +544,8 @@ removed." (defvar org-fc-review-rate-mode-map (let ((map (make-sparse-keymap))) + (define-key map (kbd "i") 'org-fc-review-rate-incorrect) + (define-key map (kbd "c") 'org-fc-review-rate-correct) (define-key map (kbd "a") 'org-fc-review-rate-again) (define-key map (kbd "h") 'org-fc-review-rate-hard) (define-key map (kbd "g") 'org-fc-review-rate-good) diff --git a/org-fc.el b/org-fc.el index f763607..18484c5 100644 --- a/org-fc.el +++ b/org-fc.el @@ -31,6 +31,7 @@ (require 'org-fc-awk) (require 'org-fc-algo-sm2) +(require 'org-fc-algo-tn) (require 'org-fc-review) (require 'org-fc-dashboard) -- cgit v1.2.3