Browse Source

feat(srs): add config :srs/learning-fraction, :srs/initial-interval

rcmerci 4 years ago
parent
commit
ba95db41a9
2 changed files with 30 additions and 4 deletions
  1. 22 3
      src/main/frontend/extensions/srs.cljs
  2. 8 1
      templates/config.edn

+ 22 - 3
src/main/frontend/extensions/srs.cljs

@@ -49,12 +49,31 @@
   "{{card-query ...}}"
   "card-query")
 
-(def learning-fraction
+(def learning-fraction-default
   "any number between 0 and 1 (the greater it is the faster the changes of the OF matrix)"
   0.5)
 
+(defn- learning-fraction []
+  (if-let [learning-fraction (:srs/learning-fraction (state/get-config))]
+    (if (and (number? learning-fraction)
+             (< learning-fraction 1)
+             (> learning-fraction 0))
+      learning-fraction
+      learning-fraction-default)
+    learning-fraction-default))
+
 (def of-matrix (persist-var/persist-var nil "srs-of-matrix"))
 
+(def initial-interval-default 4)
+
+(defn- initial-interval []
+  (if-let [initial-interval (:srs/initial-interval (state/get-config))]
+    (if (and (number? initial-interval)
+             (> initial-interval 0))
+      initial-interval
+      initial-interval-default)
+    initial-interval-default))
+
 ;;; ================================================================
 ;;; utils
 
@@ -114,7 +133,7 @@
 (defn- get-of [of-matrix n ef]
   (or (get-in of-matrix [n ef])
       (if (<= n 1)
-        4
+        (initial-interval)
         ef)))
 
 (defn- set-of [of-matrix n ef of]
@@ -148,7 +167,7 @@
   (let [ef (or ef 2.5)
         last-interval (if (or (nil? last-interval) (<= last-interval 0)) 1 last-interval)
         next-ef (next-ef ef quality)
-        next-of-matrix (next-of-matrix of-matrix repeats quality learning-fraction ef)
+        next-of-matrix (next-of-matrix of-matrix repeats quality (learning-fraction) ef)
         next-interval (interval repeats next-ef next-of-matrix)]
 
     (if (< quality 3)

+ 8 - 1
templates/config.edn

@@ -156,4 +156,11 @@
  ;;
  ;; With the default value of level 2, `b` will be collapsed.
  ;; If we set the level's value to 3, `b` will be opened and `c` will be collapsed.
- :ref/default-open-blocks-level 2}
+ :ref/default-open-blocks-level 2
+
+ ;; any number between 0 and 1 (the greater it is the faster the changes of the next-interval of card reviews) (default 0.5)
+ ;; :srs/learning-fraction 0.5
+
+ ;; the initial interval after the first successful review of a card (default 4)
+ ;; :srs/initial-interval 4
+ }