@vue-skuilder/db 0.1.20 → 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-CZdMBiTU.d.ts → contentSource-BP9hznNV.d.ts} +150 -196
- package/dist/{classroomDB-PxDZTky3.d.cts → contentSource-DsJadoBU.d.cts} +150 -196
- package/dist/core/index.d.cts +3 -3
- package/dist/core/index.d.ts +3 -3
- package/dist/core/index.js +615 -1758
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.mjs +579 -1727
- package/dist/core/index.mjs.map +1 -1
- package/dist/{dataLayerProvider-D8o6ZnKW.d.ts → dataLayerProvider-CHYrQ5pB.d.cts} +1 -1
- package/dist/{dataLayerProvider-D0MoZMjH.d.cts → dataLayerProvider-MDTxXq2l.d.ts} +1 -1
- package/dist/impl/couch/index.d.cts +6 -22
- package/dist/impl/couch/index.d.ts +6 -22
- package/dist/impl/couch/index.js +598 -1769
- package/dist/impl/couch/index.js.map +1 -1
- package/dist/impl/couch/index.mjs +579 -1755
- package/dist/impl/couch/index.mjs.map +1 -1
- package/dist/impl/static/index.d.cts +22 -6
- package/dist/impl/static/index.d.ts +22 -6
- package/dist/impl/static/index.js +617 -1629
- package/dist/impl/static/index.js.map +1 -1
- package/dist/impl/static/index.mjs +607 -1624
- package/dist/impl/static/index.mjs.map +1 -1
- package/dist/index.d.cts +64 -56
- package/dist/index.d.ts +64 -56
- package/dist/index.js +1000 -2161
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +970 -2127
- 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/docs/navigators-architecture.md +2 -9
- package/package.json +3 -3
- package/src/core/interfaces/classroomDB.ts +5 -13
- package/src/core/interfaces/contentSource.ts +6 -66
- package/src/core/interfaces/courseDB.ts +2 -7
- package/src/core/navigators/Pipeline.ts +24 -53
- 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} +11 -25
- package/src/core/navigators/{interferenceMitigator.ts → filters/interferenceMitigator.ts} +10 -24
- package/src/core/navigators/{relativePriority.ts → filters/relativePriority.ts} +10 -24
- package/src/core/navigators/filters/userTagPreference.ts +1 -16
- 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 +36 -91
- package/src/impl/couch/classroomDB.ts +100 -103
- package/src/impl/couch/courseDB.ts +5 -81
- package/src/impl/couch/pouchdb-setup.ts +7 -0
- package/src/impl/static/StaticDataUnpacker.ts +50 -1
- package/src/impl/static/courseDB.ts +76 -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 +5 -72
- package/tests/core/navigators/PipelineAssembler.test.ts +8 -58
- package/tests/core/navigators/navigators.test.ts +118 -151
- package/src/core/navigators/hardcodedOrder.ts +0 -163
- package/src/util/tuiLogger.ts +0 -139
- /package/src/core/navigators/{inferredPreference.ts → filters/inferredPreferenceStub.ts} +0 -0
- /package/src/core/navigators/{userGoal.ts → filters/userGoalStub.ts} +0 -0
package/dist/impl/couch/index.js
CHANGED
|
@@ -5,11 +5,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __glob = (map) => (path2) => {
|
|
9
|
-
var fn = map[path2];
|
|
10
|
-
if (fn) return fn();
|
|
11
|
-
throw new Error("Module not found in bundle: " + path2);
|
|
12
|
-
};
|
|
13
8
|
var __esm = (fn, res) => function __init() {
|
|
14
9
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
15
10
|
};
|
|
@@ -111,6 +106,9 @@ var init_pouchdb_setup = __esm({
|
|
|
111
106
|
import_pouchdb_authentication = __toESM(require("@nilock2/pouchdb-authentication"), 1);
|
|
112
107
|
import_pouchdb.default.plugin(import_pouchdb_find.default);
|
|
113
108
|
import_pouchdb.default.plugin(import_pouchdb_authentication.default);
|
|
109
|
+
if (typeof import_pouchdb.default.debug !== "undefined") {
|
|
110
|
+
import_pouchdb.default.debug.disable();
|
|
111
|
+
}
|
|
114
112
|
import_pouchdb.default.defaults({
|
|
115
113
|
// ajax: {
|
|
116
114
|
// timeout: 60000,
|
|
@@ -622,195 +620,159 @@ var init_courseLookupDB = __esm({
|
|
|
622
620
|
}
|
|
623
621
|
});
|
|
624
622
|
|
|
625
|
-
// src/core/navigators/
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
var
|
|
633
|
-
|
|
623
|
+
// src/core/navigators/index.ts
|
|
624
|
+
function isGenerator(impl) {
|
|
625
|
+
return NavigatorRoles[impl] === "generator" /* GENERATOR */;
|
|
626
|
+
}
|
|
627
|
+
function isFilter(impl) {
|
|
628
|
+
return NavigatorRoles[impl] === "filter" /* FILTER */;
|
|
629
|
+
}
|
|
630
|
+
var NavigatorRoles, ContentNavigator;
|
|
631
|
+
var init_navigators = __esm({
|
|
632
|
+
"src/core/navigators/index.ts"() {
|
|
634
633
|
"use strict";
|
|
635
|
-
init_navigators();
|
|
636
634
|
init_logger();
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
/**
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
if (generators.length === 0) {
|
|
655
|
-
throw new Error("CompositeGenerator requires at least one generator");
|
|
656
|
-
}
|
|
657
|
-
logger.debug(
|
|
658
|
-
`[CompositeGenerator] Created with ${generators.length} generators, mode: ${aggregationMode}`
|
|
659
|
-
);
|
|
660
|
-
}
|
|
635
|
+
NavigatorRoles = {
|
|
636
|
+
["elo" /* ELO */]: "generator" /* GENERATOR */,
|
|
637
|
+
["srs" /* SRS */]: "generator" /* GENERATOR */,
|
|
638
|
+
["hierarchyDefinition" /* HIERARCHY */]: "filter" /* FILTER */,
|
|
639
|
+
["interferenceMitigator" /* INTERFERENCE */]: "filter" /* FILTER */,
|
|
640
|
+
["relativePriority" /* RELATIVE_PRIORITY */]: "filter" /* FILTER */,
|
|
641
|
+
["userTagPreference" /* USER_TAG_PREFERENCE */]: "filter" /* FILTER */
|
|
642
|
+
};
|
|
643
|
+
ContentNavigator = class {
|
|
644
|
+
/** User interface for this navigation session */
|
|
645
|
+
user;
|
|
646
|
+
/** Course interface for this navigation session */
|
|
647
|
+
course;
|
|
648
|
+
/** Human-readable name for this strategy instance (from ContentNavigationStrategyData.name) */
|
|
649
|
+
strategyName;
|
|
650
|
+
/** Unique document ID for this strategy instance (from ContentNavigationStrategyData._id) */
|
|
651
|
+
strategyId;
|
|
661
652
|
/**
|
|
662
|
-
*
|
|
653
|
+
* Constructor for standard navigators.
|
|
654
|
+
* Call this from subclass constructors to initialize common fields.
|
|
663
655
|
*
|
|
664
|
-
*
|
|
656
|
+
* Note: CompositeGenerator and Pipeline call super() without args, then set
|
|
657
|
+
* user/course fields directly if needed.
|
|
665
658
|
*/
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
)
|
|
670
|
-
|
|
659
|
+
constructor(user, course, strategyData) {
|
|
660
|
+
this.user = user;
|
|
661
|
+
this.course = course;
|
|
662
|
+
if (strategyData) {
|
|
663
|
+
this.strategyName = strategyData.name;
|
|
664
|
+
this.strategyId = strategyData._id;
|
|
665
|
+
}
|
|
671
666
|
}
|
|
667
|
+
// ============================================================================
|
|
668
|
+
// STRATEGY STATE HELPERS
|
|
669
|
+
// ============================================================================
|
|
670
|
+
//
|
|
671
|
+
// These methods allow strategies to persist their own state (user preferences,
|
|
672
|
+
// learned patterns, temporal tracking) in the user database.
|
|
673
|
+
//
|
|
674
|
+
// ============================================================================
|
|
672
675
|
/**
|
|
673
|
-
*
|
|
674
|
-
*
|
|
675
|
-
* Cards appearing in multiple generators receive a score boost.
|
|
676
|
-
* Provenance tracks which generators produced each card and how scores were aggregated.
|
|
677
|
-
*
|
|
678
|
-
* This method supports both the legacy signature (limit only) and the
|
|
679
|
-
* CardGenerator interface signature (limit, context).
|
|
676
|
+
* Unique key identifying this strategy for state storage.
|
|
680
677
|
*
|
|
681
|
-
*
|
|
682
|
-
*
|
|
678
|
+
* Defaults to the constructor name (e.g., "UserTagPreferenceFilter").
|
|
679
|
+
* Override in subclasses if multiple instances of the same strategy type
|
|
680
|
+
* need separate state storage.
|
|
683
681
|
*/
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
this.generators.map((g) => g.getWeightedCards(limit, context))
|
|
687
|
-
);
|
|
688
|
-
const byCardId = /* @__PURE__ */ new Map();
|
|
689
|
-
for (const cards of results) {
|
|
690
|
-
for (const card of cards) {
|
|
691
|
-
const existing = byCardId.get(card.cardId) || [];
|
|
692
|
-
existing.push(card);
|
|
693
|
-
byCardId.set(card.cardId, existing);
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
const merged = [];
|
|
697
|
-
for (const [, cards] of byCardId) {
|
|
698
|
-
const aggregatedScore = this.aggregateScores(cards);
|
|
699
|
-
const finalScore = Math.min(1, aggregatedScore);
|
|
700
|
-
const mergedProvenance = cards.flatMap((c) => c.provenance);
|
|
701
|
-
const initialScore = cards[0].score;
|
|
702
|
-
const action = finalScore > initialScore ? "boosted" : finalScore < initialScore ? "penalized" : "passed";
|
|
703
|
-
const reason = this.buildAggregationReason(cards, finalScore);
|
|
704
|
-
merged.push({
|
|
705
|
-
...cards[0],
|
|
706
|
-
score: finalScore,
|
|
707
|
-
provenance: [
|
|
708
|
-
...mergedProvenance,
|
|
709
|
-
{
|
|
710
|
-
strategy: "composite",
|
|
711
|
-
strategyName: "Composite Generator",
|
|
712
|
-
strategyId: "COMPOSITE_GENERATOR",
|
|
713
|
-
action,
|
|
714
|
-
score: finalScore,
|
|
715
|
-
reason
|
|
716
|
-
}
|
|
717
|
-
]
|
|
718
|
-
});
|
|
719
|
-
}
|
|
720
|
-
return merged.sort((a, b) => b.score - a.score).slice(0, limit);
|
|
682
|
+
get strategyKey() {
|
|
683
|
+
return this.constructor.name;
|
|
721
684
|
}
|
|
722
685
|
/**
|
|
723
|
-
*
|
|
686
|
+
* Get this strategy's persisted state for the current course.
|
|
687
|
+
*
|
|
688
|
+
* @returns The strategy's data payload, or null if no state exists
|
|
689
|
+
* @throws Error if user or course is not initialized
|
|
724
690
|
*/
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
}
|
|
731
|
-
const strategies = cards.map((c) => c.provenance[0]?.strategy || "unknown").join(", ");
|
|
732
|
-
switch (this.aggregationMode) {
|
|
733
|
-
case "max" /* MAX */:
|
|
734
|
-
return `Max of ${count} generators (${strategies}): scores [${scores}] \u2192 ${finalScore.toFixed(2)}`;
|
|
735
|
-
case "average" /* AVERAGE */:
|
|
736
|
-
return `Average of ${count} generators (${strategies}): scores [${scores}] \u2192 ${finalScore.toFixed(2)}`;
|
|
737
|
-
case "frequencyBoost" /* FREQUENCY_BOOST */: {
|
|
738
|
-
const avg = cards.reduce((sum, c) => sum + c.score, 0) / count;
|
|
739
|
-
const boost = 1 + FREQUENCY_BOOST_FACTOR * (count - 1);
|
|
740
|
-
return `Frequency boost from ${count} generators (${strategies}): avg ${avg.toFixed(2)} \xD7 ${boost.toFixed(2)} \u2192 ${finalScore.toFixed(2)}`;
|
|
741
|
-
}
|
|
742
|
-
default:
|
|
743
|
-
return `Aggregated from ${count} generators: ${finalScore.toFixed(2)}`;
|
|
691
|
+
async getStrategyState() {
|
|
692
|
+
if (!this.user || !this.course) {
|
|
693
|
+
throw new Error(
|
|
694
|
+
`Cannot get strategy state: navigator not properly initialized. Ensure user and course are provided to constructor.`
|
|
695
|
+
);
|
|
744
696
|
}
|
|
697
|
+
return this.user.getStrategyState(this.course.getCourseID(), this.strategyKey);
|
|
745
698
|
}
|
|
746
699
|
/**
|
|
747
|
-
*
|
|
700
|
+
* Persist this strategy's state for the current course.
|
|
701
|
+
*
|
|
702
|
+
* @param data - The strategy's data payload to store
|
|
703
|
+
* @throws Error if user or course is not initialized
|
|
748
704
|
*/
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
case "average" /* AVERAGE */:
|
|
755
|
-
return scores.reduce((sum, s) => sum + s, 0) / scores.length;
|
|
756
|
-
case "frequencyBoost" /* FREQUENCY_BOOST */: {
|
|
757
|
-
const avg = scores.reduce((sum, s) => sum + s, 0) / scores.length;
|
|
758
|
-
const frequencyBoost = 1 + FREQUENCY_BOOST_FACTOR * (cards.length - 1);
|
|
759
|
-
return avg * frequencyBoost;
|
|
760
|
-
}
|
|
761
|
-
default:
|
|
762
|
-
return scores[0];
|
|
705
|
+
async putStrategyState(data) {
|
|
706
|
+
if (!this.user || !this.course) {
|
|
707
|
+
throw new Error(
|
|
708
|
+
`Cannot put strategy state: navigator not properly initialized. Ensure user and course are provided to constructor.`
|
|
709
|
+
);
|
|
763
710
|
}
|
|
711
|
+
return this.user.putStrategyState(this.course.getCourseID(), this.strategyKey, data);
|
|
764
712
|
}
|
|
765
713
|
/**
|
|
766
|
-
*
|
|
714
|
+
* Factory method to create navigator instances dynamically.
|
|
715
|
+
*
|
|
716
|
+
* @param user - User interface
|
|
717
|
+
* @param course - Course interface
|
|
718
|
+
* @param strategyData - Strategy configuration document
|
|
719
|
+
* @returns the runtime object used to steer a study session.
|
|
767
720
|
*/
|
|
768
|
-
async
|
|
769
|
-
const
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
const
|
|
773
|
-
const
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
721
|
+
static async create(user, course, strategyData) {
|
|
722
|
+
const implementingClass = strategyData.implementingClass;
|
|
723
|
+
let NavigatorImpl;
|
|
724
|
+
const variations = [".ts", ".js", ""];
|
|
725
|
+
const dirs = ["filters", "generators"];
|
|
726
|
+
for (const ext of variations) {
|
|
727
|
+
for (const dir of dirs) {
|
|
728
|
+
const loadFrom = `./${dir}/${implementingClass}${ext}`;
|
|
729
|
+
try {
|
|
730
|
+
const module2 = await import(loadFrom);
|
|
731
|
+
NavigatorImpl = module2.default;
|
|
732
|
+
break;
|
|
733
|
+
} catch (e) {
|
|
734
|
+
logger.debug(`Failed to load extension from ${loadFrom}:`, e);
|
|
780
735
|
}
|
|
781
736
|
}
|
|
782
737
|
}
|
|
783
|
-
|
|
738
|
+
if (!NavigatorImpl) {
|
|
739
|
+
throw new Error(`Could not load navigator implementation for: ${implementingClass}`);
|
|
740
|
+
}
|
|
741
|
+
return new NavigatorImpl(user, course, strategyData);
|
|
784
742
|
}
|
|
785
743
|
/**
|
|
786
|
-
* Get
|
|
744
|
+
* Get cards with suitability scores and provenance trails.
|
|
745
|
+
*
|
|
746
|
+
* **This is the PRIMARY API for navigation strategies.**
|
|
747
|
+
*
|
|
748
|
+
* Returns cards ranked by suitability score (0-1). Higher scores indicate
|
|
749
|
+
* better candidates for presentation. Each card includes a provenance trail
|
|
750
|
+
* documenting how strategies contributed to the final score.
|
|
751
|
+
*
|
|
752
|
+
* ## Implementation Required
|
|
753
|
+
* All navigation strategies MUST override this method. The base class does
|
|
754
|
+
* not provide a default implementation.
|
|
755
|
+
*
|
|
756
|
+
* ## For Generators
|
|
757
|
+
* Override this method to generate candidates and compute scores based on
|
|
758
|
+
* your strategy's logic (e.g., ELO proximity, review urgency). Create the
|
|
759
|
+
* initial provenance entry with action='generated'.
|
|
760
|
+
*
|
|
761
|
+
* ## For Filters
|
|
762
|
+
* Filters should implement the CardFilter interface instead and be composed
|
|
763
|
+
* via Pipeline. Filters do not directly implement getWeightedCards().
|
|
764
|
+
*
|
|
765
|
+
* @param limit - Maximum cards to return
|
|
766
|
+
* @returns Cards sorted by score descending, with provenance trails
|
|
787
767
|
*/
|
|
788
|
-
async
|
|
789
|
-
|
|
790
|
-
(g) => g instanceof ContentNavigator
|
|
791
|
-
);
|
|
792
|
-
const results = await Promise.all(legacyGenerators.map((g) => g.getPendingReviews()));
|
|
793
|
-
const seen = /* @__PURE__ */ new Set();
|
|
794
|
-
const merged = [];
|
|
795
|
-
for (const reviews of results) {
|
|
796
|
-
for (const review of reviews) {
|
|
797
|
-
if (!seen.has(review.cardID)) {
|
|
798
|
-
seen.add(review.cardID);
|
|
799
|
-
merged.push(review);
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
}
|
|
803
|
-
return merged;
|
|
768
|
+
async getWeightedCards(_limit) {
|
|
769
|
+
throw new Error(`${this.constructor.name} must implement getWeightedCards(). `);
|
|
804
770
|
}
|
|
805
771
|
};
|
|
806
772
|
}
|
|
807
773
|
});
|
|
808
774
|
|
|
809
775
|
// src/core/navigators/Pipeline.ts
|
|
810
|
-
var Pipeline_exports = {};
|
|
811
|
-
__export(Pipeline_exports, {
|
|
812
|
-
Pipeline: () => Pipeline
|
|
813
|
-
});
|
|
814
776
|
function logPipelineConfig(generator, filters) {
|
|
815
777
|
const filterList = filters.length > 0 ? "\n - " + filters.map((f) => f.name).join("\n - ") : " none";
|
|
816
778
|
logger.info(
|
|
@@ -870,6 +832,11 @@ var init_Pipeline = __esm({
|
|
|
870
832
|
this.filters = filters;
|
|
871
833
|
this.user = user;
|
|
872
834
|
this.course = course;
|
|
835
|
+
course.getCourseConfig().then((cfg) => {
|
|
836
|
+
logger.debug(`[pipeline] Crated pipeline for ${cfg.name}`);
|
|
837
|
+
}).catch((e) => {
|
|
838
|
+
logger.error(`[pipeline] Failed to lookup courseCfg: ${e}`);
|
|
839
|
+
});
|
|
873
840
|
logPipelineConfig(generator, filters);
|
|
874
841
|
}
|
|
875
842
|
/**
|
|
@@ -906,7 +873,13 @@ var init_Pipeline = __esm({
|
|
|
906
873
|
cards.sort((a, b) => b.score - a.score);
|
|
907
874
|
const result = cards.slice(0, limit);
|
|
908
875
|
const topScores = result.slice(0, 3).map((c) => c.score);
|
|
909
|
-
logExecutionSummary(
|
|
876
|
+
logExecutionSummary(
|
|
877
|
+
this.generator.name,
|
|
878
|
+
generatedCount,
|
|
879
|
+
this.filters.length,
|
|
880
|
+
result.length,
|
|
881
|
+
topScores
|
|
882
|
+
);
|
|
910
883
|
logCardProvenance(result, 3);
|
|
911
884
|
return result;
|
|
912
885
|
}
|
|
@@ -955,33 +928,6 @@ var init_Pipeline = __esm({
|
|
|
955
928
|
userElo
|
|
956
929
|
};
|
|
957
930
|
}
|
|
958
|
-
// ===========================================================================
|
|
959
|
-
// Legacy StudyContentSource methods
|
|
960
|
-
// ===========================================================================
|
|
961
|
-
//
|
|
962
|
-
// These delegate to the generator for backward compatibility.
|
|
963
|
-
// Eventually SessionController will use getWeightedCards() exclusively.
|
|
964
|
-
//
|
|
965
|
-
/**
|
|
966
|
-
* Get new cards via legacy API.
|
|
967
|
-
* Delegates to the generator if it supports the legacy interface.
|
|
968
|
-
*/
|
|
969
|
-
async getNewCards(n) {
|
|
970
|
-
if ("getNewCards" in this.generator && typeof this.generator.getNewCards === "function") {
|
|
971
|
-
return this.generator.getNewCards(n);
|
|
972
|
-
}
|
|
973
|
-
return [];
|
|
974
|
-
}
|
|
975
|
-
/**
|
|
976
|
-
* Get pending reviews via legacy API.
|
|
977
|
-
* Delegates to the generator if it supports the legacy interface.
|
|
978
|
-
*/
|
|
979
|
-
async getPendingReviews() {
|
|
980
|
-
if ("getPendingReviews" in this.generator && typeof this.generator.getPendingReviews === "function") {
|
|
981
|
-
return this.generator.getPendingReviews();
|
|
982
|
-
}
|
|
983
|
-
return [];
|
|
984
|
-
}
|
|
985
931
|
/**
|
|
986
932
|
* Get the course ID for this pipeline.
|
|
987
933
|
*/
|
|
@@ -992,29 +938,163 @@ var init_Pipeline = __esm({
|
|
|
992
938
|
}
|
|
993
939
|
});
|
|
994
940
|
|
|
995
|
-
// src/core/navigators/
|
|
996
|
-
var
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
});
|
|
1000
|
-
var PipelineAssembler;
|
|
1001
|
-
var init_PipelineAssembler = __esm({
|
|
1002
|
-
"src/core/navigators/PipelineAssembler.ts"() {
|
|
941
|
+
// src/core/navigators/generators/CompositeGenerator.ts
|
|
942
|
+
var DEFAULT_AGGREGATION_MODE, FREQUENCY_BOOST_FACTOR, CompositeGenerator;
|
|
943
|
+
var init_CompositeGenerator = __esm({
|
|
944
|
+
"src/core/navigators/generators/CompositeGenerator.ts"() {
|
|
1003
945
|
"use strict";
|
|
1004
946
|
init_navigators();
|
|
1005
|
-
init_Pipeline();
|
|
1006
|
-
init_types_legacy();
|
|
1007
947
|
init_logger();
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
948
|
+
DEFAULT_AGGREGATION_MODE = "frequencyBoost" /* FREQUENCY_BOOST */;
|
|
949
|
+
FREQUENCY_BOOST_FACTOR = 0.1;
|
|
950
|
+
CompositeGenerator = class _CompositeGenerator extends ContentNavigator {
|
|
951
|
+
/** Human-readable name for CardGenerator interface */
|
|
952
|
+
name = "Composite Generator";
|
|
953
|
+
generators;
|
|
954
|
+
aggregationMode;
|
|
955
|
+
constructor(generators, aggregationMode = DEFAULT_AGGREGATION_MODE) {
|
|
956
|
+
super();
|
|
957
|
+
this.generators = generators;
|
|
958
|
+
this.aggregationMode = aggregationMode;
|
|
959
|
+
if (generators.length === 0) {
|
|
960
|
+
throw new Error("CompositeGenerator requires at least one generator");
|
|
961
|
+
}
|
|
962
|
+
logger.debug(
|
|
963
|
+
`[CompositeGenerator] Created with ${generators.length} generators, mode: ${aggregationMode}`
|
|
964
|
+
);
|
|
965
|
+
}
|
|
966
|
+
/**
|
|
967
|
+
* Creates a CompositeGenerator from strategy data.
|
|
968
|
+
*
|
|
969
|
+
* This is a convenience factory for use by PipelineAssembler.
|
|
970
|
+
*/
|
|
971
|
+
static async fromStrategies(user, course, strategies, aggregationMode = DEFAULT_AGGREGATION_MODE) {
|
|
972
|
+
const generators = await Promise.all(
|
|
973
|
+
strategies.map((s) => ContentNavigator.create(user, course, s))
|
|
974
|
+
);
|
|
975
|
+
return new _CompositeGenerator(generators, aggregationMode);
|
|
976
|
+
}
|
|
977
|
+
/**
|
|
978
|
+
* Get weighted cards from all generators, merge and deduplicate.
|
|
979
|
+
*
|
|
980
|
+
* Cards appearing in multiple generators receive a score boost.
|
|
981
|
+
* Provenance tracks which generators produced each card and how scores were aggregated.
|
|
982
|
+
*
|
|
983
|
+
* This method supports both the legacy signature (limit only) and the
|
|
984
|
+
* CardGenerator interface signature (limit, context).
|
|
985
|
+
*
|
|
986
|
+
* @param limit - Maximum number of cards to return
|
|
987
|
+
* @param context - GeneratorContext passed to child generators (required when called via Pipeline)
|
|
988
|
+
*/
|
|
989
|
+
async getWeightedCards(limit, context) {
|
|
990
|
+
if (!context) {
|
|
991
|
+
throw new Error(
|
|
992
|
+
"CompositeGenerator.getWeightedCards requires a GeneratorContext. It should be called via Pipeline, not directly."
|
|
993
|
+
);
|
|
994
|
+
}
|
|
995
|
+
const results = await Promise.all(
|
|
996
|
+
this.generators.map((g) => g.getWeightedCards(limit, context))
|
|
997
|
+
);
|
|
998
|
+
const byCardId = /* @__PURE__ */ new Map();
|
|
999
|
+
for (const cards of results) {
|
|
1000
|
+
for (const card of cards) {
|
|
1001
|
+
const existing = byCardId.get(card.cardId) || [];
|
|
1002
|
+
existing.push(card);
|
|
1003
|
+
byCardId.set(card.cardId, existing);
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
const merged = [];
|
|
1007
|
+
for (const [, cards] of byCardId) {
|
|
1008
|
+
const aggregatedScore = this.aggregateScores(cards);
|
|
1009
|
+
const finalScore = Math.min(1, aggregatedScore);
|
|
1010
|
+
const mergedProvenance = cards.flatMap((c) => c.provenance);
|
|
1011
|
+
const initialScore = cards[0].score;
|
|
1012
|
+
const action = finalScore > initialScore ? "boosted" : finalScore < initialScore ? "penalized" : "passed";
|
|
1013
|
+
const reason = this.buildAggregationReason(cards, finalScore);
|
|
1014
|
+
merged.push({
|
|
1015
|
+
...cards[0],
|
|
1016
|
+
score: finalScore,
|
|
1017
|
+
provenance: [
|
|
1018
|
+
...mergedProvenance,
|
|
1019
|
+
{
|
|
1020
|
+
strategy: "composite",
|
|
1021
|
+
strategyName: "Composite Generator",
|
|
1022
|
+
strategyId: "COMPOSITE_GENERATOR",
|
|
1023
|
+
action,
|
|
1024
|
+
score: finalScore,
|
|
1025
|
+
reason
|
|
1026
|
+
}
|
|
1027
|
+
]
|
|
1028
|
+
});
|
|
1029
|
+
}
|
|
1030
|
+
return merged.sort((a, b) => b.score - a.score).slice(0, limit);
|
|
1031
|
+
}
|
|
1032
|
+
/**
|
|
1033
|
+
* Build human-readable reason for score aggregation.
|
|
1034
|
+
*/
|
|
1035
|
+
buildAggregationReason(cards, finalScore) {
|
|
1036
|
+
const count = cards.length;
|
|
1037
|
+
const scores = cards.map((c) => c.score.toFixed(2)).join(", ");
|
|
1038
|
+
if (count === 1) {
|
|
1039
|
+
return `Single generator, score ${finalScore.toFixed(2)}`;
|
|
1040
|
+
}
|
|
1041
|
+
const strategies = cards.map((c) => c.provenance[0]?.strategy || "unknown").join(", ");
|
|
1042
|
+
switch (this.aggregationMode) {
|
|
1043
|
+
case "max" /* MAX */:
|
|
1044
|
+
return `Max of ${count} generators (${strategies}): scores [${scores}] \u2192 ${finalScore.toFixed(2)}`;
|
|
1045
|
+
case "average" /* AVERAGE */:
|
|
1046
|
+
return `Average of ${count} generators (${strategies}): scores [${scores}] \u2192 ${finalScore.toFixed(2)}`;
|
|
1047
|
+
case "frequencyBoost" /* FREQUENCY_BOOST */: {
|
|
1048
|
+
const avg = cards.reduce((sum, c) => sum + c.score, 0) / count;
|
|
1049
|
+
const boost = 1 + FREQUENCY_BOOST_FACTOR * (count - 1);
|
|
1050
|
+
return `Frequency boost from ${count} generators (${strategies}): avg ${avg.toFixed(2)} \xD7 ${boost.toFixed(2)} \u2192 ${finalScore.toFixed(2)}`;
|
|
1051
|
+
}
|
|
1052
|
+
default:
|
|
1053
|
+
return `Aggregated from ${count} generators: ${finalScore.toFixed(2)}`;
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
/**
|
|
1057
|
+
* Aggregate scores from multiple generators for the same card.
|
|
1058
|
+
*/
|
|
1059
|
+
aggregateScores(cards) {
|
|
1060
|
+
const scores = cards.map((c) => c.score);
|
|
1061
|
+
switch (this.aggregationMode) {
|
|
1062
|
+
case "max" /* MAX */:
|
|
1063
|
+
return Math.max(...scores);
|
|
1064
|
+
case "average" /* AVERAGE */:
|
|
1065
|
+
return scores.reduce((sum, s) => sum + s, 0) / scores.length;
|
|
1066
|
+
case "frequencyBoost" /* FREQUENCY_BOOST */: {
|
|
1067
|
+
const avg = scores.reduce((sum, s) => sum + s, 0) / scores.length;
|
|
1068
|
+
const frequencyBoost = 1 + FREQUENCY_BOOST_FACTOR * (cards.length - 1);
|
|
1069
|
+
return avg * frequencyBoost;
|
|
1070
|
+
}
|
|
1071
|
+
default:
|
|
1072
|
+
return scores[0];
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
};
|
|
1076
|
+
}
|
|
1077
|
+
});
|
|
1078
|
+
|
|
1079
|
+
// src/core/navigators/PipelineAssembler.ts
|
|
1080
|
+
var PipelineAssembler;
|
|
1081
|
+
var init_PipelineAssembler = __esm({
|
|
1082
|
+
"src/core/navigators/PipelineAssembler.ts"() {
|
|
1083
|
+
"use strict";
|
|
1084
|
+
init_navigators();
|
|
1085
|
+
init_Pipeline();
|
|
1086
|
+
init_types_legacy();
|
|
1087
|
+
init_logger();
|
|
1088
|
+
init_CompositeGenerator();
|
|
1089
|
+
PipelineAssembler = class {
|
|
1090
|
+
/**
|
|
1091
|
+
* Assembles a navigation pipeline from strategy documents.
|
|
1092
|
+
*
|
|
1093
|
+
* 1. Separates into generators and filters by role
|
|
1094
|
+
* 2. Validates at least one generator exists (or creates default ELO)
|
|
1095
|
+
* 3. Instantiates generators - wraps multiple in CompositeGenerator
|
|
1096
|
+
* 4. Instantiates filters
|
|
1097
|
+
* 5. Returns Pipeline(generator, filters)
|
|
1018
1098
|
*
|
|
1019
1099
|
* @param input - Strategy documents plus user/course interfaces
|
|
1020
1100
|
* @returns Assembled pipeline and any warnings
|
|
@@ -1117,14 +1197,10 @@ var init_PipelineAssembler = __esm({
|
|
|
1117
1197
|
}
|
|
1118
1198
|
});
|
|
1119
1199
|
|
|
1120
|
-
// src/core/navigators/elo.ts
|
|
1121
|
-
var elo_exports = {};
|
|
1122
|
-
__export(elo_exports, {
|
|
1123
|
-
default: () => ELONavigator
|
|
1124
|
-
});
|
|
1200
|
+
// src/core/navigators/generators/elo.ts
|
|
1125
1201
|
var import_common6, ELONavigator;
|
|
1126
1202
|
var init_elo = __esm({
|
|
1127
|
-
"src/core/navigators/elo.ts"() {
|
|
1203
|
+
"src/core/navigators/generators/elo.ts"() {
|
|
1128
1204
|
"use strict";
|
|
1129
1205
|
init_navigators();
|
|
1130
1206
|
import_common6 = require("@vue-skuilder/common");
|
|
@@ -1135,50 +1211,6 @@ var init_elo = __esm({
|
|
|
1135
1211
|
super(user, course, strategyData);
|
|
1136
1212
|
this.name = strategyData?.name || "ELO";
|
|
1137
1213
|
}
|
|
1138
|
-
async getPendingReviews() {
|
|
1139
|
-
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
1140
|
-
const elo = await this.course.getCardEloData(reviews.map((r) => r.cardId));
|
|
1141
|
-
const ratedReviews = reviews.map((r, i) => {
|
|
1142
|
-
const ratedR = {
|
|
1143
|
-
...r,
|
|
1144
|
-
...elo[i]
|
|
1145
|
-
};
|
|
1146
|
-
return ratedR;
|
|
1147
|
-
});
|
|
1148
|
-
ratedReviews.sort((a, b) => {
|
|
1149
|
-
return a.global.score - b.global.score;
|
|
1150
|
-
});
|
|
1151
|
-
return ratedReviews.map((r) => {
|
|
1152
|
-
return {
|
|
1153
|
-
...r,
|
|
1154
|
-
contentSourceType: "course",
|
|
1155
|
-
contentSourceID: this.course.getCourseID(),
|
|
1156
|
-
cardID: r.cardId,
|
|
1157
|
-
courseID: r.courseId,
|
|
1158
|
-
qualifiedID: `${r.courseId}-${r.cardId}`,
|
|
1159
|
-
reviewID: r._id,
|
|
1160
|
-
status: "review"
|
|
1161
|
-
};
|
|
1162
|
-
});
|
|
1163
|
-
}
|
|
1164
|
-
async getNewCards(limit = 99) {
|
|
1165
|
-
const activeCards = await this.user.getActiveCards();
|
|
1166
|
-
return (await this.course.getCardsCenteredAtELO(
|
|
1167
|
-
{ limit, elo: "user" },
|
|
1168
|
-
(c) => {
|
|
1169
|
-
if (activeCards.some((ac) => c.cardID === ac.cardID)) {
|
|
1170
|
-
return false;
|
|
1171
|
-
} else {
|
|
1172
|
-
return true;
|
|
1173
|
-
}
|
|
1174
|
-
}
|
|
1175
|
-
)).map((c) => {
|
|
1176
|
-
return {
|
|
1177
|
-
...c,
|
|
1178
|
-
status: "new"
|
|
1179
|
-
};
|
|
1180
|
-
});
|
|
1181
|
-
}
|
|
1182
1214
|
/**
|
|
1183
1215
|
* Get new cards with suitability scores based on ELO distance.
|
|
1184
1216
|
*
|
|
@@ -1203,7 +1235,11 @@ var init_elo = __esm({
|
|
|
1203
1235
|
const userElo = (0, import_common6.toCourseElo)(courseReg.elo);
|
|
1204
1236
|
userGlobalElo = userElo.global.score;
|
|
1205
1237
|
}
|
|
1206
|
-
const
|
|
1238
|
+
const activeCards = await this.user.getActiveCards();
|
|
1239
|
+
const newCards = (await this.course.getCardsCenteredAtELO(
|
|
1240
|
+
{ limit, elo: "user" },
|
|
1241
|
+
(c) => !activeCards.some((ac) => c.cardID === ac.cardID)
|
|
1242
|
+
)).map((c) => ({ ...c, status: "new" }));
|
|
1207
1243
|
const cardIds = newCards.map((c) => c.cardID);
|
|
1208
1244
|
const cardEloData = await this.course.getCardEloData(cardIds);
|
|
1209
1245
|
const scored = newCards.map((c, i) => {
|
|
@@ -1233,946 +1269,35 @@ var init_elo = __esm({
|
|
|
1233
1269
|
}
|
|
1234
1270
|
});
|
|
1235
1271
|
|
|
1236
|
-
// src/core/navigators/
|
|
1237
|
-
var
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
DEFAULT_MAX_MULTIPLIER: () => DEFAULT_MAX_MULTIPLIER,
|
|
1241
|
-
DEFAULT_MIN_MULTIPLIER: () => DEFAULT_MIN_MULTIPLIER,
|
|
1242
|
-
createEloDistanceFilter: () => createEloDistanceFilter
|
|
1243
|
-
});
|
|
1244
|
-
function computeMultiplier(distance, halfLife, minMultiplier, maxMultiplier) {
|
|
1245
|
-
const normalizedDistance = distance / halfLife;
|
|
1246
|
-
const decay = Math.exp(-(normalizedDistance * normalizedDistance));
|
|
1247
|
-
return minMultiplier + (maxMultiplier - minMultiplier) * decay;
|
|
1248
|
-
}
|
|
1249
|
-
function createEloDistanceFilter(config) {
|
|
1250
|
-
const halfLife = config?.halfLife ?? DEFAULT_HALF_LIFE;
|
|
1251
|
-
const minMultiplier = config?.minMultiplier ?? DEFAULT_MIN_MULTIPLIER;
|
|
1252
|
-
const maxMultiplier = config?.maxMultiplier ?? DEFAULT_MAX_MULTIPLIER;
|
|
1253
|
-
return {
|
|
1254
|
-
name: "ELO Distance Filter",
|
|
1255
|
-
async transform(cards, context) {
|
|
1256
|
-
const { course, userElo } = context;
|
|
1257
|
-
const cardIds = cards.map((c) => c.cardId);
|
|
1258
|
-
const cardElos = await course.getCardEloData(cardIds);
|
|
1259
|
-
return cards.map((card, i) => {
|
|
1260
|
-
const cardElo = cardElos[i]?.global?.score ?? 1e3;
|
|
1261
|
-
const distance = Math.abs(cardElo - userElo);
|
|
1262
|
-
const multiplier = computeMultiplier(distance, halfLife, minMultiplier, maxMultiplier);
|
|
1263
|
-
const newScore = card.score * multiplier;
|
|
1264
|
-
const action = multiplier < maxMultiplier - 0.01 ? "penalized" : "passed";
|
|
1265
|
-
return {
|
|
1266
|
-
...card,
|
|
1267
|
-
score: newScore,
|
|
1268
|
-
provenance: [
|
|
1269
|
-
...card.provenance,
|
|
1270
|
-
{
|
|
1271
|
-
strategy: "eloDistance",
|
|
1272
|
-
strategyName: "ELO Distance Filter",
|
|
1273
|
-
strategyId: "ELO_DISTANCE_FILTER",
|
|
1274
|
-
action,
|
|
1275
|
-
score: newScore,
|
|
1276
|
-
reason: `ELO distance ${Math.round(distance)} (card: ${Math.round(cardElo)}, user: ${Math.round(userElo)}) \u2192 ${multiplier.toFixed(2)}x`
|
|
1277
|
-
}
|
|
1278
|
-
]
|
|
1279
|
-
};
|
|
1280
|
-
});
|
|
1281
|
-
}
|
|
1282
|
-
};
|
|
1283
|
-
}
|
|
1284
|
-
var DEFAULT_HALF_LIFE, DEFAULT_MIN_MULTIPLIER, DEFAULT_MAX_MULTIPLIER;
|
|
1285
|
-
var init_eloDistance = __esm({
|
|
1286
|
-
"src/core/navigators/filters/eloDistance.ts"() {
|
|
1287
|
-
"use strict";
|
|
1288
|
-
DEFAULT_HALF_LIFE = 200;
|
|
1289
|
-
DEFAULT_MIN_MULTIPLIER = 0.3;
|
|
1290
|
-
DEFAULT_MAX_MULTIPLIER = 1;
|
|
1291
|
-
}
|
|
1292
|
-
});
|
|
1293
|
-
|
|
1294
|
-
// src/core/navigators/filters/userTagPreference.ts
|
|
1295
|
-
var userTagPreference_exports = {};
|
|
1296
|
-
__export(userTagPreference_exports, {
|
|
1297
|
-
default: () => UserTagPreferenceFilter
|
|
1298
|
-
});
|
|
1299
|
-
var UserTagPreferenceFilter;
|
|
1300
|
-
var init_userTagPreference = __esm({
|
|
1301
|
-
"src/core/navigators/filters/userTagPreference.ts"() {
|
|
1272
|
+
// src/core/navigators/generators/srs.ts
|
|
1273
|
+
var import_moment, SRSNavigator;
|
|
1274
|
+
var init_srs = __esm({
|
|
1275
|
+
"src/core/navigators/generators/srs.ts"() {
|
|
1302
1276
|
"use strict";
|
|
1277
|
+
import_moment = __toESM(require("moment"), 1);
|
|
1303
1278
|
init_navigators();
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
/** Human-readable name for
|
|
1279
|
+
init_logger();
|
|
1280
|
+
SRSNavigator = class extends ContentNavigator {
|
|
1281
|
+
/** Human-readable name for CardGenerator interface */
|
|
1307
1282
|
name;
|
|
1308
1283
|
constructor(user, course, strategyData) {
|
|
1309
1284
|
super(user, course, strategyData);
|
|
1310
|
-
this.
|
|
1311
|
-
this.name = strategyData.name || "User Tag Preferences";
|
|
1312
|
-
}
|
|
1313
|
-
/**
|
|
1314
|
-
* Compute multiplier for a card based on its tags and user preferences.
|
|
1315
|
-
* Returns the maximum multiplier among all matching tags, or 1.0 if no matches.
|
|
1316
|
-
*/
|
|
1317
|
-
computeMultiplier(cardTags, boostMap) {
|
|
1318
|
-
const multipliers = cardTags.map((tag) => boostMap[tag]).filter((val) => val !== void 0);
|
|
1319
|
-
if (multipliers.length === 0) {
|
|
1320
|
-
return 1;
|
|
1321
|
-
}
|
|
1322
|
-
return Math.max(...multipliers);
|
|
1323
|
-
}
|
|
1324
|
-
/**
|
|
1325
|
-
* Build human-readable reason for the filter's decision.
|
|
1326
|
-
*/
|
|
1327
|
-
buildReason(cardTags, boostMap, multiplier) {
|
|
1328
|
-
const matchingTags = cardTags.filter((tag) => boostMap[tag] === multiplier);
|
|
1329
|
-
if (multiplier === 0) {
|
|
1330
|
-
return `Excluded by user preference: ${matchingTags.join(", ")} (${multiplier}x)`;
|
|
1331
|
-
}
|
|
1332
|
-
if (multiplier < 1) {
|
|
1333
|
-
return `Penalized by user preference: ${matchingTags.join(", ")} (${multiplier.toFixed(2)}x)`;
|
|
1334
|
-
}
|
|
1335
|
-
if (multiplier > 1) {
|
|
1336
|
-
return `Boosted by user preference: ${matchingTags.join(", ")} (${multiplier.toFixed(2)}x)`;
|
|
1337
|
-
}
|
|
1338
|
-
return "No matching user preferences";
|
|
1285
|
+
this.name = strategyData?.name || "SRS";
|
|
1339
1286
|
}
|
|
1340
1287
|
/**
|
|
1341
|
-
*
|
|
1288
|
+
* Get review cards scored by urgency.
|
|
1289
|
+
*
|
|
1290
|
+
* Score formula combines:
|
|
1291
|
+
* - Relative overdueness: hoursOverdue / intervalHours
|
|
1292
|
+
* - Interval recency: exponential decay favoring shorter intervals
|
|
1293
|
+
*
|
|
1294
|
+
* Cards not yet due are excluded (not scored as 0).
|
|
1342
1295
|
*
|
|
1343
|
-
*
|
|
1344
|
-
*
|
|
1345
|
-
*
|
|
1346
|
-
*
|
|
1347
|
-
*
|
|
1348
|
-
* - If tag found: apply multiplier (0 = exclude, 1 = neutral, >1 = boost)
|
|
1349
|
-
* - If multiple tags match: use max multiplier
|
|
1350
|
-
* - Append provenance with clear reason
|
|
1351
|
-
*/
|
|
1352
|
-
async transform(cards, _context) {
|
|
1353
|
-
const prefs = await this.getStrategyState();
|
|
1354
|
-
if (!prefs || Object.keys(prefs.boost).length === 0) {
|
|
1355
|
-
return cards.map((card) => ({
|
|
1356
|
-
...card,
|
|
1357
|
-
provenance: [
|
|
1358
|
-
...card.provenance,
|
|
1359
|
-
{
|
|
1360
|
-
strategy: "userTagPreference",
|
|
1361
|
-
strategyName: this.strategyName || this.name,
|
|
1362
|
-
strategyId: this.strategyId || this._strategyData._id,
|
|
1363
|
-
action: "passed",
|
|
1364
|
-
score: card.score,
|
|
1365
|
-
reason: "No user tag preferences configured"
|
|
1366
|
-
}
|
|
1367
|
-
]
|
|
1368
|
-
}));
|
|
1369
|
-
}
|
|
1370
|
-
const adjusted = await Promise.all(
|
|
1371
|
-
cards.map(async (card) => {
|
|
1372
|
-
const cardTags = card.tags ?? [];
|
|
1373
|
-
const multiplier = this.computeMultiplier(cardTags, prefs.boost);
|
|
1374
|
-
const finalScore = Math.min(1, card.score * multiplier);
|
|
1375
|
-
let action;
|
|
1376
|
-
if (multiplier === 0 || multiplier < 1) {
|
|
1377
|
-
action = "penalized";
|
|
1378
|
-
} else if (multiplier > 1) {
|
|
1379
|
-
action = "boosted";
|
|
1380
|
-
} else {
|
|
1381
|
-
action = "passed";
|
|
1382
|
-
}
|
|
1383
|
-
return {
|
|
1384
|
-
...card,
|
|
1385
|
-
score: finalScore,
|
|
1386
|
-
provenance: [
|
|
1387
|
-
...card.provenance,
|
|
1388
|
-
{
|
|
1389
|
-
strategy: "userTagPreference",
|
|
1390
|
-
strategyName: this.strategyName || this.name,
|
|
1391
|
-
strategyId: this.strategyId || this._strategyData._id,
|
|
1392
|
-
action,
|
|
1393
|
-
score: finalScore,
|
|
1394
|
-
reason: this.buildReason(cardTags, prefs.boost, multiplier)
|
|
1395
|
-
}
|
|
1396
|
-
]
|
|
1397
|
-
};
|
|
1398
|
-
})
|
|
1399
|
-
);
|
|
1400
|
-
return adjusted;
|
|
1401
|
-
}
|
|
1402
|
-
/**
|
|
1403
|
-
* Legacy getWeightedCards - throws as filters should not be used as generators.
|
|
1404
|
-
*/
|
|
1405
|
-
async getWeightedCards(_limit) {
|
|
1406
|
-
throw new Error(
|
|
1407
|
-
"UserTagPreferenceFilter is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
|
|
1408
|
-
);
|
|
1409
|
-
}
|
|
1410
|
-
// Legacy methods - stub implementations since filters don't generate cards
|
|
1411
|
-
async getNewCards(_n) {
|
|
1412
|
-
return [];
|
|
1413
|
-
}
|
|
1414
|
-
async getPendingReviews() {
|
|
1415
|
-
return [];
|
|
1416
|
-
}
|
|
1417
|
-
};
|
|
1418
|
-
}
|
|
1419
|
-
});
|
|
1420
|
-
|
|
1421
|
-
// src/core/navigators/filters/index.ts
|
|
1422
|
-
var filters_exports = {};
|
|
1423
|
-
__export(filters_exports, {
|
|
1424
|
-
UserTagPreferenceFilter: () => UserTagPreferenceFilter,
|
|
1425
|
-
createEloDistanceFilter: () => createEloDistanceFilter
|
|
1426
|
-
});
|
|
1427
|
-
var init_filters = __esm({
|
|
1428
|
-
"src/core/navigators/filters/index.ts"() {
|
|
1429
|
-
"use strict";
|
|
1430
|
-
init_eloDistance();
|
|
1431
|
-
init_userTagPreference();
|
|
1432
|
-
}
|
|
1433
|
-
});
|
|
1434
|
-
|
|
1435
|
-
// src/core/navigators/filters/types.ts
|
|
1436
|
-
var types_exports = {};
|
|
1437
|
-
var init_types = __esm({
|
|
1438
|
-
"src/core/navigators/filters/types.ts"() {
|
|
1439
|
-
"use strict";
|
|
1440
|
-
}
|
|
1441
|
-
});
|
|
1442
|
-
|
|
1443
|
-
// src/core/navigators/generators/index.ts
|
|
1444
|
-
var generators_exports = {};
|
|
1445
|
-
var init_generators = __esm({
|
|
1446
|
-
"src/core/navigators/generators/index.ts"() {
|
|
1447
|
-
"use strict";
|
|
1448
|
-
}
|
|
1449
|
-
});
|
|
1450
|
-
|
|
1451
|
-
// src/core/navigators/generators/types.ts
|
|
1452
|
-
var types_exports2 = {};
|
|
1453
|
-
var init_types2 = __esm({
|
|
1454
|
-
"src/core/navigators/generators/types.ts"() {
|
|
1455
|
-
"use strict";
|
|
1456
|
-
}
|
|
1457
|
-
});
|
|
1458
|
-
|
|
1459
|
-
// src/core/navigators/hardcodedOrder.ts
|
|
1460
|
-
var hardcodedOrder_exports = {};
|
|
1461
|
-
__export(hardcodedOrder_exports, {
|
|
1462
|
-
default: () => HardcodedOrderNavigator
|
|
1463
|
-
});
|
|
1464
|
-
var HardcodedOrderNavigator;
|
|
1465
|
-
var init_hardcodedOrder = __esm({
|
|
1466
|
-
"src/core/navigators/hardcodedOrder.ts"() {
|
|
1467
|
-
"use strict";
|
|
1468
|
-
init_navigators();
|
|
1469
|
-
init_logger();
|
|
1470
|
-
HardcodedOrderNavigator = class extends ContentNavigator {
|
|
1471
|
-
/** Human-readable name for CardGenerator interface */
|
|
1472
|
-
name;
|
|
1473
|
-
orderedCardIds = [];
|
|
1474
|
-
constructor(user, course, strategyData) {
|
|
1475
|
-
super(user, course, strategyData);
|
|
1476
|
-
this.name = strategyData.name || "Hardcoded Order";
|
|
1477
|
-
if (strategyData.serializedData) {
|
|
1478
|
-
try {
|
|
1479
|
-
this.orderedCardIds = JSON.parse(strategyData.serializedData);
|
|
1480
|
-
} catch (e) {
|
|
1481
|
-
logger.error("Failed to parse serializedData for HardcodedOrderNavigator", e);
|
|
1482
|
-
}
|
|
1483
|
-
}
|
|
1484
|
-
}
|
|
1485
|
-
async getPendingReviews() {
|
|
1486
|
-
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
1487
|
-
return reviews.map((r) => {
|
|
1488
|
-
return {
|
|
1489
|
-
...r,
|
|
1490
|
-
contentSourceType: "course",
|
|
1491
|
-
contentSourceID: this.course.getCourseID(),
|
|
1492
|
-
cardID: r.cardId,
|
|
1493
|
-
courseID: r.courseId,
|
|
1494
|
-
reviewID: r._id,
|
|
1495
|
-
status: "review"
|
|
1496
|
-
};
|
|
1497
|
-
});
|
|
1498
|
-
}
|
|
1499
|
-
async getNewCards(limit = 99) {
|
|
1500
|
-
const activeCardIds = (await this.user.getActiveCards()).map((c) => c.cardID);
|
|
1501
|
-
const newCardIds = this.orderedCardIds.filter((cardId) => !activeCardIds.includes(cardId));
|
|
1502
|
-
const cardsToReturn = newCardIds.slice(0, limit);
|
|
1503
|
-
return cardsToReturn.map((cardId) => {
|
|
1504
|
-
return {
|
|
1505
|
-
cardID: cardId,
|
|
1506
|
-
courseID: this.course.getCourseID(),
|
|
1507
|
-
contentSourceType: "course",
|
|
1508
|
-
contentSourceID: this.course.getCourseID(),
|
|
1509
|
-
status: "new"
|
|
1510
|
-
};
|
|
1511
|
-
});
|
|
1512
|
-
}
|
|
1513
|
-
/**
|
|
1514
|
-
* Get cards in hardcoded order with scores based on position.
|
|
1515
|
-
*
|
|
1516
|
-
* Earlier cards in the sequence get higher scores.
|
|
1517
|
-
* Score formula: 1.0 - (position / totalCards) * 0.5
|
|
1518
|
-
* This ensures scores range from 1.0 (first card) to 0.5+ (last card).
|
|
1519
|
-
*
|
|
1520
|
-
* This method supports both the legacy signature (limit only) and the
|
|
1521
|
-
* CardGenerator interface signature (limit, context).
|
|
1522
|
-
*
|
|
1523
|
-
* @param limit - Maximum number of cards to return
|
|
1524
|
-
* @param _context - Optional GeneratorContext (currently unused, but required for interface)
|
|
1525
|
-
*/
|
|
1526
|
-
async getWeightedCards(limit, _context) {
|
|
1527
|
-
const activeCardIds = (await this.user.getActiveCards()).map((c) => c.cardID);
|
|
1528
|
-
const reviews = await this.getPendingReviews();
|
|
1529
|
-
const newCardIds = this.orderedCardIds.filter((cardId) => !activeCardIds.includes(cardId));
|
|
1530
|
-
const totalCards = newCardIds.length;
|
|
1531
|
-
const scoredNew = newCardIds.slice(0, limit).map((cardId, index) => {
|
|
1532
|
-
const position = index + 1;
|
|
1533
|
-
const score = Math.max(0.5, 1 - index / totalCards * 0.5);
|
|
1534
|
-
return {
|
|
1535
|
-
cardId,
|
|
1536
|
-
courseId: this.course.getCourseID(),
|
|
1537
|
-
score,
|
|
1538
|
-
provenance: [
|
|
1539
|
-
{
|
|
1540
|
-
strategy: "hardcodedOrder",
|
|
1541
|
-
strategyName: this.strategyName || this.name,
|
|
1542
|
-
strategyId: this.strategyId || "NAVIGATION_STRATEGY-hardcoded",
|
|
1543
|
-
action: "generated",
|
|
1544
|
-
score,
|
|
1545
|
-
reason: `Position ${position} of ${totalCards} in fixed sequence, new card`
|
|
1546
|
-
}
|
|
1547
|
-
]
|
|
1548
|
-
};
|
|
1549
|
-
});
|
|
1550
|
-
const scoredReviews = reviews.map((r) => ({
|
|
1551
|
-
cardId: r.cardID,
|
|
1552
|
-
courseId: r.courseID,
|
|
1553
|
-
score: 1,
|
|
1554
|
-
provenance: [
|
|
1555
|
-
{
|
|
1556
|
-
strategy: "hardcodedOrder",
|
|
1557
|
-
strategyName: this.strategyName || this.name,
|
|
1558
|
-
strategyId: this.strategyId || "NAVIGATION_STRATEGY-hardcoded",
|
|
1559
|
-
action: "generated",
|
|
1560
|
-
score: 1,
|
|
1561
|
-
reason: "Scheduled review, highest priority"
|
|
1562
|
-
}
|
|
1563
|
-
]
|
|
1564
|
-
}));
|
|
1565
|
-
const all = [...scoredReviews, ...scoredNew];
|
|
1566
|
-
all.sort((a, b) => b.score - a.score);
|
|
1567
|
-
return all.slice(0, limit);
|
|
1568
|
-
}
|
|
1569
|
-
};
|
|
1570
|
-
}
|
|
1571
|
-
});
|
|
1572
|
-
|
|
1573
|
-
// src/core/navigators/hierarchyDefinition.ts
|
|
1574
|
-
var hierarchyDefinition_exports = {};
|
|
1575
|
-
__export(hierarchyDefinition_exports, {
|
|
1576
|
-
default: () => HierarchyDefinitionNavigator
|
|
1577
|
-
});
|
|
1578
|
-
var import_common7, DEFAULT_MIN_COUNT, HierarchyDefinitionNavigator;
|
|
1579
|
-
var init_hierarchyDefinition = __esm({
|
|
1580
|
-
"src/core/navigators/hierarchyDefinition.ts"() {
|
|
1581
|
-
"use strict";
|
|
1582
|
-
init_navigators();
|
|
1583
|
-
import_common7 = require("@vue-skuilder/common");
|
|
1584
|
-
DEFAULT_MIN_COUNT = 3;
|
|
1585
|
-
HierarchyDefinitionNavigator = class extends ContentNavigator {
|
|
1586
|
-
config;
|
|
1587
|
-
_strategyData;
|
|
1588
|
-
/** Human-readable name for CardFilter interface */
|
|
1589
|
-
name;
|
|
1590
|
-
constructor(user, course, _strategyData) {
|
|
1591
|
-
super(user, course, _strategyData);
|
|
1592
|
-
this._strategyData = _strategyData;
|
|
1593
|
-
this.config = this.parseConfig(_strategyData.serializedData);
|
|
1594
|
-
this.name = _strategyData.name || "Hierarchy Definition";
|
|
1595
|
-
}
|
|
1596
|
-
parseConfig(serializedData) {
|
|
1597
|
-
try {
|
|
1598
|
-
const parsed = JSON.parse(serializedData);
|
|
1599
|
-
return {
|
|
1600
|
-
prerequisites: parsed.prerequisites || {}
|
|
1601
|
-
};
|
|
1602
|
-
} catch {
|
|
1603
|
-
return {
|
|
1604
|
-
prerequisites: {}
|
|
1605
|
-
};
|
|
1606
|
-
}
|
|
1607
|
-
}
|
|
1608
|
-
/**
|
|
1609
|
-
* Check if a specific prerequisite is satisfied
|
|
1610
|
-
*/
|
|
1611
|
-
isPrerequisiteMet(prereq, userTagElo, userGlobalElo) {
|
|
1612
|
-
if (!userTagElo) return false;
|
|
1613
|
-
const minCount = prereq.masteryThreshold?.minCount ?? DEFAULT_MIN_COUNT;
|
|
1614
|
-
if (userTagElo.count < minCount) return false;
|
|
1615
|
-
if (prereq.masteryThreshold?.minElo !== void 0) {
|
|
1616
|
-
return userTagElo.score >= prereq.masteryThreshold.minElo;
|
|
1617
|
-
} else {
|
|
1618
|
-
return userTagElo.score >= userGlobalElo;
|
|
1619
|
-
}
|
|
1620
|
-
}
|
|
1621
|
-
/**
|
|
1622
|
-
* Get the set of tags the user has mastered.
|
|
1623
|
-
* A tag is "mastered" if it appears as a prerequisite somewhere and meets its threshold.
|
|
1624
|
-
*/
|
|
1625
|
-
async getMasteredTags(context) {
|
|
1626
|
-
const mastered = /* @__PURE__ */ new Set();
|
|
1627
|
-
try {
|
|
1628
|
-
const courseReg = await context.user.getCourseRegDoc(context.course.getCourseID());
|
|
1629
|
-
const userElo = (0, import_common7.toCourseElo)(courseReg.elo);
|
|
1630
|
-
for (const prereqs of Object.values(this.config.prerequisites)) {
|
|
1631
|
-
for (const prereq of prereqs) {
|
|
1632
|
-
const tagElo = userElo.tags[prereq.tag];
|
|
1633
|
-
if (this.isPrerequisiteMet(prereq, tagElo, userElo.global.score)) {
|
|
1634
|
-
mastered.add(prereq.tag);
|
|
1635
|
-
}
|
|
1636
|
-
}
|
|
1637
|
-
}
|
|
1638
|
-
} catch {
|
|
1639
|
-
}
|
|
1640
|
-
return mastered;
|
|
1641
|
-
}
|
|
1642
|
-
/**
|
|
1643
|
-
* Get the set of tags that are unlocked (prerequisites met)
|
|
1644
|
-
*/
|
|
1645
|
-
getUnlockedTags(masteredTags) {
|
|
1646
|
-
const unlocked = /* @__PURE__ */ new Set();
|
|
1647
|
-
for (const [tagId, prereqs] of Object.entries(this.config.prerequisites)) {
|
|
1648
|
-
const allPrereqsMet = prereqs.every((prereq) => masteredTags.has(prereq.tag));
|
|
1649
|
-
if (allPrereqsMet) {
|
|
1650
|
-
unlocked.add(tagId);
|
|
1651
|
-
}
|
|
1652
|
-
}
|
|
1653
|
-
return unlocked;
|
|
1654
|
-
}
|
|
1655
|
-
/**
|
|
1656
|
-
* Check if a tag has prerequisites defined in config
|
|
1657
|
-
*/
|
|
1658
|
-
hasPrerequisites(tagId) {
|
|
1659
|
-
return tagId in this.config.prerequisites;
|
|
1660
|
-
}
|
|
1661
|
-
/**
|
|
1662
|
-
* Check if a card is unlocked and generate reason.
|
|
1663
|
-
*/
|
|
1664
|
-
async checkCardUnlock(card, course, unlockedTags, masteredTags) {
|
|
1665
|
-
try {
|
|
1666
|
-
const cardTags = card.tags ?? [];
|
|
1667
|
-
const lockedTags = cardTags.filter(
|
|
1668
|
-
(tag) => this.hasPrerequisites(tag) && !unlockedTags.has(tag)
|
|
1669
|
-
);
|
|
1670
|
-
if (lockedTags.length === 0) {
|
|
1671
|
-
const tagList = cardTags.length > 0 ? cardTags.join(", ") : "none";
|
|
1672
|
-
return {
|
|
1673
|
-
isUnlocked: true,
|
|
1674
|
-
reason: `Prerequisites met, tags: ${tagList}`
|
|
1675
|
-
};
|
|
1676
|
-
}
|
|
1677
|
-
const missingPrereqs = lockedTags.flatMap((tag) => {
|
|
1678
|
-
const prereqs = this.config.prerequisites[tag] || [];
|
|
1679
|
-
return prereqs.filter((p) => !masteredTags.has(p.tag)).map((p) => p.tag);
|
|
1680
|
-
});
|
|
1681
|
-
return {
|
|
1682
|
-
isUnlocked: false,
|
|
1683
|
-
reason: `Blocked: missing prerequisites ${missingPrereqs.join(", ")} for tags ${lockedTags.join(", ")}`
|
|
1684
|
-
};
|
|
1685
|
-
} catch {
|
|
1686
|
-
return {
|
|
1687
|
-
isUnlocked: true,
|
|
1688
|
-
reason: "Prerequisites check skipped (tag lookup failed)"
|
|
1689
|
-
};
|
|
1690
|
-
}
|
|
1691
|
-
}
|
|
1692
|
-
/**
|
|
1693
|
-
* CardFilter.transform implementation.
|
|
1694
|
-
*
|
|
1695
|
-
* Apply prerequisite gating to cards. Cards with locked tags receive score: 0.
|
|
1696
|
-
*/
|
|
1697
|
-
async transform(cards, context) {
|
|
1698
|
-
const masteredTags = await this.getMasteredTags(context);
|
|
1699
|
-
const unlockedTags = this.getUnlockedTags(masteredTags);
|
|
1700
|
-
const gated = [];
|
|
1701
|
-
for (const card of cards) {
|
|
1702
|
-
const { isUnlocked, reason } = await this.checkCardUnlock(
|
|
1703
|
-
card,
|
|
1704
|
-
context.course,
|
|
1705
|
-
unlockedTags,
|
|
1706
|
-
masteredTags
|
|
1707
|
-
);
|
|
1708
|
-
const finalScore = isUnlocked ? card.score : 0;
|
|
1709
|
-
const action = isUnlocked ? "passed" : "penalized";
|
|
1710
|
-
gated.push({
|
|
1711
|
-
...card,
|
|
1712
|
-
score: finalScore,
|
|
1713
|
-
provenance: [
|
|
1714
|
-
...card.provenance,
|
|
1715
|
-
{
|
|
1716
|
-
strategy: "hierarchyDefinition",
|
|
1717
|
-
strategyName: this.strategyName || this.name,
|
|
1718
|
-
strategyId: this.strategyId || "NAVIGATION_STRATEGY-hierarchy",
|
|
1719
|
-
action,
|
|
1720
|
-
score: finalScore,
|
|
1721
|
-
reason
|
|
1722
|
-
}
|
|
1723
|
-
]
|
|
1724
|
-
});
|
|
1725
|
-
}
|
|
1726
|
-
return gated;
|
|
1727
|
-
}
|
|
1728
|
-
/**
|
|
1729
|
-
* Legacy getWeightedCards - now throws as filters should not be used as generators.
|
|
1730
|
-
*
|
|
1731
|
-
* Use transform() via Pipeline instead.
|
|
1732
|
-
*/
|
|
1733
|
-
async getWeightedCards(_limit) {
|
|
1734
|
-
throw new Error(
|
|
1735
|
-
"HierarchyDefinitionNavigator is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
|
|
1736
|
-
);
|
|
1737
|
-
}
|
|
1738
|
-
// Legacy methods - stub implementations since filters don't generate cards
|
|
1739
|
-
async getNewCards(_n) {
|
|
1740
|
-
return [];
|
|
1741
|
-
}
|
|
1742
|
-
async getPendingReviews() {
|
|
1743
|
-
return [];
|
|
1744
|
-
}
|
|
1745
|
-
};
|
|
1746
|
-
}
|
|
1747
|
-
});
|
|
1748
|
-
|
|
1749
|
-
// src/core/navigators/inferredPreference.ts
|
|
1750
|
-
var inferredPreference_exports = {};
|
|
1751
|
-
__export(inferredPreference_exports, {
|
|
1752
|
-
INFERRED_PREFERENCE_NAVIGATOR_STUB: () => INFERRED_PREFERENCE_NAVIGATOR_STUB
|
|
1753
|
-
});
|
|
1754
|
-
var INFERRED_PREFERENCE_NAVIGATOR_STUB;
|
|
1755
|
-
var init_inferredPreference = __esm({
|
|
1756
|
-
"src/core/navigators/inferredPreference.ts"() {
|
|
1757
|
-
"use strict";
|
|
1758
|
-
INFERRED_PREFERENCE_NAVIGATOR_STUB = true;
|
|
1759
|
-
}
|
|
1760
|
-
});
|
|
1761
|
-
|
|
1762
|
-
// src/core/navigators/interferenceMitigator.ts
|
|
1763
|
-
var interferenceMitigator_exports = {};
|
|
1764
|
-
__export(interferenceMitigator_exports, {
|
|
1765
|
-
default: () => InterferenceMitigatorNavigator
|
|
1766
|
-
});
|
|
1767
|
-
var import_common8, DEFAULT_MIN_COUNT2, DEFAULT_MIN_ELAPSED_DAYS, DEFAULT_INTERFERENCE_DECAY, InterferenceMitigatorNavigator;
|
|
1768
|
-
var init_interferenceMitigator = __esm({
|
|
1769
|
-
"src/core/navigators/interferenceMitigator.ts"() {
|
|
1770
|
-
"use strict";
|
|
1771
|
-
init_navigators();
|
|
1772
|
-
import_common8 = require("@vue-skuilder/common");
|
|
1773
|
-
DEFAULT_MIN_COUNT2 = 10;
|
|
1774
|
-
DEFAULT_MIN_ELAPSED_DAYS = 3;
|
|
1775
|
-
DEFAULT_INTERFERENCE_DECAY = 0.8;
|
|
1776
|
-
InterferenceMitigatorNavigator = class extends ContentNavigator {
|
|
1777
|
-
config;
|
|
1778
|
-
_strategyData;
|
|
1779
|
-
/** Human-readable name for CardFilter interface */
|
|
1780
|
-
name;
|
|
1781
|
-
/** Precomputed map: tag -> set of { partner, decay } it interferes with */
|
|
1782
|
-
interferenceMap;
|
|
1783
|
-
constructor(user, course, _strategyData) {
|
|
1784
|
-
super(user, course, _strategyData);
|
|
1785
|
-
this._strategyData = _strategyData;
|
|
1786
|
-
this.config = this.parseConfig(_strategyData.serializedData);
|
|
1787
|
-
this.interferenceMap = this.buildInterferenceMap();
|
|
1788
|
-
this.name = _strategyData.name || "Interference Mitigator";
|
|
1789
|
-
}
|
|
1790
|
-
parseConfig(serializedData) {
|
|
1791
|
-
try {
|
|
1792
|
-
const parsed = JSON.parse(serializedData);
|
|
1793
|
-
let sets = parsed.interferenceSets || [];
|
|
1794
|
-
if (sets.length > 0 && Array.isArray(sets[0])) {
|
|
1795
|
-
sets = sets.map((tags) => ({ tags }));
|
|
1796
|
-
}
|
|
1797
|
-
return {
|
|
1798
|
-
interferenceSets: sets,
|
|
1799
|
-
maturityThreshold: {
|
|
1800
|
-
minCount: parsed.maturityThreshold?.minCount ?? DEFAULT_MIN_COUNT2,
|
|
1801
|
-
minElo: parsed.maturityThreshold?.minElo,
|
|
1802
|
-
minElapsedDays: parsed.maturityThreshold?.minElapsedDays ?? DEFAULT_MIN_ELAPSED_DAYS
|
|
1803
|
-
},
|
|
1804
|
-
defaultDecay: parsed.defaultDecay ?? DEFAULT_INTERFERENCE_DECAY
|
|
1805
|
-
};
|
|
1806
|
-
} catch {
|
|
1807
|
-
return {
|
|
1808
|
-
interferenceSets: [],
|
|
1809
|
-
maturityThreshold: {
|
|
1810
|
-
minCount: DEFAULT_MIN_COUNT2,
|
|
1811
|
-
minElapsedDays: DEFAULT_MIN_ELAPSED_DAYS
|
|
1812
|
-
},
|
|
1813
|
-
defaultDecay: DEFAULT_INTERFERENCE_DECAY
|
|
1814
|
-
};
|
|
1815
|
-
}
|
|
1816
|
-
}
|
|
1817
|
-
/**
|
|
1818
|
-
* Build a map from each tag to its interference partners with decay coefficients.
|
|
1819
|
-
* If tags A, B, C are in an interference group with decay 0.8, then:
|
|
1820
|
-
* - A interferes with B (decay 0.8) and C (decay 0.8)
|
|
1821
|
-
* - B interferes with A (decay 0.8) and C (decay 0.8)
|
|
1822
|
-
* - etc.
|
|
1823
|
-
*/
|
|
1824
|
-
buildInterferenceMap() {
|
|
1825
|
-
const map = /* @__PURE__ */ new Map();
|
|
1826
|
-
for (const group of this.config.interferenceSets) {
|
|
1827
|
-
const decay = group.decay ?? this.config.defaultDecay ?? DEFAULT_INTERFERENCE_DECAY;
|
|
1828
|
-
for (const tag of group.tags) {
|
|
1829
|
-
if (!map.has(tag)) {
|
|
1830
|
-
map.set(tag, []);
|
|
1831
|
-
}
|
|
1832
|
-
const partners = map.get(tag);
|
|
1833
|
-
for (const other of group.tags) {
|
|
1834
|
-
if (other !== tag) {
|
|
1835
|
-
const existing = partners.find((p) => p.partner === other);
|
|
1836
|
-
if (existing) {
|
|
1837
|
-
existing.decay = Math.max(existing.decay, decay);
|
|
1838
|
-
} else {
|
|
1839
|
-
partners.push({ partner: other, decay });
|
|
1840
|
-
}
|
|
1841
|
-
}
|
|
1842
|
-
}
|
|
1843
|
-
}
|
|
1844
|
-
}
|
|
1845
|
-
return map;
|
|
1846
|
-
}
|
|
1847
|
-
/**
|
|
1848
|
-
* Get the set of tags that are currently immature for this user.
|
|
1849
|
-
* A tag is immature if the user has interacted with it but hasn't
|
|
1850
|
-
* reached the maturity threshold.
|
|
1851
|
-
*/
|
|
1852
|
-
async getImmatureTags(context) {
|
|
1853
|
-
const immature = /* @__PURE__ */ new Set();
|
|
1854
|
-
try {
|
|
1855
|
-
const courseReg = await context.user.getCourseRegDoc(context.course.getCourseID());
|
|
1856
|
-
const userElo = (0, import_common8.toCourseElo)(courseReg.elo);
|
|
1857
|
-
const minCount = this.config.maturityThreshold?.minCount ?? DEFAULT_MIN_COUNT2;
|
|
1858
|
-
const minElo = this.config.maturityThreshold?.minElo;
|
|
1859
|
-
const minElapsedDays = this.config.maturityThreshold?.minElapsedDays ?? DEFAULT_MIN_ELAPSED_DAYS;
|
|
1860
|
-
const minCountForElapsed = minElapsedDays * 2;
|
|
1861
|
-
for (const [tagId, tagElo] of Object.entries(userElo.tags)) {
|
|
1862
|
-
if (tagElo.count === 0) continue;
|
|
1863
|
-
const belowCount = tagElo.count < minCount;
|
|
1864
|
-
const belowElo = minElo !== void 0 && tagElo.score < minElo;
|
|
1865
|
-
const belowElapsed = tagElo.count < minCountForElapsed;
|
|
1866
|
-
if (belowCount || belowElo || belowElapsed) {
|
|
1867
|
-
immature.add(tagId);
|
|
1868
|
-
}
|
|
1869
|
-
}
|
|
1870
|
-
} catch {
|
|
1871
|
-
}
|
|
1872
|
-
return immature;
|
|
1873
|
-
}
|
|
1874
|
-
/**
|
|
1875
|
-
* Get all tags that interfere with any immature tag, along with their decay coefficients.
|
|
1876
|
-
* These are the tags we want to avoid introducing.
|
|
1877
|
-
*/
|
|
1878
|
-
getTagsToAvoid(immatureTags) {
|
|
1879
|
-
const avoid = /* @__PURE__ */ new Map();
|
|
1880
|
-
for (const immatureTag of immatureTags) {
|
|
1881
|
-
const partners = this.interferenceMap.get(immatureTag);
|
|
1882
|
-
if (partners) {
|
|
1883
|
-
for (const { partner, decay } of partners) {
|
|
1884
|
-
if (!immatureTags.has(partner)) {
|
|
1885
|
-
const existing = avoid.get(partner) ?? 0;
|
|
1886
|
-
avoid.set(partner, Math.max(existing, decay));
|
|
1887
|
-
}
|
|
1888
|
-
}
|
|
1889
|
-
}
|
|
1890
|
-
}
|
|
1891
|
-
return avoid;
|
|
1892
|
-
}
|
|
1893
|
-
/**
|
|
1894
|
-
* Compute interference score reduction for a card.
|
|
1895
|
-
* Returns: { multiplier, interfering tags, reason }
|
|
1896
|
-
*/
|
|
1897
|
-
computeInterferenceEffect(cardTags, tagsToAvoid, immatureTags) {
|
|
1898
|
-
if (tagsToAvoid.size === 0) {
|
|
1899
|
-
return {
|
|
1900
|
-
multiplier: 1,
|
|
1901
|
-
interferingTags: [],
|
|
1902
|
-
reason: "No interference detected"
|
|
1903
|
-
};
|
|
1904
|
-
}
|
|
1905
|
-
let multiplier = 1;
|
|
1906
|
-
const interferingTags = [];
|
|
1907
|
-
for (const tag of cardTags) {
|
|
1908
|
-
const decay = tagsToAvoid.get(tag);
|
|
1909
|
-
if (decay !== void 0) {
|
|
1910
|
-
interferingTags.push(tag);
|
|
1911
|
-
multiplier *= 1 - decay;
|
|
1912
|
-
}
|
|
1913
|
-
}
|
|
1914
|
-
if (interferingTags.length === 0) {
|
|
1915
|
-
return {
|
|
1916
|
-
multiplier: 1,
|
|
1917
|
-
interferingTags: [],
|
|
1918
|
-
reason: "No interference detected"
|
|
1919
|
-
};
|
|
1920
|
-
}
|
|
1921
|
-
const causingTags = /* @__PURE__ */ new Set();
|
|
1922
|
-
for (const tag of interferingTags) {
|
|
1923
|
-
for (const immatureTag of immatureTags) {
|
|
1924
|
-
const partners = this.interferenceMap.get(immatureTag);
|
|
1925
|
-
if (partners?.some((p) => p.partner === tag)) {
|
|
1926
|
-
causingTags.add(immatureTag);
|
|
1927
|
-
}
|
|
1928
|
-
}
|
|
1929
|
-
}
|
|
1930
|
-
const reason = `Interferes with immature tags ${Array.from(causingTags).join(", ")} (tags: ${interferingTags.join(", ")}, multiplier: ${multiplier.toFixed(2)})`;
|
|
1931
|
-
return { multiplier, interferingTags, reason };
|
|
1932
|
-
}
|
|
1933
|
-
/**
|
|
1934
|
-
* CardFilter.transform implementation.
|
|
1935
|
-
*
|
|
1936
|
-
* Apply interference-aware scoring. Cards with tags that interfere with
|
|
1937
|
-
* immature learnings get reduced scores.
|
|
1938
|
-
*/
|
|
1939
|
-
async transform(cards, context) {
|
|
1940
|
-
const immatureTags = await this.getImmatureTags(context);
|
|
1941
|
-
const tagsToAvoid = this.getTagsToAvoid(immatureTags);
|
|
1942
|
-
const adjusted = [];
|
|
1943
|
-
for (const card of cards) {
|
|
1944
|
-
const cardTags = card.tags ?? [];
|
|
1945
|
-
const { multiplier, reason } = this.computeInterferenceEffect(
|
|
1946
|
-
cardTags,
|
|
1947
|
-
tagsToAvoid,
|
|
1948
|
-
immatureTags
|
|
1949
|
-
);
|
|
1950
|
-
const finalScore = card.score * multiplier;
|
|
1951
|
-
const action = multiplier < 1 ? "penalized" : multiplier > 1 ? "boosted" : "passed";
|
|
1952
|
-
adjusted.push({
|
|
1953
|
-
...card,
|
|
1954
|
-
score: finalScore,
|
|
1955
|
-
provenance: [
|
|
1956
|
-
...card.provenance,
|
|
1957
|
-
{
|
|
1958
|
-
strategy: "interferenceMitigator",
|
|
1959
|
-
strategyName: this.strategyName || this.name,
|
|
1960
|
-
strategyId: this.strategyId || "NAVIGATION_STRATEGY-interference",
|
|
1961
|
-
action,
|
|
1962
|
-
score: finalScore,
|
|
1963
|
-
reason
|
|
1964
|
-
}
|
|
1965
|
-
]
|
|
1966
|
-
});
|
|
1967
|
-
}
|
|
1968
|
-
return adjusted;
|
|
1969
|
-
}
|
|
1970
|
-
/**
|
|
1971
|
-
* Legacy getWeightedCards - now throws as filters should not be used as generators.
|
|
1972
|
-
*
|
|
1973
|
-
* Use transform() via Pipeline instead.
|
|
1974
|
-
*/
|
|
1975
|
-
async getWeightedCards(_limit) {
|
|
1976
|
-
throw new Error(
|
|
1977
|
-
"InterferenceMitigatorNavigator is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
|
|
1978
|
-
);
|
|
1979
|
-
}
|
|
1980
|
-
// Legacy methods - stub implementations since filters don't generate cards
|
|
1981
|
-
async getNewCards(_n) {
|
|
1982
|
-
return [];
|
|
1983
|
-
}
|
|
1984
|
-
async getPendingReviews() {
|
|
1985
|
-
return [];
|
|
1986
|
-
}
|
|
1987
|
-
};
|
|
1988
|
-
}
|
|
1989
|
-
});
|
|
1990
|
-
|
|
1991
|
-
// src/core/navigators/relativePriority.ts
|
|
1992
|
-
var relativePriority_exports = {};
|
|
1993
|
-
__export(relativePriority_exports, {
|
|
1994
|
-
default: () => RelativePriorityNavigator
|
|
1995
|
-
});
|
|
1996
|
-
var DEFAULT_PRIORITY, DEFAULT_PRIORITY_INFLUENCE, DEFAULT_COMBINE_MODE, RelativePriorityNavigator;
|
|
1997
|
-
var init_relativePriority = __esm({
|
|
1998
|
-
"src/core/navigators/relativePriority.ts"() {
|
|
1999
|
-
"use strict";
|
|
2000
|
-
init_navigators();
|
|
2001
|
-
DEFAULT_PRIORITY = 0.5;
|
|
2002
|
-
DEFAULT_PRIORITY_INFLUENCE = 0.5;
|
|
2003
|
-
DEFAULT_COMBINE_MODE = "max";
|
|
2004
|
-
RelativePriorityNavigator = class extends ContentNavigator {
|
|
2005
|
-
config;
|
|
2006
|
-
_strategyData;
|
|
2007
|
-
/** Human-readable name for CardFilter interface */
|
|
2008
|
-
name;
|
|
2009
|
-
constructor(user, course, _strategyData) {
|
|
2010
|
-
super(user, course, _strategyData);
|
|
2011
|
-
this._strategyData = _strategyData;
|
|
2012
|
-
this.config = this.parseConfig(_strategyData.serializedData);
|
|
2013
|
-
this.name = _strategyData.name || "Relative Priority";
|
|
2014
|
-
}
|
|
2015
|
-
parseConfig(serializedData) {
|
|
2016
|
-
try {
|
|
2017
|
-
const parsed = JSON.parse(serializedData);
|
|
2018
|
-
return {
|
|
2019
|
-
tagPriorities: parsed.tagPriorities || {},
|
|
2020
|
-
defaultPriority: parsed.defaultPriority ?? DEFAULT_PRIORITY,
|
|
2021
|
-
combineMode: parsed.combineMode ?? DEFAULT_COMBINE_MODE,
|
|
2022
|
-
priorityInfluence: parsed.priorityInfluence ?? DEFAULT_PRIORITY_INFLUENCE
|
|
2023
|
-
};
|
|
2024
|
-
} catch {
|
|
2025
|
-
return {
|
|
2026
|
-
tagPriorities: {},
|
|
2027
|
-
defaultPriority: DEFAULT_PRIORITY,
|
|
2028
|
-
combineMode: DEFAULT_COMBINE_MODE,
|
|
2029
|
-
priorityInfluence: DEFAULT_PRIORITY_INFLUENCE
|
|
2030
|
-
};
|
|
2031
|
-
}
|
|
2032
|
-
}
|
|
2033
|
-
/**
|
|
2034
|
-
* Look up the priority for a tag.
|
|
2035
|
-
*/
|
|
2036
|
-
getTagPriority(tagId) {
|
|
2037
|
-
return this.config.tagPriorities[tagId] ?? this.config.defaultPriority ?? DEFAULT_PRIORITY;
|
|
2038
|
-
}
|
|
2039
|
-
/**
|
|
2040
|
-
* Compute combined priority for a card based on its tags.
|
|
2041
|
-
*/
|
|
2042
|
-
computeCardPriority(cardTags) {
|
|
2043
|
-
if (cardTags.length === 0) {
|
|
2044
|
-
return this.config.defaultPriority ?? DEFAULT_PRIORITY;
|
|
2045
|
-
}
|
|
2046
|
-
const priorities = cardTags.map((tag) => this.getTagPriority(tag));
|
|
2047
|
-
switch (this.config.combineMode) {
|
|
2048
|
-
case "max":
|
|
2049
|
-
return Math.max(...priorities);
|
|
2050
|
-
case "min":
|
|
2051
|
-
return Math.min(...priorities);
|
|
2052
|
-
case "average":
|
|
2053
|
-
return priorities.reduce((sum, p) => sum + p, 0) / priorities.length;
|
|
2054
|
-
default:
|
|
2055
|
-
return Math.max(...priorities);
|
|
2056
|
-
}
|
|
2057
|
-
}
|
|
2058
|
-
/**
|
|
2059
|
-
* Compute boost factor based on priority.
|
|
2060
|
-
*
|
|
2061
|
-
* The formula: 1 + (priority - 0.5) * priorityInfluence
|
|
2062
|
-
*
|
|
2063
|
-
* This creates a multiplier centered around 1.0:
|
|
2064
|
-
* - Priority 1.0 with influence 0.5 → 1.25 (25% boost)
|
|
2065
|
-
* - Priority 0.5 with any influence → 1.00 (neutral)
|
|
2066
|
-
* - Priority 0.0 with influence 0.5 → 0.75 (25% reduction)
|
|
2067
|
-
*/
|
|
2068
|
-
computeBoostFactor(priority) {
|
|
2069
|
-
const influence = this.config.priorityInfluence ?? DEFAULT_PRIORITY_INFLUENCE;
|
|
2070
|
-
return 1 + (priority - 0.5) * influence;
|
|
2071
|
-
}
|
|
2072
|
-
/**
|
|
2073
|
-
* Build human-readable reason for priority adjustment.
|
|
2074
|
-
*/
|
|
2075
|
-
buildPriorityReason(cardTags, priority, boostFactor, finalScore) {
|
|
2076
|
-
if (cardTags.length === 0) {
|
|
2077
|
-
return `No tags, neutral priority (${priority.toFixed(2)})`;
|
|
2078
|
-
}
|
|
2079
|
-
const tagList = cardTags.slice(0, 3).join(", ");
|
|
2080
|
-
const more = cardTags.length > 3 ? ` (+${cardTags.length - 3} more)` : "";
|
|
2081
|
-
if (boostFactor === 1) {
|
|
2082
|
-
return `Neutral priority (${priority.toFixed(2)}) for tags: ${tagList}${more}`;
|
|
2083
|
-
} else if (boostFactor > 1) {
|
|
2084
|
-
return `High-priority tags: ${tagList}${more} (priority ${priority.toFixed(2)} \u2192 boost ${boostFactor.toFixed(2)}x \u2192 ${finalScore.toFixed(2)})`;
|
|
2085
|
-
} else {
|
|
2086
|
-
return `Low-priority tags: ${tagList}${more} (priority ${priority.toFixed(2)} \u2192 reduce ${boostFactor.toFixed(2)}x \u2192 ${finalScore.toFixed(2)})`;
|
|
2087
|
-
}
|
|
2088
|
-
}
|
|
2089
|
-
/**
|
|
2090
|
-
* CardFilter.transform implementation.
|
|
2091
|
-
*
|
|
2092
|
-
* Apply priority-adjusted scoring. Cards with high-priority tags get boosted,
|
|
2093
|
-
* cards with low-priority tags get reduced scores.
|
|
2094
|
-
*/
|
|
2095
|
-
async transform(cards, _context) {
|
|
2096
|
-
const adjusted = await Promise.all(
|
|
2097
|
-
cards.map(async (card) => {
|
|
2098
|
-
const cardTags = card.tags ?? [];
|
|
2099
|
-
const priority = this.computeCardPriority(cardTags);
|
|
2100
|
-
const boostFactor = this.computeBoostFactor(priority);
|
|
2101
|
-
const finalScore = Math.max(0, Math.min(1, card.score * boostFactor));
|
|
2102
|
-
const action = boostFactor > 1 ? "boosted" : boostFactor < 1 ? "penalized" : "passed";
|
|
2103
|
-
const reason = this.buildPriorityReason(cardTags, priority, boostFactor, finalScore);
|
|
2104
|
-
return {
|
|
2105
|
-
...card,
|
|
2106
|
-
score: finalScore,
|
|
2107
|
-
provenance: [
|
|
2108
|
-
...card.provenance,
|
|
2109
|
-
{
|
|
2110
|
-
strategy: "relativePriority",
|
|
2111
|
-
strategyName: this.strategyName || this.name,
|
|
2112
|
-
strategyId: this.strategyId || "NAVIGATION_STRATEGY-priority",
|
|
2113
|
-
action,
|
|
2114
|
-
score: finalScore,
|
|
2115
|
-
reason
|
|
2116
|
-
}
|
|
2117
|
-
]
|
|
2118
|
-
};
|
|
2119
|
-
})
|
|
2120
|
-
);
|
|
2121
|
-
return adjusted;
|
|
2122
|
-
}
|
|
2123
|
-
/**
|
|
2124
|
-
* Legacy getWeightedCards - now throws as filters should not be used as generators.
|
|
2125
|
-
*
|
|
2126
|
-
* Use transform() via Pipeline instead.
|
|
2127
|
-
*/
|
|
2128
|
-
async getWeightedCards(_limit) {
|
|
2129
|
-
throw new Error(
|
|
2130
|
-
"RelativePriorityNavigator is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
|
|
2131
|
-
);
|
|
2132
|
-
}
|
|
2133
|
-
// Legacy methods - stub implementations since filters don't generate cards
|
|
2134
|
-
async getNewCards(_n) {
|
|
2135
|
-
return [];
|
|
2136
|
-
}
|
|
2137
|
-
async getPendingReviews() {
|
|
2138
|
-
return [];
|
|
2139
|
-
}
|
|
2140
|
-
};
|
|
2141
|
-
}
|
|
2142
|
-
});
|
|
2143
|
-
|
|
2144
|
-
// src/core/navigators/srs.ts
|
|
2145
|
-
var srs_exports = {};
|
|
2146
|
-
__export(srs_exports, {
|
|
2147
|
-
default: () => SRSNavigator
|
|
2148
|
-
});
|
|
2149
|
-
var import_moment, SRSNavigator;
|
|
2150
|
-
var init_srs = __esm({
|
|
2151
|
-
"src/core/navigators/srs.ts"() {
|
|
2152
|
-
"use strict";
|
|
2153
|
-
import_moment = __toESM(require("moment"), 1);
|
|
2154
|
-
init_navigators();
|
|
2155
|
-
SRSNavigator = class extends ContentNavigator {
|
|
2156
|
-
/** Human-readable name for CardGenerator interface */
|
|
2157
|
-
name;
|
|
2158
|
-
constructor(user, course, strategyData) {
|
|
2159
|
-
super(user, course, strategyData);
|
|
2160
|
-
this.name = strategyData?.name || "SRS";
|
|
2161
|
-
}
|
|
2162
|
-
/**
|
|
2163
|
-
* Get review cards scored by urgency.
|
|
2164
|
-
*
|
|
2165
|
-
* Score formula combines:
|
|
2166
|
-
* - Relative overdueness: hoursOverdue / intervalHours
|
|
2167
|
-
* - Interval recency: exponential decay favoring shorter intervals
|
|
2168
|
-
*
|
|
2169
|
-
* Cards not yet due are excluded (not scored as 0).
|
|
2170
|
-
*
|
|
2171
|
-
* This method supports both the legacy signature (limit only) and the
|
|
2172
|
-
* CardGenerator interface signature (limit, context).
|
|
2173
|
-
*
|
|
2174
|
-
* @param limit - Maximum number of cards to return
|
|
2175
|
-
* @param _context - Optional GeneratorContext (currently unused, but required for interface)
|
|
1296
|
+
* This method supports both the legacy signature (limit only) and the
|
|
1297
|
+
* CardGenerator interface signature (limit, context).
|
|
1298
|
+
*
|
|
1299
|
+
* @param limit - Maximum number of cards to return
|
|
1300
|
+
* @param _context - Optional GeneratorContext (currently unused, but required for interface)
|
|
2176
1301
|
*/
|
|
2177
1302
|
async getWeightedCards(limit, _context) {
|
|
2178
1303
|
if (!this.user || !this.course) {
|
|
@@ -2187,6 +1312,7 @@ var init_srs = __esm({
|
|
|
2187
1312
|
cardId: review.cardId,
|
|
2188
1313
|
courseId: review.courseId,
|
|
2189
1314
|
score,
|
|
1315
|
+
reviewID: review._id,
|
|
2190
1316
|
provenance: [
|
|
2191
1317
|
{
|
|
2192
1318
|
strategy: "srs",
|
|
@@ -2199,6 +1325,7 @@ var init_srs = __esm({
|
|
|
2199
1325
|
]
|
|
2200
1326
|
};
|
|
2201
1327
|
});
|
|
1328
|
+
logger.debug(`[srsNav] got ${scored.length} weighted cards`);
|
|
2202
1329
|
return scored.sort((a, b) => b.score - a.score).slice(0, limit);
|
|
2203
1330
|
}
|
|
2204
1331
|
/**
|
|
@@ -2216,316 +1343,119 @@ var init_srs = __esm({
|
|
|
2216
1343
|
*
|
|
2217
1344
|
* Combined: base 0.5 + weighted average of factors * 0.45
|
|
2218
1345
|
* Result range: approximately 0.5 to 0.95
|
|
2219
|
-
*/
|
|
2220
|
-
computeUrgencyScore(review, now) {
|
|
2221
|
-
const scheduledAt = import_moment.default.utc(review.scheduledAt);
|
|
2222
|
-
const due = import_moment.default.utc(review.reviewTime);
|
|
2223
|
-
const intervalHours = Math.max(1, due.diff(scheduledAt, "hours"));
|
|
2224
|
-
const hoursOverdue = now.diff(due, "hours");
|
|
2225
|
-
const relativeOverdue = hoursOverdue / intervalHours;
|
|
2226
|
-
const recencyFactor = 0.3 + 0.7 * Math.exp(-intervalHours / 720);
|
|
2227
|
-
const overdueContribution = Math.min(1, Math.max(0, relativeOverdue));
|
|
2228
|
-
const urgency = overdueContribution * 0.5 + recencyFactor * 0.5;
|
|
2229
|
-
const score = Math.min(0.95, 0.5 + urgency * 0.45);
|
|
2230
|
-
const reason = `${Math.round(hoursOverdue)}h overdue (interval: ${Math.round(intervalHours)}h, relative: ${relativeOverdue.toFixed(2)}), recency: ${recencyFactor.toFixed(2)}, review`;
|
|
2231
|
-
return { score, reason };
|
|
2232
|
-
}
|
|
2233
|
-
/**
|
|
2234
|
-
* Get pending reviews in legacy format.
|
|
2235
|
-
*
|
|
2236
|
-
* Returns all pending reviews for the course, enriched with session item fields.
|
|
2237
|
-
*/
|
|
2238
|
-
async getPendingReviews() {
|
|
2239
|
-
if (!this.user || !this.course) {
|
|
2240
|
-
throw new Error("SRSNavigator requires user and course to be set");
|
|
2241
|
-
}
|
|
2242
|
-
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
2243
|
-
return reviews.map((r) => ({
|
|
2244
|
-
...r,
|
|
2245
|
-
contentSourceType: "course",
|
|
2246
|
-
contentSourceID: this.course.getCourseID(),
|
|
2247
|
-
cardID: r.cardId,
|
|
2248
|
-
courseID: r.courseId,
|
|
2249
|
-
qualifiedID: `${r.courseId}-${r.cardId}`,
|
|
2250
|
-
reviewID: r._id,
|
|
2251
|
-
status: "review"
|
|
2252
|
-
}));
|
|
2253
|
-
}
|
|
2254
|
-
/**
|
|
2255
|
-
* SRS does not generate new cards.
|
|
2256
|
-
* Use ELONavigator or another generator for new cards.
|
|
2257
|
-
*/
|
|
2258
|
-
async getNewCards(_n) {
|
|
2259
|
-
return [];
|
|
2260
|
-
}
|
|
2261
|
-
};
|
|
2262
|
-
}
|
|
2263
|
-
});
|
|
2264
|
-
|
|
2265
|
-
// src/core/navigators/userGoal.ts
|
|
2266
|
-
var userGoal_exports = {};
|
|
2267
|
-
__export(userGoal_exports, {
|
|
2268
|
-
USER_GOAL_NAVIGATOR_STUB: () => USER_GOAL_NAVIGATOR_STUB
|
|
2269
|
-
});
|
|
2270
|
-
var USER_GOAL_NAVIGATOR_STUB;
|
|
2271
|
-
var init_userGoal = __esm({
|
|
2272
|
-
"src/core/navigators/userGoal.ts"() {
|
|
2273
|
-
"use strict";
|
|
2274
|
-
USER_GOAL_NAVIGATOR_STUB = true;
|
|
2275
|
-
}
|
|
2276
|
-
});
|
|
2277
|
-
|
|
2278
|
-
// import("./**/*") in src/core/navigators/index.ts
|
|
2279
|
-
var globImport;
|
|
2280
|
-
var init_ = __esm({
|
|
2281
|
-
'import("./**/*") in src/core/navigators/index.ts'() {
|
|
2282
|
-
globImport = __glob({
|
|
2283
|
-
"./CompositeGenerator.ts": () => Promise.resolve().then(() => (init_CompositeGenerator(), CompositeGenerator_exports)),
|
|
2284
|
-
"./Pipeline.ts": () => Promise.resolve().then(() => (init_Pipeline(), Pipeline_exports)),
|
|
2285
|
-
"./PipelineAssembler.ts": () => Promise.resolve().then(() => (init_PipelineAssembler(), PipelineAssembler_exports)),
|
|
2286
|
-
"./elo.ts": () => Promise.resolve().then(() => (init_elo(), elo_exports)),
|
|
2287
|
-
"./filters/eloDistance.ts": () => Promise.resolve().then(() => (init_eloDistance(), eloDistance_exports)),
|
|
2288
|
-
"./filters/index.ts": () => Promise.resolve().then(() => (init_filters(), filters_exports)),
|
|
2289
|
-
"./filters/types.ts": () => Promise.resolve().then(() => (init_types(), types_exports)),
|
|
2290
|
-
"./filters/userTagPreference.ts": () => Promise.resolve().then(() => (init_userTagPreference(), userTagPreference_exports)),
|
|
2291
|
-
"./generators/index.ts": () => Promise.resolve().then(() => (init_generators(), generators_exports)),
|
|
2292
|
-
"./generators/types.ts": () => Promise.resolve().then(() => (init_types2(), types_exports2)),
|
|
2293
|
-
"./hardcodedOrder.ts": () => Promise.resolve().then(() => (init_hardcodedOrder(), hardcodedOrder_exports)),
|
|
2294
|
-
"./hierarchyDefinition.ts": () => Promise.resolve().then(() => (init_hierarchyDefinition(), hierarchyDefinition_exports)),
|
|
2295
|
-
"./index.ts": () => Promise.resolve().then(() => (init_navigators(), navigators_exports)),
|
|
2296
|
-
"./inferredPreference.ts": () => Promise.resolve().then(() => (init_inferredPreference(), inferredPreference_exports)),
|
|
2297
|
-
"./interferenceMitigator.ts": () => Promise.resolve().then(() => (init_interferenceMitigator(), interferenceMitigator_exports)),
|
|
2298
|
-
"./relativePriority.ts": () => Promise.resolve().then(() => (init_relativePriority(), relativePriority_exports)),
|
|
2299
|
-
"./srs.ts": () => Promise.resolve().then(() => (init_srs(), srs_exports)),
|
|
2300
|
-
"./userGoal.ts": () => Promise.resolve().then(() => (init_userGoal(), userGoal_exports))
|
|
2301
|
-
});
|
|
2302
|
-
}
|
|
2303
|
-
});
|
|
2304
|
-
|
|
2305
|
-
// src/core/navigators/index.ts
|
|
2306
|
-
var navigators_exports = {};
|
|
2307
|
-
__export(navigators_exports, {
|
|
2308
|
-
ContentNavigator: () => ContentNavigator,
|
|
2309
|
-
NavigatorRole: () => NavigatorRole,
|
|
2310
|
-
NavigatorRoles: () => NavigatorRoles,
|
|
2311
|
-
Navigators: () => Navigators,
|
|
2312
|
-
getCardOrigin: () => getCardOrigin,
|
|
2313
|
-
isFilter: () => isFilter,
|
|
2314
|
-
isGenerator: () => isGenerator
|
|
2315
|
-
});
|
|
2316
|
-
function getCardOrigin(card) {
|
|
2317
|
-
if (card.provenance.length === 0) {
|
|
2318
|
-
throw new Error("Card has no provenance - cannot determine origin");
|
|
2319
|
-
}
|
|
2320
|
-
const firstEntry = card.provenance[0];
|
|
2321
|
-
const reason = firstEntry.reason.toLowerCase();
|
|
2322
|
-
if (reason.includes("failed")) {
|
|
2323
|
-
return "failed";
|
|
2324
|
-
}
|
|
2325
|
-
if (reason.includes("review")) {
|
|
2326
|
-
return "review";
|
|
2327
|
-
}
|
|
2328
|
-
return "new";
|
|
2329
|
-
}
|
|
2330
|
-
function isGenerator(impl) {
|
|
2331
|
-
return NavigatorRoles[impl] === "generator" /* GENERATOR */;
|
|
2332
|
-
}
|
|
2333
|
-
function isFilter(impl) {
|
|
2334
|
-
return NavigatorRoles[impl] === "filter" /* FILTER */;
|
|
2335
|
-
}
|
|
2336
|
-
var Navigators, NavigatorRole, NavigatorRoles, ContentNavigator;
|
|
2337
|
-
var init_navigators = __esm({
|
|
2338
|
-
"src/core/navigators/index.ts"() {
|
|
2339
|
-
"use strict";
|
|
2340
|
-
init_logger();
|
|
2341
|
-
init_();
|
|
2342
|
-
Navigators = /* @__PURE__ */ ((Navigators2) => {
|
|
2343
|
-
Navigators2["ELO"] = "elo";
|
|
2344
|
-
Navigators2["SRS"] = "srs";
|
|
2345
|
-
Navigators2["HARDCODED"] = "hardcodedOrder";
|
|
2346
|
-
Navigators2["HIERARCHY"] = "hierarchyDefinition";
|
|
2347
|
-
Navigators2["INTERFERENCE"] = "interferenceMitigator";
|
|
2348
|
-
Navigators2["RELATIVE_PRIORITY"] = "relativePriority";
|
|
2349
|
-
Navigators2["USER_TAG_PREFERENCE"] = "userTagPreference";
|
|
2350
|
-
return Navigators2;
|
|
2351
|
-
})(Navigators || {});
|
|
2352
|
-
NavigatorRole = /* @__PURE__ */ ((NavigatorRole2) => {
|
|
2353
|
-
NavigatorRole2["GENERATOR"] = "generator";
|
|
2354
|
-
NavigatorRole2["FILTER"] = "filter";
|
|
2355
|
-
return NavigatorRole2;
|
|
2356
|
-
})(NavigatorRole || {});
|
|
2357
|
-
NavigatorRoles = {
|
|
2358
|
-
["elo" /* ELO */]: "generator" /* GENERATOR */,
|
|
2359
|
-
["srs" /* SRS */]: "generator" /* GENERATOR */,
|
|
2360
|
-
["hardcodedOrder" /* HARDCODED */]: "generator" /* GENERATOR */,
|
|
2361
|
-
["hierarchyDefinition" /* HIERARCHY */]: "filter" /* FILTER */,
|
|
2362
|
-
["interferenceMitigator" /* INTERFERENCE */]: "filter" /* FILTER */,
|
|
2363
|
-
["relativePriority" /* RELATIVE_PRIORITY */]: "filter" /* FILTER */,
|
|
2364
|
-
["userTagPreference" /* USER_TAG_PREFERENCE */]: "filter" /* FILTER */
|
|
2365
|
-
};
|
|
2366
|
-
ContentNavigator = class {
|
|
2367
|
-
/** User interface for this navigation session */
|
|
2368
|
-
user;
|
|
2369
|
-
/** Course interface for this navigation session */
|
|
2370
|
-
course;
|
|
2371
|
-
/** Human-readable name for this strategy instance (from ContentNavigationStrategyData.name) */
|
|
2372
|
-
strategyName;
|
|
2373
|
-
/** Unique document ID for this strategy instance (from ContentNavigationStrategyData._id) */
|
|
2374
|
-
strategyId;
|
|
2375
|
-
/**
|
|
2376
|
-
* Constructor for standard navigators.
|
|
2377
|
-
* Call this from subclass constructors to initialize common fields.
|
|
2378
|
-
*
|
|
2379
|
-
* Note: CompositeGenerator doesn't use this pattern and should call super() without args.
|
|
2380
|
-
*/
|
|
2381
|
-
constructor(user, course, strategyData) {
|
|
2382
|
-
if (user && course && strategyData) {
|
|
2383
|
-
this.user = user;
|
|
2384
|
-
this.course = course;
|
|
2385
|
-
this.strategyName = strategyData.name;
|
|
2386
|
-
this.strategyId = strategyData._id;
|
|
2387
|
-
}
|
|
2388
|
-
}
|
|
2389
|
-
// ============================================================================
|
|
2390
|
-
// STRATEGY STATE HELPERS
|
|
2391
|
-
// ============================================================================
|
|
2392
|
-
//
|
|
2393
|
-
// These methods allow strategies to persist their own state (user preferences,
|
|
2394
|
-
// learned patterns, temporal tracking) in the user database.
|
|
2395
|
-
//
|
|
2396
|
-
// ============================================================================
|
|
2397
|
-
/**
|
|
2398
|
-
* Unique key identifying this strategy for state storage.
|
|
2399
|
-
*
|
|
2400
|
-
* Defaults to the constructor name (e.g., "UserTagPreferenceFilter").
|
|
2401
|
-
* Override in subclasses if multiple instances of the same strategy type
|
|
2402
|
-
* need separate state storage.
|
|
2403
|
-
*/
|
|
2404
|
-
get strategyKey() {
|
|
2405
|
-
return this.constructor.name;
|
|
2406
|
-
}
|
|
2407
|
-
/**
|
|
2408
|
-
* Get this strategy's persisted state for the current course.
|
|
2409
|
-
*
|
|
2410
|
-
* @returns The strategy's data payload, or null if no state exists
|
|
2411
|
-
* @throws Error if user or course is not initialized
|
|
2412
|
-
*/
|
|
2413
|
-
async getStrategyState() {
|
|
2414
|
-
if (!this.user || !this.course) {
|
|
2415
|
-
throw new Error(
|
|
2416
|
-
`Cannot get strategy state: navigator not properly initialized. Ensure user and course are provided to constructor.`
|
|
2417
|
-
);
|
|
2418
|
-
}
|
|
2419
|
-
return this.user.getStrategyState(this.course.getCourseID(), this.strategyKey);
|
|
2420
|
-
}
|
|
2421
|
-
/**
|
|
2422
|
-
* Persist this strategy's state for the current course.
|
|
2423
|
-
*
|
|
2424
|
-
* @param data - The strategy's data payload to store
|
|
2425
|
-
* @throws Error if user or course is not initialized
|
|
2426
|
-
*/
|
|
2427
|
-
async putStrategyState(data) {
|
|
2428
|
-
if (!this.user || !this.course) {
|
|
2429
|
-
throw new Error(
|
|
2430
|
-
`Cannot put strategy state: navigator not properly initialized. Ensure user and course are provided to constructor.`
|
|
2431
|
-
);
|
|
2432
|
-
}
|
|
2433
|
-
return this.user.putStrategyState(this.course.getCourseID(), this.strategyKey, data);
|
|
2434
|
-
}
|
|
2435
|
-
/**
|
|
2436
|
-
* Factory method to create navigator instances dynamically.
|
|
2437
|
-
*
|
|
2438
|
-
* @param user - User interface
|
|
2439
|
-
* @param course - Course interface
|
|
2440
|
-
* @param strategyData - Strategy configuration document
|
|
2441
|
-
* @returns the runtime object used to steer a study session.
|
|
2442
|
-
*/
|
|
2443
|
-
static async create(user, course, strategyData) {
|
|
2444
|
-
const implementingClass = strategyData.implementingClass;
|
|
2445
|
-
let NavigatorImpl;
|
|
2446
|
-
const variations = [".ts", ".js", ""];
|
|
2447
|
-
for (const ext of variations) {
|
|
2448
|
-
try {
|
|
2449
|
-
const module2 = await globImport(`./${implementingClass}${ext}`);
|
|
2450
|
-
NavigatorImpl = module2.default;
|
|
2451
|
-
break;
|
|
2452
|
-
} catch (e) {
|
|
2453
|
-
logger.debug(`Failed to load with extension ${ext}:`, e);
|
|
2454
|
-
}
|
|
2455
|
-
}
|
|
2456
|
-
if (!NavigatorImpl) {
|
|
2457
|
-
throw new Error(`Could not load navigator implementation for: ${implementingClass}`);
|
|
2458
|
-
}
|
|
2459
|
-
return new NavigatorImpl(user, course, strategyData);
|
|
2460
|
-
}
|
|
2461
|
-
/**
|
|
2462
|
-
* Get cards with suitability scores and provenance trails.
|
|
2463
|
-
*
|
|
2464
|
-
* **This is the PRIMARY API for navigation strategies.**
|
|
2465
|
-
*
|
|
2466
|
-
* Returns cards ranked by suitability score (0-1). Higher scores indicate
|
|
2467
|
-
* better candidates for presentation. Each card includes a provenance trail
|
|
2468
|
-
* documenting how strategies contributed to the final score.
|
|
2469
|
-
*
|
|
2470
|
-
* ## For Generators
|
|
2471
|
-
* Override this method to generate candidates and compute scores based on
|
|
2472
|
-
* your strategy's logic (e.g., ELO proximity, review urgency). Create the
|
|
2473
|
-
* initial provenance entry with action='generated'.
|
|
2474
|
-
*
|
|
2475
|
-
* ## Default Implementation
|
|
2476
|
-
* The base class provides a backward-compatible default that:
|
|
2477
|
-
* 1. Calls legacy getNewCards() and getPendingReviews()
|
|
2478
|
-
* 2. Assigns score=1.0 to all cards
|
|
2479
|
-
* 3. Creates minimal provenance from legacy methods
|
|
2480
|
-
* 4. Returns combined results up to limit
|
|
2481
|
-
*
|
|
2482
|
-
* This allows existing strategies to work without modification while
|
|
2483
|
-
* new strategies can override with proper scoring and provenance.
|
|
2484
|
-
*
|
|
2485
|
-
* @param limit - Maximum cards to return
|
|
2486
|
-
* @returns Cards sorted by score descending, with provenance trails
|
|
2487
|
-
*/
|
|
2488
|
-
async getWeightedCards(limit) {
|
|
2489
|
-
const newCards = await this.getNewCards(limit);
|
|
2490
|
-
const reviews = await this.getPendingReviews();
|
|
2491
|
-
const weighted = [
|
|
2492
|
-
...newCards.map((c) => ({
|
|
2493
|
-
cardId: c.cardID,
|
|
2494
|
-
courseId: c.courseID,
|
|
2495
|
-
score: 1,
|
|
2496
|
-
provenance: [
|
|
2497
|
-
{
|
|
2498
|
-
strategy: "legacy",
|
|
2499
|
-
strategyName: this.strategyName || "Legacy API",
|
|
2500
|
-
strategyId: this.strategyId || "legacy-fallback",
|
|
2501
|
-
action: "generated",
|
|
2502
|
-
score: 1,
|
|
2503
|
-
reason: "Generated via legacy getNewCards(), new card"
|
|
2504
|
-
}
|
|
2505
|
-
]
|
|
2506
|
-
})),
|
|
2507
|
-
...reviews.map((r) => ({
|
|
2508
|
-
cardId: r.cardID,
|
|
2509
|
-
courseId: r.courseID,
|
|
2510
|
-
score: 1,
|
|
2511
|
-
provenance: [
|
|
2512
|
-
{
|
|
2513
|
-
strategy: "legacy",
|
|
2514
|
-
strategyName: this.strategyName || "Legacy API",
|
|
2515
|
-
strategyId: this.strategyId || "legacy-fallback",
|
|
2516
|
-
action: "generated",
|
|
2517
|
-
score: 1,
|
|
2518
|
-
reason: "Generated via legacy getPendingReviews(), review"
|
|
2519
|
-
}
|
|
2520
|
-
]
|
|
2521
|
-
}))
|
|
2522
|
-
];
|
|
2523
|
-
return weighted.slice(0, limit);
|
|
1346
|
+
*/
|
|
1347
|
+
computeUrgencyScore(review, now) {
|
|
1348
|
+
const scheduledAt = import_moment.default.utc(review.scheduledAt);
|
|
1349
|
+
const due = import_moment.default.utc(review.reviewTime);
|
|
1350
|
+
const intervalHours = Math.max(1, due.diff(scheduledAt, "hours"));
|
|
1351
|
+
const hoursOverdue = now.diff(due, "hours");
|
|
1352
|
+
const relativeOverdue = hoursOverdue / intervalHours;
|
|
1353
|
+
const recencyFactor = 0.3 + 0.7 * Math.exp(-intervalHours / 720);
|
|
1354
|
+
const overdueContribution = Math.min(1, Math.max(0, relativeOverdue));
|
|
1355
|
+
const urgency = overdueContribution * 0.5 + recencyFactor * 0.5;
|
|
1356
|
+
const score = Math.min(0.95, 0.5 + urgency * 0.45);
|
|
1357
|
+
const reason = `${Math.round(hoursOverdue)}h overdue (interval: ${Math.round(intervalHours)}h, relative: ${relativeOverdue.toFixed(2)}), recency: ${recencyFactor.toFixed(2)}, review`;
|
|
1358
|
+
return { score, reason };
|
|
2524
1359
|
}
|
|
2525
1360
|
};
|
|
2526
1361
|
}
|
|
2527
1362
|
});
|
|
2528
1363
|
|
|
1364
|
+
// src/core/navigators/filters/eloDistance.ts
|
|
1365
|
+
function computeMultiplier(distance, halfLife, minMultiplier, maxMultiplier) {
|
|
1366
|
+
const normalizedDistance = distance / halfLife;
|
|
1367
|
+
const decay = Math.exp(-(normalizedDistance * normalizedDistance));
|
|
1368
|
+
return minMultiplier + (maxMultiplier - minMultiplier) * decay;
|
|
1369
|
+
}
|
|
1370
|
+
function createEloDistanceFilter(config) {
|
|
1371
|
+
const halfLife = config?.halfLife ?? DEFAULT_HALF_LIFE;
|
|
1372
|
+
const minMultiplier = config?.minMultiplier ?? DEFAULT_MIN_MULTIPLIER;
|
|
1373
|
+
const maxMultiplier = config?.maxMultiplier ?? DEFAULT_MAX_MULTIPLIER;
|
|
1374
|
+
return {
|
|
1375
|
+
name: "ELO Distance Filter",
|
|
1376
|
+
async transform(cards, context) {
|
|
1377
|
+
const { course, userElo } = context;
|
|
1378
|
+
const cardIds = cards.map((c) => c.cardId);
|
|
1379
|
+
const cardElos = await course.getCardEloData(cardIds);
|
|
1380
|
+
return cards.map((card, i) => {
|
|
1381
|
+
const cardElo = cardElos[i]?.global?.score ?? 1e3;
|
|
1382
|
+
const distance = Math.abs(cardElo - userElo);
|
|
1383
|
+
const multiplier = computeMultiplier(distance, halfLife, minMultiplier, maxMultiplier);
|
|
1384
|
+
const newScore = card.score * multiplier;
|
|
1385
|
+
const action = multiplier < maxMultiplier - 0.01 ? "penalized" : "passed";
|
|
1386
|
+
return {
|
|
1387
|
+
...card,
|
|
1388
|
+
score: newScore,
|
|
1389
|
+
provenance: [
|
|
1390
|
+
...card.provenance,
|
|
1391
|
+
{
|
|
1392
|
+
strategy: "eloDistance",
|
|
1393
|
+
strategyName: "ELO Distance Filter",
|
|
1394
|
+
strategyId: "ELO_DISTANCE_FILTER",
|
|
1395
|
+
action,
|
|
1396
|
+
score: newScore,
|
|
1397
|
+
reason: `ELO distance ${Math.round(distance)} (card: ${Math.round(cardElo)}, user: ${Math.round(userElo)}) \u2192 ${multiplier.toFixed(2)}x`
|
|
1398
|
+
}
|
|
1399
|
+
]
|
|
1400
|
+
};
|
|
1401
|
+
});
|
|
1402
|
+
}
|
|
1403
|
+
};
|
|
1404
|
+
}
|
|
1405
|
+
var DEFAULT_HALF_LIFE, DEFAULT_MIN_MULTIPLIER, DEFAULT_MAX_MULTIPLIER;
|
|
1406
|
+
var init_eloDistance = __esm({
|
|
1407
|
+
"src/core/navigators/filters/eloDistance.ts"() {
|
|
1408
|
+
"use strict";
|
|
1409
|
+
DEFAULT_HALF_LIFE = 200;
|
|
1410
|
+
DEFAULT_MIN_MULTIPLIER = 0.3;
|
|
1411
|
+
DEFAULT_MAX_MULTIPLIER = 1;
|
|
1412
|
+
}
|
|
1413
|
+
});
|
|
1414
|
+
|
|
1415
|
+
// src/core/navigators/defaults.ts
|
|
1416
|
+
function createDefaultEloStrategy(courseId) {
|
|
1417
|
+
return {
|
|
1418
|
+
_id: "NAVIGATION_STRATEGY-ELO-default",
|
|
1419
|
+
docType: "NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */,
|
|
1420
|
+
name: "ELO (default)",
|
|
1421
|
+
description: "Default ELO-based navigation strategy for new cards",
|
|
1422
|
+
implementingClass: "elo" /* ELO */,
|
|
1423
|
+
course: courseId,
|
|
1424
|
+
serializedData: ""
|
|
1425
|
+
};
|
|
1426
|
+
}
|
|
1427
|
+
function createDefaultSrsStrategy(courseId) {
|
|
1428
|
+
return {
|
|
1429
|
+
_id: "NAVIGATION_STRATEGY-SRS-default",
|
|
1430
|
+
docType: "NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */,
|
|
1431
|
+
name: "SRS (default)",
|
|
1432
|
+
description: "Default SRS-based navigation strategy for reviews",
|
|
1433
|
+
implementingClass: "srs" /* SRS */,
|
|
1434
|
+
course: courseId,
|
|
1435
|
+
serializedData: ""
|
|
1436
|
+
};
|
|
1437
|
+
}
|
|
1438
|
+
function createDefaultPipeline(user, course) {
|
|
1439
|
+
const courseId = course.getCourseID();
|
|
1440
|
+
const eloNavigator = new ELONavigator(user, course, createDefaultEloStrategy(courseId));
|
|
1441
|
+
const srsNavigator = new SRSNavigator(user, course, createDefaultSrsStrategy(courseId));
|
|
1442
|
+
const compositeGenerator = new CompositeGenerator([eloNavigator, srsNavigator]);
|
|
1443
|
+
const eloDistanceFilter = createEloDistanceFilter();
|
|
1444
|
+
return new Pipeline(compositeGenerator, [eloDistanceFilter], user, course);
|
|
1445
|
+
}
|
|
1446
|
+
var init_defaults = __esm({
|
|
1447
|
+
"src/core/navigators/defaults.ts"() {
|
|
1448
|
+
"use strict";
|
|
1449
|
+
init_navigators();
|
|
1450
|
+
init_Pipeline();
|
|
1451
|
+
init_CompositeGenerator();
|
|
1452
|
+
init_elo();
|
|
1453
|
+
init_srs();
|
|
1454
|
+
init_eloDistance();
|
|
1455
|
+
init_types_legacy();
|
|
1456
|
+
}
|
|
1457
|
+
});
|
|
1458
|
+
|
|
2529
1459
|
// src/impl/couch/courseDB.ts
|
|
2530
1460
|
function randIntWeightedTowardZero(n) {
|
|
2531
1461
|
return Math.floor(Math.random() * Math.random() * Math.random() * n);
|
|
@@ -2644,11 +1574,11 @@ ${JSON.stringify(config)}
|
|
|
2644
1574
|
function isSuccessRow(row) {
|
|
2645
1575
|
return "doc" in row && row.doc !== null && row.doc !== void 0;
|
|
2646
1576
|
}
|
|
2647
|
-
var
|
|
1577
|
+
var import_common7, CoursesDB, CourseDB;
|
|
2648
1578
|
var init_courseDB = __esm({
|
|
2649
1579
|
"src/impl/couch/courseDB.ts"() {
|
|
2650
1580
|
"use strict";
|
|
2651
|
-
|
|
1581
|
+
import_common7 = require("@vue-skuilder/common");
|
|
2652
1582
|
init_couch();
|
|
2653
1583
|
init_updateQueue();
|
|
2654
1584
|
init_types_legacy();
|
|
@@ -2657,12 +1587,8 @@ var init_courseDB = __esm({
|
|
|
2657
1587
|
init_courseAPI();
|
|
2658
1588
|
init_courseLookupDB();
|
|
2659
1589
|
init_navigators();
|
|
2660
|
-
init_Pipeline();
|
|
2661
1590
|
init_PipelineAssembler();
|
|
2662
|
-
|
|
2663
|
-
init_elo();
|
|
2664
|
-
init_srs();
|
|
2665
|
-
init_eloDistance();
|
|
1591
|
+
init_defaults();
|
|
2666
1592
|
CoursesDB = class {
|
|
2667
1593
|
_courseIDs;
|
|
2668
1594
|
constructor(courseIDs) {
|
|
@@ -2774,14 +1700,14 @@ var init_courseDB = __esm({
|
|
|
2774
1700
|
docs.rows.forEach((r) => {
|
|
2775
1701
|
if (isSuccessRow(r)) {
|
|
2776
1702
|
if (r.doc && r.doc.elo) {
|
|
2777
|
-
ret.push((0,
|
|
1703
|
+
ret.push((0, import_common7.toCourseElo)(r.doc.elo));
|
|
2778
1704
|
} else {
|
|
2779
1705
|
logger.warn("no elo data for card: " + r.id);
|
|
2780
|
-
ret.push((0,
|
|
1706
|
+
ret.push((0, import_common7.blankCourseElo)());
|
|
2781
1707
|
}
|
|
2782
1708
|
} else {
|
|
2783
1709
|
logger.warn("no elo data for card: " + JSON.stringify(r));
|
|
2784
|
-
ret.push((0,
|
|
1710
|
+
ret.push((0, import_common7.blankCourseElo)());
|
|
2785
1711
|
}
|
|
2786
1712
|
});
|
|
2787
1713
|
return ret;
|
|
@@ -2976,7 +1902,7 @@ ${above.rows.map((r) => ` ${r.id}-${r.key}
|
|
|
2976
1902
|
async getCourseTagStubs() {
|
|
2977
1903
|
return getCourseTagStubs(this.id);
|
|
2978
1904
|
}
|
|
2979
|
-
async addNote(codeCourse, shape, data, author, tags, uploads, elo = (0,
|
|
1905
|
+
async addNote(codeCourse, shape, data, author, tags, uploads, elo = (0, import_common7.blankCourseElo)()) {
|
|
2980
1906
|
try {
|
|
2981
1907
|
const resp = await addNote55(this.id, codeCourse, shape, data, author, tags, uploads, elo);
|
|
2982
1908
|
if (resp.ok) {
|
|
@@ -2985,19 +1911,19 @@ ${above.rows.map((r) => ` ${r.id}-${r.key}
|
|
|
2985
1911
|
`[courseDB.addNote] Note added but card creation failed: ${resp.cardCreationError}`
|
|
2986
1912
|
);
|
|
2987
1913
|
return {
|
|
2988
|
-
status:
|
|
1914
|
+
status: import_common7.Status.error,
|
|
2989
1915
|
message: `Note was added but no cards were created: ${resp.cardCreationError}`,
|
|
2990
1916
|
id: resp.id
|
|
2991
1917
|
};
|
|
2992
1918
|
}
|
|
2993
1919
|
return {
|
|
2994
|
-
status:
|
|
1920
|
+
status: import_common7.Status.ok,
|
|
2995
1921
|
message: "",
|
|
2996
1922
|
id: resp.id
|
|
2997
1923
|
};
|
|
2998
1924
|
} else {
|
|
2999
1925
|
return {
|
|
3000
|
-
status:
|
|
1926
|
+
status: import_common7.Status.error,
|
|
3001
1927
|
message: "Unexpected error adding note"
|
|
3002
1928
|
};
|
|
3003
1929
|
}
|
|
@@ -3009,7 +1935,7 @@ ${above.rows.map((r) => ` ${r.id}-${r.key}
|
|
|
3009
1935
|
message: ${err.message}`
|
|
3010
1936
|
);
|
|
3011
1937
|
return {
|
|
3012
|
-
status:
|
|
1938
|
+
status: import_common7.Status.error,
|
|
3013
1939
|
message: `Error adding note to course. ${e.reason || err.message}`
|
|
3014
1940
|
};
|
|
3015
1941
|
}
|
|
@@ -3076,7 +2002,7 @@ ${above.rows.map((r) => ` ${r.id}-${r.key}
|
|
|
3076
2002
|
logger.debug(
|
|
3077
2003
|
"[courseDB] No strategy documents found, using default Pipeline(Composite(ELO, SRS), [eloDistanceFilter])"
|
|
3078
2004
|
);
|
|
3079
|
-
return
|
|
2005
|
+
return createDefaultPipeline(user, this);
|
|
3080
2006
|
}
|
|
3081
2007
|
const assembler = new PipelineAssembler();
|
|
3082
2008
|
const { pipeline, generatorStrategies, filterStrategies, warnings } = await assembler.assemble({
|
|
@@ -3089,7 +2015,7 @@ ${above.rows.map((r) => ` ${r.id}-${r.key}
|
|
|
3089
2015
|
}
|
|
3090
2016
|
if (!pipeline) {
|
|
3091
2017
|
logger.debug("[courseDB] Pipeline assembly failed, using default pipeline");
|
|
3092
|
-
return
|
|
2018
|
+
return createDefaultPipeline(user, this);
|
|
3093
2019
|
}
|
|
3094
2020
|
logger.debug(
|
|
3095
2021
|
`[courseDB] Using assembled pipeline with ${generatorStrategies.length} generator(s) and ${filterStrategies.length} filter(s)`
|
|
@@ -3100,69 +2026,12 @@ ${above.rows.map((r) => ` ${r.id}-${r.key}
|
|
|
3100
2026
|
throw e;
|
|
3101
2027
|
}
|
|
3102
2028
|
}
|
|
3103
|
-
makeDefaultEloStrategy() {
|
|
3104
|
-
return {
|
|
3105
|
-
_id: "NAVIGATION_STRATEGY-ELO-default",
|
|
3106
|
-
docType: "NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */,
|
|
3107
|
-
name: "ELO (default)",
|
|
3108
|
-
description: "Default ELO-based navigation strategy for new cards",
|
|
3109
|
-
implementingClass: "elo" /* ELO */,
|
|
3110
|
-
course: this.id,
|
|
3111
|
-
serializedData: ""
|
|
3112
|
-
};
|
|
3113
|
-
}
|
|
3114
|
-
makeDefaultSrsStrategy() {
|
|
3115
|
-
return {
|
|
3116
|
-
_id: "NAVIGATION_STRATEGY-SRS-default",
|
|
3117
|
-
docType: "NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */,
|
|
3118
|
-
name: "SRS (default)",
|
|
3119
|
-
description: "Default SRS-based navigation strategy for reviews",
|
|
3120
|
-
implementingClass: "srs" /* SRS */,
|
|
3121
|
-
course: this.id,
|
|
3122
|
-
serializedData: ""
|
|
3123
|
-
};
|
|
3124
|
-
}
|
|
3125
|
-
/**
|
|
3126
|
-
* Creates the default navigation pipeline for courses with no configured strategies.
|
|
3127
|
-
*
|
|
3128
|
-
* Default: Pipeline(Composite(ELO, SRS), [eloDistanceFilter])
|
|
3129
|
-
* - ELO generator: scores new cards by skill proximity
|
|
3130
|
-
* - SRS generator: scores reviews by overdueness and interval recency
|
|
3131
|
-
* - ELO distance filter: penalizes cards far from user's current level
|
|
3132
|
-
*/
|
|
3133
|
-
createDefaultPipeline(user) {
|
|
3134
|
-
const eloNavigator = new ELONavigator(user, this, this.makeDefaultEloStrategy());
|
|
3135
|
-
const srsNavigator = new SRSNavigator(user, this, this.makeDefaultSrsStrategy());
|
|
3136
|
-
const compositeGenerator = new CompositeGenerator([eloNavigator, srsNavigator]);
|
|
3137
|
-
const eloDistanceFilter = createEloDistanceFilter();
|
|
3138
|
-
return new Pipeline(compositeGenerator, [eloDistanceFilter], user, this);
|
|
3139
|
-
}
|
|
3140
2029
|
////////////////////////////////////
|
|
3141
2030
|
// END NavigationStrategyManager implementation
|
|
3142
2031
|
////////////////////////////////////
|
|
3143
2032
|
////////////////////////////////////
|
|
3144
2033
|
// StudyContentSource implementation
|
|
3145
2034
|
////////////////////////////////////
|
|
3146
|
-
async getNewCards(limit = 99) {
|
|
3147
|
-
const u = await this._getCurrentUser();
|
|
3148
|
-
try {
|
|
3149
|
-
const navigator = await this.createNavigator(u);
|
|
3150
|
-
return navigator.getNewCards(limit);
|
|
3151
|
-
} catch (e) {
|
|
3152
|
-
logger.error(`[courseDB] Error in getNewCards: ${e}`);
|
|
3153
|
-
throw e;
|
|
3154
|
-
}
|
|
3155
|
-
}
|
|
3156
|
-
async getPendingReviews() {
|
|
3157
|
-
const u = await this._getCurrentUser();
|
|
3158
|
-
try {
|
|
3159
|
-
const navigator = await this.createNavigator(u);
|
|
3160
|
-
return navigator.getPendingReviews();
|
|
3161
|
-
} catch (e) {
|
|
3162
|
-
logger.error(`[courseDB] Error in getPendingReviews: ${e}`);
|
|
3163
|
-
throw e;
|
|
3164
|
-
}
|
|
3165
|
-
}
|
|
3166
2035
|
/**
|
|
3167
2036
|
* Get cards with suitability scores for presentation.
|
|
3168
2037
|
*
|
|
@@ -3194,7 +2063,7 @@ ${above.rows.map((r) => ` ${r.id}-${r.key}
|
|
|
3194
2063
|
const courseDoc = (await u.getCourseRegistrationsDoc()).courses.find((c) => {
|
|
3195
2064
|
return c.courseID === this.id;
|
|
3196
2065
|
});
|
|
3197
|
-
targetElo = (0,
|
|
2066
|
+
targetElo = (0, import_common7.EloToNumber)(courseDoc.elo);
|
|
3198
2067
|
} catch {
|
|
3199
2068
|
targetElo = 1e3;
|
|
3200
2069
|
}
|
|
@@ -3413,79 +2282,27 @@ var init_classroomDB2 = __esm({
|
|
|
3413
2282
|
setChangeFcn(f) {
|
|
3414
2283
|
void this.userMessages.on("change", f);
|
|
3415
2284
|
}
|
|
3416
|
-
async getPendingReviews() {
|
|
3417
|
-
const u = this._user;
|
|
3418
|
-
return (await u.getPendingReviews()).filter((r) => r.scheduledFor === "classroom" && r.schedulingAgentId === this._id).map((r) => {
|
|
3419
|
-
return {
|
|
3420
|
-
...r,
|
|
3421
|
-
qualifiedID: `${r.courseId}-${r.cardId}`,
|
|
3422
|
-
courseID: r.courseId,
|
|
3423
|
-
cardID: r.cardId,
|
|
3424
|
-
contentSourceType: "classroom",
|
|
3425
|
-
contentSourceID: this._id,
|
|
3426
|
-
reviewID: r._id,
|
|
3427
|
-
status: "review"
|
|
3428
|
-
};
|
|
3429
|
-
});
|
|
3430
|
-
}
|
|
3431
|
-
async getNewCards() {
|
|
3432
|
-
const activeCards = await this._user.getActiveCards();
|
|
3433
|
-
const now = import_moment2.default.utc();
|
|
3434
|
-
const assigned = await this.getAssignedContent();
|
|
3435
|
-
const due = assigned.filter((c) => now.isAfter(import_moment2.default.utc(c.activeOn, REVIEW_TIME_FORMAT)));
|
|
3436
|
-
logger.info(`Due content: ${JSON.stringify(due)}`);
|
|
3437
|
-
let ret = [];
|
|
3438
|
-
for (let i = 0; i < due.length; i++) {
|
|
3439
|
-
const content = due[i];
|
|
3440
|
-
if (content.type === "course") {
|
|
3441
|
-
const db = new CourseDB(content.courseID, async () => this._user);
|
|
3442
|
-
ret = ret.concat(await db.getNewCards());
|
|
3443
|
-
} else if (content.type === "tag") {
|
|
3444
|
-
const tagDoc = await getTag(content.courseID, content.tagID);
|
|
3445
|
-
ret = ret.concat(
|
|
3446
|
-
tagDoc.taggedCards.map((c) => {
|
|
3447
|
-
return {
|
|
3448
|
-
courseID: content.courseID,
|
|
3449
|
-
cardID: c,
|
|
3450
|
-
qualifiedID: `${content.courseID}-${c}`,
|
|
3451
|
-
contentSourceType: "classroom",
|
|
3452
|
-
contentSourceID: this._id,
|
|
3453
|
-
status: "new"
|
|
3454
|
-
};
|
|
3455
|
-
})
|
|
3456
|
-
);
|
|
3457
|
-
} else if (content.type === "card") {
|
|
3458
|
-
ret.push(await getCourseDB2(content.courseID).get(content.cardID));
|
|
3459
|
-
}
|
|
3460
|
-
}
|
|
3461
|
-
logger.info(
|
|
3462
|
-
`New Cards from classroom ${this._cfg.name}: ${ret.map((c) => `${c.courseID}-${c.cardID}`)}`
|
|
3463
|
-
);
|
|
3464
|
-
return ret.filter((c) => {
|
|
3465
|
-
if (activeCards.some((ac) => c.cardID === ac.cardID)) {
|
|
3466
|
-
return false;
|
|
3467
|
-
} else {
|
|
3468
|
-
return true;
|
|
3469
|
-
}
|
|
3470
|
-
});
|
|
3471
|
-
}
|
|
3472
2285
|
/**
|
|
3473
2286
|
* Get cards with suitability scores for presentation.
|
|
3474
2287
|
*
|
|
3475
|
-
*
|
|
3476
|
-
*
|
|
3477
|
-
* support pluggable navigation strategies.
|
|
2288
|
+
* Gathers new cards from assigned content (courses, tags, cards) and
|
|
2289
|
+
* pending reviews scheduled for this classroom. Assigns score=1.0 to all.
|
|
3478
2290
|
*
|
|
3479
2291
|
* @param limit - Maximum number of cards to return
|
|
3480
2292
|
* @returns Cards sorted by score descending (all scores = 1.0)
|
|
3481
2293
|
*/
|
|
3482
2294
|
async getWeightedCards(limit) {
|
|
3483
|
-
const
|
|
3484
|
-
const
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
|
|
2295
|
+
const weighted = [];
|
|
2296
|
+
const allUserReviews = await this._user.getPendingReviews();
|
|
2297
|
+
const classroomReviews = allUserReviews.filter(
|
|
2298
|
+
(r) => r.scheduledFor === "classroom" && r.schedulingAgentId === this._id
|
|
2299
|
+
);
|
|
2300
|
+
for (const r of classroomReviews) {
|
|
2301
|
+
weighted.push({
|
|
2302
|
+
cardId: r.cardId,
|
|
2303
|
+
courseId: r.courseId,
|
|
3488
2304
|
score: 1,
|
|
2305
|
+
reviewID: r._id,
|
|
3489
2306
|
provenance: [
|
|
3490
2307
|
{
|
|
3491
2308
|
strategy: "classroom",
|
|
@@ -3493,27 +2310,84 @@ var init_classroomDB2 = __esm({
|
|
|
3493
2310
|
strategyId: "CLASSROOM",
|
|
3494
2311
|
action: "generated",
|
|
3495
2312
|
score: 1,
|
|
3496
|
-
reason: "Classroom
|
|
2313
|
+
reason: "Classroom scheduled review"
|
|
3497
2314
|
}
|
|
3498
2315
|
]
|
|
3499
|
-
})
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
2316
|
+
});
|
|
2317
|
+
}
|
|
2318
|
+
const activeCards = await this._user.getActiveCards();
|
|
2319
|
+
const activeCardIds = new Set(activeCards.map((ac) => ac.cardID));
|
|
2320
|
+
const now = import_moment2.default.utc();
|
|
2321
|
+
const assigned = await this.getAssignedContent();
|
|
2322
|
+
const due = assigned.filter((c) => now.isAfter(import_moment2.default.utc(c.activeOn, REVIEW_TIME_FORMAT)));
|
|
2323
|
+
logger.info(`[StudentClassroomDB] Due content: ${JSON.stringify(due)}`);
|
|
2324
|
+
for (const content of due) {
|
|
2325
|
+
if (content.type === "course") {
|
|
2326
|
+
const db = new CourseDB(content.courseID, async () => this._user);
|
|
2327
|
+
const courseCards = await db.getWeightedCards(limit);
|
|
2328
|
+
for (const card of courseCards) {
|
|
2329
|
+
if (!activeCardIds.has(card.cardId)) {
|
|
2330
|
+
weighted.push({
|
|
2331
|
+
...card,
|
|
2332
|
+
provenance: [
|
|
2333
|
+
...card.provenance,
|
|
2334
|
+
{
|
|
2335
|
+
strategy: "classroom",
|
|
2336
|
+
strategyName: "Classroom",
|
|
2337
|
+
strategyId: "CLASSROOM",
|
|
2338
|
+
action: "passed",
|
|
2339
|
+
score: card.score,
|
|
2340
|
+
reason: `Assigned via classroom from course ${content.courseID}`
|
|
2341
|
+
}
|
|
2342
|
+
]
|
|
2343
|
+
});
|
|
3512
2344
|
}
|
|
3513
|
-
|
|
3514
|
-
})
|
|
3515
|
-
|
|
3516
|
-
|
|
2345
|
+
}
|
|
2346
|
+
} else if (content.type === "tag") {
|
|
2347
|
+
const tagDoc = await getTag(content.courseID, content.tagID);
|
|
2348
|
+
for (const cardId of tagDoc.taggedCards) {
|
|
2349
|
+
if (!activeCardIds.has(cardId)) {
|
|
2350
|
+
weighted.push({
|
|
2351
|
+
cardId,
|
|
2352
|
+
courseId: content.courseID,
|
|
2353
|
+
score: 1,
|
|
2354
|
+
provenance: [
|
|
2355
|
+
{
|
|
2356
|
+
strategy: "classroom",
|
|
2357
|
+
strategyName: "Classroom",
|
|
2358
|
+
strategyId: "CLASSROOM",
|
|
2359
|
+
action: "generated",
|
|
2360
|
+
score: 1,
|
|
2361
|
+
reason: `Classroom assigned tag: ${content.tagID}, new card`
|
|
2362
|
+
}
|
|
2363
|
+
]
|
|
2364
|
+
});
|
|
2365
|
+
}
|
|
2366
|
+
}
|
|
2367
|
+
} else if (content.type === "card") {
|
|
2368
|
+
if (!activeCardIds.has(content.cardID)) {
|
|
2369
|
+
weighted.push({
|
|
2370
|
+
cardId: content.cardID,
|
|
2371
|
+
courseId: content.courseID,
|
|
2372
|
+
score: 1,
|
|
2373
|
+
provenance: [
|
|
2374
|
+
{
|
|
2375
|
+
strategy: "classroom",
|
|
2376
|
+
strategyName: "Classroom",
|
|
2377
|
+
strategyId: "CLASSROOM",
|
|
2378
|
+
action: "generated",
|
|
2379
|
+
score: 1,
|
|
2380
|
+
reason: "Classroom assigned card, new card"
|
|
2381
|
+
}
|
|
2382
|
+
]
|
|
2383
|
+
});
|
|
2384
|
+
}
|
|
2385
|
+
}
|
|
2386
|
+
}
|
|
2387
|
+
logger.info(
|
|
2388
|
+
`[StudentClassroomDB] New cards from classroom ${this._cfg.name}: ${weighted.length} total (reviews + new)`
|
|
2389
|
+
);
|
|
2390
|
+
return weighted.sort((a, b) => b.score - a.score).slice(0, limit);
|
|
3517
2391
|
}
|
|
3518
2392
|
};
|
|
3519
2393
|
TeacherClassroomDB = class _TeacherClassroomDB extends ClassroomDBBase {
|
|
@@ -3601,11 +2475,11 @@ var init_classroomDB2 = __esm({
|
|
|
3601
2475
|
});
|
|
3602
2476
|
|
|
3603
2477
|
// src/study/TagFilteredContentSource.ts
|
|
3604
|
-
var
|
|
2478
|
+
var import_common8, TagFilteredContentSource;
|
|
3605
2479
|
var init_TagFilteredContentSource = __esm({
|
|
3606
2480
|
"src/study/TagFilteredContentSource.ts"() {
|
|
3607
2481
|
"use strict";
|
|
3608
|
-
|
|
2482
|
+
import_common8 = require("@vue-skuilder/common");
|
|
3609
2483
|
init_courseDB();
|
|
3610
2484
|
init_logger();
|
|
3611
2485
|
TagFilteredContentSource = class {
|
|
@@ -3681,108 +2555,71 @@ var init_TagFilteredContentSource = __esm({
|
|
|
3681
2555
|
return finalCardIds;
|
|
3682
2556
|
}
|
|
3683
2557
|
/**
|
|
3684
|
-
*
|
|
2558
|
+
* Get cards with suitability scores for presentation.
|
|
2559
|
+
*
|
|
2560
|
+
* Filters cards by tag inclusion/exclusion and assigns score=1.0 to all.
|
|
2561
|
+
* TagFilteredContentSource does not currently support pluggable navigation
|
|
2562
|
+
* strategies - it returns flat-scored candidates.
|
|
2563
|
+
*
|
|
2564
|
+
* @param limit - Maximum number of cards to return
|
|
2565
|
+
* @returns Cards sorted by score descending (all scores = 1.0)
|
|
3685
2566
|
*/
|
|
3686
|
-
async
|
|
3687
|
-
if (!(0,
|
|
3688
|
-
logger.warn("[TagFilteredContentSource]
|
|
2567
|
+
async getWeightedCards(limit) {
|
|
2568
|
+
if (!(0, import_common8.hasActiveFilter)(this.filter)) {
|
|
2569
|
+
logger.warn("[TagFilteredContentSource] getWeightedCards called with no active filter");
|
|
3689
2570
|
return [];
|
|
3690
2571
|
}
|
|
3691
2572
|
const eligibleCardIds = await this.resolveFilteredCardIds();
|
|
3692
2573
|
const activeCards = await this.user.getActiveCards();
|
|
3693
2574
|
const activeCardIds = new Set(activeCards.map((c) => c.cardID));
|
|
3694
|
-
const
|
|
2575
|
+
const newCardWeighted = [];
|
|
3695
2576
|
for (const cardId of eligibleCardIds) {
|
|
3696
2577
|
if (!activeCardIds.has(cardId)) {
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
|
|
2578
|
+
newCardWeighted.push({
|
|
2579
|
+
cardId,
|
|
2580
|
+
courseId: this.courseId,
|
|
2581
|
+
score: 1,
|
|
2582
|
+
provenance: [
|
|
2583
|
+
{
|
|
2584
|
+
strategy: "tagFilter",
|
|
2585
|
+
strategyName: "Tag Filter",
|
|
2586
|
+
strategyId: "TAG_FILTER",
|
|
2587
|
+
action: "generated",
|
|
2588
|
+
score: 1,
|
|
2589
|
+
reason: `Tag-filtered new card (tags: ${this.filter.include.join(", ")})`
|
|
2590
|
+
}
|
|
2591
|
+
]
|
|
3703
2592
|
});
|
|
3704
2593
|
}
|
|
3705
|
-
if (
|
|
2594
|
+
if (newCardWeighted.length >= limit) {
|
|
3706
2595
|
break;
|
|
3707
2596
|
}
|
|
3708
2597
|
}
|
|
3709
|
-
logger.info(
|
|
3710
|
-
|
|
3711
|
-
|
|
3712
|
-
/**
|
|
3713
|
-
* Gets pending reviews, filtered to only include cards that match the tag filter.
|
|
3714
|
-
*/
|
|
3715
|
-
async getPendingReviews() {
|
|
3716
|
-
if (!(0, import_common10.hasActiveFilter)(this.filter)) {
|
|
3717
|
-
logger.warn("[TagFilteredContentSource] getPendingReviews called with no active filter");
|
|
3718
|
-
return [];
|
|
3719
|
-
}
|
|
3720
|
-
const eligibleCardIds = await this.resolveFilteredCardIds();
|
|
2598
|
+
logger.info(
|
|
2599
|
+
`[TagFilteredContentSource] Found ${newCardWeighted.length} new cards matching filter`
|
|
2600
|
+
);
|
|
3721
2601
|
const allReviews = await this.user.getPendingReviews(this.courseId);
|
|
3722
|
-
const filteredReviews = allReviews.filter((review) =>
|
|
3723
|
-
return eligibleCardIds.has(review.cardId);
|
|
3724
|
-
});
|
|
2602
|
+
const filteredReviews = allReviews.filter((review) => eligibleCardIds.has(review.cardId));
|
|
3725
2603
|
logger.info(
|
|
3726
2604
|
`[TagFilteredContentSource] Found ${filteredReviews.length} pending reviews matching filter (of ${allReviews.length} total)`
|
|
3727
2605
|
);
|
|
3728
|
-
|
|
3729
|
-
|
|
3730
|
-
|
|
3731
|
-
|
|
3732
|
-
contentSourceType: "course",
|
|
3733
|
-
contentSourceID: this.courseId,
|
|
2606
|
+
const reviewWeighted = filteredReviews.map((r) => ({
|
|
2607
|
+
cardId: r.cardId,
|
|
2608
|
+
courseId: r.courseId,
|
|
2609
|
+
score: 1,
|
|
3734
2610
|
reviewID: r._id,
|
|
3735
|
-
|
|
2611
|
+
provenance: [
|
|
2612
|
+
{
|
|
2613
|
+
strategy: "tagFilter",
|
|
2614
|
+
strategyName: "Tag Filter",
|
|
2615
|
+
strategyId: "TAG_FILTER",
|
|
2616
|
+
action: "generated",
|
|
2617
|
+
score: 1,
|
|
2618
|
+
reason: `Tag-filtered review (tags: ${this.filter.include.join(", ")})`
|
|
2619
|
+
}
|
|
2620
|
+
]
|
|
3736
2621
|
}));
|
|
3737
|
-
|
|
3738
|
-
/**
|
|
3739
|
-
* Get cards with suitability scores for presentation.
|
|
3740
|
-
*
|
|
3741
|
-
* This implementation wraps the legacy getNewCards/getPendingReviews methods,
|
|
3742
|
-
* assigning score=1.0 to all cards. TagFilteredContentSource does not currently
|
|
3743
|
-
* support pluggable navigation strategies - it returns flat-scored candidates.
|
|
3744
|
-
*
|
|
3745
|
-
* @param limit - Maximum number of cards to return
|
|
3746
|
-
* @returns Cards sorted by score descending (all scores = 1.0)
|
|
3747
|
-
*/
|
|
3748
|
-
async getWeightedCards(limit) {
|
|
3749
|
-
const [newCards, reviews] = await Promise.all([
|
|
3750
|
-
this.getNewCards(limit),
|
|
3751
|
-
this.getPendingReviews()
|
|
3752
|
-
]);
|
|
3753
|
-
const weighted = [
|
|
3754
|
-
...reviews.map((r) => ({
|
|
3755
|
-
cardId: r.cardID,
|
|
3756
|
-
courseId: r.courseID,
|
|
3757
|
-
score: 1,
|
|
3758
|
-
provenance: [
|
|
3759
|
-
{
|
|
3760
|
-
strategy: "tagFilter",
|
|
3761
|
-
strategyName: "Tag Filter",
|
|
3762
|
-
strategyId: "TAG_FILTER",
|
|
3763
|
-
action: "generated",
|
|
3764
|
-
score: 1,
|
|
3765
|
-
reason: `Tag-filtered review (tags: ${this.filter.include.join(", ")})`
|
|
3766
|
-
}
|
|
3767
|
-
]
|
|
3768
|
-
})),
|
|
3769
|
-
...newCards.map((c) => ({
|
|
3770
|
-
cardId: c.cardID,
|
|
3771
|
-
courseId: c.courseID,
|
|
3772
|
-
score: 1,
|
|
3773
|
-
provenance: [
|
|
3774
|
-
{
|
|
3775
|
-
strategy: "tagFilter",
|
|
3776
|
-
strategyName: "Tag Filter",
|
|
3777
|
-
strategyId: "TAG_FILTER",
|
|
3778
|
-
action: "generated",
|
|
3779
|
-
score: 1,
|
|
3780
|
-
reason: `Tag-filtered new card (tags: ${this.filter.include.join(", ")})`
|
|
3781
|
-
}
|
|
3782
|
-
]
|
|
3783
|
-
}))
|
|
3784
|
-
];
|
|
3785
|
-
return weighted.slice(0, limit);
|
|
2622
|
+
return [...reviewWeighted, ...newCardWeighted].slice(0, limit);
|
|
3786
2623
|
}
|
|
3787
2624
|
/**
|
|
3788
2625
|
* Clears the cached resolved card IDs.
|
|
@@ -3816,19 +2653,19 @@ async function getStudySource(source, user) {
|
|
|
3816
2653
|
if (source.type === "classroom") {
|
|
3817
2654
|
return await StudentClassroomDB.factory(source.id, user);
|
|
3818
2655
|
} else {
|
|
3819
|
-
if ((0,
|
|
2656
|
+
if ((0, import_common9.hasActiveFilter)(source.tagFilter)) {
|
|
3820
2657
|
return new TagFilteredContentSource(source.id, source.tagFilter, user);
|
|
3821
2658
|
}
|
|
3822
2659
|
return getDataLayer().getCourseDB(source.id);
|
|
3823
2660
|
}
|
|
3824
2661
|
}
|
|
3825
|
-
var
|
|
2662
|
+
var import_common9;
|
|
3826
2663
|
var init_contentSource = __esm({
|
|
3827
2664
|
"src/core/interfaces/contentSource.ts"() {
|
|
3828
2665
|
"use strict";
|
|
3829
2666
|
init_factory();
|
|
3830
2667
|
init_classroomDB2();
|
|
3831
|
-
|
|
2668
|
+
import_common9 = require("@vue-skuilder/common");
|
|
3832
2669
|
init_TagFilteredContentSource();
|
|
3833
2670
|
}
|
|
3834
2671
|
});
|
|
@@ -3896,17 +2733,17 @@ var init_util = __esm({
|
|
|
3896
2733
|
});
|
|
3897
2734
|
|
|
3898
2735
|
// src/core/bulkImport/cardProcessor.ts
|
|
3899
|
-
var
|
|
2736
|
+
var import_common10;
|
|
3900
2737
|
var init_cardProcessor = __esm({
|
|
3901
2738
|
"src/core/bulkImport/cardProcessor.ts"() {
|
|
3902
2739
|
"use strict";
|
|
3903
|
-
|
|
2740
|
+
import_common10 = require("@vue-skuilder/common");
|
|
3904
2741
|
init_logger();
|
|
3905
2742
|
}
|
|
3906
2743
|
});
|
|
3907
2744
|
|
|
3908
2745
|
// src/core/bulkImport/types.ts
|
|
3909
|
-
var
|
|
2746
|
+
var init_types = __esm({
|
|
3910
2747
|
"src/core/bulkImport/types.ts"() {
|
|
3911
2748
|
"use strict";
|
|
3912
2749
|
}
|
|
@@ -3917,7 +2754,7 @@ var init_bulkImport = __esm({
|
|
|
3917
2754
|
"src/core/bulkImport/index.ts"() {
|
|
3918
2755
|
"use strict";
|
|
3919
2756
|
init_cardProcessor();
|
|
3920
|
-
|
|
2757
|
+
init_types();
|
|
3921
2758
|
}
|
|
3922
2759
|
});
|
|
3923
2760
|
|
|
@@ -3936,14 +2773,6 @@ var init_core = __esm({
|
|
|
3936
2773
|
}
|
|
3937
2774
|
});
|
|
3938
2775
|
|
|
3939
|
-
// src/util/tuiLogger.ts
|
|
3940
|
-
var init_tuiLogger = __esm({
|
|
3941
|
-
"src/util/tuiLogger.ts"() {
|
|
3942
|
-
"use strict";
|
|
3943
|
-
init_dataDirectory();
|
|
3944
|
-
}
|
|
3945
|
-
});
|
|
3946
|
-
|
|
3947
2776
|
// src/util/dataDirectory.ts
|
|
3948
2777
|
function getAppDataDirectory() {
|
|
3949
2778
|
if (ENV.LOCAL_STORAGE_PREFIX) {
|
|
@@ -3961,7 +2790,7 @@ var init_dataDirectory = __esm({
|
|
|
3961
2790
|
"use strict";
|
|
3962
2791
|
path = __toESM(require("path"), 1);
|
|
3963
2792
|
os = __toESM(require("os"), 1);
|
|
3964
|
-
|
|
2793
|
+
init_logger();
|
|
3965
2794
|
init_factory();
|
|
3966
2795
|
}
|
|
3967
2796
|
});
|
|
@@ -4286,13 +3115,13 @@ async function dropUserFromClassroom(user, classID) {
|
|
|
4286
3115
|
async function getUserClassrooms(user) {
|
|
4287
3116
|
return getOrCreateClassroomRegistrationsDoc(user);
|
|
4288
3117
|
}
|
|
4289
|
-
var
|
|
3118
|
+
var import_common11, import_moment5, log3, BaseUser, userCoursesDoc, userClassroomsDoc;
|
|
4290
3119
|
var init_BaseUserDB = __esm({
|
|
4291
3120
|
"src/impl/common/BaseUserDB.ts"() {
|
|
4292
3121
|
"use strict";
|
|
4293
3122
|
init_core();
|
|
4294
3123
|
init_util();
|
|
4295
|
-
|
|
3124
|
+
import_common11 = require("@vue-skuilder/common");
|
|
4296
3125
|
import_moment5 = __toESM(require("moment"), 1);
|
|
4297
3126
|
init_types_legacy();
|
|
4298
3127
|
init_logger();
|
|
@@ -4342,7 +3171,7 @@ Currently logged-in as ${this._username}.`
|
|
|
4342
3171
|
);
|
|
4343
3172
|
}
|
|
4344
3173
|
const result = await this.syncStrategy.createAccount(username, password);
|
|
4345
|
-
if (result.status ===
|
|
3174
|
+
if (result.status === import_common11.Status.ok) {
|
|
4346
3175
|
log3(`Account created successfully, updating username to ${username}`);
|
|
4347
3176
|
this._username = username;
|
|
4348
3177
|
try {
|
|
@@ -4384,7 +3213,7 @@ Currently logged-in as ${this._username}.`
|
|
|
4384
3213
|
async resetUserData() {
|
|
4385
3214
|
if (this.syncStrategy.canAuthenticate()) {
|
|
4386
3215
|
return {
|
|
4387
|
-
status:
|
|
3216
|
+
status: import_common11.Status.error,
|
|
4388
3217
|
error: "Reset user data is only available for local-only mode. Use logout instead for remote sync."
|
|
4389
3218
|
};
|
|
4390
3219
|
}
|
|
@@ -4403,11 +3232,11 @@ Currently logged-in as ${this._username}.`
|
|
|
4403
3232
|
await localDB.bulkDocs(docsToDelete);
|
|
4404
3233
|
}
|
|
4405
3234
|
await this.init();
|
|
4406
|
-
return { status:
|
|
3235
|
+
return { status: import_common11.Status.ok };
|
|
4407
3236
|
} catch (error) {
|
|
4408
3237
|
logger.error("Failed to reset user data:", error);
|
|
4409
3238
|
return {
|
|
4410
|
-
status:
|
|
3239
|
+
status: import_common11.Status.error,
|
|
4411
3240
|
error: error instanceof Error ? error.message : "Unknown error during reset"
|
|
4412
3241
|
};
|
|
4413
3242
|
}
|
|
@@ -5301,14 +4130,14 @@ var init_auth = __esm({
|
|
|
5301
4130
|
});
|
|
5302
4131
|
|
|
5303
4132
|
// src/impl/couch/CouchDBSyncStrategy.ts
|
|
5304
|
-
var
|
|
4133
|
+
var import_common13, log4, CouchDBSyncStrategy;
|
|
5305
4134
|
var init_CouchDBSyncStrategy = __esm({
|
|
5306
4135
|
"src/impl/couch/CouchDBSyncStrategy.ts"() {
|
|
5307
4136
|
"use strict";
|
|
5308
4137
|
init_factory();
|
|
5309
4138
|
init_types_legacy();
|
|
5310
4139
|
init_logger();
|
|
5311
|
-
|
|
4140
|
+
import_common13 = require("@vue-skuilder/common");
|
|
5312
4141
|
init_common();
|
|
5313
4142
|
init_pouchdb_setup();
|
|
5314
4143
|
init_couch();
|
|
@@ -5379,32 +4208,32 @@ var init_CouchDBSyncStrategy = __esm({
|
|
|
5379
4208
|
}
|
|
5380
4209
|
}
|
|
5381
4210
|
return {
|
|
5382
|
-
status:
|
|
4211
|
+
status: import_common13.Status.ok,
|
|
5383
4212
|
error: void 0
|
|
5384
4213
|
};
|
|
5385
4214
|
} else {
|
|
5386
4215
|
return {
|
|
5387
|
-
status:
|
|
4216
|
+
status: import_common13.Status.error,
|
|
5388
4217
|
error: "Failed to log in after account creation"
|
|
5389
4218
|
};
|
|
5390
4219
|
}
|
|
5391
4220
|
} else {
|
|
5392
4221
|
logger.warn(`Signup not OK: ${JSON.stringify(signupRequest)}`);
|
|
5393
4222
|
return {
|
|
5394
|
-
status:
|
|
4223
|
+
status: import_common13.Status.error,
|
|
5395
4224
|
error: "Account creation failed"
|
|
5396
4225
|
};
|
|
5397
4226
|
}
|
|
5398
4227
|
} catch (e) {
|
|
5399
4228
|
if (e.reason === "Document update conflict.") {
|
|
5400
4229
|
return {
|
|
5401
|
-
status:
|
|
4230
|
+
status: import_common13.Status.error,
|
|
5402
4231
|
error: "This username is taken!"
|
|
5403
4232
|
};
|
|
5404
4233
|
}
|
|
5405
4234
|
logger.error(`Error on signup: ${JSON.stringify(e)}`);
|
|
5406
4235
|
return {
|
|
5407
|
-
status:
|
|
4236
|
+
status: import_common13.Status.error,
|
|
5408
4237
|
error: e.message || "Unknown error during account creation"
|
|
5409
4238
|
};
|
|
5410
4239
|
}
|