DKL9 GitList
Repositories
DKL9 home
memoire
Code
Commits
Branches
Tags
Search
Tree:
10b7415
Branches
Tags
master
memoire
src
prompt.lua
Remove braces in Prompt:text() for bmc
John Smith
commited
10b7415
at 2023-177 12:43:56
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") 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) else return "error: unrecognised card type " .. self.card.ct end end function Prompt:retention() return self.succ / (self.succ + self.fail) end return Prompt