@vue-skuilder/db 0.1.18 → 0.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +2 -2
- package/dist/{classroomDB-BgfrVb8d.d.ts → contentSource-BP9hznNV.d.ts} +220 -197
- package/dist/{classroomDB-CTOenngH.d.cts → contentSource-DsJadoBU.d.cts} +220 -197
- package/dist/core/index.d.cts +80 -6
- package/dist/core/index.d.ts +80 -6
- package/dist/core/index.js +735 -1560
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.mjs +708 -1539
- package/dist/core/index.mjs.map +1 -1
- package/dist/{dataLayerProvider-D6PoCwS6.d.cts → dataLayerProvider-CHYrQ5pB.d.cts} +1 -1
- package/dist/{dataLayerProvider-CZxC9GtB.d.ts → dataLayerProvider-MDTxXq2l.d.ts} +1 -1
- package/dist/impl/couch/index.d.cts +8 -23
- package/dist/impl/couch/index.d.ts +8 -23
- package/dist/impl/couch/index.js +723 -1578
- package/dist/impl/couch/index.js.map +1 -1
- package/dist/impl/couch/index.mjs +692 -1552
- package/dist/impl/couch/index.mjs.map +1 -1
- package/dist/impl/static/index.d.cts +25 -8
- package/dist/impl/static/index.d.ts +25 -8
- package/dist/impl/static/index.js +700 -1400
- package/dist/impl/static/index.js.map +1 -1
- package/dist/impl/static/index.mjs +688 -1393
- package/dist/impl/static/index.mjs.map +1 -1
- package/dist/{index-D-Fa4Smt.d.cts → index-B_j6u5E4.d.cts} +1 -1
- package/dist/{index-CD8BZz2k.d.ts → index-Dj0SEgk3.d.ts} +1 -1
- package/dist/index.d.cts +71 -63
- package/dist/index.d.ts +71 -63
- package/dist/index.js +1162 -1996
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1124 -1955
- package/dist/index.mjs.map +1 -1
- package/dist/pouch/index.js +3 -0
- package/dist/pouch/index.js.map +1 -1
- package/dist/pouch/index.mjs +3 -0
- package/dist/pouch/index.mjs.map +1 -1
- package/dist/{types-CzPDLAK6.d.cts → types-Bn0itutr.d.cts} +1 -1
- package/dist/{types-CewsN87z.d.ts → types-DQaXnuoc.d.ts} +1 -1
- package/dist/{types-legacy-6ettoclI.d.cts → types-legacy-DDY4N-Uq.d.cts} +3 -1
- package/dist/{types-legacy-6ettoclI.d.ts → types-legacy-DDY4N-Uq.d.ts} +3 -1
- package/dist/util/packer/index.d.cts +3 -3
- package/dist/util/packer/index.d.ts +3 -3
- package/docs/navigators-architecture.md +115 -17
- package/package.json +4 -4
- package/src/core/index.ts +1 -0
- package/src/core/interfaces/classroomDB.ts +5 -13
- package/src/core/interfaces/contentSource.ts +6 -66
- package/src/core/interfaces/courseDB.ts +15 -7
- package/src/core/interfaces/userDB.ts +32 -0
- package/src/core/navigators/Pipeline.ts +136 -52
- package/src/core/navigators/PipelineAssembler.ts +1 -1
- package/src/core/navigators/defaults.ts +84 -0
- package/src/core/navigators/{hierarchyDefinition.ts → filters/hierarchyDefinition.ts} +15 -29
- package/src/core/navigators/filters/index.ts +3 -0
- package/src/core/navigators/filters/inferredPreferenceStub.ts +107 -0
- package/src/core/navigators/{interferenceMitigator.ts → filters/interferenceMitigator.ts} +11 -37
- package/src/core/navigators/{relativePriority.ts → filters/relativePriority.ts} +12 -38
- package/src/core/navigators/filters/userGoalStub.ts +136 -0
- package/src/core/navigators/filters/userTagPreference.ts +217 -0
- package/src/core/navigators/{CompositeGenerator.ts → generators/CompositeGenerator.ts} +15 -64
- package/src/core/navigators/{elo.ts → generators/elo.ts} +13 -63
- package/src/core/navigators/{srs.ts → generators/srs.ts} +11 -40
- package/src/core/navigators/generators/types.ts +1 -1
- package/src/core/navigators/index.ts +95 -91
- package/src/core/types/strategyState.ts +84 -0
- package/src/core/types/types-legacy.ts +2 -0
- package/src/impl/common/BaseUserDB.ts +74 -7
- package/src/impl/couch/adminDB.ts +1 -2
- package/src/impl/couch/classroomDB.ts +100 -103
- package/src/impl/couch/courseDB.ts +35 -91
- package/src/impl/couch/pouchdb-setup.ts +7 -0
- package/src/impl/static/StaticDataUnpacker.ts +50 -1
- package/src/impl/static/courseDB.ts +87 -37
- package/src/study/SessionController.ts +122 -202
- package/src/study/SourceMixer.ts +65 -0
- package/src/study/TagFilteredContentSource.ts +49 -92
- package/src/study/index.ts +1 -0
- package/src/study/services/CardHydrationService.ts +165 -81
- package/src/util/dataDirectory.ts +1 -1
- package/src/util/index.ts +0 -1
- package/tests/core/navigators/CompositeGenerator.test.ts +44 -168
- package/tests/core/navigators/Pipeline.test.ts +6 -72
- package/tests/core/navigators/PipelineAssembler.test.ts +8 -58
- package/tests/core/navigators/navigators.test.ts +118 -151
- package/docs/todo-pipeline-optimization.md +0 -117
- package/docs/todo-strategy-state-storage.md +0 -278
- package/src/core/navigators/hardcodedOrder.ts +0 -163
- package/src/util/tuiLogger.ts +0 -139
package/dist/core/index.mjs
CHANGED
|
@@ -1,17 +1,7 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
1
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
-
var __glob = (map) => (path2) => {
|
|
4
|
-
var fn = map[path2];
|
|
5
|
-
if (fn) return fn();
|
|
6
|
-
throw new Error("Module not found in bundle: " + path2);
|
|
7
|
-
};
|
|
8
2
|
var __esm = (fn, res) => function __init() {
|
|
9
3
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
10
4
|
};
|
|
11
|
-
var __export = (target, all) => {
|
|
12
|
-
for (var name in all)
|
|
13
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
14
|
-
};
|
|
15
5
|
|
|
16
6
|
// src/core/interfaces/adminDB.ts
|
|
17
7
|
var init_adminDB = __esm({
|
|
@@ -100,6 +90,7 @@ var init_types_legacy = __esm({
|
|
|
100
90
|
DocType2["SCHEDULED_CARD"] = "SCHEDULED_CARD";
|
|
101
91
|
DocType2["TAG"] = "TAG";
|
|
102
92
|
DocType2["NAVIGATION_STRATEGY"] = "NAVIGATION_STRATEGY";
|
|
93
|
+
DocType2["STRATEGY_STATE"] = "STRATEGY_STATE";
|
|
103
94
|
return DocType2;
|
|
104
95
|
})(DocType || {});
|
|
105
96
|
DocTypePrefixes = {
|
|
@@ -113,7 +104,8 @@ var init_types_legacy = __esm({
|
|
|
113
104
|
["QUESTION" /* QUESTIONTYPE */]: "QUESTION",
|
|
114
105
|
["VIEW" /* VIEW */]: "VIEW",
|
|
115
106
|
["PEDAGOGY" /* PEDAGOGY */]: "PEDAGOGY",
|
|
116
|
-
["NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */]: "NAVIGATION_STRATEGY"
|
|
107
|
+
["NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */]: "NAVIGATION_STRATEGY",
|
|
108
|
+
["STRATEGY_STATE" /* STRATEGY_STATE */]: "STRATEGY_STATE"
|
|
117
109
|
};
|
|
118
110
|
}
|
|
119
111
|
});
|
|
@@ -164,6 +156,9 @@ var init_pouchdb_setup = __esm({
|
|
|
164
156
|
"use strict";
|
|
165
157
|
PouchDB.plugin(PouchDBFind);
|
|
166
158
|
PouchDB.plugin(PouchDBAuth);
|
|
159
|
+
if (typeof PouchDB.debug !== "undefined") {
|
|
160
|
+
PouchDB.debug.disable();
|
|
161
|
+
}
|
|
167
162
|
PouchDB.defaults({
|
|
168
163
|
// ajax: {
|
|
169
164
|
// timeout: 60000,
|
|
@@ -173,14 +168,6 @@ var init_pouchdb_setup = __esm({
|
|
|
173
168
|
}
|
|
174
169
|
});
|
|
175
170
|
|
|
176
|
-
// src/util/tuiLogger.ts
|
|
177
|
-
var init_tuiLogger = __esm({
|
|
178
|
-
"src/util/tuiLogger.ts"() {
|
|
179
|
-
"use strict";
|
|
180
|
-
init_dataDirectory();
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
|
|
184
171
|
// src/util/dataDirectory.ts
|
|
185
172
|
import * as path from "path";
|
|
186
173
|
import * as os from "os";
|
|
@@ -197,7 +184,7 @@ function getDbPath(dbName) {
|
|
|
197
184
|
var init_dataDirectory = __esm({
|
|
198
185
|
"src/util/dataDirectory.ts"() {
|
|
199
186
|
"use strict";
|
|
200
|
-
|
|
187
|
+
init_logger();
|
|
201
188
|
init_factory();
|
|
202
189
|
}
|
|
203
190
|
});
|
|
@@ -686,24 +673,359 @@ var init_courseLookupDB = __esm({
|
|
|
686
673
|
}
|
|
687
674
|
});
|
|
688
675
|
|
|
689
|
-
// src/core/navigators/
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
676
|
+
// src/core/navigators/index.ts
|
|
677
|
+
function getCardOrigin(card) {
|
|
678
|
+
if (card.provenance.length === 0) {
|
|
679
|
+
throw new Error("Card has no provenance - cannot determine origin");
|
|
680
|
+
}
|
|
681
|
+
const firstEntry = card.provenance[0];
|
|
682
|
+
const reason = firstEntry.reason.toLowerCase();
|
|
683
|
+
if (reason.includes("failed")) {
|
|
684
|
+
return "failed";
|
|
685
|
+
}
|
|
686
|
+
if (reason.includes("review")) {
|
|
687
|
+
return "review";
|
|
688
|
+
}
|
|
689
|
+
return "new";
|
|
690
|
+
}
|
|
691
|
+
function isGenerator(impl) {
|
|
692
|
+
return NavigatorRoles[impl] === "generator" /* GENERATOR */;
|
|
693
|
+
}
|
|
694
|
+
function isFilter(impl) {
|
|
695
|
+
return NavigatorRoles[impl] === "filter" /* FILTER */;
|
|
696
|
+
}
|
|
697
|
+
var Navigators, NavigatorRole, NavigatorRoles, ContentNavigator;
|
|
698
|
+
var init_navigators = __esm({
|
|
699
|
+
"src/core/navigators/index.ts"() {
|
|
700
|
+
"use strict";
|
|
701
|
+
init_logger();
|
|
702
|
+
Navigators = /* @__PURE__ */ ((Navigators2) => {
|
|
703
|
+
Navigators2["ELO"] = "elo";
|
|
704
|
+
Navigators2["SRS"] = "srs";
|
|
705
|
+
Navigators2["HIERARCHY"] = "hierarchyDefinition";
|
|
706
|
+
Navigators2["INTERFERENCE"] = "interferenceMitigator";
|
|
707
|
+
Navigators2["RELATIVE_PRIORITY"] = "relativePriority";
|
|
708
|
+
Navigators2["USER_TAG_PREFERENCE"] = "userTagPreference";
|
|
709
|
+
return Navigators2;
|
|
710
|
+
})(Navigators || {});
|
|
711
|
+
NavigatorRole = /* @__PURE__ */ ((NavigatorRole2) => {
|
|
712
|
+
NavigatorRole2["GENERATOR"] = "generator";
|
|
713
|
+
NavigatorRole2["FILTER"] = "filter";
|
|
714
|
+
return NavigatorRole2;
|
|
715
|
+
})(NavigatorRole || {});
|
|
716
|
+
NavigatorRoles = {
|
|
717
|
+
["elo" /* ELO */]: "generator" /* GENERATOR */,
|
|
718
|
+
["srs" /* SRS */]: "generator" /* GENERATOR */,
|
|
719
|
+
["hierarchyDefinition" /* HIERARCHY */]: "filter" /* FILTER */,
|
|
720
|
+
["interferenceMitigator" /* INTERFERENCE */]: "filter" /* FILTER */,
|
|
721
|
+
["relativePriority" /* RELATIVE_PRIORITY */]: "filter" /* FILTER */,
|
|
722
|
+
["userTagPreference" /* USER_TAG_PREFERENCE */]: "filter" /* FILTER */
|
|
723
|
+
};
|
|
724
|
+
ContentNavigator = class {
|
|
725
|
+
/** User interface for this navigation session */
|
|
726
|
+
user;
|
|
727
|
+
/** Course interface for this navigation session */
|
|
728
|
+
course;
|
|
729
|
+
/** Human-readable name for this strategy instance (from ContentNavigationStrategyData.name) */
|
|
730
|
+
strategyName;
|
|
731
|
+
/** Unique document ID for this strategy instance (from ContentNavigationStrategyData._id) */
|
|
732
|
+
strategyId;
|
|
733
|
+
/**
|
|
734
|
+
* Constructor for standard navigators.
|
|
735
|
+
* Call this from subclass constructors to initialize common fields.
|
|
736
|
+
*
|
|
737
|
+
* Note: CompositeGenerator and Pipeline call super() without args, then set
|
|
738
|
+
* user/course fields directly if needed.
|
|
739
|
+
*/
|
|
740
|
+
constructor(user, course, strategyData) {
|
|
741
|
+
this.user = user;
|
|
742
|
+
this.course = course;
|
|
743
|
+
if (strategyData) {
|
|
744
|
+
this.strategyName = strategyData.name;
|
|
745
|
+
this.strategyId = strategyData._id;
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
// ============================================================================
|
|
749
|
+
// STRATEGY STATE HELPERS
|
|
750
|
+
// ============================================================================
|
|
751
|
+
//
|
|
752
|
+
// These methods allow strategies to persist their own state (user preferences,
|
|
753
|
+
// learned patterns, temporal tracking) in the user database.
|
|
754
|
+
//
|
|
755
|
+
// ============================================================================
|
|
756
|
+
/**
|
|
757
|
+
* Unique key identifying this strategy for state storage.
|
|
758
|
+
*
|
|
759
|
+
* Defaults to the constructor name (e.g., "UserTagPreferenceFilter").
|
|
760
|
+
* Override in subclasses if multiple instances of the same strategy type
|
|
761
|
+
* need separate state storage.
|
|
762
|
+
*/
|
|
763
|
+
get strategyKey() {
|
|
764
|
+
return this.constructor.name;
|
|
765
|
+
}
|
|
766
|
+
/**
|
|
767
|
+
* Get this strategy's persisted state for the current course.
|
|
768
|
+
*
|
|
769
|
+
* @returns The strategy's data payload, or null if no state exists
|
|
770
|
+
* @throws Error if user or course is not initialized
|
|
771
|
+
*/
|
|
772
|
+
async getStrategyState() {
|
|
773
|
+
if (!this.user || !this.course) {
|
|
774
|
+
throw new Error(
|
|
775
|
+
`Cannot get strategy state: navigator not properly initialized. Ensure user and course are provided to constructor.`
|
|
776
|
+
);
|
|
777
|
+
}
|
|
778
|
+
return this.user.getStrategyState(this.course.getCourseID(), this.strategyKey);
|
|
779
|
+
}
|
|
780
|
+
/**
|
|
781
|
+
* Persist this strategy's state for the current course.
|
|
782
|
+
*
|
|
783
|
+
* @param data - The strategy's data payload to store
|
|
784
|
+
* @throws Error if user or course is not initialized
|
|
785
|
+
*/
|
|
786
|
+
async putStrategyState(data) {
|
|
787
|
+
if (!this.user || !this.course) {
|
|
788
|
+
throw new Error(
|
|
789
|
+
`Cannot put strategy state: navigator not properly initialized. Ensure user and course are provided to constructor.`
|
|
790
|
+
);
|
|
791
|
+
}
|
|
792
|
+
return this.user.putStrategyState(this.course.getCourseID(), this.strategyKey, data);
|
|
793
|
+
}
|
|
794
|
+
/**
|
|
795
|
+
* Factory method to create navigator instances dynamically.
|
|
796
|
+
*
|
|
797
|
+
* @param user - User interface
|
|
798
|
+
* @param course - Course interface
|
|
799
|
+
* @param strategyData - Strategy configuration document
|
|
800
|
+
* @returns the runtime object used to steer a study session.
|
|
801
|
+
*/
|
|
802
|
+
static async create(user, course, strategyData) {
|
|
803
|
+
const implementingClass = strategyData.implementingClass;
|
|
804
|
+
let NavigatorImpl;
|
|
805
|
+
const variations = [".ts", ".js", ""];
|
|
806
|
+
const dirs = ["filters", "generators"];
|
|
807
|
+
for (const ext of variations) {
|
|
808
|
+
for (const dir of dirs) {
|
|
809
|
+
const loadFrom = `./${dir}/${implementingClass}${ext}`;
|
|
810
|
+
try {
|
|
811
|
+
const module = await import(loadFrom);
|
|
812
|
+
NavigatorImpl = module.default;
|
|
813
|
+
break;
|
|
814
|
+
} catch (e) {
|
|
815
|
+
logger.debug(`Failed to load extension from ${loadFrom}:`, e);
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
if (!NavigatorImpl) {
|
|
820
|
+
throw new Error(`Could not load navigator implementation for: ${implementingClass}`);
|
|
821
|
+
}
|
|
822
|
+
return new NavigatorImpl(user, course, strategyData);
|
|
823
|
+
}
|
|
824
|
+
/**
|
|
825
|
+
* Get cards with suitability scores and provenance trails.
|
|
826
|
+
*
|
|
827
|
+
* **This is the PRIMARY API for navigation strategies.**
|
|
828
|
+
*
|
|
829
|
+
* Returns cards ranked by suitability score (0-1). Higher scores indicate
|
|
830
|
+
* better candidates for presentation. Each card includes a provenance trail
|
|
831
|
+
* documenting how strategies contributed to the final score.
|
|
832
|
+
*
|
|
833
|
+
* ## Implementation Required
|
|
834
|
+
* All navigation strategies MUST override this method. The base class does
|
|
835
|
+
* not provide a default implementation.
|
|
836
|
+
*
|
|
837
|
+
* ## For Generators
|
|
838
|
+
* Override this method to generate candidates and compute scores based on
|
|
839
|
+
* your strategy's logic (e.g., ELO proximity, review urgency). Create the
|
|
840
|
+
* initial provenance entry with action='generated'.
|
|
841
|
+
*
|
|
842
|
+
* ## For Filters
|
|
843
|
+
* Filters should implement the CardFilter interface instead and be composed
|
|
844
|
+
* via Pipeline. Filters do not directly implement getWeightedCards().
|
|
845
|
+
*
|
|
846
|
+
* @param limit - Maximum cards to return
|
|
847
|
+
* @returns Cards sorted by score descending, with provenance trails
|
|
848
|
+
*/
|
|
849
|
+
async getWeightedCards(_limit) {
|
|
850
|
+
throw new Error(`${this.constructor.name} must implement getWeightedCards(). `);
|
|
851
|
+
}
|
|
852
|
+
};
|
|
853
|
+
}
|
|
854
|
+
});
|
|
855
|
+
|
|
856
|
+
// src/core/navigators/Pipeline.ts
|
|
857
|
+
import { toCourseElo as toCourseElo2 } from "@vue-skuilder/common";
|
|
858
|
+
function logPipelineConfig(generator, filters) {
|
|
859
|
+
const filterList = filters.length > 0 ? "\n - " + filters.map((f) => f.name).join("\n - ") : " none";
|
|
860
|
+
logger.info(
|
|
861
|
+
`[Pipeline] Configuration:
|
|
862
|
+
Generator: ${generator.name}
|
|
863
|
+
Filters:${filterList}`
|
|
864
|
+
);
|
|
865
|
+
}
|
|
866
|
+
function logTagHydration(cards, tagsByCard) {
|
|
867
|
+
const totalTags = Array.from(tagsByCard.values()).reduce((sum, tags) => sum + tags.length, 0);
|
|
868
|
+
const cardsWithTags = Array.from(tagsByCard.values()).filter((tags) => tags.length > 0).length;
|
|
869
|
+
logger.debug(
|
|
870
|
+
`[Pipeline] Tag hydration: ${cards.length} cards, ${cardsWithTags} have tags (${totalTags} total tags) - single batch query`
|
|
871
|
+
);
|
|
872
|
+
}
|
|
873
|
+
function logExecutionSummary(generatorName, generatedCount, filterCount, finalCount, topScores) {
|
|
874
|
+
const scoreDisplay = topScores.length > 0 ? topScores.map((s) => s.toFixed(2)).join(", ") : "none";
|
|
875
|
+
logger.info(
|
|
876
|
+
`[Pipeline] Execution: ${generatorName} produced ${generatedCount} \u2192 ${filterCount} filters \u2192 ${finalCount} results (top scores: ${scoreDisplay})`
|
|
877
|
+
);
|
|
878
|
+
}
|
|
879
|
+
function logCardProvenance(cards, maxCards = 3) {
|
|
880
|
+
const cardsToLog = cards.slice(0, maxCards);
|
|
881
|
+
logger.debug(`[Pipeline] Provenance for top ${cardsToLog.length} cards:`);
|
|
882
|
+
for (const card of cardsToLog) {
|
|
883
|
+
logger.debug(`[Pipeline] ${card.cardId} (final score: ${card.score.toFixed(3)}):`);
|
|
884
|
+
for (const entry of card.provenance) {
|
|
885
|
+
const scoreChange = entry.score.toFixed(3);
|
|
886
|
+
const action = entry.action.padEnd(9);
|
|
887
|
+
logger.debug(
|
|
888
|
+
`[Pipeline] ${action} ${scoreChange} - ${entry.strategyName}: ${entry.reason}`
|
|
889
|
+
);
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
var Pipeline;
|
|
894
|
+
var init_Pipeline = __esm({
|
|
895
|
+
"src/core/navigators/Pipeline.ts"() {
|
|
896
|
+
"use strict";
|
|
897
|
+
init_navigators();
|
|
898
|
+
init_logger();
|
|
899
|
+
Pipeline = class extends ContentNavigator {
|
|
900
|
+
generator;
|
|
901
|
+
filters;
|
|
902
|
+
/**
|
|
903
|
+
* Create a new pipeline.
|
|
904
|
+
*
|
|
905
|
+
* @param generator - The generator (or CompositeGenerator) that produces candidates
|
|
906
|
+
* @param filters - Filters to apply sequentially (order doesn't matter for multipliers)
|
|
907
|
+
* @param user - User database interface
|
|
908
|
+
* @param course - Course database interface
|
|
909
|
+
*/
|
|
910
|
+
constructor(generator, filters, user, course) {
|
|
911
|
+
super();
|
|
912
|
+
this.generator = generator;
|
|
913
|
+
this.filters = filters;
|
|
914
|
+
this.user = user;
|
|
915
|
+
this.course = course;
|
|
916
|
+
course.getCourseConfig().then((cfg) => {
|
|
917
|
+
logger.debug(`[pipeline] Crated pipeline for ${cfg.name}`);
|
|
918
|
+
}).catch((e) => {
|
|
919
|
+
logger.error(`[pipeline] Failed to lookup courseCfg: ${e}`);
|
|
920
|
+
});
|
|
921
|
+
logPipelineConfig(generator, filters);
|
|
922
|
+
}
|
|
923
|
+
/**
|
|
924
|
+
* Get weighted cards by running generator and applying filters.
|
|
925
|
+
*
|
|
926
|
+
* 1. Build shared context (user ELO, etc.)
|
|
927
|
+
* 2. Get candidates from generator (passing context)
|
|
928
|
+
* 3. Batch hydrate tags for all candidates
|
|
929
|
+
* 4. Apply each filter sequentially
|
|
930
|
+
* 5. Remove zero-score cards
|
|
931
|
+
* 6. Sort by score descending
|
|
932
|
+
* 7. Return top N
|
|
933
|
+
*
|
|
934
|
+
* @param limit - Maximum number of cards to return
|
|
935
|
+
* @returns Cards sorted by score descending
|
|
936
|
+
*/
|
|
937
|
+
async getWeightedCards(limit) {
|
|
938
|
+
const context = await this.buildContext();
|
|
939
|
+
const overFetchMultiplier = 2 + this.filters.length * 0.5;
|
|
940
|
+
const fetchLimit = Math.ceil(limit * overFetchMultiplier);
|
|
941
|
+
logger.debug(
|
|
942
|
+
`[Pipeline] Fetching ${fetchLimit} candidates from generator '${this.generator.name}'`
|
|
943
|
+
);
|
|
944
|
+
let cards = await this.generator.getWeightedCards(fetchLimit, context);
|
|
945
|
+
const generatedCount = cards.length;
|
|
946
|
+
logger.debug(`[Pipeline] Generator returned ${generatedCount} candidates`);
|
|
947
|
+
cards = await this.hydrateTags(cards);
|
|
948
|
+
for (const filter of this.filters) {
|
|
949
|
+
const beforeCount = cards.length;
|
|
950
|
+
cards = await filter.transform(cards, context);
|
|
951
|
+
logger.debug(`[Pipeline] Filter '${filter.name}': ${beforeCount} \u2192 ${cards.length} cards`);
|
|
952
|
+
}
|
|
953
|
+
cards = cards.filter((c) => c.score > 0);
|
|
954
|
+
cards.sort((a, b) => b.score - a.score);
|
|
955
|
+
const result = cards.slice(0, limit);
|
|
956
|
+
const topScores = result.slice(0, 3).map((c) => c.score);
|
|
957
|
+
logExecutionSummary(
|
|
958
|
+
this.generator.name,
|
|
959
|
+
generatedCount,
|
|
960
|
+
this.filters.length,
|
|
961
|
+
result.length,
|
|
962
|
+
topScores
|
|
963
|
+
);
|
|
964
|
+
logCardProvenance(result, 3);
|
|
965
|
+
return result;
|
|
966
|
+
}
|
|
967
|
+
/**
|
|
968
|
+
* Batch hydrate tags for all cards.
|
|
969
|
+
*
|
|
970
|
+
* Fetches tags for all cards in a single database query and attaches them
|
|
971
|
+
* to the WeightedCard objects. Filters can then use card.tags instead of
|
|
972
|
+
* making individual getAppliedTags() calls.
|
|
973
|
+
*
|
|
974
|
+
* @param cards - Cards to hydrate
|
|
975
|
+
* @returns Cards with tags populated
|
|
976
|
+
*/
|
|
977
|
+
async hydrateTags(cards) {
|
|
978
|
+
if (cards.length === 0) {
|
|
979
|
+
return cards;
|
|
980
|
+
}
|
|
981
|
+
const cardIds = cards.map((c) => c.cardId);
|
|
982
|
+
const tagsByCard = await this.course.getAppliedTagsBatch(cardIds);
|
|
983
|
+
logTagHydration(cards, tagsByCard);
|
|
984
|
+
return cards.map((card) => ({
|
|
985
|
+
...card,
|
|
986
|
+
tags: tagsByCard.get(card.cardId) ?? []
|
|
987
|
+
}));
|
|
988
|
+
}
|
|
989
|
+
/**
|
|
990
|
+
* Build shared context for generator and filters.
|
|
991
|
+
*
|
|
992
|
+
* Called once per getWeightedCards() invocation.
|
|
993
|
+
* Contains data that the generator and multiple filters might need.
|
|
994
|
+
*
|
|
995
|
+
* The context satisfies both GeneratorContext and FilterContext interfaces.
|
|
996
|
+
*/
|
|
997
|
+
async buildContext() {
|
|
998
|
+
let userElo = 1e3;
|
|
999
|
+
try {
|
|
1000
|
+
const courseReg = await this.user.getCourseRegDoc(this.course.getCourseID());
|
|
1001
|
+
const courseElo = toCourseElo2(courseReg.elo);
|
|
1002
|
+
userElo = courseElo.global.score;
|
|
1003
|
+
} catch (e) {
|
|
1004
|
+
logger.debug(`[Pipeline] Could not get user ELO, using default: ${e}`);
|
|
1005
|
+
}
|
|
1006
|
+
return {
|
|
1007
|
+
user: this.user,
|
|
1008
|
+
course: this.course,
|
|
1009
|
+
userElo
|
|
1010
|
+
};
|
|
1011
|
+
}
|
|
1012
|
+
/**
|
|
1013
|
+
* Get the course ID for this pipeline.
|
|
1014
|
+
*/
|
|
1015
|
+
getCourseID() {
|
|
1016
|
+
return this.course.getCourseID();
|
|
1017
|
+
}
|
|
1018
|
+
};
|
|
1019
|
+
}
|
|
694
1020
|
});
|
|
695
|
-
|
|
1021
|
+
|
|
1022
|
+
// src/core/navigators/generators/CompositeGenerator.ts
|
|
1023
|
+
var DEFAULT_AGGREGATION_MODE, FREQUENCY_BOOST_FACTOR, CompositeGenerator;
|
|
696
1024
|
var init_CompositeGenerator = __esm({
|
|
697
|
-
"src/core/navigators/CompositeGenerator.ts"() {
|
|
1025
|
+
"src/core/navigators/generators/CompositeGenerator.ts"() {
|
|
698
1026
|
"use strict";
|
|
699
1027
|
init_navigators();
|
|
700
1028
|
init_logger();
|
|
701
|
-
AggregationMode = /* @__PURE__ */ ((AggregationMode2) => {
|
|
702
|
-
AggregationMode2["MAX"] = "max";
|
|
703
|
-
AggregationMode2["AVERAGE"] = "average";
|
|
704
|
-
AggregationMode2["FREQUENCY_BOOST"] = "frequencyBoost";
|
|
705
|
-
return AggregationMode2;
|
|
706
|
-
})(AggregationMode || {});
|
|
707
1029
|
DEFAULT_AGGREGATION_MODE = "frequencyBoost" /* FREQUENCY_BOOST */;
|
|
708
1030
|
FREQUENCY_BOOST_FACTOR = 0.1;
|
|
709
1031
|
CompositeGenerator = class _CompositeGenerator extends ContentNavigator {
|
|
@@ -743,9 +1065,14 @@ var init_CompositeGenerator = __esm({
|
|
|
743
1065
|
* CardGenerator interface signature (limit, context).
|
|
744
1066
|
*
|
|
745
1067
|
* @param limit - Maximum number of cards to return
|
|
746
|
-
* @param context -
|
|
1068
|
+
* @param context - GeneratorContext passed to child generators (required when called via Pipeline)
|
|
747
1069
|
*/
|
|
748
1070
|
async getWeightedCards(limit, context) {
|
|
1071
|
+
if (!context) {
|
|
1072
|
+
throw new Error(
|
|
1073
|
+
"CompositeGenerator.getWeightedCards requires a GeneratorContext. It should be called via Pipeline, not directly."
|
|
1074
|
+
);
|
|
1075
|
+
}
|
|
749
1076
|
const results = await Promise.all(
|
|
750
1077
|
this.generators.map((g) => g.getWeightedCards(limit, context))
|
|
751
1078
|
);
|
|
@@ -826,183 +1153,11 @@ var init_CompositeGenerator = __esm({
|
|
|
826
1153
|
return scores[0];
|
|
827
1154
|
}
|
|
828
1155
|
}
|
|
829
|
-
/**
|
|
830
|
-
* Get new cards from all generators, merged and deduplicated.
|
|
831
|
-
*/
|
|
832
|
-
async getNewCards(n) {
|
|
833
|
-
const legacyGenerators = this.generators.filter(
|
|
834
|
-
(g) => g instanceof ContentNavigator
|
|
835
|
-
);
|
|
836
|
-
const results = await Promise.all(legacyGenerators.map((g) => g.getNewCards(n)));
|
|
837
|
-
const seen = /* @__PURE__ */ new Set();
|
|
838
|
-
const merged = [];
|
|
839
|
-
for (const cards of results) {
|
|
840
|
-
for (const card of cards) {
|
|
841
|
-
if (!seen.has(card.cardID)) {
|
|
842
|
-
seen.add(card.cardID);
|
|
843
|
-
merged.push(card);
|
|
844
|
-
}
|
|
845
|
-
}
|
|
846
|
-
}
|
|
847
|
-
return n ? merged.slice(0, n) : merged;
|
|
848
|
-
}
|
|
849
|
-
/**
|
|
850
|
-
* Get pending reviews from all generators, merged and deduplicated.
|
|
851
|
-
*/
|
|
852
|
-
async getPendingReviews() {
|
|
853
|
-
const legacyGenerators = this.generators.filter(
|
|
854
|
-
(g) => g instanceof ContentNavigator
|
|
855
|
-
);
|
|
856
|
-
const results = await Promise.all(legacyGenerators.map((g) => g.getPendingReviews()));
|
|
857
|
-
const seen = /* @__PURE__ */ new Set();
|
|
858
|
-
const merged = [];
|
|
859
|
-
for (const reviews of results) {
|
|
860
|
-
for (const review of reviews) {
|
|
861
|
-
if (!seen.has(review.cardID)) {
|
|
862
|
-
seen.add(review.cardID);
|
|
863
|
-
merged.push(review);
|
|
864
|
-
}
|
|
865
|
-
}
|
|
866
|
-
}
|
|
867
|
-
return merged;
|
|
868
|
-
}
|
|
869
|
-
};
|
|
870
|
-
}
|
|
871
|
-
});
|
|
872
|
-
|
|
873
|
-
// src/core/navigators/Pipeline.ts
|
|
874
|
-
var Pipeline_exports = {};
|
|
875
|
-
__export(Pipeline_exports, {
|
|
876
|
-
Pipeline: () => Pipeline
|
|
877
|
-
});
|
|
878
|
-
import { toCourseElo as toCourseElo2 } from "@vue-skuilder/common";
|
|
879
|
-
var Pipeline;
|
|
880
|
-
var init_Pipeline = __esm({
|
|
881
|
-
"src/core/navigators/Pipeline.ts"() {
|
|
882
|
-
"use strict";
|
|
883
|
-
init_navigators();
|
|
884
|
-
init_logger();
|
|
885
|
-
Pipeline = class extends ContentNavigator {
|
|
886
|
-
generator;
|
|
887
|
-
filters;
|
|
888
|
-
/**
|
|
889
|
-
* Create a new pipeline.
|
|
890
|
-
*
|
|
891
|
-
* @param generator - The generator (or CompositeGenerator) that produces candidates
|
|
892
|
-
* @param filters - Filters to apply sequentially (order doesn't matter for multipliers)
|
|
893
|
-
* @param user - User database interface
|
|
894
|
-
* @param course - Course database interface
|
|
895
|
-
*/
|
|
896
|
-
constructor(generator, filters, user, course) {
|
|
897
|
-
super();
|
|
898
|
-
this.generator = generator;
|
|
899
|
-
this.filters = filters;
|
|
900
|
-
this.user = user;
|
|
901
|
-
this.course = course;
|
|
902
|
-
logger.debug(
|
|
903
|
-
`[Pipeline] Created with generator '${generator.name}' and ${filters.length} filters: ${filters.map((f) => f.name).join(", ")}`
|
|
904
|
-
);
|
|
905
|
-
}
|
|
906
|
-
/**
|
|
907
|
-
* Get weighted cards by running generator and applying filters.
|
|
908
|
-
*
|
|
909
|
-
* 1. Build shared context (user ELO, etc.)
|
|
910
|
-
* 2. Get candidates from generator (passing context)
|
|
911
|
-
* 3. Apply each filter sequentially
|
|
912
|
-
* 4. Remove zero-score cards
|
|
913
|
-
* 5. Sort by score descending
|
|
914
|
-
* 6. Return top N
|
|
915
|
-
*
|
|
916
|
-
* @param limit - Maximum number of cards to return
|
|
917
|
-
* @returns Cards sorted by score descending
|
|
918
|
-
*/
|
|
919
|
-
async getWeightedCards(limit) {
|
|
920
|
-
const context = await this.buildContext();
|
|
921
|
-
const overFetchMultiplier = 2 + this.filters.length * 0.5;
|
|
922
|
-
const fetchLimit = Math.ceil(limit * overFetchMultiplier);
|
|
923
|
-
logger.debug(
|
|
924
|
-
`[Pipeline] Fetching ${fetchLimit} candidates from generator '${this.generator.name}'`
|
|
925
|
-
);
|
|
926
|
-
let cards = await this.generator.getWeightedCards(fetchLimit, context);
|
|
927
|
-
logger.debug(`[Pipeline] Generator returned ${cards.length} candidates`);
|
|
928
|
-
for (const filter of this.filters) {
|
|
929
|
-
const beforeCount = cards.length;
|
|
930
|
-
cards = await filter.transform(cards, context);
|
|
931
|
-
logger.debug(`[Pipeline] Filter '${filter.name}': ${beforeCount} \u2192 ${cards.length} cards`);
|
|
932
|
-
}
|
|
933
|
-
cards = cards.filter((c) => c.score > 0);
|
|
934
|
-
cards.sort((a, b) => b.score - a.score);
|
|
935
|
-
const result = cards.slice(0, limit);
|
|
936
|
-
logger.debug(
|
|
937
|
-
`[Pipeline] Returning ${result.length} cards (top scores: ${result.slice(0, 3).map((c) => c.score.toFixed(2)).join(", ")}...)`
|
|
938
|
-
);
|
|
939
|
-
return result;
|
|
940
|
-
}
|
|
941
|
-
/**
|
|
942
|
-
* Build shared context for generator and filters.
|
|
943
|
-
*
|
|
944
|
-
* Called once per getWeightedCards() invocation.
|
|
945
|
-
* Contains data that the generator and multiple filters might need.
|
|
946
|
-
*
|
|
947
|
-
* The context satisfies both GeneratorContext and FilterContext interfaces.
|
|
948
|
-
*/
|
|
949
|
-
async buildContext() {
|
|
950
|
-
let userElo = 1e3;
|
|
951
|
-
try {
|
|
952
|
-
const courseReg = await this.user.getCourseRegDoc(this.course.getCourseID());
|
|
953
|
-
const courseElo = toCourseElo2(courseReg.elo);
|
|
954
|
-
userElo = courseElo.global.score;
|
|
955
|
-
} catch (e) {
|
|
956
|
-
logger.debug(`[Pipeline] Could not get user ELO, using default: ${e}`);
|
|
957
|
-
}
|
|
958
|
-
return {
|
|
959
|
-
user: this.user,
|
|
960
|
-
course: this.course,
|
|
961
|
-
userElo
|
|
962
|
-
};
|
|
963
|
-
}
|
|
964
|
-
// ===========================================================================
|
|
965
|
-
// Legacy StudyContentSource methods
|
|
966
|
-
// ===========================================================================
|
|
967
|
-
//
|
|
968
|
-
// These delegate to the generator for backward compatibility.
|
|
969
|
-
// Eventually SessionController will use getWeightedCards() exclusively.
|
|
970
|
-
//
|
|
971
|
-
/**
|
|
972
|
-
* Get new cards via legacy API.
|
|
973
|
-
* Delegates to the generator if it supports the legacy interface.
|
|
974
|
-
*/
|
|
975
|
-
async getNewCards(n) {
|
|
976
|
-
if ("getNewCards" in this.generator && typeof this.generator.getNewCards === "function") {
|
|
977
|
-
return this.generator.getNewCards(n);
|
|
978
|
-
}
|
|
979
|
-
return [];
|
|
980
|
-
}
|
|
981
|
-
/**
|
|
982
|
-
* Get pending reviews via legacy API.
|
|
983
|
-
* Delegates to the generator if it supports the legacy interface.
|
|
984
|
-
*/
|
|
985
|
-
async getPendingReviews() {
|
|
986
|
-
if ("getPendingReviews" in this.generator && typeof this.generator.getPendingReviews === "function") {
|
|
987
|
-
return this.generator.getPendingReviews();
|
|
988
|
-
}
|
|
989
|
-
return [];
|
|
990
|
-
}
|
|
991
|
-
/**
|
|
992
|
-
* Get the course ID for this pipeline.
|
|
993
|
-
*/
|
|
994
|
-
getCourseID() {
|
|
995
|
-
return this.course.getCourseID();
|
|
996
|
-
}
|
|
997
1156
|
};
|
|
998
1157
|
}
|
|
999
1158
|
});
|
|
1000
1159
|
|
|
1001
1160
|
// src/core/navigators/PipelineAssembler.ts
|
|
1002
|
-
var PipelineAssembler_exports = {};
|
|
1003
|
-
__export(PipelineAssembler_exports, {
|
|
1004
|
-
PipelineAssembler: () => PipelineAssembler
|
|
1005
|
-
});
|
|
1006
1161
|
var PipelineAssembler;
|
|
1007
1162
|
var init_PipelineAssembler = __esm({
|
|
1008
1163
|
"src/core/navigators/PipelineAssembler.ts"() {
|
|
@@ -1123,15 +1278,11 @@ var init_PipelineAssembler = __esm({
|
|
|
1123
1278
|
}
|
|
1124
1279
|
});
|
|
1125
1280
|
|
|
1126
|
-
// src/core/navigators/elo.ts
|
|
1127
|
-
var elo_exports = {};
|
|
1128
|
-
__export(elo_exports, {
|
|
1129
|
-
default: () => ELONavigator
|
|
1130
|
-
});
|
|
1281
|
+
// src/core/navigators/generators/elo.ts
|
|
1131
1282
|
import { toCourseElo as toCourseElo3 } from "@vue-skuilder/common";
|
|
1132
1283
|
var ELONavigator;
|
|
1133
1284
|
var init_elo = __esm({
|
|
1134
|
-
"src/core/navigators/elo.ts"() {
|
|
1285
|
+
"src/core/navigators/generators/elo.ts"() {
|
|
1135
1286
|
"use strict";
|
|
1136
1287
|
init_navigators();
|
|
1137
1288
|
ELONavigator = class extends ContentNavigator {
|
|
@@ -1141,50 +1292,6 @@ var init_elo = __esm({
|
|
|
1141
1292
|
super(user, course, strategyData);
|
|
1142
1293
|
this.name = strategyData?.name || "ELO";
|
|
1143
1294
|
}
|
|
1144
|
-
async getPendingReviews() {
|
|
1145
|
-
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
1146
|
-
const elo = await this.course.getCardEloData(reviews.map((r) => r.cardId));
|
|
1147
|
-
const ratedReviews = reviews.map((r, i) => {
|
|
1148
|
-
const ratedR = {
|
|
1149
|
-
...r,
|
|
1150
|
-
...elo[i]
|
|
1151
|
-
};
|
|
1152
|
-
return ratedR;
|
|
1153
|
-
});
|
|
1154
|
-
ratedReviews.sort((a, b) => {
|
|
1155
|
-
return a.global.score - b.global.score;
|
|
1156
|
-
});
|
|
1157
|
-
return ratedReviews.map((r) => {
|
|
1158
|
-
return {
|
|
1159
|
-
...r,
|
|
1160
|
-
contentSourceType: "course",
|
|
1161
|
-
contentSourceID: this.course.getCourseID(),
|
|
1162
|
-
cardID: r.cardId,
|
|
1163
|
-
courseID: r.courseId,
|
|
1164
|
-
qualifiedID: `${r.courseId}-${r.cardId}`,
|
|
1165
|
-
reviewID: r._id,
|
|
1166
|
-
status: "review"
|
|
1167
|
-
};
|
|
1168
|
-
});
|
|
1169
|
-
}
|
|
1170
|
-
async getNewCards(limit = 99) {
|
|
1171
|
-
const activeCards = await this.user.getActiveCards();
|
|
1172
|
-
return (await this.course.getCardsCenteredAtELO(
|
|
1173
|
-
{ limit, elo: "user" },
|
|
1174
|
-
(c) => {
|
|
1175
|
-
if (activeCards.some((ac) => c.cardID === ac.cardID)) {
|
|
1176
|
-
return false;
|
|
1177
|
-
} else {
|
|
1178
|
-
return true;
|
|
1179
|
-
}
|
|
1180
|
-
}
|
|
1181
|
-
)).map((c) => {
|
|
1182
|
-
return {
|
|
1183
|
-
...c,
|
|
1184
|
-
status: "new"
|
|
1185
|
-
};
|
|
1186
|
-
});
|
|
1187
|
-
}
|
|
1188
1295
|
/**
|
|
1189
1296
|
* Get new cards with suitability scores based on ELO distance.
|
|
1190
1297
|
*
|
|
@@ -1209,7 +1316,11 @@ var init_elo = __esm({
|
|
|
1209
1316
|
const userElo = toCourseElo3(courseReg.elo);
|
|
1210
1317
|
userGlobalElo = userElo.global.score;
|
|
1211
1318
|
}
|
|
1212
|
-
const
|
|
1319
|
+
const activeCards = await this.user.getActiveCards();
|
|
1320
|
+
const newCards = (await this.course.getCardsCenteredAtELO(
|
|
1321
|
+
{ limit, elo: "user" },
|
|
1322
|
+
(c) => !activeCards.some((ac) => c.cardID === ac.cardID)
|
|
1323
|
+
)).map((c) => ({ ...c, status: "new" }));
|
|
1213
1324
|
const cardIds = newCards.map((c) => c.cardID);
|
|
1214
1325
|
const cardEloData = await this.course.getCardEloData(cardIds);
|
|
1215
1326
|
const scored = newCards.map((c, i) => {
|
|
@@ -1239,160 +1350,29 @@ var init_elo = __esm({
|
|
|
1239
1350
|
}
|
|
1240
1351
|
});
|
|
1241
1352
|
|
|
1242
|
-
// src/core/navigators/
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
DEFAULT_MIN_MULTIPLIER: () => DEFAULT_MIN_MULTIPLIER,
|
|
1248
|
-
createEloDistanceFilter: () => createEloDistanceFilter
|
|
1249
|
-
});
|
|
1250
|
-
function computeMultiplier(distance, halfLife, minMultiplier, maxMultiplier) {
|
|
1251
|
-
const normalizedDistance = distance / halfLife;
|
|
1252
|
-
const decay = Math.exp(-(normalizedDistance * normalizedDistance));
|
|
1253
|
-
return minMultiplier + (maxMultiplier - minMultiplier) * decay;
|
|
1254
|
-
}
|
|
1255
|
-
function createEloDistanceFilter(config) {
|
|
1256
|
-
const halfLife = config?.halfLife ?? DEFAULT_HALF_LIFE;
|
|
1257
|
-
const minMultiplier = config?.minMultiplier ?? DEFAULT_MIN_MULTIPLIER;
|
|
1258
|
-
const maxMultiplier = config?.maxMultiplier ?? DEFAULT_MAX_MULTIPLIER;
|
|
1259
|
-
return {
|
|
1260
|
-
name: "ELO Distance Filter",
|
|
1261
|
-
async transform(cards, context) {
|
|
1262
|
-
const { course, userElo } = context;
|
|
1263
|
-
const cardIds = cards.map((c) => c.cardId);
|
|
1264
|
-
const cardElos = await course.getCardEloData(cardIds);
|
|
1265
|
-
return cards.map((card, i) => {
|
|
1266
|
-
const cardElo = cardElos[i]?.global?.score ?? 1e3;
|
|
1267
|
-
const distance = Math.abs(cardElo - userElo);
|
|
1268
|
-
const multiplier = computeMultiplier(distance, halfLife, minMultiplier, maxMultiplier);
|
|
1269
|
-
const newScore = card.score * multiplier;
|
|
1270
|
-
const action = multiplier < maxMultiplier - 0.01 ? "penalized" : "passed";
|
|
1271
|
-
return {
|
|
1272
|
-
...card,
|
|
1273
|
-
score: newScore,
|
|
1274
|
-
provenance: [
|
|
1275
|
-
...card.provenance,
|
|
1276
|
-
{
|
|
1277
|
-
strategy: "eloDistance",
|
|
1278
|
-
strategyName: "ELO Distance Filter",
|
|
1279
|
-
strategyId: "ELO_DISTANCE_FILTER",
|
|
1280
|
-
action,
|
|
1281
|
-
score: newScore,
|
|
1282
|
-
reason: `ELO distance ${Math.round(distance)} (card: ${Math.round(cardElo)}, user: ${Math.round(userElo)}) \u2192 ${multiplier.toFixed(2)}x`
|
|
1283
|
-
}
|
|
1284
|
-
]
|
|
1285
|
-
};
|
|
1286
|
-
});
|
|
1287
|
-
}
|
|
1288
|
-
};
|
|
1289
|
-
}
|
|
1290
|
-
var DEFAULT_HALF_LIFE, DEFAULT_MIN_MULTIPLIER, DEFAULT_MAX_MULTIPLIER;
|
|
1291
|
-
var init_eloDistance = __esm({
|
|
1292
|
-
"src/core/navigators/filters/eloDistance.ts"() {
|
|
1293
|
-
"use strict";
|
|
1294
|
-
DEFAULT_HALF_LIFE = 200;
|
|
1295
|
-
DEFAULT_MIN_MULTIPLIER = 0.3;
|
|
1296
|
-
DEFAULT_MAX_MULTIPLIER = 1;
|
|
1297
|
-
}
|
|
1298
|
-
});
|
|
1299
|
-
|
|
1300
|
-
// src/core/navigators/filters/index.ts
|
|
1301
|
-
var filters_exports = {};
|
|
1302
|
-
__export(filters_exports, {
|
|
1303
|
-
createEloDistanceFilter: () => createEloDistanceFilter
|
|
1304
|
-
});
|
|
1305
|
-
var init_filters = __esm({
|
|
1306
|
-
"src/core/navigators/filters/index.ts"() {
|
|
1307
|
-
"use strict";
|
|
1308
|
-
init_eloDistance();
|
|
1309
|
-
}
|
|
1310
|
-
});
|
|
1311
|
-
|
|
1312
|
-
// src/core/navigators/filters/types.ts
|
|
1313
|
-
var types_exports = {};
|
|
1314
|
-
var init_types = __esm({
|
|
1315
|
-
"src/core/navigators/filters/types.ts"() {
|
|
1316
|
-
"use strict";
|
|
1317
|
-
}
|
|
1318
|
-
});
|
|
1319
|
-
|
|
1320
|
-
// src/core/navigators/generators/index.ts
|
|
1321
|
-
var generators_exports = {};
|
|
1322
|
-
var init_generators = __esm({
|
|
1323
|
-
"src/core/navigators/generators/index.ts"() {
|
|
1324
|
-
"use strict";
|
|
1325
|
-
}
|
|
1326
|
-
});
|
|
1327
|
-
|
|
1328
|
-
// src/core/navigators/generators/types.ts
|
|
1329
|
-
var types_exports2 = {};
|
|
1330
|
-
var init_types2 = __esm({
|
|
1331
|
-
"src/core/navigators/generators/types.ts"() {
|
|
1332
|
-
"use strict";
|
|
1333
|
-
}
|
|
1334
|
-
});
|
|
1335
|
-
|
|
1336
|
-
// src/core/navigators/hardcodedOrder.ts
|
|
1337
|
-
var hardcodedOrder_exports = {};
|
|
1338
|
-
__export(hardcodedOrder_exports, {
|
|
1339
|
-
default: () => HardcodedOrderNavigator
|
|
1340
|
-
});
|
|
1341
|
-
var HardcodedOrderNavigator;
|
|
1342
|
-
var init_hardcodedOrder = __esm({
|
|
1343
|
-
"src/core/navigators/hardcodedOrder.ts"() {
|
|
1353
|
+
// src/core/navigators/generators/srs.ts
|
|
1354
|
+
import moment3 from "moment";
|
|
1355
|
+
var SRSNavigator;
|
|
1356
|
+
var init_srs = __esm({
|
|
1357
|
+
"src/core/navigators/generators/srs.ts"() {
|
|
1344
1358
|
"use strict";
|
|
1345
1359
|
init_navigators();
|
|
1346
1360
|
init_logger();
|
|
1347
|
-
|
|
1361
|
+
SRSNavigator = class extends ContentNavigator {
|
|
1348
1362
|
/** Human-readable name for CardGenerator interface */
|
|
1349
1363
|
name;
|
|
1350
|
-
orderedCardIds = [];
|
|
1351
1364
|
constructor(user, course, strategyData) {
|
|
1352
1365
|
super(user, course, strategyData);
|
|
1353
|
-
this.name = strategyData
|
|
1354
|
-
if (strategyData.serializedData) {
|
|
1355
|
-
try {
|
|
1356
|
-
this.orderedCardIds = JSON.parse(strategyData.serializedData);
|
|
1357
|
-
} catch (e) {
|
|
1358
|
-
logger.error("Failed to parse serializedData for HardcodedOrderNavigator", e);
|
|
1359
|
-
}
|
|
1360
|
-
}
|
|
1361
|
-
}
|
|
1362
|
-
async getPendingReviews() {
|
|
1363
|
-
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
1364
|
-
return reviews.map((r) => {
|
|
1365
|
-
return {
|
|
1366
|
-
...r,
|
|
1367
|
-
contentSourceType: "course",
|
|
1368
|
-
contentSourceID: this.course.getCourseID(),
|
|
1369
|
-
cardID: r.cardId,
|
|
1370
|
-
courseID: r.courseId,
|
|
1371
|
-
reviewID: r._id,
|
|
1372
|
-
status: "review"
|
|
1373
|
-
};
|
|
1374
|
-
});
|
|
1375
|
-
}
|
|
1376
|
-
async getNewCards(limit = 99) {
|
|
1377
|
-
const activeCardIds = (await this.user.getActiveCards()).map((c) => c.cardID);
|
|
1378
|
-
const newCardIds = this.orderedCardIds.filter((cardId) => !activeCardIds.includes(cardId));
|
|
1379
|
-
const cardsToReturn = newCardIds.slice(0, limit);
|
|
1380
|
-
return cardsToReturn.map((cardId) => {
|
|
1381
|
-
return {
|
|
1382
|
-
cardID: cardId,
|
|
1383
|
-
courseID: this.course.getCourseID(),
|
|
1384
|
-
contentSourceType: "course",
|
|
1385
|
-
contentSourceID: this.course.getCourseID(),
|
|
1386
|
-
status: "new"
|
|
1387
|
-
};
|
|
1388
|
-
});
|
|
1366
|
+
this.name = strategyData?.name || "SRS";
|
|
1389
1367
|
}
|
|
1390
1368
|
/**
|
|
1391
|
-
* Get cards
|
|
1369
|
+
* Get review cards scored by urgency.
|
|
1392
1370
|
*
|
|
1393
|
-
*
|
|
1394
|
-
*
|
|
1395
|
-
*
|
|
1371
|
+
* Score formula combines:
|
|
1372
|
+
* - Relative overdueness: hoursOverdue / intervalHours
|
|
1373
|
+
* - Interval recency: exponential decay favoring shorter intervals
|
|
1374
|
+
*
|
|
1375
|
+
* Cards not yet due are excluded (not scored as 0).
|
|
1396
1376
|
*
|
|
1397
1377
|
* This method supports both the legacy signature (limit only) and the
|
|
1398
1378
|
* CardGenerator interface signature (limit, context).
|
|
@@ -1401,682 +1381,22 @@ var init_hardcodedOrder = __esm({
|
|
|
1401
1381
|
* @param _context - Optional GeneratorContext (currently unused, but required for interface)
|
|
1402
1382
|
*/
|
|
1403
1383
|
async getWeightedCards(limit, _context) {
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
const
|
|
1408
|
-
const
|
|
1409
|
-
|
|
1410
|
-
|
|
1384
|
+
if (!this.user || !this.course) {
|
|
1385
|
+
throw new Error("SRSNavigator requires user and course to be set");
|
|
1386
|
+
}
|
|
1387
|
+
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
1388
|
+
const now = moment3.utc();
|
|
1389
|
+
const dueReviews = reviews.filter((r) => now.isAfter(moment3.utc(r.reviewTime)));
|
|
1390
|
+
const scored = dueReviews.map((review) => {
|
|
1391
|
+
const { score, reason } = this.computeUrgencyScore(review, now);
|
|
1411
1392
|
return {
|
|
1412
|
-
cardId,
|
|
1413
|
-
courseId:
|
|
1393
|
+
cardId: review.cardId,
|
|
1394
|
+
courseId: review.courseId,
|
|
1414
1395
|
score,
|
|
1396
|
+
reviewID: review._id,
|
|
1415
1397
|
provenance: [
|
|
1416
1398
|
{
|
|
1417
|
-
strategy: "
|
|
1418
|
-
strategyName: this.strategyName || this.name,
|
|
1419
|
-
strategyId: this.strategyId || "NAVIGATION_STRATEGY-hardcoded",
|
|
1420
|
-
action: "generated",
|
|
1421
|
-
score,
|
|
1422
|
-
reason: `Position ${position} of ${totalCards} in fixed sequence, new card`
|
|
1423
|
-
}
|
|
1424
|
-
]
|
|
1425
|
-
};
|
|
1426
|
-
});
|
|
1427
|
-
const scoredReviews = reviews.map((r) => ({
|
|
1428
|
-
cardId: r.cardID,
|
|
1429
|
-
courseId: r.courseID,
|
|
1430
|
-
score: 1,
|
|
1431
|
-
provenance: [
|
|
1432
|
-
{
|
|
1433
|
-
strategy: "hardcodedOrder",
|
|
1434
|
-
strategyName: this.strategyName || this.name,
|
|
1435
|
-
strategyId: this.strategyId || "NAVIGATION_STRATEGY-hardcoded",
|
|
1436
|
-
action: "generated",
|
|
1437
|
-
score: 1,
|
|
1438
|
-
reason: "Scheduled review, highest priority"
|
|
1439
|
-
}
|
|
1440
|
-
]
|
|
1441
|
-
}));
|
|
1442
|
-
const all = [...scoredReviews, ...scoredNew];
|
|
1443
|
-
all.sort((a, b) => b.score - a.score);
|
|
1444
|
-
return all.slice(0, limit);
|
|
1445
|
-
}
|
|
1446
|
-
};
|
|
1447
|
-
}
|
|
1448
|
-
});
|
|
1449
|
-
|
|
1450
|
-
// src/core/navigators/hierarchyDefinition.ts
|
|
1451
|
-
var hierarchyDefinition_exports = {};
|
|
1452
|
-
__export(hierarchyDefinition_exports, {
|
|
1453
|
-
default: () => HierarchyDefinitionNavigator
|
|
1454
|
-
});
|
|
1455
|
-
import { toCourseElo as toCourseElo4 } from "@vue-skuilder/common";
|
|
1456
|
-
var DEFAULT_MIN_COUNT, HierarchyDefinitionNavigator;
|
|
1457
|
-
var init_hierarchyDefinition = __esm({
|
|
1458
|
-
"src/core/navigators/hierarchyDefinition.ts"() {
|
|
1459
|
-
"use strict";
|
|
1460
|
-
init_navigators();
|
|
1461
|
-
DEFAULT_MIN_COUNT = 3;
|
|
1462
|
-
HierarchyDefinitionNavigator = class extends ContentNavigator {
|
|
1463
|
-
config;
|
|
1464
|
-
_strategyData;
|
|
1465
|
-
/** Human-readable name for CardFilter interface */
|
|
1466
|
-
name;
|
|
1467
|
-
constructor(user, course, _strategyData) {
|
|
1468
|
-
super(user, course, _strategyData);
|
|
1469
|
-
this._strategyData = _strategyData;
|
|
1470
|
-
this.config = this.parseConfig(_strategyData.serializedData);
|
|
1471
|
-
this.name = _strategyData.name || "Hierarchy Definition";
|
|
1472
|
-
}
|
|
1473
|
-
parseConfig(serializedData) {
|
|
1474
|
-
try {
|
|
1475
|
-
const parsed = JSON.parse(serializedData);
|
|
1476
|
-
return {
|
|
1477
|
-
prerequisites: parsed.prerequisites || {}
|
|
1478
|
-
};
|
|
1479
|
-
} catch {
|
|
1480
|
-
return {
|
|
1481
|
-
prerequisites: {}
|
|
1482
|
-
};
|
|
1483
|
-
}
|
|
1484
|
-
}
|
|
1485
|
-
/**
|
|
1486
|
-
* Check if a specific prerequisite is satisfied
|
|
1487
|
-
*/
|
|
1488
|
-
isPrerequisiteMet(prereq, userTagElo, userGlobalElo) {
|
|
1489
|
-
if (!userTagElo) return false;
|
|
1490
|
-
const minCount = prereq.masteryThreshold?.minCount ?? DEFAULT_MIN_COUNT;
|
|
1491
|
-
if (userTagElo.count < minCount) return false;
|
|
1492
|
-
if (prereq.masteryThreshold?.minElo !== void 0) {
|
|
1493
|
-
return userTagElo.score >= prereq.masteryThreshold.minElo;
|
|
1494
|
-
} else {
|
|
1495
|
-
return userTagElo.score >= userGlobalElo;
|
|
1496
|
-
}
|
|
1497
|
-
}
|
|
1498
|
-
/**
|
|
1499
|
-
* Get the set of tags the user has mastered.
|
|
1500
|
-
* A tag is "mastered" if it appears as a prerequisite somewhere and meets its threshold.
|
|
1501
|
-
*/
|
|
1502
|
-
async getMasteredTags(context) {
|
|
1503
|
-
const mastered = /* @__PURE__ */ new Set();
|
|
1504
|
-
try {
|
|
1505
|
-
const courseReg = await context.user.getCourseRegDoc(context.course.getCourseID());
|
|
1506
|
-
const userElo = toCourseElo4(courseReg.elo);
|
|
1507
|
-
for (const prereqs of Object.values(this.config.prerequisites)) {
|
|
1508
|
-
for (const prereq of prereqs) {
|
|
1509
|
-
const tagElo = userElo.tags[prereq.tag];
|
|
1510
|
-
if (this.isPrerequisiteMet(prereq, tagElo, userElo.global.score)) {
|
|
1511
|
-
mastered.add(prereq.tag);
|
|
1512
|
-
}
|
|
1513
|
-
}
|
|
1514
|
-
}
|
|
1515
|
-
} catch {
|
|
1516
|
-
}
|
|
1517
|
-
return mastered;
|
|
1518
|
-
}
|
|
1519
|
-
/**
|
|
1520
|
-
* Get the set of tags that are unlocked (prerequisites met)
|
|
1521
|
-
*/
|
|
1522
|
-
getUnlockedTags(masteredTags) {
|
|
1523
|
-
const unlocked = /* @__PURE__ */ new Set();
|
|
1524
|
-
for (const [tagId, prereqs] of Object.entries(this.config.prerequisites)) {
|
|
1525
|
-
const allPrereqsMet = prereqs.every((prereq) => masteredTags.has(prereq.tag));
|
|
1526
|
-
if (allPrereqsMet) {
|
|
1527
|
-
unlocked.add(tagId);
|
|
1528
|
-
}
|
|
1529
|
-
}
|
|
1530
|
-
return unlocked;
|
|
1531
|
-
}
|
|
1532
|
-
/**
|
|
1533
|
-
* Check if a tag has prerequisites defined in config
|
|
1534
|
-
*/
|
|
1535
|
-
hasPrerequisites(tagId) {
|
|
1536
|
-
return tagId in this.config.prerequisites;
|
|
1537
|
-
}
|
|
1538
|
-
/**
|
|
1539
|
-
* Check if a card is unlocked and generate reason.
|
|
1540
|
-
*/
|
|
1541
|
-
async checkCardUnlock(cardId, course, unlockedTags, masteredTags) {
|
|
1542
|
-
try {
|
|
1543
|
-
const tagResponse = await course.getAppliedTags(cardId);
|
|
1544
|
-
const cardTags = tagResponse.rows.map((row) => row.value?.name || row.key);
|
|
1545
|
-
const lockedTags = cardTags.filter(
|
|
1546
|
-
(tag) => this.hasPrerequisites(tag) && !unlockedTags.has(tag)
|
|
1547
|
-
);
|
|
1548
|
-
if (lockedTags.length === 0) {
|
|
1549
|
-
const tagList = cardTags.length > 0 ? cardTags.join(", ") : "none";
|
|
1550
|
-
return {
|
|
1551
|
-
isUnlocked: true,
|
|
1552
|
-
reason: `Prerequisites met, tags: ${tagList}`
|
|
1553
|
-
};
|
|
1554
|
-
}
|
|
1555
|
-
const missingPrereqs = lockedTags.flatMap((tag) => {
|
|
1556
|
-
const prereqs = this.config.prerequisites[tag] || [];
|
|
1557
|
-
return prereqs.filter((p) => !masteredTags.has(p.tag)).map((p) => p.tag);
|
|
1558
|
-
});
|
|
1559
|
-
return {
|
|
1560
|
-
isUnlocked: false,
|
|
1561
|
-
reason: `Blocked: missing prerequisites ${missingPrereqs.join(", ")} for tags ${lockedTags.join(", ")}`
|
|
1562
|
-
};
|
|
1563
|
-
} catch {
|
|
1564
|
-
return {
|
|
1565
|
-
isUnlocked: true,
|
|
1566
|
-
reason: "Prerequisites check skipped (tag lookup failed)"
|
|
1567
|
-
};
|
|
1568
|
-
}
|
|
1569
|
-
}
|
|
1570
|
-
/**
|
|
1571
|
-
* CardFilter.transform implementation.
|
|
1572
|
-
*
|
|
1573
|
-
* Apply prerequisite gating to cards. Cards with locked tags receive score: 0.
|
|
1574
|
-
*/
|
|
1575
|
-
async transform(cards, context) {
|
|
1576
|
-
const masteredTags = await this.getMasteredTags(context);
|
|
1577
|
-
const unlockedTags = this.getUnlockedTags(masteredTags);
|
|
1578
|
-
const gated = [];
|
|
1579
|
-
for (const card of cards) {
|
|
1580
|
-
const { isUnlocked, reason } = await this.checkCardUnlock(
|
|
1581
|
-
card.cardId,
|
|
1582
|
-
context.course,
|
|
1583
|
-
unlockedTags,
|
|
1584
|
-
masteredTags
|
|
1585
|
-
);
|
|
1586
|
-
const finalScore = isUnlocked ? card.score : 0;
|
|
1587
|
-
const action = isUnlocked ? "passed" : "penalized";
|
|
1588
|
-
gated.push({
|
|
1589
|
-
...card,
|
|
1590
|
-
score: finalScore,
|
|
1591
|
-
provenance: [
|
|
1592
|
-
...card.provenance,
|
|
1593
|
-
{
|
|
1594
|
-
strategy: "hierarchyDefinition",
|
|
1595
|
-
strategyName: this.strategyName || this.name,
|
|
1596
|
-
strategyId: this.strategyId || "NAVIGATION_STRATEGY-hierarchy",
|
|
1597
|
-
action,
|
|
1598
|
-
score: finalScore,
|
|
1599
|
-
reason
|
|
1600
|
-
}
|
|
1601
|
-
]
|
|
1602
|
-
});
|
|
1603
|
-
}
|
|
1604
|
-
return gated;
|
|
1605
|
-
}
|
|
1606
|
-
/**
|
|
1607
|
-
* Legacy getWeightedCards - now throws as filters should not be used as generators.
|
|
1608
|
-
*
|
|
1609
|
-
* Use transform() via Pipeline instead.
|
|
1610
|
-
*/
|
|
1611
|
-
async getWeightedCards(_limit) {
|
|
1612
|
-
throw new Error(
|
|
1613
|
-
"HierarchyDefinitionNavigator is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
|
|
1614
|
-
);
|
|
1615
|
-
}
|
|
1616
|
-
// Legacy methods - stub implementations since filters don't generate cards
|
|
1617
|
-
async getNewCards(_n) {
|
|
1618
|
-
return [];
|
|
1619
|
-
}
|
|
1620
|
-
async getPendingReviews() {
|
|
1621
|
-
return [];
|
|
1622
|
-
}
|
|
1623
|
-
};
|
|
1624
|
-
}
|
|
1625
|
-
});
|
|
1626
|
-
|
|
1627
|
-
// src/core/navigators/interferenceMitigator.ts
|
|
1628
|
-
var interferenceMitigator_exports = {};
|
|
1629
|
-
__export(interferenceMitigator_exports, {
|
|
1630
|
-
default: () => InterferenceMitigatorNavigator
|
|
1631
|
-
});
|
|
1632
|
-
import { toCourseElo as toCourseElo5 } from "@vue-skuilder/common";
|
|
1633
|
-
var DEFAULT_MIN_COUNT2, DEFAULT_MIN_ELAPSED_DAYS, DEFAULT_INTERFERENCE_DECAY, InterferenceMitigatorNavigator;
|
|
1634
|
-
var init_interferenceMitigator = __esm({
|
|
1635
|
-
"src/core/navigators/interferenceMitigator.ts"() {
|
|
1636
|
-
"use strict";
|
|
1637
|
-
init_navigators();
|
|
1638
|
-
DEFAULT_MIN_COUNT2 = 10;
|
|
1639
|
-
DEFAULT_MIN_ELAPSED_DAYS = 3;
|
|
1640
|
-
DEFAULT_INTERFERENCE_DECAY = 0.8;
|
|
1641
|
-
InterferenceMitigatorNavigator = class extends ContentNavigator {
|
|
1642
|
-
config;
|
|
1643
|
-
_strategyData;
|
|
1644
|
-
/** Human-readable name for CardFilter interface */
|
|
1645
|
-
name;
|
|
1646
|
-
/** Precomputed map: tag -> set of { partner, decay } it interferes with */
|
|
1647
|
-
interferenceMap;
|
|
1648
|
-
constructor(user, course, _strategyData) {
|
|
1649
|
-
super(user, course, _strategyData);
|
|
1650
|
-
this._strategyData = _strategyData;
|
|
1651
|
-
this.config = this.parseConfig(_strategyData.serializedData);
|
|
1652
|
-
this.interferenceMap = this.buildInterferenceMap();
|
|
1653
|
-
this.name = _strategyData.name || "Interference Mitigator";
|
|
1654
|
-
}
|
|
1655
|
-
parseConfig(serializedData) {
|
|
1656
|
-
try {
|
|
1657
|
-
const parsed = JSON.parse(serializedData);
|
|
1658
|
-
let sets = parsed.interferenceSets || [];
|
|
1659
|
-
if (sets.length > 0 && Array.isArray(sets[0])) {
|
|
1660
|
-
sets = sets.map((tags) => ({ tags }));
|
|
1661
|
-
}
|
|
1662
|
-
return {
|
|
1663
|
-
interferenceSets: sets,
|
|
1664
|
-
maturityThreshold: {
|
|
1665
|
-
minCount: parsed.maturityThreshold?.minCount ?? DEFAULT_MIN_COUNT2,
|
|
1666
|
-
minElo: parsed.maturityThreshold?.minElo,
|
|
1667
|
-
minElapsedDays: parsed.maturityThreshold?.minElapsedDays ?? DEFAULT_MIN_ELAPSED_DAYS
|
|
1668
|
-
},
|
|
1669
|
-
defaultDecay: parsed.defaultDecay ?? DEFAULT_INTERFERENCE_DECAY
|
|
1670
|
-
};
|
|
1671
|
-
} catch {
|
|
1672
|
-
return {
|
|
1673
|
-
interferenceSets: [],
|
|
1674
|
-
maturityThreshold: {
|
|
1675
|
-
minCount: DEFAULT_MIN_COUNT2,
|
|
1676
|
-
minElapsedDays: DEFAULT_MIN_ELAPSED_DAYS
|
|
1677
|
-
},
|
|
1678
|
-
defaultDecay: DEFAULT_INTERFERENCE_DECAY
|
|
1679
|
-
};
|
|
1680
|
-
}
|
|
1681
|
-
}
|
|
1682
|
-
/**
|
|
1683
|
-
* Build a map from each tag to its interference partners with decay coefficients.
|
|
1684
|
-
* If tags A, B, C are in an interference group with decay 0.8, then:
|
|
1685
|
-
* - A interferes with B (decay 0.8) and C (decay 0.8)
|
|
1686
|
-
* - B interferes with A (decay 0.8) and C (decay 0.8)
|
|
1687
|
-
* - etc.
|
|
1688
|
-
*/
|
|
1689
|
-
buildInterferenceMap() {
|
|
1690
|
-
const map = /* @__PURE__ */ new Map();
|
|
1691
|
-
for (const group of this.config.interferenceSets) {
|
|
1692
|
-
const decay = group.decay ?? this.config.defaultDecay ?? DEFAULT_INTERFERENCE_DECAY;
|
|
1693
|
-
for (const tag of group.tags) {
|
|
1694
|
-
if (!map.has(tag)) {
|
|
1695
|
-
map.set(tag, []);
|
|
1696
|
-
}
|
|
1697
|
-
const partners = map.get(tag);
|
|
1698
|
-
for (const other of group.tags) {
|
|
1699
|
-
if (other !== tag) {
|
|
1700
|
-
const existing = partners.find((p) => p.partner === other);
|
|
1701
|
-
if (existing) {
|
|
1702
|
-
existing.decay = Math.max(existing.decay, decay);
|
|
1703
|
-
} else {
|
|
1704
|
-
partners.push({ partner: other, decay });
|
|
1705
|
-
}
|
|
1706
|
-
}
|
|
1707
|
-
}
|
|
1708
|
-
}
|
|
1709
|
-
}
|
|
1710
|
-
return map;
|
|
1711
|
-
}
|
|
1712
|
-
/**
|
|
1713
|
-
* Get the set of tags that are currently immature for this user.
|
|
1714
|
-
* A tag is immature if the user has interacted with it but hasn't
|
|
1715
|
-
* reached the maturity threshold.
|
|
1716
|
-
*/
|
|
1717
|
-
async getImmatureTags(context) {
|
|
1718
|
-
const immature = /* @__PURE__ */ new Set();
|
|
1719
|
-
try {
|
|
1720
|
-
const courseReg = await context.user.getCourseRegDoc(context.course.getCourseID());
|
|
1721
|
-
const userElo = toCourseElo5(courseReg.elo);
|
|
1722
|
-
const minCount = this.config.maturityThreshold?.minCount ?? DEFAULT_MIN_COUNT2;
|
|
1723
|
-
const minElo = this.config.maturityThreshold?.minElo;
|
|
1724
|
-
const minElapsedDays = this.config.maturityThreshold?.minElapsedDays ?? DEFAULT_MIN_ELAPSED_DAYS;
|
|
1725
|
-
const minCountForElapsed = minElapsedDays * 2;
|
|
1726
|
-
for (const [tagId, tagElo] of Object.entries(userElo.tags)) {
|
|
1727
|
-
if (tagElo.count === 0) continue;
|
|
1728
|
-
const belowCount = tagElo.count < minCount;
|
|
1729
|
-
const belowElo = minElo !== void 0 && tagElo.score < minElo;
|
|
1730
|
-
const belowElapsed = tagElo.count < minCountForElapsed;
|
|
1731
|
-
if (belowCount || belowElo || belowElapsed) {
|
|
1732
|
-
immature.add(tagId);
|
|
1733
|
-
}
|
|
1734
|
-
}
|
|
1735
|
-
} catch {
|
|
1736
|
-
}
|
|
1737
|
-
return immature;
|
|
1738
|
-
}
|
|
1739
|
-
/**
|
|
1740
|
-
* Get all tags that interfere with any immature tag, along with their decay coefficients.
|
|
1741
|
-
* These are the tags we want to avoid introducing.
|
|
1742
|
-
*/
|
|
1743
|
-
getTagsToAvoid(immatureTags) {
|
|
1744
|
-
const avoid = /* @__PURE__ */ new Map();
|
|
1745
|
-
for (const immatureTag of immatureTags) {
|
|
1746
|
-
const partners = this.interferenceMap.get(immatureTag);
|
|
1747
|
-
if (partners) {
|
|
1748
|
-
for (const { partner, decay } of partners) {
|
|
1749
|
-
if (!immatureTags.has(partner)) {
|
|
1750
|
-
const existing = avoid.get(partner) ?? 0;
|
|
1751
|
-
avoid.set(partner, Math.max(existing, decay));
|
|
1752
|
-
}
|
|
1753
|
-
}
|
|
1754
|
-
}
|
|
1755
|
-
}
|
|
1756
|
-
return avoid;
|
|
1757
|
-
}
|
|
1758
|
-
/**
|
|
1759
|
-
* Get tags for a single card
|
|
1760
|
-
*/
|
|
1761
|
-
async getCardTags(cardId, course) {
|
|
1762
|
-
try {
|
|
1763
|
-
const tagResponse = await course.getAppliedTags(cardId);
|
|
1764
|
-
return tagResponse.rows.map((row) => row.value?.name || row.key).filter(Boolean);
|
|
1765
|
-
} catch {
|
|
1766
|
-
return [];
|
|
1767
|
-
}
|
|
1768
|
-
}
|
|
1769
|
-
/**
|
|
1770
|
-
* Compute interference score reduction for a card.
|
|
1771
|
-
* Returns: { multiplier, interfering tags, reason }
|
|
1772
|
-
*/
|
|
1773
|
-
computeInterferenceEffect(cardTags, tagsToAvoid, immatureTags) {
|
|
1774
|
-
if (tagsToAvoid.size === 0) {
|
|
1775
|
-
return {
|
|
1776
|
-
multiplier: 1,
|
|
1777
|
-
interferingTags: [],
|
|
1778
|
-
reason: "No interference detected"
|
|
1779
|
-
};
|
|
1780
|
-
}
|
|
1781
|
-
let multiplier = 1;
|
|
1782
|
-
const interferingTags = [];
|
|
1783
|
-
for (const tag of cardTags) {
|
|
1784
|
-
const decay = tagsToAvoid.get(tag);
|
|
1785
|
-
if (decay !== void 0) {
|
|
1786
|
-
interferingTags.push(tag);
|
|
1787
|
-
multiplier *= 1 - decay;
|
|
1788
|
-
}
|
|
1789
|
-
}
|
|
1790
|
-
if (interferingTags.length === 0) {
|
|
1791
|
-
return {
|
|
1792
|
-
multiplier: 1,
|
|
1793
|
-
interferingTags: [],
|
|
1794
|
-
reason: "No interference detected"
|
|
1795
|
-
};
|
|
1796
|
-
}
|
|
1797
|
-
const causingTags = /* @__PURE__ */ new Set();
|
|
1798
|
-
for (const tag of interferingTags) {
|
|
1799
|
-
for (const immatureTag of immatureTags) {
|
|
1800
|
-
const partners = this.interferenceMap.get(immatureTag);
|
|
1801
|
-
if (partners?.some((p) => p.partner === tag)) {
|
|
1802
|
-
causingTags.add(immatureTag);
|
|
1803
|
-
}
|
|
1804
|
-
}
|
|
1805
|
-
}
|
|
1806
|
-
const reason = `Interferes with immature tags ${Array.from(causingTags).join(", ")} (tags: ${interferingTags.join(", ")}, multiplier: ${multiplier.toFixed(2)})`;
|
|
1807
|
-
return { multiplier, interferingTags, reason };
|
|
1808
|
-
}
|
|
1809
|
-
/**
|
|
1810
|
-
* CardFilter.transform implementation.
|
|
1811
|
-
*
|
|
1812
|
-
* Apply interference-aware scoring. Cards with tags that interfere with
|
|
1813
|
-
* immature learnings get reduced scores.
|
|
1814
|
-
*/
|
|
1815
|
-
async transform(cards, context) {
|
|
1816
|
-
const immatureTags = await this.getImmatureTags(context);
|
|
1817
|
-
const tagsToAvoid = this.getTagsToAvoid(immatureTags);
|
|
1818
|
-
const adjusted = [];
|
|
1819
|
-
for (const card of cards) {
|
|
1820
|
-
const cardTags = await this.getCardTags(card.cardId, context.course);
|
|
1821
|
-
const { multiplier, reason } = this.computeInterferenceEffect(
|
|
1822
|
-
cardTags,
|
|
1823
|
-
tagsToAvoid,
|
|
1824
|
-
immatureTags
|
|
1825
|
-
);
|
|
1826
|
-
const finalScore = card.score * multiplier;
|
|
1827
|
-
const action = multiplier < 1 ? "penalized" : multiplier > 1 ? "boosted" : "passed";
|
|
1828
|
-
adjusted.push({
|
|
1829
|
-
...card,
|
|
1830
|
-
score: finalScore,
|
|
1831
|
-
provenance: [
|
|
1832
|
-
...card.provenance,
|
|
1833
|
-
{
|
|
1834
|
-
strategy: "interferenceMitigator",
|
|
1835
|
-
strategyName: this.strategyName || this.name,
|
|
1836
|
-
strategyId: this.strategyId || "NAVIGATION_STRATEGY-interference",
|
|
1837
|
-
action,
|
|
1838
|
-
score: finalScore,
|
|
1839
|
-
reason
|
|
1840
|
-
}
|
|
1841
|
-
]
|
|
1842
|
-
});
|
|
1843
|
-
}
|
|
1844
|
-
return adjusted;
|
|
1845
|
-
}
|
|
1846
|
-
/**
|
|
1847
|
-
* Legacy getWeightedCards - now throws as filters should not be used as generators.
|
|
1848
|
-
*
|
|
1849
|
-
* Use transform() via Pipeline instead.
|
|
1850
|
-
*/
|
|
1851
|
-
async getWeightedCards(_limit) {
|
|
1852
|
-
throw new Error(
|
|
1853
|
-
"InterferenceMitigatorNavigator is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
|
|
1854
|
-
);
|
|
1855
|
-
}
|
|
1856
|
-
// Legacy methods - stub implementations since filters don't generate cards
|
|
1857
|
-
async getNewCards(_n) {
|
|
1858
|
-
return [];
|
|
1859
|
-
}
|
|
1860
|
-
async getPendingReviews() {
|
|
1861
|
-
return [];
|
|
1862
|
-
}
|
|
1863
|
-
};
|
|
1864
|
-
}
|
|
1865
|
-
});
|
|
1866
|
-
|
|
1867
|
-
// src/core/navigators/relativePriority.ts
|
|
1868
|
-
var relativePriority_exports = {};
|
|
1869
|
-
__export(relativePriority_exports, {
|
|
1870
|
-
default: () => RelativePriorityNavigator
|
|
1871
|
-
});
|
|
1872
|
-
var DEFAULT_PRIORITY, DEFAULT_PRIORITY_INFLUENCE, DEFAULT_COMBINE_MODE, RelativePriorityNavigator;
|
|
1873
|
-
var init_relativePriority = __esm({
|
|
1874
|
-
"src/core/navigators/relativePriority.ts"() {
|
|
1875
|
-
"use strict";
|
|
1876
|
-
init_navigators();
|
|
1877
|
-
DEFAULT_PRIORITY = 0.5;
|
|
1878
|
-
DEFAULT_PRIORITY_INFLUENCE = 0.5;
|
|
1879
|
-
DEFAULT_COMBINE_MODE = "max";
|
|
1880
|
-
RelativePriorityNavigator = class extends ContentNavigator {
|
|
1881
|
-
config;
|
|
1882
|
-
_strategyData;
|
|
1883
|
-
/** Human-readable name for CardFilter interface */
|
|
1884
|
-
name;
|
|
1885
|
-
constructor(user, course, _strategyData) {
|
|
1886
|
-
super(user, course, _strategyData);
|
|
1887
|
-
this._strategyData = _strategyData;
|
|
1888
|
-
this.config = this.parseConfig(_strategyData.serializedData);
|
|
1889
|
-
this.name = _strategyData.name || "Relative Priority";
|
|
1890
|
-
}
|
|
1891
|
-
parseConfig(serializedData) {
|
|
1892
|
-
try {
|
|
1893
|
-
const parsed = JSON.parse(serializedData);
|
|
1894
|
-
return {
|
|
1895
|
-
tagPriorities: parsed.tagPriorities || {},
|
|
1896
|
-
defaultPriority: parsed.defaultPriority ?? DEFAULT_PRIORITY,
|
|
1897
|
-
combineMode: parsed.combineMode ?? DEFAULT_COMBINE_MODE,
|
|
1898
|
-
priorityInfluence: parsed.priorityInfluence ?? DEFAULT_PRIORITY_INFLUENCE
|
|
1899
|
-
};
|
|
1900
|
-
} catch {
|
|
1901
|
-
return {
|
|
1902
|
-
tagPriorities: {},
|
|
1903
|
-
defaultPriority: DEFAULT_PRIORITY,
|
|
1904
|
-
combineMode: DEFAULT_COMBINE_MODE,
|
|
1905
|
-
priorityInfluence: DEFAULT_PRIORITY_INFLUENCE
|
|
1906
|
-
};
|
|
1907
|
-
}
|
|
1908
|
-
}
|
|
1909
|
-
/**
|
|
1910
|
-
* Look up the priority for a tag.
|
|
1911
|
-
*/
|
|
1912
|
-
getTagPriority(tagId) {
|
|
1913
|
-
return this.config.tagPriorities[tagId] ?? this.config.defaultPriority ?? DEFAULT_PRIORITY;
|
|
1914
|
-
}
|
|
1915
|
-
/**
|
|
1916
|
-
* Compute combined priority for a card based on its tags.
|
|
1917
|
-
*/
|
|
1918
|
-
computeCardPriority(cardTags) {
|
|
1919
|
-
if (cardTags.length === 0) {
|
|
1920
|
-
return this.config.defaultPriority ?? DEFAULT_PRIORITY;
|
|
1921
|
-
}
|
|
1922
|
-
const priorities = cardTags.map((tag) => this.getTagPriority(tag));
|
|
1923
|
-
switch (this.config.combineMode) {
|
|
1924
|
-
case "max":
|
|
1925
|
-
return Math.max(...priorities);
|
|
1926
|
-
case "min":
|
|
1927
|
-
return Math.min(...priorities);
|
|
1928
|
-
case "average":
|
|
1929
|
-
return priorities.reduce((sum, p) => sum + p, 0) / priorities.length;
|
|
1930
|
-
default:
|
|
1931
|
-
return Math.max(...priorities);
|
|
1932
|
-
}
|
|
1933
|
-
}
|
|
1934
|
-
/**
|
|
1935
|
-
* Compute boost factor based on priority.
|
|
1936
|
-
*
|
|
1937
|
-
* The formula: 1 + (priority - 0.5) * priorityInfluence
|
|
1938
|
-
*
|
|
1939
|
-
* This creates a multiplier centered around 1.0:
|
|
1940
|
-
* - Priority 1.0 with influence 0.5 → 1.25 (25% boost)
|
|
1941
|
-
* - Priority 0.5 with any influence → 1.00 (neutral)
|
|
1942
|
-
* - Priority 0.0 with influence 0.5 → 0.75 (25% reduction)
|
|
1943
|
-
*/
|
|
1944
|
-
computeBoostFactor(priority) {
|
|
1945
|
-
const influence = this.config.priorityInfluence ?? DEFAULT_PRIORITY_INFLUENCE;
|
|
1946
|
-
return 1 + (priority - 0.5) * influence;
|
|
1947
|
-
}
|
|
1948
|
-
/**
|
|
1949
|
-
* Build human-readable reason for priority adjustment.
|
|
1950
|
-
*/
|
|
1951
|
-
buildPriorityReason(cardTags, priority, boostFactor, finalScore) {
|
|
1952
|
-
if (cardTags.length === 0) {
|
|
1953
|
-
return `No tags, neutral priority (${priority.toFixed(2)})`;
|
|
1954
|
-
}
|
|
1955
|
-
const tagList = cardTags.slice(0, 3).join(", ");
|
|
1956
|
-
const more = cardTags.length > 3 ? ` (+${cardTags.length - 3} more)` : "";
|
|
1957
|
-
if (boostFactor === 1) {
|
|
1958
|
-
return `Neutral priority (${priority.toFixed(2)}) for tags: ${tagList}${more}`;
|
|
1959
|
-
} else if (boostFactor > 1) {
|
|
1960
|
-
return `High-priority tags: ${tagList}${more} (priority ${priority.toFixed(2)} \u2192 boost ${boostFactor.toFixed(2)}x \u2192 ${finalScore.toFixed(2)})`;
|
|
1961
|
-
} else {
|
|
1962
|
-
return `Low-priority tags: ${tagList}${more} (priority ${priority.toFixed(2)} \u2192 reduce ${boostFactor.toFixed(2)}x \u2192 ${finalScore.toFixed(2)})`;
|
|
1963
|
-
}
|
|
1964
|
-
}
|
|
1965
|
-
/**
|
|
1966
|
-
* Get tags for a single card.
|
|
1967
|
-
*/
|
|
1968
|
-
async getCardTags(cardId, course) {
|
|
1969
|
-
try {
|
|
1970
|
-
const tagResponse = await course.getAppliedTags(cardId);
|
|
1971
|
-
return tagResponse.rows.map((r) => r.doc?.name).filter((x) => !!x);
|
|
1972
|
-
} catch {
|
|
1973
|
-
return [];
|
|
1974
|
-
}
|
|
1975
|
-
}
|
|
1976
|
-
/**
|
|
1977
|
-
* CardFilter.transform implementation.
|
|
1978
|
-
*
|
|
1979
|
-
* Apply priority-adjusted scoring. Cards with high-priority tags get boosted,
|
|
1980
|
-
* cards with low-priority tags get reduced scores.
|
|
1981
|
-
*/
|
|
1982
|
-
async transform(cards, context) {
|
|
1983
|
-
const adjusted = await Promise.all(
|
|
1984
|
-
cards.map(async (card) => {
|
|
1985
|
-
const cardTags = await this.getCardTags(card.cardId, context.course);
|
|
1986
|
-
const priority = this.computeCardPriority(cardTags);
|
|
1987
|
-
const boostFactor = this.computeBoostFactor(priority);
|
|
1988
|
-
const finalScore = Math.max(0, Math.min(1, card.score * boostFactor));
|
|
1989
|
-
const action = boostFactor > 1 ? "boosted" : boostFactor < 1 ? "penalized" : "passed";
|
|
1990
|
-
const reason = this.buildPriorityReason(cardTags, priority, boostFactor, finalScore);
|
|
1991
|
-
return {
|
|
1992
|
-
...card,
|
|
1993
|
-
score: finalScore,
|
|
1994
|
-
provenance: [
|
|
1995
|
-
...card.provenance,
|
|
1996
|
-
{
|
|
1997
|
-
strategy: "relativePriority",
|
|
1998
|
-
strategyName: this.strategyName || this.name,
|
|
1999
|
-
strategyId: this.strategyId || "NAVIGATION_STRATEGY-priority",
|
|
2000
|
-
action,
|
|
2001
|
-
score: finalScore,
|
|
2002
|
-
reason
|
|
2003
|
-
}
|
|
2004
|
-
]
|
|
2005
|
-
};
|
|
2006
|
-
})
|
|
2007
|
-
);
|
|
2008
|
-
return adjusted;
|
|
2009
|
-
}
|
|
2010
|
-
/**
|
|
2011
|
-
* Legacy getWeightedCards - now throws as filters should not be used as generators.
|
|
2012
|
-
*
|
|
2013
|
-
* Use transform() via Pipeline instead.
|
|
2014
|
-
*/
|
|
2015
|
-
async getWeightedCards(_limit) {
|
|
2016
|
-
throw new Error(
|
|
2017
|
-
"RelativePriorityNavigator is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
|
|
2018
|
-
);
|
|
2019
|
-
}
|
|
2020
|
-
// Legacy methods - stub implementations since filters don't generate cards
|
|
2021
|
-
async getNewCards(_n) {
|
|
2022
|
-
return [];
|
|
2023
|
-
}
|
|
2024
|
-
async getPendingReviews() {
|
|
2025
|
-
return [];
|
|
2026
|
-
}
|
|
2027
|
-
};
|
|
2028
|
-
}
|
|
2029
|
-
});
|
|
2030
|
-
|
|
2031
|
-
// src/core/navigators/srs.ts
|
|
2032
|
-
var srs_exports = {};
|
|
2033
|
-
__export(srs_exports, {
|
|
2034
|
-
default: () => SRSNavigator
|
|
2035
|
-
});
|
|
2036
|
-
import moment3 from "moment";
|
|
2037
|
-
var SRSNavigator;
|
|
2038
|
-
var init_srs = __esm({
|
|
2039
|
-
"src/core/navigators/srs.ts"() {
|
|
2040
|
-
"use strict";
|
|
2041
|
-
init_navigators();
|
|
2042
|
-
SRSNavigator = class extends ContentNavigator {
|
|
2043
|
-
/** Human-readable name for CardGenerator interface */
|
|
2044
|
-
name;
|
|
2045
|
-
constructor(user, course, strategyData) {
|
|
2046
|
-
super(user, course, strategyData);
|
|
2047
|
-
this.name = strategyData?.name || "SRS";
|
|
2048
|
-
}
|
|
2049
|
-
/**
|
|
2050
|
-
* Get review cards scored by urgency.
|
|
2051
|
-
*
|
|
2052
|
-
* Score formula combines:
|
|
2053
|
-
* - Relative overdueness: hoursOverdue / intervalHours
|
|
2054
|
-
* - Interval recency: exponential decay favoring shorter intervals
|
|
2055
|
-
*
|
|
2056
|
-
* Cards not yet due are excluded (not scored as 0).
|
|
2057
|
-
*
|
|
2058
|
-
* This method supports both the legacy signature (limit only) and the
|
|
2059
|
-
* CardGenerator interface signature (limit, context).
|
|
2060
|
-
*
|
|
2061
|
-
* @param limit - Maximum number of cards to return
|
|
2062
|
-
* @param _context - Optional GeneratorContext (currently unused, but required for interface)
|
|
2063
|
-
*/
|
|
2064
|
-
async getWeightedCards(limit, _context) {
|
|
2065
|
-
if (!this.user || !this.course) {
|
|
2066
|
-
throw new Error("SRSNavigator requires user and course to be set");
|
|
2067
|
-
}
|
|
2068
|
-
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
2069
|
-
const now = moment3.utc();
|
|
2070
|
-
const dueReviews = reviews.filter((r) => now.isAfter(moment3.utc(r.reviewTime)));
|
|
2071
|
-
const scored = dueReviews.map((review) => {
|
|
2072
|
-
const { score, reason } = this.computeUrgencyScore(review, now);
|
|
2073
|
-
return {
|
|
2074
|
-
cardId: review.cardId,
|
|
2075
|
-
courseId: review.courseId,
|
|
2076
|
-
score,
|
|
2077
|
-
provenance: [
|
|
2078
|
-
{
|
|
2079
|
-
strategy: "srs",
|
|
1399
|
+
strategy: "srs",
|
|
2080
1400
|
strategyName: this.strategyName || this.name,
|
|
2081
1401
|
strategyId: this.strategyId || "NAVIGATION_STRATEGY-SRS-default",
|
|
2082
1402
|
action: "generated",
|
|
@@ -2086,6 +1406,7 @@ var init_srs = __esm({
|
|
|
2086
1406
|
]
|
|
2087
1407
|
};
|
|
2088
1408
|
});
|
|
1409
|
+
logger.debug(`[srsNav] got ${scored.length} weighted cards`);
|
|
2089
1410
|
return scored.sort((a, b) => b.score - a.score).slice(0, limit);
|
|
2090
1411
|
}
|
|
2091
1412
|
/**
|
|
@@ -2117,235 +1438,102 @@ var init_srs = __esm({
|
|
|
2117
1438
|
const reason = `${Math.round(hoursOverdue)}h overdue (interval: ${Math.round(intervalHours)}h, relative: ${relativeOverdue.toFixed(2)}), recency: ${recencyFactor.toFixed(2)}, review`;
|
|
2118
1439
|
return { score, reason };
|
|
2119
1440
|
}
|
|
2120
|
-
/**
|
|
2121
|
-
* Get pending reviews in legacy format.
|
|
2122
|
-
*
|
|
2123
|
-
* Returns all pending reviews for the course, enriched with session item fields.
|
|
2124
|
-
*/
|
|
2125
|
-
async getPendingReviews() {
|
|
2126
|
-
if (!this.user || !this.course) {
|
|
2127
|
-
throw new Error("SRSNavigator requires user and course to be set");
|
|
2128
|
-
}
|
|
2129
|
-
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
2130
|
-
return reviews.map((r) => ({
|
|
2131
|
-
...r,
|
|
2132
|
-
contentSourceType: "course",
|
|
2133
|
-
contentSourceID: this.course.getCourseID(),
|
|
2134
|
-
cardID: r.cardId,
|
|
2135
|
-
courseID: r.courseId,
|
|
2136
|
-
qualifiedID: `${r.courseId}-${r.cardId}`,
|
|
2137
|
-
reviewID: r._id,
|
|
2138
|
-
status: "review"
|
|
2139
|
-
}));
|
|
2140
|
-
}
|
|
2141
|
-
/**
|
|
2142
|
-
* SRS does not generate new cards.
|
|
2143
|
-
* Use ELONavigator or another generator for new cards.
|
|
2144
|
-
*/
|
|
2145
|
-
async getNewCards(_n) {
|
|
2146
|
-
return [];
|
|
2147
|
-
}
|
|
2148
1441
|
};
|
|
2149
1442
|
}
|
|
2150
1443
|
});
|
|
2151
1444
|
|
|
2152
|
-
//
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
}
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
}
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
function
|
|
2205
|
-
return
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
"
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
/**
|
|
2245
|
-
* Constructor for standard navigators.
|
|
2246
|
-
* Call this from subclass constructors to initialize common fields.
|
|
2247
|
-
*
|
|
2248
|
-
* Note: CompositeGenerator doesn't use this pattern and should call super() without args.
|
|
2249
|
-
*/
|
|
2250
|
-
constructor(user, course, strategyData) {
|
|
2251
|
-
if (user && course && strategyData) {
|
|
2252
|
-
this.user = user;
|
|
2253
|
-
this.course = course;
|
|
2254
|
-
this.strategyName = strategyData.name;
|
|
2255
|
-
this.strategyId = strategyData._id;
|
|
2256
|
-
}
|
|
2257
|
-
}
|
|
2258
|
-
/**
|
|
2259
|
-
* Factory method to create navigator instances dynamically.
|
|
2260
|
-
*
|
|
2261
|
-
* @param user - User interface
|
|
2262
|
-
* @param course - Course interface
|
|
2263
|
-
* @param strategyData - Strategy configuration document
|
|
2264
|
-
* @returns the runtime object used to steer a study session.
|
|
2265
|
-
*/
|
|
2266
|
-
static async create(user, course, strategyData) {
|
|
2267
|
-
const implementingClass = strategyData.implementingClass;
|
|
2268
|
-
let NavigatorImpl;
|
|
2269
|
-
const variations = [".ts", ".js", ""];
|
|
2270
|
-
for (const ext of variations) {
|
|
2271
|
-
try {
|
|
2272
|
-
const module = await globImport(`./${implementingClass}${ext}`);
|
|
2273
|
-
NavigatorImpl = module.default;
|
|
2274
|
-
break;
|
|
2275
|
-
} catch (e) {
|
|
2276
|
-
logger.debug(`Failed to load with extension ${ext}:`, e);
|
|
2277
|
-
}
|
|
2278
|
-
}
|
|
2279
|
-
if (!NavigatorImpl) {
|
|
2280
|
-
throw new Error(`Could not load navigator implementation for: ${implementingClass}`);
|
|
2281
|
-
}
|
|
2282
|
-
return new NavigatorImpl(user, course, strategyData);
|
|
2283
|
-
}
|
|
2284
|
-
/**
|
|
2285
|
-
* Get cards with suitability scores and provenance trails.
|
|
2286
|
-
*
|
|
2287
|
-
* **This is the PRIMARY API for navigation strategies.**
|
|
2288
|
-
*
|
|
2289
|
-
* Returns cards ranked by suitability score (0-1). Higher scores indicate
|
|
2290
|
-
* better candidates for presentation. Each card includes a provenance trail
|
|
2291
|
-
* documenting how strategies contributed to the final score.
|
|
2292
|
-
*
|
|
2293
|
-
* ## For Generators
|
|
2294
|
-
* Override this method to generate candidates and compute scores based on
|
|
2295
|
-
* your strategy's logic (e.g., ELO proximity, review urgency). Create the
|
|
2296
|
-
* initial provenance entry with action='generated'.
|
|
2297
|
-
*
|
|
2298
|
-
* ## Default Implementation
|
|
2299
|
-
* The base class provides a backward-compatible default that:
|
|
2300
|
-
* 1. Calls legacy getNewCards() and getPendingReviews()
|
|
2301
|
-
* 2. Assigns score=1.0 to all cards
|
|
2302
|
-
* 3. Creates minimal provenance from legacy methods
|
|
2303
|
-
* 4. Returns combined results up to limit
|
|
2304
|
-
*
|
|
2305
|
-
* This allows existing strategies to work without modification while
|
|
2306
|
-
* new strategies can override with proper scoring and provenance.
|
|
2307
|
-
*
|
|
2308
|
-
* @param limit - Maximum cards to return
|
|
2309
|
-
* @returns Cards sorted by score descending, with provenance trails
|
|
2310
|
-
*/
|
|
2311
|
-
async getWeightedCards(limit) {
|
|
2312
|
-
const newCards = await this.getNewCards(limit);
|
|
2313
|
-
const reviews = await this.getPendingReviews();
|
|
2314
|
-
const weighted = [
|
|
2315
|
-
...newCards.map((c) => ({
|
|
2316
|
-
cardId: c.cardID,
|
|
2317
|
-
courseId: c.courseID,
|
|
2318
|
-
score: 1,
|
|
2319
|
-
provenance: [
|
|
2320
|
-
{
|
|
2321
|
-
strategy: "legacy",
|
|
2322
|
-
strategyName: this.strategyName || "Legacy API",
|
|
2323
|
-
strategyId: this.strategyId || "legacy-fallback",
|
|
2324
|
-
action: "generated",
|
|
2325
|
-
score: 1,
|
|
2326
|
-
reason: "Generated via legacy getNewCards(), new card"
|
|
2327
|
-
}
|
|
2328
|
-
]
|
|
2329
|
-
})),
|
|
2330
|
-
...reviews.map((r) => ({
|
|
2331
|
-
cardId: r.cardID,
|
|
2332
|
-
courseId: r.courseID,
|
|
2333
|
-
score: 1,
|
|
2334
|
-
provenance: [
|
|
2335
|
-
{
|
|
2336
|
-
strategy: "legacy",
|
|
2337
|
-
strategyName: this.strategyName || "Legacy API",
|
|
2338
|
-
strategyId: this.strategyId || "legacy-fallback",
|
|
2339
|
-
action: "generated",
|
|
2340
|
-
score: 1,
|
|
2341
|
-
reason: "Generated via legacy getPendingReviews(), review"
|
|
2342
|
-
}
|
|
2343
|
-
]
|
|
2344
|
-
}))
|
|
2345
|
-
];
|
|
2346
|
-
return weighted.slice(0, limit);
|
|
2347
|
-
}
|
|
2348
|
-
};
|
|
1445
|
+
// src/core/navigators/filters/eloDistance.ts
|
|
1446
|
+
function computeMultiplier(distance, halfLife, minMultiplier, maxMultiplier) {
|
|
1447
|
+
const normalizedDistance = distance / halfLife;
|
|
1448
|
+
const decay = Math.exp(-(normalizedDistance * normalizedDistance));
|
|
1449
|
+
return minMultiplier + (maxMultiplier - minMultiplier) * decay;
|
|
1450
|
+
}
|
|
1451
|
+
function createEloDistanceFilter(config) {
|
|
1452
|
+
const halfLife = config?.halfLife ?? DEFAULT_HALF_LIFE;
|
|
1453
|
+
const minMultiplier = config?.minMultiplier ?? DEFAULT_MIN_MULTIPLIER;
|
|
1454
|
+
const maxMultiplier = config?.maxMultiplier ?? DEFAULT_MAX_MULTIPLIER;
|
|
1455
|
+
return {
|
|
1456
|
+
name: "ELO Distance Filter",
|
|
1457
|
+
async transform(cards, context) {
|
|
1458
|
+
const { course, userElo } = context;
|
|
1459
|
+
const cardIds = cards.map((c) => c.cardId);
|
|
1460
|
+
const cardElos = await course.getCardEloData(cardIds);
|
|
1461
|
+
return cards.map((card, i) => {
|
|
1462
|
+
const cardElo = cardElos[i]?.global?.score ?? 1e3;
|
|
1463
|
+
const distance = Math.abs(cardElo - userElo);
|
|
1464
|
+
const multiplier = computeMultiplier(distance, halfLife, minMultiplier, maxMultiplier);
|
|
1465
|
+
const newScore = card.score * multiplier;
|
|
1466
|
+
const action = multiplier < maxMultiplier - 0.01 ? "penalized" : "passed";
|
|
1467
|
+
return {
|
|
1468
|
+
...card,
|
|
1469
|
+
score: newScore,
|
|
1470
|
+
provenance: [
|
|
1471
|
+
...card.provenance,
|
|
1472
|
+
{
|
|
1473
|
+
strategy: "eloDistance",
|
|
1474
|
+
strategyName: "ELO Distance Filter",
|
|
1475
|
+
strategyId: "ELO_DISTANCE_FILTER",
|
|
1476
|
+
action,
|
|
1477
|
+
score: newScore,
|
|
1478
|
+
reason: `ELO distance ${Math.round(distance)} (card: ${Math.round(cardElo)}, user: ${Math.round(userElo)}) \u2192 ${multiplier.toFixed(2)}x`
|
|
1479
|
+
}
|
|
1480
|
+
]
|
|
1481
|
+
};
|
|
1482
|
+
});
|
|
1483
|
+
}
|
|
1484
|
+
};
|
|
1485
|
+
}
|
|
1486
|
+
var DEFAULT_HALF_LIFE, DEFAULT_MIN_MULTIPLIER, DEFAULT_MAX_MULTIPLIER;
|
|
1487
|
+
var init_eloDistance = __esm({
|
|
1488
|
+
"src/core/navigators/filters/eloDistance.ts"() {
|
|
1489
|
+
"use strict";
|
|
1490
|
+
DEFAULT_HALF_LIFE = 200;
|
|
1491
|
+
DEFAULT_MIN_MULTIPLIER = 0.3;
|
|
1492
|
+
DEFAULT_MAX_MULTIPLIER = 1;
|
|
1493
|
+
}
|
|
1494
|
+
});
|
|
1495
|
+
|
|
1496
|
+
// src/core/navigators/defaults.ts
|
|
1497
|
+
function createDefaultEloStrategy(courseId) {
|
|
1498
|
+
return {
|
|
1499
|
+
_id: "NAVIGATION_STRATEGY-ELO-default",
|
|
1500
|
+
docType: "NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */,
|
|
1501
|
+
name: "ELO (default)",
|
|
1502
|
+
description: "Default ELO-based navigation strategy for new cards",
|
|
1503
|
+
implementingClass: "elo" /* ELO */,
|
|
1504
|
+
course: courseId,
|
|
1505
|
+
serializedData: ""
|
|
1506
|
+
};
|
|
1507
|
+
}
|
|
1508
|
+
function createDefaultSrsStrategy(courseId) {
|
|
1509
|
+
return {
|
|
1510
|
+
_id: "NAVIGATION_STRATEGY-SRS-default",
|
|
1511
|
+
docType: "NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */,
|
|
1512
|
+
name: "SRS (default)",
|
|
1513
|
+
description: "Default SRS-based navigation strategy for reviews",
|
|
1514
|
+
implementingClass: "srs" /* SRS */,
|
|
1515
|
+
course: courseId,
|
|
1516
|
+
serializedData: ""
|
|
1517
|
+
};
|
|
1518
|
+
}
|
|
1519
|
+
function createDefaultPipeline(user, course) {
|
|
1520
|
+
const courseId = course.getCourseID();
|
|
1521
|
+
const eloNavigator = new ELONavigator(user, course, createDefaultEloStrategy(courseId));
|
|
1522
|
+
const srsNavigator = new SRSNavigator(user, course, createDefaultSrsStrategy(courseId));
|
|
1523
|
+
const compositeGenerator = new CompositeGenerator([eloNavigator, srsNavigator]);
|
|
1524
|
+
const eloDistanceFilter = createEloDistanceFilter();
|
|
1525
|
+
return new Pipeline(compositeGenerator, [eloDistanceFilter], user, course);
|
|
1526
|
+
}
|
|
1527
|
+
var init_defaults = __esm({
|
|
1528
|
+
"src/core/navigators/defaults.ts"() {
|
|
1529
|
+
"use strict";
|
|
1530
|
+
init_navigators();
|
|
1531
|
+
init_Pipeline();
|
|
1532
|
+
init_CompositeGenerator();
|
|
1533
|
+
init_elo();
|
|
1534
|
+
init_srs();
|
|
1535
|
+
init_eloDistance();
|
|
1536
|
+
init_types_legacy();
|
|
2349
1537
|
}
|
|
2350
1538
|
});
|
|
2351
1539
|
|
|
@@ -2354,7 +1542,7 @@ import {
|
|
|
2354
1542
|
EloToNumber,
|
|
2355
1543
|
Status,
|
|
2356
1544
|
blankCourseElo as blankCourseElo2,
|
|
2357
|
-
toCourseElo as
|
|
1545
|
+
toCourseElo as toCourseElo4
|
|
2358
1546
|
} from "@vue-skuilder/common";
|
|
2359
1547
|
function randIntWeightedTowardZero(n) {
|
|
2360
1548
|
return Math.floor(Math.random() * Math.random() * Math.random() * n);
|
|
@@ -2443,12 +1631,8 @@ var init_courseDB = __esm({
|
|
|
2443
1631
|
init_courseAPI();
|
|
2444
1632
|
init_courseLookupDB();
|
|
2445
1633
|
init_navigators();
|
|
2446
|
-
init_Pipeline();
|
|
2447
1634
|
init_PipelineAssembler();
|
|
2448
|
-
|
|
2449
|
-
init_elo();
|
|
2450
|
-
init_srs();
|
|
2451
|
-
init_eloDistance();
|
|
1635
|
+
init_defaults();
|
|
2452
1636
|
CourseDB = class {
|
|
2453
1637
|
// private log(msg: string): void {
|
|
2454
1638
|
// log(`CourseLog: ${this.id}\n ${msg}`);
|
|
@@ -2515,7 +1699,7 @@ var init_courseDB = __esm({
|
|
|
2515
1699
|
docs.rows.forEach((r) => {
|
|
2516
1700
|
if (isSuccessRow(r)) {
|
|
2517
1701
|
if (r.doc && r.doc.elo) {
|
|
2518
|
-
ret.push(
|
|
1702
|
+
ret.push(toCourseElo4(r.doc.elo));
|
|
2519
1703
|
} else {
|
|
2520
1704
|
logger.warn("no elo data for card: " + r.id);
|
|
2521
1705
|
ret.push(blankCourseElo2());
|
|
@@ -2584,15 +1768,6 @@ var init_courseDB = __esm({
|
|
|
2584
1768
|
ret[r.id] = r.doc.id_displayable_data;
|
|
2585
1769
|
}
|
|
2586
1770
|
});
|
|
2587
|
-
await Promise.all(
|
|
2588
|
-
cards.rows.map((r) => {
|
|
2589
|
-
return async () => {
|
|
2590
|
-
if (isSuccessRow(r)) {
|
|
2591
|
-
ret[r.id] = r.doc.id_displayable_data;
|
|
2592
|
-
}
|
|
2593
|
-
};
|
|
2594
|
-
})
|
|
2595
|
-
);
|
|
2596
1771
|
return ret;
|
|
2597
1772
|
}
|
|
2598
1773
|
async getCardsByELO(elo, cardLimit) {
|
|
@@ -2677,6 +1852,28 @@ ${above.rows.map((r) => ` ${r.id}-${r.key}
|
|
|
2677
1852
|
throw new Error(`Failed to find tags for card ${this.id}-${cardId}`);
|
|
2678
1853
|
}
|
|
2679
1854
|
}
|
|
1855
|
+
async getAppliedTagsBatch(cardIds) {
|
|
1856
|
+
if (cardIds.length === 0) {
|
|
1857
|
+
return /* @__PURE__ */ new Map();
|
|
1858
|
+
}
|
|
1859
|
+
const db = getCourseDB2(this.id);
|
|
1860
|
+
const result = await db.query("getTags", {
|
|
1861
|
+
keys: cardIds,
|
|
1862
|
+
include_docs: false
|
|
1863
|
+
});
|
|
1864
|
+
const tagsByCard = /* @__PURE__ */ new Map();
|
|
1865
|
+
for (const cardId of cardIds) {
|
|
1866
|
+
tagsByCard.set(cardId, []);
|
|
1867
|
+
}
|
|
1868
|
+
for (const row of result.rows) {
|
|
1869
|
+
const cardId = row.key;
|
|
1870
|
+
const tagName = row.value?.name;
|
|
1871
|
+
if (tagName && tagsByCard.has(cardId)) {
|
|
1872
|
+
tagsByCard.get(cardId).push(tagName);
|
|
1873
|
+
}
|
|
1874
|
+
}
|
|
1875
|
+
return tagsByCard;
|
|
1876
|
+
}
|
|
2680
1877
|
async addTagToCard(cardId, tagId, updateELO) {
|
|
2681
1878
|
return await addTagToCard(
|
|
2682
1879
|
this.id,
|
|
@@ -2804,7 +2001,7 @@ ${above.rows.map((r) => ` ${r.id}-${r.key}
|
|
|
2804
2001
|
logger.debug(
|
|
2805
2002
|
"[courseDB] No strategy documents found, using default Pipeline(Composite(ELO, SRS), [eloDistanceFilter])"
|
|
2806
2003
|
);
|
|
2807
|
-
return
|
|
2004
|
+
return createDefaultPipeline(user, this);
|
|
2808
2005
|
}
|
|
2809
2006
|
const assembler = new PipelineAssembler();
|
|
2810
2007
|
const { pipeline, generatorStrategies, filterStrategies, warnings } = await assembler.assemble({
|
|
@@ -2817,7 +2014,7 @@ ${above.rows.map((r) => ` ${r.id}-${r.key}
|
|
|
2817
2014
|
}
|
|
2818
2015
|
if (!pipeline) {
|
|
2819
2016
|
logger.debug("[courseDB] Pipeline assembly failed, using default pipeline");
|
|
2820
|
-
return
|
|
2017
|
+
return createDefaultPipeline(user, this);
|
|
2821
2018
|
}
|
|
2822
2019
|
logger.debug(
|
|
2823
2020
|
`[courseDB] Using assembled pipeline with ${generatorStrategies.length} generator(s) and ${filterStrategies.length} filter(s)`
|
|
@@ -2828,69 +2025,12 @@ ${above.rows.map((r) => ` ${r.id}-${r.key}
|
|
|
2828
2025
|
throw e;
|
|
2829
2026
|
}
|
|
2830
2027
|
}
|
|
2831
|
-
makeDefaultEloStrategy() {
|
|
2832
|
-
return {
|
|
2833
|
-
_id: "NAVIGATION_STRATEGY-ELO-default",
|
|
2834
|
-
docType: "NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */,
|
|
2835
|
-
name: "ELO (default)",
|
|
2836
|
-
description: "Default ELO-based navigation strategy for new cards",
|
|
2837
|
-
implementingClass: "elo" /* ELO */,
|
|
2838
|
-
course: this.id,
|
|
2839
|
-
serializedData: ""
|
|
2840
|
-
};
|
|
2841
|
-
}
|
|
2842
|
-
makeDefaultSrsStrategy() {
|
|
2843
|
-
return {
|
|
2844
|
-
_id: "NAVIGATION_STRATEGY-SRS-default",
|
|
2845
|
-
docType: "NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */,
|
|
2846
|
-
name: "SRS (default)",
|
|
2847
|
-
description: "Default SRS-based navigation strategy for reviews",
|
|
2848
|
-
implementingClass: "srs" /* SRS */,
|
|
2849
|
-
course: this.id,
|
|
2850
|
-
serializedData: ""
|
|
2851
|
-
};
|
|
2852
|
-
}
|
|
2853
|
-
/**
|
|
2854
|
-
* Creates the default navigation pipeline for courses with no configured strategies.
|
|
2855
|
-
*
|
|
2856
|
-
* Default: Pipeline(Composite(ELO, SRS), [eloDistanceFilter])
|
|
2857
|
-
* - ELO generator: scores new cards by skill proximity
|
|
2858
|
-
* - SRS generator: scores reviews by overdueness and interval recency
|
|
2859
|
-
* - ELO distance filter: penalizes cards far from user's current level
|
|
2860
|
-
*/
|
|
2861
|
-
createDefaultPipeline(user) {
|
|
2862
|
-
const eloNavigator = new ELONavigator(user, this, this.makeDefaultEloStrategy());
|
|
2863
|
-
const srsNavigator = new SRSNavigator(user, this, this.makeDefaultSrsStrategy());
|
|
2864
|
-
const compositeGenerator = new CompositeGenerator([eloNavigator, srsNavigator]);
|
|
2865
|
-
const eloDistanceFilter = createEloDistanceFilter();
|
|
2866
|
-
return new Pipeline(compositeGenerator, [eloDistanceFilter], user, this);
|
|
2867
|
-
}
|
|
2868
2028
|
////////////////////////////////////
|
|
2869
2029
|
// END NavigationStrategyManager implementation
|
|
2870
2030
|
////////////////////////////////////
|
|
2871
2031
|
////////////////////////////////////
|
|
2872
2032
|
// StudyContentSource implementation
|
|
2873
2033
|
////////////////////////////////////
|
|
2874
|
-
async getNewCards(limit = 99) {
|
|
2875
|
-
const u = await this._getCurrentUser();
|
|
2876
|
-
try {
|
|
2877
|
-
const navigator = await this.createNavigator(u);
|
|
2878
|
-
return navigator.getNewCards(limit);
|
|
2879
|
-
} catch (e) {
|
|
2880
|
-
logger.error(`[courseDB] Error in getNewCards: ${e}`);
|
|
2881
|
-
throw e;
|
|
2882
|
-
}
|
|
2883
|
-
}
|
|
2884
|
-
async getPendingReviews() {
|
|
2885
|
-
const u = await this._getCurrentUser();
|
|
2886
|
-
try {
|
|
2887
|
-
const navigator = await this.createNavigator(u);
|
|
2888
|
-
return navigator.getPendingReviews();
|
|
2889
|
-
} catch (e) {
|
|
2890
|
-
logger.error(`[courseDB] Error in getPendingReviews: ${e}`);
|
|
2891
|
-
throw e;
|
|
2892
|
-
}
|
|
2893
|
-
}
|
|
2894
2034
|
/**
|
|
2895
2035
|
* Get cards with suitability scores for presentation.
|
|
2896
2036
|
*
|
|
@@ -3129,79 +2269,27 @@ var init_classroomDB2 = __esm({
|
|
|
3129
2269
|
setChangeFcn(f) {
|
|
3130
2270
|
void this.userMessages.on("change", f);
|
|
3131
2271
|
}
|
|
3132
|
-
async getPendingReviews() {
|
|
3133
|
-
const u = this._user;
|
|
3134
|
-
return (await u.getPendingReviews()).filter((r) => r.scheduledFor === "classroom" && r.schedulingAgentId === this._id).map((r) => {
|
|
3135
|
-
return {
|
|
3136
|
-
...r,
|
|
3137
|
-
qualifiedID: `${r.courseId}-${r.cardId}`,
|
|
3138
|
-
courseID: r.courseId,
|
|
3139
|
-
cardID: r.cardId,
|
|
3140
|
-
contentSourceType: "classroom",
|
|
3141
|
-
contentSourceID: this._id,
|
|
3142
|
-
reviewID: r._id,
|
|
3143
|
-
status: "review"
|
|
3144
|
-
};
|
|
3145
|
-
});
|
|
3146
|
-
}
|
|
3147
|
-
async getNewCards() {
|
|
3148
|
-
const activeCards = await this._user.getActiveCards();
|
|
3149
|
-
const now = moment4.utc();
|
|
3150
|
-
const assigned = await this.getAssignedContent();
|
|
3151
|
-
const due = assigned.filter((c) => now.isAfter(moment4.utc(c.activeOn, REVIEW_TIME_FORMAT2)));
|
|
3152
|
-
logger.info(`Due content: ${JSON.stringify(due)}`);
|
|
3153
|
-
let ret = [];
|
|
3154
|
-
for (let i = 0; i < due.length; i++) {
|
|
3155
|
-
const content = due[i];
|
|
3156
|
-
if (content.type === "course") {
|
|
3157
|
-
const db = new CourseDB(content.courseID, async () => this._user);
|
|
3158
|
-
ret = ret.concat(await db.getNewCards());
|
|
3159
|
-
} else if (content.type === "tag") {
|
|
3160
|
-
const tagDoc = await getTag(content.courseID, content.tagID);
|
|
3161
|
-
ret = ret.concat(
|
|
3162
|
-
tagDoc.taggedCards.map((c) => {
|
|
3163
|
-
return {
|
|
3164
|
-
courseID: content.courseID,
|
|
3165
|
-
cardID: c,
|
|
3166
|
-
qualifiedID: `${content.courseID}-${c}`,
|
|
3167
|
-
contentSourceType: "classroom",
|
|
3168
|
-
contentSourceID: this._id,
|
|
3169
|
-
status: "new"
|
|
3170
|
-
};
|
|
3171
|
-
})
|
|
3172
|
-
);
|
|
3173
|
-
} else if (content.type === "card") {
|
|
3174
|
-
ret.push(await getCourseDB2(content.courseID).get(content.cardID));
|
|
3175
|
-
}
|
|
3176
|
-
}
|
|
3177
|
-
logger.info(
|
|
3178
|
-
`New Cards from classroom ${this._cfg.name}: ${ret.map((c) => `${c.courseID}-${c.cardID}`)}`
|
|
3179
|
-
);
|
|
3180
|
-
return ret.filter((c) => {
|
|
3181
|
-
if (activeCards.some((ac) => c.cardID === ac.cardID)) {
|
|
3182
|
-
return false;
|
|
3183
|
-
} else {
|
|
3184
|
-
return true;
|
|
3185
|
-
}
|
|
3186
|
-
});
|
|
3187
|
-
}
|
|
3188
2272
|
/**
|
|
3189
2273
|
* Get cards with suitability scores for presentation.
|
|
3190
2274
|
*
|
|
3191
|
-
*
|
|
3192
|
-
*
|
|
3193
|
-
* support pluggable navigation strategies.
|
|
2275
|
+
* Gathers new cards from assigned content (courses, tags, cards) and
|
|
2276
|
+
* pending reviews scheduled for this classroom. Assigns score=1.0 to all.
|
|
3194
2277
|
*
|
|
3195
2278
|
* @param limit - Maximum number of cards to return
|
|
3196
2279
|
* @returns Cards sorted by score descending (all scores = 1.0)
|
|
3197
2280
|
*/
|
|
3198
2281
|
async getWeightedCards(limit) {
|
|
3199
|
-
const
|
|
3200
|
-
const
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
2282
|
+
const weighted = [];
|
|
2283
|
+
const allUserReviews = await this._user.getPendingReviews();
|
|
2284
|
+
const classroomReviews = allUserReviews.filter(
|
|
2285
|
+
(r) => r.scheduledFor === "classroom" && r.schedulingAgentId === this._id
|
|
2286
|
+
);
|
|
2287
|
+
for (const r of classroomReviews) {
|
|
2288
|
+
weighted.push({
|
|
2289
|
+
cardId: r.cardId,
|
|
2290
|
+
courseId: r.courseId,
|
|
3204
2291
|
score: 1,
|
|
2292
|
+
reviewID: r._id,
|
|
3205
2293
|
provenance: [
|
|
3206
2294
|
{
|
|
3207
2295
|
strategy: "classroom",
|
|
@@ -3209,27 +2297,84 @@ var init_classroomDB2 = __esm({
|
|
|
3209
2297
|
strategyId: "CLASSROOM",
|
|
3210
2298
|
action: "generated",
|
|
3211
2299
|
score: 1,
|
|
3212
|
-
reason: "Classroom
|
|
2300
|
+
reason: "Classroom scheduled review"
|
|
3213
2301
|
}
|
|
3214
2302
|
]
|
|
3215
|
-
})
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
2303
|
+
});
|
|
2304
|
+
}
|
|
2305
|
+
const activeCards = await this._user.getActiveCards();
|
|
2306
|
+
const activeCardIds = new Set(activeCards.map((ac) => ac.cardID));
|
|
2307
|
+
const now = moment4.utc();
|
|
2308
|
+
const assigned = await this.getAssignedContent();
|
|
2309
|
+
const due = assigned.filter((c) => now.isAfter(moment4.utc(c.activeOn, REVIEW_TIME_FORMAT2)));
|
|
2310
|
+
logger.info(`[StudentClassroomDB] Due content: ${JSON.stringify(due)}`);
|
|
2311
|
+
for (const content of due) {
|
|
2312
|
+
if (content.type === "course") {
|
|
2313
|
+
const db = new CourseDB(content.courseID, async () => this._user);
|
|
2314
|
+
const courseCards = await db.getWeightedCards(limit);
|
|
2315
|
+
for (const card of courseCards) {
|
|
2316
|
+
if (!activeCardIds.has(card.cardId)) {
|
|
2317
|
+
weighted.push({
|
|
2318
|
+
...card,
|
|
2319
|
+
provenance: [
|
|
2320
|
+
...card.provenance,
|
|
2321
|
+
{
|
|
2322
|
+
strategy: "classroom",
|
|
2323
|
+
strategyName: "Classroom",
|
|
2324
|
+
strategyId: "CLASSROOM",
|
|
2325
|
+
action: "passed",
|
|
2326
|
+
score: card.score,
|
|
2327
|
+
reason: `Assigned via classroom from course ${content.courseID}`
|
|
2328
|
+
}
|
|
2329
|
+
]
|
|
2330
|
+
});
|
|
3228
2331
|
}
|
|
3229
|
-
|
|
3230
|
-
})
|
|
3231
|
-
|
|
3232
|
-
|
|
2332
|
+
}
|
|
2333
|
+
} else if (content.type === "tag") {
|
|
2334
|
+
const tagDoc = await getTag(content.courseID, content.tagID);
|
|
2335
|
+
for (const cardId of tagDoc.taggedCards) {
|
|
2336
|
+
if (!activeCardIds.has(cardId)) {
|
|
2337
|
+
weighted.push({
|
|
2338
|
+
cardId,
|
|
2339
|
+
courseId: content.courseID,
|
|
2340
|
+
score: 1,
|
|
2341
|
+
provenance: [
|
|
2342
|
+
{
|
|
2343
|
+
strategy: "classroom",
|
|
2344
|
+
strategyName: "Classroom",
|
|
2345
|
+
strategyId: "CLASSROOM",
|
|
2346
|
+
action: "generated",
|
|
2347
|
+
score: 1,
|
|
2348
|
+
reason: `Classroom assigned tag: ${content.tagID}, new card`
|
|
2349
|
+
}
|
|
2350
|
+
]
|
|
2351
|
+
});
|
|
2352
|
+
}
|
|
2353
|
+
}
|
|
2354
|
+
} else if (content.type === "card") {
|
|
2355
|
+
if (!activeCardIds.has(content.cardID)) {
|
|
2356
|
+
weighted.push({
|
|
2357
|
+
cardId: content.cardID,
|
|
2358
|
+
courseId: content.courseID,
|
|
2359
|
+
score: 1,
|
|
2360
|
+
provenance: [
|
|
2361
|
+
{
|
|
2362
|
+
strategy: "classroom",
|
|
2363
|
+
strategyName: "Classroom",
|
|
2364
|
+
strategyId: "CLASSROOM",
|
|
2365
|
+
action: "generated",
|
|
2366
|
+
score: 1,
|
|
2367
|
+
reason: "Classroom assigned card, new card"
|
|
2368
|
+
}
|
|
2369
|
+
]
|
|
2370
|
+
});
|
|
2371
|
+
}
|
|
2372
|
+
}
|
|
2373
|
+
}
|
|
2374
|
+
logger.info(
|
|
2375
|
+
`[StudentClassroomDB] New cards from classroom ${this._cfg.name}: ${weighted.length} total (reviews + new)`
|
|
2376
|
+
);
|
|
2377
|
+
return weighted.sort((a, b) => b.score - a.score).slice(0, limit);
|
|
3233
2378
|
}
|
|
3234
2379
|
};
|
|
3235
2380
|
}
|
|
@@ -4263,6 +3408,55 @@ Currently logged-in as ${this._username}.`
|
|
|
4263
3408
|
async updateUserElo(courseId, elo) {
|
|
4264
3409
|
return updateUserElo(this._username, courseId, elo);
|
|
4265
3410
|
}
|
|
3411
|
+
async getStrategyState(courseId, strategyKey) {
|
|
3412
|
+
const docId = buildStrategyStateId(courseId, strategyKey);
|
|
3413
|
+
try {
|
|
3414
|
+
const doc = await this.localDB.get(docId);
|
|
3415
|
+
return doc.data;
|
|
3416
|
+
} catch (e) {
|
|
3417
|
+
const err = e;
|
|
3418
|
+
if (err.status === 404) {
|
|
3419
|
+
return null;
|
|
3420
|
+
}
|
|
3421
|
+
throw e;
|
|
3422
|
+
}
|
|
3423
|
+
}
|
|
3424
|
+
async putStrategyState(courseId, strategyKey, data) {
|
|
3425
|
+
const docId = buildStrategyStateId(courseId, strategyKey);
|
|
3426
|
+
let existingRev;
|
|
3427
|
+
try {
|
|
3428
|
+
const existing = await this.localDB.get(docId);
|
|
3429
|
+
existingRev = existing._rev;
|
|
3430
|
+
} catch (e) {
|
|
3431
|
+
const err = e;
|
|
3432
|
+
if (err.status !== 404) {
|
|
3433
|
+
throw e;
|
|
3434
|
+
}
|
|
3435
|
+
}
|
|
3436
|
+
const doc = {
|
|
3437
|
+
_id: docId,
|
|
3438
|
+
_rev: existingRev,
|
|
3439
|
+
docType: "STRATEGY_STATE" /* STRATEGY_STATE */,
|
|
3440
|
+
courseId,
|
|
3441
|
+
strategyKey,
|
|
3442
|
+
data,
|
|
3443
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
3444
|
+
};
|
|
3445
|
+
await this.localDB.put(doc);
|
|
3446
|
+
}
|
|
3447
|
+
async deleteStrategyState(courseId, strategyKey) {
|
|
3448
|
+
const docId = buildStrategyStateId(courseId, strategyKey);
|
|
3449
|
+
try {
|
|
3450
|
+
const doc = await this.localDB.get(docId);
|
|
3451
|
+
await this.localDB.remove(doc);
|
|
3452
|
+
} catch (e) {
|
|
3453
|
+
const err = e;
|
|
3454
|
+
if (err.status === 404) {
|
|
3455
|
+
return;
|
|
3456
|
+
}
|
|
3457
|
+
throw e;
|
|
3458
|
+
}
|
|
3459
|
+
}
|
|
4266
3460
|
};
|
|
4267
3461
|
userCoursesDoc = "CourseRegistrations";
|
|
4268
3462
|
userClassroomsDoc = "ClassroomRegistrations";
|
|
@@ -4383,108 +3577,71 @@ var init_TagFilteredContentSource = __esm({
|
|
|
4383
3577
|
return finalCardIds;
|
|
4384
3578
|
}
|
|
4385
3579
|
/**
|
|
4386
|
-
*
|
|
3580
|
+
* Get cards with suitability scores for presentation.
|
|
3581
|
+
*
|
|
3582
|
+
* Filters cards by tag inclusion/exclusion and assigns score=1.0 to all.
|
|
3583
|
+
* TagFilteredContentSource does not currently support pluggable navigation
|
|
3584
|
+
* strategies - it returns flat-scored candidates.
|
|
3585
|
+
*
|
|
3586
|
+
* @param limit - Maximum number of cards to return
|
|
3587
|
+
* @returns Cards sorted by score descending (all scores = 1.0)
|
|
4387
3588
|
*/
|
|
4388
|
-
async
|
|
3589
|
+
async getWeightedCards(limit) {
|
|
4389
3590
|
if (!hasActiveFilter(this.filter)) {
|
|
4390
|
-
logger.warn("[TagFilteredContentSource]
|
|
3591
|
+
logger.warn("[TagFilteredContentSource] getWeightedCards called with no active filter");
|
|
4391
3592
|
return [];
|
|
4392
3593
|
}
|
|
4393
3594
|
const eligibleCardIds = await this.resolveFilteredCardIds();
|
|
4394
3595
|
const activeCards = await this.user.getActiveCards();
|
|
4395
3596
|
const activeCardIds = new Set(activeCards.map((c) => c.cardID));
|
|
4396
|
-
const
|
|
3597
|
+
const newCardWeighted = [];
|
|
4397
3598
|
for (const cardId of eligibleCardIds) {
|
|
4398
3599
|
if (!activeCardIds.has(cardId)) {
|
|
4399
|
-
|
|
4400
|
-
|
|
4401
|
-
|
|
4402
|
-
|
|
4403
|
-
|
|
4404
|
-
|
|
3600
|
+
newCardWeighted.push({
|
|
3601
|
+
cardId,
|
|
3602
|
+
courseId: this.courseId,
|
|
3603
|
+
score: 1,
|
|
3604
|
+
provenance: [
|
|
3605
|
+
{
|
|
3606
|
+
strategy: "tagFilter",
|
|
3607
|
+
strategyName: "Tag Filter",
|
|
3608
|
+
strategyId: "TAG_FILTER",
|
|
3609
|
+
action: "generated",
|
|
3610
|
+
score: 1,
|
|
3611
|
+
reason: `Tag-filtered new card (tags: ${this.filter.include.join(", ")})`
|
|
3612
|
+
}
|
|
3613
|
+
]
|
|
4405
3614
|
});
|
|
4406
3615
|
}
|
|
4407
|
-
if (
|
|
3616
|
+
if (newCardWeighted.length >= limit) {
|
|
4408
3617
|
break;
|
|
4409
3618
|
}
|
|
4410
3619
|
}
|
|
4411
|
-
logger.info(
|
|
4412
|
-
|
|
4413
|
-
|
|
4414
|
-
/**
|
|
4415
|
-
* Gets pending reviews, filtered to only include cards that match the tag filter.
|
|
4416
|
-
*/
|
|
4417
|
-
async getPendingReviews() {
|
|
4418
|
-
if (!hasActiveFilter(this.filter)) {
|
|
4419
|
-
logger.warn("[TagFilteredContentSource] getPendingReviews called with no active filter");
|
|
4420
|
-
return [];
|
|
4421
|
-
}
|
|
4422
|
-
const eligibleCardIds = await this.resolveFilteredCardIds();
|
|
3620
|
+
logger.info(
|
|
3621
|
+
`[TagFilteredContentSource] Found ${newCardWeighted.length} new cards matching filter`
|
|
3622
|
+
);
|
|
4423
3623
|
const allReviews = await this.user.getPendingReviews(this.courseId);
|
|
4424
|
-
const filteredReviews = allReviews.filter((review) =>
|
|
4425
|
-
return eligibleCardIds.has(review.cardId);
|
|
4426
|
-
});
|
|
3624
|
+
const filteredReviews = allReviews.filter((review) => eligibleCardIds.has(review.cardId));
|
|
4427
3625
|
logger.info(
|
|
4428
3626
|
`[TagFilteredContentSource] Found ${filteredReviews.length} pending reviews matching filter (of ${allReviews.length} total)`
|
|
4429
3627
|
);
|
|
4430
|
-
|
|
4431
|
-
|
|
4432
|
-
|
|
4433
|
-
|
|
4434
|
-
contentSourceType: "course",
|
|
4435
|
-
contentSourceID: this.courseId,
|
|
3628
|
+
const reviewWeighted = filteredReviews.map((r) => ({
|
|
3629
|
+
cardId: r.cardId,
|
|
3630
|
+
courseId: r.courseId,
|
|
3631
|
+
score: 1,
|
|
4436
3632
|
reviewID: r._id,
|
|
4437
|
-
|
|
3633
|
+
provenance: [
|
|
3634
|
+
{
|
|
3635
|
+
strategy: "tagFilter",
|
|
3636
|
+
strategyName: "Tag Filter",
|
|
3637
|
+
strategyId: "TAG_FILTER",
|
|
3638
|
+
action: "generated",
|
|
3639
|
+
score: 1,
|
|
3640
|
+
reason: `Tag-filtered review (tags: ${this.filter.include.join(", ")})`
|
|
3641
|
+
}
|
|
3642
|
+
]
|
|
4438
3643
|
}));
|
|
4439
|
-
|
|
4440
|
-
/**
|
|
4441
|
-
* Get cards with suitability scores for presentation.
|
|
4442
|
-
*
|
|
4443
|
-
* This implementation wraps the legacy getNewCards/getPendingReviews methods,
|
|
4444
|
-
* assigning score=1.0 to all cards. TagFilteredContentSource does not currently
|
|
4445
|
-
* support pluggable navigation strategies - it returns flat-scored candidates.
|
|
4446
|
-
*
|
|
4447
|
-
* @param limit - Maximum number of cards to return
|
|
4448
|
-
* @returns Cards sorted by score descending (all scores = 1.0)
|
|
4449
|
-
*/
|
|
4450
|
-
async getWeightedCards(limit) {
|
|
4451
|
-
const [newCards, reviews] = await Promise.all([
|
|
4452
|
-
this.getNewCards(limit),
|
|
4453
|
-
this.getPendingReviews()
|
|
4454
|
-
]);
|
|
4455
|
-
const weighted = [
|
|
4456
|
-
...reviews.map((r) => ({
|
|
4457
|
-
cardId: r.cardID,
|
|
4458
|
-
courseId: r.courseID,
|
|
4459
|
-
score: 1,
|
|
4460
|
-
provenance: [
|
|
4461
|
-
{
|
|
4462
|
-
strategy: "tagFilter",
|
|
4463
|
-
strategyName: "Tag Filter",
|
|
4464
|
-
strategyId: "TAG_FILTER",
|
|
4465
|
-
action: "generated",
|
|
4466
|
-
score: 1,
|
|
4467
|
-
reason: `Tag-filtered review (tags: ${this.filter.include.join(", ")})`
|
|
4468
|
-
}
|
|
4469
|
-
]
|
|
4470
|
-
})),
|
|
4471
|
-
...newCards.map((c) => ({
|
|
4472
|
-
cardId: c.cardID,
|
|
4473
|
-
courseId: c.courseID,
|
|
4474
|
-
score: 1,
|
|
4475
|
-
provenance: [
|
|
4476
|
-
{
|
|
4477
|
-
strategy: "tagFilter",
|
|
4478
|
-
strategyName: "Tag Filter",
|
|
4479
|
-
strategyId: "TAG_FILTER",
|
|
4480
|
-
action: "generated",
|
|
4481
|
-
score: 1,
|
|
4482
|
-
reason: `Tag-filtered new card (tags: ${this.filter.include.join(", ")})`
|
|
4483
|
-
}
|
|
4484
|
-
]
|
|
4485
|
-
}))
|
|
4486
|
-
];
|
|
4487
|
-
return weighted.slice(0, limit);
|
|
3644
|
+
return [...reviewWeighted, ...newCardWeighted].slice(0, limit);
|
|
4488
3645
|
}
|
|
4489
3646
|
/**
|
|
4490
3647
|
* Clears the cached resolved card IDs.
|
|
@@ -4575,6 +3732,16 @@ var init_user = __esm({
|
|
|
4575
3732
|
}
|
|
4576
3733
|
});
|
|
4577
3734
|
|
|
3735
|
+
// src/core/types/strategyState.ts
|
|
3736
|
+
function buildStrategyStateId(courseId, strategyKey) {
|
|
3737
|
+
return `STRATEGY_STATE::${courseId}::${strategyKey}`;
|
|
3738
|
+
}
|
|
3739
|
+
var init_strategyState = __esm({
|
|
3740
|
+
"src/core/types/strategyState.ts"() {
|
|
3741
|
+
"use strict";
|
|
3742
|
+
}
|
|
3743
|
+
});
|
|
3744
|
+
|
|
4578
3745
|
// src/core/bulkImport/cardProcessor.ts
|
|
4579
3746
|
import { Status as Status4 } from "@vue-skuilder/common";
|
|
4580
3747
|
async function importParsedCards(parsedCards, courseDB, config) {
|
|
@@ -4696,7 +3863,7 @@ var init_cardProcessor = __esm({
|
|
|
4696
3863
|
});
|
|
4697
3864
|
|
|
4698
3865
|
// src/core/bulkImport/types.ts
|
|
4699
|
-
var
|
|
3866
|
+
var init_types = __esm({
|
|
4700
3867
|
"src/core/bulkImport/types.ts"() {
|
|
4701
3868
|
"use strict";
|
|
4702
3869
|
}
|
|
@@ -4707,7 +3874,7 @@ var init_bulkImport = __esm({
|
|
|
4707
3874
|
"src/core/bulkImport/index.ts"() {
|
|
4708
3875
|
"use strict";
|
|
4709
3876
|
init_cardProcessor();
|
|
4710
|
-
|
|
3877
|
+
init_types();
|
|
4711
3878
|
}
|
|
4712
3879
|
});
|
|
4713
3880
|
|
|
@@ -4717,6 +3884,7 @@ var init_core = __esm({
|
|
|
4717
3884
|
init_interfaces();
|
|
4718
3885
|
init_types_legacy();
|
|
4719
3886
|
init_user();
|
|
3887
|
+
init_strategyState();
|
|
4720
3888
|
init_Loggable();
|
|
4721
3889
|
init_util();
|
|
4722
3890
|
init_navigators();
|
|
@@ -4734,6 +3902,7 @@ export {
|
|
|
4734
3902
|
NavigatorRoles,
|
|
4735
3903
|
Navigators,
|
|
4736
3904
|
areQuestionRecords,
|
|
3905
|
+
buildStrategyStateId,
|
|
4737
3906
|
docIsDeleted,
|
|
4738
3907
|
getCardHistoryID,
|
|
4739
3908
|
getCardOrigin,
|