From 3da233cad36df0d65111b96848477d3f12ea643a Mon Sep 17 00:00:00 2001 From: Newdea <9208450+Newdea@users.noreply.github.com> Date: Sun, 3 Dec 2023 15:54:27 +0800 Subject: [PATCH] bump version 1.10.5.2 close #25 add reset fix stats update docs fix last tag directly await --- docs/changelog.md | 6 ++++ docs/usage.md | 4 +-- ...77\347\224\250\346\225\231\347\250\213.md" | 4 +-- manifest.json | 2 +- package.json | 2 +- src/Events/trackFileEvents.ts | 4 +-- src/commands.ts | 24 +++++++-------- src/dataStore/dataSyncer.ts | 8 ++--- src/dataStore/location_switch.ts | 21 +++++++++++--- src/dataStore/repetitionItem.ts | 21 ++++++++++++++ src/main.ts | 29 ++++++++++--------- src/reviewNote/review-note.ts | 15 +++++++--- src/stats.ts | 13 +++++---- 13 files changed, 103 insertions(+), 50 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index 587bde68..f46e7115 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. Dates are d Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). +## [1.10.5.2] + +- close #25, 笔记复习增加重来命令 +- 修复查看数据时卡死的问题; +- 正常不会用到的命令放入了调试命令时; + ## [1.10.5.1] - 合并主分支; diff --git a/docs/usage.md b/docs/usage.md index 80ed3904..3dd585f1 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -25,8 +25,8 @@ Suggestions: 1. Close the original plugin first to avoid conflict. 2. backup the note vault (because after changing the DataLocation in the settings, the review information in the note content will be deleted and saved to a separate file tracked_files.json.) - -If you want to use FSRS algorithm, you need to set it as recommended [above CASE1](). +3. close Obsidan.md, copy `obsidian-spaced-repetition/data.json` to `obsidian-spaced-repetition-recall/data.json`, then start Obsidan.md. +4. If you want to use FSRS algorithm, you need to set it as recommended [above CASE1](). --- diff --git "a/docs/\344\275\277\347\224\250\346\225\231\347\250\213.md" "b/docs/\344\275\277\347\224\250\346\225\231\347\250\213.md" index 6bba166a..8e0cee92 100644 --- "a/docs/\344\275\277\347\224\250\346\225\231\347\250\213.md" +++ "b/docs/\344\275\277\347\224\250\346\225\231\347\250\213.md" @@ -27,8 +27,8 @@ 1. 先关闭原插件,避免冲突。 2. 备份笔记库(因在设置中修改DataLocation后,会删除笔记内容中的复习信息,另存到 单独文件 tracked_files.json。 ) - -如果是想用FSRS算法,需要按上述CASE1推荐设置。 +3. 关闭Obsidian.md,复制原插件的`obsidian-spaced-repetition/data.json` 到 `obsidian-spaced-repetition-recall/data.json`,再打开Obsidan.md。 +4. 如果是想用FSRS算法,需要按上述CASE1推荐设置。 --- diff --git a/manifest.json b/manifest.json index b6761c53..eae599f4 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-spaced-repetition-recall", "name": "Spaced Repetition Recall", - "version": "1.10.5.1", + "version": "1.10.5.2", "minAppVersion": "0.15.4", "description": "Fight the forgetting curve by reviewing flashcards & entire notes.", "author": "Newdea", diff --git a/package.json b/package.json index 0b154cf5..f44d5547 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obsidian-spaced-repetition", - "version": "1.10.5.1", + "version": "1.10.5.2", "description": "Fight the forgetting curve by reviewing flashcards & entire notes.", "main": "main.js", "scripts": { diff --git a/src/Events/trackFileEvents.ts b/src/Events/trackFileEvents.ts index c0d95f9c..74ecf126 100644 --- a/src/Events/trackFileEvents.ts +++ b/src/Events/trackFileEvents.ts @@ -4,11 +4,11 @@ import SRPlugin from "src/main"; export function registerTrackFileEvents(plugin: SRPlugin) { plugin.registerEvent( - plugin.app.vault.on("rename", (file, old) => { + plugin.app.vault.on("rename", async (file, old) => { const trackFile = plugin.store.getTrackedFile(old); if (trackFile != null) { trackFile.rename(file.path); - plugin.store.save(); + await plugin.store.save(); } }), ); diff --git a/src/commands.ts b/src/commands.ts index 43df3ec1..469d5633 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -87,6 +87,11 @@ export default class Commands { // return false; // }, // }); + } + + addDebugCommands() { + console.log("Injecting debug commands..."); + const plugin = this.plugin; plugin.addCommand({ id: "build-queue", @@ -104,11 +109,6 @@ export default class Commands { ReviewNote.recallReviewNote(this.plugin.data.settings); }, }); - } - - addDebugCommands() { - console.log("Injecting debug commands..."); - const plugin = this.plugin; plugin.addCommand({ id: "debug-print-view-state", @@ -141,13 +141,13 @@ export default class Commands { // }, // }); - // plugin.addCommand({ - // id: "debug-clear-queue", - // name: "Clear Queue", - // callback: () => { - // Queue.getInstance().clearQueue(); - // }, - // }); + plugin.addCommand({ + id: "debug-clear-queue", + name: "Clear Queue", + callback: () => { + Queue.getInstance().clearQueue(); + }, + }); plugin.addCommand({ id: "debug-queue-all", diff --git a/src/dataStore/dataSyncer.ts b/src/dataStore/dataSyncer.ts index 5f3e4124..bcfe7b93 100644 --- a/src/dataStore/dataSyncer.ts +++ b/src/dataStore/dataSyncer.ts @@ -77,15 +77,15 @@ export class DataSyncer { const ind = store.getFileIndex(note.path); const trackedFile = store.getTrackedFile(note.path); const fileid = store.getFileId(note.path); - let item = store.getItembyID(fileid); + const item = store.getItembyID(fileid); let now_number: number = now; const nowToday: number = DateUtils.EndofToday; if (item == null || !item.isTracked) { - store._updateItem(fileid, ind, RPITEMTYPE.NOTE, rdeck.deckName); - item = store.getItembyID(fileid); + // store._updateItem(fileid, ind, RPITEMTYPE.NOTE, rdeck.deckName); + // item = store.getItembyID(fileid); console.debug("syncRCDataToSRrevDeck update null item:", item, trackedFile); - // return; + return; } if (now == null) { now_number = nowToday; diff --git a/src/dataStore/location_switch.ts b/src/dataStore/location_switch.ts index df22002b..ddd3915c 100644 --- a/src/dataStore/location_switch.ts +++ b/src/dataStore/location_switch.ts @@ -11,7 +11,7 @@ import SRPlugin from "src/main"; import { isIgnoredPath } from "src/reviewNote/review-note"; import { SRSettings } from "src/settings"; import { escapeRegexString } from "src/util/utils"; -import { DataStore } from "./data"; +import { DataStore, RPITEMTYPE } from "./data"; import { Tags } from "src/tags"; import { DataSyncer } from "./dataSyncer"; @@ -342,9 +342,22 @@ export class LocationSwitch { } else if (item?.isNew) { plugin.noteStats.incrementNew(); } - if (item?.deckName === store.defaultDackName) { - fileText = addDefaultTagtoNote(fileText, this.revTag); - fileChanged = true; + //update tag to note + if (item?.itemType === RPITEMTYPE.NOTE) { + const noteTag = Tags.getNoteDeckName(note, this.settings); + if (item.deckName === store.defaultDackName) { + fileText = addDefaultTagtoNote(fileText, this.revTag); + fileChanged = true; + } else if ( + noteTag == null && + this.settings.tagsToReview.includes(item.deckName) + ) { + const tag = [this.settings.tagsToReview[0], item.deckName.substring(1)] + .join("/") + .substring(1); + fileText = addDefaultTagtoNote(fileText, tag); + fileChanged = true; + } } if (!dryrun && fileChanged) { if (fileText == null) { diff --git a/src/dataStore/repetitionItem.ts b/src/dataStore/repetitionItem.ts index b1ef50ed..2ccd1ec2 100644 --- a/src/dataStore/repetitionItem.ts +++ b/src/dataStore/repetitionItem.ts @@ -69,6 +69,27 @@ export class RepetitionItem { this.data = data; } + /** + * @param {ReviewResult} result + * @return {*} + */ + reviewUpdate(result: ReviewResult) { + this.nextReview = DateUtils.fromNow(result.nextReview).getTime(); + this.timesReviewed += 1; + if (result.correct) { + this.timesCorrect += 1; + this.errorStreak = 0; + } else { + this.errorStreak += 1; + } + } + + /** + * + * @param isFsrs + * @param isNumDue default is true. + * @returns + */ getSched(isFsrs?: boolean, isNumDue = true): RegExpMatchArray | null { if (this.nextReview === 0 || this.nextReview === null || this.timesReviewed === 0) { return null; // new card doesn't need schedinfo diff --git a/src/main.ts b/src/main.ts index 67346a22..18704641 100644 --- a/src/main.ts +++ b/src/main.ts @@ -93,7 +93,7 @@ export default class SRPlugin extends Plugin { private questionPostponementList: QuestionPostponementList; public incomingLinks: Record = {}; public pageranks: Record = {}; - public dueNotesCount = 0; + private dueNotesCount = 0; public dueDatesNotes: Record = {}; // Record<# of days in future, due count> public deckTree: Deck = new Deck("root", null); @@ -209,9 +209,9 @@ export default class SRPlugin extends Plugin { const options = this.algorithm.srsOptions(); const algo = this.data.settings.algorithm; const showtext = this.data.settings.responseOptionBtnsText; - for (let i = 1; i < options.length; i++) { + options.map((option, i) => { this.addCommand({ - id: "srs-note-review-" + options[i].toLowerCase(), + id: "srs-note-review-" + option.toLowerCase(), name: "review as: " + showtext[algo][i], callback: () => { const openFile: TFile | null = this.app.workspace.getActiveFile(); @@ -220,7 +220,7 @@ export default class SRPlugin extends Plugin { } }, }); - } + }); this.addCommand({ id: "srs-review-flashcards", @@ -588,7 +588,14 @@ export default class SRPlugin extends Plugin { } const settings = this.data.settings; - const deckname = Tags.getNoteDeckName(noteFile, this.data.settings); + let deckname = Tags.getNoteDeckName(noteFile, this.data.settings); + if (deckname == null) { + const tf = store.getTrackedFile(noteFile.path); + const tag = tf?.lastTag; + if (tag != undefined && settings.tagsToReview.includes(tag)) { + deckname = tag; + } + } if (deckname != null) { if (!Object.prototype.hasOwnProperty.call(this.reviewDecks, deckname)) { this.reviewDecks[deckname] = new ReviewDeck(deckname); @@ -632,13 +639,6 @@ export default class SRPlugin extends Plugin { } } } - } else { - const tf = store.getTrackedFile(noteFile.path); - const tag = tf?.tags?.last(); - if (tag != undefined && settings.tagsToReview.includes(tag)) { - tf.tags.remove(tag); - tf.updateTags(store.defaultDackName); - } } } @@ -895,7 +895,10 @@ export default class SRPlugin extends Plugin { async reviewNextNoteModal(): Promise { const reviewDeckNames: string[] = Object.keys(this.reviewDecks); if (this.data.settings.reviewingNoteDirectly) { - const rdname = ReviewNote.getDeckNameForReviewDirectly(this.reviewDecks); + const rdname = + this.lastSelectedReviewDeck ?? + ReviewNote.getDeckNameForReviewDirectly(this.reviewDecks) ?? + reviewDeckNames[0]; this.reviewNextNote(rdname); } else if (reviewDeckNames.length === 1) { this.reviewNextNote(reviewDeckNames[0]); diff --git a/src/reviewNote/review-note.ts b/src/reviewNote/review-note.ts index a9167c95..8f89ce8c 100644 --- a/src/reviewNote/review-note.ts +++ b/src/reviewNote/review-note.ts @@ -143,13 +143,20 @@ export class ReviewNote { [deckKey: string]: ReviewDeck; }): string | null { const reviewDeckNames: string[] = Object.keys(reviewDecks); - - const rdname = reviewDeckNames.find((dkey: string) => { + const rdnames: string[] = []; + reviewDeckNames.some((dkey: string) => { const ndeck = reviewDecks[dkey]; const ncount = ndeck.dueNotesCount + ndeck.newNotes.length; - return ncount > 0; + if (ncount > 0) { + rdnames.push(dkey); + } }); - return rdname; + if (rdnames.length > 0) { + const ind = Math.floor(Math.random() * rdnames.length); + return rdnames[ind]; + } else { + return null; + } } static getNextDueNoteIndex(NotesCount: number, openRandomNote: boolean = false) { diff --git a/src/stats.ts b/src/stats.ts index 00b63965..c9858ead 100644 --- a/src/stats.ts +++ b/src/stats.ts @@ -73,12 +73,15 @@ export class Stats { const interval: number = parseInt(scheduling[2]), ease: number = parseFloat(scheduling[3]); const delayedDays: number = Math.ceil( - (window - .moment(scheduling[1], ["YYYY-MM-DD", "DD-MM-YYYY", "ddd MMM DD YYYY"]) - .valueOf() - - now) / - DateUtils.DAYS_TO_MILLIS, + (parseFloat(scheduling[1]) - now) / DateUtils.DAYS_TO_MILLIS, ); + // const delayedDays: number = Math.ceil( + // (window + // .moment(scheduling[1], ["YYYY-MM-DD", "DD-MM-YYYY", "ddd MMM DD YYYY"]) + // .valueOf() - + // now) / + // DateUtils.DAYS_TO_MILLIS, + // ); this.update(delayedDays, interval, ease); }