John Smith commited on 2021-355 22:57:54
Showing 1 changed files, with 26 additions and 10 deletions.
Whenever a review session starts, the user is prompted for a number of prompts to review, which limits the scale of the review.
| ... | ... |
@@ -86,12 +86,28 @@ elseif action == "h" then |
| 86 | 86 |
elseif action == "r" then |
| 87 | 87 |
local deck = loader.load(deckfname) |
| 88 | 88 |
if deck then |
| 89 |
- local cardcount = 0 |
|
| 90 |
- local start = os.time() |
|
| 91 |
- -- review each card that needs it |
|
| 89 |
+ -- collect list of index-pairs for prompts to be reviewed this session |
|
| 90 |
+ local ctrt = {}
|
|
| 92 | 91 |
for i, cg in ipairs(deck) do |
| 93 | 92 |
for j, pr in ipairs(cg) do |
| 94 | 93 |
if review.should(pr) then |
| 94 |
+ table.insert(ctrt, { i, j })
|
|
| 95 |
+ end |
|
| 96 |
+ end |
|
| 97 |
+ end |
|
| 98 |
+ io.write(string.format( |
|
| 99 |
+ "%d prompts are ready for review.\nHow many to review in this session? ", #ctrt |
|
| 100 |
+ )) |
|
| 101 |
+ local climt = io.read("l")
|
|
| 102 |
+ local climn = tonumber(climt) |
|
| 103 |
+ if climn then |
|
| 104 |
+ local start = os.time() |
|
| 105 |
+ -- review propmts in this session's set |
|
| 106 |
+ for ind, ip in ipairs(ctrt) do |
|
| 107 |
+ if ind > climn then |
|
| 108 |
+ break |
|
| 109 |
+ end |
|
| 110 |
+ local pr = deck[ip[1]][ip[2]] |
|
| 95 | 111 |
-- remove braces for display |
| 96 | 112 |
local pst = pr.text:gsub("%{([^{}]+)%}", "%1")
|
| 97 | 113 |
local st = os.time() |
| ... | ... |
@@ -105,25 +121,25 @@ elseif action == "r" then |
| 105 | 121 |
pst:gsub("%%A", pr.ans)
|
| 106 | 122 |
)) |
| 107 | 123 |
local resp = io.read("l")
|
| 108 |
- review.update(pr, st, isyes(resp)) |
|
| 109 |
- cardcount = cardcount + 1 |
|
| 124 |
+ review.update(deck[ip[1]][ip[2]], st, isyes(resp)) |
|
| 110 | 125 |
clear() |
| 111 | 126 |
end |
| 112 |
- end |
|
| 113 |
- end |
|
| 114 | 127 |
local endt = os.time() |
| 115 | 128 |
io.write(string.format( |
| 116 | 129 |
"Reviewed %d prompts in %d seconds\n", |
| 117 |
- cardcount, |
|
| 130 |
+ math.min(#ctrt, climn), |
|
| 118 | 131 |
endt - start |
| 119 | 132 |
)) |
| 120 |
- if cardcount > 0 then |
|
| 133 |
+ if #ctrt > 0 then |
|
| 121 | 134 |
io.write(string.format( |
| 122 | 135 |
"(%f seconds per card)\n", |
| 123 |
- (endt - start) / cardcount |
|
| 136 |
+ (endt - start) / math.min(#ctrt, climn) |
|
| 124 | 137 |
)) |
| 125 | 138 |
loader.save(deckfname, deck) |
| 126 | 139 |
end |
| 140 |
+ else |
|
| 141 |
+ io.write("Input not a number -- aborting\n")
|
|
| 142 |
+ end |
|
| 127 | 143 |
else |
| 128 | 144 |
io.write("Failed to load deck\n")
|
| 129 | 145 |
end |
| 130 | 146 |