Skip to content

Commit

Permalink
feat: add load balancer setting (st3v3nmw#1139)
Browse files Browse the repository at this point in the history
  • Loading branch information
st3v3nmw authored Oct 18, 2024
1 parent b0b5b84 commit f2c5739
Show file tree
Hide file tree
Showing 21 changed files with 169 additions and 33 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: Lint and Test Code
on:
pull_request:
branches: [master]
push:
branches: [master]

jobs:
lint_and_test_code:
Expand Down
3 changes: 1 addition & 2 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ coverage:
round: down
precision: 2
status:
project: off
project: true
patch:
default:
target: 100
threshold: 0.0
only_pulls: true
changes: off
10 changes: 5 additions & 5 deletions src/algorithms/osr/note-scheduling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function osrSchedule(
originalInterval: number,
ease: number,
delayedBeforeReview: number,
settingsObj: SRSettings,
settings: SRSettings,
dueDateHistogram?: DueDateHistogram,
): Record<string, number> {
const delayedBeforeReviewDays = Math.max(0, Math.floor(delayedBeforeReview / TICKS_PER_DAY));
Expand All @@ -22,19 +22,19 @@ export function osrSchedule(
if (response === ReviewResponse.Easy) {
ease += 20;
interval = ((interval + delayedBeforeReviewDays) * ease) / 100;
interval *= settingsObj.easyBonus;
interval *= settings.easyBonus;
} else if (response === ReviewResponse.Good) {
interval = ((interval + delayedBeforeReviewDays / 2) * ease) / 100;
} else if (response === ReviewResponse.Hard) {
ease = Math.max(130, ease - 20);
interval = Math.max(
1,
(interval + delayedBeforeReviewDays / 4) * settingsObj.lapsesIntervalChange,
(interval + delayedBeforeReviewDays / 4) * settings.lapsesIntervalChange,
);
}

// replaces random fuzz with load balancing over the fuzz interval
if (dueDateHistogram !== undefined) {
if (settings.loadBalance && dueDateHistogram !== undefined) {
interval = Math.round(interval);
// disable fuzzing for small intervals
if (interval > 4) {
Expand All @@ -48,7 +48,7 @@ export function osrSchedule(
}
}

interval = Math.min(interval, settingsObj.maximumInterval);
interval = Math.min(interval, settings.maximumInterval);
interval = Math.round(interval * 10) / 10;

return { interval, ease };
Expand Down
10 changes: 7 additions & 3 deletions src/gui/flashcard-review-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -586,10 +586,14 @@ export class FlashcardReviewView {
);
const interval: number = schedule.interval;

if (Platform.isMobile) {
button.setText(textInterval(interval, true));
if (this.settings.showIntervalInReviewButtons) {
if (Platform.isMobile) {
button.setText(textInterval(interval, true));
} else {
button.setText(`${buttonName} - ${textInterval(interval, false)}`);
}
} else {
button.setText(`${buttonName} - ${textInterval(interval, false)}`);
button.setText(buttonName);
}
}
}
22 changes: 22 additions & 0 deletions src/gui/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,18 @@ export class SRSettingTab extends PluginSettingTab {
}),
);

new Setting(containerEl)
.setName(t("SHOW_INTERVAL_IN_REVIEW_BUTTONS"))
.setDesc(t("SHOW_INTERVAL_IN_REVIEW_BUTTONS_DESC"))
.addToggle((toggle) =>
toggle
.setValue(this.plugin.data.settings.showIntervalInReviewButtons)
.onChange(async (value) => {
this.plugin.data.settings.showIntervalInReviewButtons = value;
await this.plugin.savePluginData();
}),
);

new Setting(containerEl)
.setName(t("CARD_MODAL_HEIGHT_PERCENT"))
.setDesc(t("CARD_MODAL_SIZE_PERCENT_DESC"))
Expand Down Expand Up @@ -886,6 +898,16 @@ export class SRSettingTab extends PluginSettingTab {
});
});

new Setting(containerEl)
.setName(t("LOAD_BALANCE"))
.setDesc(t("LOAD_BALANCE_DESC"))
.addToggle((toggle) =>
toggle.setValue(this.plugin.data.settings.loadBalance).onChange(async (value) => {
this.plugin.data.settings.loadBalance = value;
await this.plugin.savePluginData();
}),
);

new Setting(containerEl)
.setName(t("MAX_INTERVAL"))
.setDesc(t("MAX_INTERVAL_DESC"))
Expand Down
13 changes: 10 additions & 3 deletions src/lang/locale/ar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ export default {
"cloze deletions : البطاقات الشقيقة هي بطاقات تم إنشاؤها من نفس نص البطاقة كـ",
SHOW_CARD_CONTEXT: "إظهار السياق في البطاقات؟",
SHOW_CARD_CONTEXT_DESC: "i.e. Title > Heading 1 > Subheading > ... > Subheading",
SHOW_INTERVAL_IN_REVIEW_BUTTONS: "Show next review time in the review buttons",
SHOW_INTERVAL_IN_REVIEW_BUTTONS_DESC:
"Useful to know how far in the future your cards are being pushed.",
CARD_MODAL_HEIGHT_PERCENT: "نسبة ارتفاع البطاقة",
CARD_MODAL_SIZE_PERCENT_DESC:
"يجب ضبطها على 100 ٪ على الهاتف المحمول أو إذا كان لديك صور كبيرة جدًا",
Expand All @@ -112,9 +115,9 @@ export default {
"Randomly (once all cards in previous deck reviewed)",
REVIEW_DECK_ORDER_RANDOM_DECK_AND_CARD: "Random card from random deck",
DISABLE_CLOZE_CARDS: "؟cloze تعطيل بطاقات",
CONVERT_HIGHLIGHTS_TO_CLOZES: "Convert ==highlights== to clozes?",
CONVERT_BOLD_TEXT_TO_CLOZES: "Convert **bolded text** to clozes?",
CONVERT_CURLY_BRACKETS_TO_CLOZES: "Convert {{curly brackets}} to clozes?",
CONVERT_HIGHLIGHTS_TO_CLOZES: "Convert ==highlights== to clozes",
CONVERT_BOLD_TEXT_TO_CLOZES: "Convert **bolded text** to clozes",
CONVERT_CURLY_BRACKETS_TO_CLOZES: "Convert {{curly brackets}} to clozes",
CLOZE_PATTERNS: "Cloze Patterns",
CLOZE_PATTERNS_DESC:
'Enter cloze patterns separated by newlines. Check the <a href="${docsUrl}">wiki</a> for guidance.',
Expand Down Expand Up @@ -161,6 +164,10 @@ export default {
EASY_BONUS_DESC:
"تتيح لك المكافأة السهلة ضبط الفرق في الفواصل الزمنية بين الرد الجيد والسهل على بطاقة/ملاحظة (الحد الأدنى = 100 ٪).",
EASY_BONUS_MIN_WARNING: "يجب أن تكون المكافأة السهلة 100 على الأقل.",
LOAD_BALANCE: "Enable load balancer",
LOAD_BALANCE_DESC: `Slightly tweaks the interval so that the number of reviews per day is more consistent.
It's like Anki's fuzz but instead of being random, it picks the day with the least amount of reviews.
It's turned off for small intervals.`,
MAX_INTERVAL: "Maximum interval in days",
MAX_INTERVAL_DESC: "يتيح لك وضع حد أعلى للفاصل الزمني (افتراضي = 100 عام).",
MAX_INTERVAL_MIN_WARNING: "يجب أن يكون الحد الأقصى للفاصل الزمني لمدة يوم واحد على الأقل.",
Expand Down
7 changes: 7 additions & 0 deletions src/lang/locale/cz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ export default {
"Příbuzné kartičky jsou kartičky generované z textu stejné poznámky například cloze smazání",
SHOW_CARD_CONTEXT: "Ukázat kontext v kartičce?",
SHOW_CARD_CONTEXT_DESC: "například Titulek > Nadpis1 > Podnadpis > ... > Podnadpis",
SHOW_INTERVAL_IN_REVIEW_BUTTONS: "Show next review time in the review buttons",
SHOW_INTERVAL_IN_REVIEW_BUTTONS_DESC:
"Useful to know how far in the future your cards are being pushed.",
CARD_MODAL_HEIGHT_PERCENT: "Výška kartiček v procentech",
CARD_MODAL_SIZE_PERCENT_DESC:
"Mělo by být nastaveno na 100% na mobilu nebo když používáte velké obrázky",
Expand Down Expand Up @@ -165,6 +168,10 @@ export default {
EASY_BONUS_DESC:
"Tento bonus umožňuje nastavit rozdíl intervalu mezi jednoduchými a dobrými kartičkami/poznámkami (minimum = 100%).",
EASY_BONUS_MIN_WARNING: "Bonus pro jednoduchost musí být minimálně 100.",
LOAD_BALANCE: "Enable load balancer",
LOAD_BALANCE_DESC: `Slightly tweaks the interval so that the number of reviews per day is more consistent.
It's like Anki's fuzz but instead of being random, it picks the day with the least amount of reviews.
It's turned off for small intervals.`,
MAX_INTERVAL: "Maximum interval in days",
MAX_INTERVAL_DESC: "Umožňuje nastavit horní limit pro interval (defaultně = 100 let).",
MAX_INTERVAL_MIN_WARNING: "Maximální interval musí být alespoň 1 den.",
Expand Down
7 changes: 7 additions & 0 deletions src/lang/locale/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ export default {
"Verwandte Karten sind aus der gleichen Karte generiert worden (z.B. Lückentextkarten oder beidseitige Karten).",
SHOW_CARD_CONTEXT: "Kontext in den Karten anzeigen?",
SHOW_CARD_CONTEXT_DESC: "Bsp. Titel > Überschrift 1 > Sektion > ... > Untersektion",
SHOW_INTERVAL_IN_REVIEW_BUTTONS: "Show next review time in the review buttons",
SHOW_INTERVAL_IN_REVIEW_BUTTONS_DESC:
"Useful to know how far in the future your cards are being pushed.",
CARD_MODAL_HEIGHT_PERCENT: "Höhe der Lernkartei in Prozent",
CARD_MODAL_SIZE_PERCENT_DESC:
"Auf kleinen Bildschirmen (z.B. Smartphones) oder bei sehr grossen Bildern sollte dieser Wert auf 100% gesetzt werden.",
Expand Down Expand Up @@ -183,6 +186,10 @@ export default {
EASY_BONUS_DESC:
"Der Einfachheit-Bonus gibt an um welchen Faktor (in Prozent) das Intervall länger sein soll, wenn eine Notiz / Karte 'Einfach' statt 'Gut' abgeschlossen wird. Minimum ist 100%.",
EASY_BONUS_MIN_WARNING: "Der Einfachheit-Bonus muss mindestens 100 sein.",
LOAD_BALANCE: "Enable load balancer",
LOAD_BALANCE_DESC: `Slightly tweaks the interval so that the number of reviews per day is more consistent.
It's like Anki's fuzz but instead of being random, it picks the day with the least amount of reviews.
It's turned off for small intervals.`,
MAX_INTERVAL: "Maximale Intervall in Tagen",
MAX_INTERVAL_DESC:
"Das maximale Intervall (in Tagen) für Wiederholungen. Standard sind 100 Jahre.",
Expand Down
19 changes: 13 additions & 6 deletions src/lang/locale/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,20 @@ export default {
FLASHCARD_TAGS: "Flashcard tags",
FLASHCARD_TAGS_DESC:
"Enter tags separated by spaces or newlines i.e. #flashcards #deck2 #deck3.",
CONVERT_FOLDERS_TO_DECKS: "Convert folders to decks and subdecks?",
CONVERT_FOLDERS_TO_DECKS: "Convert folders to decks and subdecks",
CONVERT_FOLDERS_TO_DECKS_DESC: "This is an alternative to the Flashcard tags option above.",
INLINE_SCHEDULING_COMMENTS:
"Save scheduling comment on the same line as the flashcard's last line?",
INLINE_SCHEDULING_COMMENTS_DESC:
"Turning this on will make the HTML comments not break list formatting.",
BURY_SIBLINGS_TILL_NEXT_DAY: "Bury sibling cards until the next day?",
BURY_SIBLINGS_TILL_NEXT_DAY: "Bury sibling cards until the next day",
BURY_SIBLINGS_TILL_NEXT_DAY_DESC:
"Siblings are cards generated from the same card text i.e. cloze deletions",
SHOW_CARD_CONTEXT: "Show context in cards?",
SHOW_CARD_CONTEXT: "Show context in cards",
SHOW_CARD_CONTEXT_DESC: "i.e. Title > Heading 1 > Subheading > ... > Subheading",
SHOW_INTERVAL_IN_REVIEW_BUTTONS: "Show next review time in the review buttons",
SHOW_INTERVAL_IN_REVIEW_BUTTONS_DESC:
"Useful to know how far in the future your cards are being pushed.",
CARD_MODAL_HEIGHT_PERCENT: "Flashcard Height Percentage",
CARD_MODAL_SIZE_PERCENT_DESC:
"Should be set to 100% on mobile or if you have very large images",
Expand All @@ -115,9 +118,9 @@ export default {
"Randomly (once all cards in previous deck reviewed)",
REVIEW_DECK_ORDER_RANDOM_DECK_AND_CARD: "Random card from random deck",
DISABLE_CLOZE_CARDS: "Disable cloze cards?",
CONVERT_HIGHLIGHTS_TO_CLOZES: "Convert ==highlights== to clozes?",
CONVERT_BOLD_TEXT_TO_CLOZES: "Convert **bolded text** to clozes?",
CONVERT_CURLY_BRACKETS_TO_CLOZES: "Convert {{curly brackets}} to clozes?",
CONVERT_HIGHLIGHTS_TO_CLOZES: "Convert ==highlights== to clozes",
CONVERT_BOLD_TEXT_TO_CLOZES: "Convert **bolded text** to clozes",
CONVERT_CURLY_BRACKETS_TO_CLOZES: "Convert {{curly brackets}} to clozes",
CLOZE_PATTERNS: "Cloze Patterns",
CLOZE_PATTERNS_DESC:
'Enter cloze patterns separated by newlines. Check the <a href="${docsUrl}">wiki</a> for guidance.',
Expand Down Expand Up @@ -164,6 +167,10 @@ export default {
EASY_BONUS_DESC:
"The easy bonus allows you to set the difference in intervals between answering Good and Easy on a flashcard/note (minimum = 100%).",
EASY_BONUS_MIN_WARNING: "The easy bonus must be at least 100.",
LOAD_BALANCE: "Enable load balancer",
LOAD_BALANCE_DESC: `Slightly tweaks the interval so that the number of reviews per day is more consistent.
It's like Anki's fuzz but instead of being random, it picks the day with the least amount of reviews.
It's turned off for small intervals.`,
MAX_INTERVAL: "Maximum interval in days",
MAX_INTERVAL_DESC: "Allows you to place an upper limit on the interval (default = 100 years).",
MAX_INTERVAL_MIN_WARNING: "The maximum interval must be at least 1 day.",
Expand Down
7 changes: 7 additions & 0 deletions src/lang/locale/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ export default {
"Los hermanos son tarjetas generadas del mismo texto de la tarjeta, por ejemplo, deletreos de huecos (cloze deletions en inglés)",
SHOW_CARD_CONTEXT: "¿Mostrar contexto en las tarjetas?",
SHOW_CARD_CONTEXT_DESC: "Por Ejemplo: Título > Cabecera > Sub-Cabecera > ... > Sub-Cabecera",
SHOW_INTERVAL_IN_REVIEW_BUTTONS: "Show next review time in the review buttons",
SHOW_INTERVAL_IN_REVIEW_BUTTONS_DESC:
"Useful to know how far in the future your cards are being pushed.",
CARD_MODAL_HEIGHT_PERCENT: "Porcentaje de la altura de las tarjetas de memoria",
CARD_MODAL_SIZE_PERCENT_DESC: "Debería ser establecido en 100% si tienes imágenes grandes",
RESET_DEFAULT: "Reiniciar a la configuración por defecto",
Expand Down Expand Up @@ -170,6 +173,10 @@ export default {
EASY_BONUS_DESC:
"La bonificación para Fácil te permite establecer la diferencia entre intervalos al responder Bien y Fácil en las tarjetas o notas (mínimo = 100%).",
EASY_BONUS_MIN_WARNING: "El bono de facilidad debe ser al menos 100.",
LOAD_BALANCE: "Enable load balancer",
LOAD_BALANCE_DESC: `Slightly tweaks the interval so that the number of reviews per day is more consistent.
It's like Anki's fuzz but instead of being random, it picks the day with the least amount of reviews.
It's turned off for small intervals.`,
MAX_INTERVAL: "Intervalo máximo en días",
MAX_INTERVAL_DESC:
"Te permite establecer un límite mayor en el intervalo (por defecto es de 100 años).",
Expand Down
7 changes: 7 additions & 0 deletions src/lang/locale/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ export default {
"Les cartes sœurs sont les cartes générées depuis le même texte, par exemple pour les textes à trous",
SHOW_CARD_CONTEXT: "Montrer le contexte dans les cartes ?",
SHOW_CARD_CONTEXT_DESC: "ex. Titre de la note > Titre 1 > Sous-titre > ... > Sous-titre",
SHOW_INTERVAL_IN_REVIEW_BUTTONS: "Show next review time in the review buttons",
SHOW_INTERVAL_IN_REVIEW_BUTTONS_DESC:
"Useful to know how far in the future your cards are being pushed.",
CARD_MODAL_HEIGHT_PERCENT: "Pourcentage de hauteur de la flashcard",
CARD_MODAL_SIZE_PERCENT_DESC: "Devrait être 100% sur mobile ou en cas de grandes images",
RESET_DEFAULT: "Réinitialiser les paramètres",
Expand Down Expand Up @@ -170,6 +173,10 @@ export default {
EASY_BONUS_DESC:
"Le bonus Facile vous permet d'augmenter l'intervalle entre une réponse Correct et une réponse Facile sur une flashcard/note (minimum = 100%).",
EASY_BONUS_MIN_WARNING: "Le bonus Facile doit être au moins 100.",
LOAD_BALANCE: "Enable load balancer",
LOAD_BALANCE_DESC: `Slightly tweaks the interval so that the number of reviews per day is more consistent.
It's like Anki's fuzz but instead of being random, it picks the day with the least amount of reviews.
It's turned off for small intervals.`,
MAX_INTERVAL: "Intervalle maximum (en jours)",
MAX_INTERVAL_DESC:
"Vous permet de mettre une limite maximale sur l'intervalle (par défaut, 100 ans).",
Expand Down
7 changes: 7 additions & 0 deletions src/lang/locale/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ export default {
SHOW_CARD_CONTEXT: "Mostrare contesto nelle schede?",
SHOW_CARD_CONTEXT_DESC:
"per esempio, Titolo > Intestazione 1 > Sottotitolo 1 > ... > Sottotitolo",
SHOW_INTERVAL_IN_REVIEW_BUTTONS: "Show next review time in the review buttons",
SHOW_INTERVAL_IN_REVIEW_BUTTONS_DESC:
"Useful to know how far in the future your cards are being pushed.",
CARD_MODAL_HEIGHT_PERCENT: "Percentuale altezza schede",
CARD_MODAL_SIZE_PERCENT_DESC:
"Dovrebbe essere 100% se sei su telefono o se hai immagini molto grandi",
Expand Down Expand Up @@ -173,6 +176,10 @@ export default {
EASY_BONUS_DESC:
"Il bonus facilità ti permette di impostare le differenze negli intervalli tra il rispondere Buono e Facile su una scheda o nota (minimo 100%).",
EASY_BONUS_MIN_WARNING: "Il bonus facilità deve essere di almeno 100.",
LOAD_BALANCE: "Enable load balancer",
LOAD_BALANCE_DESC: `Slightly tweaks the interval so that the number of reviews per day is more consistent.
It's like Anki's fuzz but instead of being random, it picks the day with the least amount of reviews.
It's turned off for small intervals.`,
MAX_INTERVAL: "Intervallo massimo in giorni",
MAX_INTERVAL_DESC:
"Ti permette di mettere un limite massimo all'intervallo (default 100 anni).",
Expand Down
7 changes: 7 additions & 0 deletions src/lang/locale/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ export default {
SHOW_CARD_CONTEXT: "カードにコンテキストを表示しますか?",
SHOW_CARD_CONTEXT_DESC:
"「タイトル > 見出し 1 > 副見出し > ... > 副見出し」の表示を行うかどうかを決めます。",
SHOW_INTERVAL_IN_REVIEW_BUTTONS: "Show next review time in the review buttons",
SHOW_INTERVAL_IN_REVIEW_BUTTONS_DESC:
"Useful to know how far in the future your cards are being pushed.",
CARD_MODAL_HEIGHT_PERCENT: "フラッシュカードの縦サイズのパーセンテージ",
CARD_MODAL_SIZE_PERCENT_DESC:
"モバイル版、または非常に大きなサイズの画像がある場合には100%にする必要があります。",
Expand Down Expand Up @@ -169,6 +172,10 @@ export default {
EASY_BONUS_DESC:
"Easyボーナスによってフラッシュカード/ノートにおける間隔の差分を設定できます(最小値 = 100%)。",
EASY_BONUS_MIN_WARNING: "Easyボーナスには100以上の数字を指定してください。",
LOAD_BALANCE: "Enable load balancer",
LOAD_BALANCE_DESC: `Slightly tweaks the interval so that the number of reviews per day is more consistent.
It's like Anki's fuzz but instead of being random, it picks the day with the least amount of reviews.
It's turned off for small intervals.`,
MAX_INTERVAL: "Maximum interval in days",
MAX_INTERVAL_DESC: "間隔に上限値を設定することができます(デフォルト値 = 100年)。",
MAX_INTERVAL_MIN_WARNING: "間隔の最大値には1以上の数字を指定してください。",
Expand Down
Loading

0 comments on commit f2c5739

Please sign in to comment.