riff

package module
v0.0.0-...-b3e8b2b Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: AGPL-3.0 Imports: 14 Imported by: 4

README

Riff

中文

💡 Introduction

Riff is the component of spaced repetition for SiYuan.

✨ Features

  • Algorithm FSRS
  • Data persistence

📄 License

Riff uses the GNU AFFERO GENERAL PUBLIC LICENSE, Version 3 open source license.

🙏 Acknowledgement

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Algo

type Algo string

Algo 描述了闪卡复习算法的名称。

const (
	AlgoFSRS Algo = "fsrs"
	AlgoSM2  Algo = "sm2"
)

type BaseCard

type BaseCard struct {
	CID   string
	BID   string
	NDues map[Rating]time.Time
}

BaseCard 描述了基础的闪卡实现。

func (*BaseCard) BlockID

func (card *BaseCard) BlockID() string

func (*BaseCard) ID

func (card *BaseCard) ID() string

func (*BaseCard) NextDues

func (card *BaseCard) NextDues() map[Rating]time.Time

func (*BaseCard) SetNextDues

func (card *BaseCard) SetNextDues(dues map[Rating]time.Time)

type BaseStore

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

BaseStore 描述了基础的闪卡存储实现。

func NewBaseStore

func NewBaseStore(id string, algo Algo, saveDir string) *BaseStore

func (*BaseStore) Algo

func (store *BaseStore) Algo() Algo

func (*BaseStore) GetSaveDir

func (store *BaseStore) GetSaveDir() string

func (*BaseStore) ID

func (store *BaseStore) ID() string

type Card

type Card interface {
	// ID 返回闪卡 ID。
	ID() string

	// BlockID 返回闪卡关联的内容块 ID。
	BlockID() string

	// NextDues 返回每种评分对应的下次到期时间。
	NextDues() map[Rating]time.Time

	// SetNextDues 设置每种评分对应的下次到期时间。
	SetNextDues(map[Rating]time.Time)

	// SetDue 设置到期时间。
	SetDue(time.Time)

	// GetLapses 返回闪卡的遗忘次数。
	GetLapses() int

	// GetReps 返回闪卡的复习次数。
	GetReps() int

	// GetState 返回闪卡状态。
	GetState() State

	// GetLastReview 返回闪卡的最后复习时间。
	GetLastReview() time.Time

	// Clone 返回闪卡的克隆。
	Clone() Card

	// Impl 返回具体的闪卡实现。
	Impl() interface{}

	// SetImpl 设置具体的闪卡实现。
	SetImpl(c interface{})
}

Card 描述了闪卡。

type Deck

type Deck struct {
	ID      string // ID
	Name    string // 名称
	Algo    Algo   // 间隔重复算法
	Desc    string // 描述
	Created int64  // 创建时间
	Updated int64  // 更新时间
	// contains filtered or unexported fields
}

Deck 描述了一套闪卡包。

func LoadDeck

func LoadDeck(saveDir, id string, requestRetention float64, maximumInterval int, weights string) (deck *Deck, err error)

LoadDeck 从文件夹 saveDir 路径上加载 id 闪卡包。

func (*Deck) AddCard

func (deck *Deck) AddCard(cardID, blockID string)

AddCard 新建一张闪卡。

func (*Deck) CountCards

func (deck *Deck) CountCards() int

CountCards 获取卡包中的闪卡数量。

func (*Deck) Dues

func (deck *Deck) Dues() (ret []Card)

Dues 返回所有到期的闪卡。

func (*Deck) GetBlockIDs

func (deck *Deck) GetBlockIDs() (ret []string)

GetBlockIDs 获取所有内容块 ID。

func (*Deck) GetCard

func (deck *Deck) GetCard(cardID string) Card

GetCard 根据闪卡 ID 获取对应的闪卡。

func (*Deck) GetCardsByBlockID

func (deck *Deck) GetCardsByBlockID(blockID string) (ret []Card)

func (*Deck) GetCardsByBlockIDs

func (deck *Deck) GetCardsByBlockIDs(blockIDs []string) (ret []Card)

GetCardsByBlockIDs 获取指定内容块的所有卡片。

func (*Deck) GetDueCardsByBlockIDs

func (deck *Deck) GetDueCardsByBlockIDs(blockIDs []string) (ret []Card)

func (*Deck) GetNewCardsByBlockIDs

func (deck *Deck) GetNewCardsByBlockIDs(blockIDs []string) (ret []Card)

func (*Deck) RemoveCard

func (deck *Deck) RemoveCard(cardID string)

RemoveCard 删除一张闪卡。

func (*Deck) Review

func (deck *Deck) Review(cardID string, rating Rating) (ret *Log)

Review 复习一张闪卡,rating 为复习评分结果。

func (*Deck) Save

func (deck *Deck) Save() (err error)

Save 保存闪卡包。

func (*Deck) SaveLog

func (deck *Deck) SaveLog(log *Log) (err error)

SaveLog 保存闪卡包的复习日志。

func (*Deck) SetCard

func (deck *Deck) SetCard(card Card)

SetCard 设置一张闪卡。

type FSRSCard

type FSRSCard struct {
	*BaseCard
	C *fsrs.Card
}

func (*FSRSCard) Clone

func (card *FSRSCard) Clone() Card

func (*FSRSCard) GetLapses

func (card *FSRSCard) GetLapses() int

func (*FSRSCard) GetLastReview

func (card *FSRSCard) GetLastReview() time.Time

func (*FSRSCard) GetReps

func (card *FSRSCard) GetReps() int

func (*FSRSCard) GetState

func (card *FSRSCard) GetState() State

func (*FSRSCard) Impl

func (card *FSRSCard) Impl() interface{}

func (*FSRSCard) SetDue

func (card *FSRSCard) SetDue(due time.Time)

func (*FSRSCard) SetImpl

func (card *FSRSCard) SetImpl(c interface{})

type FSRSStore

type FSRSStore struct {
	*BaseStore
	// contains filtered or unexported fields
}

func NewFSRSStore

func NewFSRSStore(id, saveDir string, requestRetention float64, maximumInterval int, weights string) *FSRSStore

func (*FSRSStore) AddCard

func (store *FSRSStore) AddCard(id, blockID string) Card

func (*FSRSStore) CountCards

func (store *FSRSStore) CountCards() int

func (*FSRSStore) Dues

func (store *FSRSStore) Dues() (ret []Card)

func (*FSRSStore) GetBlockIDs

func (store *FSRSStore) GetBlockIDs() (ret []string)

func (*FSRSStore) GetCard

func (store *FSRSStore) GetCard(id string) Card

func (*FSRSStore) GetCardsByBlockID

func (store *FSRSStore) GetCardsByBlockID(blockID string) (ret []Card)

func (*FSRSStore) GetCardsByBlockIDs

func (store *FSRSStore) GetCardsByBlockIDs(blockIDs []string) (ret []Card)

func (*FSRSStore) GetDueCardsByBlockIDs

func (store *FSRSStore) GetDueCardsByBlockIDs(blockIDs []string) (ret []Card)

func (*FSRSStore) GetNewCardsByBlockIDs

func (store *FSRSStore) GetNewCardsByBlockIDs(blockIDs []string) (ret []Card)

func (*FSRSStore) Load

func (store *FSRSStore) Load() (err error)

func (*FSRSStore) RemoveCard

func (store *FSRSStore) RemoveCard(id string) Card

func (*FSRSStore) Review

func (store *FSRSStore) Review(cardId string, rating Rating) (ret *Log)

func (*FSRSStore) Save

func (store *FSRSStore) Save() (err error)

func (*FSRSStore) SaveLog

func (store *FSRSStore) SaveLog(log *Log) (err error)

func (*FSRSStore) SetCard

func (store *FSRSStore) SetCard(card Card)

type Log

type Log struct {
	ID            string
	CardID        string
	Rating        Rating
	ScheduledDays uint64
	ElapsedDays   uint64
	Reviewed      int64
	State         State
}

Log 描述了复习日志记录。

type Rating

type Rating int8

Rating 描述了闪卡复习的评分。

const (
	Again Rating = iota + 1 // 完全不会,必须再复习一遍
	Hard                    // 有点难
	Good                    // 一般
	Easy                    // 很容易
)

type State

type State int8

State 描述了闪卡的状态。

const (
	New State = iota
	Learning
	Review
	Relearning
)

type Store

type Store interface {

	// AddCard 添加一张卡片。
	AddCard(id, blockID string) Card

	// GetCard 获取一张卡片。
	GetCard(id string) Card

	// SetCard 设置一张卡片。
	SetCard(card Card)

	// RemoveCard 移除一张卡片。
	RemoveCard(id string) Card

	// GetCardsByBlockID 获取指定内容块的所有卡片。
	GetCardsByBlockID(blockID string) []Card

	// GetCardsByBlockIDs 获取指定内容块的所有卡片。
	GetCardsByBlockIDs(blockIDs []string) []Card

	// GetNewCardsByBlockIDs 获取指定内容块的所有新的卡片(制卡后没有进行过复习的卡片)。
	GetNewCardsByBlockIDs(blockIDs []string) []Card

	// GetDueCardsByBlockIDs 获取指定内容块的所有到期的卡片。
	GetDueCardsByBlockIDs(blockIDs []string) []Card

	// GetBlockIDs 获取所有内容块 ID。
	GetBlockIDs() []string

	// CountCards 获取卡包中的闪卡数量。
	CountCards() int

	// Review 闪卡复习。
	Review(id string, rating Rating) (ret *Log)

	// Dues 获取所有到期的闪卡列表。
	Dues() []Card

	// ID 获取存储 ID。
	ID() string

	// Algo 返回算法名称,如:fsrs。
	Algo() Algo

	// Load 从持久化存储中加载全部闪卡到内存。
	Load() (err error)

	// Save 将全部闪卡从内存保存到持久化存储中。
	Save() error

	// SaveLog 保存复习日志。
	SaveLog(log *Log) error

	// GetSaveDir 获取数据文件夹路径。
	GetSaveDir() string
}

Store 描述了闪卡存储。

Jump to

Keyboard shortcuts

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