Skip to content

Commit

Permalink
Merge pull request #155 from st3v3nmw/develop
Browse files Browse the repository at this point in the history
Cards forecast stats
  • Loading branch information
st3v3nmw committed Jun 12, 2021
2 parents 356fd31 + ab52d36 commit 3bc29c4
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 3 deletions.
12 changes: 11 additions & 1 deletion src/main.ts
Expand Up @@ -9,6 +9,7 @@ import {
import * as graph from "pagerank.js";
import { SRSettingTab, DEFAULT_SETTINGS, getSetting } from "./settings";
import { FlashcardModal } from "./flashcard-modal";
import { StatsModal } from "./stats-modal";
import { ReviewQueueListView, REVIEW_QUEUE_VIEW_TYPE } from "./sidebar";
import { schedule } from "./sched";
import {
Expand Down Expand Up @@ -210,6 +211,14 @@ export default class SRPlugin extends Plugin {
},
});

this.addCommand({
id: "srs-view-stats",
name: "View statistics",
callback: () => {
new StatsModal(this.app, this.dueDatesFlashcards).open();
},
});

this.addSettingTab(new SRSettingTab(this.app, this));

this.app.workspace.onLayoutReady(() => {
Expand Down Expand Up @@ -752,7 +761,8 @@ export default class SRPlugin extends Plugin {
if (!this.dueDatesFlashcards.hasOwnProperty(nDays))
this.dueDatesFlashcards[nDays] = 0;
this.dueDatesFlashcards[nDays]++;
if (this.data.buryList.includes(cyrb53(cardText))) continue;
if (this.data.buryList.includes(cyrb53(cardText)))
continue;

if (dueUnix <= now) {
cardObj = {
Expand Down
6 changes: 4 additions & 2 deletions src/sidebar.ts
Expand Up @@ -155,7 +155,7 @@ export class ReviewQueueListView extends ItemView {
}
});

return childrenEl;
return folderEl;
}

private createRightPaneFile(
Expand All @@ -164,7 +164,9 @@ export class ReviewQueueListView extends ItemView {
fileElActive: boolean,
hidden: boolean
) {
const navFileEl: HTMLElement = folderEl.createDiv("nav-file");
const navFileEl: HTMLElement = folderEl
.getElementsByClassName("nav-folder-children")[0]
.createDiv("nav-file");
if (hidden) navFileEl.style.display = "none";

const navFileTitle: HTMLElement = navFileEl.createDiv("nav-file-title");
Expand Down
53 changes: 53 additions & 0 deletions src/stats-modal.ts
@@ -0,0 +1,53 @@
import { Modal, App, MarkdownRenderer, Notice, Platform } from "obsidian";

export class StatsModal extends Modal {
private dueDatesFlashcards: Record<number, number>;

constructor(app: App, dueDatesFlashcards: Record<number, number>) {
super(app);

this.dueDatesFlashcards = dueDatesFlashcards;

this.titleEl.setText("Statistics");

if (Platform.isMobile) {
this.modalEl.style.height = "100%";
this.modalEl.style.width = "100%";
this.contentEl.style.display = "block";
} else {
this.modalEl.style.height = "100%";
this.modalEl.style.width = "100%";
}
}

onOpen() {
let { contentEl } = this;

contentEl.innerHTML +=
"<div style='text-align:center'>" +
"<span>Note that this requires the Obsidian Charts plugin to work</span>" +
"<h2 style='text-align:center'>Forecast</h2>" +
"<h4 style='text-align:center'>The number of cards due in the future</h4>" +
"</div>";

let text =
"```chart\n" +
"\ttype: bar\n" +
`\tlabels: [${Object.keys(this.dueDatesFlashcards)}]\n` +
"\tseries:\n" +
"\t\t- title: Scheduled\n" +
`\t\t data: [${Object.values(this.dueDatesFlashcards)}]\n` +
'\txTitle: "Days"\n' +
'\tyTitle: "Number of cards"\n' +
"\tlegend: false\n" +
"\tstacked: true\n" +
"````";

MarkdownRenderer.renderMarkdown(text, contentEl, null, null);
}

onClose() {
let { contentEl } = this;
contentEl.empty();
}
}

0 comments on commit 3bc29c4

Please sign in to comment.