forked from l3kn/org-fc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
org-fc-algo-sm2.el
168 lines (141 loc) · 5.84 KB
/
org-fc-algo-sm2.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
;;; org-fc-algo-sm2.el --- Variation of SM2 spacing algorithm -*- lexical-binding: t; -*-
;; Copyright (C) 2020-2021 Leon Rische
;; Author: Leon Rische <[email protected]>
;; Url: https://www.leonrische.me/pages/org_flashcards.html
;; Package-requires: ((emacs "26.3") (org "9.3"))
;; Version: 0.1.0
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;;
;;
;;
;;; Code:
(require 'cl-lib)
(require 'org-fc-core)
(require 'org-fc-algo)
;;;; Properties
(org-fc-property org-fc-algo-sm2-ease-min 1.3
"Lower bound for a cards ease."
:type 'float
:group 'org-fc
:property "FC_SM2_EASE_MIN")
(org-fc-property org-fc-algo-sm2-ease-max 5.0
"Upper bound for a cards ease."
:type 'float
:group 'org-fc
:property "FC_SM2_EASE_MAX")
(org-fc-property org-fc-algo-sm2-ease-initial 2.5
"Initial ease."
:type 'float
:group 'org-fc
:property "FC_SM2_EASE_INITIAL")
(org-fc-property org-fc-algo-sm2-fuzz-min 0.9
"Lower bound for random interval fuzz factor."
:type 'float
:group 'org-fc
:property "FC_SM2_FUZZ_MIN")
(org-fc-property org-fc-algo-sm2-fuzz-max 1.1
"Upper bound for random interval fuzz factor."
:type 'float
:group 'org-fc
:property "FC_SM2_FUZZ_MAX")
(org-fc-property org-fc-algo-sm2-changes
'((again . -0.3)
(hard . -0.15)
(good . 0.0)
(easy . 0.15))
"Changes to a cards ease depending on its rating."
:type 'list
:group 'org-fc
:property "FC_SM2_CHANGES")
(org-fc-property org-fc-algo-sm2-intervals
'(0.0 0.01 1.0 6.0)
"Hard-coded intervals for the first few card boxes.
Values are in days."
:type 'list
:group 'org-fc
:property "FC_SM2_INTERVALS")
;;;; Helper Functions
(defun org-fc-algo-sm2-fuzz (interval)
"Apply fuzz to INTERVAL.
INTERVAL is by a random factor between `org-fc-algo-sm2-fuzz-min' and
`org-fc-algo-sm2-fuzz-max'"
(let ((min (org-fc-algo-sm2-fuzz-min))
(max (org-fc-algo-sm2-fuzz-max)))
(* interval (+ min (cl-random (- max min))))))
;;;; Main Algorithm
(defun org-fc-algo-sm2-next-parameters (rating position ease box interval due)
"Calculate the next parameters of a card, based on the review RATING.
EASE, BOX and INTERVAL are the current parameters of the card."
(let* ((intervals (org-fc-algo-sm2-intervals))
(changes (org-fc-algo-sm2-changes))
(next-ease
(if (< box 2)
ease
(min
(max
(+ ease (alist-get rating changes))
(org-fc-algo-sm2-ease-min))
(org-fc-algo-sm2-ease-max))))
(next-box
(cond
;; If a card is rated easy, skip the learning phase
((and (eq box 0) (eq rating 'easy)) 2)
;; If the review failed, go back to box 0
((eq rating 'again) 0)
;; Otherwise, move forward one 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))))))
(list position next-ease next-box next-interval (org-fc-timestamp-in next-interval))))
(defun org-fc-algo-sm2-initial-review-data ()
"Initial SM2 review data."
(let* ((box 0)
(ease (org-fc-algo-sm2-ease-initial))
(interval 0)
(due (org-fc-timestamp-in interval)))
(list "front" ease box interval due)))
(defun org-fc-algo-sm2-omit-due-date-in-history-file (where position ease box interval due)
(let ((formatted-params (list position
(format "%.2f" ease)
(format "%d" box)
(format "%.2f" interval)
due)))
(if (eq where 'history)
(butlast formatted-params)
formatted-params)))
(org-fc-register-algo
'sm2-v1
'("position" "ease" "box" "interval" "due")
'((:rate again :tag "Again" :key "a" :face (:background "red"))
(:rate hard :tag "Hard" :key "h" :face (:background "orange"))
(:rate good :tag "Good" :key "g" :face (:background "green"))
(:rate easy :tag "Easy" :key "e" :face (:background "lime green")))
'org-fc-algo-sm2-initial-review-data
'org-fc-algo-sm2-next-parameters
'org-fc-algo-sm2-omit-due-date-in-history-file)
(org-fc-register-algo
'sm2-v2
'("position" "ease" "box" "interval" "due")
'((:rate again :tag "Again" :key "a" :face (:background "red"))
(:rate hard :tag "Hard" :key "h" :face (:background "orange"))
(:rate good :tag "Good" :key "g" :face (:background "green"))
(:rate easy :tag "Easy" :key "e" :face (:background "lime green")))
'org-fc-algo-sm2-initial-review-data
'org-fc-algo-sm2-next-parameters
'org-fc-algo-sm2-omit-due-date-in-history-file)
;;; Footer
(provide 'org-fc-algo-sm2)
;;; org-fc-algo-sm2.el ends here