Skip to content

Commit

Permalink
fix #56 复习没到期的笔记
Browse files Browse the repository at this point in the history
fix #58 卡片复习数据显示不正确
  • Loading branch information
Newdea committed Jun 26, 2024
2 parents 27109e5 + 9797461 commit 7c60a10
Show file tree
Hide file tree
Showing 12 changed files with 243 additions and 216 deletions.
1 change: 0 additions & 1 deletion src/CardSchedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { ReviewResponse, schedule } from "./scheduling";
import { SRSettings } from "./settings";
import { formatDate_YYYY_MM_DD } from "./util/utils";
import { DateUtil, globalDateProvider } from "./util/DateProvider";
import { DateUtils } from "./util/utils_recall";

export class CardScheduleInfo {
dueDate: Moment;
Expand Down
5 changes: 4 additions & 1 deletion src/NoteQuestionParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ export class NoteQuestionParser {
//
private determineQuestionTopicPathList(question: Question): TopicPathList {
let result: TopicPathList;
if (this.settings.convertFoldersToDecks || this.settings.trackedNoteToDecks) {
if (this.settings.convertFoldersToDecks) {
result = new TopicPathList([this.folderTopicPath]);
} else {
// If present, the question specific TopicPath takes precedence over everything else
Expand Down Expand Up @@ -348,6 +348,9 @@ export class NoteQuestionParser {
}
}
}
if (!result && this.settings.trackedNoteToDecks && this.folderTopicPath) {
result = new TopicPathList([this.folderTopicPath]);
}
return result;
}
}
1 change: 0 additions & 1 deletion src/ReviewDeck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { TFile } from "obsidian";

import { t } from "src/lang/helpers";
import { RepetitionItem } from "./dataStore/repetitionItem";
import { DateUtils } from "./util/utils_recall";
import { globalDateProvider } from "./util/DateProvider";

export interface SchedNote {
Expand Down
6 changes: 3 additions & 3 deletions src/commands.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { MarkdownView, Notice } from "obsidian";
import ObsidianSrsPlugin from "./main";
import { ReviewNote } from "src/reviewNote/review-note";
import { ItemInfoModal } from "src/gui/info";
import { Queue } from "./dataStore/queue";
import { debug } from "./util/utils_recall";
import { postponeItems } from "./algorithms/balance/postpone";
import { reschedule } from "./algorithms/balance/reschedule";
import { GetInputModal } from "./gui/getInputModal";
import { ReviewView } from "./gui/reviewView";

export default class Commands {
plugin: ObsidianSrsPlugin;
Expand Down Expand Up @@ -38,7 +38,7 @@ export default class Commands {
// decks: deck.scheduledNotes.map((sn) => [sn.note.path, sn.item]),
que: store.data.queues.toDayLaterQueue,
});
new ItemInfoModal(plugin.data.settings, file).open();
new ItemInfoModal(plugin, file).open();
}
return true;
}
Expand Down Expand Up @@ -124,7 +124,7 @@ export default class Commands {
name: "Review",
callback: () => {
Queue.getInstance().buildQueue();
ReviewNote.recallReviewNote(this.plugin.data.settings);
ReviewView.getInstance().recallReviewNote(this.plugin.data.settings);
},
});

Expand Down
57 changes: 21 additions & 36 deletions src/dataStore/itemToDecks.ts → src/dataStore/itemTrans.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { TFile } from "obsidian";
import { CardScheduleInfo, NoteCardScheduleParser } from "src/CardSchedule";
import { Note } from "src/Note";
import { ReviewDeck } from "src/ReviewDeck";
import { ReviewDeck, SchedNote } from "src/ReviewDeck";
import { SrTFile } from "src/SRFile";
import { TopicPath } from "src/TopicPath";
import { DataStore } from "src/dataStore/data";
import { BlockUtils, debug, logExecutionTime } from "src/util/utils_recall";
import { CardInfo } from "./trackedFile";
import { Card } from "src/Card";
import { DataLocation } from "./dataLocation";
import { RPITEMTYPE } from "./repetitionItem";
import { RPITEMTYPE, RepetitionItem } from "./repetitionItem";
import { Tags } from "src/tags";
import { SRSettings } from "src/settings";
import { INoteEaseList } from "src/NoteEaseList";
import { algorithmNames } from "src/algorithms/algorithms";

export class ItemToDecks {
export class ItemTrans {
settings: SRSettings;

static create(settings: SRSettings) {
return new ItemToDecks(settings);
return new ItemTrans(settings);
}
constructor(settings: SRSettings) {
this.settings = settings;
Expand All @@ -39,7 +39,6 @@ export class ItemToDecks {
const store = DataStore.getInstance();
const settings = this.settings;
// store.data.queues.buildQueue();
const now = new Date().getTime();
notes.forEach(async (note) => {
let deckname = Tags.getNoteDeckName(note, this.settings);
if (deckname == null) {
Expand Down Expand Up @@ -74,27 +73,8 @@ export class ItemToDecks {
}
}
}
ItemToDecks.toRevDeck(reviewDecks[deckname], note);
ItemTrans._toRevDeck(reviewDecks[deckname], note);
}

// Add Recall reviewnote deck
// const dkname = DEFAULT_DECKNAME;
// if (!Object.prototype.hasOwnProperty.call(reviewDecks, dkname)) {
// reviewDecks[dkname] = new ReviewDeck(dkname);
// }

// store.data.trackedFiles
// .filter((trackedFile) => trackedFile?.noteID >= 0 && trackedFile.isTracked)
// .filter((trackedFile) => trackedFile.isDefault)
// .filter((trackedFile) => {
// // only add default deck.
// const note = app.vault.getAbstractFileByPath(trackedFile.path) as TFile;
// if (note instanceof TFile) {
// noteStats.updateStats(store.getItembyID(trackedFile.noteID));
// DataSyncer.syncRCDataToSRrevDeck(reviewDecks[deckName], note);
// return true;
// }
// });
});
return;
}
Expand All @@ -105,11 +85,9 @@ export class ItemToDecks {
* @param rdeck
* @returns
*/
static toRevDeck(rdeck: ReviewDeck, note: TFile, now?: number) {
private static _toRevDeck(rdeck: ReviewDeck, note: TFile, now?: number) {
// const plugin = plugin;
// const rdeck = reviewDecks[deckName];
const store = DataStore.getInstance();
// const queue = store.data.queues;
const ind = store.getFileIndex(note.path);
const trackedFile = store.getTrackedFile(note.path);
const item = store.getNoteItem(note.path);
Expand All @@ -125,13 +103,7 @@ export class ItemToDecks {
}

if (item.hasDue) {
rdeck.scheduledNotes.push({
note,
item,
dueUnix: item.nextReview,
interval: item.interval,
ease: item.ease,
});
rdeck.scheduledNotes.push(itemToShedNote(item, note));
} else {
rdeck.newNotes.push({ note, item });
}
Expand All @@ -146,7 +118,10 @@ export class ItemToDecks {
const store = DataStore.getInstance();
const settings = store.settings;
const noteFile: SrTFile = note.file as SrTFile;
if (topicPath.isEmptyPath || settings.dataLocation === DataLocation.SaveOnNoteFile) {
if (
note.questionList.length === 0 ||
settings.dataLocation === DataLocation.SaveOnNoteFile
) {
return;
}
if (store.getFileIndex(note.filePath) < 0) {
Expand Down Expand Up @@ -208,3 +183,13 @@ function updateCardObjs(cards: Card[], cardinfo: CardInfo, scheduling: RegExpMat
cardObj.Id = carditemIds[i];
}
}

export function itemToShedNote(item: RepetitionItem, note: TFile): SchedNote {
return {
note,
item,
dueUnix: item.nextReview,
interval: item.interval,
ease: item.ease,
};
}
7 changes: 5 additions & 2 deletions src/dataStore/trackedFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ export class TrackedFile implements ITrackedFile {
settings.convertBoldTextToClozes,
settings.convertCurlyBracketsToClozes,
);
if (!this.hasCards && parsedCards.length === 0) {
return false;
}

for (const parsedCard of parsedCards) {
// deckPath = noteDeckPath;
Expand Down Expand Up @@ -218,7 +221,7 @@ export class TrackedFile implements ITrackedFile {

// sync by total parsedCards.length
if (!this.hasCards) {
return;
return false;
}
const carditems = this?.cardItems;
if (lines.length === carditems.length && negIndFlag) {
Expand All @@ -233,7 +236,7 @@ export class TrackedFile implements ITrackedFile {
}
}
// store.save();
return;
return true;
}

get lastTag() {
Expand Down
4 changes: 2 additions & 2 deletions src/gui/FlashcardReviewView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ export class FlashcardReviewView {

private _processReviewbyAlgo(response: ReviewResponse) {
const algo = this.plugin.algorithm;
setDueDates(this.plugin.noteStats.delayedDays.dict, this.plugin.noteStats.delayedDays.dict);
setDueDates(this.plugin.cardStats.delayedDays.dict, this.plugin.cardStats.delayedDays.dict);
const opt = algo.srsOptions()[response];
const store = this.plugin.store;
const id = this._currentCard.Id;
Expand Down Expand Up @@ -506,7 +506,7 @@ export class FlashcardReviewView {
const srfile = this._currentNote.file as SrTFile;
const store = this.plugin.store;
const id = this._currentCard.Id;
const infoM = new ItemInfoModal(this.settings, srfile.file, store.getItembyID(id));
const infoM = new ItemInfoModal(this.plugin, srfile.file, store.getItembyID(id));
infoM.open();
});
}
Expand Down
58 changes: 33 additions & 25 deletions src/gui/info.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
import { ButtonComponent, Modal, Setting, TFile } from "obsidian";
import { ButtonComponent, MarkdownRenderer, Modal, Setting, TFile } from "obsidian";
import { algorithmNames } from "src/algorithms/algorithms";
import { AnkiData } from "src/algorithms/anki";
import { FsrsData } from "src/algorithms/fsrs";
import { DataStore } from "src/dataStore/data";
import { RepetitionItem } from "src/dataStore/repetitionItem";
import { TrackedFile } from "src/dataStore/trackedFile";
import SRPlugin from "src/main";
import { SRSettings } from "src/settings";

export class ItemInfoModal extends Modal {
// plugin: ObsidianSrsPlugin;
plugin: SRPlugin;
store: DataStore;
settings: SRSettings;
file: TFile;
item: RepetitionItem;
nextReview: number;
lastInterval: number;

constructor(settings: SRSettings, file: TFile, item: RepetitionItem = null) {
constructor(plugin: SRPlugin, file: TFile, item: RepetitionItem = null) {
super(app);
// this.plugin = plugin;
this.plugin = plugin;
this.store = DataStore.getInstance();
this.settings = settings;
this.settings = plugin.data.settings;
this.file = file;
if (item == null) {
this.item = this.store.getItemsOfFile(this.file.path)[0];
Expand Down Expand Up @@ -83,7 +84,8 @@ export class ItemInfoModal extends Modal {
items.forEach((item) => {
const divdetails = details.createEl("details");
const divsummary = divdetails.createEl("summary");
divsummary.setText("ID:" + item.ID.toString());
const dt = window.moment(item.nextReview).format("YYYY-MM-DD HH:mm:ss");
divsummary.setText(`ID: ${item.ID} \t nextReivew: ${dt}`);
const div = divdetails.createDiv();
this.displayitem(div, item);
});
Expand All @@ -100,42 +102,48 @@ export class ItemInfoModal extends Modal {
// contentEl.createDiv("li").setText(key+ ": "+ item[key])
// });
// type dataType = typeof plugin.algorithm.defaultData;
const title =
"key | value \n\
---|---\n";
let tablestr = "";
Object.keys(item).forEach((key) => {
if (key != "data") {
new Setting(contentdiv).setDesc(key).addText((text) => {
if (key === "nextReview") {
if (key === "nextReview") {
new Setting(contentdiv).setDesc(key).addText((text) => {
this.nextReview = undefined;
const dt = window.moment(item.nextReview).format("YYYY-MM-DD HH:mm:ss");
text.setValue(dt).onChange((value) => {
const nr = window.moment(value).valueOf();
this.nextReview = nr ?? 0;
});
} else {
text.setDisabled(true);
text.setValue(item[key as keyof typeof item]?.toString());
}
});
});
} else {
tablestr += `| ${key} | ${item[key as keyof typeof item]} |\n`;
// const span = contentdiv.createDiv("span");
// span.setText(key + "\t: " + item[key as keyof typeof item]?.toString());
}
}
});
MarkdownRenderer.render(this.plugin.app, title + tablestr, contentdiv, "", this.plugin);
contentdiv.createEl("p").setText("Item.data info");

const data = item.data as AnkiData;
tablestr = "";
Object.keys(item.data).forEach((key) => {
new Setting(contentdiv).setDesc(key).addText((text) => {
key = key as keyof typeof item.data;
if (key === "lastInterval") {
const dkey = key as keyof typeof item.data;
if (key === "lastInterval") {
const akey = key as keyof AnkiData;
new Setting(contentdiv).setDesc(key).addText((text) => {
const data = item.data as AnkiData;
this.lastInterval = undefined;
text.setValue(data[key]?.toString()).onChange((value) => {
text.setValue(data[akey]?.toString()).onChange((value) => {
this.lastInterval = Number(value) ?? 0;
});
} else {
text.setDisabled(true);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
text.setValue(data[key]?.toString());
}
});
});
} else {
tablestr += `| ${key} | ${item.data[dkey]} |\n`;
}
});
MarkdownRenderer.render(this.plugin.app, title + tablestr, contentdiv, "", this.plugin);
}

submit() {
Expand Down
Loading

0 comments on commit 7c60a10

Please sign in to comment.