From dac7f7e14dd246f825c55058d35d420c454b1df3 Mon Sep 17 00:00:00 2001 From: ishiko Date: Thu, 25 Jul 2024 09:02:47 +0800 Subject: [PATCH] Chore/add debugging folder (#102) --- .vscode/launch.json | 27 ++++++++++++++++++++ .vscode/setting.json | 6 +++++ debug/index.ts | 7 ++++++ debug/short-term.ts | 60 ++++++++++++++++++++++++++++++++++++++++++++ nodemon.json | 6 +++++ tsconfig.json | 9 ++++++- 6 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 .vscode/launch.json create mode 100644 .vscode/setting.json create mode 100644 debug/index.ts create mode 100644 debug/short-term.ts create mode 100644 nodemon.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..ee86ac8 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,27 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "ts-fsrs debug", + "skipFiles": ["/**"], + "env": { + // "DEBUG": "*", + }, + "outputCapture": "std", + "runtimeExecutable": "nodemon", + "restart": true, + "console": "integratedTerminal", + "cwd": "${workspaceFolder}", + "args": ["${workspaceFolder}/debug/index.ts"] + }, + { + "type": "node", + "request": "attach", + "name": "Node: Nodemon", + "processId": "${command:PickProcess}", + "restart": true + } + ] +} diff --git a/.vscode/setting.json b/.vscode/setting.json new file mode 100644 index 0000000..5f5fd74 --- /dev/null +++ b/.vscode/setting.json @@ -0,0 +1,6 @@ +{ + "typescript.preferences.importModuleSpecifier": "non-relative", + "typescript.preferences.quoteStyle": "single", + "typescript.preferGoToSourceDefinition": true, + "typescript.tsdk": "./node_modules/typescript/lib" +} \ No newline at end of file diff --git a/debug/index.ts b/debug/index.ts new file mode 100644 index 0000000..cacad02 --- /dev/null +++ b/debug/index.ts @@ -0,0 +1,7 @@ +import { FSRSVersion } from '../src/fsrs' +import { runShortTerm } from './short-term' + +console.log(FSRSVersion) + + +runShortTerm() \ No newline at end of file diff --git a/debug/short-term.ts b/debug/short-term.ts new file mode 100644 index 0000000..ca96747 --- /dev/null +++ b/debug/short-term.ts @@ -0,0 +1,60 @@ +import assert from 'assert' +import { createEmptyCard, fsrs, Grade, Rating } from '../src/fsrs' + +const f = fsrs() + +function test1() { + let card = createEmptyCard() + let now = new Date(2022, 11, 29, 12, 30, 0, 0) + const ratings: Grade[] = [ + Rating.Good, + Rating.Good, + Rating.Good, + Rating.Good, + Rating.Good, + Rating.Good, + Rating.Again, + Rating.Again, + Rating.Good, + Rating.Good, + Rating.Good, + Rating.Good, + Rating.Good, + ] + const ivl_history: number[] = [] + const s_history: number[] = [] + const d_history: number[] = [] + for (const rating of ratings) { + const record = f.repeat(card, now)[rating] + card = record.card + ivl_history.push(card.scheduled_days) + s_history.push(card.stability) + d_history.push(card.difficulty) + now = card.due + } + + assert.deepStrictEqual( + ivl_history, + [0, 4, 17, 57, 163, 412, 0, 0, 8, 15, 27, 49, 86] + ) + assert.deepStrictEqual( + s_history, + [ + 3.0412, 4.17286168, 16.55123695, 56.74378762, 163.35708827, 411.77071586, + 11.15423471, 5.75442486, 7.89570531, 14.90748589, 27.437534, 48.90521597, + 85.82782993, + ] + ) + assert.deepStrictEqual( + d_history, + [ + 4.49094334, 4.66971892, 4.83644502, 4.99193379, 5.13694261, 5.27217784, + 7.26480385, 9.12312687, 8.98969328, 8.86525311, 8.74920021, 8.64096928, + 8.54003311, + ] + ) +} + +export function runShortTerm() { + test1() +} diff --git a/nodemon.json b/nodemon.json new file mode 100644 index 0000000..51d5cdc --- /dev/null +++ b/nodemon.json @@ -0,0 +1,6 @@ +{ + "watch": ["./src/..","./debug/.."], + "ext": "ts", + "ignore": ["src/**/*.spec.ts"], + "exec": "npx ts-node --project ./tsconfig.json ./debug/index.ts" + } \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 492563e..7685f89 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -102,5 +102,12 @@ }, "include": ["src"], "exclude": ["node_modules", "**/__tests__/*"], - "detectCycles": true + "detectCycles": true, + "ts-node": { + "experimentalSpecifierResolution": "node", + "transpileOnly": true, // you can specify ts-node options here + "compilerOptions": { + "module": "commonjs" // you can also override compilerOptions. Only ts-node will use these overrides + } + }, }