@vue-skuilder/db 0.1.17 → 0.1.20
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/dist/{userDB-BqwxtJ_7.d.mts → classroomDB-CZdMBiTU.d.ts} +427 -104
- package/dist/{userDB-DNa0XPtn.d.ts → classroomDB-PxDZTky3.d.cts} +427 -104
- package/dist/core/index.d.cts +304 -0
- package/dist/core/index.d.ts +237 -25
- package/dist/core/index.js +2246 -118
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.mjs +2235 -114
- package/dist/core/index.mjs.map +1 -1
- package/dist/{dataLayerProvider-VlngD19_.d.mts → dataLayerProvider-D0MoZMjH.d.cts} +1 -1
- package/dist/{dataLayerProvider-BV5iZqt_.d.ts → dataLayerProvider-D8o6ZnKW.d.ts} +1 -1
- package/dist/impl/couch/{index.d.mts → index.d.cts} +47 -5
- package/dist/impl/couch/index.d.ts +46 -4
- package/dist/impl/couch/index.js +2250 -134
- package/dist/impl/couch/index.js.map +1 -1
- package/dist/impl/couch/index.mjs +2212 -97
- package/dist/impl/couch/index.mjs.map +1 -1
- package/dist/impl/static/{index.d.mts → index.d.cts} +6 -6
- package/dist/impl/static/index.d.ts +5 -5
- package/dist/impl/static/index.js +1950 -143
- package/dist/impl/static/index.js.map +1 -1
- package/dist/impl/static/index.mjs +1922 -117
- package/dist/impl/static/index.mjs.map +1 -1
- package/dist/{index-Bmll7Xse.d.mts → index-B_j6u5E4.d.cts} +1 -1
- package/dist/{index-CD8BZz2k.d.ts → index-Dj0SEgk3.d.ts} +1 -1
- package/dist/{index.d.mts → index.d.cts} +97 -13
- package/dist/index.d.ts +96 -12
- package/dist/index.js +2439 -180
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2386 -135
- package/dist/index.mjs.map +1 -1
- package/dist/pouch/index.js +3 -3
- package/dist/{types-Dbp5DaRR.d.mts → types-Bn0itutr.d.cts} +1 -1
- package/dist/{types-CewsN87z.d.ts → types-DQaXnuoc.d.ts} +1 -1
- package/dist/{types-legacy-6ettoclI.d.ts → types-legacy-DDY4N-Uq.d.cts} +3 -1
- package/dist/{types-legacy-6ettoclI.d.mts → types-legacy-DDY4N-Uq.d.ts} +3 -1
- package/dist/util/packer/{index.d.mts → index.d.cts} +3 -3
- package/dist/util/packer/index.d.ts +3 -3
- package/dist/util/packer/index.js.map +1 -1
- package/dist/util/packer/index.mjs.map +1 -1
- package/docs/brainstorm-navigation-paradigm.md +369 -0
- package/docs/navigators-architecture.md +370 -0
- package/docs/todo-evolutionary-orchestration.md +310 -0
- package/docs/todo-nominal-tag-types.md +121 -0
- package/docs/todo-strategy-authoring.md +401 -0
- package/eslint.config.mjs +1 -1
- package/package.json +9 -4
- package/src/core/index.ts +1 -0
- package/src/core/interfaces/contentSource.ts +88 -4
- package/src/core/interfaces/courseDB.ts +13 -0
- package/src/core/interfaces/navigationStrategyManager.ts +0 -5
- package/src/core/interfaces/userDB.ts +32 -0
- package/src/core/navigators/CompositeGenerator.ts +268 -0
- package/src/core/navigators/Pipeline.ts +318 -0
- package/src/core/navigators/PipelineAssembler.ts +194 -0
- package/src/core/navigators/elo.ts +104 -15
- package/src/core/navigators/filters/eloDistance.ts +132 -0
- package/src/core/navigators/filters/index.ts +9 -0
- package/src/core/navigators/filters/types.ts +115 -0
- package/src/core/navigators/filters/userTagPreference.ts +232 -0
- package/src/core/navigators/generators/index.ts +2 -0
- package/src/core/navigators/generators/types.ts +107 -0
- package/src/core/navigators/hardcodedOrder.ts +111 -12
- package/src/core/navigators/hierarchyDefinition.ts +266 -0
- package/src/core/navigators/index.ts +404 -3
- package/src/core/navigators/inferredPreference.ts +107 -0
- package/src/core/navigators/interferenceMitigator.ts +355 -0
- package/src/core/navigators/relativePriority.ts +255 -0
- package/src/core/navigators/srs.ts +195 -0
- package/src/core/navigators/userGoal.ts +136 -0
- package/src/core/types/strategyState.ts +84 -0
- package/src/core/types/types-legacy.ts +2 -0
- package/src/impl/common/BaseUserDB.ts +74 -7
- package/src/impl/couch/adminDB.ts +1 -2
- package/src/impl/couch/classroomDB.ts +51 -0
- package/src/impl/couch/courseDB.ts +147 -49
- package/src/impl/static/courseDB.ts +11 -4
- package/src/study/SessionController.ts +149 -1
- package/src/study/TagFilteredContentSource.ts +255 -0
- package/src/study/index.ts +1 -0
- package/src/util/dataDirectory.test.ts +51 -22
- package/src/util/logger.ts +0 -1
- package/tests/core/navigators/CompositeGenerator.test.ts +455 -0
- package/tests/core/navigators/Pipeline.test.ts +406 -0
- package/tests/core/navigators/PipelineAssembler.test.ts +351 -0
- package/tests/core/navigators/SRSNavigator.test.ts +344 -0
- package/tests/core/navigators/eloDistanceFilter.test.ts +192 -0
- package/tests/core/navigators/navigators.test.ts +710 -0
- package/tsconfig.json +1 -1
- package/vitest.config.ts +29 -0
- package/dist/core/index.d.mts +0 -92
- /package/dist/{SyncStrategy-CyATpyLQ.d.mts → SyncStrategy-CyATpyLQ.d.cts} +0 -0
- /package/dist/pouch/{index.d.mts → index.d.cts} +0 -0
package/dist/core/index.mjs
CHANGED
|
@@ -100,6 +100,7 @@ var init_types_legacy = __esm({
|
|
|
100
100
|
DocType2["SCHEDULED_CARD"] = "SCHEDULED_CARD";
|
|
101
101
|
DocType2["TAG"] = "TAG";
|
|
102
102
|
DocType2["NAVIGATION_STRATEGY"] = "NAVIGATION_STRATEGY";
|
|
103
|
+
DocType2["STRATEGY_STATE"] = "STRATEGY_STATE";
|
|
103
104
|
return DocType2;
|
|
104
105
|
})(DocType || {});
|
|
105
106
|
DocTypePrefixes = {
|
|
@@ -113,7 +114,8 @@ var init_types_legacy = __esm({
|
|
|
113
114
|
["QUESTION" /* QUESTIONTYPE */]: "QUESTION",
|
|
114
115
|
["VIEW" /* VIEW */]: "VIEW",
|
|
115
116
|
["PEDAGOGY" /* PEDAGOGY */]: "PEDAGOGY",
|
|
116
|
-
["NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */]: "NAVIGATION_STRATEGY"
|
|
117
|
+
["NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */]: "NAVIGATION_STRATEGY",
|
|
118
|
+
["STRATEGY_STATE" /* STRATEGY_STATE */]: "STRATEGY_STATE"
|
|
117
119
|
};
|
|
118
120
|
}
|
|
119
121
|
});
|
|
@@ -686,23 +688,518 @@ var init_courseLookupDB = __esm({
|
|
|
686
688
|
}
|
|
687
689
|
});
|
|
688
690
|
|
|
691
|
+
// src/core/navigators/CompositeGenerator.ts
|
|
692
|
+
var CompositeGenerator_exports = {};
|
|
693
|
+
__export(CompositeGenerator_exports, {
|
|
694
|
+
AggregationMode: () => AggregationMode,
|
|
695
|
+
default: () => CompositeGenerator
|
|
696
|
+
});
|
|
697
|
+
var AggregationMode, DEFAULT_AGGREGATION_MODE, FREQUENCY_BOOST_FACTOR, CompositeGenerator;
|
|
698
|
+
var init_CompositeGenerator = __esm({
|
|
699
|
+
"src/core/navigators/CompositeGenerator.ts"() {
|
|
700
|
+
"use strict";
|
|
701
|
+
init_navigators();
|
|
702
|
+
init_logger();
|
|
703
|
+
AggregationMode = /* @__PURE__ */ ((AggregationMode2) => {
|
|
704
|
+
AggregationMode2["MAX"] = "max";
|
|
705
|
+
AggregationMode2["AVERAGE"] = "average";
|
|
706
|
+
AggregationMode2["FREQUENCY_BOOST"] = "frequencyBoost";
|
|
707
|
+
return AggregationMode2;
|
|
708
|
+
})(AggregationMode || {});
|
|
709
|
+
DEFAULT_AGGREGATION_MODE = "frequencyBoost" /* FREQUENCY_BOOST */;
|
|
710
|
+
FREQUENCY_BOOST_FACTOR = 0.1;
|
|
711
|
+
CompositeGenerator = class _CompositeGenerator extends ContentNavigator {
|
|
712
|
+
/** Human-readable name for CardGenerator interface */
|
|
713
|
+
name = "Composite Generator";
|
|
714
|
+
generators;
|
|
715
|
+
aggregationMode;
|
|
716
|
+
constructor(generators, aggregationMode = DEFAULT_AGGREGATION_MODE) {
|
|
717
|
+
super();
|
|
718
|
+
this.generators = generators;
|
|
719
|
+
this.aggregationMode = aggregationMode;
|
|
720
|
+
if (generators.length === 0) {
|
|
721
|
+
throw new Error("CompositeGenerator requires at least one generator");
|
|
722
|
+
}
|
|
723
|
+
logger.debug(
|
|
724
|
+
`[CompositeGenerator] Created with ${generators.length} generators, mode: ${aggregationMode}`
|
|
725
|
+
);
|
|
726
|
+
}
|
|
727
|
+
/**
|
|
728
|
+
* Creates a CompositeGenerator from strategy data.
|
|
729
|
+
*
|
|
730
|
+
* This is a convenience factory for use by PipelineAssembler.
|
|
731
|
+
*/
|
|
732
|
+
static async fromStrategies(user, course, strategies, aggregationMode = DEFAULT_AGGREGATION_MODE) {
|
|
733
|
+
const generators = await Promise.all(
|
|
734
|
+
strategies.map((s) => ContentNavigator.create(user, course, s))
|
|
735
|
+
);
|
|
736
|
+
return new _CompositeGenerator(generators, aggregationMode);
|
|
737
|
+
}
|
|
738
|
+
/**
|
|
739
|
+
* Get weighted cards from all generators, merge and deduplicate.
|
|
740
|
+
*
|
|
741
|
+
* Cards appearing in multiple generators receive a score boost.
|
|
742
|
+
* Provenance tracks which generators produced each card and how scores were aggregated.
|
|
743
|
+
*
|
|
744
|
+
* This method supports both the legacy signature (limit only) and the
|
|
745
|
+
* CardGenerator interface signature (limit, context).
|
|
746
|
+
*
|
|
747
|
+
* @param limit - Maximum number of cards to return
|
|
748
|
+
* @param context - Optional GeneratorContext passed to child generators
|
|
749
|
+
*/
|
|
750
|
+
async getWeightedCards(limit, context) {
|
|
751
|
+
const results = await Promise.all(
|
|
752
|
+
this.generators.map((g) => g.getWeightedCards(limit, context))
|
|
753
|
+
);
|
|
754
|
+
const byCardId = /* @__PURE__ */ new Map();
|
|
755
|
+
for (const cards of results) {
|
|
756
|
+
for (const card of cards) {
|
|
757
|
+
const existing = byCardId.get(card.cardId) || [];
|
|
758
|
+
existing.push(card);
|
|
759
|
+
byCardId.set(card.cardId, existing);
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
const merged = [];
|
|
763
|
+
for (const [, cards] of byCardId) {
|
|
764
|
+
const aggregatedScore = this.aggregateScores(cards);
|
|
765
|
+
const finalScore = Math.min(1, aggregatedScore);
|
|
766
|
+
const mergedProvenance = cards.flatMap((c) => c.provenance);
|
|
767
|
+
const initialScore = cards[0].score;
|
|
768
|
+
const action = finalScore > initialScore ? "boosted" : finalScore < initialScore ? "penalized" : "passed";
|
|
769
|
+
const reason = this.buildAggregationReason(cards, finalScore);
|
|
770
|
+
merged.push({
|
|
771
|
+
...cards[0],
|
|
772
|
+
score: finalScore,
|
|
773
|
+
provenance: [
|
|
774
|
+
...mergedProvenance,
|
|
775
|
+
{
|
|
776
|
+
strategy: "composite",
|
|
777
|
+
strategyName: "Composite Generator",
|
|
778
|
+
strategyId: "COMPOSITE_GENERATOR",
|
|
779
|
+
action,
|
|
780
|
+
score: finalScore,
|
|
781
|
+
reason
|
|
782
|
+
}
|
|
783
|
+
]
|
|
784
|
+
});
|
|
785
|
+
}
|
|
786
|
+
return merged.sort((a, b) => b.score - a.score).slice(0, limit);
|
|
787
|
+
}
|
|
788
|
+
/**
|
|
789
|
+
* Build human-readable reason for score aggregation.
|
|
790
|
+
*/
|
|
791
|
+
buildAggregationReason(cards, finalScore) {
|
|
792
|
+
const count = cards.length;
|
|
793
|
+
const scores = cards.map((c) => c.score.toFixed(2)).join(", ");
|
|
794
|
+
if (count === 1) {
|
|
795
|
+
return `Single generator, score ${finalScore.toFixed(2)}`;
|
|
796
|
+
}
|
|
797
|
+
const strategies = cards.map((c) => c.provenance[0]?.strategy || "unknown").join(", ");
|
|
798
|
+
switch (this.aggregationMode) {
|
|
799
|
+
case "max" /* MAX */:
|
|
800
|
+
return `Max of ${count} generators (${strategies}): scores [${scores}] \u2192 ${finalScore.toFixed(2)}`;
|
|
801
|
+
case "average" /* AVERAGE */:
|
|
802
|
+
return `Average of ${count} generators (${strategies}): scores [${scores}] \u2192 ${finalScore.toFixed(2)}`;
|
|
803
|
+
case "frequencyBoost" /* FREQUENCY_BOOST */: {
|
|
804
|
+
const avg = cards.reduce((sum, c) => sum + c.score, 0) / count;
|
|
805
|
+
const boost = 1 + FREQUENCY_BOOST_FACTOR * (count - 1);
|
|
806
|
+
return `Frequency boost from ${count} generators (${strategies}): avg ${avg.toFixed(2)} \xD7 ${boost.toFixed(2)} \u2192 ${finalScore.toFixed(2)}`;
|
|
807
|
+
}
|
|
808
|
+
default:
|
|
809
|
+
return `Aggregated from ${count} generators: ${finalScore.toFixed(2)}`;
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
/**
|
|
813
|
+
* Aggregate scores from multiple generators for the same card.
|
|
814
|
+
*/
|
|
815
|
+
aggregateScores(cards) {
|
|
816
|
+
const scores = cards.map((c) => c.score);
|
|
817
|
+
switch (this.aggregationMode) {
|
|
818
|
+
case "max" /* MAX */:
|
|
819
|
+
return Math.max(...scores);
|
|
820
|
+
case "average" /* AVERAGE */:
|
|
821
|
+
return scores.reduce((sum, s) => sum + s, 0) / scores.length;
|
|
822
|
+
case "frequencyBoost" /* FREQUENCY_BOOST */: {
|
|
823
|
+
const avg = scores.reduce((sum, s) => sum + s, 0) / scores.length;
|
|
824
|
+
const frequencyBoost = 1 + FREQUENCY_BOOST_FACTOR * (cards.length - 1);
|
|
825
|
+
return avg * frequencyBoost;
|
|
826
|
+
}
|
|
827
|
+
default:
|
|
828
|
+
return scores[0];
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
/**
|
|
832
|
+
* Get new cards from all generators, merged and deduplicated.
|
|
833
|
+
*/
|
|
834
|
+
async getNewCards(n) {
|
|
835
|
+
const legacyGenerators = this.generators.filter(
|
|
836
|
+
(g) => g instanceof ContentNavigator
|
|
837
|
+
);
|
|
838
|
+
const results = await Promise.all(legacyGenerators.map((g) => g.getNewCards(n)));
|
|
839
|
+
const seen = /* @__PURE__ */ new Set();
|
|
840
|
+
const merged = [];
|
|
841
|
+
for (const cards of results) {
|
|
842
|
+
for (const card of cards) {
|
|
843
|
+
if (!seen.has(card.cardID)) {
|
|
844
|
+
seen.add(card.cardID);
|
|
845
|
+
merged.push(card);
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
return n ? merged.slice(0, n) : merged;
|
|
850
|
+
}
|
|
851
|
+
/**
|
|
852
|
+
* Get pending reviews from all generators, merged and deduplicated.
|
|
853
|
+
*/
|
|
854
|
+
async getPendingReviews() {
|
|
855
|
+
const legacyGenerators = this.generators.filter(
|
|
856
|
+
(g) => g instanceof ContentNavigator
|
|
857
|
+
);
|
|
858
|
+
const results = await Promise.all(legacyGenerators.map((g) => g.getPendingReviews()));
|
|
859
|
+
const seen = /* @__PURE__ */ new Set();
|
|
860
|
+
const merged = [];
|
|
861
|
+
for (const reviews of results) {
|
|
862
|
+
for (const review of reviews) {
|
|
863
|
+
if (!seen.has(review.cardID)) {
|
|
864
|
+
seen.add(review.cardID);
|
|
865
|
+
merged.push(review);
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
return merged;
|
|
870
|
+
}
|
|
871
|
+
};
|
|
872
|
+
}
|
|
873
|
+
});
|
|
874
|
+
|
|
875
|
+
// src/core/navigators/Pipeline.ts
|
|
876
|
+
var Pipeline_exports = {};
|
|
877
|
+
__export(Pipeline_exports, {
|
|
878
|
+
Pipeline: () => Pipeline
|
|
879
|
+
});
|
|
880
|
+
import { toCourseElo as toCourseElo2 } from "@vue-skuilder/common";
|
|
881
|
+
function logPipelineConfig(generator, filters) {
|
|
882
|
+
const filterList = filters.length > 0 ? "\n - " + filters.map((f) => f.name).join("\n - ") : " none";
|
|
883
|
+
logger.info(
|
|
884
|
+
`[Pipeline] Configuration:
|
|
885
|
+
Generator: ${generator.name}
|
|
886
|
+
Filters:${filterList}`
|
|
887
|
+
);
|
|
888
|
+
}
|
|
889
|
+
function logTagHydration(cards, tagsByCard) {
|
|
890
|
+
const totalTags = Array.from(tagsByCard.values()).reduce((sum, tags) => sum + tags.length, 0);
|
|
891
|
+
const cardsWithTags = Array.from(tagsByCard.values()).filter((tags) => tags.length > 0).length;
|
|
892
|
+
logger.debug(
|
|
893
|
+
`[Pipeline] Tag hydration: ${cards.length} cards, ${cardsWithTags} have tags (${totalTags} total tags) - single batch query`
|
|
894
|
+
);
|
|
895
|
+
}
|
|
896
|
+
function logExecutionSummary(generatorName, generatedCount, filterCount, finalCount, topScores) {
|
|
897
|
+
const scoreDisplay = topScores.length > 0 ? topScores.map((s) => s.toFixed(2)).join(", ") : "none";
|
|
898
|
+
logger.info(
|
|
899
|
+
`[Pipeline] Execution: ${generatorName} produced ${generatedCount} \u2192 ${filterCount} filters \u2192 ${finalCount} results (top scores: ${scoreDisplay})`
|
|
900
|
+
);
|
|
901
|
+
}
|
|
902
|
+
function logCardProvenance(cards, maxCards = 3) {
|
|
903
|
+
const cardsToLog = cards.slice(0, maxCards);
|
|
904
|
+
logger.debug(`[Pipeline] Provenance for top ${cardsToLog.length} cards:`);
|
|
905
|
+
for (const card of cardsToLog) {
|
|
906
|
+
logger.debug(`[Pipeline] ${card.cardId} (final score: ${card.score.toFixed(3)}):`);
|
|
907
|
+
for (const entry of card.provenance) {
|
|
908
|
+
const scoreChange = entry.score.toFixed(3);
|
|
909
|
+
const action = entry.action.padEnd(9);
|
|
910
|
+
logger.debug(
|
|
911
|
+
`[Pipeline] ${action} ${scoreChange} - ${entry.strategyName}: ${entry.reason}`
|
|
912
|
+
);
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
var Pipeline;
|
|
917
|
+
var init_Pipeline = __esm({
|
|
918
|
+
"src/core/navigators/Pipeline.ts"() {
|
|
919
|
+
"use strict";
|
|
920
|
+
init_navigators();
|
|
921
|
+
init_logger();
|
|
922
|
+
Pipeline = class extends ContentNavigator {
|
|
923
|
+
generator;
|
|
924
|
+
filters;
|
|
925
|
+
/**
|
|
926
|
+
* Create a new pipeline.
|
|
927
|
+
*
|
|
928
|
+
* @param generator - The generator (or CompositeGenerator) that produces candidates
|
|
929
|
+
* @param filters - Filters to apply sequentially (order doesn't matter for multipliers)
|
|
930
|
+
* @param user - User database interface
|
|
931
|
+
* @param course - Course database interface
|
|
932
|
+
*/
|
|
933
|
+
constructor(generator, filters, user, course) {
|
|
934
|
+
super();
|
|
935
|
+
this.generator = generator;
|
|
936
|
+
this.filters = filters;
|
|
937
|
+
this.user = user;
|
|
938
|
+
this.course = course;
|
|
939
|
+
logPipelineConfig(generator, filters);
|
|
940
|
+
}
|
|
941
|
+
/**
|
|
942
|
+
* Get weighted cards by running generator and applying filters.
|
|
943
|
+
*
|
|
944
|
+
* 1. Build shared context (user ELO, etc.)
|
|
945
|
+
* 2. Get candidates from generator (passing context)
|
|
946
|
+
* 3. Batch hydrate tags for all candidates
|
|
947
|
+
* 4. Apply each filter sequentially
|
|
948
|
+
* 5. Remove zero-score cards
|
|
949
|
+
* 6. Sort by score descending
|
|
950
|
+
* 7. Return top N
|
|
951
|
+
*
|
|
952
|
+
* @param limit - Maximum number of cards to return
|
|
953
|
+
* @returns Cards sorted by score descending
|
|
954
|
+
*/
|
|
955
|
+
async getWeightedCards(limit) {
|
|
956
|
+
const context = await this.buildContext();
|
|
957
|
+
const overFetchMultiplier = 2 + this.filters.length * 0.5;
|
|
958
|
+
const fetchLimit = Math.ceil(limit * overFetchMultiplier);
|
|
959
|
+
logger.debug(
|
|
960
|
+
`[Pipeline] Fetching ${fetchLimit} candidates from generator '${this.generator.name}'`
|
|
961
|
+
);
|
|
962
|
+
let cards = await this.generator.getWeightedCards(fetchLimit, context);
|
|
963
|
+
const generatedCount = cards.length;
|
|
964
|
+
logger.debug(`[Pipeline] Generator returned ${generatedCount} candidates`);
|
|
965
|
+
cards = await this.hydrateTags(cards);
|
|
966
|
+
for (const filter of this.filters) {
|
|
967
|
+
const beforeCount = cards.length;
|
|
968
|
+
cards = await filter.transform(cards, context);
|
|
969
|
+
logger.debug(`[Pipeline] Filter '${filter.name}': ${beforeCount} \u2192 ${cards.length} cards`);
|
|
970
|
+
}
|
|
971
|
+
cards = cards.filter((c) => c.score > 0);
|
|
972
|
+
cards.sort((a, b) => b.score - a.score);
|
|
973
|
+
const result = cards.slice(0, limit);
|
|
974
|
+
const topScores = result.slice(0, 3).map((c) => c.score);
|
|
975
|
+
logExecutionSummary(this.generator.name, generatedCount, this.filters.length, result.length, topScores);
|
|
976
|
+
logCardProvenance(result, 3);
|
|
977
|
+
return result;
|
|
978
|
+
}
|
|
979
|
+
/**
|
|
980
|
+
* Batch hydrate tags for all cards.
|
|
981
|
+
*
|
|
982
|
+
* Fetches tags for all cards in a single database query and attaches them
|
|
983
|
+
* to the WeightedCard objects. Filters can then use card.tags instead of
|
|
984
|
+
* making individual getAppliedTags() calls.
|
|
985
|
+
*
|
|
986
|
+
* @param cards - Cards to hydrate
|
|
987
|
+
* @returns Cards with tags populated
|
|
988
|
+
*/
|
|
989
|
+
async hydrateTags(cards) {
|
|
990
|
+
if (cards.length === 0) {
|
|
991
|
+
return cards;
|
|
992
|
+
}
|
|
993
|
+
const cardIds = cards.map((c) => c.cardId);
|
|
994
|
+
const tagsByCard = await this.course.getAppliedTagsBatch(cardIds);
|
|
995
|
+
logTagHydration(cards, tagsByCard);
|
|
996
|
+
return cards.map((card) => ({
|
|
997
|
+
...card,
|
|
998
|
+
tags: tagsByCard.get(card.cardId) ?? []
|
|
999
|
+
}));
|
|
1000
|
+
}
|
|
1001
|
+
/**
|
|
1002
|
+
* Build shared context for generator and filters.
|
|
1003
|
+
*
|
|
1004
|
+
* Called once per getWeightedCards() invocation.
|
|
1005
|
+
* Contains data that the generator and multiple filters might need.
|
|
1006
|
+
*
|
|
1007
|
+
* The context satisfies both GeneratorContext and FilterContext interfaces.
|
|
1008
|
+
*/
|
|
1009
|
+
async buildContext() {
|
|
1010
|
+
let userElo = 1e3;
|
|
1011
|
+
try {
|
|
1012
|
+
const courseReg = await this.user.getCourseRegDoc(this.course.getCourseID());
|
|
1013
|
+
const courseElo = toCourseElo2(courseReg.elo);
|
|
1014
|
+
userElo = courseElo.global.score;
|
|
1015
|
+
} catch (e) {
|
|
1016
|
+
logger.debug(`[Pipeline] Could not get user ELO, using default: ${e}`);
|
|
1017
|
+
}
|
|
1018
|
+
return {
|
|
1019
|
+
user: this.user,
|
|
1020
|
+
course: this.course,
|
|
1021
|
+
userElo
|
|
1022
|
+
};
|
|
1023
|
+
}
|
|
1024
|
+
// ===========================================================================
|
|
1025
|
+
// Legacy StudyContentSource methods
|
|
1026
|
+
// ===========================================================================
|
|
1027
|
+
//
|
|
1028
|
+
// These delegate to the generator for backward compatibility.
|
|
1029
|
+
// Eventually SessionController will use getWeightedCards() exclusively.
|
|
1030
|
+
//
|
|
1031
|
+
/**
|
|
1032
|
+
* Get new cards via legacy API.
|
|
1033
|
+
* Delegates to the generator if it supports the legacy interface.
|
|
1034
|
+
*/
|
|
1035
|
+
async getNewCards(n) {
|
|
1036
|
+
if ("getNewCards" in this.generator && typeof this.generator.getNewCards === "function") {
|
|
1037
|
+
return this.generator.getNewCards(n);
|
|
1038
|
+
}
|
|
1039
|
+
return [];
|
|
1040
|
+
}
|
|
1041
|
+
/**
|
|
1042
|
+
* Get pending reviews via legacy API.
|
|
1043
|
+
* Delegates to the generator if it supports the legacy interface.
|
|
1044
|
+
*/
|
|
1045
|
+
async getPendingReviews() {
|
|
1046
|
+
if ("getPendingReviews" in this.generator && typeof this.generator.getPendingReviews === "function") {
|
|
1047
|
+
return this.generator.getPendingReviews();
|
|
1048
|
+
}
|
|
1049
|
+
return [];
|
|
1050
|
+
}
|
|
1051
|
+
/**
|
|
1052
|
+
* Get the course ID for this pipeline.
|
|
1053
|
+
*/
|
|
1054
|
+
getCourseID() {
|
|
1055
|
+
return this.course.getCourseID();
|
|
1056
|
+
}
|
|
1057
|
+
};
|
|
1058
|
+
}
|
|
1059
|
+
});
|
|
1060
|
+
|
|
1061
|
+
// src/core/navigators/PipelineAssembler.ts
|
|
1062
|
+
var PipelineAssembler_exports = {};
|
|
1063
|
+
__export(PipelineAssembler_exports, {
|
|
1064
|
+
PipelineAssembler: () => PipelineAssembler
|
|
1065
|
+
});
|
|
1066
|
+
var PipelineAssembler;
|
|
1067
|
+
var init_PipelineAssembler = __esm({
|
|
1068
|
+
"src/core/navigators/PipelineAssembler.ts"() {
|
|
1069
|
+
"use strict";
|
|
1070
|
+
init_navigators();
|
|
1071
|
+
init_Pipeline();
|
|
1072
|
+
init_types_legacy();
|
|
1073
|
+
init_logger();
|
|
1074
|
+
init_CompositeGenerator();
|
|
1075
|
+
PipelineAssembler = class {
|
|
1076
|
+
/**
|
|
1077
|
+
* Assembles a navigation pipeline from strategy documents.
|
|
1078
|
+
*
|
|
1079
|
+
* 1. Separates into generators and filters by role
|
|
1080
|
+
* 2. Validates at least one generator exists (or creates default ELO)
|
|
1081
|
+
* 3. Instantiates generators - wraps multiple in CompositeGenerator
|
|
1082
|
+
* 4. Instantiates filters
|
|
1083
|
+
* 5. Returns Pipeline(generator, filters)
|
|
1084
|
+
*
|
|
1085
|
+
* @param input - Strategy documents plus user/course interfaces
|
|
1086
|
+
* @returns Assembled pipeline and any warnings
|
|
1087
|
+
*/
|
|
1088
|
+
async assemble(input) {
|
|
1089
|
+
const { strategies, user, course } = input;
|
|
1090
|
+
const warnings = [];
|
|
1091
|
+
if (strategies.length === 0) {
|
|
1092
|
+
return {
|
|
1093
|
+
pipeline: null,
|
|
1094
|
+
generatorStrategies: [],
|
|
1095
|
+
filterStrategies: [],
|
|
1096
|
+
warnings
|
|
1097
|
+
};
|
|
1098
|
+
}
|
|
1099
|
+
const generatorStrategies = [];
|
|
1100
|
+
const filterStrategies = [];
|
|
1101
|
+
for (const s of strategies) {
|
|
1102
|
+
if (isGenerator(s.implementingClass)) {
|
|
1103
|
+
generatorStrategies.push(s);
|
|
1104
|
+
} else if (isFilter(s.implementingClass)) {
|
|
1105
|
+
filterStrategies.push(s);
|
|
1106
|
+
} else {
|
|
1107
|
+
warnings.push(`Unknown strategy type '${s.implementingClass}', skipping: ${s.name}`);
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
if (generatorStrategies.length === 0) {
|
|
1111
|
+
if (filterStrategies.length > 0) {
|
|
1112
|
+
logger.debug(
|
|
1113
|
+
"[PipelineAssembler] No generator found, using default ELO with configured filters"
|
|
1114
|
+
);
|
|
1115
|
+
generatorStrategies.push(this.makeDefaultEloStrategy(course.getCourseID()));
|
|
1116
|
+
} else {
|
|
1117
|
+
warnings.push("No generator strategy found");
|
|
1118
|
+
return {
|
|
1119
|
+
pipeline: null,
|
|
1120
|
+
generatorStrategies: [],
|
|
1121
|
+
filterStrategies: [],
|
|
1122
|
+
warnings
|
|
1123
|
+
};
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
let generator;
|
|
1127
|
+
if (generatorStrategies.length === 1) {
|
|
1128
|
+
const nav = await ContentNavigator.create(user, course, generatorStrategies[0]);
|
|
1129
|
+
generator = nav;
|
|
1130
|
+
logger.debug(`[PipelineAssembler] Using single generator: ${generatorStrategies[0].name}`);
|
|
1131
|
+
} else {
|
|
1132
|
+
logger.debug(
|
|
1133
|
+
`[PipelineAssembler] Using CompositeGenerator for ${generatorStrategies.length} generators: ${generatorStrategies.map((g) => g.name).join(", ")}`
|
|
1134
|
+
);
|
|
1135
|
+
generator = await CompositeGenerator.fromStrategies(user, course, generatorStrategies);
|
|
1136
|
+
}
|
|
1137
|
+
const filters = [];
|
|
1138
|
+
const sortedFilterStrategies = [...filterStrategies].sort(
|
|
1139
|
+
(a, b) => a.name.localeCompare(b.name)
|
|
1140
|
+
);
|
|
1141
|
+
for (const filterStrategy of sortedFilterStrategies) {
|
|
1142
|
+
try {
|
|
1143
|
+
const nav = await ContentNavigator.create(user, course, filterStrategy);
|
|
1144
|
+
if ("transform" in nav && typeof nav.transform === "function") {
|
|
1145
|
+
filters.push(nav);
|
|
1146
|
+
logger.debug(`[PipelineAssembler] Added filter: ${filterStrategy.name}`);
|
|
1147
|
+
} else {
|
|
1148
|
+
warnings.push(
|
|
1149
|
+
`Filter '${filterStrategy.name}' does not implement CardFilter.transform(), skipping`
|
|
1150
|
+
);
|
|
1151
|
+
}
|
|
1152
|
+
} catch (e) {
|
|
1153
|
+
warnings.push(`Failed to instantiate filter '${filterStrategy.name}': ${e}`);
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
const pipeline = new Pipeline(generator, filters, user, course);
|
|
1157
|
+
logger.debug(
|
|
1158
|
+
`[PipelineAssembler] Assembled pipeline with ${generatorStrategies.length} generator(s) and ${filters.length} filter(s)`
|
|
1159
|
+
);
|
|
1160
|
+
return {
|
|
1161
|
+
pipeline,
|
|
1162
|
+
generatorStrategies,
|
|
1163
|
+
filterStrategies: sortedFilterStrategies,
|
|
1164
|
+
warnings
|
|
1165
|
+
};
|
|
1166
|
+
}
|
|
1167
|
+
/**
|
|
1168
|
+
* Creates a default ELO generator strategy.
|
|
1169
|
+
* Used when filters are configured but no generator is specified.
|
|
1170
|
+
*/
|
|
1171
|
+
makeDefaultEloStrategy(courseId) {
|
|
1172
|
+
return {
|
|
1173
|
+
_id: "NAVIGATION_STRATEGY-ELO-default",
|
|
1174
|
+
course: courseId,
|
|
1175
|
+
docType: "NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */,
|
|
1176
|
+
name: "ELO (default)",
|
|
1177
|
+
description: "Default ELO-based generator",
|
|
1178
|
+
implementingClass: "elo" /* ELO */,
|
|
1179
|
+
serializedData: ""
|
|
1180
|
+
};
|
|
1181
|
+
}
|
|
1182
|
+
};
|
|
1183
|
+
}
|
|
1184
|
+
});
|
|
1185
|
+
|
|
689
1186
|
// src/core/navigators/elo.ts
|
|
690
1187
|
var elo_exports = {};
|
|
691
1188
|
__export(elo_exports, {
|
|
692
1189
|
default: () => ELONavigator
|
|
693
1190
|
});
|
|
1191
|
+
import { toCourseElo as toCourseElo3 } from "@vue-skuilder/common";
|
|
694
1192
|
var ELONavigator;
|
|
695
1193
|
var init_elo = __esm({
|
|
696
1194
|
"src/core/navigators/elo.ts"() {
|
|
697
1195
|
"use strict";
|
|
698
1196
|
init_navigators();
|
|
699
1197
|
ELONavigator = class extends ContentNavigator {
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
constructor(user, course) {
|
|
703
|
-
super();
|
|
704
|
-
this.
|
|
705
|
-
this.course = course;
|
|
1198
|
+
/** Human-readable name for CardGenerator interface */
|
|
1199
|
+
name;
|
|
1200
|
+
constructor(user, course, strategyData) {
|
|
1201
|
+
super(user, course, strategyData);
|
|
1202
|
+
this.name = strategyData?.name || "ELO";
|
|
706
1203
|
}
|
|
707
1204
|
async getPendingReviews() {
|
|
708
1205
|
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
@@ -748,79 +1245,1125 @@ var init_elo = __esm({
|
|
|
748
1245
|
};
|
|
749
1246
|
});
|
|
750
1247
|
}
|
|
1248
|
+
/**
|
|
1249
|
+
* Get new cards with suitability scores based on ELO distance.
|
|
1250
|
+
*
|
|
1251
|
+
* Cards closer to user's ELO get higher scores.
|
|
1252
|
+
* Score formula: max(0, 1 - distance / 500)
|
|
1253
|
+
*
|
|
1254
|
+
* NOTE: This generator only handles NEW cards. Reviews are handled by
|
|
1255
|
+
* SRSNavigator. Use CompositeGenerator to combine both.
|
|
1256
|
+
*
|
|
1257
|
+
* This method supports both the legacy signature (limit only) and the
|
|
1258
|
+
* CardGenerator interface signature (limit, context).
|
|
1259
|
+
*
|
|
1260
|
+
* @param limit - Maximum number of cards to return
|
|
1261
|
+
* @param context - Optional GeneratorContext (used when called via Pipeline)
|
|
1262
|
+
*/
|
|
1263
|
+
async getWeightedCards(limit, context) {
|
|
1264
|
+
let userGlobalElo;
|
|
1265
|
+
if (context?.userElo !== void 0) {
|
|
1266
|
+
userGlobalElo = context.userElo;
|
|
1267
|
+
} else {
|
|
1268
|
+
const courseReg = await this.user.getCourseRegDoc(this.course.getCourseID());
|
|
1269
|
+
const userElo = toCourseElo3(courseReg.elo);
|
|
1270
|
+
userGlobalElo = userElo.global.score;
|
|
1271
|
+
}
|
|
1272
|
+
const newCards = await this.getNewCards(limit);
|
|
1273
|
+
const cardIds = newCards.map((c) => c.cardID);
|
|
1274
|
+
const cardEloData = await this.course.getCardEloData(cardIds);
|
|
1275
|
+
const scored = newCards.map((c, i) => {
|
|
1276
|
+
const cardElo = cardEloData[i]?.global?.score ?? 1e3;
|
|
1277
|
+
const distance = Math.abs(cardElo - userGlobalElo);
|
|
1278
|
+
const score = Math.max(0, 1 - distance / 500);
|
|
1279
|
+
return {
|
|
1280
|
+
cardId: c.cardID,
|
|
1281
|
+
courseId: c.courseID,
|
|
1282
|
+
score,
|
|
1283
|
+
provenance: [
|
|
1284
|
+
{
|
|
1285
|
+
strategy: "elo",
|
|
1286
|
+
strategyName: this.strategyName || this.name,
|
|
1287
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-ELO-default",
|
|
1288
|
+
action: "generated",
|
|
1289
|
+
score,
|
|
1290
|
+
reason: `ELO distance ${Math.round(distance)} (card: ${Math.round(cardElo)}, user: ${Math.round(userGlobalElo)}), new card`
|
|
1291
|
+
}
|
|
1292
|
+
]
|
|
1293
|
+
};
|
|
1294
|
+
});
|
|
1295
|
+
scored.sort((a, b) => b.score - a.score);
|
|
1296
|
+
return scored.slice(0, limit);
|
|
1297
|
+
}
|
|
751
1298
|
};
|
|
752
1299
|
}
|
|
753
1300
|
});
|
|
754
1301
|
|
|
755
|
-
// src/core/navigators/
|
|
756
|
-
var
|
|
757
|
-
__export(
|
|
758
|
-
|
|
1302
|
+
// src/core/navigators/filters/eloDistance.ts
|
|
1303
|
+
var eloDistance_exports = {};
|
|
1304
|
+
__export(eloDistance_exports, {
|
|
1305
|
+
DEFAULT_HALF_LIFE: () => DEFAULT_HALF_LIFE,
|
|
1306
|
+
DEFAULT_MAX_MULTIPLIER: () => DEFAULT_MAX_MULTIPLIER,
|
|
1307
|
+
DEFAULT_MIN_MULTIPLIER: () => DEFAULT_MIN_MULTIPLIER,
|
|
1308
|
+
createEloDistanceFilter: () => createEloDistanceFilter
|
|
759
1309
|
});
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
1310
|
+
function computeMultiplier(distance, halfLife, minMultiplier, maxMultiplier) {
|
|
1311
|
+
const normalizedDistance = distance / halfLife;
|
|
1312
|
+
const decay = Math.exp(-(normalizedDistance * normalizedDistance));
|
|
1313
|
+
return minMultiplier + (maxMultiplier - minMultiplier) * decay;
|
|
1314
|
+
}
|
|
1315
|
+
function createEloDistanceFilter(config) {
|
|
1316
|
+
const halfLife = config?.halfLife ?? DEFAULT_HALF_LIFE;
|
|
1317
|
+
const minMultiplier = config?.minMultiplier ?? DEFAULT_MIN_MULTIPLIER;
|
|
1318
|
+
const maxMultiplier = config?.maxMultiplier ?? DEFAULT_MAX_MULTIPLIER;
|
|
1319
|
+
return {
|
|
1320
|
+
name: "ELO Distance Filter",
|
|
1321
|
+
async transform(cards, context) {
|
|
1322
|
+
const { course, userElo } = context;
|
|
1323
|
+
const cardIds = cards.map((c) => c.cardId);
|
|
1324
|
+
const cardElos = await course.getCardEloData(cardIds);
|
|
1325
|
+
return cards.map((card, i) => {
|
|
1326
|
+
const cardElo = cardElos[i]?.global?.score ?? 1e3;
|
|
1327
|
+
const distance = Math.abs(cardElo - userElo);
|
|
1328
|
+
const multiplier = computeMultiplier(distance, halfLife, minMultiplier, maxMultiplier);
|
|
1329
|
+
const newScore = card.score * multiplier;
|
|
1330
|
+
const action = multiplier < maxMultiplier - 0.01 ? "penalized" : "passed";
|
|
1331
|
+
return {
|
|
1332
|
+
...card,
|
|
1333
|
+
score: newScore,
|
|
1334
|
+
provenance: [
|
|
1335
|
+
...card.provenance,
|
|
1336
|
+
{
|
|
1337
|
+
strategy: "eloDistance",
|
|
1338
|
+
strategyName: "ELO Distance Filter",
|
|
1339
|
+
strategyId: "ELO_DISTANCE_FILTER",
|
|
1340
|
+
action,
|
|
1341
|
+
score: newScore,
|
|
1342
|
+
reason: `ELO distance ${Math.round(distance)} (card: ${Math.round(cardElo)}, user: ${Math.round(userElo)}) \u2192 ${multiplier.toFixed(2)}x`
|
|
1343
|
+
}
|
|
1344
|
+
]
|
|
1345
|
+
};
|
|
1346
|
+
});
|
|
1347
|
+
}
|
|
1348
|
+
};
|
|
1349
|
+
}
|
|
1350
|
+
var DEFAULT_HALF_LIFE, DEFAULT_MIN_MULTIPLIER, DEFAULT_MAX_MULTIPLIER;
|
|
1351
|
+
var init_eloDistance = __esm({
|
|
1352
|
+
"src/core/navigators/filters/eloDistance.ts"() {
|
|
1353
|
+
"use strict";
|
|
1354
|
+
DEFAULT_HALF_LIFE = 200;
|
|
1355
|
+
DEFAULT_MIN_MULTIPLIER = 0.3;
|
|
1356
|
+
DEFAULT_MAX_MULTIPLIER = 1;
|
|
1357
|
+
}
|
|
1358
|
+
});
|
|
1359
|
+
|
|
1360
|
+
// src/core/navigators/filters/userTagPreference.ts
|
|
1361
|
+
var userTagPreference_exports = {};
|
|
1362
|
+
__export(userTagPreference_exports, {
|
|
1363
|
+
default: () => UserTagPreferenceFilter
|
|
1364
|
+
});
|
|
1365
|
+
var UserTagPreferenceFilter;
|
|
1366
|
+
var init_userTagPreference = __esm({
|
|
1367
|
+
"src/core/navigators/filters/userTagPreference.ts"() {
|
|
763
1368
|
"use strict";
|
|
764
1369
|
init_navigators();
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
course;
|
|
1370
|
+
UserTagPreferenceFilter = class extends ContentNavigator {
|
|
1371
|
+
_strategyData;
|
|
1372
|
+
/** Human-readable name for CardFilter interface */
|
|
1373
|
+
name;
|
|
770
1374
|
constructor(user, course, strategyData) {
|
|
771
|
-
super();
|
|
772
|
-
this.
|
|
773
|
-
this.
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
1375
|
+
super(user, course, strategyData);
|
|
1376
|
+
this._strategyData = strategyData;
|
|
1377
|
+
this.name = strategyData.name || "User Tag Preferences";
|
|
1378
|
+
}
|
|
1379
|
+
/**
|
|
1380
|
+
* Compute multiplier for a card based on its tags and user preferences.
|
|
1381
|
+
* Returns the maximum multiplier among all matching tags, or 1.0 if no matches.
|
|
1382
|
+
*/
|
|
1383
|
+
computeMultiplier(cardTags, boostMap) {
|
|
1384
|
+
const multipliers = cardTags.map((tag) => boostMap[tag]).filter((val) => val !== void 0);
|
|
1385
|
+
if (multipliers.length === 0) {
|
|
1386
|
+
return 1;
|
|
1387
|
+
}
|
|
1388
|
+
return Math.max(...multipliers);
|
|
1389
|
+
}
|
|
1390
|
+
/**
|
|
1391
|
+
* Build human-readable reason for the filter's decision.
|
|
1392
|
+
*/
|
|
1393
|
+
buildReason(cardTags, boostMap, multiplier) {
|
|
1394
|
+
const matchingTags = cardTags.filter((tag) => boostMap[tag] === multiplier);
|
|
1395
|
+
if (multiplier === 0) {
|
|
1396
|
+
return `Excluded by user preference: ${matchingTags.join(", ")} (${multiplier}x)`;
|
|
1397
|
+
}
|
|
1398
|
+
if (multiplier < 1) {
|
|
1399
|
+
return `Penalized by user preference: ${matchingTags.join(", ")} (${multiplier.toFixed(2)}x)`;
|
|
1400
|
+
}
|
|
1401
|
+
if (multiplier > 1) {
|
|
1402
|
+
return `Boosted by user preference: ${matchingTags.join(", ")} (${multiplier.toFixed(2)}x)`;
|
|
1403
|
+
}
|
|
1404
|
+
return "No matching user preferences";
|
|
1405
|
+
}
|
|
1406
|
+
/**
|
|
1407
|
+
* CardFilter.transform implementation.
|
|
1408
|
+
*
|
|
1409
|
+
* Apply user tag preferences:
|
|
1410
|
+
* 1. Read preferences from strategy state
|
|
1411
|
+
* 2. If no preferences, pass through unchanged
|
|
1412
|
+
* 3. For each card:
|
|
1413
|
+
* - Look up tag in boost record
|
|
1414
|
+
* - If tag found: apply multiplier (0 = exclude, 1 = neutral, >1 = boost)
|
|
1415
|
+
* - If multiple tags match: use max multiplier
|
|
1416
|
+
* - Append provenance with clear reason
|
|
1417
|
+
*/
|
|
1418
|
+
async transform(cards, _context) {
|
|
1419
|
+
const prefs = await this.getStrategyState();
|
|
1420
|
+
if (!prefs || Object.keys(prefs.boost).length === 0) {
|
|
1421
|
+
return cards.map((card) => ({
|
|
1422
|
+
...card,
|
|
1423
|
+
provenance: [
|
|
1424
|
+
...card.provenance,
|
|
1425
|
+
{
|
|
1426
|
+
strategy: "userTagPreference",
|
|
1427
|
+
strategyName: this.strategyName || this.name,
|
|
1428
|
+
strategyId: this.strategyId || this._strategyData._id,
|
|
1429
|
+
action: "passed",
|
|
1430
|
+
score: card.score,
|
|
1431
|
+
reason: "No user tag preferences configured"
|
|
1432
|
+
}
|
|
1433
|
+
]
|
|
1434
|
+
}));
|
|
1435
|
+
}
|
|
1436
|
+
const adjusted = await Promise.all(
|
|
1437
|
+
cards.map(async (card) => {
|
|
1438
|
+
const cardTags = card.tags ?? [];
|
|
1439
|
+
const multiplier = this.computeMultiplier(cardTags, prefs.boost);
|
|
1440
|
+
const finalScore = Math.min(1, card.score * multiplier);
|
|
1441
|
+
let action;
|
|
1442
|
+
if (multiplier === 0 || multiplier < 1) {
|
|
1443
|
+
action = "penalized";
|
|
1444
|
+
} else if (multiplier > 1) {
|
|
1445
|
+
action = "boosted";
|
|
1446
|
+
} else {
|
|
1447
|
+
action = "passed";
|
|
1448
|
+
}
|
|
1449
|
+
return {
|
|
1450
|
+
...card,
|
|
1451
|
+
score: finalScore,
|
|
1452
|
+
provenance: [
|
|
1453
|
+
...card.provenance,
|
|
1454
|
+
{
|
|
1455
|
+
strategy: "userTagPreference",
|
|
1456
|
+
strategyName: this.strategyName || this.name,
|
|
1457
|
+
strategyId: this.strategyId || this._strategyData._id,
|
|
1458
|
+
action,
|
|
1459
|
+
score: finalScore,
|
|
1460
|
+
reason: this.buildReason(cardTags, prefs.boost, multiplier)
|
|
1461
|
+
}
|
|
1462
|
+
]
|
|
1463
|
+
};
|
|
1464
|
+
})
|
|
1465
|
+
);
|
|
1466
|
+
return adjusted;
|
|
1467
|
+
}
|
|
1468
|
+
/**
|
|
1469
|
+
* Legacy getWeightedCards - throws as filters should not be used as generators.
|
|
1470
|
+
*/
|
|
1471
|
+
async getWeightedCards(_limit) {
|
|
1472
|
+
throw new Error(
|
|
1473
|
+
"UserTagPreferenceFilter is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
|
|
1474
|
+
);
|
|
1475
|
+
}
|
|
1476
|
+
// Legacy methods - stub implementations since filters don't generate cards
|
|
1477
|
+
async getNewCards(_n) {
|
|
1478
|
+
return [];
|
|
1479
|
+
}
|
|
1480
|
+
async getPendingReviews() {
|
|
1481
|
+
return [];
|
|
1482
|
+
}
|
|
1483
|
+
};
|
|
1484
|
+
}
|
|
1485
|
+
});
|
|
1486
|
+
|
|
1487
|
+
// src/core/navigators/filters/index.ts
|
|
1488
|
+
var filters_exports = {};
|
|
1489
|
+
__export(filters_exports, {
|
|
1490
|
+
UserTagPreferenceFilter: () => UserTagPreferenceFilter,
|
|
1491
|
+
createEloDistanceFilter: () => createEloDistanceFilter
|
|
1492
|
+
});
|
|
1493
|
+
var init_filters = __esm({
|
|
1494
|
+
"src/core/navigators/filters/index.ts"() {
|
|
1495
|
+
"use strict";
|
|
1496
|
+
init_eloDistance();
|
|
1497
|
+
init_userTagPreference();
|
|
1498
|
+
}
|
|
1499
|
+
});
|
|
1500
|
+
|
|
1501
|
+
// src/core/navigators/filters/types.ts
|
|
1502
|
+
var types_exports = {};
|
|
1503
|
+
var init_types = __esm({
|
|
1504
|
+
"src/core/navigators/filters/types.ts"() {
|
|
1505
|
+
"use strict";
|
|
1506
|
+
}
|
|
1507
|
+
});
|
|
1508
|
+
|
|
1509
|
+
// src/core/navigators/generators/index.ts
|
|
1510
|
+
var generators_exports = {};
|
|
1511
|
+
var init_generators = __esm({
|
|
1512
|
+
"src/core/navigators/generators/index.ts"() {
|
|
1513
|
+
"use strict";
|
|
1514
|
+
}
|
|
1515
|
+
});
|
|
1516
|
+
|
|
1517
|
+
// src/core/navigators/generators/types.ts
|
|
1518
|
+
var types_exports2 = {};
|
|
1519
|
+
var init_types2 = __esm({
|
|
1520
|
+
"src/core/navigators/generators/types.ts"() {
|
|
1521
|
+
"use strict";
|
|
1522
|
+
}
|
|
1523
|
+
});
|
|
1524
|
+
|
|
1525
|
+
// src/core/navigators/hardcodedOrder.ts
|
|
1526
|
+
var hardcodedOrder_exports = {};
|
|
1527
|
+
__export(hardcodedOrder_exports, {
|
|
1528
|
+
default: () => HardcodedOrderNavigator
|
|
1529
|
+
});
|
|
1530
|
+
var HardcodedOrderNavigator;
|
|
1531
|
+
var init_hardcodedOrder = __esm({
|
|
1532
|
+
"src/core/navigators/hardcodedOrder.ts"() {
|
|
1533
|
+
"use strict";
|
|
1534
|
+
init_navigators();
|
|
1535
|
+
init_logger();
|
|
1536
|
+
HardcodedOrderNavigator = class extends ContentNavigator {
|
|
1537
|
+
/** Human-readable name for CardGenerator interface */
|
|
1538
|
+
name;
|
|
1539
|
+
orderedCardIds = [];
|
|
1540
|
+
constructor(user, course, strategyData) {
|
|
1541
|
+
super(user, course, strategyData);
|
|
1542
|
+
this.name = strategyData.name || "Hardcoded Order";
|
|
1543
|
+
if (strategyData.serializedData) {
|
|
1544
|
+
try {
|
|
1545
|
+
this.orderedCardIds = JSON.parse(strategyData.serializedData);
|
|
1546
|
+
} catch (e) {
|
|
1547
|
+
logger.error("Failed to parse serializedData for HardcodedOrderNavigator", e);
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1551
|
+
async getPendingReviews() {
|
|
1552
|
+
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
1553
|
+
return reviews.map((r) => {
|
|
1554
|
+
return {
|
|
1555
|
+
...r,
|
|
1556
|
+
contentSourceType: "course",
|
|
1557
|
+
contentSourceID: this.course.getCourseID(),
|
|
1558
|
+
cardID: r.cardId,
|
|
1559
|
+
courseID: r.courseId,
|
|
1560
|
+
reviewID: r._id,
|
|
1561
|
+
status: "review"
|
|
1562
|
+
};
|
|
1563
|
+
});
|
|
1564
|
+
}
|
|
1565
|
+
async getNewCards(limit = 99) {
|
|
1566
|
+
const activeCardIds = (await this.user.getActiveCards()).map((c) => c.cardID);
|
|
1567
|
+
const newCardIds = this.orderedCardIds.filter((cardId) => !activeCardIds.includes(cardId));
|
|
1568
|
+
const cardsToReturn = newCardIds.slice(0, limit);
|
|
1569
|
+
return cardsToReturn.map((cardId) => {
|
|
1570
|
+
return {
|
|
1571
|
+
cardID: cardId,
|
|
1572
|
+
courseID: this.course.getCourseID(),
|
|
1573
|
+
contentSourceType: "course",
|
|
1574
|
+
contentSourceID: this.course.getCourseID(),
|
|
1575
|
+
status: "new"
|
|
1576
|
+
};
|
|
1577
|
+
});
|
|
1578
|
+
}
|
|
1579
|
+
/**
|
|
1580
|
+
* Get cards in hardcoded order with scores based on position.
|
|
1581
|
+
*
|
|
1582
|
+
* Earlier cards in the sequence get higher scores.
|
|
1583
|
+
* Score formula: 1.0 - (position / totalCards) * 0.5
|
|
1584
|
+
* This ensures scores range from 1.0 (first card) to 0.5+ (last card).
|
|
1585
|
+
*
|
|
1586
|
+
* This method supports both the legacy signature (limit only) and the
|
|
1587
|
+
* CardGenerator interface signature (limit, context).
|
|
1588
|
+
*
|
|
1589
|
+
* @param limit - Maximum number of cards to return
|
|
1590
|
+
* @param _context - Optional GeneratorContext (currently unused, but required for interface)
|
|
1591
|
+
*/
|
|
1592
|
+
async getWeightedCards(limit, _context) {
|
|
1593
|
+
const activeCardIds = (await this.user.getActiveCards()).map((c) => c.cardID);
|
|
1594
|
+
const reviews = await this.getPendingReviews();
|
|
1595
|
+
const newCardIds = this.orderedCardIds.filter((cardId) => !activeCardIds.includes(cardId));
|
|
1596
|
+
const totalCards = newCardIds.length;
|
|
1597
|
+
const scoredNew = newCardIds.slice(0, limit).map((cardId, index) => {
|
|
1598
|
+
const position = index + 1;
|
|
1599
|
+
const score = Math.max(0.5, 1 - index / totalCards * 0.5);
|
|
1600
|
+
return {
|
|
1601
|
+
cardId,
|
|
1602
|
+
courseId: this.course.getCourseID(),
|
|
1603
|
+
score,
|
|
1604
|
+
provenance: [
|
|
1605
|
+
{
|
|
1606
|
+
strategy: "hardcodedOrder",
|
|
1607
|
+
strategyName: this.strategyName || this.name,
|
|
1608
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-hardcoded",
|
|
1609
|
+
action: "generated",
|
|
1610
|
+
score,
|
|
1611
|
+
reason: `Position ${position} of ${totalCards} in fixed sequence, new card`
|
|
1612
|
+
}
|
|
1613
|
+
]
|
|
1614
|
+
};
|
|
1615
|
+
});
|
|
1616
|
+
const scoredReviews = reviews.map((r) => ({
|
|
1617
|
+
cardId: r.cardID,
|
|
1618
|
+
courseId: r.courseID,
|
|
1619
|
+
score: 1,
|
|
1620
|
+
provenance: [
|
|
1621
|
+
{
|
|
1622
|
+
strategy: "hardcodedOrder",
|
|
1623
|
+
strategyName: this.strategyName || this.name,
|
|
1624
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-hardcoded",
|
|
1625
|
+
action: "generated",
|
|
1626
|
+
score: 1,
|
|
1627
|
+
reason: "Scheduled review, highest priority"
|
|
1628
|
+
}
|
|
1629
|
+
]
|
|
1630
|
+
}));
|
|
1631
|
+
const all = [...scoredReviews, ...scoredNew];
|
|
1632
|
+
all.sort((a, b) => b.score - a.score);
|
|
1633
|
+
return all.slice(0, limit);
|
|
1634
|
+
}
|
|
1635
|
+
};
|
|
1636
|
+
}
|
|
1637
|
+
});
|
|
1638
|
+
|
|
1639
|
+
// src/core/navigators/hierarchyDefinition.ts
|
|
1640
|
+
var hierarchyDefinition_exports = {};
|
|
1641
|
+
__export(hierarchyDefinition_exports, {
|
|
1642
|
+
default: () => HierarchyDefinitionNavigator
|
|
1643
|
+
});
|
|
1644
|
+
import { toCourseElo as toCourseElo4 } from "@vue-skuilder/common";
|
|
1645
|
+
var DEFAULT_MIN_COUNT, HierarchyDefinitionNavigator;
|
|
1646
|
+
var init_hierarchyDefinition = __esm({
|
|
1647
|
+
"src/core/navigators/hierarchyDefinition.ts"() {
|
|
1648
|
+
"use strict";
|
|
1649
|
+
init_navigators();
|
|
1650
|
+
DEFAULT_MIN_COUNT = 3;
|
|
1651
|
+
HierarchyDefinitionNavigator = class extends ContentNavigator {
|
|
1652
|
+
config;
|
|
1653
|
+
_strategyData;
|
|
1654
|
+
/** Human-readable name for CardFilter interface */
|
|
1655
|
+
name;
|
|
1656
|
+
constructor(user, course, _strategyData) {
|
|
1657
|
+
super(user, course, _strategyData);
|
|
1658
|
+
this._strategyData = _strategyData;
|
|
1659
|
+
this.config = this.parseConfig(_strategyData.serializedData);
|
|
1660
|
+
this.name = _strategyData.name || "Hierarchy Definition";
|
|
1661
|
+
}
|
|
1662
|
+
parseConfig(serializedData) {
|
|
1663
|
+
try {
|
|
1664
|
+
const parsed = JSON.parse(serializedData);
|
|
1665
|
+
return {
|
|
1666
|
+
prerequisites: parsed.prerequisites || {}
|
|
1667
|
+
};
|
|
1668
|
+
} catch {
|
|
1669
|
+
return {
|
|
1670
|
+
prerequisites: {}
|
|
1671
|
+
};
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
/**
|
|
1675
|
+
* Check if a specific prerequisite is satisfied
|
|
1676
|
+
*/
|
|
1677
|
+
isPrerequisiteMet(prereq, userTagElo, userGlobalElo) {
|
|
1678
|
+
if (!userTagElo) return false;
|
|
1679
|
+
const minCount = prereq.masteryThreshold?.minCount ?? DEFAULT_MIN_COUNT;
|
|
1680
|
+
if (userTagElo.count < minCount) return false;
|
|
1681
|
+
if (prereq.masteryThreshold?.minElo !== void 0) {
|
|
1682
|
+
return userTagElo.score >= prereq.masteryThreshold.minElo;
|
|
1683
|
+
} else {
|
|
1684
|
+
return userTagElo.score >= userGlobalElo;
|
|
1685
|
+
}
|
|
1686
|
+
}
|
|
1687
|
+
/**
|
|
1688
|
+
* Get the set of tags the user has mastered.
|
|
1689
|
+
* A tag is "mastered" if it appears as a prerequisite somewhere and meets its threshold.
|
|
1690
|
+
*/
|
|
1691
|
+
async getMasteredTags(context) {
|
|
1692
|
+
const mastered = /* @__PURE__ */ new Set();
|
|
1693
|
+
try {
|
|
1694
|
+
const courseReg = await context.user.getCourseRegDoc(context.course.getCourseID());
|
|
1695
|
+
const userElo = toCourseElo4(courseReg.elo);
|
|
1696
|
+
for (const prereqs of Object.values(this.config.prerequisites)) {
|
|
1697
|
+
for (const prereq of prereqs) {
|
|
1698
|
+
const tagElo = userElo.tags[prereq.tag];
|
|
1699
|
+
if (this.isPrerequisiteMet(prereq, tagElo, userElo.global.score)) {
|
|
1700
|
+
mastered.add(prereq.tag);
|
|
1701
|
+
}
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1704
|
+
} catch {
|
|
1705
|
+
}
|
|
1706
|
+
return mastered;
|
|
1707
|
+
}
|
|
1708
|
+
/**
|
|
1709
|
+
* Get the set of tags that are unlocked (prerequisites met)
|
|
1710
|
+
*/
|
|
1711
|
+
getUnlockedTags(masteredTags) {
|
|
1712
|
+
const unlocked = /* @__PURE__ */ new Set();
|
|
1713
|
+
for (const [tagId, prereqs] of Object.entries(this.config.prerequisites)) {
|
|
1714
|
+
const allPrereqsMet = prereqs.every((prereq) => masteredTags.has(prereq.tag));
|
|
1715
|
+
if (allPrereqsMet) {
|
|
1716
|
+
unlocked.add(tagId);
|
|
1717
|
+
}
|
|
1718
|
+
}
|
|
1719
|
+
return unlocked;
|
|
1720
|
+
}
|
|
1721
|
+
/**
|
|
1722
|
+
* Check if a tag has prerequisites defined in config
|
|
1723
|
+
*/
|
|
1724
|
+
hasPrerequisites(tagId) {
|
|
1725
|
+
return tagId in this.config.prerequisites;
|
|
1726
|
+
}
|
|
1727
|
+
/**
|
|
1728
|
+
* Check if a card is unlocked and generate reason.
|
|
1729
|
+
*/
|
|
1730
|
+
async checkCardUnlock(card, course, unlockedTags, masteredTags) {
|
|
1731
|
+
try {
|
|
1732
|
+
const cardTags = card.tags ?? [];
|
|
1733
|
+
const lockedTags = cardTags.filter(
|
|
1734
|
+
(tag) => this.hasPrerequisites(tag) && !unlockedTags.has(tag)
|
|
1735
|
+
);
|
|
1736
|
+
if (lockedTags.length === 0) {
|
|
1737
|
+
const tagList = cardTags.length > 0 ? cardTags.join(", ") : "none";
|
|
1738
|
+
return {
|
|
1739
|
+
isUnlocked: true,
|
|
1740
|
+
reason: `Prerequisites met, tags: ${tagList}`
|
|
1741
|
+
};
|
|
1742
|
+
}
|
|
1743
|
+
const missingPrereqs = lockedTags.flatMap((tag) => {
|
|
1744
|
+
const prereqs = this.config.prerequisites[tag] || [];
|
|
1745
|
+
return prereqs.filter((p) => !masteredTags.has(p.tag)).map((p) => p.tag);
|
|
1746
|
+
});
|
|
1747
|
+
return {
|
|
1748
|
+
isUnlocked: false,
|
|
1749
|
+
reason: `Blocked: missing prerequisites ${missingPrereqs.join(", ")} for tags ${lockedTags.join(", ")}`
|
|
1750
|
+
};
|
|
1751
|
+
} catch {
|
|
1752
|
+
return {
|
|
1753
|
+
isUnlocked: true,
|
|
1754
|
+
reason: "Prerequisites check skipped (tag lookup failed)"
|
|
1755
|
+
};
|
|
1756
|
+
}
|
|
1757
|
+
}
|
|
1758
|
+
/**
|
|
1759
|
+
* CardFilter.transform implementation.
|
|
1760
|
+
*
|
|
1761
|
+
* Apply prerequisite gating to cards. Cards with locked tags receive score: 0.
|
|
1762
|
+
*/
|
|
1763
|
+
async transform(cards, context) {
|
|
1764
|
+
const masteredTags = await this.getMasteredTags(context);
|
|
1765
|
+
const unlockedTags = this.getUnlockedTags(masteredTags);
|
|
1766
|
+
const gated = [];
|
|
1767
|
+
for (const card of cards) {
|
|
1768
|
+
const { isUnlocked, reason } = await this.checkCardUnlock(
|
|
1769
|
+
card,
|
|
1770
|
+
context.course,
|
|
1771
|
+
unlockedTags,
|
|
1772
|
+
masteredTags
|
|
1773
|
+
);
|
|
1774
|
+
const finalScore = isUnlocked ? card.score : 0;
|
|
1775
|
+
const action = isUnlocked ? "passed" : "penalized";
|
|
1776
|
+
gated.push({
|
|
1777
|
+
...card,
|
|
1778
|
+
score: finalScore,
|
|
1779
|
+
provenance: [
|
|
1780
|
+
...card.provenance,
|
|
1781
|
+
{
|
|
1782
|
+
strategy: "hierarchyDefinition",
|
|
1783
|
+
strategyName: this.strategyName || this.name,
|
|
1784
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-hierarchy",
|
|
1785
|
+
action,
|
|
1786
|
+
score: finalScore,
|
|
1787
|
+
reason
|
|
1788
|
+
}
|
|
1789
|
+
]
|
|
1790
|
+
});
|
|
1791
|
+
}
|
|
1792
|
+
return gated;
|
|
1793
|
+
}
|
|
1794
|
+
/**
|
|
1795
|
+
* Legacy getWeightedCards - now throws as filters should not be used as generators.
|
|
1796
|
+
*
|
|
1797
|
+
* Use transform() via Pipeline instead.
|
|
1798
|
+
*/
|
|
1799
|
+
async getWeightedCards(_limit) {
|
|
1800
|
+
throw new Error(
|
|
1801
|
+
"HierarchyDefinitionNavigator is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
|
|
1802
|
+
);
|
|
1803
|
+
}
|
|
1804
|
+
// Legacy methods - stub implementations since filters don't generate cards
|
|
1805
|
+
async getNewCards(_n) {
|
|
1806
|
+
return [];
|
|
1807
|
+
}
|
|
1808
|
+
async getPendingReviews() {
|
|
1809
|
+
return [];
|
|
1810
|
+
}
|
|
1811
|
+
};
|
|
1812
|
+
}
|
|
1813
|
+
});
|
|
1814
|
+
|
|
1815
|
+
// src/core/navigators/inferredPreference.ts
|
|
1816
|
+
var inferredPreference_exports = {};
|
|
1817
|
+
__export(inferredPreference_exports, {
|
|
1818
|
+
INFERRED_PREFERENCE_NAVIGATOR_STUB: () => INFERRED_PREFERENCE_NAVIGATOR_STUB
|
|
1819
|
+
});
|
|
1820
|
+
var INFERRED_PREFERENCE_NAVIGATOR_STUB;
|
|
1821
|
+
var init_inferredPreference = __esm({
|
|
1822
|
+
"src/core/navigators/inferredPreference.ts"() {
|
|
1823
|
+
"use strict";
|
|
1824
|
+
INFERRED_PREFERENCE_NAVIGATOR_STUB = true;
|
|
1825
|
+
}
|
|
1826
|
+
});
|
|
1827
|
+
|
|
1828
|
+
// src/core/navigators/interferenceMitigator.ts
|
|
1829
|
+
var interferenceMitigator_exports = {};
|
|
1830
|
+
__export(interferenceMitigator_exports, {
|
|
1831
|
+
default: () => InterferenceMitigatorNavigator
|
|
1832
|
+
});
|
|
1833
|
+
import { toCourseElo as toCourseElo5 } from "@vue-skuilder/common";
|
|
1834
|
+
var DEFAULT_MIN_COUNT2, DEFAULT_MIN_ELAPSED_DAYS, DEFAULT_INTERFERENCE_DECAY, InterferenceMitigatorNavigator;
|
|
1835
|
+
var init_interferenceMitigator = __esm({
|
|
1836
|
+
"src/core/navigators/interferenceMitigator.ts"() {
|
|
1837
|
+
"use strict";
|
|
1838
|
+
init_navigators();
|
|
1839
|
+
DEFAULT_MIN_COUNT2 = 10;
|
|
1840
|
+
DEFAULT_MIN_ELAPSED_DAYS = 3;
|
|
1841
|
+
DEFAULT_INTERFERENCE_DECAY = 0.8;
|
|
1842
|
+
InterferenceMitigatorNavigator = class extends ContentNavigator {
|
|
1843
|
+
config;
|
|
1844
|
+
_strategyData;
|
|
1845
|
+
/** Human-readable name for CardFilter interface */
|
|
1846
|
+
name;
|
|
1847
|
+
/** Precomputed map: tag -> set of { partner, decay } it interferes with */
|
|
1848
|
+
interferenceMap;
|
|
1849
|
+
constructor(user, course, _strategyData) {
|
|
1850
|
+
super(user, course, _strategyData);
|
|
1851
|
+
this._strategyData = _strategyData;
|
|
1852
|
+
this.config = this.parseConfig(_strategyData.serializedData);
|
|
1853
|
+
this.interferenceMap = this.buildInterferenceMap();
|
|
1854
|
+
this.name = _strategyData.name || "Interference Mitigator";
|
|
1855
|
+
}
|
|
1856
|
+
parseConfig(serializedData) {
|
|
1857
|
+
try {
|
|
1858
|
+
const parsed = JSON.parse(serializedData);
|
|
1859
|
+
let sets = parsed.interferenceSets || [];
|
|
1860
|
+
if (sets.length > 0 && Array.isArray(sets[0])) {
|
|
1861
|
+
sets = sets.map((tags) => ({ tags }));
|
|
1862
|
+
}
|
|
1863
|
+
return {
|
|
1864
|
+
interferenceSets: sets,
|
|
1865
|
+
maturityThreshold: {
|
|
1866
|
+
minCount: parsed.maturityThreshold?.minCount ?? DEFAULT_MIN_COUNT2,
|
|
1867
|
+
minElo: parsed.maturityThreshold?.minElo,
|
|
1868
|
+
minElapsedDays: parsed.maturityThreshold?.minElapsedDays ?? DEFAULT_MIN_ELAPSED_DAYS
|
|
1869
|
+
},
|
|
1870
|
+
defaultDecay: parsed.defaultDecay ?? DEFAULT_INTERFERENCE_DECAY
|
|
1871
|
+
};
|
|
1872
|
+
} catch {
|
|
1873
|
+
return {
|
|
1874
|
+
interferenceSets: [],
|
|
1875
|
+
maturityThreshold: {
|
|
1876
|
+
minCount: DEFAULT_MIN_COUNT2,
|
|
1877
|
+
minElapsedDays: DEFAULT_MIN_ELAPSED_DAYS
|
|
1878
|
+
},
|
|
1879
|
+
defaultDecay: DEFAULT_INTERFERENCE_DECAY
|
|
1880
|
+
};
|
|
1881
|
+
}
|
|
1882
|
+
}
|
|
1883
|
+
/**
|
|
1884
|
+
* Build a map from each tag to its interference partners with decay coefficients.
|
|
1885
|
+
* If tags A, B, C are in an interference group with decay 0.8, then:
|
|
1886
|
+
* - A interferes with B (decay 0.8) and C (decay 0.8)
|
|
1887
|
+
* - B interferes with A (decay 0.8) and C (decay 0.8)
|
|
1888
|
+
* - etc.
|
|
1889
|
+
*/
|
|
1890
|
+
buildInterferenceMap() {
|
|
1891
|
+
const map = /* @__PURE__ */ new Map();
|
|
1892
|
+
for (const group of this.config.interferenceSets) {
|
|
1893
|
+
const decay = group.decay ?? this.config.defaultDecay ?? DEFAULT_INTERFERENCE_DECAY;
|
|
1894
|
+
for (const tag of group.tags) {
|
|
1895
|
+
if (!map.has(tag)) {
|
|
1896
|
+
map.set(tag, []);
|
|
1897
|
+
}
|
|
1898
|
+
const partners = map.get(tag);
|
|
1899
|
+
for (const other of group.tags) {
|
|
1900
|
+
if (other !== tag) {
|
|
1901
|
+
const existing = partners.find((p) => p.partner === other);
|
|
1902
|
+
if (existing) {
|
|
1903
|
+
existing.decay = Math.max(existing.decay, decay);
|
|
1904
|
+
} else {
|
|
1905
|
+
partners.push({ partner: other, decay });
|
|
1906
|
+
}
|
|
1907
|
+
}
|
|
1908
|
+
}
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
return map;
|
|
1912
|
+
}
|
|
1913
|
+
/**
|
|
1914
|
+
* Get the set of tags that are currently immature for this user.
|
|
1915
|
+
* A tag is immature if the user has interacted with it but hasn't
|
|
1916
|
+
* reached the maturity threshold.
|
|
1917
|
+
*/
|
|
1918
|
+
async getImmatureTags(context) {
|
|
1919
|
+
const immature = /* @__PURE__ */ new Set();
|
|
1920
|
+
try {
|
|
1921
|
+
const courseReg = await context.user.getCourseRegDoc(context.course.getCourseID());
|
|
1922
|
+
const userElo = toCourseElo5(courseReg.elo);
|
|
1923
|
+
const minCount = this.config.maturityThreshold?.minCount ?? DEFAULT_MIN_COUNT2;
|
|
1924
|
+
const minElo = this.config.maturityThreshold?.minElo;
|
|
1925
|
+
const minElapsedDays = this.config.maturityThreshold?.minElapsedDays ?? DEFAULT_MIN_ELAPSED_DAYS;
|
|
1926
|
+
const minCountForElapsed = minElapsedDays * 2;
|
|
1927
|
+
for (const [tagId, tagElo] of Object.entries(userElo.tags)) {
|
|
1928
|
+
if (tagElo.count === 0) continue;
|
|
1929
|
+
const belowCount = tagElo.count < minCount;
|
|
1930
|
+
const belowElo = minElo !== void 0 && tagElo.score < minElo;
|
|
1931
|
+
const belowElapsed = tagElo.count < minCountForElapsed;
|
|
1932
|
+
if (belowCount || belowElo || belowElapsed) {
|
|
1933
|
+
immature.add(tagId);
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1936
|
+
} catch {
|
|
1937
|
+
}
|
|
1938
|
+
return immature;
|
|
1939
|
+
}
|
|
1940
|
+
/**
|
|
1941
|
+
* Get all tags that interfere with any immature tag, along with their decay coefficients.
|
|
1942
|
+
* These are the tags we want to avoid introducing.
|
|
1943
|
+
*/
|
|
1944
|
+
getTagsToAvoid(immatureTags) {
|
|
1945
|
+
const avoid = /* @__PURE__ */ new Map();
|
|
1946
|
+
for (const immatureTag of immatureTags) {
|
|
1947
|
+
const partners = this.interferenceMap.get(immatureTag);
|
|
1948
|
+
if (partners) {
|
|
1949
|
+
for (const { partner, decay } of partners) {
|
|
1950
|
+
if (!immatureTags.has(partner)) {
|
|
1951
|
+
const existing = avoid.get(partner) ?? 0;
|
|
1952
|
+
avoid.set(partner, Math.max(existing, decay));
|
|
1953
|
+
}
|
|
1954
|
+
}
|
|
1955
|
+
}
|
|
1956
|
+
}
|
|
1957
|
+
return avoid;
|
|
1958
|
+
}
|
|
1959
|
+
/**
|
|
1960
|
+
* Compute interference score reduction for a card.
|
|
1961
|
+
* Returns: { multiplier, interfering tags, reason }
|
|
1962
|
+
*/
|
|
1963
|
+
computeInterferenceEffect(cardTags, tagsToAvoid, immatureTags) {
|
|
1964
|
+
if (tagsToAvoid.size === 0) {
|
|
1965
|
+
return {
|
|
1966
|
+
multiplier: 1,
|
|
1967
|
+
interferingTags: [],
|
|
1968
|
+
reason: "No interference detected"
|
|
1969
|
+
};
|
|
1970
|
+
}
|
|
1971
|
+
let multiplier = 1;
|
|
1972
|
+
const interferingTags = [];
|
|
1973
|
+
for (const tag of cardTags) {
|
|
1974
|
+
const decay = tagsToAvoid.get(tag);
|
|
1975
|
+
if (decay !== void 0) {
|
|
1976
|
+
interferingTags.push(tag);
|
|
1977
|
+
multiplier *= 1 - decay;
|
|
1978
|
+
}
|
|
1979
|
+
}
|
|
1980
|
+
if (interferingTags.length === 0) {
|
|
1981
|
+
return {
|
|
1982
|
+
multiplier: 1,
|
|
1983
|
+
interferingTags: [],
|
|
1984
|
+
reason: "No interference detected"
|
|
1985
|
+
};
|
|
1986
|
+
}
|
|
1987
|
+
const causingTags = /* @__PURE__ */ new Set();
|
|
1988
|
+
for (const tag of interferingTags) {
|
|
1989
|
+
for (const immatureTag of immatureTags) {
|
|
1990
|
+
const partners = this.interferenceMap.get(immatureTag);
|
|
1991
|
+
if (partners?.some((p) => p.partner === tag)) {
|
|
1992
|
+
causingTags.add(immatureTag);
|
|
1993
|
+
}
|
|
1994
|
+
}
|
|
1995
|
+
}
|
|
1996
|
+
const reason = `Interferes with immature tags ${Array.from(causingTags).join(", ")} (tags: ${interferingTags.join(", ")}, multiplier: ${multiplier.toFixed(2)})`;
|
|
1997
|
+
return { multiplier, interferingTags, reason };
|
|
1998
|
+
}
|
|
1999
|
+
/**
|
|
2000
|
+
* CardFilter.transform implementation.
|
|
2001
|
+
*
|
|
2002
|
+
* Apply interference-aware scoring. Cards with tags that interfere with
|
|
2003
|
+
* immature learnings get reduced scores.
|
|
2004
|
+
*/
|
|
2005
|
+
async transform(cards, context) {
|
|
2006
|
+
const immatureTags = await this.getImmatureTags(context);
|
|
2007
|
+
const tagsToAvoid = this.getTagsToAvoid(immatureTags);
|
|
2008
|
+
const adjusted = [];
|
|
2009
|
+
for (const card of cards) {
|
|
2010
|
+
const cardTags = card.tags ?? [];
|
|
2011
|
+
const { multiplier, reason } = this.computeInterferenceEffect(
|
|
2012
|
+
cardTags,
|
|
2013
|
+
tagsToAvoid,
|
|
2014
|
+
immatureTags
|
|
2015
|
+
);
|
|
2016
|
+
const finalScore = card.score * multiplier;
|
|
2017
|
+
const action = multiplier < 1 ? "penalized" : multiplier > 1 ? "boosted" : "passed";
|
|
2018
|
+
adjusted.push({
|
|
2019
|
+
...card,
|
|
2020
|
+
score: finalScore,
|
|
2021
|
+
provenance: [
|
|
2022
|
+
...card.provenance,
|
|
2023
|
+
{
|
|
2024
|
+
strategy: "interferenceMitigator",
|
|
2025
|
+
strategyName: this.strategyName || this.name,
|
|
2026
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-interference",
|
|
2027
|
+
action,
|
|
2028
|
+
score: finalScore,
|
|
2029
|
+
reason
|
|
2030
|
+
}
|
|
2031
|
+
]
|
|
2032
|
+
});
|
|
2033
|
+
}
|
|
2034
|
+
return adjusted;
|
|
2035
|
+
}
|
|
2036
|
+
/**
|
|
2037
|
+
* Legacy getWeightedCards - now throws as filters should not be used as generators.
|
|
2038
|
+
*
|
|
2039
|
+
* Use transform() via Pipeline instead.
|
|
2040
|
+
*/
|
|
2041
|
+
async getWeightedCards(_limit) {
|
|
2042
|
+
throw new Error(
|
|
2043
|
+
"InterferenceMitigatorNavigator is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
|
|
2044
|
+
);
|
|
2045
|
+
}
|
|
2046
|
+
// Legacy methods - stub implementations since filters don't generate cards
|
|
2047
|
+
async getNewCards(_n) {
|
|
2048
|
+
return [];
|
|
2049
|
+
}
|
|
2050
|
+
async getPendingReviews() {
|
|
2051
|
+
return [];
|
|
2052
|
+
}
|
|
2053
|
+
};
|
|
2054
|
+
}
|
|
2055
|
+
});
|
|
2056
|
+
|
|
2057
|
+
// src/core/navigators/relativePriority.ts
|
|
2058
|
+
var relativePriority_exports = {};
|
|
2059
|
+
__export(relativePriority_exports, {
|
|
2060
|
+
default: () => RelativePriorityNavigator
|
|
2061
|
+
});
|
|
2062
|
+
var DEFAULT_PRIORITY, DEFAULT_PRIORITY_INFLUENCE, DEFAULT_COMBINE_MODE, RelativePriorityNavigator;
|
|
2063
|
+
var init_relativePriority = __esm({
|
|
2064
|
+
"src/core/navigators/relativePriority.ts"() {
|
|
2065
|
+
"use strict";
|
|
2066
|
+
init_navigators();
|
|
2067
|
+
DEFAULT_PRIORITY = 0.5;
|
|
2068
|
+
DEFAULT_PRIORITY_INFLUENCE = 0.5;
|
|
2069
|
+
DEFAULT_COMBINE_MODE = "max";
|
|
2070
|
+
RelativePriorityNavigator = class extends ContentNavigator {
|
|
2071
|
+
config;
|
|
2072
|
+
_strategyData;
|
|
2073
|
+
/** Human-readable name for CardFilter interface */
|
|
2074
|
+
name;
|
|
2075
|
+
constructor(user, course, _strategyData) {
|
|
2076
|
+
super(user, course, _strategyData);
|
|
2077
|
+
this._strategyData = _strategyData;
|
|
2078
|
+
this.config = this.parseConfig(_strategyData.serializedData);
|
|
2079
|
+
this.name = _strategyData.name || "Relative Priority";
|
|
2080
|
+
}
|
|
2081
|
+
parseConfig(serializedData) {
|
|
2082
|
+
try {
|
|
2083
|
+
const parsed = JSON.parse(serializedData);
|
|
2084
|
+
return {
|
|
2085
|
+
tagPriorities: parsed.tagPriorities || {},
|
|
2086
|
+
defaultPriority: parsed.defaultPriority ?? DEFAULT_PRIORITY,
|
|
2087
|
+
combineMode: parsed.combineMode ?? DEFAULT_COMBINE_MODE,
|
|
2088
|
+
priorityInfluence: parsed.priorityInfluence ?? DEFAULT_PRIORITY_INFLUENCE
|
|
2089
|
+
};
|
|
2090
|
+
} catch {
|
|
2091
|
+
return {
|
|
2092
|
+
tagPriorities: {},
|
|
2093
|
+
defaultPriority: DEFAULT_PRIORITY,
|
|
2094
|
+
combineMode: DEFAULT_COMBINE_MODE,
|
|
2095
|
+
priorityInfluence: DEFAULT_PRIORITY_INFLUENCE
|
|
2096
|
+
};
|
|
2097
|
+
}
|
|
2098
|
+
}
|
|
2099
|
+
/**
|
|
2100
|
+
* Look up the priority for a tag.
|
|
2101
|
+
*/
|
|
2102
|
+
getTagPriority(tagId) {
|
|
2103
|
+
return this.config.tagPriorities[tagId] ?? this.config.defaultPriority ?? DEFAULT_PRIORITY;
|
|
2104
|
+
}
|
|
2105
|
+
/**
|
|
2106
|
+
* Compute combined priority for a card based on its tags.
|
|
2107
|
+
*/
|
|
2108
|
+
computeCardPriority(cardTags) {
|
|
2109
|
+
if (cardTags.length === 0) {
|
|
2110
|
+
return this.config.defaultPriority ?? DEFAULT_PRIORITY;
|
|
2111
|
+
}
|
|
2112
|
+
const priorities = cardTags.map((tag) => this.getTagPriority(tag));
|
|
2113
|
+
switch (this.config.combineMode) {
|
|
2114
|
+
case "max":
|
|
2115
|
+
return Math.max(...priorities);
|
|
2116
|
+
case "min":
|
|
2117
|
+
return Math.min(...priorities);
|
|
2118
|
+
case "average":
|
|
2119
|
+
return priorities.reduce((sum, p) => sum + p, 0) / priorities.length;
|
|
2120
|
+
default:
|
|
2121
|
+
return Math.max(...priorities);
|
|
2122
|
+
}
|
|
2123
|
+
}
|
|
2124
|
+
/**
|
|
2125
|
+
* Compute boost factor based on priority.
|
|
2126
|
+
*
|
|
2127
|
+
* The formula: 1 + (priority - 0.5) * priorityInfluence
|
|
2128
|
+
*
|
|
2129
|
+
* This creates a multiplier centered around 1.0:
|
|
2130
|
+
* - Priority 1.0 with influence 0.5 → 1.25 (25% boost)
|
|
2131
|
+
* - Priority 0.5 with any influence → 1.00 (neutral)
|
|
2132
|
+
* - Priority 0.0 with influence 0.5 → 0.75 (25% reduction)
|
|
2133
|
+
*/
|
|
2134
|
+
computeBoostFactor(priority) {
|
|
2135
|
+
const influence = this.config.priorityInfluence ?? DEFAULT_PRIORITY_INFLUENCE;
|
|
2136
|
+
return 1 + (priority - 0.5) * influence;
|
|
2137
|
+
}
|
|
2138
|
+
/**
|
|
2139
|
+
* Build human-readable reason for priority adjustment.
|
|
2140
|
+
*/
|
|
2141
|
+
buildPriorityReason(cardTags, priority, boostFactor, finalScore) {
|
|
2142
|
+
if (cardTags.length === 0) {
|
|
2143
|
+
return `No tags, neutral priority (${priority.toFixed(2)})`;
|
|
2144
|
+
}
|
|
2145
|
+
const tagList = cardTags.slice(0, 3).join(", ");
|
|
2146
|
+
const more = cardTags.length > 3 ? ` (+${cardTags.length - 3} more)` : "";
|
|
2147
|
+
if (boostFactor === 1) {
|
|
2148
|
+
return `Neutral priority (${priority.toFixed(2)}) for tags: ${tagList}${more}`;
|
|
2149
|
+
} else if (boostFactor > 1) {
|
|
2150
|
+
return `High-priority tags: ${tagList}${more} (priority ${priority.toFixed(2)} \u2192 boost ${boostFactor.toFixed(2)}x \u2192 ${finalScore.toFixed(2)})`;
|
|
2151
|
+
} else {
|
|
2152
|
+
return `Low-priority tags: ${tagList}${more} (priority ${priority.toFixed(2)} \u2192 reduce ${boostFactor.toFixed(2)}x \u2192 ${finalScore.toFixed(2)})`;
|
|
2153
|
+
}
|
|
2154
|
+
}
|
|
2155
|
+
/**
|
|
2156
|
+
* CardFilter.transform implementation.
|
|
2157
|
+
*
|
|
2158
|
+
* Apply priority-adjusted scoring. Cards with high-priority tags get boosted,
|
|
2159
|
+
* cards with low-priority tags get reduced scores.
|
|
2160
|
+
*/
|
|
2161
|
+
async transform(cards, _context) {
|
|
2162
|
+
const adjusted = await Promise.all(
|
|
2163
|
+
cards.map(async (card) => {
|
|
2164
|
+
const cardTags = card.tags ?? [];
|
|
2165
|
+
const priority = this.computeCardPriority(cardTags);
|
|
2166
|
+
const boostFactor = this.computeBoostFactor(priority);
|
|
2167
|
+
const finalScore = Math.max(0, Math.min(1, card.score * boostFactor));
|
|
2168
|
+
const action = boostFactor > 1 ? "boosted" : boostFactor < 1 ? "penalized" : "passed";
|
|
2169
|
+
const reason = this.buildPriorityReason(cardTags, priority, boostFactor, finalScore);
|
|
2170
|
+
return {
|
|
2171
|
+
...card,
|
|
2172
|
+
score: finalScore,
|
|
2173
|
+
provenance: [
|
|
2174
|
+
...card.provenance,
|
|
2175
|
+
{
|
|
2176
|
+
strategy: "relativePriority",
|
|
2177
|
+
strategyName: this.strategyName || this.name,
|
|
2178
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-priority",
|
|
2179
|
+
action,
|
|
2180
|
+
score: finalScore,
|
|
2181
|
+
reason
|
|
2182
|
+
}
|
|
2183
|
+
]
|
|
2184
|
+
};
|
|
2185
|
+
})
|
|
2186
|
+
);
|
|
2187
|
+
return adjusted;
|
|
2188
|
+
}
|
|
2189
|
+
/**
|
|
2190
|
+
* Legacy getWeightedCards - now throws as filters should not be used as generators.
|
|
2191
|
+
*
|
|
2192
|
+
* Use transform() via Pipeline instead.
|
|
2193
|
+
*/
|
|
2194
|
+
async getWeightedCards(_limit) {
|
|
2195
|
+
throw new Error(
|
|
2196
|
+
"RelativePriorityNavigator is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
|
|
2197
|
+
);
|
|
2198
|
+
}
|
|
2199
|
+
// Legacy methods - stub implementations since filters don't generate cards
|
|
2200
|
+
async getNewCards(_n) {
|
|
2201
|
+
return [];
|
|
2202
|
+
}
|
|
2203
|
+
async getPendingReviews() {
|
|
2204
|
+
return [];
|
|
2205
|
+
}
|
|
2206
|
+
};
|
|
2207
|
+
}
|
|
2208
|
+
});
|
|
2209
|
+
|
|
2210
|
+
// src/core/navigators/srs.ts
|
|
2211
|
+
var srs_exports = {};
|
|
2212
|
+
__export(srs_exports, {
|
|
2213
|
+
default: () => SRSNavigator
|
|
2214
|
+
});
|
|
2215
|
+
import moment3 from "moment";
|
|
2216
|
+
var SRSNavigator;
|
|
2217
|
+
var init_srs = __esm({
|
|
2218
|
+
"src/core/navigators/srs.ts"() {
|
|
2219
|
+
"use strict";
|
|
2220
|
+
init_navigators();
|
|
2221
|
+
SRSNavigator = class extends ContentNavigator {
|
|
2222
|
+
/** Human-readable name for CardGenerator interface */
|
|
2223
|
+
name;
|
|
2224
|
+
constructor(user, course, strategyData) {
|
|
2225
|
+
super(user, course, strategyData);
|
|
2226
|
+
this.name = strategyData?.name || "SRS";
|
|
2227
|
+
}
|
|
2228
|
+
/**
|
|
2229
|
+
* Get review cards scored by urgency.
|
|
2230
|
+
*
|
|
2231
|
+
* Score formula combines:
|
|
2232
|
+
* - Relative overdueness: hoursOverdue / intervalHours
|
|
2233
|
+
* - Interval recency: exponential decay favoring shorter intervals
|
|
2234
|
+
*
|
|
2235
|
+
* Cards not yet due are excluded (not scored as 0).
|
|
2236
|
+
*
|
|
2237
|
+
* This method supports both the legacy signature (limit only) and the
|
|
2238
|
+
* CardGenerator interface signature (limit, context).
|
|
2239
|
+
*
|
|
2240
|
+
* @param limit - Maximum number of cards to return
|
|
2241
|
+
* @param _context - Optional GeneratorContext (currently unused, but required for interface)
|
|
2242
|
+
*/
|
|
2243
|
+
async getWeightedCards(limit, _context) {
|
|
2244
|
+
if (!this.user || !this.course) {
|
|
2245
|
+
throw new Error("SRSNavigator requires user and course to be set");
|
|
780
2246
|
}
|
|
781
|
-
}
|
|
782
|
-
async getPendingReviews() {
|
|
783
2247
|
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
784
|
-
|
|
2248
|
+
const now = moment3.utc();
|
|
2249
|
+
const dueReviews = reviews.filter((r) => now.isAfter(moment3.utc(r.reviewTime)));
|
|
2250
|
+
const scored = dueReviews.map((review) => {
|
|
2251
|
+
const { score, reason } = this.computeUrgencyScore(review, now);
|
|
785
2252
|
return {
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
2253
|
+
cardId: review.cardId,
|
|
2254
|
+
courseId: review.courseId,
|
|
2255
|
+
score,
|
|
2256
|
+
provenance: [
|
|
2257
|
+
{
|
|
2258
|
+
strategy: "srs",
|
|
2259
|
+
strategyName: this.strategyName || this.name,
|
|
2260
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-SRS-default",
|
|
2261
|
+
action: "generated",
|
|
2262
|
+
score,
|
|
2263
|
+
reason
|
|
2264
|
+
}
|
|
2265
|
+
]
|
|
793
2266
|
};
|
|
794
2267
|
});
|
|
2268
|
+
return scored.sort((a, b) => b.score - a.score).slice(0, limit);
|
|
795
2269
|
}
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
2270
|
+
/**
|
|
2271
|
+
* Compute urgency score for a review card.
|
|
2272
|
+
*
|
|
2273
|
+
* Two factors:
|
|
2274
|
+
* 1. Relative overdueness = hoursOverdue / intervalHours
|
|
2275
|
+
* - 2 days overdue on 3-day interval = 0.67 (urgent)
|
|
2276
|
+
* - 2 days overdue on 180-day interval = 0.01 (not urgent)
|
|
2277
|
+
*
|
|
2278
|
+
* 2. Interval recency factor = 0.3 + 0.7 * exp(-intervalHours / 720)
|
|
2279
|
+
* - 24h interval → ~1.0 (very recent learning)
|
|
2280
|
+
* - 30 days (720h) → ~0.56
|
|
2281
|
+
* - 180 days → ~0.30
|
|
2282
|
+
*
|
|
2283
|
+
* Combined: base 0.5 + weighted average of factors * 0.45
|
|
2284
|
+
* Result range: approximately 0.5 to 0.95
|
|
2285
|
+
*/
|
|
2286
|
+
computeUrgencyScore(review, now) {
|
|
2287
|
+
const scheduledAt = moment3.utc(review.scheduledAt);
|
|
2288
|
+
const due = moment3.utc(review.reviewTime);
|
|
2289
|
+
const intervalHours = Math.max(1, due.diff(scheduledAt, "hours"));
|
|
2290
|
+
const hoursOverdue = now.diff(due, "hours");
|
|
2291
|
+
const relativeOverdue = hoursOverdue / intervalHours;
|
|
2292
|
+
const recencyFactor = 0.3 + 0.7 * Math.exp(-intervalHours / 720);
|
|
2293
|
+
const overdueContribution = Math.min(1, Math.max(0, relativeOverdue));
|
|
2294
|
+
const urgency = overdueContribution * 0.5 + recencyFactor * 0.5;
|
|
2295
|
+
const score = Math.min(0.95, 0.5 + urgency * 0.45);
|
|
2296
|
+
const reason = `${Math.round(hoursOverdue)}h overdue (interval: ${Math.round(intervalHours)}h, relative: ${relativeOverdue.toFixed(2)}), recency: ${recencyFactor.toFixed(2)}, review`;
|
|
2297
|
+
return { score, reason };
|
|
2298
|
+
}
|
|
2299
|
+
/**
|
|
2300
|
+
* Get pending reviews in legacy format.
|
|
2301
|
+
*
|
|
2302
|
+
* Returns all pending reviews for the course, enriched with session item fields.
|
|
2303
|
+
*/
|
|
2304
|
+
async getPendingReviews() {
|
|
2305
|
+
if (!this.user || !this.course) {
|
|
2306
|
+
throw new Error("SRSNavigator requires user and course to be set");
|
|
2307
|
+
}
|
|
2308
|
+
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
2309
|
+
return reviews.map((r) => ({
|
|
2310
|
+
...r,
|
|
2311
|
+
contentSourceType: "course",
|
|
2312
|
+
contentSourceID: this.course.getCourseID(),
|
|
2313
|
+
cardID: r.cardId,
|
|
2314
|
+
courseID: r.courseId,
|
|
2315
|
+
qualifiedID: `${r.courseId}-${r.cardId}`,
|
|
2316
|
+
reviewID: r._id,
|
|
2317
|
+
status: "review"
|
|
2318
|
+
}));
|
|
2319
|
+
}
|
|
2320
|
+
/**
|
|
2321
|
+
* SRS does not generate new cards.
|
|
2322
|
+
* Use ELONavigator or another generator for new cards.
|
|
2323
|
+
*/
|
|
2324
|
+
async getNewCards(_n) {
|
|
2325
|
+
return [];
|
|
811
2326
|
}
|
|
812
2327
|
};
|
|
813
2328
|
}
|
|
814
2329
|
});
|
|
815
2330
|
|
|
2331
|
+
// src/core/navigators/userGoal.ts
|
|
2332
|
+
var userGoal_exports = {};
|
|
2333
|
+
__export(userGoal_exports, {
|
|
2334
|
+
USER_GOAL_NAVIGATOR_STUB: () => USER_GOAL_NAVIGATOR_STUB
|
|
2335
|
+
});
|
|
2336
|
+
var USER_GOAL_NAVIGATOR_STUB;
|
|
2337
|
+
var init_userGoal = __esm({
|
|
2338
|
+
"src/core/navigators/userGoal.ts"() {
|
|
2339
|
+
"use strict";
|
|
2340
|
+
USER_GOAL_NAVIGATOR_STUB = true;
|
|
2341
|
+
}
|
|
2342
|
+
});
|
|
2343
|
+
|
|
816
2344
|
// import("./**/*") in src/core/navigators/index.ts
|
|
817
2345
|
var globImport;
|
|
818
2346
|
var init_ = __esm({
|
|
819
2347
|
'import("./**/*") in src/core/navigators/index.ts'() {
|
|
820
2348
|
globImport = __glob({
|
|
2349
|
+
"./CompositeGenerator.ts": () => Promise.resolve().then(() => (init_CompositeGenerator(), CompositeGenerator_exports)),
|
|
2350
|
+
"./Pipeline.ts": () => Promise.resolve().then(() => (init_Pipeline(), Pipeline_exports)),
|
|
2351
|
+
"./PipelineAssembler.ts": () => Promise.resolve().then(() => (init_PipelineAssembler(), PipelineAssembler_exports)),
|
|
821
2352
|
"./elo.ts": () => Promise.resolve().then(() => (init_elo(), elo_exports)),
|
|
2353
|
+
"./filters/eloDistance.ts": () => Promise.resolve().then(() => (init_eloDistance(), eloDistance_exports)),
|
|
2354
|
+
"./filters/index.ts": () => Promise.resolve().then(() => (init_filters(), filters_exports)),
|
|
2355
|
+
"./filters/types.ts": () => Promise.resolve().then(() => (init_types(), types_exports)),
|
|
2356
|
+
"./filters/userTagPreference.ts": () => Promise.resolve().then(() => (init_userTagPreference(), userTagPreference_exports)),
|
|
2357
|
+
"./generators/index.ts": () => Promise.resolve().then(() => (init_generators(), generators_exports)),
|
|
2358
|
+
"./generators/types.ts": () => Promise.resolve().then(() => (init_types2(), types_exports2)),
|
|
822
2359
|
"./hardcodedOrder.ts": () => Promise.resolve().then(() => (init_hardcodedOrder(), hardcodedOrder_exports)),
|
|
823
|
-
"./
|
|
2360
|
+
"./hierarchyDefinition.ts": () => Promise.resolve().then(() => (init_hierarchyDefinition(), hierarchyDefinition_exports)),
|
|
2361
|
+
"./index.ts": () => Promise.resolve().then(() => (init_navigators(), navigators_exports)),
|
|
2362
|
+
"./inferredPreference.ts": () => Promise.resolve().then(() => (init_inferredPreference(), inferredPreference_exports)),
|
|
2363
|
+
"./interferenceMitigator.ts": () => Promise.resolve().then(() => (init_interferenceMitigator(), interferenceMitigator_exports)),
|
|
2364
|
+
"./relativePriority.ts": () => Promise.resolve().then(() => (init_relativePriority(), relativePriority_exports)),
|
|
2365
|
+
"./srs.ts": () => Promise.resolve().then(() => (init_srs(), srs_exports)),
|
|
2366
|
+
"./userGoal.ts": () => Promise.resolve().then(() => (init_userGoal(), userGoal_exports))
|
|
824
2367
|
});
|
|
825
2368
|
}
|
|
826
2369
|
});
|
|
@@ -829,9 +2372,34 @@ var init_ = __esm({
|
|
|
829
2372
|
var navigators_exports = {};
|
|
830
2373
|
__export(navigators_exports, {
|
|
831
2374
|
ContentNavigator: () => ContentNavigator,
|
|
832
|
-
|
|
2375
|
+
NavigatorRole: () => NavigatorRole,
|
|
2376
|
+
NavigatorRoles: () => NavigatorRoles,
|
|
2377
|
+
Navigators: () => Navigators,
|
|
2378
|
+
getCardOrigin: () => getCardOrigin,
|
|
2379
|
+
isFilter: () => isFilter,
|
|
2380
|
+
isGenerator: () => isGenerator
|
|
833
2381
|
});
|
|
834
|
-
|
|
2382
|
+
function getCardOrigin(card) {
|
|
2383
|
+
if (card.provenance.length === 0) {
|
|
2384
|
+
throw new Error("Card has no provenance - cannot determine origin");
|
|
2385
|
+
}
|
|
2386
|
+
const firstEntry = card.provenance[0];
|
|
2387
|
+
const reason = firstEntry.reason.toLowerCase();
|
|
2388
|
+
if (reason.includes("failed")) {
|
|
2389
|
+
return "failed";
|
|
2390
|
+
}
|
|
2391
|
+
if (reason.includes("review")) {
|
|
2392
|
+
return "review";
|
|
2393
|
+
}
|
|
2394
|
+
return "new";
|
|
2395
|
+
}
|
|
2396
|
+
function isGenerator(impl) {
|
|
2397
|
+
return NavigatorRoles[impl] === "generator" /* GENERATOR */;
|
|
2398
|
+
}
|
|
2399
|
+
function isFilter(impl) {
|
|
2400
|
+
return NavigatorRoles[impl] === "filter" /* FILTER */;
|
|
2401
|
+
}
|
|
2402
|
+
var Navigators, NavigatorRole, NavigatorRoles, ContentNavigator;
|
|
835
2403
|
var init_navigators = __esm({
|
|
836
2404
|
"src/core/navigators/index.ts"() {
|
|
837
2405
|
"use strict";
|
|
@@ -839,14 +2407,103 @@ var init_navigators = __esm({
|
|
|
839
2407
|
init_();
|
|
840
2408
|
Navigators = /* @__PURE__ */ ((Navigators2) => {
|
|
841
2409
|
Navigators2["ELO"] = "elo";
|
|
2410
|
+
Navigators2["SRS"] = "srs";
|
|
842
2411
|
Navigators2["HARDCODED"] = "hardcodedOrder";
|
|
2412
|
+
Navigators2["HIERARCHY"] = "hierarchyDefinition";
|
|
2413
|
+
Navigators2["INTERFERENCE"] = "interferenceMitigator";
|
|
2414
|
+
Navigators2["RELATIVE_PRIORITY"] = "relativePriority";
|
|
2415
|
+
Navigators2["USER_TAG_PREFERENCE"] = "userTagPreference";
|
|
843
2416
|
return Navigators2;
|
|
844
2417
|
})(Navigators || {});
|
|
2418
|
+
NavigatorRole = /* @__PURE__ */ ((NavigatorRole2) => {
|
|
2419
|
+
NavigatorRole2["GENERATOR"] = "generator";
|
|
2420
|
+
NavigatorRole2["FILTER"] = "filter";
|
|
2421
|
+
return NavigatorRole2;
|
|
2422
|
+
})(NavigatorRole || {});
|
|
2423
|
+
NavigatorRoles = {
|
|
2424
|
+
["elo" /* ELO */]: "generator" /* GENERATOR */,
|
|
2425
|
+
["srs" /* SRS */]: "generator" /* GENERATOR */,
|
|
2426
|
+
["hardcodedOrder" /* HARDCODED */]: "generator" /* GENERATOR */,
|
|
2427
|
+
["hierarchyDefinition" /* HIERARCHY */]: "filter" /* FILTER */,
|
|
2428
|
+
["interferenceMitigator" /* INTERFERENCE */]: "filter" /* FILTER */,
|
|
2429
|
+
["relativePriority" /* RELATIVE_PRIORITY */]: "filter" /* FILTER */,
|
|
2430
|
+
["userTagPreference" /* USER_TAG_PREFERENCE */]: "filter" /* FILTER */
|
|
2431
|
+
};
|
|
845
2432
|
ContentNavigator = class {
|
|
2433
|
+
/** User interface for this navigation session */
|
|
2434
|
+
user;
|
|
2435
|
+
/** Course interface for this navigation session */
|
|
2436
|
+
course;
|
|
2437
|
+
/** Human-readable name for this strategy instance (from ContentNavigationStrategyData.name) */
|
|
2438
|
+
strategyName;
|
|
2439
|
+
/** Unique document ID for this strategy instance (from ContentNavigationStrategyData._id) */
|
|
2440
|
+
strategyId;
|
|
2441
|
+
/**
|
|
2442
|
+
* Constructor for standard navigators.
|
|
2443
|
+
* Call this from subclass constructors to initialize common fields.
|
|
2444
|
+
*
|
|
2445
|
+
* Note: CompositeGenerator doesn't use this pattern and should call super() without args.
|
|
2446
|
+
*/
|
|
2447
|
+
constructor(user, course, strategyData) {
|
|
2448
|
+
if (user && course && strategyData) {
|
|
2449
|
+
this.user = user;
|
|
2450
|
+
this.course = course;
|
|
2451
|
+
this.strategyName = strategyData.name;
|
|
2452
|
+
this.strategyId = strategyData._id;
|
|
2453
|
+
}
|
|
2454
|
+
}
|
|
2455
|
+
// ============================================================================
|
|
2456
|
+
// STRATEGY STATE HELPERS
|
|
2457
|
+
// ============================================================================
|
|
2458
|
+
//
|
|
2459
|
+
// These methods allow strategies to persist their own state (user preferences,
|
|
2460
|
+
// learned patterns, temporal tracking) in the user database.
|
|
2461
|
+
//
|
|
2462
|
+
// ============================================================================
|
|
2463
|
+
/**
|
|
2464
|
+
* Unique key identifying this strategy for state storage.
|
|
2465
|
+
*
|
|
2466
|
+
* Defaults to the constructor name (e.g., "UserTagPreferenceFilter").
|
|
2467
|
+
* Override in subclasses if multiple instances of the same strategy type
|
|
2468
|
+
* need separate state storage.
|
|
2469
|
+
*/
|
|
2470
|
+
get strategyKey() {
|
|
2471
|
+
return this.constructor.name;
|
|
2472
|
+
}
|
|
846
2473
|
/**
|
|
2474
|
+
* Get this strategy's persisted state for the current course.
|
|
847
2475
|
*
|
|
848
|
-
* @
|
|
849
|
-
* @
|
|
2476
|
+
* @returns The strategy's data payload, or null if no state exists
|
|
2477
|
+
* @throws Error if user or course is not initialized
|
|
2478
|
+
*/
|
|
2479
|
+
async getStrategyState() {
|
|
2480
|
+
if (!this.user || !this.course) {
|
|
2481
|
+
throw new Error(
|
|
2482
|
+
`Cannot get strategy state: navigator not properly initialized. Ensure user and course are provided to constructor.`
|
|
2483
|
+
);
|
|
2484
|
+
}
|
|
2485
|
+
return this.user.getStrategyState(this.course.getCourseID(), this.strategyKey);
|
|
2486
|
+
}
|
|
2487
|
+
/**
|
|
2488
|
+
* Persist this strategy's state for the current course.
|
|
2489
|
+
*
|
|
2490
|
+
* @param data - The strategy's data payload to store
|
|
2491
|
+
* @throws Error if user or course is not initialized
|
|
2492
|
+
*/
|
|
2493
|
+
async putStrategyState(data) {
|
|
2494
|
+
if (!this.user || !this.course) {
|
|
2495
|
+
throw new Error(
|
|
2496
|
+
`Cannot put strategy state: navigator not properly initialized. Ensure user and course are provided to constructor.`
|
|
2497
|
+
);
|
|
2498
|
+
}
|
|
2499
|
+
return this.user.putStrategyState(this.course.getCourseID(), this.strategyKey, data);
|
|
2500
|
+
}
|
|
2501
|
+
/**
|
|
2502
|
+
* Factory method to create navigator instances dynamically.
|
|
2503
|
+
*
|
|
2504
|
+
* @param user - User interface
|
|
2505
|
+
* @param course - Course interface
|
|
2506
|
+
* @param strategyData - Strategy configuration document
|
|
850
2507
|
* @returns the runtime object used to steer a study session.
|
|
851
2508
|
*/
|
|
852
2509
|
static async create(user, course, strategyData) {
|
|
@@ -867,6 +2524,70 @@ var init_navigators = __esm({
|
|
|
867
2524
|
}
|
|
868
2525
|
return new NavigatorImpl(user, course, strategyData);
|
|
869
2526
|
}
|
|
2527
|
+
/**
|
|
2528
|
+
* Get cards with suitability scores and provenance trails.
|
|
2529
|
+
*
|
|
2530
|
+
* **This is the PRIMARY API for navigation strategies.**
|
|
2531
|
+
*
|
|
2532
|
+
* Returns cards ranked by suitability score (0-1). Higher scores indicate
|
|
2533
|
+
* better candidates for presentation. Each card includes a provenance trail
|
|
2534
|
+
* documenting how strategies contributed to the final score.
|
|
2535
|
+
*
|
|
2536
|
+
* ## For Generators
|
|
2537
|
+
* Override this method to generate candidates and compute scores based on
|
|
2538
|
+
* your strategy's logic (e.g., ELO proximity, review urgency). Create the
|
|
2539
|
+
* initial provenance entry with action='generated'.
|
|
2540
|
+
*
|
|
2541
|
+
* ## Default Implementation
|
|
2542
|
+
* The base class provides a backward-compatible default that:
|
|
2543
|
+
* 1. Calls legacy getNewCards() and getPendingReviews()
|
|
2544
|
+
* 2. Assigns score=1.0 to all cards
|
|
2545
|
+
* 3. Creates minimal provenance from legacy methods
|
|
2546
|
+
* 4. Returns combined results up to limit
|
|
2547
|
+
*
|
|
2548
|
+
* This allows existing strategies to work without modification while
|
|
2549
|
+
* new strategies can override with proper scoring and provenance.
|
|
2550
|
+
*
|
|
2551
|
+
* @param limit - Maximum cards to return
|
|
2552
|
+
* @returns Cards sorted by score descending, with provenance trails
|
|
2553
|
+
*/
|
|
2554
|
+
async getWeightedCards(limit) {
|
|
2555
|
+
const newCards = await this.getNewCards(limit);
|
|
2556
|
+
const reviews = await this.getPendingReviews();
|
|
2557
|
+
const weighted = [
|
|
2558
|
+
...newCards.map((c) => ({
|
|
2559
|
+
cardId: c.cardID,
|
|
2560
|
+
courseId: c.courseID,
|
|
2561
|
+
score: 1,
|
|
2562
|
+
provenance: [
|
|
2563
|
+
{
|
|
2564
|
+
strategy: "legacy",
|
|
2565
|
+
strategyName: this.strategyName || "Legacy API",
|
|
2566
|
+
strategyId: this.strategyId || "legacy-fallback",
|
|
2567
|
+
action: "generated",
|
|
2568
|
+
score: 1,
|
|
2569
|
+
reason: "Generated via legacy getNewCards(), new card"
|
|
2570
|
+
}
|
|
2571
|
+
]
|
|
2572
|
+
})),
|
|
2573
|
+
...reviews.map((r) => ({
|
|
2574
|
+
cardId: r.cardID,
|
|
2575
|
+
courseId: r.courseID,
|
|
2576
|
+
score: 1,
|
|
2577
|
+
provenance: [
|
|
2578
|
+
{
|
|
2579
|
+
strategy: "legacy",
|
|
2580
|
+
strategyName: this.strategyName || "Legacy API",
|
|
2581
|
+
strategyId: this.strategyId || "legacy-fallback",
|
|
2582
|
+
action: "generated",
|
|
2583
|
+
score: 1,
|
|
2584
|
+
reason: "Generated via legacy getPendingReviews(), review"
|
|
2585
|
+
}
|
|
2586
|
+
]
|
|
2587
|
+
}))
|
|
2588
|
+
];
|
|
2589
|
+
return weighted.slice(0, limit);
|
|
2590
|
+
}
|
|
870
2591
|
};
|
|
871
2592
|
}
|
|
872
2593
|
});
|
|
@@ -876,7 +2597,7 @@ import {
|
|
|
876
2597
|
EloToNumber,
|
|
877
2598
|
Status,
|
|
878
2599
|
blankCourseElo as blankCourseElo2,
|
|
879
|
-
toCourseElo as
|
|
2600
|
+
toCourseElo as toCourseElo6
|
|
880
2601
|
} from "@vue-skuilder/common";
|
|
881
2602
|
function randIntWeightedTowardZero(n) {
|
|
882
2603
|
return Math.floor(Math.random() * Math.random() * Math.random() * n);
|
|
@@ -965,6 +2686,12 @@ var init_courseDB = __esm({
|
|
|
965
2686
|
init_courseAPI();
|
|
966
2687
|
init_courseLookupDB();
|
|
967
2688
|
init_navigators();
|
|
2689
|
+
init_Pipeline();
|
|
2690
|
+
init_PipelineAssembler();
|
|
2691
|
+
init_CompositeGenerator();
|
|
2692
|
+
init_elo();
|
|
2693
|
+
init_srs();
|
|
2694
|
+
init_eloDistance();
|
|
968
2695
|
CourseDB = class {
|
|
969
2696
|
// private log(msg: string): void {
|
|
970
2697
|
// log(`CourseLog: ${this.id}\n ${msg}`);
|
|
@@ -1031,7 +2758,7 @@ var init_courseDB = __esm({
|
|
|
1031
2758
|
docs.rows.forEach((r) => {
|
|
1032
2759
|
if (isSuccessRow(r)) {
|
|
1033
2760
|
if (r.doc && r.doc.elo) {
|
|
1034
|
-
ret.push(
|
|
2761
|
+
ret.push(toCourseElo6(r.doc.elo));
|
|
1035
2762
|
} else {
|
|
1036
2763
|
logger.warn("no elo data for card: " + r.id);
|
|
1037
2764
|
ret.push(blankCourseElo2());
|
|
@@ -1100,15 +2827,6 @@ var init_courseDB = __esm({
|
|
|
1100
2827
|
ret[r.id] = r.doc.id_displayable_data;
|
|
1101
2828
|
}
|
|
1102
2829
|
});
|
|
1103
|
-
await Promise.all(
|
|
1104
|
-
cards.rows.map((r) => {
|
|
1105
|
-
return async () => {
|
|
1106
|
-
if (isSuccessRow(r)) {
|
|
1107
|
-
ret[r.id] = r.doc.id_displayable_data;
|
|
1108
|
-
}
|
|
1109
|
-
};
|
|
1110
|
-
})
|
|
1111
|
-
);
|
|
1112
2830
|
return ret;
|
|
1113
2831
|
}
|
|
1114
2832
|
async getCardsByELO(elo, cardLimit) {
|
|
@@ -1193,6 +2911,28 @@ ${above.rows.map((r) => ` ${r.id}-${r.key}
|
|
|
1193
2911
|
throw new Error(`Failed to find tags for card ${this.id}-${cardId}`);
|
|
1194
2912
|
}
|
|
1195
2913
|
}
|
|
2914
|
+
async getAppliedTagsBatch(cardIds) {
|
|
2915
|
+
if (cardIds.length === 0) {
|
|
2916
|
+
return /* @__PURE__ */ new Map();
|
|
2917
|
+
}
|
|
2918
|
+
const db = getCourseDB2(this.id);
|
|
2919
|
+
const result = await db.query("getTags", {
|
|
2920
|
+
keys: cardIds,
|
|
2921
|
+
include_docs: false
|
|
2922
|
+
});
|
|
2923
|
+
const tagsByCard = /* @__PURE__ */ new Map();
|
|
2924
|
+
for (const cardId of cardIds) {
|
|
2925
|
+
tagsByCard.set(cardId, []);
|
|
2926
|
+
}
|
|
2927
|
+
for (const row of result.rows) {
|
|
2928
|
+
const cardId = row.key;
|
|
2929
|
+
const tagName = row.value?.name;
|
|
2930
|
+
if (tagName && tagsByCard.has(cardId)) {
|
|
2931
|
+
tagsByCard.get(cardId).push(tagName);
|
|
2932
|
+
}
|
|
2933
|
+
}
|
|
2934
|
+
return tagsByCard;
|
|
2935
|
+
}
|
|
1196
2936
|
async addTagToCard(cardId, tagId, updateELO) {
|
|
1197
2937
|
return await addTagToCard(
|
|
1198
2938
|
this.id,
|
|
@@ -1304,42 +3044,82 @@ ${above.rows.map((r) => ` ${r.id}-${r.key}
|
|
|
1304
3044
|
logger.debug(JSON.stringify(data));
|
|
1305
3045
|
return Promise.resolve();
|
|
1306
3046
|
}
|
|
1307
|
-
|
|
3047
|
+
/**
|
|
3048
|
+
* Creates an instantiated navigator for this course.
|
|
3049
|
+
*
|
|
3050
|
+
* Handles multiple generators by wrapping them in CompositeGenerator.
|
|
3051
|
+
* This is the preferred method for getting a ready-to-use navigator.
|
|
3052
|
+
*
|
|
3053
|
+
* @param user - User database interface
|
|
3054
|
+
* @returns Instantiated ContentNavigator ready for use
|
|
3055
|
+
*/
|
|
3056
|
+
async createNavigator(user) {
|
|
1308
3057
|
try {
|
|
1309
|
-
const
|
|
1310
|
-
if (
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
return strategy;
|
|
1316
|
-
}
|
|
1317
|
-
} catch (e) {
|
|
1318
|
-
logger.warn(
|
|
1319
|
-
// @ts-expect-error tmp: defaultNavigationStrategyId property does not yet exist
|
|
1320
|
-
`Failed to load strategy '${config.defaultNavigationStrategyId}' specified in course config. Falling back to ELO.`,
|
|
1321
|
-
e
|
|
1322
|
-
);
|
|
1323
|
-
}
|
|
3058
|
+
const allStrategies = await this.getAllNavigationStrategies();
|
|
3059
|
+
if (allStrategies.length === 0) {
|
|
3060
|
+
logger.debug(
|
|
3061
|
+
"[courseDB] No strategy documents found, using default Pipeline(Composite(ELO, SRS), [eloDistanceFilter])"
|
|
3062
|
+
);
|
|
3063
|
+
return this.createDefaultPipeline(user);
|
|
1324
3064
|
}
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
3065
|
+
const assembler = new PipelineAssembler();
|
|
3066
|
+
const { pipeline, generatorStrategies, filterStrategies, warnings } = await assembler.assemble({
|
|
3067
|
+
strategies: allStrategies,
|
|
3068
|
+
user,
|
|
3069
|
+
course: this
|
|
3070
|
+
});
|
|
3071
|
+
for (const warning of warnings) {
|
|
3072
|
+
logger.warn(`[PipelineAssembler] ${warning}`);
|
|
3073
|
+
}
|
|
3074
|
+
if (!pipeline) {
|
|
3075
|
+
logger.debug("[courseDB] Pipeline assembly failed, using default pipeline");
|
|
3076
|
+
return this.createDefaultPipeline(user);
|
|
3077
|
+
}
|
|
3078
|
+
logger.debug(
|
|
3079
|
+
`[courseDB] Using assembled pipeline with ${generatorStrategies.length} generator(s) and ${filterStrategies.length} filter(s)`
|
|
1329
3080
|
);
|
|
3081
|
+
return pipeline;
|
|
3082
|
+
} catch (e) {
|
|
3083
|
+
logger.error(`[courseDB] Error creating navigator: ${e}`);
|
|
3084
|
+
throw e;
|
|
1330
3085
|
}
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
3086
|
+
}
|
|
3087
|
+
makeDefaultEloStrategy() {
|
|
3088
|
+
return {
|
|
3089
|
+
_id: "NAVIGATION_STRATEGY-ELO-default",
|
|
1334
3090
|
docType: "NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */,
|
|
1335
|
-
name: "ELO",
|
|
1336
|
-
description: "ELO-based navigation strategy",
|
|
3091
|
+
name: "ELO (default)",
|
|
3092
|
+
description: "Default ELO-based navigation strategy for new cards",
|
|
1337
3093
|
implementingClass: "elo" /* ELO */,
|
|
1338
3094
|
course: this.id,
|
|
1339
3095
|
serializedData: ""
|
|
1340
|
-
// serde is a noop for ELO navigator.
|
|
1341
3096
|
};
|
|
1342
|
-
|
|
3097
|
+
}
|
|
3098
|
+
makeDefaultSrsStrategy() {
|
|
3099
|
+
return {
|
|
3100
|
+
_id: "NAVIGATION_STRATEGY-SRS-default",
|
|
3101
|
+
docType: "NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */,
|
|
3102
|
+
name: "SRS (default)",
|
|
3103
|
+
description: "Default SRS-based navigation strategy for reviews",
|
|
3104
|
+
implementingClass: "srs" /* SRS */,
|
|
3105
|
+
course: this.id,
|
|
3106
|
+
serializedData: ""
|
|
3107
|
+
};
|
|
3108
|
+
}
|
|
3109
|
+
/**
|
|
3110
|
+
* Creates the default navigation pipeline for courses with no configured strategies.
|
|
3111
|
+
*
|
|
3112
|
+
* Default: Pipeline(Composite(ELO, SRS), [eloDistanceFilter])
|
|
3113
|
+
* - ELO generator: scores new cards by skill proximity
|
|
3114
|
+
* - SRS generator: scores reviews by overdueness and interval recency
|
|
3115
|
+
* - ELO distance filter: penalizes cards far from user's current level
|
|
3116
|
+
*/
|
|
3117
|
+
createDefaultPipeline(user) {
|
|
3118
|
+
const eloNavigator = new ELONavigator(user, this, this.makeDefaultEloStrategy());
|
|
3119
|
+
const srsNavigator = new SRSNavigator(user, this, this.makeDefaultSrsStrategy());
|
|
3120
|
+
const compositeGenerator = new CompositeGenerator([eloNavigator, srsNavigator]);
|
|
3121
|
+
const eloDistanceFilter = createEloDistanceFilter();
|
|
3122
|
+
return new Pipeline(compositeGenerator, [eloDistanceFilter], user, this);
|
|
1343
3123
|
}
|
|
1344
3124
|
////////////////////////////////////
|
|
1345
3125
|
// END NavigationStrategyManager implementation
|
|
@@ -1350,22 +3130,39 @@ ${above.rows.map((r) => ` ${r.id}-${r.key}
|
|
|
1350
3130
|
async getNewCards(limit = 99) {
|
|
1351
3131
|
const u = await this._getCurrentUser();
|
|
1352
3132
|
try {
|
|
1353
|
-
const
|
|
1354
|
-
const navigator = await ContentNavigator.create(u, this, strategy);
|
|
3133
|
+
const navigator = await this.createNavigator(u);
|
|
1355
3134
|
return navigator.getNewCards(limit);
|
|
1356
3135
|
} catch (e) {
|
|
1357
|
-
logger.error(`[courseDB] Error
|
|
3136
|
+
logger.error(`[courseDB] Error in getNewCards: ${e}`);
|
|
1358
3137
|
throw e;
|
|
1359
3138
|
}
|
|
1360
3139
|
}
|
|
1361
3140
|
async getPendingReviews() {
|
|
1362
3141
|
const u = await this._getCurrentUser();
|
|
1363
3142
|
try {
|
|
1364
|
-
const
|
|
1365
|
-
const navigator = await ContentNavigator.create(u, this, strategy);
|
|
3143
|
+
const navigator = await this.createNavigator(u);
|
|
1366
3144
|
return navigator.getPendingReviews();
|
|
1367
3145
|
} catch (e) {
|
|
1368
|
-
logger.error(`[courseDB] Error
|
|
3146
|
+
logger.error(`[courseDB] Error in getPendingReviews: ${e}`);
|
|
3147
|
+
throw e;
|
|
3148
|
+
}
|
|
3149
|
+
}
|
|
3150
|
+
/**
|
|
3151
|
+
* Get cards with suitability scores for presentation.
|
|
3152
|
+
*
|
|
3153
|
+
* This is the PRIMARY API for content sources going forward. Delegates to the
|
|
3154
|
+
* course's configured NavigationStrategy to get scored candidates.
|
|
3155
|
+
*
|
|
3156
|
+
* @param limit - Maximum number of cards to return
|
|
3157
|
+
* @returns Cards sorted by score descending
|
|
3158
|
+
*/
|
|
3159
|
+
async getWeightedCards(limit) {
|
|
3160
|
+
const u = await this._getCurrentUser();
|
|
3161
|
+
try {
|
|
3162
|
+
const navigator = await this.createNavigator(u);
|
|
3163
|
+
return navigator.getWeightedCards(limit);
|
|
3164
|
+
} catch (e) {
|
|
3165
|
+
logger.error(`[courseDB] Error getting weighted cards: ${e}`);
|
|
1369
3166
|
throw e;
|
|
1370
3167
|
}
|
|
1371
3168
|
}
|
|
@@ -1505,7 +3302,7 @@ ${above.rows.map((r) => ` ${r.id}-${r.key}
|
|
|
1505
3302
|
});
|
|
1506
3303
|
|
|
1507
3304
|
// src/impl/couch/classroomDB.ts
|
|
1508
|
-
import
|
|
3305
|
+
import moment4 from "moment";
|
|
1509
3306
|
var CLASSROOM_CONFIG, ClassroomDBBase, StudentClassroomDB;
|
|
1510
3307
|
var init_classroomDB2 = __esm({
|
|
1511
3308
|
"src/impl/couch/classroomDB.ts"() {
|
|
@@ -1605,9 +3402,9 @@ var init_classroomDB2 = __esm({
|
|
|
1605
3402
|
}
|
|
1606
3403
|
async getNewCards() {
|
|
1607
3404
|
const activeCards = await this._user.getActiveCards();
|
|
1608
|
-
const now =
|
|
3405
|
+
const now = moment4.utc();
|
|
1609
3406
|
const assigned = await this.getAssignedContent();
|
|
1610
|
-
const due = assigned.filter((c) => now.isAfter(
|
|
3407
|
+
const due = assigned.filter((c) => now.isAfter(moment4.utc(c.activeOn, REVIEW_TIME_FORMAT2)));
|
|
1611
3408
|
logger.info(`Due content: ${JSON.stringify(due)}`);
|
|
1612
3409
|
let ret = [];
|
|
1613
3410
|
for (let i = 0; i < due.length; i++) {
|
|
@@ -1644,6 +3441,52 @@ var init_classroomDB2 = __esm({
|
|
|
1644
3441
|
}
|
|
1645
3442
|
});
|
|
1646
3443
|
}
|
|
3444
|
+
/**
|
|
3445
|
+
* Get cards with suitability scores for presentation.
|
|
3446
|
+
*
|
|
3447
|
+
* This implementation wraps the legacy getNewCards/getPendingReviews methods,
|
|
3448
|
+
* assigning score=1.0 to all cards. StudentClassroomDB does not currently
|
|
3449
|
+
* support pluggable navigation strategies.
|
|
3450
|
+
*
|
|
3451
|
+
* @param limit - Maximum number of cards to return
|
|
3452
|
+
* @returns Cards sorted by score descending (all scores = 1.0)
|
|
3453
|
+
*/
|
|
3454
|
+
async getWeightedCards(limit) {
|
|
3455
|
+
const [newCards, reviews] = await Promise.all([this.getNewCards(), this.getPendingReviews()]);
|
|
3456
|
+
const weighted = [
|
|
3457
|
+
...newCards.map((c) => ({
|
|
3458
|
+
cardId: c.cardID,
|
|
3459
|
+
courseId: c.courseID,
|
|
3460
|
+
score: 1,
|
|
3461
|
+
provenance: [
|
|
3462
|
+
{
|
|
3463
|
+
strategy: "classroom",
|
|
3464
|
+
strategyName: "Classroom",
|
|
3465
|
+
strategyId: "CLASSROOM",
|
|
3466
|
+
action: "generated",
|
|
3467
|
+
score: 1,
|
|
3468
|
+
reason: "Classroom legacy getNewCards(), new card"
|
|
3469
|
+
}
|
|
3470
|
+
]
|
|
3471
|
+
})),
|
|
3472
|
+
...reviews.map((r) => ({
|
|
3473
|
+
cardId: r.cardID,
|
|
3474
|
+
courseId: r.courseID,
|
|
3475
|
+
score: 1,
|
|
3476
|
+
provenance: [
|
|
3477
|
+
{
|
|
3478
|
+
strategy: "classroom",
|
|
3479
|
+
strategyName: "Classroom",
|
|
3480
|
+
strategyId: "CLASSROOM",
|
|
3481
|
+
action: "generated",
|
|
3482
|
+
score: 1,
|
|
3483
|
+
reason: "Classroom legacy getPendingReviews(), review"
|
|
3484
|
+
}
|
|
3485
|
+
]
|
|
3486
|
+
}))
|
|
3487
|
+
];
|
|
3488
|
+
return weighted.slice(0, limit);
|
|
3489
|
+
}
|
|
1647
3490
|
};
|
|
1648
3491
|
}
|
|
1649
3492
|
});
|
|
@@ -1688,7 +3531,7 @@ var init_CouchDBSyncStrategy = __esm({
|
|
|
1688
3531
|
|
|
1689
3532
|
// src/impl/couch/index.ts
|
|
1690
3533
|
import fetch2 from "cross-fetch";
|
|
1691
|
-
import
|
|
3534
|
+
import moment5 from "moment";
|
|
1692
3535
|
import process2 from "process";
|
|
1693
3536
|
function createPouchDBConfig() {
|
|
1694
3537
|
const hasExplicitCredentials = ENV.COUCHDB_USERNAME && ENV.COUCHDB_PASSWORD;
|
|
@@ -1773,7 +3616,7 @@ var init_couch = __esm({
|
|
|
1773
3616
|
|
|
1774
3617
|
// src/impl/common/BaseUserDB.ts
|
|
1775
3618
|
import { Status as Status3 } from "@vue-skuilder/common";
|
|
1776
|
-
import
|
|
3619
|
+
import moment6 from "moment";
|
|
1777
3620
|
async function getOrCreateClassroomRegistrationsDoc(user) {
|
|
1778
3621
|
let ret;
|
|
1779
3622
|
try {
|
|
@@ -2132,7 +3975,7 @@ Currently logged-in as ${this._username}.`
|
|
|
2132
3975
|
);
|
|
2133
3976
|
return reviews.rows.filter((r) => {
|
|
2134
3977
|
if (r.id.startsWith(DocTypePrefixes["SCHEDULED_CARD" /* SCHEDULED_CARD */])) {
|
|
2135
|
-
const date =
|
|
3978
|
+
const date = moment6.utc(
|
|
2136
3979
|
r.id.substr(DocTypePrefixes["SCHEDULED_CARD" /* SCHEDULED_CARD */].length),
|
|
2137
3980
|
REVIEW_TIME_FORMAT
|
|
2138
3981
|
);
|
|
@@ -2145,11 +3988,11 @@ Currently logged-in as ${this._username}.`
|
|
|
2145
3988
|
}).map((r) => r.doc);
|
|
2146
3989
|
}
|
|
2147
3990
|
async getReviewsForcast(daysCount) {
|
|
2148
|
-
const time =
|
|
3991
|
+
const time = moment6.utc().add(daysCount, "days");
|
|
2149
3992
|
return this.getReviewstoDate(time);
|
|
2150
3993
|
}
|
|
2151
3994
|
async getPendingReviews(course_id) {
|
|
2152
|
-
const now =
|
|
3995
|
+
const now = moment6.utc();
|
|
2153
3996
|
return this.getReviewstoDate(now, course_id);
|
|
2154
3997
|
}
|
|
2155
3998
|
async getScheduledReviewCount(course_id) {
|
|
@@ -2436,7 +4279,7 @@ Currently logged-in as ${this._username}.`
|
|
|
2436
4279
|
*/
|
|
2437
4280
|
async putCardRecord(record) {
|
|
2438
4281
|
const cardHistoryID = getCardHistoryID(record.courseID, record.cardID);
|
|
2439
|
-
record.timeStamp =
|
|
4282
|
+
record.timeStamp = moment6.utc(record.timeStamp).toString();
|
|
2440
4283
|
try {
|
|
2441
4284
|
const cardHistory = await this.update(
|
|
2442
4285
|
cardHistoryID,
|
|
@@ -2452,7 +4295,7 @@ Currently logged-in as ${this._username}.`
|
|
|
2452
4295
|
const ret = {
|
|
2453
4296
|
...record2
|
|
2454
4297
|
};
|
|
2455
|
-
ret.timeStamp =
|
|
4298
|
+
ret.timeStamp = moment6.utc(record2.timeStamp);
|
|
2456
4299
|
return ret;
|
|
2457
4300
|
});
|
|
2458
4301
|
return cardHistory;
|
|
@@ -2676,6 +4519,55 @@ Currently logged-in as ${this._username}.`
|
|
|
2676
4519
|
async updateUserElo(courseId, elo) {
|
|
2677
4520
|
return updateUserElo(this._username, courseId, elo);
|
|
2678
4521
|
}
|
|
4522
|
+
async getStrategyState(courseId, strategyKey) {
|
|
4523
|
+
const docId = buildStrategyStateId(courseId, strategyKey);
|
|
4524
|
+
try {
|
|
4525
|
+
const doc = await this.localDB.get(docId);
|
|
4526
|
+
return doc.data;
|
|
4527
|
+
} catch (e) {
|
|
4528
|
+
const err = e;
|
|
4529
|
+
if (err.status === 404) {
|
|
4530
|
+
return null;
|
|
4531
|
+
}
|
|
4532
|
+
throw e;
|
|
4533
|
+
}
|
|
4534
|
+
}
|
|
4535
|
+
async putStrategyState(courseId, strategyKey, data) {
|
|
4536
|
+
const docId = buildStrategyStateId(courseId, strategyKey);
|
|
4537
|
+
let existingRev;
|
|
4538
|
+
try {
|
|
4539
|
+
const existing = await this.localDB.get(docId);
|
|
4540
|
+
existingRev = existing._rev;
|
|
4541
|
+
} catch (e) {
|
|
4542
|
+
const err = e;
|
|
4543
|
+
if (err.status !== 404) {
|
|
4544
|
+
throw e;
|
|
4545
|
+
}
|
|
4546
|
+
}
|
|
4547
|
+
const doc = {
|
|
4548
|
+
_id: docId,
|
|
4549
|
+
_rev: existingRev,
|
|
4550
|
+
docType: "STRATEGY_STATE" /* STRATEGY_STATE */,
|
|
4551
|
+
courseId,
|
|
4552
|
+
strategyKey,
|
|
4553
|
+
data,
|
|
4554
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
4555
|
+
};
|
|
4556
|
+
await this.localDB.put(doc);
|
|
4557
|
+
}
|
|
4558
|
+
async deleteStrategyState(courseId, strategyKey) {
|
|
4559
|
+
const docId = buildStrategyStateId(courseId, strategyKey);
|
|
4560
|
+
try {
|
|
4561
|
+
const doc = await this.localDB.get(docId);
|
|
4562
|
+
await this.localDB.remove(doc);
|
|
4563
|
+
} catch (e) {
|
|
4564
|
+
const err = e;
|
|
4565
|
+
if (err.status === 404) {
|
|
4566
|
+
return;
|
|
4567
|
+
}
|
|
4568
|
+
throw e;
|
|
4569
|
+
}
|
|
4570
|
+
}
|
|
2679
4571
|
};
|
|
2680
4572
|
userCoursesDoc = "CourseRegistrations";
|
|
2681
4573
|
userClassroomsDoc = "ClassroomRegistrations";
|
|
@@ -2715,7 +4607,215 @@ var init_factory = __esm({
|
|
|
2715
4607
|
}
|
|
2716
4608
|
});
|
|
2717
4609
|
|
|
4610
|
+
// src/study/TagFilteredContentSource.ts
|
|
4611
|
+
import { hasActiveFilter } from "@vue-skuilder/common";
|
|
4612
|
+
var TagFilteredContentSource;
|
|
4613
|
+
var init_TagFilteredContentSource = __esm({
|
|
4614
|
+
"src/study/TagFilteredContentSource.ts"() {
|
|
4615
|
+
"use strict";
|
|
4616
|
+
init_courseDB();
|
|
4617
|
+
init_logger();
|
|
4618
|
+
TagFilteredContentSource = class {
|
|
4619
|
+
courseId;
|
|
4620
|
+
filter;
|
|
4621
|
+
user;
|
|
4622
|
+
// Cache resolved card IDs to avoid repeated lookups within a session
|
|
4623
|
+
resolvedCardIds = null;
|
|
4624
|
+
constructor(courseId, filter, user) {
|
|
4625
|
+
this.courseId = courseId;
|
|
4626
|
+
this.filter = filter;
|
|
4627
|
+
this.user = user;
|
|
4628
|
+
logger.info(
|
|
4629
|
+
`[TagFilteredContentSource] Created for course "${courseId}" with filter:`,
|
|
4630
|
+
JSON.stringify(filter)
|
|
4631
|
+
);
|
|
4632
|
+
}
|
|
4633
|
+
/**
|
|
4634
|
+
* Resolves the TagFilter to a set of eligible card IDs.
|
|
4635
|
+
*
|
|
4636
|
+
* - Cards in `include` tags are OR'd together (card needs at least one)
|
|
4637
|
+
* - Cards in `exclude` tags are removed from the result
|
|
4638
|
+
*/
|
|
4639
|
+
async resolveFilteredCardIds() {
|
|
4640
|
+
if (this.resolvedCardIds !== null) {
|
|
4641
|
+
return this.resolvedCardIds;
|
|
4642
|
+
}
|
|
4643
|
+
const includedCardIds = /* @__PURE__ */ new Set();
|
|
4644
|
+
if (this.filter.include.length > 0) {
|
|
4645
|
+
for (const tagName of this.filter.include) {
|
|
4646
|
+
try {
|
|
4647
|
+
const tagDoc = await getTag(this.courseId, tagName);
|
|
4648
|
+
tagDoc.taggedCards.forEach((cardId) => includedCardIds.add(cardId));
|
|
4649
|
+
} catch (error) {
|
|
4650
|
+
logger.warn(
|
|
4651
|
+
`[TagFilteredContentSource] Could not resolve tag "${tagName}" for inclusion:`,
|
|
4652
|
+
error
|
|
4653
|
+
);
|
|
4654
|
+
}
|
|
4655
|
+
}
|
|
4656
|
+
}
|
|
4657
|
+
if (includedCardIds.size === 0 && this.filter.include.length > 0) {
|
|
4658
|
+
logger.warn(
|
|
4659
|
+
`[TagFilteredContentSource] No cards found for include tags: ${this.filter.include.join(", ")}`
|
|
4660
|
+
);
|
|
4661
|
+
this.resolvedCardIds = /* @__PURE__ */ new Set();
|
|
4662
|
+
return this.resolvedCardIds;
|
|
4663
|
+
}
|
|
4664
|
+
const excludedCardIds = /* @__PURE__ */ new Set();
|
|
4665
|
+
if (this.filter.exclude.length > 0) {
|
|
4666
|
+
for (const tagName of this.filter.exclude) {
|
|
4667
|
+
try {
|
|
4668
|
+
const tagDoc = await getTag(this.courseId, tagName);
|
|
4669
|
+
tagDoc.taggedCards.forEach((cardId) => excludedCardIds.add(cardId));
|
|
4670
|
+
} catch (error) {
|
|
4671
|
+
logger.warn(
|
|
4672
|
+
`[TagFilteredContentSource] Could not resolve tag "${tagName}" for exclusion:`,
|
|
4673
|
+
error
|
|
4674
|
+
);
|
|
4675
|
+
}
|
|
4676
|
+
}
|
|
4677
|
+
}
|
|
4678
|
+
const finalCardIds = /* @__PURE__ */ new Set();
|
|
4679
|
+
for (const cardId of includedCardIds) {
|
|
4680
|
+
if (!excludedCardIds.has(cardId)) {
|
|
4681
|
+
finalCardIds.add(cardId);
|
|
4682
|
+
}
|
|
4683
|
+
}
|
|
4684
|
+
logger.info(
|
|
4685
|
+
`[TagFilteredContentSource] Resolved ${finalCardIds.size} cards (included: ${includedCardIds.size}, excluded: ${excludedCardIds.size})`
|
|
4686
|
+
);
|
|
4687
|
+
this.resolvedCardIds = finalCardIds;
|
|
4688
|
+
return finalCardIds;
|
|
4689
|
+
}
|
|
4690
|
+
/**
|
|
4691
|
+
* Gets new cards that match the tag filter and are not already active for the user.
|
|
4692
|
+
*/
|
|
4693
|
+
async getNewCards(limit) {
|
|
4694
|
+
if (!hasActiveFilter(this.filter)) {
|
|
4695
|
+
logger.warn("[TagFilteredContentSource] getNewCards called with no active filter");
|
|
4696
|
+
return [];
|
|
4697
|
+
}
|
|
4698
|
+
const eligibleCardIds = await this.resolveFilteredCardIds();
|
|
4699
|
+
const activeCards = await this.user.getActiveCards();
|
|
4700
|
+
const activeCardIds = new Set(activeCards.map((c) => c.cardID));
|
|
4701
|
+
const newItems = [];
|
|
4702
|
+
for (const cardId of eligibleCardIds) {
|
|
4703
|
+
if (!activeCardIds.has(cardId)) {
|
|
4704
|
+
newItems.push({
|
|
4705
|
+
courseID: this.courseId,
|
|
4706
|
+
cardID: cardId,
|
|
4707
|
+
contentSourceType: "course",
|
|
4708
|
+
contentSourceID: this.courseId,
|
|
4709
|
+
status: "new"
|
|
4710
|
+
});
|
|
4711
|
+
}
|
|
4712
|
+
if (limit !== void 0 && newItems.length >= limit) {
|
|
4713
|
+
break;
|
|
4714
|
+
}
|
|
4715
|
+
}
|
|
4716
|
+
logger.info(`[TagFilteredContentSource] Found ${newItems.length} new cards matching filter`);
|
|
4717
|
+
return newItems;
|
|
4718
|
+
}
|
|
4719
|
+
/**
|
|
4720
|
+
* Gets pending reviews, filtered to only include cards that match the tag filter.
|
|
4721
|
+
*/
|
|
4722
|
+
async getPendingReviews() {
|
|
4723
|
+
if (!hasActiveFilter(this.filter)) {
|
|
4724
|
+
logger.warn("[TagFilteredContentSource] getPendingReviews called with no active filter");
|
|
4725
|
+
return [];
|
|
4726
|
+
}
|
|
4727
|
+
const eligibleCardIds = await this.resolveFilteredCardIds();
|
|
4728
|
+
const allReviews = await this.user.getPendingReviews(this.courseId);
|
|
4729
|
+
const filteredReviews = allReviews.filter((review) => {
|
|
4730
|
+
return eligibleCardIds.has(review.cardId);
|
|
4731
|
+
});
|
|
4732
|
+
logger.info(
|
|
4733
|
+
`[TagFilteredContentSource] Found ${filteredReviews.length} pending reviews matching filter (of ${allReviews.length} total)`
|
|
4734
|
+
);
|
|
4735
|
+
return filteredReviews.map((r) => ({
|
|
4736
|
+
...r,
|
|
4737
|
+
courseID: r.courseId,
|
|
4738
|
+
cardID: r.cardId,
|
|
4739
|
+
contentSourceType: "course",
|
|
4740
|
+
contentSourceID: this.courseId,
|
|
4741
|
+
reviewID: r._id,
|
|
4742
|
+
status: "review"
|
|
4743
|
+
}));
|
|
4744
|
+
}
|
|
4745
|
+
/**
|
|
4746
|
+
* Get cards with suitability scores for presentation.
|
|
4747
|
+
*
|
|
4748
|
+
* This implementation wraps the legacy getNewCards/getPendingReviews methods,
|
|
4749
|
+
* assigning score=1.0 to all cards. TagFilteredContentSource does not currently
|
|
4750
|
+
* support pluggable navigation strategies - it returns flat-scored candidates.
|
|
4751
|
+
*
|
|
4752
|
+
* @param limit - Maximum number of cards to return
|
|
4753
|
+
* @returns Cards sorted by score descending (all scores = 1.0)
|
|
4754
|
+
*/
|
|
4755
|
+
async getWeightedCards(limit) {
|
|
4756
|
+
const [newCards, reviews] = await Promise.all([
|
|
4757
|
+
this.getNewCards(limit),
|
|
4758
|
+
this.getPendingReviews()
|
|
4759
|
+
]);
|
|
4760
|
+
const weighted = [
|
|
4761
|
+
...reviews.map((r) => ({
|
|
4762
|
+
cardId: r.cardID,
|
|
4763
|
+
courseId: r.courseID,
|
|
4764
|
+
score: 1,
|
|
4765
|
+
provenance: [
|
|
4766
|
+
{
|
|
4767
|
+
strategy: "tagFilter",
|
|
4768
|
+
strategyName: "Tag Filter",
|
|
4769
|
+
strategyId: "TAG_FILTER",
|
|
4770
|
+
action: "generated",
|
|
4771
|
+
score: 1,
|
|
4772
|
+
reason: `Tag-filtered review (tags: ${this.filter.include.join(", ")})`
|
|
4773
|
+
}
|
|
4774
|
+
]
|
|
4775
|
+
})),
|
|
4776
|
+
...newCards.map((c) => ({
|
|
4777
|
+
cardId: c.cardID,
|
|
4778
|
+
courseId: c.courseID,
|
|
4779
|
+
score: 1,
|
|
4780
|
+
provenance: [
|
|
4781
|
+
{
|
|
4782
|
+
strategy: "tagFilter",
|
|
4783
|
+
strategyName: "Tag Filter",
|
|
4784
|
+
strategyId: "TAG_FILTER",
|
|
4785
|
+
action: "generated",
|
|
4786
|
+
score: 1,
|
|
4787
|
+
reason: `Tag-filtered new card (tags: ${this.filter.include.join(", ")})`
|
|
4788
|
+
}
|
|
4789
|
+
]
|
|
4790
|
+
}))
|
|
4791
|
+
];
|
|
4792
|
+
return weighted.slice(0, limit);
|
|
4793
|
+
}
|
|
4794
|
+
/**
|
|
4795
|
+
* Clears the cached resolved card IDs.
|
|
4796
|
+
* Call this if the underlying tag data may have changed during a session.
|
|
4797
|
+
*/
|
|
4798
|
+
clearCache() {
|
|
4799
|
+
this.resolvedCardIds = null;
|
|
4800
|
+
}
|
|
4801
|
+
/**
|
|
4802
|
+
* Returns the course ID this source is filtering.
|
|
4803
|
+
*/
|
|
4804
|
+
getCourseId() {
|
|
4805
|
+
return this.courseId;
|
|
4806
|
+
}
|
|
4807
|
+
/**
|
|
4808
|
+
* Returns the active tag filter.
|
|
4809
|
+
*/
|
|
4810
|
+
getFilter() {
|
|
4811
|
+
return this.filter;
|
|
4812
|
+
}
|
|
4813
|
+
};
|
|
4814
|
+
}
|
|
4815
|
+
});
|
|
4816
|
+
|
|
2718
4817
|
// src/core/interfaces/contentSource.ts
|
|
4818
|
+
import { hasActiveFilter as hasActiveFilter2 } from "@vue-skuilder/common";
|
|
2719
4819
|
function isReview(item) {
|
|
2720
4820
|
const ret = item.status === "review" || item.status === "failed-review" || "reviewID" in item;
|
|
2721
4821
|
return ret;
|
|
@@ -2724,6 +4824,9 @@ async function getStudySource(source, user) {
|
|
|
2724
4824
|
if (source.type === "classroom") {
|
|
2725
4825
|
return await StudentClassroomDB.factory(source.id, user);
|
|
2726
4826
|
} else {
|
|
4827
|
+
if (hasActiveFilter2(source.tagFilter)) {
|
|
4828
|
+
return new TagFilteredContentSource(source.id, source.tagFilter, user);
|
|
4829
|
+
}
|
|
2727
4830
|
return getDataLayer().getCourseDB(source.id);
|
|
2728
4831
|
}
|
|
2729
4832
|
}
|
|
@@ -2732,6 +4835,7 @@ var init_contentSource = __esm({
|
|
|
2732
4835
|
"use strict";
|
|
2733
4836
|
init_factory();
|
|
2734
4837
|
init_classroomDB2();
|
|
4838
|
+
init_TagFilteredContentSource();
|
|
2735
4839
|
}
|
|
2736
4840
|
});
|
|
2737
4841
|
|
|
@@ -2776,6 +4880,16 @@ var init_user = __esm({
|
|
|
2776
4880
|
}
|
|
2777
4881
|
});
|
|
2778
4882
|
|
|
4883
|
+
// src/core/types/strategyState.ts
|
|
4884
|
+
function buildStrategyStateId(courseId, strategyKey) {
|
|
4885
|
+
return `STRATEGY_STATE::${courseId}::${strategyKey}`;
|
|
4886
|
+
}
|
|
4887
|
+
var init_strategyState = __esm({
|
|
4888
|
+
"src/core/types/strategyState.ts"() {
|
|
4889
|
+
"use strict";
|
|
4890
|
+
}
|
|
4891
|
+
});
|
|
4892
|
+
|
|
2779
4893
|
// src/core/bulkImport/cardProcessor.ts
|
|
2780
4894
|
import { Status as Status4 } from "@vue-skuilder/common";
|
|
2781
4895
|
async function importParsedCards(parsedCards, courseDB, config) {
|
|
@@ -2897,7 +5011,7 @@ var init_cardProcessor = __esm({
|
|
|
2897
5011
|
});
|
|
2898
5012
|
|
|
2899
5013
|
// src/core/bulkImport/types.ts
|
|
2900
|
-
var
|
|
5014
|
+
var init_types3 = __esm({
|
|
2901
5015
|
"src/core/bulkImport/types.ts"() {
|
|
2902
5016
|
"use strict";
|
|
2903
5017
|
}
|
|
@@ -2908,7 +5022,7 @@ var init_bulkImport = __esm({
|
|
|
2908
5022
|
"src/core/bulkImport/index.ts"() {
|
|
2909
5023
|
"use strict";
|
|
2910
5024
|
init_cardProcessor();
|
|
2911
|
-
|
|
5025
|
+
init_types3();
|
|
2912
5026
|
}
|
|
2913
5027
|
});
|
|
2914
5028
|
|
|
@@ -2918,6 +5032,7 @@ var init_core = __esm({
|
|
|
2918
5032
|
init_interfaces();
|
|
2919
5033
|
init_types_legacy();
|
|
2920
5034
|
init_user();
|
|
5035
|
+
init_strategyState();
|
|
2921
5036
|
init_Loggable();
|
|
2922
5037
|
init_util();
|
|
2923
5038
|
init_navigators();
|
|
@@ -2931,12 +5046,18 @@ export {
|
|
|
2931
5046
|
DocTypePrefixes,
|
|
2932
5047
|
GuestUsername,
|
|
2933
5048
|
Loggable,
|
|
5049
|
+
NavigatorRole,
|
|
5050
|
+
NavigatorRoles,
|
|
2934
5051
|
Navigators,
|
|
2935
5052
|
areQuestionRecords,
|
|
5053
|
+
buildStrategyStateId,
|
|
2936
5054
|
docIsDeleted,
|
|
2937
5055
|
getCardHistoryID,
|
|
5056
|
+
getCardOrigin,
|
|
2938
5057
|
getStudySource,
|
|
2939
5058
|
importParsedCards,
|
|
5059
|
+
isFilter,
|
|
5060
|
+
isGenerator,
|
|
2940
5061
|
isQuestionRecord,
|
|
2941
5062
|
isReview,
|
|
2942
5063
|
log,
|