Control and bias review order
John Smith

John Smith commited on 2022-275 22:46:50
Showing 1 changed files, with 16 additions and 15 deletions.


The list of prompts for review is now sorted to include
the most overdue prompts at the start, then gently shuffled,
so as to leave everything near, but not necessarily at,
its original location.
... ...
@@ -44,25 +44,23 @@ end
44 44
     checks (returns boolean) if `Prompt` `prompt` should be reviewed now
45 45
 ]]
46 46
 local function should(prompt)
47
-    return os.time() - (prompt.time or 0) >= (prompt.delay or 0) and prompt.delay >= 0
47
+    local ct = os.time()
48
+    return prompt.delay >= 0 and ct - (prompt.time or 0) >= (prompt.delay or 0) and (ct - (prompt.time or 0)) / prompt.delay
48 49
 end
49 50
 
50 51
 --[[
51
-    returns a shuffled version of the table,
52
-    destroying the table in-place
53
-    adapted from
54
-    https://stackoverflow.com/q/55192727
52
+    shuffles a table in-place,
53
+    intentionally biased to keep the list
54
+    in a roughly-similar order to how it was originally
55 55
 ]]
56
-local function shuffle(t)
57
-    local ret = {}
58
-    local ci = 1
59
-    while #t > 0 do
60
-        local ri = math.random(1, #t)
61
-        ret[ci] = t[ri]
62
-        table.remove(t, ri)
63
-        ci = ci + 1
56
+local function biasedshuffle(t)
57
+    for i = 1, (#t-1) do
58
+        if math.random() < 0.5 then
59
+            local s = t[i]
60
+            t[i] = t[i + 1]
61
+            t[i + 1] = s
62
+        end
64 63
     end
65
-    return ret
66 64
 end
67 65
 
68 66
 local function alwaystrue(x)
... ...
@@ -86,7 +84,10 @@ local function toreviewlist(deck, filter)
86 84
             end
87 85
         end
88 86
     end
89
-    ctrt = shuffle(ctrt)
87
+    table.sort(ctrt, function(a, b)
88
+        return should(deck[a[1]][a[2]]) > should(deck[b[1]][b[2]])
89
+    end)
90
+    biasedshuffle(ctrt)
90 91
     return ctrt
91 92
 end
92 93
 
93 94