Add `Created` field to card records
John Smith

John Smith commited on 2021-357 12:24:35
Showing 2 changed files, with 10 additions and 4 deletions.


Each record in Memoire's Rec serialisation, representing a card
(set of prompts), may now have a `Created` field -- the timestamp
of the card's creation.
The `Created` value is only read and written for new records
or records that have it, so this should be backwards-compatible.
... ...
@@ -77,7 +77,7 @@ if action == "a" then
77 77
             local nc = {}
78 78
             -- these Prompts will just be converted to Rec, so we don't need to exclude answers from prompt-text
79 79
             for _re in pt:gmatch("%{[^%}]+%}") do
80
-                table.insert(nc, Prompt:new(pt, "", os.time(), 30, 0, 0))
80
+                table.insert(nc, Prompt:new(pt, "", os.time(), 30, 0, 0, os.time()))
81 81
                 prctr = prctr + 1
82 82
             end
83 83
             table.insert(deck, nc)
... ...
@@ -1,7 +1,8 @@
1 1
 --[[
2 2
     a prompt consists of prompt text (with an answer-insertion point),
3 3
     a correct answer, the review timestamp, the review delay,
4
-    and counts of successful and failde reviews
4
+    counts of successful and failed reviews,
5
+    and a creation timestamp
5 6
 
6 7
     timestamps are seconds from the Unix epoch
7 8
     review delay is in seconds
... ...
@@ -13,7 +14,7 @@ Prompt.__index = Prompt
13 14
 --[[
14 15
     the answer-insertion point is indicated with a "%A" in the prompt text
15 16
 ]]
16
-function Prompt:new(pt, ca, rts, rd, sc, fc)
17
+function Prompt:new(pt, ca, rts, rd, sc, fc, ct)
17 18
     local o = {}
18 19
     setmetatable(o, self)
19 20
     o.text = pt
... ...
@@ -22,6 +23,7 @@ function Prompt:new(pt, ca, rts, rd, sc, fc)
22 23
     o.delay = tonumber(rd)
23 24
     o.succ = sc
24 25
     o.fail = fc
26
+    o.created = ct
25 27
     return o
26 28
 end
27 29
 
... ...
@@ -57,7 +59,8 @@ function Prompt:fromrecs(recs)
57 59
                     (rec.LastReview or {})[ctr],
58 60
                     (rec.LastDelay or {})[ctr],
59 61
                     (rec.Successes or {})[ctr],
60
-                    (rec.Failures or {})[ctr]
62
+                    (rec.Failures or {})[ctr],
63
+                    (rec.Created or {})[1]
61 64
                 ))
62 65
                 m, n = opt:find("%{[^%}]+%}", n)
63 66
                 ctr = ctr + 1
... ...
@@ -75,6 +78,9 @@ end
75 78
 function Prompt:torec(prompts)
76 79
     local fspt = prompts[1]:spt()
77 80
     local ret = { PromptText = { fspt }, LastReview = {}, LastDelay = {}, Successes = {}, Failures = {} }
81
+    if prompts[1].created then
82
+        ret.Created = { propmts[1].created }
83
+    end
78 84
     for i, pr in ipairs(prompts) do
79 85
         if pr:spt() ~= fspt then
80 86
             -- not from the same `PromptText`
81 87