srs

package module
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 19, 2023 License: MIT Imports: 4 Imported by: 0

README

go-srs

Go Reference test Go Report Card

go-srs provides libraries to build spaced repetition learning capable programs and servers.

It currently provides:

Use

First, instantiate the srs struct with the provided algorithm, uid and db implementations:

// Algo
now := time.Now().UTC()
sm2 := sm2.New(now)

// Db
opts := badger.DefaultOptions("./badger")
opts.Logger = nil
bad, err := badger.Open(opts)
defer bad.Close()
db := bdg.New(bad, sm2)

// uid
entropy := ulidPkg.Monotonic(crand.Reader, 0)
uid := ulid.New(entropy)

// instantiate srs struct
hdl := srs.New(db, uid)

After that, you can update and save card reviews of a given deck:

r = review.Review{}
r.DeckId = "somedeckid"

r.Items = []review.ReviewItem{
    {CardId: 65, Quality: 1},
    {CardId: 3, Quality: 5},
    {CardId: 1, Quality: 0},
}

_, err = hdl.Update(r)
if err != nil {
    fatal(err)
}

And retrieve cards that are due for review

tdue := time.Now().UTC()
dueCards, _ := hdl.Due(res.DeckId, tdue)

See srs_test.go for more examples.

Additional implementations

go-srs provides interfaces for db, algorithm and unique id implementations.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Srs

type Srs struct {
	Db  db.Handler
	UID uid.UID
}

Srs encapsulates the db handler and the UID generator.

Deck and card ids are provided by this package

func New

func New(db db.Handler, id uid.UID) *Srs

func (*Srs) Due

func (h *Srs) Due(deckId string, t time.Time) (due review.Due, err error)

Due returns all card ids that are due to be reviewed at time t

func (*Srs) Update

func (h *Srs) Update(r review.Review) (due review.Due, err error)

Update update the cards in Review, persist then in th db and returns the updated Cards due time.

Directories

Path Synopsis
sm2
Package sm2 is an implementation of the supermemo algorithm.
Package sm2 is an implementation of the supermemo algorithm.
db
badger
Package badger implements the srs/db.Handler interface with a badger backend
Package badger implements the srs/db.Handler interface with a badger backend
uid

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL