@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
|
@@ -599,23 +599,460 @@ var init_courseLookupDB = __esm({
|
|
|
599
599
|
}
|
|
600
600
|
});
|
|
601
601
|
|
|
602
|
+
// src/core/navigators/CompositeGenerator.ts
|
|
603
|
+
var CompositeGenerator_exports = {};
|
|
604
|
+
__export(CompositeGenerator_exports, {
|
|
605
|
+
AggregationMode: () => AggregationMode,
|
|
606
|
+
default: () => CompositeGenerator
|
|
607
|
+
});
|
|
608
|
+
var AggregationMode, DEFAULT_AGGREGATION_MODE, FREQUENCY_BOOST_FACTOR, CompositeGenerator;
|
|
609
|
+
var init_CompositeGenerator = __esm({
|
|
610
|
+
"src/core/navigators/CompositeGenerator.ts"() {
|
|
611
|
+
"use strict";
|
|
612
|
+
init_navigators();
|
|
613
|
+
init_logger();
|
|
614
|
+
AggregationMode = /* @__PURE__ */ ((AggregationMode2) => {
|
|
615
|
+
AggregationMode2["MAX"] = "max";
|
|
616
|
+
AggregationMode2["AVERAGE"] = "average";
|
|
617
|
+
AggregationMode2["FREQUENCY_BOOST"] = "frequencyBoost";
|
|
618
|
+
return AggregationMode2;
|
|
619
|
+
})(AggregationMode || {});
|
|
620
|
+
DEFAULT_AGGREGATION_MODE = "frequencyBoost" /* FREQUENCY_BOOST */;
|
|
621
|
+
FREQUENCY_BOOST_FACTOR = 0.1;
|
|
622
|
+
CompositeGenerator = class _CompositeGenerator extends ContentNavigator {
|
|
623
|
+
/** Human-readable name for CardGenerator interface */
|
|
624
|
+
name = "Composite Generator";
|
|
625
|
+
generators;
|
|
626
|
+
aggregationMode;
|
|
627
|
+
constructor(generators, aggregationMode = DEFAULT_AGGREGATION_MODE) {
|
|
628
|
+
super();
|
|
629
|
+
this.generators = generators;
|
|
630
|
+
this.aggregationMode = aggregationMode;
|
|
631
|
+
if (generators.length === 0) {
|
|
632
|
+
throw new Error("CompositeGenerator requires at least one generator");
|
|
633
|
+
}
|
|
634
|
+
logger.debug(
|
|
635
|
+
`[CompositeGenerator] Created with ${generators.length} generators, mode: ${aggregationMode}`
|
|
636
|
+
);
|
|
637
|
+
}
|
|
638
|
+
/**
|
|
639
|
+
* Creates a CompositeGenerator from strategy data.
|
|
640
|
+
*
|
|
641
|
+
* This is a convenience factory for use by PipelineAssembler.
|
|
642
|
+
*/
|
|
643
|
+
static async fromStrategies(user, course, strategies, aggregationMode = DEFAULT_AGGREGATION_MODE) {
|
|
644
|
+
const generators = await Promise.all(
|
|
645
|
+
strategies.map((s) => ContentNavigator.create(user, course, s))
|
|
646
|
+
);
|
|
647
|
+
return new _CompositeGenerator(generators, aggregationMode);
|
|
648
|
+
}
|
|
649
|
+
/**
|
|
650
|
+
* Get weighted cards from all generators, merge and deduplicate.
|
|
651
|
+
*
|
|
652
|
+
* Cards appearing in multiple generators receive a score boost.
|
|
653
|
+
* Provenance tracks which generators produced each card and how scores were aggregated.
|
|
654
|
+
*
|
|
655
|
+
* This method supports both the legacy signature (limit only) and the
|
|
656
|
+
* CardGenerator interface signature (limit, context).
|
|
657
|
+
*
|
|
658
|
+
* @param limit - Maximum number of cards to return
|
|
659
|
+
* @param context - Optional GeneratorContext passed to child generators
|
|
660
|
+
*/
|
|
661
|
+
async getWeightedCards(limit, context) {
|
|
662
|
+
const results = await Promise.all(
|
|
663
|
+
this.generators.map((g) => g.getWeightedCards(limit, context))
|
|
664
|
+
);
|
|
665
|
+
const byCardId = /* @__PURE__ */ new Map();
|
|
666
|
+
for (const cards of results) {
|
|
667
|
+
for (const card of cards) {
|
|
668
|
+
const existing = byCardId.get(card.cardId) || [];
|
|
669
|
+
existing.push(card);
|
|
670
|
+
byCardId.set(card.cardId, existing);
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
const merged = [];
|
|
674
|
+
for (const [, cards] of byCardId) {
|
|
675
|
+
const aggregatedScore = this.aggregateScores(cards);
|
|
676
|
+
const finalScore = Math.min(1, aggregatedScore);
|
|
677
|
+
const mergedProvenance = cards.flatMap((c) => c.provenance);
|
|
678
|
+
const initialScore = cards[0].score;
|
|
679
|
+
const action = finalScore > initialScore ? "boosted" : finalScore < initialScore ? "penalized" : "passed";
|
|
680
|
+
const reason = this.buildAggregationReason(cards, finalScore);
|
|
681
|
+
merged.push({
|
|
682
|
+
...cards[0],
|
|
683
|
+
score: finalScore,
|
|
684
|
+
provenance: [
|
|
685
|
+
...mergedProvenance,
|
|
686
|
+
{
|
|
687
|
+
strategy: "composite",
|
|
688
|
+
strategyName: "Composite Generator",
|
|
689
|
+
strategyId: "COMPOSITE_GENERATOR",
|
|
690
|
+
action,
|
|
691
|
+
score: finalScore,
|
|
692
|
+
reason
|
|
693
|
+
}
|
|
694
|
+
]
|
|
695
|
+
});
|
|
696
|
+
}
|
|
697
|
+
return merged.sort((a, b) => b.score - a.score).slice(0, limit);
|
|
698
|
+
}
|
|
699
|
+
/**
|
|
700
|
+
* Build human-readable reason for score aggregation.
|
|
701
|
+
*/
|
|
702
|
+
buildAggregationReason(cards, finalScore) {
|
|
703
|
+
const count = cards.length;
|
|
704
|
+
const scores = cards.map((c) => c.score.toFixed(2)).join(", ");
|
|
705
|
+
if (count === 1) {
|
|
706
|
+
return `Single generator, score ${finalScore.toFixed(2)}`;
|
|
707
|
+
}
|
|
708
|
+
const strategies = cards.map((c) => c.provenance[0]?.strategy || "unknown").join(", ");
|
|
709
|
+
switch (this.aggregationMode) {
|
|
710
|
+
case "max" /* MAX */:
|
|
711
|
+
return `Max of ${count} generators (${strategies}): scores [${scores}] \u2192 ${finalScore.toFixed(2)}`;
|
|
712
|
+
case "average" /* AVERAGE */:
|
|
713
|
+
return `Average of ${count} generators (${strategies}): scores [${scores}] \u2192 ${finalScore.toFixed(2)}`;
|
|
714
|
+
case "frequencyBoost" /* FREQUENCY_BOOST */: {
|
|
715
|
+
const avg = cards.reduce((sum, c) => sum + c.score, 0) / count;
|
|
716
|
+
const boost = 1 + FREQUENCY_BOOST_FACTOR * (count - 1);
|
|
717
|
+
return `Frequency boost from ${count} generators (${strategies}): avg ${avg.toFixed(2)} \xD7 ${boost.toFixed(2)} \u2192 ${finalScore.toFixed(2)}`;
|
|
718
|
+
}
|
|
719
|
+
default:
|
|
720
|
+
return `Aggregated from ${count} generators: ${finalScore.toFixed(2)}`;
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
/**
|
|
724
|
+
* Aggregate scores from multiple generators for the same card.
|
|
725
|
+
*/
|
|
726
|
+
aggregateScores(cards) {
|
|
727
|
+
const scores = cards.map((c) => c.score);
|
|
728
|
+
switch (this.aggregationMode) {
|
|
729
|
+
case "max" /* MAX */:
|
|
730
|
+
return Math.max(...scores);
|
|
731
|
+
case "average" /* AVERAGE */:
|
|
732
|
+
return scores.reduce((sum, s) => sum + s, 0) / scores.length;
|
|
733
|
+
case "frequencyBoost" /* FREQUENCY_BOOST */: {
|
|
734
|
+
const avg = scores.reduce((sum, s) => sum + s, 0) / scores.length;
|
|
735
|
+
const frequencyBoost = 1 + FREQUENCY_BOOST_FACTOR * (cards.length - 1);
|
|
736
|
+
return avg * frequencyBoost;
|
|
737
|
+
}
|
|
738
|
+
default:
|
|
739
|
+
return scores[0];
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
/**
|
|
743
|
+
* Get new cards from all generators, merged and deduplicated.
|
|
744
|
+
*/
|
|
745
|
+
async getNewCards(n) {
|
|
746
|
+
const legacyGenerators = this.generators.filter(
|
|
747
|
+
(g) => g instanceof ContentNavigator
|
|
748
|
+
);
|
|
749
|
+
const results = await Promise.all(legacyGenerators.map((g) => g.getNewCards(n)));
|
|
750
|
+
const seen = /* @__PURE__ */ new Set();
|
|
751
|
+
const merged = [];
|
|
752
|
+
for (const cards of results) {
|
|
753
|
+
for (const card of cards) {
|
|
754
|
+
if (!seen.has(card.cardID)) {
|
|
755
|
+
seen.add(card.cardID);
|
|
756
|
+
merged.push(card);
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
return n ? merged.slice(0, n) : merged;
|
|
761
|
+
}
|
|
762
|
+
/**
|
|
763
|
+
* Get pending reviews from all generators, merged and deduplicated.
|
|
764
|
+
*/
|
|
765
|
+
async getPendingReviews() {
|
|
766
|
+
const legacyGenerators = this.generators.filter(
|
|
767
|
+
(g) => g instanceof ContentNavigator
|
|
768
|
+
);
|
|
769
|
+
const results = await Promise.all(legacyGenerators.map((g) => g.getPendingReviews()));
|
|
770
|
+
const seen = /* @__PURE__ */ new Set();
|
|
771
|
+
const merged = [];
|
|
772
|
+
for (const reviews of results) {
|
|
773
|
+
for (const review of reviews) {
|
|
774
|
+
if (!seen.has(review.cardID)) {
|
|
775
|
+
seen.add(review.cardID);
|
|
776
|
+
merged.push(review);
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
return merged;
|
|
781
|
+
}
|
|
782
|
+
};
|
|
783
|
+
}
|
|
784
|
+
});
|
|
785
|
+
|
|
786
|
+
// src/core/navigators/Pipeline.ts
|
|
787
|
+
var Pipeline_exports = {};
|
|
788
|
+
__export(Pipeline_exports, {
|
|
789
|
+
Pipeline: () => Pipeline
|
|
790
|
+
});
|
|
791
|
+
import { toCourseElo as toCourseElo2 } from "@vue-skuilder/common";
|
|
792
|
+
var Pipeline;
|
|
793
|
+
var init_Pipeline = __esm({
|
|
794
|
+
"src/core/navigators/Pipeline.ts"() {
|
|
795
|
+
"use strict";
|
|
796
|
+
init_navigators();
|
|
797
|
+
init_logger();
|
|
798
|
+
Pipeline = class extends ContentNavigator {
|
|
799
|
+
generator;
|
|
800
|
+
filters;
|
|
801
|
+
/**
|
|
802
|
+
* Create a new pipeline.
|
|
803
|
+
*
|
|
804
|
+
* @param generator - The generator (or CompositeGenerator) that produces candidates
|
|
805
|
+
* @param filters - Filters to apply sequentially (order doesn't matter for multipliers)
|
|
806
|
+
* @param user - User database interface
|
|
807
|
+
* @param course - Course database interface
|
|
808
|
+
*/
|
|
809
|
+
constructor(generator, filters, user, course) {
|
|
810
|
+
super();
|
|
811
|
+
this.generator = generator;
|
|
812
|
+
this.filters = filters;
|
|
813
|
+
this.user = user;
|
|
814
|
+
this.course = course;
|
|
815
|
+
logger.debug(
|
|
816
|
+
`[Pipeline] Created with generator '${generator.name}' and ${filters.length} filters: ${filters.map((f) => f.name).join(", ")}`
|
|
817
|
+
);
|
|
818
|
+
}
|
|
819
|
+
/**
|
|
820
|
+
* Get weighted cards by running generator and applying filters.
|
|
821
|
+
*
|
|
822
|
+
* 1. Build shared context (user ELO, etc.)
|
|
823
|
+
* 2. Get candidates from generator (passing context)
|
|
824
|
+
* 3. Apply each filter sequentially
|
|
825
|
+
* 4. Remove zero-score cards
|
|
826
|
+
* 5. Sort by score descending
|
|
827
|
+
* 6. Return top N
|
|
828
|
+
*
|
|
829
|
+
* @param limit - Maximum number of cards to return
|
|
830
|
+
* @returns Cards sorted by score descending
|
|
831
|
+
*/
|
|
832
|
+
async getWeightedCards(limit) {
|
|
833
|
+
const context = await this.buildContext();
|
|
834
|
+
const overFetchMultiplier = 2 + this.filters.length * 0.5;
|
|
835
|
+
const fetchLimit = Math.ceil(limit * overFetchMultiplier);
|
|
836
|
+
logger.debug(
|
|
837
|
+
`[Pipeline] Fetching ${fetchLimit} candidates from generator '${this.generator.name}'`
|
|
838
|
+
);
|
|
839
|
+
let cards = await this.generator.getWeightedCards(fetchLimit, context);
|
|
840
|
+
logger.debug(`[Pipeline] Generator returned ${cards.length} candidates`);
|
|
841
|
+
for (const filter of this.filters) {
|
|
842
|
+
const beforeCount = cards.length;
|
|
843
|
+
cards = await filter.transform(cards, context);
|
|
844
|
+
logger.debug(`[Pipeline] Filter '${filter.name}': ${beforeCount} \u2192 ${cards.length} cards`);
|
|
845
|
+
}
|
|
846
|
+
cards = cards.filter((c) => c.score > 0);
|
|
847
|
+
cards.sort((a, b) => b.score - a.score);
|
|
848
|
+
const result = cards.slice(0, limit);
|
|
849
|
+
logger.debug(
|
|
850
|
+
`[Pipeline] Returning ${result.length} cards (top scores: ${result.slice(0, 3).map((c) => c.score.toFixed(2)).join(", ")}...)`
|
|
851
|
+
);
|
|
852
|
+
return result;
|
|
853
|
+
}
|
|
854
|
+
/**
|
|
855
|
+
* Build shared context for generator and filters.
|
|
856
|
+
*
|
|
857
|
+
* Called once per getWeightedCards() invocation.
|
|
858
|
+
* Contains data that the generator and multiple filters might need.
|
|
859
|
+
*
|
|
860
|
+
* The context satisfies both GeneratorContext and FilterContext interfaces.
|
|
861
|
+
*/
|
|
862
|
+
async buildContext() {
|
|
863
|
+
let userElo = 1e3;
|
|
864
|
+
try {
|
|
865
|
+
const courseReg = await this.user.getCourseRegDoc(this.course.getCourseID());
|
|
866
|
+
const courseElo = toCourseElo2(courseReg.elo);
|
|
867
|
+
userElo = courseElo.global.score;
|
|
868
|
+
} catch (e) {
|
|
869
|
+
logger.debug(`[Pipeline] Could not get user ELO, using default: ${e}`);
|
|
870
|
+
}
|
|
871
|
+
return {
|
|
872
|
+
user: this.user,
|
|
873
|
+
course: this.course,
|
|
874
|
+
userElo
|
|
875
|
+
};
|
|
876
|
+
}
|
|
877
|
+
// ===========================================================================
|
|
878
|
+
// Legacy StudyContentSource methods
|
|
879
|
+
// ===========================================================================
|
|
880
|
+
//
|
|
881
|
+
// These delegate to the generator for backward compatibility.
|
|
882
|
+
// Eventually SessionController will use getWeightedCards() exclusively.
|
|
883
|
+
//
|
|
884
|
+
/**
|
|
885
|
+
* Get new cards via legacy API.
|
|
886
|
+
* Delegates to the generator if it supports the legacy interface.
|
|
887
|
+
*/
|
|
888
|
+
async getNewCards(n) {
|
|
889
|
+
if ("getNewCards" in this.generator && typeof this.generator.getNewCards === "function") {
|
|
890
|
+
return this.generator.getNewCards(n);
|
|
891
|
+
}
|
|
892
|
+
return [];
|
|
893
|
+
}
|
|
894
|
+
/**
|
|
895
|
+
* Get pending reviews via legacy API.
|
|
896
|
+
* Delegates to the generator if it supports the legacy interface.
|
|
897
|
+
*/
|
|
898
|
+
async getPendingReviews() {
|
|
899
|
+
if ("getPendingReviews" in this.generator && typeof this.generator.getPendingReviews === "function") {
|
|
900
|
+
return this.generator.getPendingReviews();
|
|
901
|
+
}
|
|
902
|
+
return [];
|
|
903
|
+
}
|
|
904
|
+
/**
|
|
905
|
+
* Get the course ID for this pipeline.
|
|
906
|
+
*/
|
|
907
|
+
getCourseID() {
|
|
908
|
+
return this.course.getCourseID();
|
|
909
|
+
}
|
|
910
|
+
};
|
|
911
|
+
}
|
|
912
|
+
});
|
|
913
|
+
|
|
914
|
+
// src/core/navigators/PipelineAssembler.ts
|
|
915
|
+
var PipelineAssembler_exports = {};
|
|
916
|
+
__export(PipelineAssembler_exports, {
|
|
917
|
+
PipelineAssembler: () => PipelineAssembler
|
|
918
|
+
});
|
|
919
|
+
var PipelineAssembler;
|
|
920
|
+
var init_PipelineAssembler = __esm({
|
|
921
|
+
"src/core/navigators/PipelineAssembler.ts"() {
|
|
922
|
+
"use strict";
|
|
923
|
+
init_navigators();
|
|
924
|
+
init_Pipeline();
|
|
925
|
+
init_types_legacy();
|
|
926
|
+
init_logger();
|
|
927
|
+
init_CompositeGenerator();
|
|
928
|
+
PipelineAssembler = class {
|
|
929
|
+
/**
|
|
930
|
+
* Assembles a navigation pipeline from strategy documents.
|
|
931
|
+
*
|
|
932
|
+
* 1. Separates into generators and filters by role
|
|
933
|
+
* 2. Validates at least one generator exists (or creates default ELO)
|
|
934
|
+
* 3. Instantiates generators - wraps multiple in CompositeGenerator
|
|
935
|
+
* 4. Instantiates filters
|
|
936
|
+
* 5. Returns Pipeline(generator, filters)
|
|
937
|
+
*
|
|
938
|
+
* @param input - Strategy documents plus user/course interfaces
|
|
939
|
+
* @returns Assembled pipeline and any warnings
|
|
940
|
+
*/
|
|
941
|
+
async assemble(input) {
|
|
942
|
+
const { strategies, user, course } = input;
|
|
943
|
+
const warnings = [];
|
|
944
|
+
if (strategies.length === 0) {
|
|
945
|
+
return {
|
|
946
|
+
pipeline: null,
|
|
947
|
+
generatorStrategies: [],
|
|
948
|
+
filterStrategies: [],
|
|
949
|
+
warnings
|
|
950
|
+
};
|
|
951
|
+
}
|
|
952
|
+
const generatorStrategies = [];
|
|
953
|
+
const filterStrategies = [];
|
|
954
|
+
for (const s of strategies) {
|
|
955
|
+
if (isGenerator(s.implementingClass)) {
|
|
956
|
+
generatorStrategies.push(s);
|
|
957
|
+
} else if (isFilter(s.implementingClass)) {
|
|
958
|
+
filterStrategies.push(s);
|
|
959
|
+
} else {
|
|
960
|
+
warnings.push(`Unknown strategy type '${s.implementingClass}', skipping: ${s.name}`);
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
if (generatorStrategies.length === 0) {
|
|
964
|
+
if (filterStrategies.length > 0) {
|
|
965
|
+
logger.debug(
|
|
966
|
+
"[PipelineAssembler] No generator found, using default ELO with configured filters"
|
|
967
|
+
);
|
|
968
|
+
generatorStrategies.push(this.makeDefaultEloStrategy(course.getCourseID()));
|
|
969
|
+
} else {
|
|
970
|
+
warnings.push("No generator strategy found");
|
|
971
|
+
return {
|
|
972
|
+
pipeline: null,
|
|
973
|
+
generatorStrategies: [],
|
|
974
|
+
filterStrategies: [],
|
|
975
|
+
warnings
|
|
976
|
+
};
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
let generator;
|
|
980
|
+
if (generatorStrategies.length === 1) {
|
|
981
|
+
const nav = await ContentNavigator.create(user, course, generatorStrategies[0]);
|
|
982
|
+
generator = nav;
|
|
983
|
+
logger.debug(`[PipelineAssembler] Using single generator: ${generatorStrategies[0].name}`);
|
|
984
|
+
} else {
|
|
985
|
+
logger.debug(
|
|
986
|
+
`[PipelineAssembler] Using CompositeGenerator for ${generatorStrategies.length} generators: ${generatorStrategies.map((g) => g.name).join(", ")}`
|
|
987
|
+
);
|
|
988
|
+
generator = await CompositeGenerator.fromStrategies(user, course, generatorStrategies);
|
|
989
|
+
}
|
|
990
|
+
const filters = [];
|
|
991
|
+
const sortedFilterStrategies = [...filterStrategies].sort(
|
|
992
|
+
(a, b) => a.name.localeCompare(b.name)
|
|
993
|
+
);
|
|
994
|
+
for (const filterStrategy of sortedFilterStrategies) {
|
|
995
|
+
try {
|
|
996
|
+
const nav = await ContentNavigator.create(user, course, filterStrategy);
|
|
997
|
+
if ("transform" in nav && typeof nav.transform === "function") {
|
|
998
|
+
filters.push(nav);
|
|
999
|
+
logger.debug(`[PipelineAssembler] Added filter: ${filterStrategy.name}`);
|
|
1000
|
+
} else {
|
|
1001
|
+
warnings.push(
|
|
1002
|
+
`Filter '${filterStrategy.name}' does not implement CardFilter.transform(), skipping`
|
|
1003
|
+
);
|
|
1004
|
+
}
|
|
1005
|
+
} catch (e) {
|
|
1006
|
+
warnings.push(`Failed to instantiate filter '${filterStrategy.name}': ${e}`);
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
const pipeline = new Pipeline(generator, filters, user, course);
|
|
1010
|
+
logger.debug(
|
|
1011
|
+
`[PipelineAssembler] Assembled pipeline with ${generatorStrategies.length} generator(s) and ${filters.length} filter(s)`
|
|
1012
|
+
);
|
|
1013
|
+
return {
|
|
1014
|
+
pipeline,
|
|
1015
|
+
generatorStrategies,
|
|
1016
|
+
filterStrategies: sortedFilterStrategies,
|
|
1017
|
+
warnings
|
|
1018
|
+
};
|
|
1019
|
+
}
|
|
1020
|
+
/**
|
|
1021
|
+
* Creates a default ELO generator strategy.
|
|
1022
|
+
* Used when filters are configured but no generator is specified.
|
|
1023
|
+
*/
|
|
1024
|
+
makeDefaultEloStrategy(courseId) {
|
|
1025
|
+
return {
|
|
1026
|
+
_id: "NAVIGATION_STRATEGY-ELO-default",
|
|
1027
|
+
course: courseId,
|
|
1028
|
+
docType: "NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */,
|
|
1029
|
+
name: "ELO (default)",
|
|
1030
|
+
description: "Default ELO-based generator",
|
|
1031
|
+
implementingClass: "elo" /* ELO */,
|
|
1032
|
+
serializedData: ""
|
|
1033
|
+
};
|
|
1034
|
+
}
|
|
1035
|
+
};
|
|
1036
|
+
}
|
|
1037
|
+
});
|
|
1038
|
+
|
|
602
1039
|
// src/core/navigators/elo.ts
|
|
603
1040
|
var elo_exports = {};
|
|
604
1041
|
__export(elo_exports, {
|
|
605
1042
|
default: () => ELONavigator
|
|
606
1043
|
});
|
|
1044
|
+
import { toCourseElo as toCourseElo3 } from "@vue-skuilder/common";
|
|
607
1045
|
var ELONavigator;
|
|
608
1046
|
var init_elo = __esm({
|
|
609
1047
|
"src/core/navigators/elo.ts"() {
|
|
610
1048
|
"use strict";
|
|
611
1049
|
init_navigators();
|
|
612
1050
|
ELONavigator = class extends ContentNavigator {
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
constructor(user, course) {
|
|
616
|
-
super();
|
|
617
|
-
this.
|
|
618
|
-
this.course = course;
|
|
1051
|
+
/** Human-readable name for CardGenerator interface */
|
|
1052
|
+
name;
|
|
1053
|
+
constructor(user, course, strategyData) {
|
|
1054
|
+
super(user, course, strategyData);
|
|
1055
|
+
this.name = strategyData?.name || "ELO";
|
|
619
1056
|
}
|
|
620
1057
|
async getPendingReviews() {
|
|
621
1058
|
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
@@ -643,84 +1080,983 @@ var init_elo = __esm({
|
|
|
643
1080
|
};
|
|
644
1081
|
});
|
|
645
1082
|
}
|
|
646
|
-
async getNewCards(limit = 99) {
|
|
647
|
-
const activeCards = await this.user.getActiveCards();
|
|
648
|
-
return (await this.course.getCardsCenteredAtELO(
|
|
649
|
-
{ limit, elo: "user" },
|
|
650
|
-
(c) => {
|
|
651
|
-
if (activeCards.some((ac) => c.cardID === ac.cardID)) {
|
|
652
|
-
return false;
|
|
653
|
-
} else {
|
|
654
|
-
return true;
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
)).map((c) => {
|
|
658
|
-
return {
|
|
659
|
-
...c,
|
|
660
|
-
status: "new"
|
|
661
|
-
};
|
|
662
|
-
});
|
|
1083
|
+
async getNewCards(limit = 99) {
|
|
1084
|
+
const activeCards = await this.user.getActiveCards();
|
|
1085
|
+
return (await this.course.getCardsCenteredAtELO(
|
|
1086
|
+
{ limit, elo: "user" },
|
|
1087
|
+
(c) => {
|
|
1088
|
+
if (activeCards.some((ac) => c.cardID === ac.cardID)) {
|
|
1089
|
+
return false;
|
|
1090
|
+
} else {
|
|
1091
|
+
return true;
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
)).map((c) => {
|
|
1095
|
+
return {
|
|
1096
|
+
...c,
|
|
1097
|
+
status: "new"
|
|
1098
|
+
};
|
|
1099
|
+
});
|
|
1100
|
+
}
|
|
1101
|
+
/**
|
|
1102
|
+
* Get new cards with suitability scores based on ELO distance.
|
|
1103
|
+
*
|
|
1104
|
+
* Cards closer to user's ELO get higher scores.
|
|
1105
|
+
* Score formula: max(0, 1 - distance / 500)
|
|
1106
|
+
*
|
|
1107
|
+
* NOTE: This generator only handles NEW cards. Reviews are handled by
|
|
1108
|
+
* SRSNavigator. Use CompositeGenerator to combine both.
|
|
1109
|
+
*
|
|
1110
|
+
* This method supports both the legacy signature (limit only) and the
|
|
1111
|
+
* CardGenerator interface signature (limit, context).
|
|
1112
|
+
*
|
|
1113
|
+
* @param limit - Maximum number of cards to return
|
|
1114
|
+
* @param context - Optional GeneratorContext (used when called via Pipeline)
|
|
1115
|
+
*/
|
|
1116
|
+
async getWeightedCards(limit, context) {
|
|
1117
|
+
let userGlobalElo;
|
|
1118
|
+
if (context?.userElo !== void 0) {
|
|
1119
|
+
userGlobalElo = context.userElo;
|
|
1120
|
+
} else {
|
|
1121
|
+
const courseReg = await this.user.getCourseRegDoc(this.course.getCourseID());
|
|
1122
|
+
const userElo = toCourseElo3(courseReg.elo);
|
|
1123
|
+
userGlobalElo = userElo.global.score;
|
|
1124
|
+
}
|
|
1125
|
+
const newCards = await this.getNewCards(limit);
|
|
1126
|
+
const cardIds = newCards.map((c) => c.cardID);
|
|
1127
|
+
const cardEloData = await this.course.getCardEloData(cardIds);
|
|
1128
|
+
const scored = newCards.map((c, i) => {
|
|
1129
|
+
const cardElo = cardEloData[i]?.global?.score ?? 1e3;
|
|
1130
|
+
const distance = Math.abs(cardElo - userGlobalElo);
|
|
1131
|
+
const score = Math.max(0, 1 - distance / 500);
|
|
1132
|
+
return {
|
|
1133
|
+
cardId: c.cardID,
|
|
1134
|
+
courseId: c.courseID,
|
|
1135
|
+
score,
|
|
1136
|
+
provenance: [
|
|
1137
|
+
{
|
|
1138
|
+
strategy: "elo",
|
|
1139
|
+
strategyName: this.strategyName || this.name,
|
|
1140
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-ELO-default",
|
|
1141
|
+
action: "generated",
|
|
1142
|
+
score,
|
|
1143
|
+
reason: `ELO distance ${Math.round(distance)} (card: ${Math.round(cardElo)}, user: ${Math.round(userGlobalElo)}), new card`
|
|
1144
|
+
}
|
|
1145
|
+
]
|
|
1146
|
+
};
|
|
1147
|
+
});
|
|
1148
|
+
scored.sort((a, b) => b.score - a.score);
|
|
1149
|
+
return scored.slice(0, limit);
|
|
1150
|
+
}
|
|
1151
|
+
};
|
|
1152
|
+
}
|
|
1153
|
+
});
|
|
1154
|
+
|
|
1155
|
+
// src/core/navigators/filters/eloDistance.ts
|
|
1156
|
+
var eloDistance_exports = {};
|
|
1157
|
+
__export(eloDistance_exports, {
|
|
1158
|
+
DEFAULT_HALF_LIFE: () => DEFAULT_HALF_LIFE,
|
|
1159
|
+
DEFAULT_MAX_MULTIPLIER: () => DEFAULT_MAX_MULTIPLIER,
|
|
1160
|
+
DEFAULT_MIN_MULTIPLIER: () => DEFAULT_MIN_MULTIPLIER,
|
|
1161
|
+
createEloDistanceFilter: () => createEloDistanceFilter
|
|
1162
|
+
});
|
|
1163
|
+
function computeMultiplier(distance, halfLife, minMultiplier, maxMultiplier) {
|
|
1164
|
+
const normalizedDistance = distance / halfLife;
|
|
1165
|
+
const decay = Math.exp(-(normalizedDistance * normalizedDistance));
|
|
1166
|
+
return minMultiplier + (maxMultiplier - minMultiplier) * decay;
|
|
1167
|
+
}
|
|
1168
|
+
function createEloDistanceFilter(config) {
|
|
1169
|
+
const halfLife = config?.halfLife ?? DEFAULT_HALF_LIFE;
|
|
1170
|
+
const minMultiplier = config?.minMultiplier ?? DEFAULT_MIN_MULTIPLIER;
|
|
1171
|
+
const maxMultiplier = config?.maxMultiplier ?? DEFAULT_MAX_MULTIPLIER;
|
|
1172
|
+
return {
|
|
1173
|
+
name: "ELO Distance Filter",
|
|
1174
|
+
async transform(cards, context) {
|
|
1175
|
+
const { course, userElo } = context;
|
|
1176
|
+
const cardIds = cards.map((c) => c.cardId);
|
|
1177
|
+
const cardElos = await course.getCardEloData(cardIds);
|
|
1178
|
+
return cards.map((card, i) => {
|
|
1179
|
+
const cardElo = cardElos[i]?.global?.score ?? 1e3;
|
|
1180
|
+
const distance = Math.abs(cardElo - userElo);
|
|
1181
|
+
const multiplier = computeMultiplier(distance, halfLife, minMultiplier, maxMultiplier);
|
|
1182
|
+
const newScore = card.score * multiplier;
|
|
1183
|
+
const action = multiplier < maxMultiplier - 0.01 ? "penalized" : "passed";
|
|
1184
|
+
return {
|
|
1185
|
+
...card,
|
|
1186
|
+
score: newScore,
|
|
1187
|
+
provenance: [
|
|
1188
|
+
...card.provenance,
|
|
1189
|
+
{
|
|
1190
|
+
strategy: "eloDistance",
|
|
1191
|
+
strategyName: "ELO Distance Filter",
|
|
1192
|
+
strategyId: "ELO_DISTANCE_FILTER",
|
|
1193
|
+
action,
|
|
1194
|
+
score: newScore,
|
|
1195
|
+
reason: `ELO distance ${Math.round(distance)} (card: ${Math.round(cardElo)}, user: ${Math.round(userElo)}) \u2192 ${multiplier.toFixed(2)}x`
|
|
1196
|
+
}
|
|
1197
|
+
]
|
|
1198
|
+
};
|
|
1199
|
+
});
|
|
1200
|
+
}
|
|
1201
|
+
};
|
|
1202
|
+
}
|
|
1203
|
+
var DEFAULT_HALF_LIFE, DEFAULT_MIN_MULTIPLIER, DEFAULT_MAX_MULTIPLIER;
|
|
1204
|
+
var init_eloDistance = __esm({
|
|
1205
|
+
"src/core/navigators/filters/eloDistance.ts"() {
|
|
1206
|
+
"use strict";
|
|
1207
|
+
DEFAULT_HALF_LIFE = 200;
|
|
1208
|
+
DEFAULT_MIN_MULTIPLIER = 0.3;
|
|
1209
|
+
DEFAULT_MAX_MULTIPLIER = 1;
|
|
1210
|
+
}
|
|
1211
|
+
});
|
|
1212
|
+
|
|
1213
|
+
// src/core/navigators/filters/index.ts
|
|
1214
|
+
var filters_exports = {};
|
|
1215
|
+
__export(filters_exports, {
|
|
1216
|
+
createEloDistanceFilter: () => createEloDistanceFilter
|
|
1217
|
+
});
|
|
1218
|
+
var init_filters = __esm({
|
|
1219
|
+
"src/core/navigators/filters/index.ts"() {
|
|
1220
|
+
"use strict";
|
|
1221
|
+
init_eloDistance();
|
|
1222
|
+
}
|
|
1223
|
+
});
|
|
1224
|
+
|
|
1225
|
+
// src/core/navigators/filters/types.ts
|
|
1226
|
+
var types_exports = {};
|
|
1227
|
+
var init_types = __esm({
|
|
1228
|
+
"src/core/navigators/filters/types.ts"() {
|
|
1229
|
+
"use strict";
|
|
1230
|
+
}
|
|
1231
|
+
});
|
|
1232
|
+
|
|
1233
|
+
// src/core/navigators/generators/index.ts
|
|
1234
|
+
var generators_exports = {};
|
|
1235
|
+
var init_generators = __esm({
|
|
1236
|
+
"src/core/navigators/generators/index.ts"() {
|
|
1237
|
+
"use strict";
|
|
1238
|
+
}
|
|
1239
|
+
});
|
|
1240
|
+
|
|
1241
|
+
// src/core/navigators/generators/types.ts
|
|
1242
|
+
var types_exports2 = {};
|
|
1243
|
+
var init_types2 = __esm({
|
|
1244
|
+
"src/core/navigators/generators/types.ts"() {
|
|
1245
|
+
"use strict";
|
|
1246
|
+
}
|
|
1247
|
+
});
|
|
1248
|
+
|
|
1249
|
+
// src/core/navigators/hardcodedOrder.ts
|
|
1250
|
+
var hardcodedOrder_exports = {};
|
|
1251
|
+
__export(hardcodedOrder_exports, {
|
|
1252
|
+
default: () => HardcodedOrderNavigator
|
|
1253
|
+
});
|
|
1254
|
+
var HardcodedOrderNavigator;
|
|
1255
|
+
var init_hardcodedOrder = __esm({
|
|
1256
|
+
"src/core/navigators/hardcodedOrder.ts"() {
|
|
1257
|
+
"use strict";
|
|
1258
|
+
init_navigators();
|
|
1259
|
+
init_logger();
|
|
1260
|
+
HardcodedOrderNavigator = class extends ContentNavigator {
|
|
1261
|
+
/** Human-readable name for CardGenerator interface */
|
|
1262
|
+
name;
|
|
1263
|
+
orderedCardIds = [];
|
|
1264
|
+
constructor(user, course, strategyData) {
|
|
1265
|
+
super(user, course, strategyData);
|
|
1266
|
+
this.name = strategyData.name || "Hardcoded Order";
|
|
1267
|
+
if (strategyData.serializedData) {
|
|
1268
|
+
try {
|
|
1269
|
+
this.orderedCardIds = JSON.parse(strategyData.serializedData);
|
|
1270
|
+
} catch (e) {
|
|
1271
|
+
logger.error("Failed to parse serializedData for HardcodedOrderNavigator", e);
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
async getPendingReviews() {
|
|
1276
|
+
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
1277
|
+
return reviews.map((r) => {
|
|
1278
|
+
return {
|
|
1279
|
+
...r,
|
|
1280
|
+
contentSourceType: "course",
|
|
1281
|
+
contentSourceID: this.course.getCourseID(),
|
|
1282
|
+
cardID: r.cardId,
|
|
1283
|
+
courseID: r.courseId,
|
|
1284
|
+
reviewID: r._id,
|
|
1285
|
+
status: "review"
|
|
1286
|
+
};
|
|
1287
|
+
});
|
|
1288
|
+
}
|
|
1289
|
+
async getNewCards(limit = 99) {
|
|
1290
|
+
const activeCardIds = (await this.user.getActiveCards()).map((c) => c.cardID);
|
|
1291
|
+
const newCardIds = this.orderedCardIds.filter((cardId) => !activeCardIds.includes(cardId));
|
|
1292
|
+
const cardsToReturn = newCardIds.slice(0, limit);
|
|
1293
|
+
return cardsToReturn.map((cardId) => {
|
|
1294
|
+
return {
|
|
1295
|
+
cardID: cardId,
|
|
1296
|
+
courseID: this.course.getCourseID(),
|
|
1297
|
+
contentSourceType: "course",
|
|
1298
|
+
contentSourceID: this.course.getCourseID(),
|
|
1299
|
+
status: "new"
|
|
1300
|
+
};
|
|
1301
|
+
});
|
|
1302
|
+
}
|
|
1303
|
+
/**
|
|
1304
|
+
* Get cards in hardcoded order with scores based on position.
|
|
1305
|
+
*
|
|
1306
|
+
* Earlier cards in the sequence get higher scores.
|
|
1307
|
+
* Score formula: 1.0 - (position / totalCards) * 0.5
|
|
1308
|
+
* This ensures scores range from 1.0 (first card) to 0.5+ (last card).
|
|
1309
|
+
*
|
|
1310
|
+
* This method supports both the legacy signature (limit only) and the
|
|
1311
|
+
* CardGenerator interface signature (limit, context).
|
|
1312
|
+
*
|
|
1313
|
+
* @param limit - Maximum number of cards to return
|
|
1314
|
+
* @param _context - Optional GeneratorContext (currently unused, but required for interface)
|
|
1315
|
+
*/
|
|
1316
|
+
async getWeightedCards(limit, _context) {
|
|
1317
|
+
const activeCardIds = (await this.user.getActiveCards()).map((c) => c.cardID);
|
|
1318
|
+
const reviews = await this.getPendingReviews();
|
|
1319
|
+
const newCardIds = this.orderedCardIds.filter((cardId) => !activeCardIds.includes(cardId));
|
|
1320
|
+
const totalCards = newCardIds.length;
|
|
1321
|
+
const scoredNew = newCardIds.slice(0, limit).map((cardId, index) => {
|
|
1322
|
+
const position = index + 1;
|
|
1323
|
+
const score = Math.max(0.5, 1 - index / totalCards * 0.5);
|
|
1324
|
+
return {
|
|
1325
|
+
cardId,
|
|
1326
|
+
courseId: this.course.getCourseID(),
|
|
1327
|
+
score,
|
|
1328
|
+
provenance: [
|
|
1329
|
+
{
|
|
1330
|
+
strategy: "hardcodedOrder",
|
|
1331
|
+
strategyName: this.strategyName || this.name,
|
|
1332
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-hardcoded",
|
|
1333
|
+
action: "generated",
|
|
1334
|
+
score,
|
|
1335
|
+
reason: `Position ${position} of ${totalCards} in fixed sequence, new card`
|
|
1336
|
+
}
|
|
1337
|
+
]
|
|
1338
|
+
};
|
|
1339
|
+
});
|
|
1340
|
+
const scoredReviews = reviews.map((r) => ({
|
|
1341
|
+
cardId: r.cardID,
|
|
1342
|
+
courseId: r.courseID,
|
|
1343
|
+
score: 1,
|
|
1344
|
+
provenance: [
|
|
1345
|
+
{
|
|
1346
|
+
strategy: "hardcodedOrder",
|
|
1347
|
+
strategyName: this.strategyName || this.name,
|
|
1348
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-hardcoded",
|
|
1349
|
+
action: "generated",
|
|
1350
|
+
score: 1,
|
|
1351
|
+
reason: "Scheduled review, highest priority"
|
|
1352
|
+
}
|
|
1353
|
+
]
|
|
1354
|
+
}));
|
|
1355
|
+
const all = [...scoredReviews, ...scoredNew];
|
|
1356
|
+
all.sort((a, b) => b.score - a.score);
|
|
1357
|
+
return all.slice(0, limit);
|
|
1358
|
+
}
|
|
1359
|
+
};
|
|
1360
|
+
}
|
|
1361
|
+
});
|
|
1362
|
+
|
|
1363
|
+
// src/core/navigators/hierarchyDefinition.ts
|
|
1364
|
+
var hierarchyDefinition_exports = {};
|
|
1365
|
+
__export(hierarchyDefinition_exports, {
|
|
1366
|
+
default: () => HierarchyDefinitionNavigator
|
|
1367
|
+
});
|
|
1368
|
+
import { toCourseElo as toCourseElo4 } from "@vue-skuilder/common";
|
|
1369
|
+
var DEFAULT_MIN_COUNT, HierarchyDefinitionNavigator;
|
|
1370
|
+
var init_hierarchyDefinition = __esm({
|
|
1371
|
+
"src/core/navigators/hierarchyDefinition.ts"() {
|
|
1372
|
+
"use strict";
|
|
1373
|
+
init_navigators();
|
|
1374
|
+
DEFAULT_MIN_COUNT = 3;
|
|
1375
|
+
HierarchyDefinitionNavigator = class extends ContentNavigator {
|
|
1376
|
+
config;
|
|
1377
|
+
_strategyData;
|
|
1378
|
+
/** Human-readable name for CardFilter interface */
|
|
1379
|
+
name;
|
|
1380
|
+
constructor(user, course, _strategyData) {
|
|
1381
|
+
super(user, course, _strategyData);
|
|
1382
|
+
this._strategyData = _strategyData;
|
|
1383
|
+
this.config = this.parseConfig(_strategyData.serializedData);
|
|
1384
|
+
this.name = _strategyData.name || "Hierarchy Definition";
|
|
1385
|
+
}
|
|
1386
|
+
parseConfig(serializedData) {
|
|
1387
|
+
try {
|
|
1388
|
+
const parsed = JSON.parse(serializedData);
|
|
1389
|
+
return {
|
|
1390
|
+
prerequisites: parsed.prerequisites || {}
|
|
1391
|
+
};
|
|
1392
|
+
} catch {
|
|
1393
|
+
return {
|
|
1394
|
+
prerequisites: {}
|
|
1395
|
+
};
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
/**
|
|
1399
|
+
* Check if a specific prerequisite is satisfied
|
|
1400
|
+
*/
|
|
1401
|
+
isPrerequisiteMet(prereq, userTagElo, userGlobalElo) {
|
|
1402
|
+
if (!userTagElo) return false;
|
|
1403
|
+
const minCount = prereq.masteryThreshold?.minCount ?? DEFAULT_MIN_COUNT;
|
|
1404
|
+
if (userTagElo.count < minCount) return false;
|
|
1405
|
+
if (prereq.masteryThreshold?.minElo !== void 0) {
|
|
1406
|
+
return userTagElo.score >= prereq.masteryThreshold.minElo;
|
|
1407
|
+
} else {
|
|
1408
|
+
return userTagElo.score >= userGlobalElo;
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
/**
|
|
1412
|
+
* Get the set of tags the user has mastered.
|
|
1413
|
+
* A tag is "mastered" if it appears as a prerequisite somewhere and meets its threshold.
|
|
1414
|
+
*/
|
|
1415
|
+
async getMasteredTags(context) {
|
|
1416
|
+
const mastered = /* @__PURE__ */ new Set();
|
|
1417
|
+
try {
|
|
1418
|
+
const courseReg = await context.user.getCourseRegDoc(context.course.getCourseID());
|
|
1419
|
+
const userElo = toCourseElo4(courseReg.elo);
|
|
1420
|
+
for (const prereqs of Object.values(this.config.prerequisites)) {
|
|
1421
|
+
for (const prereq of prereqs) {
|
|
1422
|
+
const tagElo = userElo.tags[prereq.tag];
|
|
1423
|
+
if (this.isPrerequisiteMet(prereq, tagElo, userElo.global.score)) {
|
|
1424
|
+
mastered.add(prereq.tag);
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1428
|
+
} catch {
|
|
1429
|
+
}
|
|
1430
|
+
return mastered;
|
|
1431
|
+
}
|
|
1432
|
+
/**
|
|
1433
|
+
* Get the set of tags that are unlocked (prerequisites met)
|
|
1434
|
+
*/
|
|
1435
|
+
getUnlockedTags(masteredTags) {
|
|
1436
|
+
const unlocked = /* @__PURE__ */ new Set();
|
|
1437
|
+
for (const [tagId, prereqs] of Object.entries(this.config.prerequisites)) {
|
|
1438
|
+
const allPrereqsMet = prereqs.every((prereq) => masteredTags.has(prereq.tag));
|
|
1439
|
+
if (allPrereqsMet) {
|
|
1440
|
+
unlocked.add(tagId);
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1443
|
+
return unlocked;
|
|
1444
|
+
}
|
|
1445
|
+
/**
|
|
1446
|
+
* Check if a tag has prerequisites defined in config
|
|
1447
|
+
*/
|
|
1448
|
+
hasPrerequisites(tagId) {
|
|
1449
|
+
return tagId in this.config.prerequisites;
|
|
1450
|
+
}
|
|
1451
|
+
/**
|
|
1452
|
+
* Check if a card is unlocked and generate reason.
|
|
1453
|
+
*/
|
|
1454
|
+
async checkCardUnlock(cardId, course, unlockedTags, masteredTags) {
|
|
1455
|
+
try {
|
|
1456
|
+
const tagResponse = await course.getAppliedTags(cardId);
|
|
1457
|
+
const cardTags = tagResponse.rows.map((row) => row.value?.name || row.key);
|
|
1458
|
+
const lockedTags = cardTags.filter(
|
|
1459
|
+
(tag) => this.hasPrerequisites(tag) && !unlockedTags.has(tag)
|
|
1460
|
+
);
|
|
1461
|
+
if (lockedTags.length === 0) {
|
|
1462
|
+
const tagList = cardTags.length > 0 ? cardTags.join(", ") : "none";
|
|
1463
|
+
return {
|
|
1464
|
+
isUnlocked: true,
|
|
1465
|
+
reason: `Prerequisites met, tags: ${tagList}`
|
|
1466
|
+
};
|
|
1467
|
+
}
|
|
1468
|
+
const missingPrereqs = lockedTags.flatMap((tag) => {
|
|
1469
|
+
const prereqs = this.config.prerequisites[tag] || [];
|
|
1470
|
+
return prereqs.filter((p) => !masteredTags.has(p.tag)).map((p) => p.tag);
|
|
1471
|
+
});
|
|
1472
|
+
return {
|
|
1473
|
+
isUnlocked: false,
|
|
1474
|
+
reason: `Blocked: missing prerequisites ${missingPrereqs.join(", ")} for tags ${lockedTags.join(", ")}`
|
|
1475
|
+
};
|
|
1476
|
+
} catch {
|
|
1477
|
+
return {
|
|
1478
|
+
isUnlocked: true,
|
|
1479
|
+
reason: "Prerequisites check skipped (tag lookup failed)"
|
|
1480
|
+
};
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1483
|
+
/**
|
|
1484
|
+
* CardFilter.transform implementation.
|
|
1485
|
+
*
|
|
1486
|
+
* Apply prerequisite gating to cards. Cards with locked tags receive score: 0.
|
|
1487
|
+
*/
|
|
1488
|
+
async transform(cards, context) {
|
|
1489
|
+
const masteredTags = await this.getMasteredTags(context);
|
|
1490
|
+
const unlockedTags = this.getUnlockedTags(masteredTags);
|
|
1491
|
+
const gated = [];
|
|
1492
|
+
for (const card of cards) {
|
|
1493
|
+
const { isUnlocked, reason } = await this.checkCardUnlock(
|
|
1494
|
+
card.cardId,
|
|
1495
|
+
context.course,
|
|
1496
|
+
unlockedTags,
|
|
1497
|
+
masteredTags
|
|
1498
|
+
);
|
|
1499
|
+
const finalScore = isUnlocked ? card.score : 0;
|
|
1500
|
+
const action = isUnlocked ? "passed" : "penalized";
|
|
1501
|
+
gated.push({
|
|
1502
|
+
...card,
|
|
1503
|
+
score: finalScore,
|
|
1504
|
+
provenance: [
|
|
1505
|
+
...card.provenance,
|
|
1506
|
+
{
|
|
1507
|
+
strategy: "hierarchyDefinition",
|
|
1508
|
+
strategyName: this.strategyName || this.name,
|
|
1509
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-hierarchy",
|
|
1510
|
+
action,
|
|
1511
|
+
score: finalScore,
|
|
1512
|
+
reason
|
|
1513
|
+
}
|
|
1514
|
+
]
|
|
1515
|
+
});
|
|
1516
|
+
}
|
|
1517
|
+
return gated;
|
|
1518
|
+
}
|
|
1519
|
+
/**
|
|
1520
|
+
* Legacy getWeightedCards - now throws as filters should not be used as generators.
|
|
1521
|
+
*
|
|
1522
|
+
* Use transform() via Pipeline instead.
|
|
1523
|
+
*/
|
|
1524
|
+
async getWeightedCards(_limit) {
|
|
1525
|
+
throw new Error(
|
|
1526
|
+
"HierarchyDefinitionNavigator is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
|
|
1527
|
+
);
|
|
1528
|
+
}
|
|
1529
|
+
// Legacy methods - stub implementations since filters don't generate cards
|
|
1530
|
+
async getNewCards(_n) {
|
|
1531
|
+
return [];
|
|
1532
|
+
}
|
|
1533
|
+
async getPendingReviews() {
|
|
1534
|
+
return [];
|
|
1535
|
+
}
|
|
1536
|
+
};
|
|
1537
|
+
}
|
|
1538
|
+
});
|
|
1539
|
+
|
|
1540
|
+
// src/core/navigators/interferenceMitigator.ts
|
|
1541
|
+
var interferenceMitigator_exports = {};
|
|
1542
|
+
__export(interferenceMitigator_exports, {
|
|
1543
|
+
default: () => InterferenceMitigatorNavigator
|
|
1544
|
+
});
|
|
1545
|
+
import { toCourseElo as toCourseElo5 } from "@vue-skuilder/common";
|
|
1546
|
+
var DEFAULT_MIN_COUNT2, DEFAULT_MIN_ELAPSED_DAYS, DEFAULT_INTERFERENCE_DECAY, InterferenceMitigatorNavigator;
|
|
1547
|
+
var init_interferenceMitigator = __esm({
|
|
1548
|
+
"src/core/navigators/interferenceMitigator.ts"() {
|
|
1549
|
+
"use strict";
|
|
1550
|
+
init_navigators();
|
|
1551
|
+
DEFAULT_MIN_COUNT2 = 10;
|
|
1552
|
+
DEFAULT_MIN_ELAPSED_DAYS = 3;
|
|
1553
|
+
DEFAULT_INTERFERENCE_DECAY = 0.8;
|
|
1554
|
+
InterferenceMitigatorNavigator = class extends ContentNavigator {
|
|
1555
|
+
config;
|
|
1556
|
+
_strategyData;
|
|
1557
|
+
/** Human-readable name for CardFilter interface */
|
|
1558
|
+
name;
|
|
1559
|
+
/** Precomputed map: tag -> set of { partner, decay } it interferes with */
|
|
1560
|
+
interferenceMap;
|
|
1561
|
+
constructor(user, course, _strategyData) {
|
|
1562
|
+
super(user, course, _strategyData);
|
|
1563
|
+
this._strategyData = _strategyData;
|
|
1564
|
+
this.config = this.parseConfig(_strategyData.serializedData);
|
|
1565
|
+
this.interferenceMap = this.buildInterferenceMap();
|
|
1566
|
+
this.name = _strategyData.name || "Interference Mitigator";
|
|
1567
|
+
}
|
|
1568
|
+
parseConfig(serializedData) {
|
|
1569
|
+
try {
|
|
1570
|
+
const parsed = JSON.parse(serializedData);
|
|
1571
|
+
let sets = parsed.interferenceSets || [];
|
|
1572
|
+
if (sets.length > 0 && Array.isArray(sets[0])) {
|
|
1573
|
+
sets = sets.map((tags) => ({ tags }));
|
|
1574
|
+
}
|
|
1575
|
+
return {
|
|
1576
|
+
interferenceSets: sets,
|
|
1577
|
+
maturityThreshold: {
|
|
1578
|
+
minCount: parsed.maturityThreshold?.minCount ?? DEFAULT_MIN_COUNT2,
|
|
1579
|
+
minElo: parsed.maturityThreshold?.minElo,
|
|
1580
|
+
minElapsedDays: parsed.maturityThreshold?.minElapsedDays ?? DEFAULT_MIN_ELAPSED_DAYS
|
|
1581
|
+
},
|
|
1582
|
+
defaultDecay: parsed.defaultDecay ?? DEFAULT_INTERFERENCE_DECAY
|
|
1583
|
+
};
|
|
1584
|
+
} catch {
|
|
1585
|
+
return {
|
|
1586
|
+
interferenceSets: [],
|
|
1587
|
+
maturityThreshold: {
|
|
1588
|
+
minCount: DEFAULT_MIN_COUNT2,
|
|
1589
|
+
minElapsedDays: DEFAULT_MIN_ELAPSED_DAYS
|
|
1590
|
+
},
|
|
1591
|
+
defaultDecay: DEFAULT_INTERFERENCE_DECAY
|
|
1592
|
+
};
|
|
1593
|
+
}
|
|
1594
|
+
}
|
|
1595
|
+
/**
|
|
1596
|
+
* Build a map from each tag to its interference partners with decay coefficients.
|
|
1597
|
+
* If tags A, B, C are in an interference group with decay 0.8, then:
|
|
1598
|
+
* - A interferes with B (decay 0.8) and C (decay 0.8)
|
|
1599
|
+
* - B interferes with A (decay 0.8) and C (decay 0.8)
|
|
1600
|
+
* - etc.
|
|
1601
|
+
*/
|
|
1602
|
+
buildInterferenceMap() {
|
|
1603
|
+
const map = /* @__PURE__ */ new Map();
|
|
1604
|
+
for (const group of this.config.interferenceSets) {
|
|
1605
|
+
const decay = group.decay ?? this.config.defaultDecay ?? DEFAULT_INTERFERENCE_DECAY;
|
|
1606
|
+
for (const tag of group.tags) {
|
|
1607
|
+
if (!map.has(tag)) {
|
|
1608
|
+
map.set(tag, []);
|
|
1609
|
+
}
|
|
1610
|
+
const partners = map.get(tag);
|
|
1611
|
+
for (const other of group.tags) {
|
|
1612
|
+
if (other !== tag) {
|
|
1613
|
+
const existing = partners.find((p) => p.partner === other);
|
|
1614
|
+
if (existing) {
|
|
1615
|
+
existing.decay = Math.max(existing.decay, decay);
|
|
1616
|
+
} else {
|
|
1617
|
+
partners.push({ partner: other, decay });
|
|
1618
|
+
}
|
|
1619
|
+
}
|
|
1620
|
+
}
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1623
|
+
return map;
|
|
1624
|
+
}
|
|
1625
|
+
/**
|
|
1626
|
+
* Get the set of tags that are currently immature for this user.
|
|
1627
|
+
* A tag is immature if the user has interacted with it but hasn't
|
|
1628
|
+
* reached the maturity threshold.
|
|
1629
|
+
*/
|
|
1630
|
+
async getImmatureTags(context) {
|
|
1631
|
+
const immature = /* @__PURE__ */ new Set();
|
|
1632
|
+
try {
|
|
1633
|
+
const courseReg = await context.user.getCourseRegDoc(context.course.getCourseID());
|
|
1634
|
+
const userElo = toCourseElo5(courseReg.elo);
|
|
1635
|
+
const minCount = this.config.maturityThreshold?.minCount ?? DEFAULT_MIN_COUNT2;
|
|
1636
|
+
const minElo = this.config.maturityThreshold?.minElo;
|
|
1637
|
+
const minElapsedDays = this.config.maturityThreshold?.minElapsedDays ?? DEFAULT_MIN_ELAPSED_DAYS;
|
|
1638
|
+
const minCountForElapsed = minElapsedDays * 2;
|
|
1639
|
+
for (const [tagId, tagElo] of Object.entries(userElo.tags)) {
|
|
1640
|
+
if (tagElo.count === 0) continue;
|
|
1641
|
+
const belowCount = tagElo.count < minCount;
|
|
1642
|
+
const belowElo = minElo !== void 0 && tagElo.score < minElo;
|
|
1643
|
+
const belowElapsed = tagElo.count < minCountForElapsed;
|
|
1644
|
+
if (belowCount || belowElo || belowElapsed) {
|
|
1645
|
+
immature.add(tagId);
|
|
1646
|
+
}
|
|
1647
|
+
}
|
|
1648
|
+
} catch {
|
|
1649
|
+
}
|
|
1650
|
+
return immature;
|
|
1651
|
+
}
|
|
1652
|
+
/**
|
|
1653
|
+
* Get all tags that interfere with any immature tag, along with their decay coefficients.
|
|
1654
|
+
* These are the tags we want to avoid introducing.
|
|
1655
|
+
*/
|
|
1656
|
+
getTagsToAvoid(immatureTags) {
|
|
1657
|
+
const avoid = /* @__PURE__ */ new Map();
|
|
1658
|
+
for (const immatureTag of immatureTags) {
|
|
1659
|
+
const partners = this.interferenceMap.get(immatureTag);
|
|
1660
|
+
if (partners) {
|
|
1661
|
+
for (const { partner, decay } of partners) {
|
|
1662
|
+
if (!immatureTags.has(partner)) {
|
|
1663
|
+
const existing = avoid.get(partner) ?? 0;
|
|
1664
|
+
avoid.set(partner, Math.max(existing, decay));
|
|
1665
|
+
}
|
|
1666
|
+
}
|
|
1667
|
+
}
|
|
1668
|
+
}
|
|
1669
|
+
return avoid;
|
|
1670
|
+
}
|
|
1671
|
+
/**
|
|
1672
|
+
* Get tags for a single card
|
|
1673
|
+
*/
|
|
1674
|
+
async getCardTags(cardId, course) {
|
|
1675
|
+
try {
|
|
1676
|
+
const tagResponse = await course.getAppliedTags(cardId);
|
|
1677
|
+
return tagResponse.rows.map((row) => row.value?.name || row.key).filter(Boolean);
|
|
1678
|
+
} catch {
|
|
1679
|
+
return [];
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
/**
|
|
1683
|
+
* Compute interference score reduction for a card.
|
|
1684
|
+
* Returns: { multiplier, interfering tags, reason }
|
|
1685
|
+
*/
|
|
1686
|
+
computeInterferenceEffect(cardTags, tagsToAvoid, immatureTags) {
|
|
1687
|
+
if (tagsToAvoid.size === 0) {
|
|
1688
|
+
return {
|
|
1689
|
+
multiplier: 1,
|
|
1690
|
+
interferingTags: [],
|
|
1691
|
+
reason: "No interference detected"
|
|
1692
|
+
};
|
|
1693
|
+
}
|
|
1694
|
+
let multiplier = 1;
|
|
1695
|
+
const interferingTags = [];
|
|
1696
|
+
for (const tag of cardTags) {
|
|
1697
|
+
const decay = tagsToAvoid.get(tag);
|
|
1698
|
+
if (decay !== void 0) {
|
|
1699
|
+
interferingTags.push(tag);
|
|
1700
|
+
multiplier *= 1 - decay;
|
|
1701
|
+
}
|
|
1702
|
+
}
|
|
1703
|
+
if (interferingTags.length === 0) {
|
|
1704
|
+
return {
|
|
1705
|
+
multiplier: 1,
|
|
1706
|
+
interferingTags: [],
|
|
1707
|
+
reason: "No interference detected"
|
|
1708
|
+
};
|
|
1709
|
+
}
|
|
1710
|
+
const causingTags = /* @__PURE__ */ new Set();
|
|
1711
|
+
for (const tag of interferingTags) {
|
|
1712
|
+
for (const immatureTag of immatureTags) {
|
|
1713
|
+
const partners = this.interferenceMap.get(immatureTag);
|
|
1714
|
+
if (partners?.some((p) => p.partner === tag)) {
|
|
1715
|
+
causingTags.add(immatureTag);
|
|
1716
|
+
}
|
|
1717
|
+
}
|
|
1718
|
+
}
|
|
1719
|
+
const reason = `Interferes with immature tags ${Array.from(causingTags).join(", ")} (tags: ${interferingTags.join(", ")}, multiplier: ${multiplier.toFixed(2)})`;
|
|
1720
|
+
return { multiplier, interferingTags, reason };
|
|
1721
|
+
}
|
|
1722
|
+
/**
|
|
1723
|
+
* CardFilter.transform implementation.
|
|
1724
|
+
*
|
|
1725
|
+
* Apply interference-aware scoring. Cards with tags that interfere with
|
|
1726
|
+
* immature learnings get reduced scores.
|
|
1727
|
+
*/
|
|
1728
|
+
async transform(cards, context) {
|
|
1729
|
+
const immatureTags = await this.getImmatureTags(context);
|
|
1730
|
+
const tagsToAvoid = this.getTagsToAvoid(immatureTags);
|
|
1731
|
+
const adjusted = [];
|
|
1732
|
+
for (const card of cards) {
|
|
1733
|
+
const cardTags = await this.getCardTags(card.cardId, context.course);
|
|
1734
|
+
const { multiplier, reason } = this.computeInterferenceEffect(
|
|
1735
|
+
cardTags,
|
|
1736
|
+
tagsToAvoid,
|
|
1737
|
+
immatureTags
|
|
1738
|
+
);
|
|
1739
|
+
const finalScore = card.score * multiplier;
|
|
1740
|
+
const action = multiplier < 1 ? "penalized" : multiplier > 1 ? "boosted" : "passed";
|
|
1741
|
+
adjusted.push({
|
|
1742
|
+
...card,
|
|
1743
|
+
score: finalScore,
|
|
1744
|
+
provenance: [
|
|
1745
|
+
...card.provenance,
|
|
1746
|
+
{
|
|
1747
|
+
strategy: "interferenceMitigator",
|
|
1748
|
+
strategyName: this.strategyName || this.name,
|
|
1749
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-interference",
|
|
1750
|
+
action,
|
|
1751
|
+
score: finalScore,
|
|
1752
|
+
reason
|
|
1753
|
+
}
|
|
1754
|
+
]
|
|
1755
|
+
});
|
|
1756
|
+
}
|
|
1757
|
+
return adjusted;
|
|
1758
|
+
}
|
|
1759
|
+
/**
|
|
1760
|
+
* Legacy getWeightedCards - now throws as filters should not be used as generators.
|
|
1761
|
+
*
|
|
1762
|
+
* Use transform() via Pipeline instead.
|
|
1763
|
+
*/
|
|
1764
|
+
async getWeightedCards(_limit) {
|
|
1765
|
+
throw new Error(
|
|
1766
|
+
"InterferenceMitigatorNavigator is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
|
|
1767
|
+
);
|
|
1768
|
+
}
|
|
1769
|
+
// Legacy methods - stub implementations since filters don't generate cards
|
|
1770
|
+
async getNewCards(_n) {
|
|
1771
|
+
return [];
|
|
1772
|
+
}
|
|
1773
|
+
async getPendingReviews() {
|
|
1774
|
+
return [];
|
|
1775
|
+
}
|
|
1776
|
+
};
|
|
1777
|
+
}
|
|
1778
|
+
});
|
|
1779
|
+
|
|
1780
|
+
// src/core/navigators/relativePriority.ts
|
|
1781
|
+
var relativePriority_exports = {};
|
|
1782
|
+
__export(relativePriority_exports, {
|
|
1783
|
+
default: () => RelativePriorityNavigator
|
|
1784
|
+
});
|
|
1785
|
+
var DEFAULT_PRIORITY, DEFAULT_PRIORITY_INFLUENCE, DEFAULT_COMBINE_MODE, RelativePriorityNavigator;
|
|
1786
|
+
var init_relativePriority = __esm({
|
|
1787
|
+
"src/core/navigators/relativePriority.ts"() {
|
|
1788
|
+
"use strict";
|
|
1789
|
+
init_navigators();
|
|
1790
|
+
DEFAULT_PRIORITY = 0.5;
|
|
1791
|
+
DEFAULT_PRIORITY_INFLUENCE = 0.5;
|
|
1792
|
+
DEFAULT_COMBINE_MODE = "max";
|
|
1793
|
+
RelativePriorityNavigator = class extends ContentNavigator {
|
|
1794
|
+
config;
|
|
1795
|
+
_strategyData;
|
|
1796
|
+
/** Human-readable name for CardFilter interface */
|
|
1797
|
+
name;
|
|
1798
|
+
constructor(user, course, _strategyData) {
|
|
1799
|
+
super(user, course, _strategyData);
|
|
1800
|
+
this._strategyData = _strategyData;
|
|
1801
|
+
this.config = this.parseConfig(_strategyData.serializedData);
|
|
1802
|
+
this.name = _strategyData.name || "Relative Priority";
|
|
1803
|
+
}
|
|
1804
|
+
parseConfig(serializedData) {
|
|
1805
|
+
try {
|
|
1806
|
+
const parsed = JSON.parse(serializedData);
|
|
1807
|
+
return {
|
|
1808
|
+
tagPriorities: parsed.tagPriorities || {},
|
|
1809
|
+
defaultPriority: parsed.defaultPriority ?? DEFAULT_PRIORITY,
|
|
1810
|
+
combineMode: parsed.combineMode ?? DEFAULT_COMBINE_MODE,
|
|
1811
|
+
priorityInfluence: parsed.priorityInfluence ?? DEFAULT_PRIORITY_INFLUENCE
|
|
1812
|
+
};
|
|
1813
|
+
} catch {
|
|
1814
|
+
return {
|
|
1815
|
+
tagPriorities: {},
|
|
1816
|
+
defaultPriority: DEFAULT_PRIORITY,
|
|
1817
|
+
combineMode: DEFAULT_COMBINE_MODE,
|
|
1818
|
+
priorityInfluence: DEFAULT_PRIORITY_INFLUENCE
|
|
1819
|
+
};
|
|
1820
|
+
}
|
|
1821
|
+
}
|
|
1822
|
+
/**
|
|
1823
|
+
* Look up the priority for a tag.
|
|
1824
|
+
*/
|
|
1825
|
+
getTagPriority(tagId) {
|
|
1826
|
+
return this.config.tagPriorities[tagId] ?? this.config.defaultPriority ?? DEFAULT_PRIORITY;
|
|
1827
|
+
}
|
|
1828
|
+
/**
|
|
1829
|
+
* Compute combined priority for a card based on its tags.
|
|
1830
|
+
*/
|
|
1831
|
+
computeCardPriority(cardTags) {
|
|
1832
|
+
if (cardTags.length === 0) {
|
|
1833
|
+
return this.config.defaultPriority ?? DEFAULT_PRIORITY;
|
|
1834
|
+
}
|
|
1835
|
+
const priorities = cardTags.map((tag) => this.getTagPriority(tag));
|
|
1836
|
+
switch (this.config.combineMode) {
|
|
1837
|
+
case "max":
|
|
1838
|
+
return Math.max(...priorities);
|
|
1839
|
+
case "min":
|
|
1840
|
+
return Math.min(...priorities);
|
|
1841
|
+
case "average":
|
|
1842
|
+
return priorities.reduce((sum, p) => sum + p, 0) / priorities.length;
|
|
1843
|
+
default:
|
|
1844
|
+
return Math.max(...priorities);
|
|
1845
|
+
}
|
|
1846
|
+
}
|
|
1847
|
+
/**
|
|
1848
|
+
* Compute boost factor based on priority.
|
|
1849
|
+
*
|
|
1850
|
+
* The formula: 1 + (priority - 0.5) * priorityInfluence
|
|
1851
|
+
*
|
|
1852
|
+
* This creates a multiplier centered around 1.0:
|
|
1853
|
+
* - Priority 1.0 with influence 0.5 → 1.25 (25% boost)
|
|
1854
|
+
* - Priority 0.5 with any influence → 1.00 (neutral)
|
|
1855
|
+
* - Priority 0.0 with influence 0.5 → 0.75 (25% reduction)
|
|
1856
|
+
*/
|
|
1857
|
+
computeBoostFactor(priority) {
|
|
1858
|
+
const influence = this.config.priorityInfluence ?? DEFAULT_PRIORITY_INFLUENCE;
|
|
1859
|
+
return 1 + (priority - 0.5) * influence;
|
|
1860
|
+
}
|
|
1861
|
+
/**
|
|
1862
|
+
* Build human-readable reason for priority adjustment.
|
|
1863
|
+
*/
|
|
1864
|
+
buildPriorityReason(cardTags, priority, boostFactor, finalScore) {
|
|
1865
|
+
if (cardTags.length === 0) {
|
|
1866
|
+
return `No tags, neutral priority (${priority.toFixed(2)})`;
|
|
1867
|
+
}
|
|
1868
|
+
const tagList = cardTags.slice(0, 3).join(", ");
|
|
1869
|
+
const more = cardTags.length > 3 ? ` (+${cardTags.length - 3} more)` : "";
|
|
1870
|
+
if (boostFactor === 1) {
|
|
1871
|
+
return `Neutral priority (${priority.toFixed(2)}) for tags: ${tagList}${more}`;
|
|
1872
|
+
} else if (boostFactor > 1) {
|
|
1873
|
+
return `High-priority tags: ${tagList}${more} (priority ${priority.toFixed(2)} \u2192 boost ${boostFactor.toFixed(2)}x \u2192 ${finalScore.toFixed(2)})`;
|
|
1874
|
+
} else {
|
|
1875
|
+
return `Low-priority tags: ${tagList}${more} (priority ${priority.toFixed(2)} \u2192 reduce ${boostFactor.toFixed(2)}x \u2192 ${finalScore.toFixed(2)})`;
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1878
|
+
/**
|
|
1879
|
+
* Get tags for a single card.
|
|
1880
|
+
*/
|
|
1881
|
+
async getCardTags(cardId, course) {
|
|
1882
|
+
try {
|
|
1883
|
+
const tagResponse = await course.getAppliedTags(cardId);
|
|
1884
|
+
return tagResponse.rows.map((r) => r.doc?.name).filter((x) => !!x);
|
|
1885
|
+
} catch {
|
|
1886
|
+
return [];
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1889
|
+
/**
|
|
1890
|
+
* CardFilter.transform implementation.
|
|
1891
|
+
*
|
|
1892
|
+
* Apply priority-adjusted scoring. Cards with high-priority tags get boosted,
|
|
1893
|
+
* cards with low-priority tags get reduced scores.
|
|
1894
|
+
*/
|
|
1895
|
+
async transform(cards, context) {
|
|
1896
|
+
const adjusted = await Promise.all(
|
|
1897
|
+
cards.map(async (card) => {
|
|
1898
|
+
const cardTags = await this.getCardTags(card.cardId, context.course);
|
|
1899
|
+
const priority = this.computeCardPriority(cardTags);
|
|
1900
|
+
const boostFactor = this.computeBoostFactor(priority);
|
|
1901
|
+
const finalScore = Math.max(0, Math.min(1, card.score * boostFactor));
|
|
1902
|
+
const action = boostFactor > 1 ? "boosted" : boostFactor < 1 ? "penalized" : "passed";
|
|
1903
|
+
const reason = this.buildPriorityReason(cardTags, priority, boostFactor, finalScore);
|
|
1904
|
+
return {
|
|
1905
|
+
...card,
|
|
1906
|
+
score: finalScore,
|
|
1907
|
+
provenance: [
|
|
1908
|
+
...card.provenance,
|
|
1909
|
+
{
|
|
1910
|
+
strategy: "relativePriority",
|
|
1911
|
+
strategyName: this.strategyName || this.name,
|
|
1912
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-priority",
|
|
1913
|
+
action,
|
|
1914
|
+
score: finalScore,
|
|
1915
|
+
reason
|
|
1916
|
+
}
|
|
1917
|
+
]
|
|
1918
|
+
};
|
|
1919
|
+
})
|
|
1920
|
+
);
|
|
1921
|
+
return adjusted;
|
|
1922
|
+
}
|
|
1923
|
+
/**
|
|
1924
|
+
* Legacy getWeightedCards - now throws as filters should not be used as generators.
|
|
1925
|
+
*
|
|
1926
|
+
* Use transform() via Pipeline instead.
|
|
1927
|
+
*/
|
|
1928
|
+
async getWeightedCards(_limit) {
|
|
1929
|
+
throw new Error(
|
|
1930
|
+
"RelativePriorityNavigator is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
|
|
1931
|
+
);
|
|
1932
|
+
}
|
|
1933
|
+
// Legacy methods - stub implementations since filters don't generate cards
|
|
1934
|
+
async getNewCards(_n) {
|
|
1935
|
+
return [];
|
|
1936
|
+
}
|
|
1937
|
+
async getPendingReviews() {
|
|
1938
|
+
return [];
|
|
663
1939
|
}
|
|
664
1940
|
};
|
|
665
1941
|
}
|
|
666
1942
|
});
|
|
667
1943
|
|
|
668
|
-
// src/core/navigators/
|
|
669
|
-
var
|
|
670
|
-
__export(
|
|
671
|
-
default: () =>
|
|
1944
|
+
// src/core/navigators/srs.ts
|
|
1945
|
+
var srs_exports = {};
|
|
1946
|
+
__export(srs_exports, {
|
|
1947
|
+
default: () => SRSNavigator
|
|
672
1948
|
});
|
|
673
|
-
|
|
674
|
-
var
|
|
675
|
-
|
|
1949
|
+
import moment from "moment";
|
|
1950
|
+
var SRSNavigator;
|
|
1951
|
+
var init_srs = __esm({
|
|
1952
|
+
"src/core/navigators/srs.ts"() {
|
|
676
1953
|
"use strict";
|
|
677
1954
|
init_navigators();
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
user;
|
|
682
|
-
course;
|
|
1955
|
+
SRSNavigator = class extends ContentNavigator {
|
|
1956
|
+
/** Human-readable name for CardGenerator interface */
|
|
1957
|
+
name;
|
|
683
1958
|
constructor(user, course, strategyData) {
|
|
684
|
-
super();
|
|
685
|
-
this.
|
|
686
|
-
this.course = course;
|
|
687
|
-
if (strategyData.serializedData) {
|
|
688
|
-
try {
|
|
689
|
-
this.orderedCardIds = JSON.parse(strategyData.serializedData);
|
|
690
|
-
} catch (e) {
|
|
691
|
-
logger.error("Failed to parse serializedData for HardcodedOrderNavigator", e);
|
|
692
|
-
}
|
|
693
|
-
}
|
|
1959
|
+
super(user, course, strategyData);
|
|
1960
|
+
this.name = strategyData?.name || "SRS";
|
|
694
1961
|
}
|
|
695
|
-
|
|
1962
|
+
/**
|
|
1963
|
+
* Get review cards scored by urgency.
|
|
1964
|
+
*
|
|
1965
|
+
* Score formula combines:
|
|
1966
|
+
* - Relative overdueness: hoursOverdue / intervalHours
|
|
1967
|
+
* - Interval recency: exponential decay favoring shorter intervals
|
|
1968
|
+
*
|
|
1969
|
+
* Cards not yet due are excluded (not scored as 0).
|
|
1970
|
+
*
|
|
1971
|
+
* This method supports both the legacy signature (limit only) and the
|
|
1972
|
+
* CardGenerator interface signature (limit, context).
|
|
1973
|
+
*
|
|
1974
|
+
* @param limit - Maximum number of cards to return
|
|
1975
|
+
* @param _context - Optional GeneratorContext (currently unused, but required for interface)
|
|
1976
|
+
*/
|
|
1977
|
+
async getWeightedCards(limit, _context) {
|
|
1978
|
+
if (!this.user || !this.course) {
|
|
1979
|
+
throw new Error("SRSNavigator requires user and course to be set");
|
|
1980
|
+
}
|
|
696
1981
|
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
697
|
-
|
|
1982
|
+
const now = moment.utc();
|
|
1983
|
+
const dueReviews = reviews.filter((r) => now.isAfter(moment.utc(r.reviewTime)));
|
|
1984
|
+
const scored = dueReviews.map((review) => {
|
|
1985
|
+
const { score, reason } = this.computeUrgencyScore(review, now);
|
|
698
1986
|
return {
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
1987
|
+
cardId: review.cardId,
|
|
1988
|
+
courseId: review.courseId,
|
|
1989
|
+
score,
|
|
1990
|
+
provenance: [
|
|
1991
|
+
{
|
|
1992
|
+
strategy: "srs",
|
|
1993
|
+
strategyName: this.strategyName || this.name,
|
|
1994
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-SRS-default",
|
|
1995
|
+
action: "generated",
|
|
1996
|
+
score,
|
|
1997
|
+
reason
|
|
1998
|
+
}
|
|
1999
|
+
]
|
|
706
2000
|
};
|
|
707
2001
|
});
|
|
2002
|
+
return scored.sort((a, b) => b.score - a.score).slice(0, limit);
|
|
708
2003
|
}
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
2004
|
+
/**
|
|
2005
|
+
* Compute urgency score for a review card.
|
|
2006
|
+
*
|
|
2007
|
+
* Two factors:
|
|
2008
|
+
* 1. Relative overdueness = hoursOverdue / intervalHours
|
|
2009
|
+
* - 2 days overdue on 3-day interval = 0.67 (urgent)
|
|
2010
|
+
* - 2 days overdue on 180-day interval = 0.01 (not urgent)
|
|
2011
|
+
*
|
|
2012
|
+
* 2. Interval recency factor = 0.3 + 0.7 * exp(-intervalHours / 720)
|
|
2013
|
+
* - 24h interval → ~1.0 (very recent learning)
|
|
2014
|
+
* - 30 days (720h) → ~0.56
|
|
2015
|
+
* - 180 days → ~0.30
|
|
2016
|
+
*
|
|
2017
|
+
* Combined: base 0.5 + weighted average of factors * 0.45
|
|
2018
|
+
* Result range: approximately 0.5 to 0.95
|
|
2019
|
+
*/
|
|
2020
|
+
computeUrgencyScore(review, now) {
|
|
2021
|
+
const scheduledAt = moment.utc(review.scheduledAt);
|
|
2022
|
+
const due = moment.utc(review.reviewTime);
|
|
2023
|
+
const intervalHours = Math.max(1, due.diff(scheduledAt, "hours"));
|
|
2024
|
+
const hoursOverdue = now.diff(due, "hours");
|
|
2025
|
+
const relativeOverdue = hoursOverdue / intervalHours;
|
|
2026
|
+
const recencyFactor = 0.3 + 0.7 * Math.exp(-intervalHours / 720);
|
|
2027
|
+
const overdueContribution = Math.min(1, Math.max(0, relativeOverdue));
|
|
2028
|
+
const urgency = overdueContribution * 0.5 + recencyFactor * 0.5;
|
|
2029
|
+
const score = Math.min(0.95, 0.5 + urgency * 0.45);
|
|
2030
|
+
const reason = `${Math.round(hoursOverdue)}h overdue (interval: ${Math.round(intervalHours)}h, relative: ${relativeOverdue.toFixed(2)}), recency: ${recencyFactor.toFixed(2)}, review`;
|
|
2031
|
+
return { score, reason };
|
|
2032
|
+
}
|
|
2033
|
+
/**
|
|
2034
|
+
* Get pending reviews in legacy format.
|
|
2035
|
+
*
|
|
2036
|
+
* Returns all pending reviews for the course, enriched with session item fields.
|
|
2037
|
+
*/
|
|
2038
|
+
async getPendingReviews() {
|
|
2039
|
+
if (!this.user || !this.course) {
|
|
2040
|
+
throw new Error("SRSNavigator requires user and course to be set");
|
|
2041
|
+
}
|
|
2042
|
+
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
2043
|
+
return reviews.map((r) => ({
|
|
2044
|
+
...r,
|
|
2045
|
+
contentSourceType: "course",
|
|
2046
|
+
contentSourceID: this.course.getCourseID(),
|
|
2047
|
+
cardID: r.cardId,
|
|
2048
|
+
courseID: r.courseId,
|
|
2049
|
+
qualifiedID: `${r.courseId}-${r.cardId}`,
|
|
2050
|
+
reviewID: r._id,
|
|
2051
|
+
status: "review"
|
|
2052
|
+
}));
|
|
2053
|
+
}
|
|
2054
|
+
/**
|
|
2055
|
+
* SRS does not generate new cards.
|
|
2056
|
+
* Use ELONavigator or another generator for new cards.
|
|
2057
|
+
*/
|
|
2058
|
+
async getNewCards(_n) {
|
|
2059
|
+
return [];
|
|
724
2060
|
}
|
|
725
2061
|
};
|
|
726
2062
|
}
|
|
@@ -731,9 +2067,21 @@ var globImport;
|
|
|
731
2067
|
var init_ = __esm({
|
|
732
2068
|
'import("./**/*") in src/core/navigators/index.ts'() {
|
|
733
2069
|
globImport = __glob({
|
|
2070
|
+
"./CompositeGenerator.ts": () => Promise.resolve().then(() => (init_CompositeGenerator(), CompositeGenerator_exports)),
|
|
2071
|
+
"./Pipeline.ts": () => Promise.resolve().then(() => (init_Pipeline(), Pipeline_exports)),
|
|
2072
|
+
"./PipelineAssembler.ts": () => Promise.resolve().then(() => (init_PipelineAssembler(), PipelineAssembler_exports)),
|
|
734
2073
|
"./elo.ts": () => Promise.resolve().then(() => (init_elo(), elo_exports)),
|
|
2074
|
+
"./filters/eloDistance.ts": () => Promise.resolve().then(() => (init_eloDistance(), eloDistance_exports)),
|
|
2075
|
+
"./filters/index.ts": () => Promise.resolve().then(() => (init_filters(), filters_exports)),
|
|
2076
|
+
"./filters/types.ts": () => Promise.resolve().then(() => (init_types(), types_exports)),
|
|
2077
|
+
"./generators/index.ts": () => Promise.resolve().then(() => (init_generators(), generators_exports)),
|
|
2078
|
+
"./generators/types.ts": () => Promise.resolve().then(() => (init_types2(), types_exports2)),
|
|
735
2079
|
"./hardcodedOrder.ts": () => Promise.resolve().then(() => (init_hardcodedOrder(), hardcodedOrder_exports)),
|
|
736
|
-
"./
|
|
2080
|
+
"./hierarchyDefinition.ts": () => Promise.resolve().then(() => (init_hierarchyDefinition(), hierarchyDefinition_exports)),
|
|
2081
|
+
"./index.ts": () => Promise.resolve().then(() => (init_navigators(), navigators_exports)),
|
|
2082
|
+
"./interferenceMitigator.ts": () => Promise.resolve().then(() => (init_interferenceMitigator(), interferenceMitigator_exports)),
|
|
2083
|
+
"./relativePriority.ts": () => Promise.resolve().then(() => (init_relativePriority(), relativePriority_exports)),
|
|
2084
|
+
"./srs.ts": () => Promise.resolve().then(() => (init_srs(), srs_exports))
|
|
737
2085
|
});
|
|
738
2086
|
}
|
|
739
2087
|
});
|
|
@@ -742,9 +2090,34 @@ var init_ = __esm({
|
|
|
742
2090
|
var navigators_exports = {};
|
|
743
2091
|
__export(navigators_exports, {
|
|
744
2092
|
ContentNavigator: () => ContentNavigator,
|
|
745
|
-
|
|
2093
|
+
NavigatorRole: () => NavigatorRole,
|
|
2094
|
+
NavigatorRoles: () => NavigatorRoles,
|
|
2095
|
+
Navigators: () => Navigators,
|
|
2096
|
+
getCardOrigin: () => getCardOrigin,
|
|
2097
|
+
isFilter: () => isFilter,
|
|
2098
|
+
isGenerator: () => isGenerator
|
|
746
2099
|
});
|
|
747
|
-
|
|
2100
|
+
function getCardOrigin(card) {
|
|
2101
|
+
if (card.provenance.length === 0) {
|
|
2102
|
+
throw new Error("Card has no provenance - cannot determine origin");
|
|
2103
|
+
}
|
|
2104
|
+
const firstEntry = card.provenance[0];
|
|
2105
|
+
const reason = firstEntry.reason.toLowerCase();
|
|
2106
|
+
if (reason.includes("failed")) {
|
|
2107
|
+
return "failed";
|
|
2108
|
+
}
|
|
2109
|
+
if (reason.includes("review")) {
|
|
2110
|
+
return "review";
|
|
2111
|
+
}
|
|
2112
|
+
return "new";
|
|
2113
|
+
}
|
|
2114
|
+
function isGenerator(impl) {
|
|
2115
|
+
return NavigatorRoles[impl] === "generator" /* GENERATOR */;
|
|
2116
|
+
}
|
|
2117
|
+
function isFilter(impl) {
|
|
2118
|
+
return NavigatorRoles[impl] === "filter" /* FILTER */;
|
|
2119
|
+
}
|
|
2120
|
+
var Navigators, NavigatorRole, NavigatorRoles, ContentNavigator;
|
|
748
2121
|
var init_navigators = __esm({
|
|
749
2122
|
"src/core/navigators/index.ts"() {
|
|
750
2123
|
"use strict";
|
|
@@ -752,14 +2125,55 @@ var init_navigators = __esm({
|
|
|
752
2125
|
init_();
|
|
753
2126
|
Navigators = /* @__PURE__ */ ((Navigators2) => {
|
|
754
2127
|
Navigators2["ELO"] = "elo";
|
|
2128
|
+
Navigators2["SRS"] = "srs";
|
|
755
2129
|
Navigators2["HARDCODED"] = "hardcodedOrder";
|
|
2130
|
+
Navigators2["HIERARCHY"] = "hierarchyDefinition";
|
|
2131
|
+
Navigators2["INTERFERENCE"] = "interferenceMitigator";
|
|
2132
|
+
Navigators2["RELATIVE_PRIORITY"] = "relativePriority";
|
|
756
2133
|
return Navigators2;
|
|
757
2134
|
})(Navigators || {});
|
|
2135
|
+
NavigatorRole = /* @__PURE__ */ ((NavigatorRole2) => {
|
|
2136
|
+
NavigatorRole2["GENERATOR"] = "generator";
|
|
2137
|
+
NavigatorRole2["FILTER"] = "filter";
|
|
2138
|
+
return NavigatorRole2;
|
|
2139
|
+
})(NavigatorRole || {});
|
|
2140
|
+
NavigatorRoles = {
|
|
2141
|
+
["elo" /* ELO */]: "generator" /* GENERATOR */,
|
|
2142
|
+
["srs" /* SRS */]: "generator" /* GENERATOR */,
|
|
2143
|
+
["hardcodedOrder" /* HARDCODED */]: "generator" /* GENERATOR */,
|
|
2144
|
+
["hierarchyDefinition" /* HIERARCHY */]: "filter" /* FILTER */,
|
|
2145
|
+
["interferenceMitigator" /* INTERFERENCE */]: "filter" /* FILTER */,
|
|
2146
|
+
["relativePriority" /* RELATIVE_PRIORITY */]: "filter" /* FILTER */
|
|
2147
|
+
};
|
|
758
2148
|
ContentNavigator = class {
|
|
2149
|
+
/** User interface for this navigation session */
|
|
2150
|
+
user;
|
|
2151
|
+
/** Course interface for this navigation session */
|
|
2152
|
+
course;
|
|
2153
|
+
/** Human-readable name for this strategy instance (from ContentNavigationStrategyData.name) */
|
|
2154
|
+
strategyName;
|
|
2155
|
+
/** Unique document ID for this strategy instance (from ContentNavigationStrategyData._id) */
|
|
2156
|
+
strategyId;
|
|
2157
|
+
/**
|
|
2158
|
+
* Constructor for standard navigators.
|
|
2159
|
+
* Call this from subclass constructors to initialize common fields.
|
|
2160
|
+
*
|
|
2161
|
+
* Note: CompositeGenerator doesn't use this pattern and should call super() without args.
|
|
2162
|
+
*/
|
|
2163
|
+
constructor(user, course, strategyData) {
|
|
2164
|
+
if (user && course && strategyData) {
|
|
2165
|
+
this.user = user;
|
|
2166
|
+
this.course = course;
|
|
2167
|
+
this.strategyName = strategyData.name;
|
|
2168
|
+
this.strategyId = strategyData._id;
|
|
2169
|
+
}
|
|
2170
|
+
}
|
|
759
2171
|
/**
|
|
2172
|
+
* Factory method to create navigator instances dynamically.
|
|
760
2173
|
*
|
|
761
|
-
* @param user
|
|
762
|
-
* @param
|
|
2174
|
+
* @param user - User interface
|
|
2175
|
+
* @param course - Course interface
|
|
2176
|
+
* @param strategyData - Strategy configuration document
|
|
763
2177
|
* @returns the runtime object used to steer a study session.
|
|
764
2178
|
*/
|
|
765
2179
|
static async create(user, course, strategyData) {
|
|
@@ -780,6 +2194,70 @@ var init_navigators = __esm({
|
|
|
780
2194
|
}
|
|
781
2195
|
return new NavigatorImpl(user, course, strategyData);
|
|
782
2196
|
}
|
|
2197
|
+
/**
|
|
2198
|
+
* Get cards with suitability scores and provenance trails.
|
|
2199
|
+
*
|
|
2200
|
+
* **This is the PRIMARY API for navigation strategies.**
|
|
2201
|
+
*
|
|
2202
|
+
* Returns cards ranked by suitability score (0-1). Higher scores indicate
|
|
2203
|
+
* better candidates for presentation. Each card includes a provenance trail
|
|
2204
|
+
* documenting how strategies contributed to the final score.
|
|
2205
|
+
*
|
|
2206
|
+
* ## For Generators
|
|
2207
|
+
* Override this method to generate candidates and compute scores based on
|
|
2208
|
+
* your strategy's logic (e.g., ELO proximity, review urgency). Create the
|
|
2209
|
+
* initial provenance entry with action='generated'.
|
|
2210
|
+
*
|
|
2211
|
+
* ## Default Implementation
|
|
2212
|
+
* The base class provides a backward-compatible default that:
|
|
2213
|
+
* 1. Calls legacy getNewCards() and getPendingReviews()
|
|
2214
|
+
* 2. Assigns score=1.0 to all cards
|
|
2215
|
+
* 3. Creates minimal provenance from legacy methods
|
|
2216
|
+
* 4. Returns combined results up to limit
|
|
2217
|
+
*
|
|
2218
|
+
* This allows existing strategies to work without modification while
|
|
2219
|
+
* new strategies can override with proper scoring and provenance.
|
|
2220
|
+
*
|
|
2221
|
+
* @param limit - Maximum cards to return
|
|
2222
|
+
* @returns Cards sorted by score descending, with provenance trails
|
|
2223
|
+
*/
|
|
2224
|
+
async getWeightedCards(limit) {
|
|
2225
|
+
const newCards = await this.getNewCards(limit);
|
|
2226
|
+
const reviews = await this.getPendingReviews();
|
|
2227
|
+
const weighted = [
|
|
2228
|
+
...newCards.map((c) => ({
|
|
2229
|
+
cardId: c.cardID,
|
|
2230
|
+
courseId: c.courseID,
|
|
2231
|
+
score: 1,
|
|
2232
|
+
provenance: [
|
|
2233
|
+
{
|
|
2234
|
+
strategy: "legacy",
|
|
2235
|
+
strategyName: this.strategyName || "Legacy API",
|
|
2236
|
+
strategyId: this.strategyId || "legacy-fallback",
|
|
2237
|
+
action: "generated",
|
|
2238
|
+
score: 1,
|
|
2239
|
+
reason: "Generated via legacy getNewCards(), new card"
|
|
2240
|
+
}
|
|
2241
|
+
]
|
|
2242
|
+
})),
|
|
2243
|
+
...reviews.map((r) => ({
|
|
2244
|
+
cardId: r.cardID,
|
|
2245
|
+
courseId: r.courseID,
|
|
2246
|
+
score: 1,
|
|
2247
|
+
provenance: [
|
|
2248
|
+
{
|
|
2249
|
+
strategy: "legacy",
|
|
2250
|
+
strategyName: this.strategyName || "Legacy API",
|
|
2251
|
+
strategyId: this.strategyId || "legacy-fallback",
|
|
2252
|
+
action: "generated",
|
|
2253
|
+
score: 1,
|
|
2254
|
+
reason: "Generated via legacy getPendingReviews(), review"
|
|
2255
|
+
}
|
|
2256
|
+
]
|
|
2257
|
+
}))
|
|
2258
|
+
];
|
|
2259
|
+
return weighted.slice(0, limit);
|
|
2260
|
+
}
|
|
783
2261
|
};
|
|
784
2262
|
}
|
|
785
2263
|
});
|
|
@@ -789,7 +2267,7 @@ import {
|
|
|
789
2267
|
EloToNumber,
|
|
790
2268
|
Status,
|
|
791
2269
|
blankCourseElo as blankCourseElo2,
|
|
792
|
-
toCourseElo as
|
|
2270
|
+
toCourseElo as toCourseElo6
|
|
793
2271
|
} from "@vue-skuilder/common";
|
|
794
2272
|
function randIntWeightedTowardZero(n) {
|
|
795
2273
|
return Math.floor(Math.random() * Math.random() * Math.random() * n);
|
|
@@ -920,6 +2398,12 @@ var init_courseDB = __esm({
|
|
|
920
2398
|
init_courseAPI();
|
|
921
2399
|
init_courseLookupDB();
|
|
922
2400
|
init_navigators();
|
|
2401
|
+
init_Pipeline();
|
|
2402
|
+
init_PipelineAssembler();
|
|
2403
|
+
init_CompositeGenerator();
|
|
2404
|
+
init_elo();
|
|
2405
|
+
init_srs();
|
|
2406
|
+
init_eloDistance();
|
|
923
2407
|
CoursesDB = class {
|
|
924
2408
|
_courseIDs;
|
|
925
2409
|
constructor(courseIDs) {
|
|
@@ -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 moment2 from "moment";
|
|
1509
3050
|
function getClassroomDB(classID, version) {
|
|
1510
3051
|
const dbName = `classdb-${version}-${classID}`;
|
|
1511
3052
|
logger.info(`Retrieving classroom db: ${dbName}`);
|
|
@@ -1617,9 +3158,9 @@ var init_classroomDB2 = __esm({
|
|
|
1617
3158
|
}
|
|
1618
3159
|
async getNewCards() {
|
|
1619
3160
|
const activeCards = await this._user.getActiveCards();
|
|
1620
|
-
const now =
|
|
3161
|
+
const now = moment2.utc();
|
|
1621
3162
|
const assigned = await this.getAssignedContent();
|
|
1622
|
-
const due = assigned.filter((c) => now.isAfter(
|
|
3163
|
+
const due = assigned.filter((c) => now.isAfter(moment2.utc(c.activeOn, REVIEW_TIME_FORMAT)));
|
|
1623
3164
|
logger.info(`Due content: ${JSON.stringify(due)}`);
|
|
1624
3165
|
let ret = [];
|
|
1625
3166
|
for (let i = 0; i < due.length; i++) {
|
|
@@ -1656,6 +3197,52 @@ var init_classroomDB2 = __esm({
|
|
|
1656
3197
|
}
|
|
1657
3198
|
});
|
|
1658
3199
|
}
|
|
3200
|
+
/**
|
|
3201
|
+
* Get cards with suitability scores for presentation.
|
|
3202
|
+
*
|
|
3203
|
+
* This implementation wraps the legacy getNewCards/getPendingReviews methods,
|
|
3204
|
+
* assigning score=1.0 to all cards. StudentClassroomDB does not currently
|
|
3205
|
+
* support pluggable navigation strategies.
|
|
3206
|
+
*
|
|
3207
|
+
* @param limit - Maximum number of cards to return
|
|
3208
|
+
* @returns Cards sorted by score descending (all scores = 1.0)
|
|
3209
|
+
*/
|
|
3210
|
+
async getWeightedCards(limit) {
|
|
3211
|
+
const [newCards, reviews] = await Promise.all([this.getNewCards(), this.getPendingReviews()]);
|
|
3212
|
+
const weighted = [
|
|
3213
|
+
...newCards.map((c) => ({
|
|
3214
|
+
cardId: c.cardID,
|
|
3215
|
+
courseId: c.courseID,
|
|
3216
|
+
score: 1,
|
|
3217
|
+
provenance: [
|
|
3218
|
+
{
|
|
3219
|
+
strategy: "classroom",
|
|
3220
|
+
strategyName: "Classroom",
|
|
3221
|
+
strategyId: "CLASSROOM",
|
|
3222
|
+
action: "generated",
|
|
3223
|
+
score: 1,
|
|
3224
|
+
reason: "Classroom legacy getNewCards(), new card"
|
|
3225
|
+
}
|
|
3226
|
+
]
|
|
3227
|
+
})),
|
|
3228
|
+
...reviews.map((r) => ({
|
|
3229
|
+
cardId: r.cardID,
|
|
3230
|
+
courseId: r.courseID,
|
|
3231
|
+
score: 1,
|
|
3232
|
+
provenance: [
|
|
3233
|
+
{
|
|
3234
|
+
strategy: "classroom",
|
|
3235
|
+
strategyName: "Classroom",
|
|
3236
|
+
strategyId: "CLASSROOM",
|
|
3237
|
+
action: "generated",
|
|
3238
|
+
score: 1,
|
|
3239
|
+
reason: "Classroom legacy getPendingReviews(), review"
|
|
3240
|
+
}
|
|
3241
|
+
]
|
|
3242
|
+
}))
|
|
3243
|
+
];
|
|
3244
|
+
return weighted.slice(0, limit);
|
|
3245
|
+
}
|
|
1659
3246
|
};
|
|
1660
3247
|
TeacherClassroomDB = class _TeacherClassroomDB extends ClassroomDBBase {
|
|
1661
3248
|
_stuDb;
|
|
@@ -1712,8 +3299,8 @@ var init_classroomDB2 = __esm({
|
|
|
1712
3299
|
type: "tag",
|
|
1713
3300
|
_id: id,
|
|
1714
3301
|
assignedBy: content.assignedBy,
|
|
1715
|
-
assignedOn:
|
|
1716
|
-
activeOn: content.activeOn ||
|
|
3302
|
+
assignedOn: moment2.utc(),
|
|
3303
|
+
activeOn: content.activeOn || moment2.utc()
|
|
1717
3304
|
});
|
|
1718
3305
|
} else {
|
|
1719
3306
|
put = await this._db.put({
|
|
@@ -1721,8 +3308,8 @@ var init_classroomDB2 = __esm({
|
|
|
1721
3308
|
type: "course",
|
|
1722
3309
|
_id: id,
|
|
1723
3310
|
assignedBy: content.assignedBy,
|
|
1724
|
-
assignedOn:
|
|
1725
|
-
activeOn: content.activeOn ||
|
|
3311
|
+
assignedOn: moment2.utc(),
|
|
3312
|
+
activeOn: content.activeOn || moment2.utc()
|
|
1726
3313
|
});
|
|
1727
3314
|
}
|
|
1728
3315
|
if (put.ok) {
|
|
@@ -1741,7 +3328,215 @@ var init_classroomDB2 = __esm({
|
|
|
1741
3328
|
}
|
|
1742
3329
|
});
|
|
1743
3330
|
|
|
3331
|
+
// src/study/TagFilteredContentSource.ts
|
|
3332
|
+
import { hasActiveFilter } from "@vue-skuilder/common";
|
|
3333
|
+
var TagFilteredContentSource;
|
|
3334
|
+
var init_TagFilteredContentSource = __esm({
|
|
3335
|
+
"src/study/TagFilteredContentSource.ts"() {
|
|
3336
|
+
"use strict";
|
|
3337
|
+
init_courseDB();
|
|
3338
|
+
init_logger();
|
|
3339
|
+
TagFilteredContentSource = class {
|
|
3340
|
+
courseId;
|
|
3341
|
+
filter;
|
|
3342
|
+
user;
|
|
3343
|
+
// Cache resolved card IDs to avoid repeated lookups within a session
|
|
3344
|
+
resolvedCardIds = null;
|
|
3345
|
+
constructor(courseId, filter, user) {
|
|
3346
|
+
this.courseId = courseId;
|
|
3347
|
+
this.filter = filter;
|
|
3348
|
+
this.user = user;
|
|
3349
|
+
logger.info(
|
|
3350
|
+
`[TagFilteredContentSource] Created for course "${courseId}" with filter:`,
|
|
3351
|
+
JSON.stringify(filter)
|
|
3352
|
+
);
|
|
3353
|
+
}
|
|
3354
|
+
/**
|
|
3355
|
+
* Resolves the TagFilter to a set of eligible card IDs.
|
|
3356
|
+
*
|
|
3357
|
+
* - Cards in `include` tags are OR'd together (card needs at least one)
|
|
3358
|
+
* - Cards in `exclude` tags are removed from the result
|
|
3359
|
+
*/
|
|
3360
|
+
async resolveFilteredCardIds() {
|
|
3361
|
+
if (this.resolvedCardIds !== null) {
|
|
3362
|
+
return this.resolvedCardIds;
|
|
3363
|
+
}
|
|
3364
|
+
const includedCardIds = /* @__PURE__ */ new Set();
|
|
3365
|
+
if (this.filter.include.length > 0) {
|
|
3366
|
+
for (const tagName of this.filter.include) {
|
|
3367
|
+
try {
|
|
3368
|
+
const tagDoc = await getTag(this.courseId, tagName);
|
|
3369
|
+
tagDoc.taggedCards.forEach((cardId) => includedCardIds.add(cardId));
|
|
3370
|
+
} catch (error) {
|
|
3371
|
+
logger.warn(
|
|
3372
|
+
`[TagFilteredContentSource] Could not resolve tag "${tagName}" for inclusion:`,
|
|
3373
|
+
error
|
|
3374
|
+
);
|
|
3375
|
+
}
|
|
3376
|
+
}
|
|
3377
|
+
}
|
|
3378
|
+
if (includedCardIds.size === 0 && this.filter.include.length > 0) {
|
|
3379
|
+
logger.warn(
|
|
3380
|
+
`[TagFilteredContentSource] No cards found for include tags: ${this.filter.include.join(", ")}`
|
|
3381
|
+
);
|
|
3382
|
+
this.resolvedCardIds = /* @__PURE__ */ new Set();
|
|
3383
|
+
return this.resolvedCardIds;
|
|
3384
|
+
}
|
|
3385
|
+
const excludedCardIds = /* @__PURE__ */ new Set();
|
|
3386
|
+
if (this.filter.exclude.length > 0) {
|
|
3387
|
+
for (const tagName of this.filter.exclude) {
|
|
3388
|
+
try {
|
|
3389
|
+
const tagDoc = await getTag(this.courseId, tagName);
|
|
3390
|
+
tagDoc.taggedCards.forEach((cardId) => excludedCardIds.add(cardId));
|
|
3391
|
+
} catch (error) {
|
|
3392
|
+
logger.warn(
|
|
3393
|
+
`[TagFilteredContentSource] Could not resolve tag "${tagName}" for exclusion:`,
|
|
3394
|
+
error
|
|
3395
|
+
);
|
|
3396
|
+
}
|
|
3397
|
+
}
|
|
3398
|
+
}
|
|
3399
|
+
const finalCardIds = /* @__PURE__ */ new Set();
|
|
3400
|
+
for (const cardId of includedCardIds) {
|
|
3401
|
+
if (!excludedCardIds.has(cardId)) {
|
|
3402
|
+
finalCardIds.add(cardId);
|
|
3403
|
+
}
|
|
3404
|
+
}
|
|
3405
|
+
logger.info(
|
|
3406
|
+
`[TagFilteredContentSource] Resolved ${finalCardIds.size} cards (included: ${includedCardIds.size}, excluded: ${excludedCardIds.size})`
|
|
3407
|
+
);
|
|
3408
|
+
this.resolvedCardIds = finalCardIds;
|
|
3409
|
+
return finalCardIds;
|
|
3410
|
+
}
|
|
3411
|
+
/**
|
|
3412
|
+
* Gets new cards that match the tag filter and are not already active for the user.
|
|
3413
|
+
*/
|
|
3414
|
+
async getNewCards(limit) {
|
|
3415
|
+
if (!hasActiveFilter(this.filter)) {
|
|
3416
|
+
logger.warn("[TagFilteredContentSource] getNewCards called with no active filter");
|
|
3417
|
+
return [];
|
|
3418
|
+
}
|
|
3419
|
+
const eligibleCardIds = await this.resolveFilteredCardIds();
|
|
3420
|
+
const activeCards = await this.user.getActiveCards();
|
|
3421
|
+
const activeCardIds = new Set(activeCards.map((c) => c.cardID));
|
|
3422
|
+
const newItems = [];
|
|
3423
|
+
for (const cardId of eligibleCardIds) {
|
|
3424
|
+
if (!activeCardIds.has(cardId)) {
|
|
3425
|
+
newItems.push({
|
|
3426
|
+
courseID: this.courseId,
|
|
3427
|
+
cardID: cardId,
|
|
3428
|
+
contentSourceType: "course",
|
|
3429
|
+
contentSourceID: this.courseId,
|
|
3430
|
+
status: "new"
|
|
3431
|
+
});
|
|
3432
|
+
}
|
|
3433
|
+
if (limit !== void 0 && newItems.length >= limit) {
|
|
3434
|
+
break;
|
|
3435
|
+
}
|
|
3436
|
+
}
|
|
3437
|
+
logger.info(`[TagFilteredContentSource] Found ${newItems.length} new cards matching filter`);
|
|
3438
|
+
return newItems;
|
|
3439
|
+
}
|
|
3440
|
+
/**
|
|
3441
|
+
* Gets pending reviews, filtered to only include cards that match the tag filter.
|
|
3442
|
+
*/
|
|
3443
|
+
async getPendingReviews() {
|
|
3444
|
+
if (!hasActiveFilter(this.filter)) {
|
|
3445
|
+
logger.warn("[TagFilteredContentSource] getPendingReviews called with no active filter");
|
|
3446
|
+
return [];
|
|
3447
|
+
}
|
|
3448
|
+
const eligibleCardIds = await this.resolveFilteredCardIds();
|
|
3449
|
+
const allReviews = await this.user.getPendingReviews(this.courseId);
|
|
3450
|
+
const filteredReviews = allReviews.filter((review) => {
|
|
3451
|
+
return eligibleCardIds.has(review.cardId);
|
|
3452
|
+
});
|
|
3453
|
+
logger.info(
|
|
3454
|
+
`[TagFilteredContentSource] Found ${filteredReviews.length} pending reviews matching filter (of ${allReviews.length} total)`
|
|
3455
|
+
);
|
|
3456
|
+
return filteredReviews.map((r) => ({
|
|
3457
|
+
...r,
|
|
3458
|
+
courseID: r.courseId,
|
|
3459
|
+
cardID: r.cardId,
|
|
3460
|
+
contentSourceType: "course",
|
|
3461
|
+
contentSourceID: this.courseId,
|
|
3462
|
+
reviewID: r._id,
|
|
3463
|
+
status: "review"
|
|
3464
|
+
}));
|
|
3465
|
+
}
|
|
3466
|
+
/**
|
|
3467
|
+
* Get cards with suitability scores for presentation.
|
|
3468
|
+
*
|
|
3469
|
+
* This implementation wraps the legacy getNewCards/getPendingReviews methods,
|
|
3470
|
+
* assigning score=1.0 to all cards. TagFilteredContentSource does not currently
|
|
3471
|
+
* support pluggable navigation strategies - it returns flat-scored candidates.
|
|
3472
|
+
*
|
|
3473
|
+
* @param limit - Maximum number of cards to return
|
|
3474
|
+
* @returns Cards sorted by score descending (all scores = 1.0)
|
|
3475
|
+
*/
|
|
3476
|
+
async getWeightedCards(limit) {
|
|
3477
|
+
const [newCards, reviews] = await Promise.all([
|
|
3478
|
+
this.getNewCards(limit),
|
|
3479
|
+
this.getPendingReviews()
|
|
3480
|
+
]);
|
|
3481
|
+
const weighted = [
|
|
3482
|
+
...reviews.map((r) => ({
|
|
3483
|
+
cardId: r.cardID,
|
|
3484
|
+
courseId: r.courseID,
|
|
3485
|
+
score: 1,
|
|
3486
|
+
provenance: [
|
|
3487
|
+
{
|
|
3488
|
+
strategy: "tagFilter",
|
|
3489
|
+
strategyName: "Tag Filter",
|
|
3490
|
+
strategyId: "TAG_FILTER",
|
|
3491
|
+
action: "generated",
|
|
3492
|
+
score: 1,
|
|
3493
|
+
reason: `Tag-filtered review (tags: ${this.filter.include.join(", ")})`
|
|
3494
|
+
}
|
|
3495
|
+
]
|
|
3496
|
+
})),
|
|
3497
|
+
...newCards.map((c) => ({
|
|
3498
|
+
cardId: c.cardID,
|
|
3499
|
+
courseId: c.courseID,
|
|
3500
|
+
score: 1,
|
|
3501
|
+
provenance: [
|
|
3502
|
+
{
|
|
3503
|
+
strategy: "tagFilter",
|
|
3504
|
+
strategyName: "Tag Filter",
|
|
3505
|
+
strategyId: "TAG_FILTER",
|
|
3506
|
+
action: "generated",
|
|
3507
|
+
score: 1,
|
|
3508
|
+
reason: `Tag-filtered new card (tags: ${this.filter.include.join(", ")})`
|
|
3509
|
+
}
|
|
3510
|
+
]
|
|
3511
|
+
}))
|
|
3512
|
+
];
|
|
3513
|
+
return weighted.slice(0, limit);
|
|
3514
|
+
}
|
|
3515
|
+
/**
|
|
3516
|
+
* Clears the cached resolved card IDs.
|
|
3517
|
+
* Call this if the underlying tag data may have changed during a session.
|
|
3518
|
+
*/
|
|
3519
|
+
clearCache() {
|
|
3520
|
+
this.resolvedCardIds = null;
|
|
3521
|
+
}
|
|
3522
|
+
/**
|
|
3523
|
+
* Returns the course ID this source is filtering.
|
|
3524
|
+
*/
|
|
3525
|
+
getCourseId() {
|
|
3526
|
+
return this.courseId;
|
|
3527
|
+
}
|
|
3528
|
+
/**
|
|
3529
|
+
* Returns the active tag filter.
|
|
3530
|
+
*/
|
|
3531
|
+
getFilter() {
|
|
3532
|
+
return this.filter;
|
|
3533
|
+
}
|
|
3534
|
+
};
|
|
3535
|
+
}
|
|
3536
|
+
});
|
|
3537
|
+
|
|
1744
3538
|
// src/core/interfaces/contentSource.ts
|
|
3539
|
+
import { hasActiveFilter as hasActiveFilter2 } from "@vue-skuilder/common";
|
|
1745
3540
|
function isReview(item) {
|
|
1746
3541
|
const ret = item.status === "review" || item.status === "failed-review" || "reviewID" in item;
|
|
1747
3542
|
return ret;
|
|
@@ -1750,6 +3545,9 @@ async function getStudySource(source, user) {
|
|
|
1750
3545
|
if (source.type === "classroom") {
|
|
1751
3546
|
return await StudentClassroomDB.factory(source.id, user);
|
|
1752
3547
|
} else {
|
|
3548
|
+
if (hasActiveFilter2(source.tagFilter)) {
|
|
3549
|
+
return new TagFilteredContentSource(source.id, source.tagFilter, user);
|
|
3550
|
+
}
|
|
1753
3551
|
return getDataLayer().getCourseDB(source.id);
|
|
1754
3552
|
}
|
|
1755
3553
|
}
|
|
@@ -1758,6 +3556,7 @@ var init_contentSource = __esm({
|
|
|
1758
3556
|
"use strict";
|
|
1759
3557
|
init_factory();
|
|
1760
3558
|
init_classroomDB2();
|
|
3559
|
+
init_TagFilteredContentSource();
|
|
1761
3560
|
}
|
|
1762
3561
|
});
|
|
1763
3562
|
|
|
@@ -1823,7 +3622,7 @@ var init_cardProcessor = __esm({
|
|
|
1823
3622
|
});
|
|
1824
3623
|
|
|
1825
3624
|
// src/core/bulkImport/types.ts
|
|
1826
|
-
var
|
|
3625
|
+
var init_types3 = __esm({
|
|
1827
3626
|
"src/core/bulkImport/types.ts"() {
|
|
1828
3627
|
"use strict";
|
|
1829
3628
|
}
|
|
@@ -1834,7 +3633,7 @@ var init_bulkImport = __esm({
|
|
|
1834
3633
|
"src/core/bulkImport/index.ts"() {
|
|
1835
3634
|
"use strict";
|
|
1836
3635
|
init_cardProcessor();
|
|
1837
|
-
|
|
3636
|
+
init_types3();
|
|
1838
3637
|
}
|
|
1839
3638
|
});
|
|
1840
3639
|
|
|
@@ -1882,7 +3681,7 @@ var init_dataDirectory = __esm({
|
|
|
1882
3681
|
});
|
|
1883
3682
|
|
|
1884
3683
|
// src/impl/common/userDBHelpers.ts
|
|
1885
|
-
import
|
|
3684
|
+
import moment3 from "moment";
|
|
1886
3685
|
function hexEncode(str) {
|
|
1887
3686
|
let hex;
|
|
1888
3687
|
let returnStr = "";
|
|
@@ -1910,7 +3709,7 @@ function getStartAndEndKeys2(key) {
|
|
|
1910
3709
|
};
|
|
1911
3710
|
}
|
|
1912
3711
|
function updateGuestAccountExpirationDate(guestDB) {
|
|
1913
|
-
const currentTime =
|
|
3712
|
+
const currentTime = moment3.utc();
|
|
1914
3713
|
const expirationDate = currentTime.add(2, "months").toISOString();
|
|
1915
3714
|
const expiryDocID2 = "GuestAccountExpirationDate";
|
|
1916
3715
|
void guestDB.get(expiryDocID2).then((doc) => {
|
|
@@ -1935,7 +3734,7 @@ function getLocalUserDB(username) {
|
|
|
1935
3734
|
}
|
|
1936
3735
|
}
|
|
1937
3736
|
function scheduleCardReviewLocal(userDB, review) {
|
|
1938
|
-
const now =
|
|
3737
|
+
const now = moment3.utc();
|
|
1939
3738
|
logger.info(`Scheduling for review in: ${review.time.diff(now, "h") / 24} days`);
|
|
1940
3739
|
void userDB.put({
|
|
1941
3740
|
_id: DocTypePrefixes["SCHEDULED_CARD" /* SCHEDULED_CARD */] + review.time.format(REVIEW_TIME_FORMAT2),
|
|
@@ -1974,7 +3773,7 @@ var init_userDBHelpers = __esm({
|
|
|
1974
3773
|
});
|
|
1975
3774
|
|
|
1976
3775
|
// src/impl/couch/user-course-relDB.ts
|
|
1977
|
-
import
|
|
3776
|
+
import moment4 from "moment";
|
|
1978
3777
|
var UsrCrsData;
|
|
1979
3778
|
var init_user_course_relDB = __esm({
|
|
1980
3779
|
"src/impl/couch/user-course-relDB.ts"() {
|
|
@@ -1988,11 +3787,11 @@ var init_user_course_relDB = __esm({
|
|
|
1988
3787
|
this._courseId = courseId;
|
|
1989
3788
|
}
|
|
1990
3789
|
async getReviewsForcast(daysCount) {
|
|
1991
|
-
const time =
|
|
3790
|
+
const time = moment4.utc().add(daysCount, "days");
|
|
1992
3791
|
return this.getReviewstoDate(time);
|
|
1993
3792
|
}
|
|
1994
3793
|
async getPendingReviews() {
|
|
1995
|
-
const now =
|
|
3794
|
+
const now = moment4.utc();
|
|
1996
3795
|
return this.getReviewstoDate(now);
|
|
1997
3796
|
}
|
|
1998
3797
|
async getScheduledReviewCount() {
|
|
@@ -2019,7 +3818,7 @@ var init_user_course_relDB = __esm({
|
|
|
2019
3818
|
`Fetching ${this.user.getUsername()}'s scheduled reviews for course ${this._courseId}.`
|
|
2020
3819
|
);
|
|
2021
3820
|
return allReviews.filter((review) => {
|
|
2022
|
-
const reviewTime =
|
|
3821
|
+
const reviewTime = moment4.utc(review.reviewTime);
|
|
2023
3822
|
return targetDate.isAfter(reviewTime);
|
|
2024
3823
|
});
|
|
2025
3824
|
}
|
|
@@ -2029,7 +3828,7 @@ var init_user_course_relDB = __esm({
|
|
|
2029
3828
|
|
|
2030
3829
|
// src/impl/common/BaseUserDB.ts
|
|
2031
3830
|
import { Status as Status3 } from "@vue-skuilder/common";
|
|
2032
|
-
import
|
|
3831
|
+
import moment5 from "moment";
|
|
2033
3832
|
function accomodateGuest() {
|
|
2034
3833
|
logger.log("[funnel] accomodateGuest() called");
|
|
2035
3834
|
if (typeof localStorage === "undefined") {
|
|
@@ -2467,7 +4266,7 @@ Currently logged-in as ${this._username}.`
|
|
|
2467
4266
|
);
|
|
2468
4267
|
return reviews.rows.filter((r) => {
|
|
2469
4268
|
if (r.id.startsWith(DocTypePrefixes["SCHEDULED_CARD" /* SCHEDULED_CARD */])) {
|
|
2470
|
-
const date =
|
|
4269
|
+
const date = moment5.utc(
|
|
2471
4270
|
r.id.substr(DocTypePrefixes["SCHEDULED_CARD" /* SCHEDULED_CARD */].length),
|
|
2472
4271
|
REVIEW_TIME_FORMAT2
|
|
2473
4272
|
);
|
|
@@ -2480,11 +4279,11 @@ Currently logged-in as ${this._username}.`
|
|
|
2480
4279
|
}).map((r) => r.doc);
|
|
2481
4280
|
}
|
|
2482
4281
|
async getReviewsForcast(daysCount) {
|
|
2483
|
-
const time =
|
|
4282
|
+
const time = moment5.utc().add(daysCount, "days");
|
|
2484
4283
|
return this.getReviewstoDate(time);
|
|
2485
4284
|
}
|
|
2486
4285
|
async getPendingReviews(course_id) {
|
|
2487
|
-
const now =
|
|
4286
|
+
const now = moment5.utc();
|
|
2488
4287
|
return this.getReviewstoDate(now, course_id);
|
|
2489
4288
|
}
|
|
2490
4289
|
async getScheduledReviewCount(course_id) {
|
|
@@ -2771,7 +4570,7 @@ Currently logged-in as ${this._username}.`
|
|
|
2771
4570
|
*/
|
|
2772
4571
|
async putCardRecord(record) {
|
|
2773
4572
|
const cardHistoryID = getCardHistoryID(record.courseID, record.cardID);
|
|
2774
|
-
record.timeStamp =
|
|
4573
|
+
record.timeStamp = moment5.utc(record.timeStamp).toString();
|
|
2775
4574
|
try {
|
|
2776
4575
|
const cardHistory = await this.update(
|
|
2777
4576
|
cardHistoryID,
|
|
@@ -2787,7 +4586,7 @@ Currently logged-in as ${this._username}.`
|
|
|
2787
4586
|
const ret = {
|
|
2788
4587
|
...record2
|
|
2789
4588
|
};
|
|
2790
|
-
ret.timeStamp =
|
|
4589
|
+
ret.timeStamp = moment5.utc(record2.timeStamp);
|
|
2791
4590
|
return ret;
|
|
2792
4591
|
});
|
|
2793
4592
|
return cardHistory;
|
|
@@ -3392,7 +5191,7 @@ var init_CouchDBSyncStrategy = __esm({
|
|
|
3392
5191
|
|
|
3393
5192
|
// src/impl/couch/index.ts
|
|
3394
5193
|
import fetch2 from "cross-fetch";
|
|
3395
|
-
import
|
|
5194
|
+
import moment6 from "moment";
|
|
3396
5195
|
import process2 from "process";
|
|
3397
5196
|
function hexEncode2(str) {
|
|
3398
5197
|
let hex;
|
|
@@ -3461,7 +5260,7 @@ async function usernameIsAvailable(username) {
|
|
|
3461
5260
|
}
|
|
3462
5261
|
}
|
|
3463
5262
|
function updateGuestAccountExpirationDate2(guestDB) {
|
|
3464
|
-
const currentTime =
|
|
5263
|
+
const currentTime = moment6.utc();
|
|
3465
5264
|
const expirationDate = currentTime.add(2, "months").toISOString();
|
|
3466
5265
|
void guestDB.get(expiryDocID).then((doc) => {
|
|
3467
5266
|
return guestDB.put({
|
|
@@ -3524,7 +5323,7 @@ function getCouchUserDB(username) {
|
|
|
3524
5323
|
return ret;
|
|
3525
5324
|
}
|
|
3526
5325
|
function scheduleCardReview(review) {
|
|
3527
|
-
const now =
|
|
5326
|
+
const now = moment6.utc();
|
|
3528
5327
|
logger.info(`Scheduling for review in: ${review.time.diff(now, "h") / 24} days`);
|
|
3529
5328
|
void getCouchUserDB(review.user).put({
|
|
3530
5329
|
_id: DocTypePrefixes["SCHEDULED_CARD" /* SCHEDULED_CARD */] + review.time.format(REVIEW_TIME_FORMAT),
|