flashcard

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDeckNotFound = errors.New("deck not found")
View Source
var ErrEmptyReview = errors.New("no cards in queue")

ErrEmptyReview indicates the review session has not more cards left to review.

View Source
var ErrInvalidScore = errors.New("invalid score")

ErrInvalidScore is returned by NewReviewScore when the given string is not a number of is out of the valid range.

Functions

This section is empty.

Types

type Card

type Card struct {
	ID             string    `json:"id" validate:"required"`
	Question       string    `json:"question" validate:"required"`
	Answer         string    `json:"answer" validate:"required"`
	ReviewedAt     time.Time `json:"reviewed_at" validate:"required"`
	EasinessFactor float64   `json:"easiness_factor" validate:"required"`
	Interval       float64   `json:"interval" validate:"required"`
	Repetitions    int       `json:"repetitions" validate:"required"`
	Stats          []Stats   `json:"stats"`
}

Card represents a single card in a Deck.

func NewCard

func NewCard(question, answer string, today time.Time, options ...cardOption) Card

NewCard create a new Card instance.

func (Card) Advance

func (c Card) Advance(ts time.Time, score ReviewScore) Card

Advance advances supermemo state for a card.

func (Card) IsDue

func (c Card) IsDue(t time.Time) bool

IsDue reports whether the card is due at the instant t.

func (Card) NextReviewAt

func (c Card) NextReviewAt() time.Time

NextReviewAt returns next review timestamp for a card.

type Deck

type Deck struct {
	Name  string `json:"name" validate:"required"`
	Cards []Card `json:"cards"`

	ID string
	// contains filtered or unexported fields
}

Deck represents a named collection of cards.

func NewDeck

func NewDeck(name string, clock clock.Clock, cards []Card) (deck Deck, err error)

NewDeck creates a new deck.

func (Deck) Add

func (d Deck) Add(question, answer string) (Deck, Card)

Add adds a new card to the deck.

func (Deck) Change

func (d Deck) Change(updated Card) Deck

Change updates a card in the deck.

func (Deck) DueCards

func (d Deck) DueCards() []Card

DueCards returns a collection of cards that needs review.

func (Deck) HasDueCards

func (d Deck) HasDueCards() bool

HasDueCards says if the deck has due cards.

func (Deck) List

func (d Deck) List() []Card

List returns a collection of cards order by the time of the last review and question.

func (Deck) Remove

func (d Deck) Remove(card Card) Deck

Remove excludes card from the deck.

func (Deck) Total

func (d Deck) Total() int

Total returns number of cards in the deck.

type Repository

type Repository struct {
	// contains filtered or unexported fields
}

Repository defines storage interface that manages a set of decks.

func NewRepository

func NewRepository(path string, clock clock.Clock) (*Repository, error)

NewRepository create a new deck repository by reading all decks from a given folder.

func (*Repository) Create

func (r *Repository) Create(name string, cards []Card) (Deck, error)

Create creates a new deck from a given name.

func (*Repository) Delete

func (r *Repository) Delete(deck Deck) error

Delete removes the deck from the repository.

func (*Repository) Find

func (r *Repository) Find(name string) (Deck, error)

Find searches deck by name.

func (*Repository) List

func (r *Repository) List() []Deck

List returns the available deck names.

func (*Repository) Save

func (r *Repository) Save(deck Deck) error

Save writes changes to disk.

func (*Repository) Total

func (r *Repository) Total() int

Total returns the number of decks.

type Review

type Review struct {
	Deck Deck

	Completed int
	// contains filtered or unexported fields
}

Review represents a review session.

func NewReview

func NewReview(deck Deck, clock clock.Clock) Review

NewReview returns a new Review from a given a deck. It gets the due cards from the deck a shuffle them.

func (Review) Card

func (r Review) Card() (Card, error)

Card returns the card being reviewed.

func (Review) Current

func (r Review) Current() int

Current returns the number of cards already reviewed.

func (Review) Left

func (r Review) Left() int

Left returns the number of cards left to review.

func (Review) Rate

func (r Review) Rate(score ReviewScore) (Review, error)

Rate scores the current card.

func (Review) Skip

func (r Review) Skip() (Review, error)

Skip moves the current card to the end of the queue.

func (Review) Total

func (r Review) Total() int

Total returns the number of cards in the review session.

type ReviewScore

type ReviewScore int

ReviewScore defines grade for review attempts. Review uses scores to calculate rating in range from [0, 4] inclusive.

const (
	ReviewScoreAgain ReviewScore = iota
	ReviewScoreHard
	ReviewScoreNormal
	ReviewScoreEasy
	ReviewScoreSuperEasy

	// InitialEasinessFactor defines the initial easiness factor.
	InitialEasinessFactor = 2.5
	// MinEasinessFactor defines the minimal easiness factor possible.
	MinEasinessFactor = 1.3
)

func NewReviewScore

func NewReviewScore(s string) (ReviewScore, error)

NewReviewScore converts a string to a ReviewScore.

func (ReviewScore) String

func (s ReviewScore) String() string

type Stats

type Stats struct {
	Algorithm      string      `json:"algorithm" validate:"required"`
	Timestamp      time.Time   `json:"timestamp" validate:"required"`
	Score          ReviewScore `json:"score" validate:"required"`
	LastReview     time.Time   `json:"last_review" validate:"required"`
	Repetitions    int         `json:"repetitions" validate:"required"`
	Interval       float64     `json:"interval" validate:"required"`
	EasinessFactor float64     `json:"easiness_factor" validate:"required"`
}

Stats is the revised card statistics.

func NewStats

func NewStats(ts time.Time, score ReviewScore, previous Card) Stats

Jump to

Keyboard shortcuts

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