DKL9 GitList
Repositories
DKL9 home
memoire
Code
Commits
Branches
Tags
Search
Tree:
44e11a9
Branches
Tags
master
memoire
src
prompt.lua
Add "seq" card type
John Smith
commited
44e11a9
at 2023-179 17:42:36
prompt.lua
Blame
History
Raw
--[[ a prompt consists of a parent card, an index into the note, the review timestamp, the review delay, counts of successful and failed reviews, and an ease measurement timestamps are seconds from the Unix epoch review delay is in seconds ]] local Prompt = {} Prompt.__index = Prompt function Prompt:new(prtable) local o = { card = {}, ind = 0, time = os.time(), delay = 30, succ = 0, fail = 0, ease = 2.5 } setmetatable(o, self) for k, v in pairs(prtable) do if o[k] then o[k] = v end end return o end function Prompt:__tostring() return string.format( "\"%s\" (\"%s\") %d -> %d+%d*%f %d/%d", self:text(), self:ans(), self.card.created or 0, self.time, math.floor(self.delay), self.ease, self.succ, self.fail ) end --[[ the answer-insertion point is indicated with a "%A" in the prompt text ]] function Prompt:text() if self.ind == 0 then return "error: unpopulated ind" end if self.card.ct == "bmc" then local _, eoa = self.card.note:find("{[^}]+}", self.ind) return (self.card.note:sub(1, self.ind - 1) .. "%A" .. self.card.note:sub(eoa + 1)):gsub("{([^}]+)}", "%1") elseif self.card.ct == "seq" then return (self.card.note:sub(1, self.ind - 1) .. "%A"):gsub(";;", "") else return "error: unrecognised card type " .. self.card.ct end end function Prompt:ans() if self.ind == 0 then return "error: unpopulated ind" end if self.card.ct == "bmc" then return self.card.note:match("{([^}]+)}", self.ind) elseif self.card.ct == "seq" then local m = self.card.note:match("[^;]+;;", self.ind) if not m then m = self.card.note:sub(self.ind) end return m:gsub(";;", "") else return "error: unrecognised card type " .. self.card.ct end end function Prompt:retention() return self.succ / (self.succ + self.fail) end return Prompt