Basic spaced repetition with code generation.
This commit is contained in:
6
projects/kiss-spaced-rep/src/kiss_spaced_rep/Card.hx
Normal file
6
projects/kiss-spaced-rep/src/kiss_spaced_rep/Card.hx
Normal file
@@ -0,0 +1,6 @@
|
||||
package kiss_spaced_rep;
|
||||
|
||||
typedef Card = {
|
||||
front: String,
|
||||
back: String
|
||||
};
|
||||
7
projects/kiss-spaced-rep/src/kiss_spaced_rep/Main.hx
Normal file
7
projects/kiss-spaced-rep/src/kiss_spaced_rep/Main.hx
Normal file
@@ -0,0 +1,7 @@
|
||||
package kiss_spaced_rep;
|
||||
|
||||
class Main {
|
||||
static function main() {
|
||||
Main_.main();
|
||||
}
|
||||
}
|
||||
51
projects/kiss-spaced-rep/src/kiss_spaced_rep/Main_.kiss
Normal file
51
projects/kiss-spaced-rep/src/kiss_spaced_rep/Main_.kiss
Normal file
@@ -0,0 +1,51 @@
|
||||
(import
|
||||
datetime.DateTime
|
||||
datetime.DateTimeInterval)
|
||||
|
||||
(var oneDayInterval (DateTimeInterval.create (DateTime.make 1970 1 1) (DateTime.make 1970 1 2)))
|
||||
|
||||
(defMacroVar cardId 0)
|
||||
|
||||
(defMacro card [front back &builder b]
|
||||
(let [cObject (b.symbol "cObject$cardId")
|
||||
cScore (b.symbol "cScore$cardId")
|
||||
cRepetitions (b.symbol "cRepetitions$cardId")
|
||||
cPreviousEaseFactor (b.symbol "cPreviousEaseFactor$cardId")
|
||||
cPreviousInterval (b.symbol "cPreviousInterval$cardId")
|
||||
cNextDate (b.symbol "cNextDate$cardId")]
|
||||
(setMacroVar cardId (+ cardId 1))
|
||||
`{
|
||||
(var ,cObject (object front ,front back ,back))
|
||||
(savedVar :Int ,cRepetitions 0)
|
||||
(savedVar :Float ,cPreviousEaseFactor 2.5)
|
||||
(savedVar :Int ,cPreviousInterval 0)
|
||||
(savedVar :Float ,cNextDate (DateTime.make))
|
||||
|
||||
(function :Void ,cScore [:Int quality]
|
||||
(localVar &mut interval 0)
|
||||
(cond
|
||||
((>= quality 3)
|
||||
(set interval (Math.ceil (case ,cRepetitions (0 1) (1 6) (more (* ,cPreviousEaseFactor ,cPreviousInterval)) (never otherwise))))
|
||||
(+= ,cRepetitions 1)
|
||||
(set ,cPreviousEaseFactor (+ ,cPreviousEaseFactor (- 0.1 (* (- 5 quality) (+ 0.08 (* (- 5 quality ) 0.02)))))))
|
||||
(true
|
||||
(set ,cRepetitions 0)
|
||||
(set interval 1)))
|
||||
(set ,cPreviousEaseFactor (max 1.3 ,cPreviousEaseFactor))
|
||||
(set ,cPreviousInterval interval)
|
||||
(doFor _ (range interval)
|
||||
(set ,cNextDate #{DateTime.now() + oneDayInterval;}#))
|
||||
(print interval))
|
||||
|
||||
(let [:DateTime nextDate ,cNextDate]
|
||||
(if #{DateTime.now() > nextDate;}#
|
||||
{
|
||||
(print .front ,cObject)
|
||||
(.readLine (Sys.stdin))
|
||||
(print .back ,cObject)
|
||||
(,cScore (Std.parseInt (.readLine (Sys.stdin))))
|
||||
}
|
||||
(print "skipping a card until $(nextDate.toString)")))
|
||||
}))
|
||||
|
||||
(card "dog" "chien")
|
||||
Reference in New Issue
Block a user