Skip to content

Commit

Permalink
🎨 Apply result optimized by FSRS optimizer #9309
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Sep 28, 2023
1 parent b2a27bb commit 6354d04
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 10 deletions.
6 changes: 6 additions & 0 deletions app/appearance/langs/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@
"flashcardSuperBlockTip": "After enabling, the first child block of a super block is recognized as a question, and the rest of the child blocks are recognized as answers",
"flashcardDeck": "Deck",
"flashcardDeckTip": "After enabling, the card deck classification is supported. This is a historical compatibility option, it is not recommended to enable it unless necessary, and it is recommended to use <code class='fn__code'>Quick make card</code>",
"flashcardFSRSParamRequestRetention": "FSRS Request Retention",
"flashcardFSRSParamRequestRetentionTip": "Represents the probability of recall you want to target. Note that there is a tradeoff between higher retention and higher number of repetitions. It is recommended that you set this value somewhere between 0.8 and 0.9",
"flashcardFSRSParamMaximumInterval": "FSRS Maximum Interval",
"flashcardFSRSParamMaximumIntervalTip": "The maximum number of days between repetitions",
"flashcardFSRSParamWeights": "FSRS Weights",
"flashcardFSRSParamWeightsTip": "Algorithm weight parameters. The default value is obtained from a smaller sample. If adjustments are needed, please use the FSRS optimizer to calculate",
"apiKey": "API Key",
"apiKeyTip": "It is recommended to assign an API Key to SiYuan separately for subsequent management. If this item is left blank, AI-related functions will be disabled",
"apiTimeout": "Timeout",
Expand Down
6 changes: 6 additions & 0 deletions app/appearance/langs/es_ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@
"flashcardSuperBlockTip": "Después de habilitar, el primer bloque secundario de un súper bloque se reconoce como una pregunta y el resto de los bloques secundarios se reconocen como respuestas",
"flashcardDeck": "Mazo",
"flashcardDeckTip": "Después de habilitar, se admite la clasificación del mazo de cartas. Esta es una opción de compatibilidad histórica, no se recomienda habilitarla a menos que sea necesario, y se recomienda usar <code class='fn__code'>Quick make card</code>",
"flashcardFSRSParamRequestRetention": "Retención de solicitud FSRS",
"flashcardFSRSParamRequestRetentionTip": "Representa la probabilidad de recuperación a la que desea apuntar. Tenga en cuenta que existe un equilibrio entre una mayor retención y un mayor número de repeticiones. Se recomienda establecer este valor entre 0,8 y 0,9",
"flashcardFSRSParamMaximumInterval": "Intervalo máximo FSRS",
"flashcardFSRSParamMaximumIntervalTip": "El número máximo de días entre repeticiones",
"flashcardFSRSParamWeights": "Pesos FSRS",
"flashcardFSRSParamWeightsTip": "Parámetros de peso del algoritmo. El valor predeterminado se obtiene de una muestra más pequeña. Si se necesitan ajustes, utilice el optimizador FSRS para calcular",
"apiKey": "Clave API",
"apiKeyTip": "Se recomienda asignar una clave API a SiYuan por separado para su posterior administración. Si este elemento se deja en blanco, las funciones relacionadas con la IA se desactivarán",
"apiTimeout": "Tiempo de espera",
Expand Down
6 changes: 6 additions & 0 deletions app/appearance/langs/fr_FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@
"flashcardSuperBlockTip": "Après l'activation, le premier bloc enfant d'un super bloc est reconnu comme une question, et les autres blocs enfants sont reconnus comme des réponses",
"flashcardDeck": "Deck",
"flashcardDeckTip": "Après l'activation, la classification du jeu de cartes est prise en charge. Il s'agit d'une option de compatibilité historique, il n'est pas recommandé de l'activer sauf si nécessaire, et il est recommandé d'utiliser <code class='fn__code'>Quick make card</code>",
"flashcardFSRSParamRequestRetention": "Rétention des requêtes FSRS",
"flashcardFSRSParamRequestRetentionTip": "Représente la probabilité de rappel que vous souhaitez cibler. Notez qu'il existe un compromis entre une rétention plus élevée et un nombre de répétitions plus élevé. Il est recommandé de définir cette valeur entre 0,8 et 0,9",
"flashcardFSRSParamMaximumInterval": "Intervalle maximum FSRS",
"flashcardFSRSParamMaximumIntervalTip": "Le nombre maximum de jours entre les répétitions",
"flashcardFSRSParamWeights": "Poids FSRS",
"flashcardFSRSParamWeightsTip": "Paramètres de poids de l'algorithme. La valeur par défaut est obtenue à partir d'un échantillon plus petit. Si des ajustements sont nécessaires, veuillez utiliser l'optimiseur FSRS pour calculer",
"apiKey": "Clé API",
"apiKeyTip": "Il est recommandé d'attribuer une clé API à SiYuan séparément pour une gestion ultérieure. Si cet élément est laissé vide, les fonctions liées à l'IA seront désactivées",
"apiTimeout": "Délai d'expiration",
Expand Down
6 changes: 6 additions & 0 deletions app/appearance/langs/zh_CHT.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@
"flashcardSuperBlockTip": "啟用後支持超級塊制卡,超級塊的第一個子塊被識別為問題,其餘子塊識別為答案",
"flashcardDeck": "卡包",
"flashcardDeckTip": "啟用後支持卡包分類。這是一個歷史兼容選項,如無必要建議不要啟用,推薦使用 <code class='fn__code'>快速制卡</code>",
"flashcardFSRSParamRequestRetention": "FSRS Request Retention",
"flashcardFSRSParamRequestRetentionTip": "回憶機率參數。請注意,這裡需要權衡更高的保留率和更高的重複次數。建議設定該值介於 0.8 和 0.9 之間",
"flashcardFSRSParamMaximumInterval": "FSRS Maximum Interval",
"flashcardFSRSParamMaximumIntervalTip": "最大間隔天數參數",
"flashcardFSRSParamWeights": "FSRS Weights",
"flashcardFSRSParamWeightsTip": "演算法權重參數。預設值為較小樣本取得,如果需要調整請使用 FSRS 最佳化器計算",
"apiKey": "API Key",
"apiKeyTip": "建議為思源單獨分配 API Key 以便於後續管理。該項留空則禁用 AI 相關功能",
"apiTimeout": "超時時間",
Expand Down
6 changes: 6 additions & 0 deletions app/appearance/langs/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@
"flashcardSuperBlockTip": "启用后支持超级块制卡,超级块的第一个子块被识别为问题,其余子块识别为答案",
"flashcardDeck": "卡包",
"flashcardDeckTip": "启用后支持卡包分类。这是一个历史兼容选项,如无必要建议不要启用,推荐使用 <code class='fn__code'>快速制卡</code>",
"flashcardFSRSParamRequestRetention": "FSRS Request Retention",
"flashcardFSRSParamRequestRetentionTip": "回忆概率参数。请注意,这里需要权衡更高的保留率和更高的重复次数。建议设置该值介于 0.8 和 0.9 之间",
"flashcardFSRSParamMaximumInterval": "FSRS Maximum Interval",
"flashcardFSRSParamMaximumIntervalTip": "最大间隔天数参数",
"flashcardFSRSParamWeights": "FSRS Weights",
"flashcardFSRSParamWeightsTip": "算法权重参数。默认值为较小样本获得,如果需要调整请使用 FSRS 优化器计算",
"apiKey": "API Key",
"apiKeyTip": "建议为思源单独分配 API Key 以便于后续管理。该项留空则禁用 AI 相关功能",
"apiTimeout": "超时时间",
Expand Down
34 changes: 31 additions & 3 deletions app/src/config/flashcard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const flashcard = {
responsiveHTML = `<div class="b3-label">
${window.siyuan.languages.flashcardNewCardLimit}
<div class="fn__hr"></div>
<input class="b3-text-field fn__flex-center fn__block" id="newCardLimit" step="1" min="0" type="number"${window.siyuan.config.flashcard.newCardLimit ? " checked" : "" } value="${window.siyuan.config.flashcard.newCardLimit}"/>
<input class="b3-text-field fn__flex-center fn__block" id="newCardLimit" step="1" min="0" type="number"${window.siyuan.config.flashcard.newCardLimit ? " checked" : ""} value="${window.siyuan.config.flashcard.newCardLimit}"/>
<div class="b3-label__text">${window.siyuan.languages.flashcardNewCardLimitTip}</div>
</div>
<div class="b3-label">
Expand All @@ -24,7 +24,7 @@ export const flashcard = {
<div class="b3-label__text">${window.siyuan.languages.flashcardNewCardLimitTip}</div>
</div>
<span class="fn__space"></span>
<input class="b3-text-field fn__flex-center fn__size200" id="newCardLimit" step="1" min="0" type="number"${window.siyuan.config.flashcard.newCardLimit ? " checked" : "" } value="${window.siyuan.config.flashcard.newCardLimit}"/>
<input class="b3-text-field fn__flex-center fn__size200" id="newCardLimit" step="1" min="0" type="number"${window.siyuan.config.flashcard.newCardLimit ? " checked" : ""} value="${window.siyuan.config.flashcard.newCardLimit}"/>
</label>
<label class="fn__flex b3-label">
<div class="fn__flex-1">
Expand Down Expand Up @@ -67,7 +67,32 @@ export const flashcard = {
</div>
<span class="fn__space"></span>
<input class="b3-switch fn__flex-center" id="deck" type="checkbox"${window.siyuan.config.flashcard.deck ? " checked" : ""}/>
</label>`;
</label>
<label class="fn__flex b3-label">
<div class="fn__flex-1">
${window.siyuan.languages.flashcardFSRSParamRequestRetention}
<div class="b3-label__text">${window.siyuan.languages.flashcardFSRSParamRequestRetentionTip}</div>
</div>
<span class="fn__space"></span>
<input class="b3-text-field fn__flex-center fn__size200" id="requestRetention" step="0.01" min="0" max="1" type="number" value="${window.siyuan.config.flashcard.requestRetention}"/>
</label>
<label class="fn__flex b3-label">
<div class="fn__flex-1">
${window.siyuan.languages.flashcardFSRSParamMaximumInterval}
<div class="b3-label__text">${window.siyuan.languages.flashcardFSRSParamMaximumIntervalTip}</div>
</div>
<span class="fn__space"></span>
<input class="b3-text-field fn__flex-center fn__size200" id="maximumInterval" step="1" min="365" max="36500" type="number" value="${window.siyuan.config.flashcard.maximumInterval}"/>
</label>
<label class="fn__flex b3-label">
<div class="fn__flex-1">
${window.siyuan.languages.flashcardFSRSParamWeights}
<div class="b3-label__text">${window.siyuan.languages.flashcardFSRSParamWeightsTip}</div>
<span class="fn__hr"></span>
<input class="b3-text-field fn__block" id="weights" value="${window.siyuan.config.flashcard.weights}"/>
</div>
</label>
`;
},
bindEvent: () => {
flashcard.element.querySelectorAll("input").forEach((item) => {
Expand All @@ -79,6 +104,9 @@ export const flashcard = {
list: (flashcard.element.querySelector("#list") as HTMLInputElement).checked,
superBlock: (flashcard.element.querySelector("#superBlock") as HTMLInputElement).checked,
deck: (flashcard.element.querySelector("#deck") as HTMLInputElement).checked,
requestRetention: parseFloat((flashcard.element.querySelector("#requestRetention") as HTMLInputElement).value),
maximumInterval: parseInt((flashcard.element.querySelector("#maximumInterval") as HTMLInputElement).value),
weights: (flashcard.element.querySelector("#weights") as HTMLInputElement).value,
}, response => {
window.siyuan.config.flashcard = response.data;
});
Expand Down
3 changes: 2 additions & 1 deletion app/src/config/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export const initConfigSearch = (element: HTMLElement, app: App) => {
// 闪卡
getLang(["riffCard", "flashcardNewCardLimit", "flashcardNewCardLimitTip", "flashcardReviewCardLimit",
"flashcardNewCardLimit", "flashcardReviewCardLimitTip", "flashcardMark", "flashcardMarkTip", "flashcardList",
"flashcardSuperBlock", "flashcardDeck", "flashcardDeckTip"]),
"flashcardSuperBlock", "flashcardDeck", "flashcardDeckTip", "flashcardFSRSParamRequestRetention", "flashcardFSRSParamRequestRetentionTip",
"flashcardFSRSParamMaximumInterval", "flashcardFSRSParamMaximumIntervalTip", "flashcardFSRSParamWeights", "flashcardFSRSParamWeightsTip"]),

// AI
["AI"].concat(getLang(["ai", "apiTimeout", "apiTimeoutTip", "apiMaxTokens", "apiMaxTokensTip", "apiKey",
Expand Down
3 changes: 3 additions & 0 deletions app/src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,9 @@ interface IConfig {
list: boolean
superBlock: boolean
deck: boolean
requestRetention: number
maximumInterval: number
weights: string
}
ai: {
openAI: {
Expand Down
35 changes: 29 additions & 6 deletions kernel/conf/flashcard.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,45 @@

package conf

import (
"bytes"
"fmt"
"github.com/open-spaced-repetition/go-fsrs"
)

type Flashcard struct {
NewCardLimit int `json:"newCardLimit"` // 新卡上限 https://github.com/siyuan-note/siyuan/issues/7695
ReviewCardLimit int `json:"reviewCardLimit"` // 复习卡上限 https://github.com/siyuan-note/siyuan/issues/7703
Mark bool `json:"mark"` // 是否启用标记制卡 https://github.com/siyuan-note/siyuan/issues/7794
List bool `json:"list"` // 是否启用列表块制卡 https://github.com/siyuan-note/siyuan/issues/7701
SuperBlock bool `json:"superBlock"` // 是否启用超级块制卡 https://github.com/siyuan-note/siyuan/issues/7702
Deck bool `json:"deck"` // 是否启用卡包制卡 https://github.com/siyuan-note/siyuan/issues/7724

// Apply result optimized by FSRS optimizer https://github.com/siyuan-note/siyuan/issues/9309
RequestRetention float64 `json:"requestRetention"`
MaximumInterval float64 `json:"maximumInterval"`
Weights string `json:"weights"`
}

func NewFlashcard() *Flashcard {
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{
NewCardLimit: 20,
ReviewCardLimit: 200,
Mark: true,
List: true,
SuperBlock: true,
Deck: false,
NewCardLimit: 20,
ReviewCardLimit: 200,
Mark: true,
List: true,
SuperBlock: true,
Deck: false,
RequestRetention: param.RequestRetention,
MaximumInterval: param.MaximumInterval,
Weights: weightsBuilder.String(),
}
}
9 changes: 9 additions & 0 deletions kernel/model/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,15 @@ func InitConf() {
if 0 > Conf.Flashcard.ReviewCardLimit {
Conf.Flashcard.ReviewCardLimit = 200
}
if 0 >= Conf.Flashcard.RequestRetention || 1 <= Conf.Flashcard.RequestRetention {
Conf.Flashcard.RequestRetention = conf.NewFlashcard().RequestRetention
}
if 0 >= Conf.Flashcard.MaximumInterval || 36500 <= Conf.Flashcard.MaximumInterval {
Conf.Flashcard.MaximumInterval = conf.NewFlashcard().MaximumInterval
}
if "" == Conf.Flashcard.Weights || 17 != len(strings.Split(Conf.Flashcard.Weights, ",")) {
Conf.Flashcard.Weights = conf.NewFlashcard().Weights
}

if nil == Conf.AI {
Conf.AI = conf.NewAI()
Expand Down

0 comments on commit 6354d04

Please sign in to comment.