List most common contexts in statistics
John Smith

John Smith commited on 2023-42 13:54:10
Showing 1 changed files, with 14 additions and 0 deletions.


The "s" option now includes in output the first few items of
a frequency-sorted list of card contexts (text before the first colon
in card text), including the number of cards in the deck
with each such context.
... ...
@@ -414,6 +414,20 @@ local actions = {
414 414
             io.write("\nReview counts\n" .. histogram(expdeck, 0, 20, 2, function(pr) return pr.succ + pr.fail end, 0.03))
415 415
             io.write("\nLog2-age (seconds)\n" .. histogram(expdeck, 18, 28, 0.5, function(pr) return math.log(os.time() - (pr.created or 2 * os.time()), 2) end, 0.05))
416 416
             io.write("\nPrompt-count\n" .. histogram(deck, 1, 10, 1, function(card) return #card end, 0.03))
417
+            local cpcs = {}
418
+            for _, card in ipairs(deck) do
419
+                local cp = card[1].text:match("([^:]+):") or ""
420
+                cpcs[cp] = (cpcs[cp] or 0) + 1
421
+            end
422
+            local scl = {}
423
+            for l, c in pairs(cpcs) do
424
+                table.insert(scl, { l = l, c = c })
425
+            end
426
+            table.sort(scl, function(a, b) return a.c > b.c end)
427
+            for k, lc in ipairs(scl) do
428
+                scl[k] = string.format("%s (%d)", lc.l ~= "" and lc.l or "(none)", lc.c)
429
+            end
430
+            io.write("\nMost common contexts: " .. table.concat(scl, ", ", 1, math.min(20, #scl)) .. "\n")
417 431
             table.sort(expdeck, function(a, b) return a.time + a.delay < b.time + b.delay end)
418 432
             io.write("\nUpcoming due prompts wrt days from now:\n")
419 433
             local ppi = 1
420 434