@vue-skuilder/db 0.1.16 → 0.1.18
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-DNa0XPtn.d.ts → classroomDB-BgfrVb8d.d.ts} +357 -103
- package/dist/{userDB-BqwxtJ_7.d.mts → classroomDB-CTOenngH.d.cts} +358 -104
- package/dist/core/index.d.cts +230 -0
- package/dist/core/index.d.ts +161 -23
- package/dist/core/index.js +1964 -154
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.mjs +1925 -121
- package/dist/core/index.mjs.map +1 -1
- package/dist/{dataLayerProvider-BV5iZqt_.d.ts → dataLayerProvider-CZxC9GtB.d.ts} +1 -1
- package/dist/{dataLayerProvider-VlngD19_.d.mts → dataLayerProvider-D6PoCwS6.d.cts} +1 -1
- package/dist/impl/couch/{index.d.mts → index.d.cts} +46 -5
- package/dist/impl/couch/index.d.ts +44 -3
- package/dist/impl/couch/index.js +1971 -171
- package/dist/impl/couch/index.js.map +1 -1
- package/dist/impl/couch/index.mjs +1933 -134
- package/dist/impl/couch/index.mjs.map +1 -1
- package/dist/impl/static/{index.d.mts → index.d.cts} +5 -6
- package/dist/impl/static/index.d.ts +2 -3
- package/dist/impl/static/index.js +1614 -119
- package/dist/impl/static/index.js.map +1 -1
- package/dist/impl/static/index.mjs +1585 -92
- package/dist/impl/static/index.mjs.map +1 -1
- package/dist/{index-Bmll7Xse.d.mts → index-D-Fa4Smt.d.cts} +1 -1
- package/dist/{index.d.mts → index.d.cts} +97 -13
- package/dist/index.d.ts +90 -6
- package/dist/index.js +2085 -153
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2031 -106
- package/dist/index.mjs.map +1 -1
- package/dist/pouch/index.js +3 -3
- package/dist/{types-Dbp5DaRR.d.mts → types-CzPDLAK6.d.cts} +1 -1
- package/dist/util/packer/{index.d.mts → index.d.cts} +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 +265 -0
- package/docs/todo-evolutionary-orchestration.md +310 -0
- package/docs/todo-nominal-tag-types.md +121 -0
- package/docs/todo-pipeline-optimization.md +117 -0
- package/docs/todo-strategy-authoring.md +401 -0
- package/docs/todo-strategy-state-storage.md +278 -0
- package/eslint.config.mjs +1 -1
- package/package.json +9 -4
- package/src/core/interfaces/contentSource.ts +88 -4
- package/src/core/interfaces/navigationStrategyManager.ts +0 -5
- package/src/core/navigators/CompositeGenerator.ts +268 -0
- package/src/core/navigators/Pipeline.ts +205 -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 +6 -0
- package/src/core/navigators/filters/types.ts +115 -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 +345 -3
- package/src/core/navigators/interferenceMitigator.ts +367 -0
- package/src/core/navigators/relativePriority.ts +267 -0
- package/src/core/navigators/srs.ts +195 -0
- package/src/impl/couch/classroomDB.ts +51 -0
- package/src/impl/couch/courseDB.ts +117 -39
- package/src/impl/static/courseDB.ts +0 -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 +405 -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/{types-legacy-6ettoclI.d.mts → types-legacy-6ettoclI.d.cts} +0 -0
package/dist/core/index.mjs
CHANGED
|
@@ -686,23 +686,460 @@ var init_courseLookupDB = __esm({
|
|
|
686
686
|
}
|
|
687
687
|
});
|
|
688
688
|
|
|
689
|
+
// src/core/navigators/CompositeGenerator.ts
|
|
690
|
+
var CompositeGenerator_exports = {};
|
|
691
|
+
__export(CompositeGenerator_exports, {
|
|
692
|
+
AggregationMode: () => AggregationMode,
|
|
693
|
+
default: () => CompositeGenerator
|
|
694
|
+
});
|
|
695
|
+
var AggregationMode, DEFAULT_AGGREGATION_MODE, FREQUENCY_BOOST_FACTOR, CompositeGenerator;
|
|
696
|
+
var init_CompositeGenerator = __esm({
|
|
697
|
+
"src/core/navigators/CompositeGenerator.ts"() {
|
|
698
|
+
"use strict";
|
|
699
|
+
init_navigators();
|
|
700
|
+
init_logger();
|
|
701
|
+
AggregationMode = /* @__PURE__ */ ((AggregationMode2) => {
|
|
702
|
+
AggregationMode2["MAX"] = "max";
|
|
703
|
+
AggregationMode2["AVERAGE"] = "average";
|
|
704
|
+
AggregationMode2["FREQUENCY_BOOST"] = "frequencyBoost";
|
|
705
|
+
return AggregationMode2;
|
|
706
|
+
})(AggregationMode || {});
|
|
707
|
+
DEFAULT_AGGREGATION_MODE = "frequencyBoost" /* FREQUENCY_BOOST */;
|
|
708
|
+
FREQUENCY_BOOST_FACTOR = 0.1;
|
|
709
|
+
CompositeGenerator = class _CompositeGenerator extends ContentNavigator {
|
|
710
|
+
/** Human-readable name for CardGenerator interface */
|
|
711
|
+
name = "Composite Generator";
|
|
712
|
+
generators;
|
|
713
|
+
aggregationMode;
|
|
714
|
+
constructor(generators, aggregationMode = DEFAULT_AGGREGATION_MODE) {
|
|
715
|
+
super();
|
|
716
|
+
this.generators = generators;
|
|
717
|
+
this.aggregationMode = aggregationMode;
|
|
718
|
+
if (generators.length === 0) {
|
|
719
|
+
throw new Error("CompositeGenerator requires at least one generator");
|
|
720
|
+
}
|
|
721
|
+
logger.debug(
|
|
722
|
+
`[CompositeGenerator] Created with ${generators.length} generators, mode: ${aggregationMode}`
|
|
723
|
+
);
|
|
724
|
+
}
|
|
725
|
+
/**
|
|
726
|
+
* Creates a CompositeGenerator from strategy data.
|
|
727
|
+
*
|
|
728
|
+
* This is a convenience factory for use by PipelineAssembler.
|
|
729
|
+
*/
|
|
730
|
+
static async fromStrategies(user, course, strategies, aggregationMode = DEFAULT_AGGREGATION_MODE) {
|
|
731
|
+
const generators = await Promise.all(
|
|
732
|
+
strategies.map((s) => ContentNavigator.create(user, course, s))
|
|
733
|
+
);
|
|
734
|
+
return new _CompositeGenerator(generators, aggregationMode);
|
|
735
|
+
}
|
|
736
|
+
/**
|
|
737
|
+
* Get weighted cards from all generators, merge and deduplicate.
|
|
738
|
+
*
|
|
739
|
+
* Cards appearing in multiple generators receive a score boost.
|
|
740
|
+
* Provenance tracks which generators produced each card and how scores were aggregated.
|
|
741
|
+
*
|
|
742
|
+
* This method supports both the legacy signature (limit only) and the
|
|
743
|
+
* CardGenerator interface signature (limit, context).
|
|
744
|
+
*
|
|
745
|
+
* @param limit - Maximum number of cards to return
|
|
746
|
+
* @param context - Optional GeneratorContext passed to child generators
|
|
747
|
+
*/
|
|
748
|
+
async getWeightedCards(limit, context) {
|
|
749
|
+
const results = await Promise.all(
|
|
750
|
+
this.generators.map((g) => g.getWeightedCards(limit, context))
|
|
751
|
+
);
|
|
752
|
+
const byCardId = /* @__PURE__ */ new Map();
|
|
753
|
+
for (const cards of results) {
|
|
754
|
+
for (const card of cards) {
|
|
755
|
+
const existing = byCardId.get(card.cardId) || [];
|
|
756
|
+
existing.push(card);
|
|
757
|
+
byCardId.set(card.cardId, existing);
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
const merged = [];
|
|
761
|
+
for (const [, cards] of byCardId) {
|
|
762
|
+
const aggregatedScore = this.aggregateScores(cards);
|
|
763
|
+
const finalScore = Math.min(1, aggregatedScore);
|
|
764
|
+
const mergedProvenance = cards.flatMap((c) => c.provenance);
|
|
765
|
+
const initialScore = cards[0].score;
|
|
766
|
+
const action = finalScore > initialScore ? "boosted" : finalScore < initialScore ? "penalized" : "passed";
|
|
767
|
+
const reason = this.buildAggregationReason(cards, finalScore);
|
|
768
|
+
merged.push({
|
|
769
|
+
...cards[0],
|
|
770
|
+
score: finalScore,
|
|
771
|
+
provenance: [
|
|
772
|
+
...mergedProvenance,
|
|
773
|
+
{
|
|
774
|
+
strategy: "composite",
|
|
775
|
+
strategyName: "Composite Generator",
|
|
776
|
+
strategyId: "COMPOSITE_GENERATOR",
|
|
777
|
+
action,
|
|
778
|
+
score: finalScore,
|
|
779
|
+
reason
|
|
780
|
+
}
|
|
781
|
+
]
|
|
782
|
+
});
|
|
783
|
+
}
|
|
784
|
+
return merged.sort((a, b) => b.score - a.score).slice(0, limit);
|
|
785
|
+
}
|
|
786
|
+
/**
|
|
787
|
+
* Build human-readable reason for score aggregation.
|
|
788
|
+
*/
|
|
789
|
+
buildAggregationReason(cards, finalScore) {
|
|
790
|
+
const count = cards.length;
|
|
791
|
+
const scores = cards.map((c) => c.score.toFixed(2)).join(", ");
|
|
792
|
+
if (count === 1) {
|
|
793
|
+
return `Single generator, score ${finalScore.toFixed(2)}`;
|
|
794
|
+
}
|
|
795
|
+
const strategies = cards.map((c) => c.provenance[0]?.strategy || "unknown").join(", ");
|
|
796
|
+
switch (this.aggregationMode) {
|
|
797
|
+
case "max" /* MAX */:
|
|
798
|
+
return `Max of ${count} generators (${strategies}): scores [${scores}] \u2192 ${finalScore.toFixed(2)}`;
|
|
799
|
+
case "average" /* AVERAGE */:
|
|
800
|
+
return `Average of ${count} generators (${strategies}): scores [${scores}] \u2192 ${finalScore.toFixed(2)}`;
|
|
801
|
+
case "frequencyBoost" /* FREQUENCY_BOOST */: {
|
|
802
|
+
const avg = cards.reduce((sum, c) => sum + c.score, 0) / count;
|
|
803
|
+
const boost = 1 + FREQUENCY_BOOST_FACTOR * (count - 1);
|
|
804
|
+
return `Frequency boost from ${count} generators (${strategies}): avg ${avg.toFixed(2)} \xD7 ${boost.toFixed(2)} \u2192 ${finalScore.toFixed(2)}`;
|
|
805
|
+
}
|
|
806
|
+
default:
|
|
807
|
+
return `Aggregated from ${count} generators: ${finalScore.toFixed(2)}`;
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
/**
|
|
811
|
+
* Aggregate scores from multiple generators for the same card.
|
|
812
|
+
*/
|
|
813
|
+
aggregateScores(cards) {
|
|
814
|
+
const scores = cards.map((c) => c.score);
|
|
815
|
+
switch (this.aggregationMode) {
|
|
816
|
+
case "max" /* MAX */:
|
|
817
|
+
return Math.max(...scores);
|
|
818
|
+
case "average" /* AVERAGE */:
|
|
819
|
+
return scores.reduce((sum, s) => sum + s, 0) / scores.length;
|
|
820
|
+
case "frequencyBoost" /* FREQUENCY_BOOST */: {
|
|
821
|
+
const avg = scores.reduce((sum, s) => sum + s, 0) / scores.length;
|
|
822
|
+
const frequencyBoost = 1 + FREQUENCY_BOOST_FACTOR * (cards.length - 1);
|
|
823
|
+
return avg * frequencyBoost;
|
|
824
|
+
}
|
|
825
|
+
default:
|
|
826
|
+
return scores[0];
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
/**
|
|
830
|
+
* Get new cards from all generators, merged and deduplicated.
|
|
831
|
+
*/
|
|
832
|
+
async getNewCards(n) {
|
|
833
|
+
const legacyGenerators = this.generators.filter(
|
|
834
|
+
(g) => g instanceof ContentNavigator
|
|
835
|
+
);
|
|
836
|
+
const results = await Promise.all(legacyGenerators.map((g) => g.getNewCards(n)));
|
|
837
|
+
const seen = /* @__PURE__ */ new Set();
|
|
838
|
+
const merged = [];
|
|
839
|
+
for (const cards of results) {
|
|
840
|
+
for (const card of cards) {
|
|
841
|
+
if (!seen.has(card.cardID)) {
|
|
842
|
+
seen.add(card.cardID);
|
|
843
|
+
merged.push(card);
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
return n ? merged.slice(0, n) : merged;
|
|
848
|
+
}
|
|
849
|
+
/**
|
|
850
|
+
* Get pending reviews from all generators, merged and deduplicated.
|
|
851
|
+
*/
|
|
852
|
+
async getPendingReviews() {
|
|
853
|
+
const legacyGenerators = this.generators.filter(
|
|
854
|
+
(g) => g instanceof ContentNavigator
|
|
855
|
+
);
|
|
856
|
+
const results = await Promise.all(legacyGenerators.map((g) => g.getPendingReviews()));
|
|
857
|
+
const seen = /* @__PURE__ */ new Set();
|
|
858
|
+
const merged = [];
|
|
859
|
+
for (const reviews of results) {
|
|
860
|
+
for (const review of reviews) {
|
|
861
|
+
if (!seen.has(review.cardID)) {
|
|
862
|
+
seen.add(review.cardID);
|
|
863
|
+
merged.push(review);
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
return merged;
|
|
868
|
+
}
|
|
869
|
+
};
|
|
870
|
+
}
|
|
871
|
+
});
|
|
872
|
+
|
|
873
|
+
// src/core/navigators/Pipeline.ts
|
|
874
|
+
var Pipeline_exports = {};
|
|
875
|
+
__export(Pipeline_exports, {
|
|
876
|
+
Pipeline: () => Pipeline
|
|
877
|
+
});
|
|
878
|
+
import { toCourseElo as toCourseElo2 } from "@vue-skuilder/common";
|
|
879
|
+
var Pipeline;
|
|
880
|
+
var init_Pipeline = __esm({
|
|
881
|
+
"src/core/navigators/Pipeline.ts"() {
|
|
882
|
+
"use strict";
|
|
883
|
+
init_navigators();
|
|
884
|
+
init_logger();
|
|
885
|
+
Pipeline = class extends ContentNavigator {
|
|
886
|
+
generator;
|
|
887
|
+
filters;
|
|
888
|
+
/**
|
|
889
|
+
* Create a new pipeline.
|
|
890
|
+
*
|
|
891
|
+
* @param generator - The generator (or CompositeGenerator) that produces candidates
|
|
892
|
+
* @param filters - Filters to apply sequentially (order doesn't matter for multipliers)
|
|
893
|
+
* @param user - User database interface
|
|
894
|
+
* @param course - Course database interface
|
|
895
|
+
*/
|
|
896
|
+
constructor(generator, filters, user, course) {
|
|
897
|
+
super();
|
|
898
|
+
this.generator = generator;
|
|
899
|
+
this.filters = filters;
|
|
900
|
+
this.user = user;
|
|
901
|
+
this.course = course;
|
|
902
|
+
logger.debug(
|
|
903
|
+
`[Pipeline] Created with generator '${generator.name}' and ${filters.length} filters: ${filters.map((f) => f.name).join(", ")}`
|
|
904
|
+
);
|
|
905
|
+
}
|
|
906
|
+
/**
|
|
907
|
+
* Get weighted cards by running generator and applying filters.
|
|
908
|
+
*
|
|
909
|
+
* 1. Build shared context (user ELO, etc.)
|
|
910
|
+
* 2. Get candidates from generator (passing context)
|
|
911
|
+
* 3. Apply each filter sequentially
|
|
912
|
+
* 4. Remove zero-score cards
|
|
913
|
+
* 5. Sort by score descending
|
|
914
|
+
* 6. Return top N
|
|
915
|
+
*
|
|
916
|
+
* @param limit - Maximum number of cards to return
|
|
917
|
+
* @returns Cards sorted by score descending
|
|
918
|
+
*/
|
|
919
|
+
async getWeightedCards(limit) {
|
|
920
|
+
const context = await this.buildContext();
|
|
921
|
+
const overFetchMultiplier = 2 + this.filters.length * 0.5;
|
|
922
|
+
const fetchLimit = Math.ceil(limit * overFetchMultiplier);
|
|
923
|
+
logger.debug(
|
|
924
|
+
`[Pipeline] Fetching ${fetchLimit} candidates from generator '${this.generator.name}'`
|
|
925
|
+
);
|
|
926
|
+
let cards = await this.generator.getWeightedCards(fetchLimit, context);
|
|
927
|
+
logger.debug(`[Pipeline] Generator returned ${cards.length} candidates`);
|
|
928
|
+
for (const filter of this.filters) {
|
|
929
|
+
const beforeCount = cards.length;
|
|
930
|
+
cards = await filter.transform(cards, context);
|
|
931
|
+
logger.debug(`[Pipeline] Filter '${filter.name}': ${beforeCount} \u2192 ${cards.length} cards`);
|
|
932
|
+
}
|
|
933
|
+
cards = cards.filter((c) => c.score > 0);
|
|
934
|
+
cards.sort((a, b) => b.score - a.score);
|
|
935
|
+
const result = cards.slice(0, limit);
|
|
936
|
+
logger.debug(
|
|
937
|
+
`[Pipeline] Returning ${result.length} cards (top scores: ${result.slice(0, 3).map((c) => c.score.toFixed(2)).join(", ")}...)`
|
|
938
|
+
);
|
|
939
|
+
return result;
|
|
940
|
+
}
|
|
941
|
+
/**
|
|
942
|
+
* Build shared context for generator and filters.
|
|
943
|
+
*
|
|
944
|
+
* Called once per getWeightedCards() invocation.
|
|
945
|
+
* Contains data that the generator and multiple filters might need.
|
|
946
|
+
*
|
|
947
|
+
* The context satisfies both GeneratorContext and FilterContext interfaces.
|
|
948
|
+
*/
|
|
949
|
+
async buildContext() {
|
|
950
|
+
let userElo = 1e3;
|
|
951
|
+
try {
|
|
952
|
+
const courseReg = await this.user.getCourseRegDoc(this.course.getCourseID());
|
|
953
|
+
const courseElo = toCourseElo2(courseReg.elo);
|
|
954
|
+
userElo = courseElo.global.score;
|
|
955
|
+
} catch (e) {
|
|
956
|
+
logger.debug(`[Pipeline] Could not get user ELO, using default: ${e}`);
|
|
957
|
+
}
|
|
958
|
+
return {
|
|
959
|
+
user: this.user,
|
|
960
|
+
course: this.course,
|
|
961
|
+
userElo
|
|
962
|
+
};
|
|
963
|
+
}
|
|
964
|
+
// ===========================================================================
|
|
965
|
+
// Legacy StudyContentSource methods
|
|
966
|
+
// ===========================================================================
|
|
967
|
+
//
|
|
968
|
+
// These delegate to the generator for backward compatibility.
|
|
969
|
+
// Eventually SessionController will use getWeightedCards() exclusively.
|
|
970
|
+
//
|
|
971
|
+
/**
|
|
972
|
+
* Get new cards via legacy API.
|
|
973
|
+
* Delegates to the generator if it supports the legacy interface.
|
|
974
|
+
*/
|
|
975
|
+
async getNewCards(n) {
|
|
976
|
+
if ("getNewCards" in this.generator && typeof this.generator.getNewCards === "function") {
|
|
977
|
+
return this.generator.getNewCards(n);
|
|
978
|
+
}
|
|
979
|
+
return [];
|
|
980
|
+
}
|
|
981
|
+
/**
|
|
982
|
+
* Get pending reviews via legacy API.
|
|
983
|
+
* Delegates to the generator if it supports the legacy interface.
|
|
984
|
+
*/
|
|
985
|
+
async getPendingReviews() {
|
|
986
|
+
if ("getPendingReviews" in this.generator && typeof this.generator.getPendingReviews === "function") {
|
|
987
|
+
return this.generator.getPendingReviews();
|
|
988
|
+
}
|
|
989
|
+
return [];
|
|
990
|
+
}
|
|
991
|
+
/**
|
|
992
|
+
* Get the course ID for this pipeline.
|
|
993
|
+
*/
|
|
994
|
+
getCourseID() {
|
|
995
|
+
return this.course.getCourseID();
|
|
996
|
+
}
|
|
997
|
+
};
|
|
998
|
+
}
|
|
999
|
+
});
|
|
1000
|
+
|
|
1001
|
+
// src/core/navigators/PipelineAssembler.ts
|
|
1002
|
+
var PipelineAssembler_exports = {};
|
|
1003
|
+
__export(PipelineAssembler_exports, {
|
|
1004
|
+
PipelineAssembler: () => PipelineAssembler
|
|
1005
|
+
});
|
|
1006
|
+
var PipelineAssembler;
|
|
1007
|
+
var init_PipelineAssembler = __esm({
|
|
1008
|
+
"src/core/navigators/PipelineAssembler.ts"() {
|
|
1009
|
+
"use strict";
|
|
1010
|
+
init_navigators();
|
|
1011
|
+
init_Pipeline();
|
|
1012
|
+
init_types_legacy();
|
|
1013
|
+
init_logger();
|
|
1014
|
+
init_CompositeGenerator();
|
|
1015
|
+
PipelineAssembler = class {
|
|
1016
|
+
/**
|
|
1017
|
+
* Assembles a navigation pipeline from strategy documents.
|
|
1018
|
+
*
|
|
1019
|
+
* 1. Separates into generators and filters by role
|
|
1020
|
+
* 2. Validates at least one generator exists (or creates default ELO)
|
|
1021
|
+
* 3. Instantiates generators - wraps multiple in CompositeGenerator
|
|
1022
|
+
* 4. Instantiates filters
|
|
1023
|
+
* 5. Returns Pipeline(generator, filters)
|
|
1024
|
+
*
|
|
1025
|
+
* @param input - Strategy documents plus user/course interfaces
|
|
1026
|
+
* @returns Assembled pipeline and any warnings
|
|
1027
|
+
*/
|
|
1028
|
+
async assemble(input) {
|
|
1029
|
+
const { strategies, user, course } = input;
|
|
1030
|
+
const warnings = [];
|
|
1031
|
+
if (strategies.length === 0) {
|
|
1032
|
+
return {
|
|
1033
|
+
pipeline: null,
|
|
1034
|
+
generatorStrategies: [],
|
|
1035
|
+
filterStrategies: [],
|
|
1036
|
+
warnings
|
|
1037
|
+
};
|
|
1038
|
+
}
|
|
1039
|
+
const generatorStrategies = [];
|
|
1040
|
+
const filterStrategies = [];
|
|
1041
|
+
for (const s of strategies) {
|
|
1042
|
+
if (isGenerator(s.implementingClass)) {
|
|
1043
|
+
generatorStrategies.push(s);
|
|
1044
|
+
} else if (isFilter(s.implementingClass)) {
|
|
1045
|
+
filterStrategies.push(s);
|
|
1046
|
+
} else {
|
|
1047
|
+
warnings.push(`Unknown strategy type '${s.implementingClass}', skipping: ${s.name}`);
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
if (generatorStrategies.length === 0) {
|
|
1051
|
+
if (filterStrategies.length > 0) {
|
|
1052
|
+
logger.debug(
|
|
1053
|
+
"[PipelineAssembler] No generator found, using default ELO with configured filters"
|
|
1054
|
+
);
|
|
1055
|
+
generatorStrategies.push(this.makeDefaultEloStrategy(course.getCourseID()));
|
|
1056
|
+
} else {
|
|
1057
|
+
warnings.push("No generator strategy found");
|
|
1058
|
+
return {
|
|
1059
|
+
pipeline: null,
|
|
1060
|
+
generatorStrategies: [],
|
|
1061
|
+
filterStrategies: [],
|
|
1062
|
+
warnings
|
|
1063
|
+
};
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
let generator;
|
|
1067
|
+
if (generatorStrategies.length === 1) {
|
|
1068
|
+
const nav = await ContentNavigator.create(user, course, generatorStrategies[0]);
|
|
1069
|
+
generator = nav;
|
|
1070
|
+
logger.debug(`[PipelineAssembler] Using single generator: ${generatorStrategies[0].name}`);
|
|
1071
|
+
} else {
|
|
1072
|
+
logger.debug(
|
|
1073
|
+
`[PipelineAssembler] Using CompositeGenerator for ${generatorStrategies.length} generators: ${generatorStrategies.map((g) => g.name).join(", ")}`
|
|
1074
|
+
);
|
|
1075
|
+
generator = await CompositeGenerator.fromStrategies(user, course, generatorStrategies);
|
|
1076
|
+
}
|
|
1077
|
+
const filters = [];
|
|
1078
|
+
const sortedFilterStrategies = [...filterStrategies].sort(
|
|
1079
|
+
(a, b) => a.name.localeCompare(b.name)
|
|
1080
|
+
);
|
|
1081
|
+
for (const filterStrategy of sortedFilterStrategies) {
|
|
1082
|
+
try {
|
|
1083
|
+
const nav = await ContentNavigator.create(user, course, filterStrategy);
|
|
1084
|
+
if ("transform" in nav && typeof nav.transform === "function") {
|
|
1085
|
+
filters.push(nav);
|
|
1086
|
+
logger.debug(`[PipelineAssembler] Added filter: ${filterStrategy.name}`);
|
|
1087
|
+
} else {
|
|
1088
|
+
warnings.push(
|
|
1089
|
+
`Filter '${filterStrategy.name}' does not implement CardFilter.transform(), skipping`
|
|
1090
|
+
);
|
|
1091
|
+
}
|
|
1092
|
+
} catch (e) {
|
|
1093
|
+
warnings.push(`Failed to instantiate filter '${filterStrategy.name}': ${e}`);
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
const pipeline = new Pipeline(generator, filters, user, course);
|
|
1097
|
+
logger.debug(
|
|
1098
|
+
`[PipelineAssembler] Assembled pipeline with ${generatorStrategies.length} generator(s) and ${filters.length} filter(s)`
|
|
1099
|
+
);
|
|
1100
|
+
return {
|
|
1101
|
+
pipeline,
|
|
1102
|
+
generatorStrategies,
|
|
1103
|
+
filterStrategies: sortedFilterStrategies,
|
|
1104
|
+
warnings
|
|
1105
|
+
};
|
|
1106
|
+
}
|
|
1107
|
+
/**
|
|
1108
|
+
* Creates a default ELO generator strategy.
|
|
1109
|
+
* Used when filters are configured but no generator is specified.
|
|
1110
|
+
*/
|
|
1111
|
+
makeDefaultEloStrategy(courseId) {
|
|
1112
|
+
return {
|
|
1113
|
+
_id: "NAVIGATION_STRATEGY-ELO-default",
|
|
1114
|
+
course: courseId,
|
|
1115
|
+
docType: "NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */,
|
|
1116
|
+
name: "ELO (default)",
|
|
1117
|
+
description: "Default ELO-based generator",
|
|
1118
|
+
implementingClass: "elo" /* ELO */,
|
|
1119
|
+
serializedData: ""
|
|
1120
|
+
};
|
|
1121
|
+
}
|
|
1122
|
+
};
|
|
1123
|
+
}
|
|
1124
|
+
});
|
|
1125
|
+
|
|
689
1126
|
// src/core/navigators/elo.ts
|
|
690
1127
|
var elo_exports = {};
|
|
691
1128
|
__export(elo_exports, {
|
|
692
1129
|
default: () => ELONavigator
|
|
693
1130
|
});
|
|
1131
|
+
import { toCourseElo as toCourseElo3 } from "@vue-skuilder/common";
|
|
694
1132
|
var ELONavigator;
|
|
695
1133
|
var init_elo = __esm({
|
|
696
1134
|
"src/core/navigators/elo.ts"() {
|
|
697
1135
|
"use strict";
|
|
698
1136
|
init_navigators();
|
|
699
1137
|
ELONavigator = class extends ContentNavigator {
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
constructor(user, course) {
|
|
703
|
-
super();
|
|
704
|
-
this.
|
|
705
|
-
this.course = course;
|
|
1138
|
+
/** Human-readable name for CardGenerator interface */
|
|
1139
|
+
name;
|
|
1140
|
+
constructor(user, course, strategyData) {
|
|
1141
|
+
super(user, course, strategyData);
|
|
1142
|
+
this.name = strategyData?.name || "ELO";
|
|
706
1143
|
}
|
|
707
1144
|
async getPendingReviews() {
|
|
708
1145
|
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
@@ -730,84 +1167,983 @@ var init_elo = __esm({
|
|
|
730
1167
|
};
|
|
731
1168
|
});
|
|
732
1169
|
}
|
|
733
|
-
async getNewCards(limit = 99) {
|
|
734
|
-
const activeCards = await this.user.getActiveCards();
|
|
735
|
-
return (await this.course.getCardsCenteredAtELO(
|
|
736
|
-
{ limit, elo: "user" },
|
|
737
|
-
(c) => {
|
|
738
|
-
if (activeCards.some((ac) => c.cardID === ac.cardID)) {
|
|
739
|
-
return false;
|
|
740
|
-
} else {
|
|
741
|
-
return true;
|
|
742
|
-
}
|
|
743
|
-
}
|
|
744
|
-
)).map((c) => {
|
|
745
|
-
return {
|
|
746
|
-
...c,
|
|
747
|
-
status: "new"
|
|
748
|
-
};
|
|
749
|
-
});
|
|
1170
|
+
async getNewCards(limit = 99) {
|
|
1171
|
+
const activeCards = await this.user.getActiveCards();
|
|
1172
|
+
return (await this.course.getCardsCenteredAtELO(
|
|
1173
|
+
{ limit, elo: "user" },
|
|
1174
|
+
(c) => {
|
|
1175
|
+
if (activeCards.some((ac) => c.cardID === ac.cardID)) {
|
|
1176
|
+
return false;
|
|
1177
|
+
} else {
|
|
1178
|
+
return true;
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
)).map((c) => {
|
|
1182
|
+
return {
|
|
1183
|
+
...c,
|
|
1184
|
+
status: "new"
|
|
1185
|
+
};
|
|
1186
|
+
});
|
|
1187
|
+
}
|
|
1188
|
+
/**
|
|
1189
|
+
* Get new cards with suitability scores based on ELO distance.
|
|
1190
|
+
*
|
|
1191
|
+
* Cards closer to user's ELO get higher scores.
|
|
1192
|
+
* Score formula: max(0, 1 - distance / 500)
|
|
1193
|
+
*
|
|
1194
|
+
* NOTE: This generator only handles NEW cards. Reviews are handled by
|
|
1195
|
+
* SRSNavigator. Use CompositeGenerator to combine both.
|
|
1196
|
+
*
|
|
1197
|
+
* This method supports both the legacy signature (limit only) and the
|
|
1198
|
+
* CardGenerator interface signature (limit, context).
|
|
1199
|
+
*
|
|
1200
|
+
* @param limit - Maximum number of cards to return
|
|
1201
|
+
* @param context - Optional GeneratorContext (used when called via Pipeline)
|
|
1202
|
+
*/
|
|
1203
|
+
async getWeightedCards(limit, context) {
|
|
1204
|
+
let userGlobalElo;
|
|
1205
|
+
if (context?.userElo !== void 0) {
|
|
1206
|
+
userGlobalElo = context.userElo;
|
|
1207
|
+
} else {
|
|
1208
|
+
const courseReg = await this.user.getCourseRegDoc(this.course.getCourseID());
|
|
1209
|
+
const userElo = toCourseElo3(courseReg.elo);
|
|
1210
|
+
userGlobalElo = userElo.global.score;
|
|
1211
|
+
}
|
|
1212
|
+
const newCards = await this.getNewCards(limit);
|
|
1213
|
+
const cardIds = newCards.map((c) => c.cardID);
|
|
1214
|
+
const cardEloData = await this.course.getCardEloData(cardIds);
|
|
1215
|
+
const scored = newCards.map((c, i) => {
|
|
1216
|
+
const cardElo = cardEloData[i]?.global?.score ?? 1e3;
|
|
1217
|
+
const distance = Math.abs(cardElo - userGlobalElo);
|
|
1218
|
+
const score = Math.max(0, 1 - distance / 500);
|
|
1219
|
+
return {
|
|
1220
|
+
cardId: c.cardID,
|
|
1221
|
+
courseId: c.courseID,
|
|
1222
|
+
score,
|
|
1223
|
+
provenance: [
|
|
1224
|
+
{
|
|
1225
|
+
strategy: "elo",
|
|
1226
|
+
strategyName: this.strategyName || this.name,
|
|
1227
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-ELO-default",
|
|
1228
|
+
action: "generated",
|
|
1229
|
+
score,
|
|
1230
|
+
reason: `ELO distance ${Math.round(distance)} (card: ${Math.round(cardElo)}, user: ${Math.round(userGlobalElo)}), new card`
|
|
1231
|
+
}
|
|
1232
|
+
]
|
|
1233
|
+
};
|
|
1234
|
+
});
|
|
1235
|
+
scored.sort((a, b) => b.score - a.score);
|
|
1236
|
+
return scored.slice(0, limit);
|
|
1237
|
+
}
|
|
1238
|
+
};
|
|
1239
|
+
}
|
|
1240
|
+
});
|
|
1241
|
+
|
|
1242
|
+
// src/core/navigators/filters/eloDistance.ts
|
|
1243
|
+
var eloDistance_exports = {};
|
|
1244
|
+
__export(eloDistance_exports, {
|
|
1245
|
+
DEFAULT_HALF_LIFE: () => DEFAULT_HALF_LIFE,
|
|
1246
|
+
DEFAULT_MAX_MULTIPLIER: () => DEFAULT_MAX_MULTIPLIER,
|
|
1247
|
+
DEFAULT_MIN_MULTIPLIER: () => DEFAULT_MIN_MULTIPLIER,
|
|
1248
|
+
createEloDistanceFilter: () => createEloDistanceFilter
|
|
1249
|
+
});
|
|
1250
|
+
function computeMultiplier(distance, halfLife, minMultiplier, maxMultiplier) {
|
|
1251
|
+
const normalizedDistance = distance / halfLife;
|
|
1252
|
+
const decay = Math.exp(-(normalizedDistance * normalizedDistance));
|
|
1253
|
+
return minMultiplier + (maxMultiplier - minMultiplier) * decay;
|
|
1254
|
+
}
|
|
1255
|
+
function createEloDistanceFilter(config) {
|
|
1256
|
+
const halfLife = config?.halfLife ?? DEFAULT_HALF_LIFE;
|
|
1257
|
+
const minMultiplier = config?.minMultiplier ?? DEFAULT_MIN_MULTIPLIER;
|
|
1258
|
+
const maxMultiplier = config?.maxMultiplier ?? DEFAULT_MAX_MULTIPLIER;
|
|
1259
|
+
return {
|
|
1260
|
+
name: "ELO Distance Filter",
|
|
1261
|
+
async transform(cards, context) {
|
|
1262
|
+
const { course, userElo } = context;
|
|
1263
|
+
const cardIds = cards.map((c) => c.cardId);
|
|
1264
|
+
const cardElos = await course.getCardEloData(cardIds);
|
|
1265
|
+
return cards.map((card, i) => {
|
|
1266
|
+
const cardElo = cardElos[i]?.global?.score ?? 1e3;
|
|
1267
|
+
const distance = Math.abs(cardElo - userElo);
|
|
1268
|
+
const multiplier = computeMultiplier(distance, halfLife, minMultiplier, maxMultiplier);
|
|
1269
|
+
const newScore = card.score * multiplier;
|
|
1270
|
+
const action = multiplier < maxMultiplier - 0.01 ? "penalized" : "passed";
|
|
1271
|
+
return {
|
|
1272
|
+
...card,
|
|
1273
|
+
score: newScore,
|
|
1274
|
+
provenance: [
|
|
1275
|
+
...card.provenance,
|
|
1276
|
+
{
|
|
1277
|
+
strategy: "eloDistance",
|
|
1278
|
+
strategyName: "ELO Distance Filter",
|
|
1279
|
+
strategyId: "ELO_DISTANCE_FILTER",
|
|
1280
|
+
action,
|
|
1281
|
+
score: newScore,
|
|
1282
|
+
reason: `ELO distance ${Math.round(distance)} (card: ${Math.round(cardElo)}, user: ${Math.round(userElo)}) \u2192 ${multiplier.toFixed(2)}x`
|
|
1283
|
+
}
|
|
1284
|
+
]
|
|
1285
|
+
};
|
|
1286
|
+
});
|
|
1287
|
+
}
|
|
1288
|
+
};
|
|
1289
|
+
}
|
|
1290
|
+
var DEFAULT_HALF_LIFE, DEFAULT_MIN_MULTIPLIER, DEFAULT_MAX_MULTIPLIER;
|
|
1291
|
+
var init_eloDistance = __esm({
|
|
1292
|
+
"src/core/navigators/filters/eloDistance.ts"() {
|
|
1293
|
+
"use strict";
|
|
1294
|
+
DEFAULT_HALF_LIFE = 200;
|
|
1295
|
+
DEFAULT_MIN_MULTIPLIER = 0.3;
|
|
1296
|
+
DEFAULT_MAX_MULTIPLIER = 1;
|
|
1297
|
+
}
|
|
1298
|
+
});
|
|
1299
|
+
|
|
1300
|
+
// src/core/navigators/filters/index.ts
|
|
1301
|
+
var filters_exports = {};
|
|
1302
|
+
__export(filters_exports, {
|
|
1303
|
+
createEloDistanceFilter: () => createEloDistanceFilter
|
|
1304
|
+
});
|
|
1305
|
+
var init_filters = __esm({
|
|
1306
|
+
"src/core/navigators/filters/index.ts"() {
|
|
1307
|
+
"use strict";
|
|
1308
|
+
init_eloDistance();
|
|
1309
|
+
}
|
|
1310
|
+
});
|
|
1311
|
+
|
|
1312
|
+
// src/core/navigators/filters/types.ts
|
|
1313
|
+
var types_exports = {};
|
|
1314
|
+
var init_types = __esm({
|
|
1315
|
+
"src/core/navigators/filters/types.ts"() {
|
|
1316
|
+
"use strict";
|
|
1317
|
+
}
|
|
1318
|
+
});
|
|
1319
|
+
|
|
1320
|
+
// src/core/navigators/generators/index.ts
|
|
1321
|
+
var generators_exports = {};
|
|
1322
|
+
var init_generators = __esm({
|
|
1323
|
+
"src/core/navigators/generators/index.ts"() {
|
|
1324
|
+
"use strict";
|
|
1325
|
+
}
|
|
1326
|
+
});
|
|
1327
|
+
|
|
1328
|
+
// src/core/navigators/generators/types.ts
|
|
1329
|
+
var types_exports2 = {};
|
|
1330
|
+
var init_types2 = __esm({
|
|
1331
|
+
"src/core/navigators/generators/types.ts"() {
|
|
1332
|
+
"use strict";
|
|
1333
|
+
}
|
|
1334
|
+
});
|
|
1335
|
+
|
|
1336
|
+
// src/core/navigators/hardcodedOrder.ts
|
|
1337
|
+
var hardcodedOrder_exports = {};
|
|
1338
|
+
__export(hardcodedOrder_exports, {
|
|
1339
|
+
default: () => HardcodedOrderNavigator
|
|
1340
|
+
});
|
|
1341
|
+
var HardcodedOrderNavigator;
|
|
1342
|
+
var init_hardcodedOrder = __esm({
|
|
1343
|
+
"src/core/navigators/hardcodedOrder.ts"() {
|
|
1344
|
+
"use strict";
|
|
1345
|
+
init_navigators();
|
|
1346
|
+
init_logger();
|
|
1347
|
+
HardcodedOrderNavigator = class extends ContentNavigator {
|
|
1348
|
+
/** Human-readable name for CardGenerator interface */
|
|
1349
|
+
name;
|
|
1350
|
+
orderedCardIds = [];
|
|
1351
|
+
constructor(user, course, strategyData) {
|
|
1352
|
+
super(user, course, strategyData);
|
|
1353
|
+
this.name = strategyData.name || "Hardcoded Order";
|
|
1354
|
+
if (strategyData.serializedData) {
|
|
1355
|
+
try {
|
|
1356
|
+
this.orderedCardIds = JSON.parse(strategyData.serializedData);
|
|
1357
|
+
} catch (e) {
|
|
1358
|
+
logger.error("Failed to parse serializedData for HardcodedOrderNavigator", e);
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
async getPendingReviews() {
|
|
1363
|
+
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
1364
|
+
return reviews.map((r) => {
|
|
1365
|
+
return {
|
|
1366
|
+
...r,
|
|
1367
|
+
contentSourceType: "course",
|
|
1368
|
+
contentSourceID: this.course.getCourseID(),
|
|
1369
|
+
cardID: r.cardId,
|
|
1370
|
+
courseID: r.courseId,
|
|
1371
|
+
reviewID: r._id,
|
|
1372
|
+
status: "review"
|
|
1373
|
+
};
|
|
1374
|
+
});
|
|
1375
|
+
}
|
|
1376
|
+
async getNewCards(limit = 99) {
|
|
1377
|
+
const activeCardIds = (await this.user.getActiveCards()).map((c) => c.cardID);
|
|
1378
|
+
const newCardIds = this.orderedCardIds.filter((cardId) => !activeCardIds.includes(cardId));
|
|
1379
|
+
const cardsToReturn = newCardIds.slice(0, limit);
|
|
1380
|
+
return cardsToReturn.map((cardId) => {
|
|
1381
|
+
return {
|
|
1382
|
+
cardID: cardId,
|
|
1383
|
+
courseID: this.course.getCourseID(),
|
|
1384
|
+
contentSourceType: "course",
|
|
1385
|
+
contentSourceID: this.course.getCourseID(),
|
|
1386
|
+
status: "new"
|
|
1387
|
+
};
|
|
1388
|
+
});
|
|
1389
|
+
}
|
|
1390
|
+
/**
|
|
1391
|
+
* Get cards in hardcoded order with scores based on position.
|
|
1392
|
+
*
|
|
1393
|
+
* Earlier cards in the sequence get higher scores.
|
|
1394
|
+
* Score formula: 1.0 - (position / totalCards) * 0.5
|
|
1395
|
+
* This ensures scores range from 1.0 (first card) to 0.5+ (last card).
|
|
1396
|
+
*
|
|
1397
|
+
* This method supports both the legacy signature (limit only) and the
|
|
1398
|
+
* CardGenerator interface signature (limit, context).
|
|
1399
|
+
*
|
|
1400
|
+
* @param limit - Maximum number of cards to return
|
|
1401
|
+
* @param _context - Optional GeneratorContext (currently unused, but required for interface)
|
|
1402
|
+
*/
|
|
1403
|
+
async getWeightedCards(limit, _context) {
|
|
1404
|
+
const activeCardIds = (await this.user.getActiveCards()).map((c) => c.cardID);
|
|
1405
|
+
const reviews = await this.getPendingReviews();
|
|
1406
|
+
const newCardIds = this.orderedCardIds.filter((cardId) => !activeCardIds.includes(cardId));
|
|
1407
|
+
const totalCards = newCardIds.length;
|
|
1408
|
+
const scoredNew = newCardIds.slice(0, limit).map((cardId, index) => {
|
|
1409
|
+
const position = index + 1;
|
|
1410
|
+
const score = Math.max(0.5, 1 - index / totalCards * 0.5);
|
|
1411
|
+
return {
|
|
1412
|
+
cardId,
|
|
1413
|
+
courseId: this.course.getCourseID(),
|
|
1414
|
+
score,
|
|
1415
|
+
provenance: [
|
|
1416
|
+
{
|
|
1417
|
+
strategy: "hardcodedOrder",
|
|
1418
|
+
strategyName: this.strategyName || this.name,
|
|
1419
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-hardcoded",
|
|
1420
|
+
action: "generated",
|
|
1421
|
+
score,
|
|
1422
|
+
reason: `Position ${position} of ${totalCards} in fixed sequence, new card`
|
|
1423
|
+
}
|
|
1424
|
+
]
|
|
1425
|
+
};
|
|
1426
|
+
});
|
|
1427
|
+
const scoredReviews = reviews.map((r) => ({
|
|
1428
|
+
cardId: r.cardID,
|
|
1429
|
+
courseId: r.courseID,
|
|
1430
|
+
score: 1,
|
|
1431
|
+
provenance: [
|
|
1432
|
+
{
|
|
1433
|
+
strategy: "hardcodedOrder",
|
|
1434
|
+
strategyName: this.strategyName || this.name,
|
|
1435
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-hardcoded",
|
|
1436
|
+
action: "generated",
|
|
1437
|
+
score: 1,
|
|
1438
|
+
reason: "Scheduled review, highest priority"
|
|
1439
|
+
}
|
|
1440
|
+
]
|
|
1441
|
+
}));
|
|
1442
|
+
const all = [...scoredReviews, ...scoredNew];
|
|
1443
|
+
all.sort((a, b) => b.score - a.score);
|
|
1444
|
+
return all.slice(0, limit);
|
|
1445
|
+
}
|
|
1446
|
+
};
|
|
1447
|
+
}
|
|
1448
|
+
});
|
|
1449
|
+
|
|
1450
|
+
// src/core/navigators/hierarchyDefinition.ts
|
|
1451
|
+
var hierarchyDefinition_exports = {};
|
|
1452
|
+
__export(hierarchyDefinition_exports, {
|
|
1453
|
+
default: () => HierarchyDefinitionNavigator
|
|
1454
|
+
});
|
|
1455
|
+
import { toCourseElo as toCourseElo4 } from "@vue-skuilder/common";
|
|
1456
|
+
var DEFAULT_MIN_COUNT, HierarchyDefinitionNavigator;
|
|
1457
|
+
var init_hierarchyDefinition = __esm({
|
|
1458
|
+
"src/core/navigators/hierarchyDefinition.ts"() {
|
|
1459
|
+
"use strict";
|
|
1460
|
+
init_navigators();
|
|
1461
|
+
DEFAULT_MIN_COUNT = 3;
|
|
1462
|
+
HierarchyDefinitionNavigator = class extends ContentNavigator {
|
|
1463
|
+
config;
|
|
1464
|
+
_strategyData;
|
|
1465
|
+
/** Human-readable name for CardFilter interface */
|
|
1466
|
+
name;
|
|
1467
|
+
constructor(user, course, _strategyData) {
|
|
1468
|
+
super(user, course, _strategyData);
|
|
1469
|
+
this._strategyData = _strategyData;
|
|
1470
|
+
this.config = this.parseConfig(_strategyData.serializedData);
|
|
1471
|
+
this.name = _strategyData.name || "Hierarchy Definition";
|
|
1472
|
+
}
|
|
1473
|
+
parseConfig(serializedData) {
|
|
1474
|
+
try {
|
|
1475
|
+
const parsed = JSON.parse(serializedData);
|
|
1476
|
+
return {
|
|
1477
|
+
prerequisites: parsed.prerequisites || {}
|
|
1478
|
+
};
|
|
1479
|
+
} catch {
|
|
1480
|
+
return {
|
|
1481
|
+
prerequisites: {}
|
|
1482
|
+
};
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
/**
|
|
1486
|
+
* Check if a specific prerequisite is satisfied
|
|
1487
|
+
*/
|
|
1488
|
+
isPrerequisiteMet(prereq, userTagElo, userGlobalElo) {
|
|
1489
|
+
if (!userTagElo) return false;
|
|
1490
|
+
const minCount = prereq.masteryThreshold?.minCount ?? DEFAULT_MIN_COUNT;
|
|
1491
|
+
if (userTagElo.count < minCount) return false;
|
|
1492
|
+
if (prereq.masteryThreshold?.minElo !== void 0) {
|
|
1493
|
+
return userTagElo.score >= prereq.masteryThreshold.minElo;
|
|
1494
|
+
} else {
|
|
1495
|
+
return userTagElo.score >= userGlobalElo;
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
/**
|
|
1499
|
+
* Get the set of tags the user has mastered.
|
|
1500
|
+
* A tag is "mastered" if it appears as a prerequisite somewhere and meets its threshold.
|
|
1501
|
+
*/
|
|
1502
|
+
async getMasteredTags(context) {
|
|
1503
|
+
const mastered = /* @__PURE__ */ new Set();
|
|
1504
|
+
try {
|
|
1505
|
+
const courseReg = await context.user.getCourseRegDoc(context.course.getCourseID());
|
|
1506
|
+
const userElo = toCourseElo4(courseReg.elo);
|
|
1507
|
+
for (const prereqs of Object.values(this.config.prerequisites)) {
|
|
1508
|
+
for (const prereq of prereqs) {
|
|
1509
|
+
const tagElo = userElo.tags[prereq.tag];
|
|
1510
|
+
if (this.isPrerequisiteMet(prereq, tagElo, userElo.global.score)) {
|
|
1511
|
+
mastered.add(prereq.tag);
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1514
|
+
}
|
|
1515
|
+
} catch {
|
|
1516
|
+
}
|
|
1517
|
+
return mastered;
|
|
1518
|
+
}
|
|
1519
|
+
/**
|
|
1520
|
+
* Get the set of tags that are unlocked (prerequisites met)
|
|
1521
|
+
*/
|
|
1522
|
+
getUnlockedTags(masteredTags) {
|
|
1523
|
+
const unlocked = /* @__PURE__ */ new Set();
|
|
1524
|
+
for (const [tagId, prereqs] of Object.entries(this.config.prerequisites)) {
|
|
1525
|
+
const allPrereqsMet = prereqs.every((prereq) => masteredTags.has(prereq.tag));
|
|
1526
|
+
if (allPrereqsMet) {
|
|
1527
|
+
unlocked.add(tagId);
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
return unlocked;
|
|
1531
|
+
}
|
|
1532
|
+
/**
|
|
1533
|
+
* Check if a tag has prerequisites defined in config
|
|
1534
|
+
*/
|
|
1535
|
+
hasPrerequisites(tagId) {
|
|
1536
|
+
return tagId in this.config.prerequisites;
|
|
1537
|
+
}
|
|
1538
|
+
/**
|
|
1539
|
+
* Check if a card is unlocked and generate reason.
|
|
1540
|
+
*/
|
|
1541
|
+
async checkCardUnlock(cardId, course, unlockedTags, masteredTags) {
|
|
1542
|
+
try {
|
|
1543
|
+
const tagResponse = await course.getAppliedTags(cardId);
|
|
1544
|
+
const cardTags = tagResponse.rows.map((row) => row.value?.name || row.key);
|
|
1545
|
+
const lockedTags = cardTags.filter(
|
|
1546
|
+
(tag) => this.hasPrerequisites(tag) && !unlockedTags.has(tag)
|
|
1547
|
+
);
|
|
1548
|
+
if (lockedTags.length === 0) {
|
|
1549
|
+
const tagList = cardTags.length > 0 ? cardTags.join(", ") : "none";
|
|
1550
|
+
return {
|
|
1551
|
+
isUnlocked: true,
|
|
1552
|
+
reason: `Prerequisites met, tags: ${tagList}`
|
|
1553
|
+
};
|
|
1554
|
+
}
|
|
1555
|
+
const missingPrereqs = lockedTags.flatMap((tag) => {
|
|
1556
|
+
const prereqs = this.config.prerequisites[tag] || [];
|
|
1557
|
+
return prereqs.filter((p) => !masteredTags.has(p.tag)).map((p) => p.tag);
|
|
1558
|
+
});
|
|
1559
|
+
return {
|
|
1560
|
+
isUnlocked: false,
|
|
1561
|
+
reason: `Blocked: missing prerequisites ${missingPrereqs.join(", ")} for tags ${lockedTags.join(", ")}`
|
|
1562
|
+
};
|
|
1563
|
+
} catch {
|
|
1564
|
+
return {
|
|
1565
|
+
isUnlocked: true,
|
|
1566
|
+
reason: "Prerequisites check skipped (tag lookup failed)"
|
|
1567
|
+
};
|
|
1568
|
+
}
|
|
1569
|
+
}
|
|
1570
|
+
/**
|
|
1571
|
+
* CardFilter.transform implementation.
|
|
1572
|
+
*
|
|
1573
|
+
* Apply prerequisite gating to cards. Cards with locked tags receive score: 0.
|
|
1574
|
+
*/
|
|
1575
|
+
async transform(cards, context) {
|
|
1576
|
+
const masteredTags = await this.getMasteredTags(context);
|
|
1577
|
+
const unlockedTags = this.getUnlockedTags(masteredTags);
|
|
1578
|
+
const gated = [];
|
|
1579
|
+
for (const card of cards) {
|
|
1580
|
+
const { isUnlocked, reason } = await this.checkCardUnlock(
|
|
1581
|
+
card.cardId,
|
|
1582
|
+
context.course,
|
|
1583
|
+
unlockedTags,
|
|
1584
|
+
masteredTags
|
|
1585
|
+
);
|
|
1586
|
+
const finalScore = isUnlocked ? card.score : 0;
|
|
1587
|
+
const action = isUnlocked ? "passed" : "penalized";
|
|
1588
|
+
gated.push({
|
|
1589
|
+
...card,
|
|
1590
|
+
score: finalScore,
|
|
1591
|
+
provenance: [
|
|
1592
|
+
...card.provenance,
|
|
1593
|
+
{
|
|
1594
|
+
strategy: "hierarchyDefinition",
|
|
1595
|
+
strategyName: this.strategyName || this.name,
|
|
1596
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-hierarchy",
|
|
1597
|
+
action,
|
|
1598
|
+
score: finalScore,
|
|
1599
|
+
reason
|
|
1600
|
+
}
|
|
1601
|
+
]
|
|
1602
|
+
});
|
|
1603
|
+
}
|
|
1604
|
+
return gated;
|
|
1605
|
+
}
|
|
1606
|
+
/**
|
|
1607
|
+
* Legacy getWeightedCards - now throws as filters should not be used as generators.
|
|
1608
|
+
*
|
|
1609
|
+
* Use transform() via Pipeline instead.
|
|
1610
|
+
*/
|
|
1611
|
+
async getWeightedCards(_limit) {
|
|
1612
|
+
throw new Error(
|
|
1613
|
+
"HierarchyDefinitionNavigator is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
|
|
1614
|
+
);
|
|
1615
|
+
}
|
|
1616
|
+
// Legacy methods - stub implementations since filters don't generate cards
|
|
1617
|
+
async getNewCards(_n) {
|
|
1618
|
+
return [];
|
|
1619
|
+
}
|
|
1620
|
+
async getPendingReviews() {
|
|
1621
|
+
return [];
|
|
1622
|
+
}
|
|
1623
|
+
};
|
|
1624
|
+
}
|
|
1625
|
+
});
|
|
1626
|
+
|
|
1627
|
+
// src/core/navigators/interferenceMitigator.ts
|
|
1628
|
+
var interferenceMitigator_exports = {};
|
|
1629
|
+
__export(interferenceMitigator_exports, {
|
|
1630
|
+
default: () => InterferenceMitigatorNavigator
|
|
1631
|
+
});
|
|
1632
|
+
import { toCourseElo as toCourseElo5 } from "@vue-skuilder/common";
|
|
1633
|
+
var DEFAULT_MIN_COUNT2, DEFAULT_MIN_ELAPSED_DAYS, DEFAULT_INTERFERENCE_DECAY, InterferenceMitigatorNavigator;
|
|
1634
|
+
var init_interferenceMitigator = __esm({
|
|
1635
|
+
"src/core/navigators/interferenceMitigator.ts"() {
|
|
1636
|
+
"use strict";
|
|
1637
|
+
init_navigators();
|
|
1638
|
+
DEFAULT_MIN_COUNT2 = 10;
|
|
1639
|
+
DEFAULT_MIN_ELAPSED_DAYS = 3;
|
|
1640
|
+
DEFAULT_INTERFERENCE_DECAY = 0.8;
|
|
1641
|
+
InterferenceMitigatorNavigator = class extends ContentNavigator {
|
|
1642
|
+
config;
|
|
1643
|
+
_strategyData;
|
|
1644
|
+
/** Human-readable name for CardFilter interface */
|
|
1645
|
+
name;
|
|
1646
|
+
/** Precomputed map: tag -> set of { partner, decay } it interferes with */
|
|
1647
|
+
interferenceMap;
|
|
1648
|
+
constructor(user, course, _strategyData) {
|
|
1649
|
+
super(user, course, _strategyData);
|
|
1650
|
+
this._strategyData = _strategyData;
|
|
1651
|
+
this.config = this.parseConfig(_strategyData.serializedData);
|
|
1652
|
+
this.interferenceMap = this.buildInterferenceMap();
|
|
1653
|
+
this.name = _strategyData.name || "Interference Mitigator";
|
|
1654
|
+
}
|
|
1655
|
+
parseConfig(serializedData) {
|
|
1656
|
+
try {
|
|
1657
|
+
const parsed = JSON.parse(serializedData);
|
|
1658
|
+
let sets = parsed.interferenceSets || [];
|
|
1659
|
+
if (sets.length > 0 && Array.isArray(sets[0])) {
|
|
1660
|
+
sets = sets.map((tags) => ({ tags }));
|
|
1661
|
+
}
|
|
1662
|
+
return {
|
|
1663
|
+
interferenceSets: sets,
|
|
1664
|
+
maturityThreshold: {
|
|
1665
|
+
minCount: parsed.maturityThreshold?.minCount ?? DEFAULT_MIN_COUNT2,
|
|
1666
|
+
minElo: parsed.maturityThreshold?.minElo,
|
|
1667
|
+
minElapsedDays: parsed.maturityThreshold?.minElapsedDays ?? DEFAULT_MIN_ELAPSED_DAYS
|
|
1668
|
+
},
|
|
1669
|
+
defaultDecay: parsed.defaultDecay ?? DEFAULT_INTERFERENCE_DECAY
|
|
1670
|
+
};
|
|
1671
|
+
} catch {
|
|
1672
|
+
return {
|
|
1673
|
+
interferenceSets: [],
|
|
1674
|
+
maturityThreshold: {
|
|
1675
|
+
minCount: DEFAULT_MIN_COUNT2,
|
|
1676
|
+
minElapsedDays: DEFAULT_MIN_ELAPSED_DAYS
|
|
1677
|
+
},
|
|
1678
|
+
defaultDecay: DEFAULT_INTERFERENCE_DECAY
|
|
1679
|
+
};
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
/**
|
|
1683
|
+
* Build a map from each tag to its interference partners with decay coefficients.
|
|
1684
|
+
* If tags A, B, C are in an interference group with decay 0.8, then:
|
|
1685
|
+
* - A interferes with B (decay 0.8) and C (decay 0.8)
|
|
1686
|
+
* - B interferes with A (decay 0.8) and C (decay 0.8)
|
|
1687
|
+
* - etc.
|
|
1688
|
+
*/
|
|
1689
|
+
buildInterferenceMap() {
|
|
1690
|
+
const map = /* @__PURE__ */ new Map();
|
|
1691
|
+
for (const group of this.config.interferenceSets) {
|
|
1692
|
+
const decay = group.decay ?? this.config.defaultDecay ?? DEFAULT_INTERFERENCE_DECAY;
|
|
1693
|
+
for (const tag of group.tags) {
|
|
1694
|
+
if (!map.has(tag)) {
|
|
1695
|
+
map.set(tag, []);
|
|
1696
|
+
}
|
|
1697
|
+
const partners = map.get(tag);
|
|
1698
|
+
for (const other of group.tags) {
|
|
1699
|
+
if (other !== tag) {
|
|
1700
|
+
const existing = partners.find((p) => p.partner === other);
|
|
1701
|
+
if (existing) {
|
|
1702
|
+
existing.decay = Math.max(existing.decay, decay);
|
|
1703
|
+
} else {
|
|
1704
|
+
partners.push({ partner: other, decay });
|
|
1705
|
+
}
|
|
1706
|
+
}
|
|
1707
|
+
}
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
return map;
|
|
1711
|
+
}
|
|
1712
|
+
/**
|
|
1713
|
+
* Get the set of tags that are currently immature for this user.
|
|
1714
|
+
* A tag is immature if the user has interacted with it but hasn't
|
|
1715
|
+
* reached the maturity threshold.
|
|
1716
|
+
*/
|
|
1717
|
+
async getImmatureTags(context) {
|
|
1718
|
+
const immature = /* @__PURE__ */ new Set();
|
|
1719
|
+
try {
|
|
1720
|
+
const courseReg = await context.user.getCourseRegDoc(context.course.getCourseID());
|
|
1721
|
+
const userElo = toCourseElo5(courseReg.elo);
|
|
1722
|
+
const minCount = this.config.maturityThreshold?.minCount ?? DEFAULT_MIN_COUNT2;
|
|
1723
|
+
const minElo = this.config.maturityThreshold?.minElo;
|
|
1724
|
+
const minElapsedDays = this.config.maturityThreshold?.minElapsedDays ?? DEFAULT_MIN_ELAPSED_DAYS;
|
|
1725
|
+
const minCountForElapsed = minElapsedDays * 2;
|
|
1726
|
+
for (const [tagId, tagElo] of Object.entries(userElo.tags)) {
|
|
1727
|
+
if (tagElo.count === 0) continue;
|
|
1728
|
+
const belowCount = tagElo.count < minCount;
|
|
1729
|
+
const belowElo = minElo !== void 0 && tagElo.score < minElo;
|
|
1730
|
+
const belowElapsed = tagElo.count < minCountForElapsed;
|
|
1731
|
+
if (belowCount || belowElo || belowElapsed) {
|
|
1732
|
+
immature.add(tagId);
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1735
|
+
} catch {
|
|
1736
|
+
}
|
|
1737
|
+
return immature;
|
|
1738
|
+
}
|
|
1739
|
+
/**
|
|
1740
|
+
* Get all tags that interfere with any immature tag, along with their decay coefficients.
|
|
1741
|
+
* These are the tags we want to avoid introducing.
|
|
1742
|
+
*/
|
|
1743
|
+
getTagsToAvoid(immatureTags) {
|
|
1744
|
+
const avoid = /* @__PURE__ */ new Map();
|
|
1745
|
+
for (const immatureTag of immatureTags) {
|
|
1746
|
+
const partners = this.interferenceMap.get(immatureTag);
|
|
1747
|
+
if (partners) {
|
|
1748
|
+
for (const { partner, decay } of partners) {
|
|
1749
|
+
if (!immatureTags.has(partner)) {
|
|
1750
|
+
const existing = avoid.get(partner) ?? 0;
|
|
1751
|
+
avoid.set(partner, Math.max(existing, decay));
|
|
1752
|
+
}
|
|
1753
|
+
}
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
return avoid;
|
|
1757
|
+
}
|
|
1758
|
+
/**
|
|
1759
|
+
* Get tags for a single card
|
|
1760
|
+
*/
|
|
1761
|
+
async getCardTags(cardId, course) {
|
|
1762
|
+
try {
|
|
1763
|
+
const tagResponse = await course.getAppliedTags(cardId);
|
|
1764
|
+
return tagResponse.rows.map((row) => row.value?.name || row.key).filter(Boolean);
|
|
1765
|
+
} catch {
|
|
1766
|
+
return [];
|
|
1767
|
+
}
|
|
1768
|
+
}
|
|
1769
|
+
/**
|
|
1770
|
+
* Compute interference score reduction for a card.
|
|
1771
|
+
* Returns: { multiplier, interfering tags, reason }
|
|
1772
|
+
*/
|
|
1773
|
+
computeInterferenceEffect(cardTags, tagsToAvoid, immatureTags) {
|
|
1774
|
+
if (tagsToAvoid.size === 0) {
|
|
1775
|
+
return {
|
|
1776
|
+
multiplier: 1,
|
|
1777
|
+
interferingTags: [],
|
|
1778
|
+
reason: "No interference detected"
|
|
1779
|
+
};
|
|
1780
|
+
}
|
|
1781
|
+
let multiplier = 1;
|
|
1782
|
+
const interferingTags = [];
|
|
1783
|
+
for (const tag of cardTags) {
|
|
1784
|
+
const decay = tagsToAvoid.get(tag);
|
|
1785
|
+
if (decay !== void 0) {
|
|
1786
|
+
interferingTags.push(tag);
|
|
1787
|
+
multiplier *= 1 - decay;
|
|
1788
|
+
}
|
|
1789
|
+
}
|
|
1790
|
+
if (interferingTags.length === 0) {
|
|
1791
|
+
return {
|
|
1792
|
+
multiplier: 1,
|
|
1793
|
+
interferingTags: [],
|
|
1794
|
+
reason: "No interference detected"
|
|
1795
|
+
};
|
|
1796
|
+
}
|
|
1797
|
+
const causingTags = /* @__PURE__ */ new Set();
|
|
1798
|
+
for (const tag of interferingTags) {
|
|
1799
|
+
for (const immatureTag of immatureTags) {
|
|
1800
|
+
const partners = this.interferenceMap.get(immatureTag);
|
|
1801
|
+
if (partners?.some((p) => p.partner === tag)) {
|
|
1802
|
+
causingTags.add(immatureTag);
|
|
1803
|
+
}
|
|
1804
|
+
}
|
|
1805
|
+
}
|
|
1806
|
+
const reason = `Interferes with immature tags ${Array.from(causingTags).join(", ")} (tags: ${interferingTags.join(", ")}, multiplier: ${multiplier.toFixed(2)})`;
|
|
1807
|
+
return { multiplier, interferingTags, reason };
|
|
1808
|
+
}
|
|
1809
|
+
/**
|
|
1810
|
+
* CardFilter.transform implementation.
|
|
1811
|
+
*
|
|
1812
|
+
* Apply interference-aware scoring. Cards with tags that interfere with
|
|
1813
|
+
* immature learnings get reduced scores.
|
|
1814
|
+
*/
|
|
1815
|
+
async transform(cards, context) {
|
|
1816
|
+
const immatureTags = await this.getImmatureTags(context);
|
|
1817
|
+
const tagsToAvoid = this.getTagsToAvoid(immatureTags);
|
|
1818
|
+
const adjusted = [];
|
|
1819
|
+
for (const card of cards) {
|
|
1820
|
+
const cardTags = await this.getCardTags(card.cardId, context.course);
|
|
1821
|
+
const { multiplier, reason } = this.computeInterferenceEffect(
|
|
1822
|
+
cardTags,
|
|
1823
|
+
tagsToAvoid,
|
|
1824
|
+
immatureTags
|
|
1825
|
+
);
|
|
1826
|
+
const finalScore = card.score * multiplier;
|
|
1827
|
+
const action = multiplier < 1 ? "penalized" : multiplier > 1 ? "boosted" : "passed";
|
|
1828
|
+
adjusted.push({
|
|
1829
|
+
...card,
|
|
1830
|
+
score: finalScore,
|
|
1831
|
+
provenance: [
|
|
1832
|
+
...card.provenance,
|
|
1833
|
+
{
|
|
1834
|
+
strategy: "interferenceMitigator",
|
|
1835
|
+
strategyName: this.strategyName || this.name,
|
|
1836
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-interference",
|
|
1837
|
+
action,
|
|
1838
|
+
score: finalScore,
|
|
1839
|
+
reason
|
|
1840
|
+
}
|
|
1841
|
+
]
|
|
1842
|
+
});
|
|
1843
|
+
}
|
|
1844
|
+
return adjusted;
|
|
1845
|
+
}
|
|
1846
|
+
/**
|
|
1847
|
+
* Legacy getWeightedCards - now throws as filters should not be used as generators.
|
|
1848
|
+
*
|
|
1849
|
+
* Use transform() via Pipeline instead.
|
|
1850
|
+
*/
|
|
1851
|
+
async getWeightedCards(_limit) {
|
|
1852
|
+
throw new Error(
|
|
1853
|
+
"InterferenceMitigatorNavigator is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
|
|
1854
|
+
);
|
|
1855
|
+
}
|
|
1856
|
+
// Legacy methods - stub implementations since filters don't generate cards
|
|
1857
|
+
async getNewCards(_n) {
|
|
1858
|
+
return [];
|
|
1859
|
+
}
|
|
1860
|
+
async getPendingReviews() {
|
|
1861
|
+
return [];
|
|
1862
|
+
}
|
|
1863
|
+
};
|
|
1864
|
+
}
|
|
1865
|
+
});
|
|
1866
|
+
|
|
1867
|
+
// src/core/navigators/relativePriority.ts
|
|
1868
|
+
var relativePriority_exports = {};
|
|
1869
|
+
__export(relativePriority_exports, {
|
|
1870
|
+
default: () => RelativePriorityNavigator
|
|
1871
|
+
});
|
|
1872
|
+
var DEFAULT_PRIORITY, DEFAULT_PRIORITY_INFLUENCE, DEFAULT_COMBINE_MODE, RelativePriorityNavigator;
|
|
1873
|
+
var init_relativePriority = __esm({
|
|
1874
|
+
"src/core/navigators/relativePriority.ts"() {
|
|
1875
|
+
"use strict";
|
|
1876
|
+
init_navigators();
|
|
1877
|
+
DEFAULT_PRIORITY = 0.5;
|
|
1878
|
+
DEFAULT_PRIORITY_INFLUENCE = 0.5;
|
|
1879
|
+
DEFAULT_COMBINE_MODE = "max";
|
|
1880
|
+
RelativePriorityNavigator = class extends ContentNavigator {
|
|
1881
|
+
config;
|
|
1882
|
+
_strategyData;
|
|
1883
|
+
/** Human-readable name for CardFilter interface */
|
|
1884
|
+
name;
|
|
1885
|
+
constructor(user, course, _strategyData) {
|
|
1886
|
+
super(user, course, _strategyData);
|
|
1887
|
+
this._strategyData = _strategyData;
|
|
1888
|
+
this.config = this.parseConfig(_strategyData.serializedData);
|
|
1889
|
+
this.name = _strategyData.name || "Relative Priority";
|
|
1890
|
+
}
|
|
1891
|
+
parseConfig(serializedData) {
|
|
1892
|
+
try {
|
|
1893
|
+
const parsed = JSON.parse(serializedData);
|
|
1894
|
+
return {
|
|
1895
|
+
tagPriorities: parsed.tagPriorities || {},
|
|
1896
|
+
defaultPriority: parsed.defaultPriority ?? DEFAULT_PRIORITY,
|
|
1897
|
+
combineMode: parsed.combineMode ?? DEFAULT_COMBINE_MODE,
|
|
1898
|
+
priorityInfluence: parsed.priorityInfluence ?? DEFAULT_PRIORITY_INFLUENCE
|
|
1899
|
+
};
|
|
1900
|
+
} catch {
|
|
1901
|
+
return {
|
|
1902
|
+
tagPriorities: {},
|
|
1903
|
+
defaultPriority: DEFAULT_PRIORITY,
|
|
1904
|
+
combineMode: DEFAULT_COMBINE_MODE,
|
|
1905
|
+
priorityInfluence: DEFAULT_PRIORITY_INFLUENCE
|
|
1906
|
+
};
|
|
1907
|
+
}
|
|
1908
|
+
}
|
|
1909
|
+
/**
|
|
1910
|
+
* Look up the priority for a tag.
|
|
1911
|
+
*/
|
|
1912
|
+
getTagPriority(tagId) {
|
|
1913
|
+
return this.config.tagPriorities[tagId] ?? this.config.defaultPriority ?? DEFAULT_PRIORITY;
|
|
1914
|
+
}
|
|
1915
|
+
/**
|
|
1916
|
+
* Compute combined priority for a card based on its tags.
|
|
1917
|
+
*/
|
|
1918
|
+
computeCardPriority(cardTags) {
|
|
1919
|
+
if (cardTags.length === 0) {
|
|
1920
|
+
return this.config.defaultPriority ?? DEFAULT_PRIORITY;
|
|
1921
|
+
}
|
|
1922
|
+
const priorities = cardTags.map((tag) => this.getTagPriority(tag));
|
|
1923
|
+
switch (this.config.combineMode) {
|
|
1924
|
+
case "max":
|
|
1925
|
+
return Math.max(...priorities);
|
|
1926
|
+
case "min":
|
|
1927
|
+
return Math.min(...priorities);
|
|
1928
|
+
case "average":
|
|
1929
|
+
return priorities.reduce((sum, p) => sum + p, 0) / priorities.length;
|
|
1930
|
+
default:
|
|
1931
|
+
return Math.max(...priorities);
|
|
1932
|
+
}
|
|
1933
|
+
}
|
|
1934
|
+
/**
|
|
1935
|
+
* Compute boost factor based on priority.
|
|
1936
|
+
*
|
|
1937
|
+
* The formula: 1 + (priority - 0.5) * priorityInfluence
|
|
1938
|
+
*
|
|
1939
|
+
* This creates a multiplier centered around 1.0:
|
|
1940
|
+
* - Priority 1.0 with influence 0.5 → 1.25 (25% boost)
|
|
1941
|
+
* - Priority 0.5 with any influence → 1.00 (neutral)
|
|
1942
|
+
* - Priority 0.0 with influence 0.5 → 0.75 (25% reduction)
|
|
1943
|
+
*/
|
|
1944
|
+
computeBoostFactor(priority) {
|
|
1945
|
+
const influence = this.config.priorityInfluence ?? DEFAULT_PRIORITY_INFLUENCE;
|
|
1946
|
+
return 1 + (priority - 0.5) * influence;
|
|
1947
|
+
}
|
|
1948
|
+
/**
|
|
1949
|
+
* Build human-readable reason for priority adjustment.
|
|
1950
|
+
*/
|
|
1951
|
+
buildPriorityReason(cardTags, priority, boostFactor, finalScore) {
|
|
1952
|
+
if (cardTags.length === 0) {
|
|
1953
|
+
return `No tags, neutral priority (${priority.toFixed(2)})`;
|
|
1954
|
+
}
|
|
1955
|
+
const tagList = cardTags.slice(0, 3).join(", ");
|
|
1956
|
+
const more = cardTags.length > 3 ? ` (+${cardTags.length - 3} more)` : "";
|
|
1957
|
+
if (boostFactor === 1) {
|
|
1958
|
+
return `Neutral priority (${priority.toFixed(2)}) for tags: ${tagList}${more}`;
|
|
1959
|
+
} else if (boostFactor > 1) {
|
|
1960
|
+
return `High-priority tags: ${tagList}${more} (priority ${priority.toFixed(2)} \u2192 boost ${boostFactor.toFixed(2)}x \u2192 ${finalScore.toFixed(2)})`;
|
|
1961
|
+
} else {
|
|
1962
|
+
return `Low-priority tags: ${tagList}${more} (priority ${priority.toFixed(2)} \u2192 reduce ${boostFactor.toFixed(2)}x \u2192 ${finalScore.toFixed(2)})`;
|
|
1963
|
+
}
|
|
1964
|
+
}
|
|
1965
|
+
/**
|
|
1966
|
+
* Get tags for a single card.
|
|
1967
|
+
*/
|
|
1968
|
+
async getCardTags(cardId, course) {
|
|
1969
|
+
try {
|
|
1970
|
+
const tagResponse = await course.getAppliedTags(cardId);
|
|
1971
|
+
return tagResponse.rows.map((r) => r.doc?.name).filter((x) => !!x);
|
|
1972
|
+
} catch {
|
|
1973
|
+
return [];
|
|
1974
|
+
}
|
|
1975
|
+
}
|
|
1976
|
+
/**
|
|
1977
|
+
* CardFilter.transform implementation.
|
|
1978
|
+
*
|
|
1979
|
+
* Apply priority-adjusted scoring. Cards with high-priority tags get boosted,
|
|
1980
|
+
* cards with low-priority tags get reduced scores.
|
|
1981
|
+
*/
|
|
1982
|
+
async transform(cards, context) {
|
|
1983
|
+
const adjusted = await Promise.all(
|
|
1984
|
+
cards.map(async (card) => {
|
|
1985
|
+
const cardTags = await this.getCardTags(card.cardId, context.course);
|
|
1986
|
+
const priority = this.computeCardPriority(cardTags);
|
|
1987
|
+
const boostFactor = this.computeBoostFactor(priority);
|
|
1988
|
+
const finalScore = Math.max(0, Math.min(1, card.score * boostFactor));
|
|
1989
|
+
const action = boostFactor > 1 ? "boosted" : boostFactor < 1 ? "penalized" : "passed";
|
|
1990
|
+
const reason = this.buildPriorityReason(cardTags, priority, boostFactor, finalScore);
|
|
1991
|
+
return {
|
|
1992
|
+
...card,
|
|
1993
|
+
score: finalScore,
|
|
1994
|
+
provenance: [
|
|
1995
|
+
...card.provenance,
|
|
1996
|
+
{
|
|
1997
|
+
strategy: "relativePriority",
|
|
1998
|
+
strategyName: this.strategyName || this.name,
|
|
1999
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-priority",
|
|
2000
|
+
action,
|
|
2001
|
+
score: finalScore,
|
|
2002
|
+
reason
|
|
2003
|
+
}
|
|
2004
|
+
]
|
|
2005
|
+
};
|
|
2006
|
+
})
|
|
2007
|
+
);
|
|
2008
|
+
return adjusted;
|
|
2009
|
+
}
|
|
2010
|
+
/**
|
|
2011
|
+
* Legacy getWeightedCards - now throws as filters should not be used as generators.
|
|
2012
|
+
*
|
|
2013
|
+
* Use transform() via Pipeline instead.
|
|
2014
|
+
*/
|
|
2015
|
+
async getWeightedCards(_limit) {
|
|
2016
|
+
throw new Error(
|
|
2017
|
+
"RelativePriorityNavigator is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
|
|
2018
|
+
);
|
|
2019
|
+
}
|
|
2020
|
+
// Legacy methods - stub implementations since filters don't generate cards
|
|
2021
|
+
async getNewCards(_n) {
|
|
2022
|
+
return [];
|
|
2023
|
+
}
|
|
2024
|
+
async getPendingReviews() {
|
|
2025
|
+
return [];
|
|
750
2026
|
}
|
|
751
2027
|
};
|
|
752
2028
|
}
|
|
753
2029
|
});
|
|
754
2030
|
|
|
755
|
-
// src/core/navigators/
|
|
756
|
-
var
|
|
757
|
-
__export(
|
|
758
|
-
default: () =>
|
|
2031
|
+
// src/core/navigators/srs.ts
|
|
2032
|
+
var srs_exports = {};
|
|
2033
|
+
__export(srs_exports, {
|
|
2034
|
+
default: () => SRSNavigator
|
|
759
2035
|
});
|
|
760
|
-
|
|
761
|
-
var
|
|
762
|
-
|
|
2036
|
+
import moment3 from "moment";
|
|
2037
|
+
var SRSNavigator;
|
|
2038
|
+
var init_srs = __esm({
|
|
2039
|
+
"src/core/navigators/srs.ts"() {
|
|
763
2040
|
"use strict";
|
|
764
2041
|
init_navigators();
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
user;
|
|
769
|
-
course;
|
|
2042
|
+
SRSNavigator = class extends ContentNavigator {
|
|
2043
|
+
/** Human-readable name for CardGenerator interface */
|
|
2044
|
+
name;
|
|
770
2045
|
constructor(user, course, strategyData) {
|
|
771
|
-
super();
|
|
772
|
-
this.
|
|
773
|
-
this.course = course;
|
|
774
|
-
if (strategyData.serializedData) {
|
|
775
|
-
try {
|
|
776
|
-
this.orderedCardIds = JSON.parse(strategyData.serializedData);
|
|
777
|
-
} catch (e) {
|
|
778
|
-
logger.error("Failed to parse serializedData for HardcodedOrderNavigator", e);
|
|
779
|
-
}
|
|
780
|
-
}
|
|
2046
|
+
super(user, course, strategyData);
|
|
2047
|
+
this.name = strategyData?.name || "SRS";
|
|
781
2048
|
}
|
|
782
|
-
|
|
2049
|
+
/**
|
|
2050
|
+
* Get review cards scored by urgency.
|
|
2051
|
+
*
|
|
2052
|
+
* Score formula combines:
|
|
2053
|
+
* - Relative overdueness: hoursOverdue / intervalHours
|
|
2054
|
+
* - Interval recency: exponential decay favoring shorter intervals
|
|
2055
|
+
*
|
|
2056
|
+
* Cards not yet due are excluded (not scored as 0).
|
|
2057
|
+
*
|
|
2058
|
+
* This method supports both the legacy signature (limit only) and the
|
|
2059
|
+
* CardGenerator interface signature (limit, context).
|
|
2060
|
+
*
|
|
2061
|
+
* @param limit - Maximum number of cards to return
|
|
2062
|
+
* @param _context - Optional GeneratorContext (currently unused, but required for interface)
|
|
2063
|
+
*/
|
|
2064
|
+
async getWeightedCards(limit, _context) {
|
|
2065
|
+
if (!this.user || !this.course) {
|
|
2066
|
+
throw new Error("SRSNavigator requires user and course to be set");
|
|
2067
|
+
}
|
|
783
2068
|
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
784
|
-
|
|
2069
|
+
const now = moment3.utc();
|
|
2070
|
+
const dueReviews = reviews.filter((r) => now.isAfter(moment3.utc(r.reviewTime)));
|
|
2071
|
+
const scored = dueReviews.map((review) => {
|
|
2072
|
+
const { score, reason } = this.computeUrgencyScore(review, now);
|
|
785
2073
|
return {
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
2074
|
+
cardId: review.cardId,
|
|
2075
|
+
courseId: review.courseId,
|
|
2076
|
+
score,
|
|
2077
|
+
provenance: [
|
|
2078
|
+
{
|
|
2079
|
+
strategy: "srs",
|
|
2080
|
+
strategyName: this.strategyName || this.name,
|
|
2081
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-SRS-default",
|
|
2082
|
+
action: "generated",
|
|
2083
|
+
score,
|
|
2084
|
+
reason
|
|
2085
|
+
}
|
|
2086
|
+
]
|
|
793
2087
|
};
|
|
794
2088
|
});
|
|
2089
|
+
return scored.sort((a, b) => b.score - a.score).slice(0, limit);
|
|
795
2090
|
}
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
2091
|
+
/**
|
|
2092
|
+
* Compute urgency score for a review card.
|
|
2093
|
+
*
|
|
2094
|
+
* Two factors:
|
|
2095
|
+
* 1. Relative overdueness = hoursOverdue / intervalHours
|
|
2096
|
+
* - 2 days overdue on 3-day interval = 0.67 (urgent)
|
|
2097
|
+
* - 2 days overdue on 180-day interval = 0.01 (not urgent)
|
|
2098
|
+
*
|
|
2099
|
+
* 2. Interval recency factor = 0.3 + 0.7 * exp(-intervalHours / 720)
|
|
2100
|
+
* - 24h interval → ~1.0 (very recent learning)
|
|
2101
|
+
* - 30 days (720h) → ~0.56
|
|
2102
|
+
* - 180 days → ~0.30
|
|
2103
|
+
*
|
|
2104
|
+
* Combined: base 0.5 + weighted average of factors * 0.45
|
|
2105
|
+
* Result range: approximately 0.5 to 0.95
|
|
2106
|
+
*/
|
|
2107
|
+
computeUrgencyScore(review, now) {
|
|
2108
|
+
const scheduledAt = moment3.utc(review.scheduledAt);
|
|
2109
|
+
const due = moment3.utc(review.reviewTime);
|
|
2110
|
+
const intervalHours = Math.max(1, due.diff(scheduledAt, "hours"));
|
|
2111
|
+
const hoursOverdue = now.diff(due, "hours");
|
|
2112
|
+
const relativeOverdue = hoursOverdue / intervalHours;
|
|
2113
|
+
const recencyFactor = 0.3 + 0.7 * Math.exp(-intervalHours / 720);
|
|
2114
|
+
const overdueContribution = Math.min(1, Math.max(0, relativeOverdue));
|
|
2115
|
+
const urgency = overdueContribution * 0.5 + recencyFactor * 0.5;
|
|
2116
|
+
const score = Math.min(0.95, 0.5 + urgency * 0.45);
|
|
2117
|
+
const reason = `${Math.round(hoursOverdue)}h overdue (interval: ${Math.round(intervalHours)}h, relative: ${relativeOverdue.toFixed(2)}), recency: ${recencyFactor.toFixed(2)}, review`;
|
|
2118
|
+
return { score, reason };
|
|
2119
|
+
}
|
|
2120
|
+
/**
|
|
2121
|
+
* Get pending reviews in legacy format.
|
|
2122
|
+
*
|
|
2123
|
+
* Returns all pending reviews for the course, enriched with session item fields.
|
|
2124
|
+
*/
|
|
2125
|
+
async getPendingReviews() {
|
|
2126
|
+
if (!this.user || !this.course) {
|
|
2127
|
+
throw new Error("SRSNavigator requires user and course to be set");
|
|
2128
|
+
}
|
|
2129
|
+
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
2130
|
+
return reviews.map((r) => ({
|
|
2131
|
+
...r,
|
|
2132
|
+
contentSourceType: "course",
|
|
2133
|
+
contentSourceID: this.course.getCourseID(),
|
|
2134
|
+
cardID: r.cardId,
|
|
2135
|
+
courseID: r.courseId,
|
|
2136
|
+
qualifiedID: `${r.courseId}-${r.cardId}`,
|
|
2137
|
+
reviewID: r._id,
|
|
2138
|
+
status: "review"
|
|
2139
|
+
}));
|
|
2140
|
+
}
|
|
2141
|
+
/**
|
|
2142
|
+
* SRS does not generate new cards.
|
|
2143
|
+
* Use ELONavigator or another generator for new cards.
|
|
2144
|
+
*/
|
|
2145
|
+
async getNewCards(_n) {
|
|
2146
|
+
return [];
|
|
811
2147
|
}
|
|
812
2148
|
};
|
|
813
2149
|
}
|
|
@@ -818,9 +2154,21 @@ var globImport;
|
|
|
818
2154
|
var init_ = __esm({
|
|
819
2155
|
'import("./**/*") in src/core/navigators/index.ts'() {
|
|
820
2156
|
globImport = __glob({
|
|
2157
|
+
"./CompositeGenerator.ts": () => Promise.resolve().then(() => (init_CompositeGenerator(), CompositeGenerator_exports)),
|
|
2158
|
+
"./Pipeline.ts": () => Promise.resolve().then(() => (init_Pipeline(), Pipeline_exports)),
|
|
2159
|
+
"./PipelineAssembler.ts": () => Promise.resolve().then(() => (init_PipelineAssembler(), PipelineAssembler_exports)),
|
|
821
2160
|
"./elo.ts": () => Promise.resolve().then(() => (init_elo(), elo_exports)),
|
|
2161
|
+
"./filters/eloDistance.ts": () => Promise.resolve().then(() => (init_eloDistance(), eloDistance_exports)),
|
|
2162
|
+
"./filters/index.ts": () => Promise.resolve().then(() => (init_filters(), filters_exports)),
|
|
2163
|
+
"./filters/types.ts": () => Promise.resolve().then(() => (init_types(), types_exports)),
|
|
2164
|
+
"./generators/index.ts": () => Promise.resolve().then(() => (init_generators(), generators_exports)),
|
|
2165
|
+
"./generators/types.ts": () => Promise.resolve().then(() => (init_types2(), types_exports2)),
|
|
822
2166
|
"./hardcodedOrder.ts": () => Promise.resolve().then(() => (init_hardcodedOrder(), hardcodedOrder_exports)),
|
|
823
|
-
"./
|
|
2167
|
+
"./hierarchyDefinition.ts": () => Promise.resolve().then(() => (init_hierarchyDefinition(), hierarchyDefinition_exports)),
|
|
2168
|
+
"./index.ts": () => Promise.resolve().then(() => (init_navigators(), navigators_exports)),
|
|
2169
|
+
"./interferenceMitigator.ts": () => Promise.resolve().then(() => (init_interferenceMitigator(), interferenceMitigator_exports)),
|
|
2170
|
+
"./relativePriority.ts": () => Promise.resolve().then(() => (init_relativePriority(), relativePriority_exports)),
|
|
2171
|
+
"./srs.ts": () => Promise.resolve().then(() => (init_srs(), srs_exports))
|
|
824
2172
|
});
|
|
825
2173
|
}
|
|
826
2174
|
});
|
|
@@ -829,9 +2177,34 @@ var init_ = __esm({
|
|
|
829
2177
|
var navigators_exports = {};
|
|
830
2178
|
__export(navigators_exports, {
|
|
831
2179
|
ContentNavigator: () => ContentNavigator,
|
|
832
|
-
|
|
2180
|
+
NavigatorRole: () => NavigatorRole,
|
|
2181
|
+
NavigatorRoles: () => NavigatorRoles,
|
|
2182
|
+
Navigators: () => Navigators,
|
|
2183
|
+
getCardOrigin: () => getCardOrigin,
|
|
2184
|
+
isFilter: () => isFilter,
|
|
2185
|
+
isGenerator: () => isGenerator
|
|
833
2186
|
});
|
|
834
|
-
|
|
2187
|
+
function getCardOrigin(card) {
|
|
2188
|
+
if (card.provenance.length === 0) {
|
|
2189
|
+
throw new Error("Card has no provenance - cannot determine origin");
|
|
2190
|
+
}
|
|
2191
|
+
const firstEntry = card.provenance[0];
|
|
2192
|
+
const reason = firstEntry.reason.toLowerCase();
|
|
2193
|
+
if (reason.includes("failed")) {
|
|
2194
|
+
return "failed";
|
|
2195
|
+
}
|
|
2196
|
+
if (reason.includes("review")) {
|
|
2197
|
+
return "review";
|
|
2198
|
+
}
|
|
2199
|
+
return "new";
|
|
2200
|
+
}
|
|
2201
|
+
function isGenerator(impl) {
|
|
2202
|
+
return NavigatorRoles[impl] === "generator" /* GENERATOR */;
|
|
2203
|
+
}
|
|
2204
|
+
function isFilter(impl) {
|
|
2205
|
+
return NavigatorRoles[impl] === "filter" /* FILTER */;
|
|
2206
|
+
}
|
|
2207
|
+
var Navigators, NavigatorRole, NavigatorRoles, ContentNavigator;
|
|
835
2208
|
var init_navigators = __esm({
|
|
836
2209
|
"src/core/navigators/index.ts"() {
|
|
837
2210
|
"use strict";
|
|
@@ -839,14 +2212,55 @@ var init_navigators = __esm({
|
|
|
839
2212
|
init_();
|
|
840
2213
|
Navigators = /* @__PURE__ */ ((Navigators2) => {
|
|
841
2214
|
Navigators2["ELO"] = "elo";
|
|
2215
|
+
Navigators2["SRS"] = "srs";
|
|
842
2216
|
Navigators2["HARDCODED"] = "hardcodedOrder";
|
|
2217
|
+
Navigators2["HIERARCHY"] = "hierarchyDefinition";
|
|
2218
|
+
Navigators2["INTERFERENCE"] = "interferenceMitigator";
|
|
2219
|
+
Navigators2["RELATIVE_PRIORITY"] = "relativePriority";
|
|
843
2220
|
return Navigators2;
|
|
844
2221
|
})(Navigators || {});
|
|
2222
|
+
NavigatorRole = /* @__PURE__ */ ((NavigatorRole2) => {
|
|
2223
|
+
NavigatorRole2["GENERATOR"] = "generator";
|
|
2224
|
+
NavigatorRole2["FILTER"] = "filter";
|
|
2225
|
+
return NavigatorRole2;
|
|
2226
|
+
})(NavigatorRole || {});
|
|
2227
|
+
NavigatorRoles = {
|
|
2228
|
+
["elo" /* ELO */]: "generator" /* GENERATOR */,
|
|
2229
|
+
["srs" /* SRS */]: "generator" /* GENERATOR */,
|
|
2230
|
+
["hardcodedOrder" /* HARDCODED */]: "generator" /* GENERATOR */,
|
|
2231
|
+
["hierarchyDefinition" /* HIERARCHY */]: "filter" /* FILTER */,
|
|
2232
|
+
["interferenceMitigator" /* INTERFERENCE */]: "filter" /* FILTER */,
|
|
2233
|
+
["relativePriority" /* RELATIVE_PRIORITY */]: "filter" /* FILTER */
|
|
2234
|
+
};
|
|
845
2235
|
ContentNavigator = class {
|
|
2236
|
+
/** User interface for this navigation session */
|
|
2237
|
+
user;
|
|
2238
|
+
/** Course interface for this navigation session */
|
|
2239
|
+
course;
|
|
2240
|
+
/** Human-readable name for this strategy instance (from ContentNavigationStrategyData.name) */
|
|
2241
|
+
strategyName;
|
|
2242
|
+
/** Unique document ID for this strategy instance (from ContentNavigationStrategyData._id) */
|
|
2243
|
+
strategyId;
|
|
2244
|
+
/**
|
|
2245
|
+
* Constructor for standard navigators.
|
|
2246
|
+
* Call this from subclass constructors to initialize common fields.
|
|
2247
|
+
*
|
|
2248
|
+
* Note: CompositeGenerator doesn't use this pattern and should call super() without args.
|
|
2249
|
+
*/
|
|
2250
|
+
constructor(user, course, strategyData) {
|
|
2251
|
+
if (user && course && strategyData) {
|
|
2252
|
+
this.user = user;
|
|
2253
|
+
this.course = course;
|
|
2254
|
+
this.strategyName = strategyData.name;
|
|
2255
|
+
this.strategyId = strategyData._id;
|
|
2256
|
+
}
|
|
2257
|
+
}
|
|
846
2258
|
/**
|
|
2259
|
+
* Factory method to create navigator instances dynamically.
|
|
847
2260
|
*
|
|
848
|
-
* @param user
|
|
849
|
-
* @param
|
|
2261
|
+
* @param user - User interface
|
|
2262
|
+
* @param course - Course interface
|
|
2263
|
+
* @param strategyData - Strategy configuration document
|
|
850
2264
|
* @returns the runtime object used to steer a study session.
|
|
851
2265
|
*/
|
|
852
2266
|
static async create(user, course, strategyData) {
|
|
@@ -867,6 +2281,70 @@ var init_navigators = __esm({
|
|
|
867
2281
|
}
|
|
868
2282
|
return new NavigatorImpl(user, course, strategyData);
|
|
869
2283
|
}
|
|
2284
|
+
/**
|
|
2285
|
+
* Get cards with suitability scores and provenance trails.
|
|
2286
|
+
*
|
|
2287
|
+
* **This is the PRIMARY API for navigation strategies.**
|
|
2288
|
+
*
|
|
2289
|
+
* Returns cards ranked by suitability score (0-1). Higher scores indicate
|
|
2290
|
+
* better candidates for presentation. Each card includes a provenance trail
|
|
2291
|
+
* documenting how strategies contributed to the final score.
|
|
2292
|
+
*
|
|
2293
|
+
* ## For Generators
|
|
2294
|
+
* Override this method to generate candidates and compute scores based on
|
|
2295
|
+
* your strategy's logic (e.g., ELO proximity, review urgency). Create the
|
|
2296
|
+
* initial provenance entry with action='generated'.
|
|
2297
|
+
*
|
|
2298
|
+
* ## Default Implementation
|
|
2299
|
+
* The base class provides a backward-compatible default that:
|
|
2300
|
+
* 1. Calls legacy getNewCards() and getPendingReviews()
|
|
2301
|
+
* 2. Assigns score=1.0 to all cards
|
|
2302
|
+
* 3. Creates minimal provenance from legacy methods
|
|
2303
|
+
* 4. Returns combined results up to limit
|
|
2304
|
+
*
|
|
2305
|
+
* This allows existing strategies to work without modification while
|
|
2306
|
+
* new strategies can override with proper scoring and provenance.
|
|
2307
|
+
*
|
|
2308
|
+
* @param limit - Maximum cards to return
|
|
2309
|
+
* @returns Cards sorted by score descending, with provenance trails
|
|
2310
|
+
*/
|
|
2311
|
+
async getWeightedCards(limit) {
|
|
2312
|
+
const newCards = await this.getNewCards(limit);
|
|
2313
|
+
const reviews = await this.getPendingReviews();
|
|
2314
|
+
const weighted = [
|
|
2315
|
+
...newCards.map((c) => ({
|
|
2316
|
+
cardId: c.cardID,
|
|
2317
|
+
courseId: c.courseID,
|
|
2318
|
+
score: 1,
|
|
2319
|
+
provenance: [
|
|
2320
|
+
{
|
|
2321
|
+
strategy: "legacy",
|
|
2322
|
+
strategyName: this.strategyName || "Legacy API",
|
|
2323
|
+
strategyId: this.strategyId || "legacy-fallback",
|
|
2324
|
+
action: "generated",
|
|
2325
|
+
score: 1,
|
|
2326
|
+
reason: "Generated via legacy getNewCards(), new card"
|
|
2327
|
+
}
|
|
2328
|
+
]
|
|
2329
|
+
})),
|
|
2330
|
+
...reviews.map((r) => ({
|
|
2331
|
+
cardId: r.cardID,
|
|
2332
|
+
courseId: r.courseID,
|
|
2333
|
+
score: 1,
|
|
2334
|
+
provenance: [
|
|
2335
|
+
{
|
|
2336
|
+
strategy: "legacy",
|
|
2337
|
+
strategyName: this.strategyName || "Legacy API",
|
|
2338
|
+
strategyId: this.strategyId || "legacy-fallback",
|
|
2339
|
+
action: "generated",
|
|
2340
|
+
score: 1,
|
|
2341
|
+
reason: "Generated via legacy getPendingReviews(), review"
|
|
2342
|
+
}
|
|
2343
|
+
]
|
|
2344
|
+
}))
|
|
2345
|
+
];
|
|
2346
|
+
return weighted.slice(0, limit);
|
|
2347
|
+
}
|
|
870
2348
|
};
|
|
871
2349
|
}
|
|
872
2350
|
});
|
|
@@ -876,7 +2354,7 @@ import {
|
|
|
876
2354
|
EloToNumber,
|
|
877
2355
|
Status,
|
|
878
2356
|
blankCourseElo as blankCourseElo2,
|
|
879
|
-
toCourseElo as
|
|
2357
|
+
toCourseElo as toCourseElo6
|
|
880
2358
|
} from "@vue-skuilder/common";
|
|
881
2359
|
function randIntWeightedTowardZero(n) {
|
|
882
2360
|
return Math.floor(Math.random() * Math.random() * Math.random() * n);
|
|
@@ -965,6 +2443,12 @@ var init_courseDB = __esm({
|
|
|
965
2443
|
init_courseAPI();
|
|
966
2444
|
init_courseLookupDB();
|
|
967
2445
|
init_navigators();
|
|
2446
|
+
init_Pipeline();
|
|
2447
|
+
init_PipelineAssembler();
|
|
2448
|
+
init_CompositeGenerator();
|
|
2449
|
+
init_elo();
|
|
2450
|
+
init_srs();
|
|
2451
|
+
init_eloDistance();
|
|
968
2452
|
CourseDB = class {
|
|
969
2453
|
// private log(msg: string): void {
|
|
970
2454
|
// log(`CourseLog: ${this.id}\n ${msg}`);
|
|
@@ -1031,7 +2515,7 @@ var init_courseDB = __esm({
|
|
|
1031
2515
|
docs.rows.forEach((r) => {
|
|
1032
2516
|
if (isSuccessRow(r)) {
|
|
1033
2517
|
if (r.doc && r.doc.elo) {
|
|
1034
|
-
ret.push(
|
|
2518
|
+
ret.push(toCourseElo6(r.doc.elo));
|
|
1035
2519
|
} else {
|
|
1036
2520
|
logger.warn("no elo data for card: " + r.id);
|
|
1037
2521
|
ret.push(blankCourseElo2());
|
|
@@ -1304,42 +2788,82 @@ ${above.rows.map((r) => ` ${r.id}-${r.key}
|
|
|
1304
2788
|
logger.debug(JSON.stringify(data));
|
|
1305
2789
|
return Promise.resolve();
|
|
1306
2790
|
}
|
|
1307
|
-
|
|
2791
|
+
/**
|
|
2792
|
+
* Creates an instantiated navigator for this course.
|
|
2793
|
+
*
|
|
2794
|
+
* Handles multiple generators by wrapping them in CompositeGenerator.
|
|
2795
|
+
* This is the preferred method for getting a ready-to-use navigator.
|
|
2796
|
+
*
|
|
2797
|
+
* @param user - User database interface
|
|
2798
|
+
* @returns Instantiated ContentNavigator ready for use
|
|
2799
|
+
*/
|
|
2800
|
+
async createNavigator(user) {
|
|
1308
2801
|
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
|
-
}
|
|
2802
|
+
const allStrategies = await this.getAllNavigationStrategies();
|
|
2803
|
+
if (allStrategies.length === 0) {
|
|
2804
|
+
logger.debug(
|
|
2805
|
+
"[courseDB] No strategy documents found, using default Pipeline(Composite(ELO, SRS), [eloDistanceFilter])"
|
|
2806
|
+
);
|
|
2807
|
+
return this.createDefaultPipeline(user);
|
|
1324
2808
|
}
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
2809
|
+
const assembler = new PipelineAssembler();
|
|
2810
|
+
const { pipeline, generatorStrategies, filterStrategies, warnings } = await assembler.assemble({
|
|
2811
|
+
strategies: allStrategies,
|
|
2812
|
+
user,
|
|
2813
|
+
course: this
|
|
2814
|
+
});
|
|
2815
|
+
for (const warning of warnings) {
|
|
2816
|
+
logger.warn(`[PipelineAssembler] ${warning}`);
|
|
2817
|
+
}
|
|
2818
|
+
if (!pipeline) {
|
|
2819
|
+
logger.debug("[courseDB] Pipeline assembly failed, using default pipeline");
|
|
2820
|
+
return this.createDefaultPipeline(user);
|
|
2821
|
+
}
|
|
2822
|
+
logger.debug(
|
|
2823
|
+
`[courseDB] Using assembled pipeline with ${generatorStrategies.length} generator(s) and ${filterStrategies.length} filter(s)`
|
|
1329
2824
|
);
|
|
2825
|
+
return pipeline;
|
|
2826
|
+
} catch (e) {
|
|
2827
|
+
logger.error(`[courseDB] Error creating navigator: ${e}`);
|
|
2828
|
+
throw e;
|
|
1330
2829
|
}
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
2830
|
+
}
|
|
2831
|
+
makeDefaultEloStrategy() {
|
|
2832
|
+
return {
|
|
2833
|
+
_id: "NAVIGATION_STRATEGY-ELO-default",
|
|
1334
2834
|
docType: "NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */,
|
|
1335
|
-
name: "ELO",
|
|
1336
|
-
description: "ELO-based navigation strategy",
|
|
2835
|
+
name: "ELO (default)",
|
|
2836
|
+
description: "Default ELO-based navigation strategy for new cards",
|
|
1337
2837
|
implementingClass: "elo" /* ELO */,
|
|
1338
2838
|
course: this.id,
|
|
1339
2839
|
serializedData: ""
|
|
1340
|
-
// serde is a noop for ELO navigator.
|
|
1341
2840
|
};
|
|
1342
|
-
|
|
2841
|
+
}
|
|
2842
|
+
makeDefaultSrsStrategy() {
|
|
2843
|
+
return {
|
|
2844
|
+
_id: "NAVIGATION_STRATEGY-SRS-default",
|
|
2845
|
+
docType: "NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */,
|
|
2846
|
+
name: "SRS (default)",
|
|
2847
|
+
description: "Default SRS-based navigation strategy for reviews",
|
|
2848
|
+
implementingClass: "srs" /* SRS */,
|
|
2849
|
+
course: this.id,
|
|
2850
|
+
serializedData: ""
|
|
2851
|
+
};
|
|
2852
|
+
}
|
|
2853
|
+
/**
|
|
2854
|
+
* Creates the default navigation pipeline for courses with no configured strategies.
|
|
2855
|
+
*
|
|
2856
|
+
* Default: Pipeline(Composite(ELO, SRS), [eloDistanceFilter])
|
|
2857
|
+
* - ELO generator: scores new cards by skill proximity
|
|
2858
|
+
* - SRS generator: scores reviews by overdueness and interval recency
|
|
2859
|
+
* - ELO distance filter: penalizes cards far from user's current level
|
|
2860
|
+
*/
|
|
2861
|
+
createDefaultPipeline(user) {
|
|
2862
|
+
const eloNavigator = new ELONavigator(user, this, this.makeDefaultEloStrategy());
|
|
2863
|
+
const srsNavigator = new SRSNavigator(user, this, this.makeDefaultSrsStrategy());
|
|
2864
|
+
const compositeGenerator = new CompositeGenerator([eloNavigator, srsNavigator]);
|
|
2865
|
+
const eloDistanceFilter = createEloDistanceFilter();
|
|
2866
|
+
return new Pipeline(compositeGenerator, [eloDistanceFilter], user, this);
|
|
1343
2867
|
}
|
|
1344
2868
|
////////////////////////////////////
|
|
1345
2869
|
// END NavigationStrategyManager implementation
|
|
@@ -1350,22 +2874,39 @@ ${above.rows.map((r) => ` ${r.id}-${r.key}
|
|
|
1350
2874
|
async getNewCards(limit = 99) {
|
|
1351
2875
|
const u = await this._getCurrentUser();
|
|
1352
2876
|
try {
|
|
1353
|
-
const
|
|
1354
|
-
const navigator = await ContentNavigator.create(u, this, strategy);
|
|
2877
|
+
const navigator = await this.createNavigator(u);
|
|
1355
2878
|
return navigator.getNewCards(limit);
|
|
1356
2879
|
} catch (e) {
|
|
1357
|
-
logger.error(`[courseDB] Error
|
|
2880
|
+
logger.error(`[courseDB] Error in getNewCards: ${e}`);
|
|
1358
2881
|
throw e;
|
|
1359
2882
|
}
|
|
1360
2883
|
}
|
|
1361
2884
|
async getPendingReviews() {
|
|
1362
2885
|
const u = await this._getCurrentUser();
|
|
1363
2886
|
try {
|
|
1364
|
-
const
|
|
1365
|
-
const navigator = await ContentNavigator.create(u, this, strategy);
|
|
2887
|
+
const navigator = await this.createNavigator(u);
|
|
1366
2888
|
return navigator.getPendingReviews();
|
|
1367
2889
|
} catch (e) {
|
|
1368
|
-
logger.error(`[courseDB] Error
|
|
2890
|
+
logger.error(`[courseDB] Error in getPendingReviews: ${e}`);
|
|
2891
|
+
throw e;
|
|
2892
|
+
}
|
|
2893
|
+
}
|
|
2894
|
+
/**
|
|
2895
|
+
* Get cards with suitability scores for presentation.
|
|
2896
|
+
*
|
|
2897
|
+
* This is the PRIMARY API for content sources going forward. Delegates to the
|
|
2898
|
+
* course's configured NavigationStrategy to get scored candidates.
|
|
2899
|
+
*
|
|
2900
|
+
* @param limit - Maximum number of cards to return
|
|
2901
|
+
* @returns Cards sorted by score descending
|
|
2902
|
+
*/
|
|
2903
|
+
async getWeightedCards(limit) {
|
|
2904
|
+
const u = await this._getCurrentUser();
|
|
2905
|
+
try {
|
|
2906
|
+
const navigator = await this.createNavigator(u);
|
|
2907
|
+
return navigator.getWeightedCards(limit);
|
|
2908
|
+
} catch (e) {
|
|
2909
|
+
logger.error(`[courseDB] Error getting weighted cards: ${e}`);
|
|
1369
2910
|
throw e;
|
|
1370
2911
|
}
|
|
1371
2912
|
}
|
|
@@ -1505,7 +3046,7 @@ ${above.rows.map((r) => ` ${r.id}-${r.key}
|
|
|
1505
3046
|
});
|
|
1506
3047
|
|
|
1507
3048
|
// src/impl/couch/classroomDB.ts
|
|
1508
|
-
import
|
|
3049
|
+
import moment4 from "moment";
|
|
1509
3050
|
var CLASSROOM_CONFIG, ClassroomDBBase, StudentClassroomDB;
|
|
1510
3051
|
var init_classroomDB2 = __esm({
|
|
1511
3052
|
"src/impl/couch/classroomDB.ts"() {
|
|
@@ -1605,9 +3146,9 @@ var init_classroomDB2 = __esm({
|
|
|
1605
3146
|
}
|
|
1606
3147
|
async getNewCards() {
|
|
1607
3148
|
const activeCards = await this._user.getActiveCards();
|
|
1608
|
-
const now =
|
|
3149
|
+
const now = moment4.utc();
|
|
1609
3150
|
const assigned = await this.getAssignedContent();
|
|
1610
|
-
const due = assigned.filter((c) => now.isAfter(
|
|
3151
|
+
const due = assigned.filter((c) => now.isAfter(moment4.utc(c.activeOn, REVIEW_TIME_FORMAT2)));
|
|
1611
3152
|
logger.info(`Due content: ${JSON.stringify(due)}`);
|
|
1612
3153
|
let ret = [];
|
|
1613
3154
|
for (let i = 0; i < due.length; i++) {
|
|
@@ -1644,6 +3185,52 @@ var init_classroomDB2 = __esm({
|
|
|
1644
3185
|
}
|
|
1645
3186
|
});
|
|
1646
3187
|
}
|
|
3188
|
+
/**
|
|
3189
|
+
* Get cards with suitability scores for presentation.
|
|
3190
|
+
*
|
|
3191
|
+
* This implementation wraps the legacy getNewCards/getPendingReviews methods,
|
|
3192
|
+
* assigning score=1.0 to all cards. StudentClassroomDB does not currently
|
|
3193
|
+
* support pluggable navigation strategies.
|
|
3194
|
+
*
|
|
3195
|
+
* @param limit - Maximum number of cards to return
|
|
3196
|
+
* @returns Cards sorted by score descending (all scores = 1.0)
|
|
3197
|
+
*/
|
|
3198
|
+
async getWeightedCards(limit) {
|
|
3199
|
+
const [newCards, reviews] = await Promise.all([this.getNewCards(), this.getPendingReviews()]);
|
|
3200
|
+
const weighted = [
|
|
3201
|
+
...newCards.map((c) => ({
|
|
3202
|
+
cardId: c.cardID,
|
|
3203
|
+
courseId: c.courseID,
|
|
3204
|
+
score: 1,
|
|
3205
|
+
provenance: [
|
|
3206
|
+
{
|
|
3207
|
+
strategy: "classroom",
|
|
3208
|
+
strategyName: "Classroom",
|
|
3209
|
+
strategyId: "CLASSROOM",
|
|
3210
|
+
action: "generated",
|
|
3211
|
+
score: 1,
|
|
3212
|
+
reason: "Classroom legacy getNewCards(), new card"
|
|
3213
|
+
}
|
|
3214
|
+
]
|
|
3215
|
+
})),
|
|
3216
|
+
...reviews.map((r) => ({
|
|
3217
|
+
cardId: r.cardID,
|
|
3218
|
+
courseId: r.courseID,
|
|
3219
|
+
score: 1,
|
|
3220
|
+
provenance: [
|
|
3221
|
+
{
|
|
3222
|
+
strategy: "classroom",
|
|
3223
|
+
strategyName: "Classroom",
|
|
3224
|
+
strategyId: "CLASSROOM",
|
|
3225
|
+
action: "generated",
|
|
3226
|
+
score: 1,
|
|
3227
|
+
reason: "Classroom legacy getPendingReviews(), review"
|
|
3228
|
+
}
|
|
3229
|
+
]
|
|
3230
|
+
}))
|
|
3231
|
+
];
|
|
3232
|
+
return weighted.slice(0, limit);
|
|
3233
|
+
}
|
|
1647
3234
|
};
|
|
1648
3235
|
}
|
|
1649
3236
|
});
|
|
@@ -1688,7 +3275,7 @@ var init_CouchDBSyncStrategy = __esm({
|
|
|
1688
3275
|
|
|
1689
3276
|
// src/impl/couch/index.ts
|
|
1690
3277
|
import fetch2 from "cross-fetch";
|
|
1691
|
-
import
|
|
3278
|
+
import moment5 from "moment";
|
|
1692
3279
|
import process2 from "process";
|
|
1693
3280
|
function createPouchDBConfig() {
|
|
1694
3281
|
const hasExplicitCredentials = ENV.COUCHDB_USERNAME && ENV.COUCHDB_PASSWORD;
|
|
@@ -1773,7 +3360,7 @@ var init_couch = __esm({
|
|
|
1773
3360
|
|
|
1774
3361
|
// src/impl/common/BaseUserDB.ts
|
|
1775
3362
|
import { Status as Status3 } from "@vue-skuilder/common";
|
|
1776
|
-
import
|
|
3363
|
+
import moment6 from "moment";
|
|
1777
3364
|
async function getOrCreateClassroomRegistrationsDoc(user) {
|
|
1778
3365
|
let ret;
|
|
1779
3366
|
try {
|
|
@@ -2132,7 +3719,7 @@ Currently logged-in as ${this._username}.`
|
|
|
2132
3719
|
);
|
|
2133
3720
|
return reviews.rows.filter((r) => {
|
|
2134
3721
|
if (r.id.startsWith(DocTypePrefixes["SCHEDULED_CARD" /* SCHEDULED_CARD */])) {
|
|
2135
|
-
const date =
|
|
3722
|
+
const date = moment6.utc(
|
|
2136
3723
|
r.id.substr(DocTypePrefixes["SCHEDULED_CARD" /* SCHEDULED_CARD */].length),
|
|
2137
3724
|
REVIEW_TIME_FORMAT
|
|
2138
3725
|
);
|
|
@@ -2145,11 +3732,11 @@ Currently logged-in as ${this._username}.`
|
|
|
2145
3732
|
}).map((r) => r.doc);
|
|
2146
3733
|
}
|
|
2147
3734
|
async getReviewsForcast(daysCount) {
|
|
2148
|
-
const time =
|
|
3735
|
+
const time = moment6.utc().add(daysCount, "days");
|
|
2149
3736
|
return this.getReviewstoDate(time);
|
|
2150
3737
|
}
|
|
2151
3738
|
async getPendingReviews(course_id) {
|
|
2152
|
-
const now =
|
|
3739
|
+
const now = moment6.utc();
|
|
2153
3740
|
return this.getReviewstoDate(now, course_id);
|
|
2154
3741
|
}
|
|
2155
3742
|
async getScheduledReviewCount(course_id) {
|
|
@@ -2436,7 +4023,7 @@ Currently logged-in as ${this._username}.`
|
|
|
2436
4023
|
*/
|
|
2437
4024
|
async putCardRecord(record) {
|
|
2438
4025
|
const cardHistoryID = getCardHistoryID(record.courseID, record.cardID);
|
|
2439
|
-
record.timeStamp =
|
|
4026
|
+
record.timeStamp = moment6.utc(record.timeStamp).toString();
|
|
2440
4027
|
try {
|
|
2441
4028
|
const cardHistory = await this.update(
|
|
2442
4029
|
cardHistoryID,
|
|
@@ -2452,7 +4039,7 @@ Currently logged-in as ${this._username}.`
|
|
|
2452
4039
|
const ret = {
|
|
2453
4040
|
...record2
|
|
2454
4041
|
};
|
|
2455
|
-
ret.timeStamp =
|
|
4042
|
+
ret.timeStamp = moment6.utc(record2.timeStamp);
|
|
2456
4043
|
return ret;
|
|
2457
4044
|
});
|
|
2458
4045
|
return cardHistory;
|
|
@@ -2715,7 +4302,215 @@ var init_factory = __esm({
|
|
|
2715
4302
|
}
|
|
2716
4303
|
});
|
|
2717
4304
|
|
|
4305
|
+
// src/study/TagFilteredContentSource.ts
|
|
4306
|
+
import { hasActiveFilter } from "@vue-skuilder/common";
|
|
4307
|
+
var TagFilteredContentSource;
|
|
4308
|
+
var init_TagFilteredContentSource = __esm({
|
|
4309
|
+
"src/study/TagFilteredContentSource.ts"() {
|
|
4310
|
+
"use strict";
|
|
4311
|
+
init_courseDB();
|
|
4312
|
+
init_logger();
|
|
4313
|
+
TagFilteredContentSource = class {
|
|
4314
|
+
courseId;
|
|
4315
|
+
filter;
|
|
4316
|
+
user;
|
|
4317
|
+
// Cache resolved card IDs to avoid repeated lookups within a session
|
|
4318
|
+
resolvedCardIds = null;
|
|
4319
|
+
constructor(courseId, filter, user) {
|
|
4320
|
+
this.courseId = courseId;
|
|
4321
|
+
this.filter = filter;
|
|
4322
|
+
this.user = user;
|
|
4323
|
+
logger.info(
|
|
4324
|
+
`[TagFilteredContentSource] Created for course "${courseId}" with filter:`,
|
|
4325
|
+
JSON.stringify(filter)
|
|
4326
|
+
);
|
|
4327
|
+
}
|
|
4328
|
+
/**
|
|
4329
|
+
* Resolves the TagFilter to a set of eligible card IDs.
|
|
4330
|
+
*
|
|
4331
|
+
* - Cards in `include` tags are OR'd together (card needs at least one)
|
|
4332
|
+
* - Cards in `exclude` tags are removed from the result
|
|
4333
|
+
*/
|
|
4334
|
+
async resolveFilteredCardIds() {
|
|
4335
|
+
if (this.resolvedCardIds !== null) {
|
|
4336
|
+
return this.resolvedCardIds;
|
|
4337
|
+
}
|
|
4338
|
+
const includedCardIds = /* @__PURE__ */ new Set();
|
|
4339
|
+
if (this.filter.include.length > 0) {
|
|
4340
|
+
for (const tagName of this.filter.include) {
|
|
4341
|
+
try {
|
|
4342
|
+
const tagDoc = await getTag(this.courseId, tagName);
|
|
4343
|
+
tagDoc.taggedCards.forEach((cardId) => includedCardIds.add(cardId));
|
|
4344
|
+
} catch (error) {
|
|
4345
|
+
logger.warn(
|
|
4346
|
+
`[TagFilteredContentSource] Could not resolve tag "${tagName}" for inclusion:`,
|
|
4347
|
+
error
|
|
4348
|
+
);
|
|
4349
|
+
}
|
|
4350
|
+
}
|
|
4351
|
+
}
|
|
4352
|
+
if (includedCardIds.size === 0 && this.filter.include.length > 0) {
|
|
4353
|
+
logger.warn(
|
|
4354
|
+
`[TagFilteredContentSource] No cards found for include tags: ${this.filter.include.join(", ")}`
|
|
4355
|
+
);
|
|
4356
|
+
this.resolvedCardIds = /* @__PURE__ */ new Set();
|
|
4357
|
+
return this.resolvedCardIds;
|
|
4358
|
+
}
|
|
4359
|
+
const excludedCardIds = /* @__PURE__ */ new Set();
|
|
4360
|
+
if (this.filter.exclude.length > 0) {
|
|
4361
|
+
for (const tagName of this.filter.exclude) {
|
|
4362
|
+
try {
|
|
4363
|
+
const tagDoc = await getTag(this.courseId, tagName);
|
|
4364
|
+
tagDoc.taggedCards.forEach((cardId) => excludedCardIds.add(cardId));
|
|
4365
|
+
} catch (error) {
|
|
4366
|
+
logger.warn(
|
|
4367
|
+
`[TagFilteredContentSource] Could not resolve tag "${tagName}" for exclusion:`,
|
|
4368
|
+
error
|
|
4369
|
+
);
|
|
4370
|
+
}
|
|
4371
|
+
}
|
|
4372
|
+
}
|
|
4373
|
+
const finalCardIds = /* @__PURE__ */ new Set();
|
|
4374
|
+
for (const cardId of includedCardIds) {
|
|
4375
|
+
if (!excludedCardIds.has(cardId)) {
|
|
4376
|
+
finalCardIds.add(cardId);
|
|
4377
|
+
}
|
|
4378
|
+
}
|
|
4379
|
+
logger.info(
|
|
4380
|
+
`[TagFilteredContentSource] Resolved ${finalCardIds.size} cards (included: ${includedCardIds.size}, excluded: ${excludedCardIds.size})`
|
|
4381
|
+
);
|
|
4382
|
+
this.resolvedCardIds = finalCardIds;
|
|
4383
|
+
return finalCardIds;
|
|
4384
|
+
}
|
|
4385
|
+
/**
|
|
4386
|
+
* Gets new cards that match the tag filter and are not already active for the user.
|
|
4387
|
+
*/
|
|
4388
|
+
async getNewCards(limit) {
|
|
4389
|
+
if (!hasActiveFilter(this.filter)) {
|
|
4390
|
+
logger.warn("[TagFilteredContentSource] getNewCards called with no active filter");
|
|
4391
|
+
return [];
|
|
4392
|
+
}
|
|
4393
|
+
const eligibleCardIds = await this.resolveFilteredCardIds();
|
|
4394
|
+
const activeCards = await this.user.getActiveCards();
|
|
4395
|
+
const activeCardIds = new Set(activeCards.map((c) => c.cardID));
|
|
4396
|
+
const newItems = [];
|
|
4397
|
+
for (const cardId of eligibleCardIds) {
|
|
4398
|
+
if (!activeCardIds.has(cardId)) {
|
|
4399
|
+
newItems.push({
|
|
4400
|
+
courseID: this.courseId,
|
|
4401
|
+
cardID: cardId,
|
|
4402
|
+
contentSourceType: "course",
|
|
4403
|
+
contentSourceID: this.courseId,
|
|
4404
|
+
status: "new"
|
|
4405
|
+
});
|
|
4406
|
+
}
|
|
4407
|
+
if (limit !== void 0 && newItems.length >= limit) {
|
|
4408
|
+
break;
|
|
4409
|
+
}
|
|
4410
|
+
}
|
|
4411
|
+
logger.info(`[TagFilteredContentSource] Found ${newItems.length} new cards matching filter`);
|
|
4412
|
+
return newItems;
|
|
4413
|
+
}
|
|
4414
|
+
/**
|
|
4415
|
+
* Gets pending reviews, filtered to only include cards that match the tag filter.
|
|
4416
|
+
*/
|
|
4417
|
+
async getPendingReviews() {
|
|
4418
|
+
if (!hasActiveFilter(this.filter)) {
|
|
4419
|
+
logger.warn("[TagFilteredContentSource] getPendingReviews called with no active filter");
|
|
4420
|
+
return [];
|
|
4421
|
+
}
|
|
4422
|
+
const eligibleCardIds = await this.resolveFilteredCardIds();
|
|
4423
|
+
const allReviews = await this.user.getPendingReviews(this.courseId);
|
|
4424
|
+
const filteredReviews = allReviews.filter((review) => {
|
|
4425
|
+
return eligibleCardIds.has(review.cardId);
|
|
4426
|
+
});
|
|
4427
|
+
logger.info(
|
|
4428
|
+
`[TagFilteredContentSource] Found ${filteredReviews.length} pending reviews matching filter (of ${allReviews.length} total)`
|
|
4429
|
+
);
|
|
4430
|
+
return filteredReviews.map((r) => ({
|
|
4431
|
+
...r,
|
|
4432
|
+
courseID: r.courseId,
|
|
4433
|
+
cardID: r.cardId,
|
|
4434
|
+
contentSourceType: "course",
|
|
4435
|
+
contentSourceID: this.courseId,
|
|
4436
|
+
reviewID: r._id,
|
|
4437
|
+
status: "review"
|
|
4438
|
+
}));
|
|
4439
|
+
}
|
|
4440
|
+
/**
|
|
4441
|
+
* Get cards with suitability scores for presentation.
|
|
4442
|
+
*
|
|
4443
|
+
* This implementation wraps the legacy getNewCards/getPendingReviews methods,
|
|
4444
|
+
* assigning score=1.0 to all cards. TagFilteredContentSource does not currently
|
|
4445
|
+
* support pluggable navigation strategies - it returns flat-scored candidates.
|
|
4446
|
+
*
|
|
4447
|
+
* @param limit - Maximum number of cards to return
|
|
4448
|
+
* @returns Cards sorted by score descending (all scores = 1.0)
|
|
4449
|
+
*/
|
|
4450
|
+
async getWeightedCards(limit) {
|
|
4451
|
+
const [newCards, reviews] = await Promise.all([
|
|
4452
|
+
this.getNewCards(limit),
|
|
4453
|
+
this.getPendingReviews()
|
|
4454
|
+
]);
|
|
4455
|
+
const weighted = [
|
|
4456
|
+
...reviews.map((r) => ({
|
|
4457
|
+
cardId: r.cardID,
|
|
4458
|
+
courseId: r.courseID,
|
|
4459
|
+
score: 1,
|
|
4460
|
+
provenance: [
|
|
4461
|
+
{
|
|
4462
|
+
strategy: "tagFilter",
|
|
4463
|
+
strategyName: "Tag Filter",
|
|
4464
|
+
strategyId: "TAG_FILTER",
|
|
4465
|
+
action: "generated",
|
|
4466
|
+
score: 1,
|
|
4467
|
+
reason: `Tag-filtered review (tags: ${this.filter.include.join(", ")})`
|
|
4468
|
+
}
|
|
4469
|
+
]
|
|
4470
|
+
})),
|
|
4471
|
+
...newCards.map((c) => ({
|
|
4472
|
+
cardId: c.cardID,
|
|
4473
|
+
courseId: c.courseID,
|
|
4474
|
+
score: 1,
|
|
4475
|
+
provenance: [
|
|
4476
|
+
{
|
|
4477
|
+
strategy: "tagFilter",
|
|
4478
|
+
strategyName: "Tag Filter",
|
|
4479
|
+
strategyId: "TAG_FILTER",
|
|
4480
|
+
action: "generated",
|
|
4481
|
+
score: 1,
|
|
4482
|
+
reason: `Tag-filtered new card (tags: ${this.filter.include.join(", ")})`
|
|
4483
|
+
}
|
|
4484
|
+
]
|
|
4485
|
+
}))
|
|
4486
|
+
];
|
|
4487
|
+
return weighted.slice(0, limit);
|
|
4488
|
+
}
|
|
4489
|
+
/**
|
|
4490
|
+
* Clears the cached resolved card IDs.
|
|
4491
|
+
* Call this if the underlying tag data may have changed during a session.
|
|
4492
|
+
*/
|
|
4493
|
+
clearCache() {
|
|
4494
|
+
this.resolvedCardIds = null;
|
|
4495
|
+
}
|
|
4496
|
+
/**
|
|
4497
|
+
* Returns the course ID this source is filtering.
|
|
4498
|
+
*/
|
|
4499
|
+
getCourseId() {
|
|
4500
|
+
return this.courseId;
|
|
4501
|
+
}
|
|
4502
|
+
/**
|
|
4503
|
+
* Returns the active tag filter.
|
|
4504
|
+
*/
|
|
4505
|
+
getFilter() {
|
|
4506
|
+
return this.filter;
|
|
4507
|
+
}
|
|
4508
|
+
};
|
|
4509
|
+
}
|
|
4510
|
+
});
|
|
4511
|
+
|
|
2718
4512
|
// src/core/interfaces/contentSource.ts
|
|
4513
|
+
import { hasActiveFilter as hasActiveFilter2 } from "@vue-skuilder/common";
|
|
2719
4514
|
function isReview(item) {
|
|
2720
4515
|
const ret = item.status === "review" || item.status === "failed-review" || "reviewID" in item;
|
|
2721
4516
|
return ret;
|
|
@@ -2724,6 +4519,9 @@ async function getStudySource(source, user) {
|
|
|
2724
4519
|
if (source.type === "classroom") {
|
|
2725
4520
|
return await StudentClassroomDB.factory(source.id, user);
|
|
2726
4521
|
} else {
|
|
4522
|
+
if (hasActiveFilter2(source.tagFilter)) {
|
|
4523
|
+
return new TagFilteredContentSource(source.id, source.tagFilter, user);
|
|
4524
|
+
}
|
|
2727
4525
|
return getDataLayer().getCourseDB(source.id);
|
|
2728
4526
|
}
|
|
2729
4527
|
}
|
|
@@ -2732,6 +4530,7 @@ var init_contentSource = __esm({
|
|
|
2732
4530
|
"use strict";
|
|
2733
4531
|
init_factory();
|
|
2734
4532
|
init_classroomDB2();
|
|
4533
|
+
init_TagFilteredContentSource();
|
|
2735
4534
|
}
|
|
2736
4535
|
});
|
|
2737
4536
|
|
|
@@ -2897,7 +4696,7 @@ var init_cardProcessor = __esm({
|
|
|
2897
4696
|
});
|
|
2898
4697
|
|
|
2899
4698
|
// src/core/bulkImport/types.ts
|
|
2900
|
-
var
|
|
4699
|
+
var init_types3 = __esm({
|
|
2901
4700
|
"src/core/bulkImport/types.ts"() {
|
|
2902
4701
|
"use strict";
|
|
2903
4702
|
}
|
|
@@ -2908,7 +4707,7 @@ var init_bulkImport = __esm({
|
|
|
2908
4707
|
"src/core/bulkImport/index.ts"() {
|
|
2909
4708
|
"use strict";
|
|
2910
4709
|
init_cardProcessor();
|
|
2911
|
-
|
|
4710
|
+
init_types3();
|
|
2912
4711
|
}
|
|
2913
4712
|
});
|
|
2914
4713
|
|
|
@@ -2931,12 +4730,17 @@ export {
|
|
|
2931
4730
|
DocTypePrefixes,
|
|
2932
4731
|
GuestUsername,
|
|
2933
4732
|
Loggable,
|
|
4733
|
+
NavigatorRole,
|
|
4734
|
+
NavigatorRoles,
|
|
2934
4735
|
Navigators,
|
|
2935
4736
|
areQuestionRecords,
|
|
2936
4737
|
docIsDeleted,
|
|
2937
4738
|
getCardHistoryID,
|
|
4739
|
+
getCardOrigin,
|
|
2938
4740
|
getStudySource,
|
|
2939
4741
|
importParsedCards,
|
|
4742
|
+
isFilter,
|
|
4743
|
+
isGenerator,
|
|
2940
4744
|
isQuestionRecord,
|
|
2941
4745
|
isReview,
|
|
2942
4746
|
log,
|