mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 14:40:12 +01:00
🎨 Improve FSRS weight initialization https://github.com/siyuan-note/siyuan/issues/16181
Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
parent
426be24f54
commit
ddfc1cbd66
4 changed files with 46 additions and 15 deletions
|
|
@ -41,14 +41,6 @@ type Flashcard struct {
|
||||||
|
|
||||||
func NewFlashcard() *Flashcard {
|
func NewFlashcard() *Flashcard {
|
||||||
param := fsrs.DefaultParam()
|
param := fsrs.DefaultParam()
|
||||||
weightsBuilder := bytes.Buffer{}
|
|
||||||
for i, w := range param.W {
|
|
||||||
weightsBuilder.WriteString(fmt.Sprintf("%.2f", w))
|
|
||||||
if i < len(param.W)-1 {
|
|
||||||
weightsBuilder.WriteString(", ")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return &Flashcard{
|
return &Flashcard{
|
||||||
NewCardLimit: 20,
|
NewCardLimit: 20,
|
||||||
ReviewCardLimit: 200,
|
ReviewCardLimit: 200,
|
||||||
|
|
@ -60,6 +52,18 @@ func NewFlashcard() *Flashcard {
|
||||||
ReviewMode: 0,
|
ReviewMode: 0,
|
||||||
RequestRetention: param.RequestRetention,
|
RequestRetention: param.RequestRetention,
|
||||||
MaximumInterval: int(param.MaximumInterval),
|
MaximumInterval: int(param.MaximumInterval),
|
||||||
Weights: weightsBuilder.String(),
|
Weights: DefaultFSRSWeights(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DefaultFSRSWeights() string {
|
||||||
|
buf := bytes.Buffer{}
|
||||||
|
defaultWs := fsrs.DefaultWeights()
|
||||||
|
for i, w := range defaultWs {
|
||||||
|
buf.WriteString(fmt.Sprintf("%v", w))
|
||||||
|
if i < len(defaultWs)-1 {
|
||||||
|
buf.WriteString(", ")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return buf.String()
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ require (
|
||||||
github.com/siyuan-note/filelock v0.0.0-20251010020544-2603449ff16d
|
github.com/siyuan-note/filelock v0.0.0-20251010020544-2603449ff16d
|
||||||
github.com/siyuan-note/httpclient v0.0.0-20251016024153-048ea2b2ebfd
|
github.com/siyuan-note/httpclient v0.0.0-20251016024153-048ea2b2ebfd
|
||||||
github.com/siyuan-note/logging v0.0.0-20250425042449-b96c40249b54
|
github.com/siyuan-note/logging v0.0.0-20250425042449-b96c40249b54
|
||||||
github.com/siyuan-note/riff v0.0.0-20250424035337-0a1e91809f6d
|
github.com/siyuan-note/riff v0.0.0-20251022131846-228528e70754
|
||||||
github.com/spf13/cast v1.10.0
|
github.com/spf13/cast v1.10.0
|
||||||
github.com/steambap/captcha v1.4.1
|
github.com/steambap/captcha v1.4.1
|
||||||
github.com/studio-b12/gowebdav v0.11.0
|
github.com/studio-b12/gowebdav v0.11.0
|
||||||
|
|
@ -145,7 +145,7 @@ require (
|
||||||
github.com/jaytaylor/html2text v0.0.0-20230321000545-74c2419ad056 // indirect
|
github.com/jaytaylor/html2text v0.0.0-20230321000545-74c2419ad056 // indirect
|
||||||
github.com/jolestar/go-commons-pool/v2 v2.1.2 // indirect
|
github.com/jolestar/go-commons-pool/v2 v2.1.2 // indirect
|
||||||
github.com/juju/errors v1.0.0 // indirect
|
github.com/juju/errors v1.0.0 // indirect
|
||||||
github.com/klauspost/compress v1.18.0 // indirect
|
github.com/klauspost/compress v1.18.1 // indirect
|
||||||
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
|
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
|
||||||
github.com/leodido/go-urn v1.4.0 // indirect
|
github.com/leodido/go-urn v1.4.0 // indirect
|
||||||
github.com/levigross/exp-html v0.0.0-20120902181939-8df60c69a8f5 // indirect
|
github.com/levigross/exp-html v0.0.0-20120902181939-8df60c69a8f5 // indirect
|
||||||
|
|
|
||||||
|
|
@ -258,8 +258,8 @@ github.com/juju/errors v1.0.0/go.mod h1:B5x9thDqx0wIMH3+aLIMP9HjItInYWObRovoCFM5
|
||||||
github.com/juju/loggo v0.0.0-20190526231331-6e530bcce5d8/go.mod h1:vgyd7OREkbtVEN/8IXZe5Ooef3LQePvuBm9UWj6ZL8U=
|
github.com/juju/loggo v0.0.0-20190526231331-6e530bcce5d8/go.mod h1:vgyd7OREkbtVEN/8IXZe5Ooef3LQePvuBm9UWj6ZL8U=
|
||||||
github.com/juju/testing v0.0.0-20191001232224-ce9dec17d28b/go.mod h1:63prj8cnj0tU0S9OHjGJn+b1h0ZghCndfnbQolrYTwA=
|
github.com/juju/testing v0.0.0-20191001232224-ce9dec17d28b/go.mod h1:63prj8cnj0tU0S9OHjGJn+b1h0ZghCndfnbQolrYTwA=
|
||||||
github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
|
github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
|
||||||
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
|
github.com/klauspost/compress v1.18.1 h1:bcSGx7UbpBqMChDtsF28Lw6v/G94LPrrbMbdC3JH2co=
|
||||||
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
|
github.com/klauspost/compress v1.18.1/go.mod h1:ZQFFVG+MdnR0P+l6wpXgIL4NTtwiKIdBnrBd8Nrxr+0=
|
||||||
github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
|
github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
|
||||||
github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y=
|
github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y=
|
||||||
github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
|
github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
|
||||||
|
|
@ -386,8 +386,8 @@ github.com/siyuan-note/httpclient v0.0.0-20251016024153-048ea2b2ebfd h1:g67edlPa
|
||||||
github.com/siyuan-note/httpclient v0.0.0-20251016024153-048ea2b2ebfd/go.mod h1:xbFmjardDUhZL5+nKVwIr3dEbyhXC2eK3bbSYVR1GRE=
|
github.com/siyuan-note/httpclient v0.0.0-20251016024153-048ea2b2ebfd/go.mod h1:xbFmjardDUhZL5+nKVwIr3dEbyhXC2eK3bbSYVR1GRE=
|
||||||
github.com/siyuan-note/logging v0.0.0-20250425042449-b96c40249b54 h1:bNfLBxasCNYNIiE8YwIDDq0DxFjQ3aDbp25w8F5aShM=
|
github.com/siyuan-note/logging v0.0.0-20250425042449-b96c40249b54 h1:bNfLBxasCNYNIiE8YwIDDq0DxFjQ3aDbp25w8F5aShM=
|
||||||
github.com/siyuan-note/logging v0.0.0-20250425042449-b96c40249b54/go.mod h1:9lb3q2RCdpjoQk7nDQwLSArNtCLafHwWtl8+kNkSISM=
|
github.com/siyuan-note/logging v0.0.0-20250425042449-b96c40249b54/go.mod h1:9lb3q2RCdpjoQk7nDQwLSArNtCLafHwWtl8+kNkSISM=
|
||||||
github.com/siyuan-note/riff v0.0.0-20250424035337-0a1e91809f6d h1:VJ/DuLIx4FE7MZtlX2Gahx2m9tr4YCXPxZxUXZIWRx4=
|
github.com/siyuan-note/riff v0.0.0-20251022131846-228528e70754 h1:6QYpy7s5HlRSge09TyM/mT0vz1RDcWYZdkxEh7hmbH4=
|
||||||
github.com/siyuan-note/riff v0.0.0-20250424035337-0a1e91809f6d/go.mod h1:oz+GggNPu23prmW5/8aqpu9Zs5eQBgN+YQJzFLxbT4g=
|
github.com/siyuan-note/riff v0.0.0-20251022131846-228528e70754/go.mod h1:/N7+N2CsZ0nleNPpP3b+06Bzqvuhy6GUmLY7Kug/zT0=
|
||||||
github.com/spf13/cast v1.10.0 h1:h2x0u2shc1QuLHfxi+cTJvs30+ZAHOGRic8uyGTDWxY=
|
github.com/spf13/cast v1.10.0 h1:h2x0u2shc1QuLHfxi+cTJvs30+ZAHOGRic8uyGTDWxY=
|
||||||
github.com/spf13/cast v1.10.0/go.mod h1:jNfB8QC9IA6ZuY2ZjDp0KtFO2LZZlg4S/7bzP6qqeHo=
|
github.com/spf13/cast v1.10.0/go.mod h1:jNfB8QC9IA6ZuY2ZjDp0KtFO2LZZlg4S/7bzP6qqeHo=
|
||||||
github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf h1:pvbZ0lM0XWPBqUKqFU8cmavspvIl9nulOYwdy6IFRRo=
|
github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf h1:pvbZ0lM0XWPBqUKqFU8cmavspvIl9nulOYwdy6IFRRo=
|
||||||
|
|
|
||||||
|
|
@ -458,6 +458,33 @@ func InitConf() {
|
||||||
if "" == Conf.Flashcard.Weights {
|
if "" == Conf.Flashcard.Weights {
|
||||||
Conf.Flashcard.Weights = conf.NewFlashcard().Weights
|
Conf.Flashcard.Weights = conf.NewFlashcard().Weights
|
||||||
}
|
}
|
||||||
|
if 19 != len(strings.Split(Conf.Flashcard.Weights, ",")) {
|
||||||
|
defaultWeights := conf.DefaultFSRSWeights()
|
||||||
|
msg := "fsrs store weights length must be [19]"
|
||||||
|
logging.LogWarnf("%s , given [%s], reset to default weights [%s]", msg, Conf.Flashcard.Weights, defaultWeights)
|
||||||
|
Conf.Flashcard.Weights = defaultWeights
|
||||||
|
go func() {
|
||||||
|
util.WaitForUILoaded()
|
||||||
|
task.AppendAsyncTaskWithDelay(task.PushMsg, 2*time.Second, util.PushErrMsg, msg, 15000)
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
isInvalidFlashcardWeights := false
|
||||||
|
for _, w := range strings.Split(Conf.Flashcard.Weights, ",") {
|
||||||
|
if _, err := strconv.ParseFloat(strings.TrimSpace(w), 64); err != nil {
|
||||||
|
isInvalidFlashcardWeights = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if isInvalidFlashcardWeights {
|
||||||
|
defaultWeights := conf.DefaultFSRSWeights()
|
||||||
|
msg := "fsrs store weights contain invalid number"
|
||||||
|
logging.LogWarnf("%s, given [%s], reset to default weights [%s]", msg, Conf.Flashcard.Weights, defaultWeights)
|
||||||
|
Conf.Flashcard.Weights = defaultWeights
|
||||||
|
go func() {
|
||||||
|
util.WaitForUILoaded()
|
||||||
|
task.AppendAsyncTaskWithDelay(task.PushMsg, 2*time.Second, util.PushErrMsg, msg, 15000)
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
if nil == Conf.AI {
|
if nil == Conf.AI {
|
||||||
Conf.AI = conf.NewAI()
|
Conf.AI = conf.NewAI()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue