Improve prompt prioritisation for review
John Smith

John Smith commited on 2023-89 19:00:39
Showing 2 changed files, with 21 additions and 5 deletions.


When the review procedure sorts prompts for review, it now considers
the text of the prompt, and for each PriorityText entry in the config,
the prompt will be made more important by a number (possibly negative)
given in a corresponding PriorityBias entry. 0.1 is a reasonable value.
... ...
@@ -290,7 +290,7 @@ local actions = {
290 290
                 return nil
291 291
             end
292 292
             -- collect list of index-pairs for prompts to be reviewed this session
293
-            local ctrt = review.list(deck)
293
+            local ctrt = review.list(deck, config)
294 294
             io.write(string.format(
295 295
                 "%d prompts are ready for review.\nHow many to review in this session? ", #ctrt
296 296
             ))
... ...
@@ -40,15 +40,31 @@ local function update(prompt, revtime, revsucc, conf)
40 40
     prompt.time = revtime
41 41
 end
42 42
 
43
+--[[
44
+    rates the importance of `Prompt` `prompt` as an additive bias
45
+    based on the rules given in `conf`
46
+]]
47
+local function importance(prompt, conf)
48
+    pt = conf["PriorityText"] or {}
49
+    pb = conf["PriorityBias"] or {}
50
+    s = 0
51
+    for i, t in ipairs(pt) do
52
+        if prompt:spt():find(t) then
53
+            s = s + pb[i]
54
+        end
55
+    end
56
+    return s
57
+end
58
+
43 59
 --[[
44 60
     checks if `Prompt` `prompt` should be reviewed now,
45 61
     returning `false` if not and a number to indicate urgency if it should
46 62
 ]]
47
-local function should(prompt)
63
+local function should(prompt, conf)
48 64
     local ct = os.time()
49 65
     if not prompt.delay then return -1 end
50 66
     if prompt.delay >= 0 and ct - (prompt.time or 0) >= (prompt.delay or 0) then
51
-        return (ct - (prompt.time or 0)) / prompt.delay / prompt.ease / (prompt.succ + 1) + 0.2 * math.random()
67
+        return (ct - (prompt.time or 0)) / prompt.delay / prompt.ease / (prompt.succ + 1) + importance(prompt, conf) + 0.1 * math.random()
52 68
     end
53 69
     return false
54 70
 end
... ...
@@ -64,12 +80,12 @@ end
64 80
     if a filter function is provided, filters the list accordingly,
65 81
     calling the filter function on each `Prompt`
66 82
 ]]
67
-local function toreviewlist(deck, filter)
83
+local function toreviewlist(deck, conf, filter)
68 84
     local ctrt = {}
69 85
     local ff = filter or alwaystrue
70 86
     for i, cg in ipairs(deck) do
71 87
         for j, pr in ipairs(cg) do
72
-            local sc = should(pr)
88
+            local sc = should(pr, conf)
73 89
             if sc and ff(pr) then
74 90
                 table.insert(ctrt, { i, j, sc or 0 })
75 91
             end
76 92