Add DelayRatio and AllowedRandomVariation config options
John Smith

John Smith commited on 2022-133 23:27:55
Showing 2 changed files, with 18 additions and 9 deletions.


The review scheduler now looks at DelayRatio and AllowedRandomVariation
options from the configuration file; these control, respectively,
- the factor/ratio by which the delay from the previous review
    is scaled to determine the new delay
- the proportion of the precisely scheduled delay by which
    a random offset can manipulate the final delay
If these options are not specified, default values will be used,
providing the same behaviour as before the change.

Implementing this involved adding a function to retrieve values
from configuration data, pressuring me to split configuration-loading
code into a separate file ...
... ...
@@ -140,6 +141,15 @@ else
140 141
 end
141 142
 end
142 143
 
144
+--[[
145
+    gets config option `name`; if multiple values were given,
146
+    provide the `ind`th one (or the first, if `ind` is not given)
147
+    return `nil` if no such option available
148
+]]
149
+function config:get(name, ind)
150
+    return (self[name] or {})[ind or 1]
151
+end
152
+
143 153
 if not config.DeckFile then
144 154
     io.write("No deck files specified -- aborting\n")
145 155
     os.exit(true, true)
... ...
@@ -240,9 +250,9 @@ elseif action == "r" then
240 250
                 imgify(pst:gsub("%%A", (pr.ans:gsub("%%", "%%%%"))), deckfname:match(".*/") or "")
241 251
                 io.write(string.format(
242 252
                     "\nAgain / Hard (%s) / Good (%s) / Easy (%s) / Correction ",
243
-                    disptime(review.schedule(pr, st, 0.5)),
244
-                    disptime(review.schedule(pr, st, 1)),
245
-                    disptime(review.schedule(pr, st, 1.5))
253
+                    disptime(review.schedule(pr, st, 0.5, config)),
254
+                    disptime(review.schedule(pr, st, 1, config)),
255
+                    disptime(review.schedule(pr, st, 1.5, config))
246 256
                 ))
247 257
                 io.flush()
248 258
                 local resp = io.read("l")
... ...
@@ -250,7 +260,7 @@ elseif action == "r" then
250 260
                 if sc == -1 then
251 261
                     table.insert(editqueue, ip[1])
252 262
                 else
253
-                    review.update(deck[ip[1]][ip[2]], st, sc)
263
+                    review.update(deck[ip[1]][ip[2]], st, sc, config)
254 264
                 end
255 265
                 clear()
256 266
             end
... ...
@@ -7,10 +7,10 @@
7 7
     when `Prompt` `prompt` is reviewed at timestamp `revtime`
8 8
     with review success `revsucc`
9 9
 ]]
10
-local function schedule(prompt, revtime, revsucc)
10
+local function schedule(prompt, revtime, revsucc, conf)
11 11
     if revsucc and revsucc > 0 then
12 12
         local ad = revtime - prompt.time
13
-        return 2.5 ^ revsucc * (ad + math.max(40000 - 0.5 * ad, 0))
13
+        return (conf:get("DelayRatio") or 2.5) ^ revsucc * (ad + math.max(40000 - 0.5 * ad, 0))
14 14
     else
15 15
         return 15
16 16
     end
... ...
@@ -20,15 +20,15 @@ end
20 20
     manipulates `Prompt` `prompt` in-place as it should be
21 21
     when reviewed at timestamp `revtime` with review success `revsucc`
22 22
 ]]
23
-local function update(prompt, revtime, revsucc)
23
+local function update(prompt, revtime, revsucc, conf)
24 24
     if revsucc and revsucc > 0 then
25 25
         prompt.succ = prompt.succ + 1
26 26
     else
27 27
         prompt.fail = prompt.fail + 1
28 28
     end
29 29
     -- allowed random variation, as a fraction of the "optimal" duration
30
-    local ARV = 0.1
31
-    prompt.delay = schedule(prompt, revtime, revsucc) * ((1 - ARV) + 2 * ARV * math.random())
30
+    local ARV = conf:get("AllowedRandomVariation") or 0.1
31
+    prompt.delay = schedule(prompt, revtime, revsucc, conf) * ((1 - ARV) + 2 * ARV * math.random())
32 32
     prompt.time = revtime
33 33
 end
34 34
 
35 35