@vue-skuilder/db 0.1.17 → 0.1.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{userDB-BqwxtJ_7.d.mts → classroomDB-CZdMBiTU.d.ts} +427 -104
- package/dist/{userDB-DNa0XPtn.d.ts → classroomDB-PxDZTky3.d.cts} +427 -104
- package/dist/core/index.d.cts +304 -0
- package/dist/core/index.d.ts +237 -25
- package/dist/core/index.js +2246 -118
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.mjs +2235 -114
- package/dist/core/index.mjs.map +1 -1
- package/dist/{dataLayerProvider-VlngD19_.d.mts → dataLayerProvider-D0MoZMjH.d.cts} +1 -1
- package/dist/{dataLayerProvider-BV5iZqt_.d.ts → dataLayerProvider-D8o6ZnKW.d.ts} +1 -1
- package/dist/impl/couch/{index.d.mts → index.d.cts} +47 -5
- package/dist/impl/couch/index.d.ts +46 -4
- package/dist/impl/couch/index.js +2250 -134
- package/dist/impl/couch/index.js.map +1 -1
- package/dist/impl/couch/index.mjs +2212 -97
- package/dist/impl/couch/index.mjs.map +1 -1
- package/dist/impl/static/{index.d.mts → index.d.cts} +6 -6
- package/dist/impl/static/index.d.ts +5 -5
- package/dist/impl/static/index.js +1950 -143
- package/dist/impl/static/index.js.map +1 -1
- package/dist/impl/static/index.mjs +1922 -117
- package/dist/impl/static/index.mjs.map +1 -1
- package/dist/{index-Bmll7Xse.d.mts → index-B_j6u5E4.d.cts} +1 -1
- package/dist/{index-CD8BZz2k.d.ts → index-Dj0SEgk3.d.ts} +1 -1
- package/dist/{index.d.mts → index.d.cts} +97 -13
- package/dist/index.d.ts +96 -12
- package/dist/index.js +2439 -180
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2386 -135
- package/dist/index.mjs.map +1 -1
- package/dist/pouch/index.js +3 -3
- package/dist/{types-Dbp5DaRR.d.mts → types-Bn0itutr.d.cts} +1 -1
- package/dist/{types-CewsN87z.d.ts → types-DQaXnuoc.d.ts} +1 -1
- package/dist/{types-legacy-6ettoclI.d.ts → types-legacy-DDY4N-Uq.d.cts} +3 -1
- package/dist/{types-legacy-6ettoclI.d.mts → types-legacy-DDY4N-Uq.d.ts} +3 -1
- package/dist/util/packer/{index.d.mts → index.d.cts} +3 -3
- package/dist/util/packer/index.d.ts +3 -3
- package/dist/util/packer/index.js.map +1 -1
- package/dist/util/packer/index.mjs.map +1 -1
- package/docs/brainstorm-navigation-paradigm.md +369 -0
- package/docs/navigators-architecture.md +370 -0
- package/docs/todo-evolutionary-orchestration.md +310 -0
- package/docs/todo-nominal-tag-types.md +121 -0
- package/docs/todo-strategy-authoring.md +401 -0
- package/eslint.config.mjs +1 -1
- package/package.json +9 -4
- package/src/core/index.ts +1 -0
- package/src/core/interfaces/contentSource.ts +88 -4
- package/src/core/interfaces/courseDB.ts +13 -0
- package/src/core/interfaces/navigationStrategyManager.ts +0 -5
- package/src/core/interfaces/userDB.ts +32 -0
- package/src/core/navigators/CompositeGenerator.ts +268 -0
- package/src/core/navigators/Pipeline.ts +318 -0
- package/src/core/navigators/PipelineAssembler.ts +194 -0
- package/src/core/navigators/elo.ts +104 -15
- package/src/core/navigators/filters/eloDistance.ts +132 -0
- package/src/core/navigators/filters/index.ts +9 -0
- package/src/core/navigators/filters/types.ts +115 -0
- package/src/core/navigators/filters/userTagPreference.ts +232 -0
- package/src/core/navigators/generators/index.ts +2 -0
- package/src/core/navigators/generators/types.ts +107 -0
- package/src/core/navigators/hardcodedOrder.ts +111 -12
- package/src/core/navigators/hierarchyDefinition.ts +266 -0
- package/src/core/navigators/index.ts +404 -3
- package/src/core/navigators/inferredPreference.ts +107 -0
- package/src/core/navigators/interferenceMitigator.ts +355 -0
- package/src/core/navigators/relativePriority.ts +255 -0
- package/src/core/navigators/srs.ts +195 -0
- package/src/core/navigators/userGoal.ts +136 -0
- package/src/core/types/strategyState.ts +84 -0
- package/src/core/types/types-legacy.ts +2 -0
- package/src/impl/common/BaseUserDB.ts +74 -7
- package/src/impl/couch/adminDB.ts +1 -2
- package/src/impl/couch/classroomDB.ts +51 -0
- package/src/impl/couch/courseDB.ts +147 -49
- package/src/impl/static/courseDB.ts +11 -4
- package/src/study/SessionController.ts +149 -1
- package/src/study/TagFilteredContentSource.ts +255 -0
- package/src/study/index.ts +1 -0
- package/src/util/dataDirectory.test.ts +51 -22
- package/src/util/logger.ts +0 -1
- package/tests/core/navigators/CompositeGenerator.test.ts +455 -0
- package/tests/core/navigators/Pipeline.test.ts +406 -0
- package/tests/core/navigators/PipelineAssembler.test.ts +351 -0
- package/tests/core/navigators/SRSNavigator.test.ts +344 -0
- package/tests/core/navigators/eloDistanceFilter.test.ts +192 -0
- package/tests/core/navigators/navigators.test.ts +710 -0
- package/tsconfig.json +1 -1
- package/vitest.config.ts +29 -0
- package/dist/core/index.d.mts +0 -92
- /package/dist/{SyncStrategy-CyATpyLQ.d.mts → SyncStrategy-CyATpyLQ.d.cts} +0 -0
- /package/dist/pouch/{index.d.mts → index.d.cts} +0 -0
|
@@ -97,7 +97,8 @@ var init_types_legacy = __esm({
|
|
|
97
97
|
["QUESTION" /* QUESTIONTYPE */]: "QUESTION",
|
|
98
98
|
["VIEW" /* VIEW */]: "VIEW",
|
|
99
99
|
["PEDAGOGY" /* PEDAGOGY */]: "PEDAGOGY",
|
|
100
|
-
["NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */]: "NAVIGATION_STRATEGY"
|
|
100
|
+
["NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */]: "NAVIGATION_STRATEGY",
|
|
101
|
+
["STRATEGY_STATE" /* STRATEGY_STATE */]: "STRATEGY_STATE"
|
|
101
102
|
};
|
|
102
103
|
}
|
|
103
104
|
});
|
|
@@ -475,141 +476,1682 @@ var init_courseLookupDB = __esm({
|
|
|
475
476
|
}
|
|
476
477
|
});
|
|
477
478
|
|
|
479
|
+
// src/core/navigators/CompositeGenerator.ts
|
|
480
|
+
var CompositeGenerator_exports = {};
|
|
481
|
+
__export(CompositeGenerator_exports, {
|
|
482
|
+
AggregationMode: () => AggregationMode,
|
|
483
|
+
default: () => CompositeGenerator
|
|
484
|
+
});
|
|
485
|
+
var AggregationMode, DEFAULT_AGGREGATION_MODE, FREQUENCY_BOOST_FACTOR, CompositeGenerator;
|
|
486
|
+
var init_CompositeGenerator = __esm({
|
|
487
|
+
"src/core/navigators/CompositeGenerator.ts"() {
|
|
488
|
+
"use strict";
|
|
489
|
+
init_navigators();
|
|
490
|
+
init_logger();
|
|
491
|
+
AggregationMode = /* @__PURE__ */ ((AggregationMode2) => {
|
|
492
|
+
AggregationMode2["MAX"] = "max";
|
|
493
|
+
AggregationMode2["AVERAGE"] = "average";
|
|
494
|
+
AggregationMode2["FREQUENCY_BOOST"] = "frequencyBoost";
|
|
495
|
+
return AggregationMode2;
|
|
496
|
+
})(AggregationMode || {});
|
|
497
|
+
DEFAULT_AGGREGATION_MODE = "frequencyBoost" /* FREQUENCY_BOOST */;
|
|
498
|
+
FREQUENCY_BOOST_FACTOR = 0.1;
|
|
499
|
+
CompositeGenerator = class _CompositeGenerator extends ContentNavigator {
|
|
500
|
+
/** Human-readable name for CardGenerator interface */
|
|
501
|
+
name = "Composite Generator";
|
|
502
|
+
generators;
|
|
503
|
+
aggregationMode;
|
|
504
|
+
constructor(generators, aggregationMode = DEFAULT_AGGREGATION_MODE) {
|
|
505
|
+
super();
|
|
506
|
+
this.generators = generators;
|
|
507
|
+
this.aggregationMode = aggregationMode;
|
|
508
|
+
if (generators.length === 0) {
|
|
509
|
+
throw new Error("CompositeGenerator requires at least one generator");
|
|
510
|
+
}
|
|
511
|
+
logger.debug(
|
|
512
|
+
`[CompositeGenerator] Created with ${generators.length} generators, mode: ${aggregationMode}`
|
|
513
|
+
);
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* Creates a CompositeGenerator from strategy data.
|
|
517
|
+
*
|
|
518
|
+
* This is a convenience factory for use by PipelineAssembler.
|
|
519
|
+
*/
|
|
520
|
+
static async fromStrategies(user, course, strategies, aggregationMode = DEFAULT_AGGREGATION_MODE) {
|
|
521
|
+
const generators = await Promise.all(
|
|
522
|
+
strategies.map((s) => ContentNavigator.create(user, course, s))
|
|
523
|
+
);
|
|
524
|
+
return new _CompositeGenerator(generators, aggregationMode);
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* Get weighted cards from all generators, merge and deduplicate.
|
|
528
|
+
*
|
|
529
|
+
* Cards appearing in multiple generators receive a score boost.
|
|
530
|
+
* Provenance tracks which generators produced each card and how scores were aggregated.
|
|
531
|
+
*
|
|
532
|
+
* This method supports both the legacy signature (limit only) and the
|
|
533
|
+
* CardGenerator interface signature (limit, context).
|
|
534
|
+
*
|
|
535
|
+
* @param limit - Maximum number of cards to return
|
|
536
|
+
* @param context - Optional GeneratorContext passed to child generators
|
|
537
|
+
*/
|
|
538
|
+
async getWeightedCards(limit, context) {
|
|
539
|
+
const results = await Promise.all(
|
|
540
|
+
this.generators.map((g) => g.getWeightedCards(limit, context))
|
|
541
|
+
);
|
|
542
|
+
const byCardId = /* @__PURE__ */ new Map();
|
|
543
|
+
for (const cards of results) {
|
|
544
|
+
for (const card of cards) {
|
|
545
|
+
const existing = byCardId.get(card.cardId) || [];
|
|
546
|
+
existing.push(card);
|
|
547
|
+
byCardId.set(card.cardId, existing);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
const merged = [];
|
|
551
|
+
for (const [, cards] of byCardId) {
|
|
552
|
+
const aggregatedScore = this.aggregateScores(cards);
|
|
553
|
+
const finalScore = Math.min(1, aggregatedScore);
|
|
554
|
+
const mergedProvenance = cards.flatMap((c) => c.provenance);
|
|
555
|
+
const initialScore = cards[0].score;
|
|
556
|
+
const action = finalScore > initialScore ? "boosted" : finalScore < initialScore ? "penalized" : "passed";
|
|
557
|
+
const reason = this.buildAggregationReason(cards, finalScore);
|
|
558
|
+
merged.push({
|
|
559
|
+
...cards[0],
|
|
560
|
+
score: finalScore,
|
|
561
|
+
provenance: [
|
|
562
|
+
...mergedProvenance,
|
|
563
|
+
{
|
|
564
|
+
strategy: "composite",
|
|
565
|
+
strategyName: "Composite Generator",
|
|
566
|
+
strategyId: "COMPOSITE_GENERATOR",
|
|
567
|
+
action,
|
|
568
|
+
score: finalScore,
|
|
569
|
+
reason
|
|
570
|
+
}
|
|
571
|
+
]
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
return merged.sort((a, b) => b.score - a.score).slice(0, limit);
|
|
575
|
+
}
|
|
576
|
+
/**
|
|
577
|
+
* Build human-readable reason for score aggregation.
|
|
578
|
+
*/
|
|
579
|
+
buildAggregationReason(cards, finalScore) {
|
|
580
|
+
const count = cards.length;
|
|
581
|
+
const scores = cards.map((c) => c.score.toFixed(2)).join(", ");
|
|
582
|
+
if (count === 1) {
|
|
583
|
+
return `Single generator, score ${finalScore.toFixed(2)}`;
|
|
584
|
+
}
|
|
585
|
+
const strategies = cards.map((c) => c.provenance[0]?.strategy || "unknown").join(", ");
|
|
586
|
+
switch (this.aggregationMode) {
|
|
587
|
+
case "max" /* MAX */:
|
|
588
|
+
return `Max of ${count} generators (${strategies}): scores [${scores}] \u2192 ${finalScore.toFixed(2)}`;
|
|
589
|
+
case "average" /* AVERAGE */:
|
|
590
|
+
return `Average of ${count} generators (${strategies}): scores [${scores}] \u2192 ${finalScore.toFixed(2)}`;
|
|
591
|
+
case "frequencyBoost" /* FREQUENCY_BOOST */: {
|
|
592
|
+
const avg = cards.reduce((sum, c) => sum + c.score, 0) / count;
|
|
593
|
+
const boost = 1 + FREQUENCY_BOOST_FACTOR * (count - 1);
|
|
594
|
+
return `Frequency boost from ${count} generators (${strategies}): avg ${avg.toFixed(2)} \xD7 ${boost.toFixed(2)} \u2192 ${finalScore.toFixed(2)}`;
|
|
595
|
+
}
|
|
596
|
+
default:
|
|
597
|
+
return `Aggregated from ${count} generators: ${finalScore.toFixed(2)}`;
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
/**
|
|
601
|
+
* Aggregate scores from multiple generators for the same card.
|
|
602
|
+
*/
|
|
603
|
+
aggregateScores(cards) {
|
|
604
|
+
const scores = cards.map((c) => c.score);
|
|
605
|
+
switch (this.aggregationMode) {
|
|
606
|
+
case "max" /* MAX */:
|
|
607
|
+
return Math.max(...scores);
|
|
608
|
+
case "average" /* AVERAGE */:
|
|
609
|
+
return scores.reduce((sum, s) => sum + s, 0) / scores.length;
|
|
610
|
+
case "frequencyBoost" /* FREQUENCY_BOOST */: {
|
|
611
|
+
const avg = scores.reduce((sum, s) => sum + s, 0) / scores.length;
|
|
612
|
+
const frequencyBoost = 1 + FREQUENCY_BOOST_FACTOR * (cards.length - 1);
|
|
613
|
+
return avg * frequencyBoost;
|
|
614
|
+
}
|
|
615
|
+
default:
|
|
616
|
+
return scores[0];
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
/**
|
|
620
|
+
* Get new cards from all generators, merged and deduplicated.
|
|
621
|
+
*/
|
|
622
|
+
async getNewCards(n) {
|
|
623
|
+
const legacyGenerators = this.generators.filter(
|
|
624
|
+
(g) => g instanceof ContentNavigator
|
|
625
|
+
);
|
|
626
|
+
const results = await Promise.all(legacyGenerators.map((g) => g.getNewCards(n)));
|
|
627
|
+
const seen = /* @__PURE__ */ new Set();
|
|
628
|
+
const merged = [];
|
|
629
|
+
for (const cards of results) {
|
|
630
|
+
for (const card of cards) {
|
|
631
|
+
if (!seen.has(card.cardID)) {
|
|
632
|
+
seen.add(card.cardID);
|
|
633
|
+
merged.push(card);
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
return n ? merged.slice(0, n) : merged;
|
|
638
|
+
}
|
|
639
|
+
/**
|
|
640
|
+
* Get pending reviews from all generators, merged and deduplicated.
|
|
641
|
+
*/
|
|
642
|
+
async getPendingReviews() {
|
|
643
|
+
const legacyGenerators = this.generators.filter(
|
|
644
|
+
(g) => g instanceof ContentNavigator
|
|
645
|
+
);
|
|
646
|
+
const results = await Promise.all(legacyGenerators.map((g) => g.getPendingReviews()));
|
|
647
|
+
const seen = /* @__PURE__ */ new Set();
|
|
648
|
+
const merged = [];
|
|
649
|
+
for (const reviews of results) {
|
|
650
|
+
for (const review of reviews) {
|
|
651
|
+
if (!seen.has(review.cardID)) {
|
|
652
|
+
seen.add(review.cardID);
|
|
653
|
+
merged.push(review);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
return merged;
|
|
658
|
+
}
|
|
659
|
+
};
|
|
660
|
+
}
|
|
661
|
+
});
|
|
662
|
+
|
|
663
|
+
// src/core/navigators/Pipeline.ts
|
|
664
|
+
var Pipeline_exports = {};
|
|
665
|
+
__export(Pipeline_exports, {
|
|
666
|
+
Pipeline: () => Pipeline
|
|
667
|
+
});
|
|
668
|
+
import { toCourseElo as toCourseElo2 } from "@vue-skuilder/common";
|
|
669
|
+
function logPipelineConfig(generator, filters) {
|
|
670
|
+
const filterList = filters.length > 0 ? "\n - " + filters.map((f) => f.name).join("\n - ") : " none";
|
|
671
|
+
logger.info(
|
|
672
|
+
`[Pipeline] Configuration:
|
|
673
|
+
Generator: ${generator.name}
|
|
674
|
+
Filters:${filterList}`
|
|
675
|
+
);
|
|
676
|
+
}
|
|
677
|
+
function logTagHydration(cards, tagsByCard) {
|
|
678
|
+
const totalTags = Array.from(tagsByCard.values()).reduce((sum, tags) => sum + tags.length, 0);
|
|
679
|
+
const cardsWithTags = Array.from(tagsByCard.values()).filter((tags) => tags.length > 0).length;
|
|
680
|
+
logger.debug(
|
|
681
|
+
`[Pipeline] Tag hydration: ${cards.length} cards, ${cardsWithTags} have tags (${totalTags} total tags) - single batch query`
|
|
682
|
+
);
|
|
683
|
+
}
|
|
684
|
+
function logExecutionSummary(generatorName, generatedCount, filterCount, finalCount, topScores) {
|
|
685
|
+
const scoreDisplay = topScores.length > 0 ? topScores.map((s) => s.toFixed(2)).join(", ") : "none";
|
|
686
|
+
logger.info(
|
|
687
|
+
`[Pipeline] Execution: ${generatorName} produced ${generatedCount} \u2192 ${filterCount} filters \u2192 ${finalCount} results (top scores: ${scoreDisplay})`
|
|
688
|
+
);
|
|
689
|
+
}
|
|
690
|
+
function logCardProvenance(cards, maxCards = 3) {
|
|
691
|
+
const cardsToLog = cards.slice(0, maxCards);
|
|
692
|
+
logger.debug(`[Pipeline] Provenance for top ${cardsToLog.length} cards:`);
|
|
693
|
+
for (const card of cardsToLog) {
|
|
694
|
+
logger.debug(`[Pipeline] ${card.cardId} (final score: ${card.score.toFixed(3)}):`);
|
|
695
|
+
for (const entry of card.provenance) {
|
|
696
|
+
const scoreChange = entry.score.toFixed(3);
|
|
697
|
+
const action = entry.action.padEnd(9);
|
|
698
|
+
logger.debug(
|
|
699
|
+
`[Pipeline] ${action} ${scoreChange} - ${entry.strategyName}: ${entry.reason}`
|
|
700
|
+
);
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
var Pipeline;
|
|
705
|
+
var init_Pipeline = __esm({
|
|
706
|
+
"src/core/navigators/Pipeline.ts"() {
|
|
707
|
+
"use strict";
|
|
708
|
+
init_navigators();
|
|
709
|
+
init_logger();
|
|
710
|
+
Pipeline = class extends ContentNavigator {
|
|
711
|
+
generator;
|
|
712
|
+
filters;
|
|
713
|
+
/**
|
|
714
|
+
* Create a new pipeline.
|
|
715
|
+
*
|
|
716
|
+
* @param generator - The generator (or CompositeGenerator) that produces candidates
|
|
717
|
+
* @param filters - Filters to apply sequentially (order doesn't matter for multipliers)
|
|
718
|
+
* @param user - User database interface
|
|
719
|
+
* @param course - Course database interface
|
|
720
|
+
*/
|
|
721
|
+
constructor(generator, filters, user, course) {
|
|
722
|
+
super();
|
|
723
|
+
this.generator = generator;
|
|
724
|
+
this.filters = filters;
|
|
725
|
+
this.user = user;
|
|
726
|
+
this.course = course;
|
|
727
|
+
logPipelineConfig(generator, filters);
|
|
728
|
+
}
|
|
729
|
+
/**
|
|
730
|
+
* Get weighted cards by running generator and applying filters.
|
|
731
|
+
*
|
|
732
|
+
* 1. Build shared context (user ELO, etc.)
|
|
733
|
+
* 2. Get candidates from generator (passing context)
|
|
734
|
+
* 3. Batch hydrate tags for all candidates
|
|
735
|
+
* 4. Apply each filter sequentially
|
|
736
|
+
* 5. Remove zero-score cards
|
|
737
|
+
* 6. Sort by score descending
|
|
738
|
+
* 7. Return top N
|
|
739
|
+
*
|
|
740
|
+
* @param limit - Maximum number of cards to return
|
|
741
|
+
* @returns Cards sorted by score descending
|
|
742
|
+
*/
|
|
743
|
+
async getWeightedCards(limit) {
|
|
744
|
+
const context = await this.buildContext();
|
|
745
|
+
const overFetchMultiplier = 2 + this.filters.length * 0.5;
|
|
746
|
+
const fetchLimit = Math.ceil(limit * overFetchMultiplier);
|
|
747
|
+
logger.debug(
|
|
748
|
+
`[Pipeline] Fetching ${fetchLimit} candidates from generator '${this.generator.name}'`
|
|
749
|
+
);
|
|
750
|
+
let cards = await this.generator.getWeightedCards(fetchLimit, context);
|
|
751
|
+
const generatedCount = cards.length;
|
|
752
|
+
logger.debug(`[Pipeline] Generator returned ${generatedCount} candidates`);
|
|
753
|
+
cards = await this.hydrateTags(cards);
|
|
754
|
+
for (const filter of this.filters) {
|
|
755
|
+
const beforeCount = cards.length;
|
|
756
|
+
cards = await filter.transform(cards, context);
|
|
757
|
+
logger.debug(`[Pipeline] Filter '${filter.name}': ${beforeCount} \u2192 ${cards.length} cards`);
|
|
758
|
+
}
|
|
759
|
+
cards = cards.filter((c) => c.score > 0);
|
|
760
|
+
cards.sort((a, b) => b.score - a.score);
|
|
761
|
+
const result = cards.slice(0, limit);
|
|
762
|
+
const topScores = result.slice(0, 3).map((c) => c.score);
|
|
763
|
+
logExecutionSummary(this.generator.name, generatedCount, this.filters.length, result.length, topScores);
|
|
764
|
+
logCardProvenance(result, 3);
|
|
765
|
+
return result;
|
|
766
|
+
}
|
|
767
|
+
/**
|
|
768
|
+
* Batch hydrate tags for all cards.
|
|
769
|
+
*
|
|
770
|
+
* Fetches tags for all cards in a single database query and attaches them
|
|
771
|
+
* to the WeightedCard objects. Filters can then use card.tags instead of
|
|
772
|
+
* making individual getAppliedTags() calls.
|
|
773
|
+
*
|
|
774
|
+
* @param cards - Cards to hydrate
|
|
775
|
+
* @returns Cards with tags populated
|
|
776
|
+
*/
|
|
777
|
+
async hydrateTags(cards) {
|
|
778
|
+
if (cards.length === 0) {
|
|
779
|
+
return cards;
|
|
780
|
+
}
|
|
781
|
+
const cardIds = cards.map((c) => c.cardId);
|
|
782
|
+
const tagsByCard = await this.course.getAppliedTagsBatch(cardIds);
|
|
783
|
+
logTagHydration(cards, tagsByCard);
|
|
784
|
+
return cards.map((card) => ({
|
|
785
|
+
...card,
|
|
786
|
+
tags: tagsByCard.get(card.cardId) ?? []
|
|
787
|
+
}));
|
|
788
|
+
}
|
|
789
|
+
/**
|
|
790
|
+
* Build shared context for generator and filters.
|
|
791
|
+
*
|
|
792
|
+
* Called once per getWeightedCards() invocation.
|
|
793
|
+
* Contains data that the generator and multiple filters might need.
|
|
794
|
+
*
|
|
795
|
+
* The context satisfies both GeneratorContext and FilterContext interfaces.
|
|
796
|
+
*/
|
|
797
|
+
async buildContext() {
|
|
798
|
+
let userElo = 1e3;
|
|
799
|
+
try {
|
|
800
|
+
const courseReg = await this.user.getCourseRegDoc(this.course.getCourseID());
|
|
801
|
+
const courseElo = toCourseElo2(courseReg.elo);
|
|
802
|
+
userElo = courseElo.global.score;
|
|
803
|
+
} catch (e) {
|
|
804
|
+
logger.debug(`[Pipeline] Could not get user ELO, using default: ${e}`);
|
|
805
|
+
}
|
|
806
|
+
return {
|
|
807
|
+
user: this.user,
|
|
808
|
+
course: this.course,
|
|
809
|
+
userElo
|
|
810
|
+
};
|
|
811
|
+
}
|
|
812
|
+
// ===========================================================================
|
|
813
|
+
// Legacy StudyContentSource methods
|
|
814
|
+
// ===========================================================================
|
|
815
|
+
//
|
|
816
|
+
// These delegate to the generator for backward compatibility.
|
|
817
|
+
// Eventually SessionController will use getWeightedCards() exclusively.
|
|
818
|
+
//
|
|
819
|
+
/**
|
|
820
|
+
* Get new cards via legacy API.
|
|
821
|
+
* Delegates to the generator if it supports the legacy interface.
|
|
822
|
+
*/
|
|
823
|
+
async getNewCards(n) {
|
|
824
|
+
if ("getNewCards" in this.generator && typeof this.generator.getNewCards === "function") {
|
|
825
|
+
return this.generator.getNewCards(n);
|
|
826
|
+
}
|
|
827
|
+
return [];
|
|
828
|
+
}
|
|
829
|
+
/**
|
|
830
|
+
* Get pending reviews via legacy API.
|
|
831
|
+
* Delegates to the generator if it supports the legacy interface.
|
|
832
|
+
*/
|
|
833
|
+
async getPendingReviews() {
|
|
834
|
+
if ("getPendingReviews" in this.generator && typeof this.generator.getPendingReviews === "function") {
|
|
835
|
+
return this.generator.getPendingReviews();
|
|
836
|
+
}
|
|
837
|
+
return [];
|
|
838
|
+
}
|
|
839
|
+
/**
|
|
840
|
+
* Get the course ID for this pipeline.
|
|
841
|
+
*/
|
|
842
|
+
getCourseID() {
|
|
843
|
+
return this.course.getCourseID();
|
|
844
|
+
}
|
|
845
|
+
};
|
|
846
|
+
}
|
|
847
|
+
});
|
|
848
|
+
|
|
849
|
+
// src/core/navigators/PipelineAssembler.ts
|
|
850
|
+
var PipelineAssembler_exports = {};
|
|
851
|
+
__export(PipelineAssembler_exports, {
|
|
852
|
+
PipelineAssembler: () => PipelineAssembler
|
|
853
|
+
});
|
|
854
|
+
var PipelineAssembler;
|
|
855
|
+
var init_PipelineAssembler = __esm({
|
|
856
|
+
"src/core/navigators/PipelineAssembler.ts"() {
|
|
857
|
+
"use strict";
|
|
858
|
+
init_navigators();
|
|
859
|
+
init_Pipeline();
|
|
860
|
+
init_types_legacy();
|
|
861
|
+
init_logger();
|
|
862
|
+
init_CompositeGenerator();
|
|
863
|
+
PipelineAssembler = class {
|
|
864
|
+
/**
|
|
865
|
+
* Assembles a navigation pipeline from strategy documents.
|
|
866
|
+
*
|
|
867
|
+
* 1. Separates into generators and filters by role
|
|
868
|
+
* 2. Validates at least one generator exists (or creates default ELO)
|
|
869
|
+
* 3. Instantiates generators - wraps multiple in CompositeGenerator
|
|
870
|
+
* 4. Instantiates filters
|
|
871
|
+
* 5. Returns Pipeline(generator, filters)
|
|
872
|
+
*
|
|
873
|
+
* @param input - Strategy documents plus user/course interfaces
|
|
874
|
+
* @returns Assembled pipeline and any warnings
|
|
875
|
+
*/
|
|
876
|
+
async assemble(input) {
|
|
877
|
+
const { strategies, user, course } = input;
|
|
878
|
+
const warnings = [];
|
|
879
|
+
if (strategies.length === 0) {
|
|
880
|
+
return {
|
|
881
|
+
pipeline: null,
|
|
882
|
+
generatorStrategies: [],
|
|
883
|
+
filterStrategies: [],
|
|
884
|
+
warnings
|
|
885
|
+
};
|
|
886
|
+
}
|
|
887
|
+
const generatorStrategies = [];
|
|
888
|
+
const filterStrategies = [];
|
|
889
|
+
for (const s of strategies) {
|
|
890
|
+
if (isGenerator(s.implementingClass)) {
|
|
891
|
+
generatorStrategies.push(s);
|
|
892
|
+
} else if (isFilter(s.implementingClass)) {
|
|
893
|
+
filterStrategies.push(s);
|
|
894
|
+
} else {
|
|
895
|
+
warnings.push(`Unknown strategy type '${s.implementingClass}', skipping: ${s.name}`);
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
if (generatorStrategies.length === 0) {
|
|
899
|
+
if (filterStrategies.length > 0) {
|
|
900
|
+
logger.debug(
|
|
901
|
+
"[PipelineAssembler] No generator found, using default ELO with configured filters"
|
|
902
|
+
);
|
|
903
|
+
generatorStrategies.push(this.makeDefaultEloStrategy(course.getCourseID()));
|
|
904
|
+
} else {
|
|
905
|
+
warnings.push("No generator strategy found");
|
|
906
|
+
return {
|
|
907
|
+
pipeline: null,
|
|
908
|
+
generatorStrategies: [],
|
|
909
|
+
filterStrategies: [],
|
|
910
|
+
warnings
|
|
911
|
+
};
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
let generator;
|
|
915
|
+
if (generatorStrategies.length === 1) {
|
|
916
|
+
const nav = await ContentNavigator.create(user, course, generatorStrategies[0]);
|
|
917
|
+
generator = nav;
|
|
918
|
+
logger.debug(`[PipelineAssembler] Using single generator: ${generatorStrategies[0].name}`);
|
|
919
|
+
} else {
|
|
920
|
+
logger.debug(
|
|
921
|
+
`[PipelineAssembler] Using CompositeGenerator for ${generatorStrategies.length} generators: ${generatorStrategies.map((g) => g.name).join(", ")}`
|
|
922
|
+
);
|
|
923
|
+
generator = await CompositeGenerator.fromStrategies(user, course, generatorStrategies);
|
|
924
|
+
}
|
|
925
|
+
const filters = [];
|
|
926
|
+
const sortedFilterStrategies = [...filterStrategies].sort(
|
|
927
|
+
(a, b) => a.name.localeCompare(b.name)
|
|
928
|
+
);
|
|
929
|
+
for (const filterStrategy of sortedFilterStrategies) {
|
|
930
|
+
try {
|
|
931
|
+
const nav = await ContentNavigator.create(user, course, filterStrategy);
|
|
932
|
+
if ("transform" in nav && typeof nav.transform === "function") {
|
|
933
|
+
filters.push(nav);
|
|
934
|
+
logger.debug(`[PipelineAssembler] Added filter: ${filterStrategy.name}`);
|
|
935
|
+
} else {
|
|
936
|
+
warnings.push(
|
|
937
|
+
`Filter '${filterStrategy.name}' does not implement CardFilter.transform(), skipping`
|
|
938
|
+
);
|
|
939
|
+
}
|
|
940
|
+
} catch (e) {
|
|
941
|
+
warnings.push(`Failed to instantiate filter '${filterStrategy.name}': ${e}`);
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
const pipeline = new Pipeline(generator, filters, user, course);
|
|
945
|
+
logger.debug(
|
|
946
|
+
`[PipelineAssembler] Assembled pipeline with ${generatorStrategies.length} generator(s) and ${filters.length} filter(s)`
|
|
947
|
+
);
|
|
948
|
+
return {
|
|
949
|
+
pipeline,
|
|
950
|
+
generatorStrategies,
|
|
951
|
+
filterStrategies: sortedFilterStrategies,
|
|
952
|
+
warnings
|
|
953
|
+
};
|
|
954
|
+
}
|
|
955
|
+
/**
|
|
956
|
+
* Creates a default ELO generator strategy.
|
|
957
|
+
* Used when filters are configured but no generator is specified.
|
|
958
|
+
*/
|
|
959
|
+
makeDefaultEloStrategy(courseId) {
|
|
960
|
+
return {
|
|
961
|
+
_id: "NAVIGATION_STRATEGY-ELO-default",
|
|
962
|
+
course: courseId,
|
|
963
|
+
docType: "NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */,
|
|
964
|
+
name: "ELO (default)",
|
|
965
|
+
description: "Default ELO-based generator",
|
|
966
|
+
implementingClass: "elo" /* ELO */,
|
|
967
|
+
serializedData: ""
|
|
968
|
+
};
|
|
969
|
+
}
|
|
970
|
+
};
|
|
971
|
+
}
|
|
972
|
+
});
|
|
973
|
+
|
|
478
974
|
// src/core/navigators/elo.ts
|
|
479
975
|
var elo_exports = {};
|
|
480
976
|
__export(elo_exports, {
|
|
481
977
|
default: () => ELONavigator
|
|
482
978
|
});
|
|
483
|
-
|
|
484
|
-
var
|
|
485
|
-
|
|
979
|
+
import { toCourseElo as toCourseElo3 } from "@vue-skuilder/common";
|
|
980
|
+
var ELONavigator;
|
|
981
|
+
var init_elo = __esm({
|
|
982
|
+
"src/core/navigators/elo.ts"() {
|
|
983
|
+
"use strict";
|
|
984
|
+
init_navigators();
|
|
985
|
+
ELONavigator = class extends ContentNavigator {
|
|
986
|
+
/** Human-readable name for CardGenerator interface */
|
|
987
|
+
name;
|
|
988
|
+
constructor(user, course, strategyData) {
|
|
989
|
+
super(user, course, strategyData);
|
|
990
|
+
this.name = strategyData?.name || "ELO";
|
|
991
|
+
}
|
|
992
|
+
async getPendingReviews() {
|
|
993
|
+
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
994
|
+
const elo = await this.course.getCardEloData(reviews.map((r) => r.cardId));
|
|
995
|
+
const ratedReviews = reviews.map((r, i) => {
|
|
996
|
+
const ratedR = {
|
|
997
|
+
...r,
|
|
998
|
+
...elo[i]
|
|
999
|
+
};
|
|
1000
|
+
return ratedR;
|
|
1001
|
+
});
|
|
1002
|
+
ratedReviews.sort((a, b) => {
|
|
1003
|
+
return a.global.score - b.global.score;
|
|
1004
|
+
});
|
|
1005
|
+
return ratedReviews.map((r) => {
|
|
1006
|
+
return {
|
|
1007
|
+
...r,
|
|
1008
|
+
contentSourceType: "course",
|
|
1009
|
+
contentSourceID: this.course.getCourseID(),
|
|
1010
|
+
cardID: r.cardId,
|
|
1011
|
+
courseID: r.courseId,
|
|
1012
|
+
qualifiedID: `${r.courseId}-${r.cardId}`,
|
|
1013
|
+
reviewID: r._id,
|
|
1014
|
+
status: "review"
|
|
1015
|
+
};
|
|
1016
|
+
});
|
|
1017
|
+
}
|
|
1018
|
+
async getNewCards(limit = 99) {
|
|
1019
|
+
const activeCards = await this.user.getActiveCards();
|
|
1020
|
+
return (await this.course.getCardsCenteredAtELO(
|
|
1021
|
+
{ limit, elo: "user" },
|
|
1022
|
+
(c) => {
|
|
1023
|
+
if (activeCards.some((ac) => c.cardID === ac.cardID)) {
|
|
1024
|
+
return false;
|
|
1025
|
+
} else {
|
|
1026
|
+
return true;
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
)).map((c) => {
|
|
1030
|
+
return {
|
|
1031
|
+
...c,
|
|
1032
|
+
status: "new"
|
|
1033
|
+
};
|
|
1034
|
+
});
|
|
1035
|
+
}
|
|
1036
|
+
/**
|
|
1037
|
+
* Get new cards with suitability scores based on ELO distance.
|
|
1038
|
+
*
|
|
1039
|
+
* Cards closer to user's ELO get higher scores.
|
|
1040
|
+
* Score formula: max(0, 1 - distance / 500)
|
|
1041
|
+
*
|
|
1042
|
+
* NOTE: This generator only handles NEW cards. Reviews are handled by
|
|
1043
|
+
* SRSNavigator. Use CompositeGenerator to combine both.
|
|
1044
|
+
*
|
|
1045
|
+
* This method supports both the legacy signature (limit only) and the
|
|
1046
|
+
* CardGenerator interface signature (limit, context).
|
|
1047
|
+
*
|
|
1048
|
+
* @param limit - Maximum number of cards to return
|
|
1049
|
+
* @param context - Optional GeneratorContext (used when called via Pipeline)
|
|
1050
|
+
*/
|
|
1051
|
+
async getWeightedCards(limit, context) {
|
|
1052
|
+
let userGlobalElo;
|
|
1053
|
+
if (context?.userElo !== void 0) {
|
|
1054
|
+
userGlobalElo = context.userElo;
|
|
1055
|
+
} else {
|
|
1056
|
+
const courseReg = await this.user.getCourseRegDoc(this.course.getCourseID());
|
|
1057
|
+
const userElo = toCourseElo3(courseReg.elo);
|
|
1058
|
+
userGlobalElo = userElo.global.score;
|
|
1059
|
+
}
|
|
1060
|
+
const newCards = await this.getNewCards(limit);
|
|
1061
|
+
const cardIds = newCards.map((c) => c.cardID);
|
|
1062
|
+
const cardEloData = await this.course.getCardEloData(cardIds);
|
|
1063
|
+
const scored = newCards.map((c, i) => {
|
|
1064
|
+
const cardElo = cardEloData[i]?.global?.score ?? 1e3;
|
|
1065
|
+
const distance = Math.abs(cardElo - userGlobalElo);
|
|
1066
|
+
const score = Math.max(0, 1 - distance / 500);
|
|
1067
|
+
return {
|
|
1068
|
+
cardId: c.cardID,
|
|
1069
|
+
courseId: c.courseID,
|
|
1070
|
+
score,
|
|
1071
|
+
provenance: [
|
|
1072
|
+
{
|
|
1073
|
+
strategy: "elo",
|
|
1074
|
+
strategyName: this.strategyName || this.name,
|
|
1075
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-ELO-default",
|
|
1076
|
+
action: "generated",
|
|
1077
|
+
score,
|
|
1078
|
+
reason: `ELO distance ${Math.round(distance)} (card: ${Math.round(cardElo)}, user: ${Math.round(userGlobalElo)}), new card`
|
|
1079
|
+
}
|
|
1080
|
+
]
|
|
1081
|
+
};
|
|
1082
|
+
});
|
|
1083
|
+
scored.sort((a, b) => b.score - a.score);
|
|
1084
|
+
return scored.slice(0, limit);
|
|
1085
|
+
}
|
|
1086
|
+
};
|
|
1087
|
+
}
|
|
1088
|
+
});
|
|
1089
|
+
|
|
1090
|
+
// src/core/navigators/filters/eloDistance.ts
|
|
1091
|
+
var eloDistance_exports = {};
|
|
1092
|
+
__export(eloDistance_exports, {
|
|
1093
|
+
DEFAULT_HALF_LIFE: () => DEFAULT_HALF_LIFE,
|
|
1094
|
+
DEFAULT_MAX_MULTIPLIER: () => DEFAULT_MAX_MULTIPLIER,
|
|
1095
|
+
DEFAULT_MIN_MULTIPLIER: () => DEFAULT_MIN_MULTIPLIER,
|
|
1096
|
+
createEloDistanceFilter: () => createEloDistanceFilter
|
|
1097
|
+
});
|
|
1098
|
+
function computeMultiplier(distance, halfLife, minMultiplier, maxMultiplier) {
|
|
1099
|
+
const normalizedDistance = distance / halfLife;
|
|
1100
|
+
const decay = Math.exp(-(normalizedDistance * normalizedDistance));
|
|
1101
|
+
return minMultiplier + (maxMultiplier - minMultiplier) * decay;
|
|
1102
|
+
}
|
|
1103
|
+
function createEloDistanceFilter(config) {
|
|
1104
|
+
const halfLife = config?.halfLife ?? DEFAULT_HALF_LIFE;
|
|
1105
|
+
const minMultiplier = config?.minMultiplier ?? DEFAULT_MIN_MULTIPLIER;
|
|
1106
|
+
const maxMultiplier = config?.maxMultiplier ?? DEFAULT_MAX_MULTIPLIER;
|
|
1107
|
+
return {
|
|
1108
|
+
name: "ELO Distance Filter",
|
|
1109
|
+
async transform(cards, context) {
|
|
1110
|
+
const { course, userElo } = context;
|
|
1111
|
+
const cardIds = cards.map((c) => c.cardId);
|
|
1112
|
+
const cardElos = await course.getCardEloData(cardIds);
|
|
1113
|
+
return cards.map((card, i) => {
|
|
1114
|
+
const cardElo = cardElos[i]?.global?.score ?? 1e3;
|
|
1115
|
+
const distance = Math.abs(cardElo - userElo);
|
|
1116
|
+
const multiplier = computeMultiplier(distance, halfLife, minMultiplier, maxMultiplier);
|
|
1117
|
+
const newScore = card.score * multiplier;
|
|
1118
|
+
const action = multiplier < maxMultiplier - 0.01 ? "penalized" : "passed";
|
|
1119
|
+
return {
|
|
1120
|
+
...card,
|
|
1121
|
+
score: newScore,
|
|
1122
|
+
provenance: [
|
|
1123
|
+
...card.provenance,
|
|
1124
|
+
{
|
|
1125
|
+
strategy: "eloDistance",
|
|
1126
|
+
strategyName: "ELO Distance Filter",
|
|
1127
|
+
strategyId: "ELO_DISTANCE_FILTER",
|
|
1128
|
+
action,
|
|
1129
|
+
score: newScore,
|
|
1130
|
+
reason: `ELO distance ${Math.round(distance)} (card: ${Math.round(cardElo)}, user: ${Math.round(userElo)}) \u2192 ${multiplier.toFixed(2)}x`
|
|
1131
|
+
}
|
|
1132
|
+
]
|
|
1133
|
+
};
|
|
1134
|
+
});
|
|
1135
|
+
}
|
|
1136
|
+
};
|
|
1137
|
+
}
|
|
1138
|
+
var DEFAULT_HALF_LIFE, DEFAULT_MIN_MULTIPLIER, DEFAULT_MAX_MULTIPLIER;
|
|
1139
|
+
var init_eloDistance = __esm({
|
|
1140
|
+
"src/core/navigators/filters/eloDistance.ts"() {
|
|
1141
|
+
"use strict";
|
|
1142
|
+
DEFAULT_HALF_LIFE = 200;
|
|
1143
|
+
DEFAULT_MIN_MULTIPLIER = 0.3;
|
|
1144
|
+
DEFAULT_MAX_MULTIPLIER = 1;
|
|
1145
|
+
}
|
|
1146
|
+
});
|
|
1147
|
+
|
|
1148
|
+
// src/core/navigators/filters/userTagPreference.ts
|
|
1149
|
+
var userTagPreference_exports = {};
|
|
1150
|
+
__export(userTagPreference_exports, {
|
|
1151
|
+
default: () => UserTagPreferenceFilter
|
|
1152
|
+
});
|
|
1153
|
+
var UserTagPreferenceFilter;
|
|
1154
|
+
var init_userTagPreference = __esm({
|
|
1155
|
+
"src/core/navigators/filters/userTagPreference.ts"() {
|
|
1156
|
+
"use strict";
|
|
1157
|
+
init_navigators();
|
|
1158
|
+
UserTagPreferenceFilter = class extends ContentNavigator {
|
|
1159
|
+
_strategyData;
|
|
1160
|
+
/** Human-readable name for CardFilter interface */
|
|
1161
|
+
name;
|
|
1162
|
+
constructor(user, course, strategyData) {
|
|
1163
|
+
super(user, course, strategyData);
|
|
1164
|
+
this._strategyData = strategyData;
|
|
1165
|
+
this.name = strategyData.name || "User Tag Preferences";
|
|
1166
|
+
}
|
|
1167
|
+
/**
|
|
1168
|
+
* Compute multiplier for a card based on its tags and user preferences.
|
|
1169
|
+
* Returns the maximum multiplier among all matching tags, or 1.0 if no matches.
|
|
1170
|
+
*/
|
|
1171
|
+
computeMultiplier(cardTags, boostMap) {
|
|
1172
|
+
const multipliers = cardTags.map((tag) => boostMap[tag]).filter((val) => val !== void 0);
|
|
1173
|
+
if (multipliers.length === 0) {
|
|
1174
|
+
return 1;
|
|
1175
|
+
}
|
|
1176
|
+
return Math.max(...multipliers);
|
|
1177
|
+
}
|
|
1178
|
+
/**
|
|
1179
|
+
* Build human-readable reason for the filter's decision.
|
|
1180
|
+
*/
|
|
1181
|
+
buildReason(cardTags, boostMap, multiplier) {
|
|
1182
|
+
const matchingTags = cardTags.filter((tag) => boostMap[tag] === multiplier);
|
|
1183
|
+
if (multiplier === 0) {
|
|
1184
|
+
return `Excluded by user preference: ${matchingTags.join(", ")} (${multiplier}x)`;
|
|
1185
|
+
}
|
|
1186
|
+
if (multiplier < 1) {
|
|
1187
|
+
return `Penalized by user preference: ${matchingTags.join(", ")} (${multiplier.toFixed(2)}x)`;
|
|
1188
|
+
}
|
|
1189
|
+
if (multiplier > 1) {
|
|
1190
|
+
return `Boosted by user preference: ${matchingTags.join(", ")} (${multiplier.toFixed(2)}x)`;
|
|
1191
|
+
}
|
|
1192
|
+
return "No matching user preferences";
|
|
1193
|
+
}
|
|
1194
|
+
/**
|
|
1195
|
+
* CardFilter.transform implementation.
|
|
1196
|
+
*
|
|
1197
|
+
* Apply user tag preferences:
|
|
1198
|
+
* 1. Read preferences from strategy state
|
|
1199
|
+
* 2. If no preferences, pass through unchanged
|
|
1200
|
+
* 3. For each card:
|
|
1201
|
+
* - Look up tag in boost record
|
|
1202
|
+
* - If tag found: apply multiplier (0 = exclude, 1 = neutral, >1 = boost)
|
|
1203
|
+
* - If multiple tags match: use max multiplier
|
|
1204
|
+
* - Append provenance with clear reason
|
|
1205
|
+
*/
|
|
1206
|
+
async transform(cards, _context) {
|
|
1207
|
+
const prefs = await this.getStrategyState();
|
|
1208
|
+
if (!prefs || Object.keys(prefs.boost).length === 0) {
|
|
1209
|
+
return cards.map((card) => ({
|
|
1210
|
+
...card,
|
|
1211
|
+
provenance: [
|
|
1212
|
+
...card.provenance,
|
|
1213
|
+
{
|
|
1214
|
+
strategy: "userTagPreference",
|
|
1215
|
+
strategyName: this.strategyName || this.name,
|
|
1216
|
+
strategyId: this.strategyId || this._strategyData._id,
|
|
1217
|
+
action: "passed",
|
|
1218
|
+
score: card.score,
|
|
1219
|
+
reason: "No user tag preferences configured"
|
|
1220
|
+
}
|
|
1221
|
+
]
|
|
1222
|
+
}));
|
|
1223
|
+
}
|
|
1224
|
+
const adjusted = await Promise.all(
|
|
1225
|
+
cards.map(async (card) => {
|
|
1226
|
+
const cardTags = card.tags ?? [];
|
|
1227
|
+
const multiplier = this.computeMultiplier(cardTags, prefs.boost);
|
|
1228
|
+
const finalScore = Math.min(1, card.score * multiplier);
|
|
1229
|
+
let action;
|
|
1230
|
+
if (multiplier === 0 || multiplier < 1) {
|
|
1231
|
+
action = "penalized";
|
|
1232
|
+
} else if (multiplier > 1) {
|
|
1233
|
+
action = "boosted";
|
|
1234
|
+
} else {
|
|
1235
|
+
action = "passed";
|
|
1236
|
+
}
|
|
1237
|
+
return {
|
|
1238
|
+
...card,
|
|
1239
|
+
score: finalScore,
|
|
1240
|
+
provenance: [
|
|
1241
|
+
...card.provenance,
|
|
1242
|
+
{
|
|
1243
|
+
strategy: "userTagPreference",
|
|
1244
|
+
strategyName: this.strategyName || this.name,
|
|
1245
|
+
strategyId: this.strategyId || this._strategyData._id,
|
|
1246
|
+
action,
|
|
1247
|
+
score: finalScore,
|
|
1248
|
+
reason: this.buildReason(cardTags, prefs.boost, multiplier)
|
|
1249
|
+
}
|
|
1250
|
+
]
|
|
1251
|
+
};
|
|
1252
|
+
})
|
|
1253
|
+
);
|
|
1254
|
+
return adjusted;
|
|
1255
|
+
}
|
|
1256
|
+
/**
|
|
1257
|
+
* Legacy getWeightedCards - throws as filters should not be used as generators.
|
|
1258
|
+
*/
|
|
1259
|
+
async getWeightedCards(_limit) {
|
|
1260
|
+
throw new Error(
|
|
1261
|
+
"UserTagPreferenceFilter is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
|
|
1262
|
+
);
|
|
1263
|
+
}
|
|
1264
|
+
// Legacy methods - stub implementations since filters don't generate cards
|
|
1265
|
+
async getNewCards(_n) {
|
|
1266
|
+
return [];
|
|
1267
|
+
}
|
|
1268
|
+
async getPendingReviews() {
|
|
1269
|
+
return [];
|
|
1270
|
+
}
|
|
1271
|
+
};
|
|
1272
|
+
}
|
|
1273
|
+
});
|
|
1274
|
+
|
|
1275
|
+
// src/core/navigators/filters/index.ts
|
|
1276
|
+
var filters_exports = {};
|
|
1277
|
+
__export(filters_exports, {
|
|
1278
|
+
UserTagPreferenceFilter: () => UserTagPreferenceFilter,
|
|
1279
|
+
createEloDistanceFilter: () => createEloDistanceFilter
|
|
1280
|
+
});
|
|
1281
|
+
var init_filters = __esm({
|
|
1282
|
+
"src/core/navigators/filters/index.ts"() {
|
|
1283
|
+
"use strict";
|
|
1284
|
+
init_eloDistance();
|
|
1285
|
+
init_userTagPreference();
|
|
1286
|
+
}
|
|
1287
|
+
});
|
|
1288
|
+
|
|
1289
|
+
// src/core/navigators/filters/types.ts
|
|
1290
|
+
var types_exports = {};
|
|
1291
|
+
var init_types = __esm({
|
|
1292
|
+
"src/core/navigators/filters/types.ts"() {
|
|
1293
|
+
"use strict";
|
|
1294
|
+
}
|
|
1295
|
+
});
|
|
1296
|
+
|
|
1297
|
+
// src/core/navigators/generators/index.ts
|
|
1298
|
+
var generators_exports = {};
|
|
1299
|
+
var init_generators = __esm({
|
|
1300
|
+
"src/core/navigators/generators/index.ts"() {
|
|
1301
|
+
"use strict";
|
|
1302
|
+
}
|
|
1303
|
+
});
|
|
1304
|
+
|
|
1305
|
+
// src/core/navigators/generators/types.ts
|
|
1306
|
+
var types_exports2 = {};
|
|
1307
|
+
var init_types2 = __esm({
|
|
1308
|
+
"src/core/navigators/generators/types.ts"() {
|
|
1309
|
+
"use strict";
|
|
1310
|
+
}
|
|
1311
|
+
});
|
|
1312
|
+
|
|
1313
|
+
// src/core/navigators/hardcodedOrder.ts
|
|
1314
|
+
var hardcodedOrder_exports = {};
|
|
1315
|
+
__export(hardcodedOrder_exports, {
|
|
1316
|
+
default: () => HardcodedOrderNavigator
|
|
1317
|
+
});
|
|
1318
|
+
var HardcodedOrderNavigator;
|
|
1319
|
+
var init_hardcodedOrder = __esm({
|
|
1320
|
+
"src/core/navigators/hardcodedOrder.ts"() {
|
|
1321
|
+
"use strict";
|
|
1322
|
+
init_navigators();
|
|
1323
|
+
init_logger();
|
|
1324
|
+
HardcodedOrderNavigator = class extends ContentNavigator {
|
|
1325
|
+
/** Human-readable name for CardGenerator interface */
|
|
1326
|
+
name;
|
|
1327
|
+
orderedCardIds = [];
|
|
1328
|
+
constructor(user, course, strategyData) {
|
|
1329
|
+
super(user, course, strategyData);
|
|
1330
|
+
this.name = strategyData.name || "Hardcoded Order";
|
|
1331
|
+
if (strategyData.serializedData) {
|
|
1332
|
+
try {
|
|
1333
|
+
this.orderedCardIds = JSON.parse(strategyData.serializedData);
|
|
1334
|
+
} catch (e) {
|
|
1335
|
+
logger.error("Failed to parse serializedData for HardcodedOrderNavigator", e);
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
async getPendingReviews() {
|
|
1340
|
+
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
1341
|
+
return reviews.map((r) => {
|
|
1342
|
+
return {
|
|
1343
|
+
...r,
|
|
1344
|
+
contentSourceType: "course",
|
|
1345
|
+
contentSourceID: this.course.getCourseID(),
|
|
1346
|
+
cardID: r.cardId,
|
|
1347
|
+
courseID: r.courseId,
|
|
1348
|
+
reviewID: r._id,
|
|
1349
|
+
status: "review"
|
|
1350
|
+
};
|
|
1351
|
+
});
|
|
1352
|
+
}
|
|
1353
|
+
async getNewCards(limit = 99) {
|
|
1354
|
+
const activeCardIds = (await this.user.getActiveCards()).map((c) => c.cardID);
|
|
1355
|
+
const newCardIds = this.orderedCardIds.filter((cardId) => !activeCardIds.includes(cardId));
|
|
1356
|
+
const cardsToReturn = newCardIds.slice(0, limit);
|
|
1357
|
+
return cardsToReturn.map((cardId) => {
|
|
1358
|
+
return {
|
|
1359
|
+
cardID: cardId,
|
|
1360
|
+
courseID: this.course.getCourseID(),
|
|
1361
|
+
contentSourceType: "course",
|
|
1362
|
+
contentSourceID: this.course.getCourseID(),
|
|
1363
|
+
status: "new"
|
|
1364
|
+
};
|
|
1365
|
+
});
|
|
1366
|
+
}
|
|
1367
|
+
/**
|
|
1368
|
+
* Get cards in hardcoded order with scores based on position.
|
|
1369
|
+
*
|
|
1370
|
+
* Earlier cards in the sequence get higher scores.
|
|
1371
|
+
* Score formula: 1.0 - (position / totalCards) * 0.5
|
|
1372
|
+
* This ensures scores range from 1.0 (first card) to 0.5+ (last card).
|
|
1373
|
+
*
|
|
1374
|
+
* This method supports both the legacy signature (limit only) and the
|
|
1375
|
+
* CardGenerator interface signature (limit, context).
|
|
1376
|
+
*
|
|
1377
|
+
* @param limit - Maximum number of cards to return
|
|
1378
|
+
* @param _context - Optional GeneratorContext (currently unused, but required for interface)
|
|
1379
|
+
*/
|
|
1380
|
+
async getWeightedCards(limit, _context) {
|
|
1381
|
+
const activeCardIds = (await this.user.getActiveCards()).map((c) => c.cardID);
|
|
1382
|
+
const reviews = await this.getPendingReviews();
|
|
1383
|
+
const newCardIds = this.orderedCardIds.filter((cardId) => !activeCardIds.includes(cardId));
|
|
1384
|
+
const totalCards = newCardIds.length;
|
|
1385
|
+
const scoredNew = newCardIds.slice(0, limit).map((cardId, index) => {
|
|
1386
|
+
const position = index + 1;
|
|
1387
|
+
const score = Math.max(0.5, 1 - index / totalCards * 0.5);
|
|
1388
|
+
return {
|
|
1389
|
+
cardId,
|
|
1390
|
+
courseId: this.course.getCourseID(),
|
|
1391
|
+
score,
|
|
1392
|
+
provenance: [
|
|
1393
|
+
{
|
|
1394
|
+
strategy: "hardcodedOrder",
|
|
1395
|
+
strategyName: this.strategyName || this.name,
|
|
1396
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-hardcoded",
|
|
1397
|
+
action: "generated",
|
|
1398
|
+
score,
|
|
1399
|
+
reason: `Position ${position} of ${totalCards} in fixed sequence, new card`
|
|
1400
|
+
}
|
|
1401
|
+
]
|
|
1402
|
+
};
|
|
1403
|
+
});
|
|
1404
|
+
const scoredReviews = reviews.map((r) => ({
|
|
1405
|
+
cardId: r.cardID,
|
|
1406
|
+
courseId: r.courseID,
|
|
1407
|
+
score: 1,
|
|
1408
|
+
provenance: [
|
|
1409
|
+
{
|
|
1410
|
+
strategy: "hardcodedOrder",
|
|
1411
|
+
strategyName: this.strategyName || this.name,
|
|
1412
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-hardcoded",
|
|
1413
|
+
action: "generated",
|
|
1414
|
+
score: 1,
|
|
1415
|
+
reason: "Scheduled review, highest priority"
|
|
1416
|
+
}
|
|
1417
|
+
]
|
|
1418
|
+
}));
|
|
1419
|
+
const all = [...scoredReviews, ...scoredNew];
|
|
1420
|
+
all.sort((a, b) => b.score - a.score);
|
|
1421
|
+
return all.slice(0, limit);
|
|
1422
|
+
}
|
|
1423
|
+
};
|
|
1424
|
+
}
|
|
1425
|
+
});
|
|
1426
|
+
|
|
1427
|
+
// src/core/navigators/hierarchyDefinition.ts
|
|
1428
|
+
var hierarchyDefinition_exports = {};
|
|
1429
|
+
__export(hierarchyDefinition_exports, {
|
|
1430
|
+
default: () => HierarchyDefinitionNavigator
|
|
1431
|
+
});
|
|
1432
|
+
import { toCourseElo as toCourseElo4 } from "@vue-skuilder/common";
|
|
1433
|
+
var DEFAULT_MIN_COUNT, HierarchyDefinitionNavigator;
|
|
1434
|
+
var init_hierarchyDefinition = __esm({
|
|
1435
|
+
"src/core/navigators/hierarchyDefinition.ts"() {
|
|
1436
|
+
"use strict";
|
|
1437
|
+
init_navigators();
|
|
1438
|
+
DEFAULT_MIN_COUNT = 3;
|
|
1439
|
+
HierarchyDefinitionNavigator = class extends ContentNavigator {
|
|
1440
|
+
config;
|
|
1441
|
+
_strategyData;
|
|
1442
|
+
/** Human-readable name for CardFilter interface */
|
|
1443
|
+
name;
|
|
1444
|
+
constructor(user, course, _strategyData) {
|
|
1445
|
+
super(user, course, _strategyData);
|
|
1446
|
+
this._strategyData = _strategyData;
|
|
1447
|
+
this.config = this.parseConfig(_strategyData.serializedData);
|
|
1448
|
+
this.name = _strategyData.name || "Hierarchy Definition";
|
|
1449
|
+
}
|
|
1450
|
+
parseConfig(serializedData) {
|
|
1451
|
+
try {
|
|
1452
|
+
const parsed = JSON.parse(serializedData);
|
|
1453
|
+
return {
|
|
1454
|
+
prerequisites: parsed.prerequisites || {}
|
|
1455
|
+
};
|
|
1456
|
+
} catch {
|
|
1457
|
+
return {
|
|
1458
|
+
prerequisites: {}
|
|
1459
|
+
};
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
/**
|
|
1463
|
+
* Check if a specific prerequisite is satisfied
|
|
1464
|
+
*/
|
|
1465
|
+
isPrerequisiteMet(prereq, userTagElo, userGlobalElo) {
|
|
1466
|
+
if (!userTagElo) return false;
|
|
1467
|
+
const minCount = prereq.masteryThreshold?.minCount ?? DEFAULT_MIN_COUNT;
|
|
1468
|
+
if (userTagElo.count < minCount) return false;
|
|
1469
|
+
if (prereq.masteryThreshold?.minElo !== void 0) {
|
|
1470
|
+
return userTagElo.score >= prereq.masteryThreshold.minElo;
|
|
1471
|
+
} else {
|
|
1472
|
+
return userTagElo.score >= userGlobalElo;
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
/**
|
|
1476
|
+
* Get the set of tags the user has mastered.
|
|
1477
|
+
* A tag is "mastered" if it appears as a prerequisite somewhere and meets its threshold.
|
|
1478
|
+
*/
|
|
1479
|
+
async getMasteredTags(context) {
|
|
1480
|
+
const mastered = /* @__PURE__ */ new Set();
|
|
1481
|
+
try {
|
|
1482
|
+
const courseReg = await context.user.getCourseRegDoc(context.course.getCourseID());
|
|
1483
|
+
const userElo = toCourseElo4(courseReg.elo);
|
|
1484
|
+
for (const prereqs of Object.values(this.config.prerequisites)) {
|
|
1485
|
+
for (const prereq of prereqs) {
|
|
1486
|
+
const tagElo = userElo.tags[prereq.tag];
|
|
1487
|
+
if (this.isPrerequisiteMet(prereq, tagElo, userElo.global.score)) {
|
|
1488
|
+
mastered.add(prereq.tag);
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
} catch {
|
|
1493
|
+
}
|
|
1494
|
+
return mastered;
|
|
1495
|
+
}
|
|
1496
|
+
/**
|
|
1497
|
+
* Get the set of tags that are unlocked (prerequisites met)
|
|
1498
|
+
*/
|
|
1499
|
+
getUnlockedTags(masteredTags) {
|
|
1500
|
+
const unlocked = /* @__PURE__ */ new Set();
|
|
1501
|
+
for (const [tagId, prereqs] of Object.entries(this.config.prerequisites)) {
|
|
1502
|
+
const allPrereqsMet = prereqs.every((prereq) => masteredTags.has(prereq.tag));
|
|
1503
|
+
if (allPrereqsMet) {
|
|
1504
|
+
unlocked.add(tagId);
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
return unlocked;
|
|
1508
|
+
}
|
|
1509
|
+
/**
|
|
1510
|
+
* Check if a tag has prerequisites defined in config
|
|
1511
|
+
*/
|
|
1512
|
+
hasPrerequisites(tagId) {
|
|
1513
|
+
return tagId in this.config.prerequisites;
|
|
1514
|
+
}
|
|
1515
|
+
/**
|
|
1516
|
+
* Check if a card is unlocked and generate reason.
|
|
1517
|
+
*/
|
|
1518
|
+
async checkCardUnlock(card, course, unlockedTags, masteredTags) {
|
|
1519
|
+
try {
|
|
1520
|
+
const cardTags = card.tags ?? [];
|
|
1521
|
+
const lockedTags = cardTags.filter(
|
|
1522
|
+
(tag) => this.hasPrerequisites(tag) && !unlockedTags.has(tag)
|
|
1523
|
+
);
|
|
1524
|
+
if (lockedTags.length === 0) {
|
|
1525
|
+
const tagList = cardTags.length > 0 ? cardTags.join(", ") : "none";
|
|
1526
|
+
return {
|
|
1527
|
+
isUnlocked: true,
|
|
1528
|
+
reason: `Prerequisites met, tags: ${tagList}`
|
|
1529
|
+
};
|
|
1530
|
+
}
|
|
1531
|
+
const missingPrereqs = lockedTags.flatMap((tag) => {
|
|
1532
|
+
const prereqs = this.config.prerequisites[tag] || [];
|
|
1533
|
+
return prereqs.filter((p) => !masteredTags.has(p.tag)).map((p) => p.tag);
|
|
1534
|
+
});
|
|
1535
|
+
return {
|
|
1536
|
+
isUnlocked: false,
|
|
1537
|
+
reason: `Blocked: missing prerequisites ${missingPrereqs.join(", ")} for tags ${lockedTags.join(", ")}`
|
|
1538
|
+
};
|
|
1539
|
+
} catch {
|
|
1540
|
+
return {
|
|
1541
|
+
isUnlocked: true,
|
|
1542
|
+
reason: "Prerequisites check skipped (tag lookup failed)"
|
|
1543
|
+
};
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
/**
|
|
1547
|
+
* CardFilter.transform implementation.
|
|
1548
|
+
*
|
|
1549
|
+
* Apply prerequisite gating to cards. Cards with locked tags receive score: 0.
|
|
1550
|
+
*/
|
|
1551
|
+
async transform(cards, context) {
|
|
1552
|
+
const masteredTags = await this.getMasteredTags(context);
|
|
1553
|
+
const unlockedTags = this.getUnlockedTags(masteredTags);
|
|
1554
|
+
const gated = [];
|
|
1555
|
+
for (const card of cards) {
|
|
1556
|
+
const { isUnlocked, reason } = await this.checkCardUnlock(
|
|
1557
|
+
card,
|
|
1558
|
+
context.course,
|
|
1559
|
+
unlockedTags,
|
|
1560
|
+
masteredTags
|
|
1561
|
+
);
|
|
1562
|
+
const finalScore = isUnlocked ? card.score : 0;
|
|
1563
|
+
const action = isUnlocked ? "passed" : "penalized";
|
|
1564
|
+
gated.push({
|
|
1565
|
+
...card,
|
|
1566
|
+
score: finalScore,
|
|
1567
|
+
provenance: [
|
|
1568
|
+
...card.provenance,
|
|
1569
|
+
{
|
|
1570
|
+
strategy: "hierarchyDefinition",
|
|
1571
|
+
strategyName: this.strategyName || this.name,
|
|
1572
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-hierarchy",
|
|
1573
|
+
action,
|
|
1574
|
+
score: finalScore,
|
|
1575
|
+
reason
|
|
1576
|
+
}
|
|
1577
|
+
]
|
|
1578
|
+
});
|
|
1579
|
+
}
|
|
1580
|
+
return gated;
|
|
1581
|
+
}
|
|
1582
|
+
/**
|
|
1583
|
+
* Legacy getWeightedCards - now throws as filters should not be used as generators.
|
|
1584
|
+
*
|
|
1585
|
+
* Use transform() via Pipeline instead.
|
|
1586
|
+
*/
|
|
1587
|
+
async getWeightedCards(_limit) {
|
|
1588
|
+
throw new Error(
|
|
1589
|
+
"HierarchyDefinitionNavigator is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
|
|
1590
|
+
);
|
|
1591
|
+
}
|
|
1592
|
+
// Legacy methods - stub implementations since filters don't generate cards
|
|
1593
|
+
async getNewCards(_n) {
|
|
1594
|
+
return [];
|
|
1595
|
+
}
|
|
1596
|
+
async getPendingReviews() {
|
|
1597
|
+
return [];
|
|
1598
|
+
}
|
|
1599
|
+
};
|
|
1600
|
+
}
|
|
1601
|
+
});
|
|
1602
|
+
|
|
1603
|
+
// src/core/navigators/inferredPreference.ts
|
|
1604
|
+
var inferredPreference_exports = {};
|
|
1605
|
+
__export(inferredPreference_exports, {
|
|
1606
|
+
INFERRED_PREFERENCE_NAVIGATOR_STUB: () => INFERRED_PREFERENCE_NAVIGATOR_STUB
|
|
1607
|
+
});
|
|
1608
|
+
var INFERRED_PREFERENCE_NAVIGATOR_STUB;
|
|
1609
|
+
var init_inferredPreference = __esm({
|
|
1610
|
+
"src/core/navigators/inferredPreference.ts"() {
|
|
1611
|
+
"use strict";
|
|
1612
|
+
INFERRED_PREFERENCE_NAVIGATOR_STUB = true;
|
|
1613
|
+
}
|
|
1614
|
+
});
|
|
1615
|
+
|
|
1616
|
+
// src/core/navigators/interferenceMitigator.ts
|
|
1617
|
+
var interferenceMitigator_exports = {};
|
|
1618
|
+
__export(interferenceMitigator_exports, {
|
|
1619
|
+
default: () => InterferenceMitigatorNavigator
|
|
1620
|
+
});
|
|
1621
|
+
import { toCourseElo as toCourseElo5 } from "@vue-skuilder/common";
|
|
1622
|
+
var DEFAULT_MIN_COUNT2, DEFAULT_MIN_ELAPSED_DAYS, DEFAULT_INTERFERENCE_DECAY, InterferenceMitigatorNavigator;
|
|
1623
|
+
var init_interferenceMitigator = __esm({
|
|
1624
|
+
"src/core/navigators/interferenceMitigator.ts"() {
|
|
1625
|
+
"use strict";
|
|
1626
|
+
init_navigators();
|
|
1627
|
+
DEFAULT_MIN_COUNT2 = 10;
|
|
1628
|
+
DEFAULT_MIN_ELAPSED_DAYS = 3;
|
|
1629
|
+
DEFAULT_INTERFERENCE_DECAY = 0.8;
|
|
1630
|
+
InterferenceMitigatorNavigator = class extends ContentNavigator {
|
|
1631
|
+
config;
|
|
1632
|
+
_strategyData;
|
|
1633
|
+
/** Human-readable name for CardFilter interface */
|
|
1634
|
+
name;
|
|
1635
|
+
/** Precomputed map: tag -> set of { partner, decay } it interferes with */
|
|
1636
|
+
interferenceMap;
|
|
1637
|
+
constructor(user, course, _strategyData) {
|
|
1638
|
+
super(user, course, _strategyData);
|
|
1639
|
+
this._strategyData = _strategyData;
|
|
1640
|
+
this.config = this.parseConfig(_strategyData.serializedData);
|
|
1641
|
+
this.interferenceMap = this.buildInterferenceMap();
|
|
1642
|
+
this.name = _strategyData.name || "Interference Mitigator";
|
|
1643
|
+
}
|
|
1644
|
+
parseConfig(serializedData) {
|
|
1645
|
+
try {
|
|
1646
|
+
const parsed = JSON.parse(serializedData);
|
|
1647
|
+
let sets = parsed.interferenceSets || [];
|
|
1648
|
+
if (sets.length > 0 && Array.isArray(sets[0])) {
|
|
1649
|
+
sets = sets.map((tags) => ({ tags }));
|
|
1650
|
+
}
|
|
1651
|
+
return {
|
|
1652
|
+
interferenceSets: sets,
|
|
1653
|
+
maturityThreshold: {
|
|
1654
|
+
minCount: parsed.maturityThreshold?.minCount ?? DEFAULT_MIN_COUNT2,
|
|
1655
|
+
minElo: parsed.maturityThreshold?.minElo,
|
|
1656
|
+
minElapsedDays: parsed.maturityThreshold?.minElapsedDays ?? DEFAULT_MIN_ELAPSED_DAYS
|
|
1657
|
+
},
|
|
1658
|
+
defaultDecay: parsed.defaultDecay ?? DEFAULT_INTERFERENCE_DECAY
|
|
1659
|
+
};
|
|
1660
|
+
} catch {
|
|
1661
|
+
return {
|
|
1662
|
+
interferenceSets: [],
|
|
1663
|
+
maturityThreshold: {
|
|
1664
|
+
minCount: DEFAULT_MIN_COUNT2,
|
|
1665
|
+
minElapsedDays: DEFAULT_MIN_ELAPSED_DAYS
|
|
1666
|
+
},
|
|
1667
|
+
defaultDecay: DEFAULT_INTERFERENCE_DECAY
|
|
1668
|
+
};
|
|
1669
|
+
}
|
|
1670
|
+
}
|
|
1671
|
+
/**
|
|
1672
|
+
* Build a map from each tag to its interference partners with decay coefficients.
|
|
1673
|
+
* If tags A, B, C are in an interference group with decay 0.8, then:
|
|
1674
|
+
* - A interferes with B (decay 0.8) and C (decay 0.8)
|
|
1675
|
+
* - B interferes with A (decay 0.8) and C (decay 0.8)
|
|
1676
|
+
* - etc.
|
|
1677
|
+
*/
|
|
1678
|
+
buildInterferenceMap() {
|
|
1679
|
+
const map = /* @__PURE__ */ new Map();
|
|
1680
|
+
for (const group of this.config.interferenceSets) {
|
|
1681
|
+
const decay = group.decay ?? this.config.defaultDecay ?? DEFAULT_INTERFERENCE_DECAY;
|
|
1682
|
+
for (const tag of group.tags) {
|
|
1683
|
+
if (!map.has(tag)) {
|
|
1684
|
+
map.set(tag, []);
|
|
1685
|
+
}
|
|
1686
|
+
const partners = map.get(tag);
|
|
1687
|
+
for (const other of group.tags) {
|
|
1688
|
+
if (other !== tag) {
|
|
1689
|
+
const existing = partners.find((p) => p.partner === other);
|
|
1690
|
+
if (existing) {
|
|
1691
|
+
existing.decay = Math.max(existing.decay, decay);
|
|
1692
|
+
} else {
|
|
1693
|
+
partners.push({ partner: other, decay });
|
|
1694
|
+
}
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
return map;
|
|
1700
|
+
}
|
|
1701
|
+
/**
|
|
1702
|
+
* Get the set of tags that are currently immature for this user.
|
|
1703
|
+
* A tag is immature if the user has interacted with it but hasn't
|
|
1704
|
+
* reached the maturity threshold.
|
|
1705
|
+
*/
|
|
1706
|
+
async getImmatureTags(context) {
|
|
1707
|
+
const immature = /* @__PURE__ */ new Set();
|
|
1708
|
+
try {
|
|
1709
|
+
const courseReg = await context.user.getCourseRegDoc(context.course.getCourseID());
|
|
1710
|
+
const userElo = toCourseElo5(courseReg.elo);
|
|
1711
|
+
const minCount = this.config.maturityThreshold?.minCount ?? DEFAULT_MIN_COUNT2;
|
|
1712
|
+
const minElo = this.config.maturityThreshold?.minElo;
|
|
1713
|
+
const minElapsedDays = this.config.maturityThreshold?.minElapsedDays ?? DEFAULT_MIN_ELAPSED_DAYS;
|
|
1714
|
+
const minCountForElapsed = minElapsedDays * 2;
|
|
1715
|
+
for (const [tagId, tagElo] of Object.entries(userElo.tags)) {
|
|
1716
|
+
if (tagElo.count === 0) continue;
|
|
1717
|
+
const belowCount = tagElo.count < minCount;
|
|
1718
|
+
const belowElo = minElo !== void 0 && tagElo.score < minElo;
|
|
1719
|
+
const belowElapsed = tagElo.count < minCountForElapsed;
|
|
1720
|
+
if (belowCount || belowElo || belowElapsed) {
|
|
1721
|
+
immature.add(tagId);
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
} catch {
|
|
1725
|
+
}
|
|
1726
|
+
return immature;
|
|
1727
|
+
}
|
|
1728
|
+
/**
|
|
1729
|
+
* Get all tags that interfere with any immature tag, along with their decay coefficients.
|
|
1730
|
+
* These are the tags we want to avoid introducing.
|
|
1731
|
+
*/
|
|
1732
|
+
getTagsToAvoid(immatureTags) {
|
|
1733
|
+
const avoid = /* @__PURE__ */ new Map();
|
|
1734
|
+
for (const immatureTag of immatureTags) {
|
|
1735
|
+
const partners = this.interferenceMap.get(immatureTag);
|
|
1736
|
+
if (partners) {
|
|
1737
|
+
for (const { partner, decay } of partners) {
|
|
1738
|
+
if (!immatureTags.has(partner)) {
|
|
1739
|
+
const existing = avoid.get(partner) ?? 0;
|
|
1740
|
+
avoid.set(partner, Math.max(existing, decay));
|
|
1741
|
+
}
|
|
1742
|
+
}
|
|
1743
|
+
}
|
|
1744
|
+
}
|
|
1745
|
+
return avoid;
|
|
1746
|
+
}
|
|
1747
|
+
/**
|
|
1748
|
+
* Compute interference score reduction for a card.
|
|
1749
|
+
* Returns: { multiplier, interfering tags, reason }
|
|
1750
|
+
*/
|
|
1751
|
+
computeInterferenceEffect(cardTags, tagsToAvoid, immatureTags) {
|
|
1752
|
+
if (tagsToAvoid.size === 0) {
|
|
1753
|
+
return {
|
|
1754
|
+
multiplier: 1,
|
|
1755
|
+
interferingTags: [],
|
|
1756
|
+
reason: "No interference detected"
|
|
1757
|
+
};
|
|
1758
|
+
}
|
|
1759
|
+
let multiplier = 1;
|
|
1760
|
+
const interferingTags = [];
|
|
1761
|
+
for (const tag of cardTags) {
|
|
1762
|
+
const decay = tagsToAvoid.get(tag);
|
|
1763
|
+
if (decay !== void 0) {
|
|
1764
|
+
interferingTags.push(tag);
|
|
1765
|
+
multiplier *= 1 - decay;
|
|
1766
|
+
}
|
|
1767
|
+
}
|
|
1768
|
+
if (interferingTags.length === 0) {
|
|
1769
|
+
return {
|
|
1770
|
+
multiplier: 1,
|
|
1771
|
+
interferingTags: [],
|
|
1772
|
+
reason: "No interference detected"
|
|
1773
|
+
};
|
|
1774
|
+
}
|
|
1775
|
+
const causingTags = /* @__PURE__ */ new Set();
|
|
1776
|
+
for (const tag of interferingTags) {
|
|
1777
|
+
for (const immatureTag of immatureTags) {
|
|
1778
|
+
const partners = this.interferenceMap.get(immatureTag);
|
|
1779
|
+
if (partners?.some((p) => p.partner === tag)) {
|
|
1780
|
+
causingTags.add(immatureTag);
|
|
1781
|
+
}
|
|
1782
|
+
}
|
|
1783
|
+
}
|
|
1784
|
+
const reason = `Interferes with immature tags ${Array.from(causingTags).join(", ")} (tags: ${interferingTags.join(", ")}, multiplier: ${multiplier.toFixed(2)})`;
|
|
1785
|
+
return { multiplier, interferingTags, reason };
|
|
1786
|
+
}
|
|
1787
|
+
/**
|
|
1788
|
+
* CardFilter.transform implementation.
|
|
1789
|
+
*
|
|
1790
|
+
* Apply interference-aware scoring. Cards with tags that interfere with
|
|
1791
|
+
* immature learnings get reduced scores.
|
|
1792
|
+
*/
|
|
1793
|
+
async transform(cards, context) {
|
|
1794
|
+
const immatureTags = await this.getImmatureTags(context);
|
|
1795
|
+
const tagsToAvoid = this.getTagsToAvoid(immatureTags);
|
|
1796
|
+
const adjusted = [];
|
|
1797
|
+
for (const card of cards) {
|
|
1798
|
+
const cardTags = card.tags ?? [];
|
|
1799
|
+
const { multiplier, reason } = this.computeInterferenceEffect(
|
|
1800
|
+
cardTags,
|
|
1801
|
+
tagsToAvoid,
|
|
1802
|
+
immatureTags
|
|
1803
|
+
);
|
|
1804
|
+
const finalScore = card.score * multiplier;
|
|
1805
|
+
const action = multiplier < 1 ? "penalized" : multiplier > 1 ? "boosted" : "passed";
|
|
1806
|
+
adjusted.push({
|
|
1807
|
+
...card,
|
|
1808
|
+
score: finalScore,
|
|
1809
|
+
provenance: [
|
|
1810
|
+
...card.provenance,
|
|
1811
|
+
{
|
|
1812
|
+
strategy: "interferenceMitigator",
|
|
1813
|
+
strategyName: this.strategyName || this.name,
|
|
1814
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-interference",
|
|
1815
|
+
action,
|
|
1816
|
+
score: finalScore,
|
|
1817
|
+
reason
|
|
1818
|
+
}
|
|
1819
|
+
]
|
|
1820
|
+
});
|
|
1821
|
+
}
|
|
1822
|
+
return adjusted;
|
|
1823
|
+
}
|
|
1824
|
+
/**
|
|
1825
|
+
* Legacy getWeightedCards - now throws as filters should not be used as generators.
|
|
1826
|
+
*
|
|
1827
|
+
* Use transform() via Pipeline instead.
|
|
1828
|
+
*/
|
|
1829
|
+
async getWeightedCards(_limit) {
|
|
1830
|
+
throw new Error(
|
|
1831
|
+
"InterferenceMitigatorNavigator is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
|
|
1832
|
+
);
|
|
1833
|
+
}
|
|
1834
|
+
// Legacy methods - stub implementations since filters don't generate cards
|
|
1835
|
+
async getNewCards(_n) {
|
|
1836
|
+
return [];
|
|
1837
|
+
}
|
|
1838
|
+
async getPendingReviews() {
|
|
1839
|
+
return [];
|
|
1840
|
+
}
|
|
1841
|
+
};
|
|
1842
|
+
}
|
|
1843
|
+
});
|
|
1844
|
+
|
|
1845
|
+
// src/core/navigators/relativePriority.ts
|
|
1846
|
+
var relativePriority_exports = {};
|
|
1847
|
+
__export(relativePriority_exports, {
|
|
1848
|
+
default: () => RelativePriorityNavigator
|
|
1849
|
+
});
|
|
1850
|
+
var DEFAULT_PRIORITY, DEFAULT_PRIORITY_INFLUENCE, DEFAULT_COMBINE_MODE, RelativePriorityNavigator;
|
|
1851
|
+
var init_relativePriority = __esm({
|
|
1852
|
+
"src/core/navigators/relativePriority.ts"() {
|
|
486
1853
|
"use strict";
|
|
487
1854
|
init_navigators();
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
});
|
|
506
|
-
ratedReviews.sort((a, b) => {
|
|
507
|
-
return a.global.score - b.global.score;
|
|
508
|
-
});
|
|
509
|
-
return ratedReviews.map((r) => {
|
|
1855
|
+
DEFAULT_PRIORITY = 0.5;
|
|
1856
|
+
DEFAULT_PRIORITY_INFLUENCE = 0.5;
|
|
1857
|
+
DEFAULT_COMBINE_MODE = "max";
|
|
1858
|
+
RelativePriorityNavigator = class extends ContentNavigator {
|
|
1859
|
+
config;
|
|
1860
|
+
_strategyData;
|
|
1861
|
+
/** Human-readable name for CardFilter interface */
|
|
1862
|
+
name;
|
|
1863
|
+
constructor(user, course, _strategyData) {
|
|
1864
|
+
super(user, course, _strategyData);
|
|
1865
|
+
this._strategyData = _strategyData;
|
|
1866
|
+
this.config = this.parseConfig(_strategyData.serializedData);
|
|
1867
|
+
this.name = _strategyData.name || "Relative Priority";
|
|
1868
|
+
}
|
|
1869
|
+
parseConfig(serializedData) {
|
|
1870
|
+
try {
|
|
1871
|
+
const parsed = JSON.parse(serializedData);
|
|
510
1872
|
return {
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
courseID: r.courseId,
|
|
516
|
-
qualifiedID: `${r.courseId}-${r.cardId}`,
|
|
517
|
-
reviewID: r._id,
|
|
518
|
-
status: "review"
|
|
1873
|
+
tagPriorities: parsed.tagPriorities || {},
|
|
1874
|
+
defaultPriority: parsed.defaultPriority ?? DEFAULT_PRIORITY,
|
|
1875
|
+
combineMode: parsed.combineMode ?? DEFAULT_COMBINE_MODE,
|
|
1876
|
+
priorityInfluence: parsed.priorityInfluence ?? DEFAULT_PRIORITY_INFLUENCE
|
|
519
1877
|
};
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
async getNewCards(limit = 99) {
|
|
523
|
-
const activeCards = await this.user.getActiveCards();
|
|
524
|
-
return (await this.course.getCardsCenteredAtELO(
|
|
525
|
-
{ limit, elo: "user" },
|
|
526
|
-
(c) => {
|
|
527
|
-
if (activeCards.some((ac) => c.cardID === ac.cardID)) {
|
|
528
|
-
return false;
|
|
529
|
-
} else {
|
|
530
|
-
return true;
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
)).map((c) => {
|
|
1878
|
+
} catch {
|
|
534
1879
|
return {
|
|
535
|
-
|
|
536
|
-
|
|
1880
|
+
tagPriorities: {},
|
|
1881
|
+
defaultPriority: DEFAULT_PRIORITY,
|
|
1882
|
+
combineMode: DEFAULT_COMBINE_MODE,
|
|
1883
|
+
priorityInfluence: DEFAULT_PRIORITY_INFLUENCE
|
|
537
1884
|
};
|
|
538
|
-
}
|
|
1885
|
+
}
|
|
1886
|
+
}
|
|
1887
|
+
/**
|
|
1888
|
+
* Look up the priority for a tag.
|
|
1889
|
+
*/
|
|
1890
|
+
getTagPriority(tagId) {
|
|
1891
|
+
return this.config.tagPriorities[tagId] ?? this.config.defaultPriority ?? DEFAULT_PRIORITY;
|
|
1892
|
+
}
|
|
1893
|
+
/**
|
|
1894
|
+
* Compute combined priority for a card based on its tags.
|
|
1895
|
+
*/
|
|
1896
|
+
computeCardPriority(cardTags) {
|
|
1897
|
+
if (cardTags.length === 0) {
|
|
1898
|
+
return this.config.defaultPriority ?? DEFAULT_PRIORITY;
|
|
1899
|
+
}
|
|
1900
|
+
const priorities = cardTags.map((tag) => this.getTagPriority(tag));
|
|
1901
|
+
switch (this.config.combineMode) {
|
|
1902
|
+
case "max":
|
|
1903
|
+
return Math.max(...priorities);
|
|
1904
|
+
case "min":
|
|
1905
|
+
return Math.min(...priorities);
|
|
1906
|
+
case "average":
|
|
1907
|
+
return priorities.reduce((sum, p) => sum + p, 0) / priorities.length;
|
|
1908
|
+
default:
|
|
1909
|
+
return Math.max(...priorities);
|
|
1910
|
+
}
|
|
1911
|
+
}
|
|
1912
|
+
/**
|
|
1913
|
+
* Compute boost factor based on priority.
|
|
1914
|
+
*
|
|
1915
|
+
* The formula: 1 + (priority - 0.5) * priorityInfluence
|
|
1916
|
+
*
|
|
1917
|
+
* This creates a multiplier centered around 1.0:
|
|
1918
|
+
* - Priority 1.0 with influence 0.5 → 1.25 (25% boost)
|
|
1919
|
+
* - Priority 0.5 with any influence → 1.00 (neutral)
|
|
1920
|
+
* - Priority 0.0 with influence 0.5 → 0.75 (25% reduction)
|
|
1921
|
+
*/
|
|
1922
|
+
computeBoostFactor(priority) {
|
|
1923
|
+
const influence = this.config.priorityInfluence ?? DEFAULT_PRIORITY_INFLUENCE;
|
|
1924
|
+
return 1 + (priority - 0.5) * influence;
|
|
1925
|
+
}
|
|
1926
|
+
/**
|
|
1927
|
+
* Build human-readable reason for priority adjustment.
|
|
1928
|
+
*/
|
|
1929
|
+
buildPriorityReason(cardTags, priority, boostFactor, finalScore) {
|
|
1930
|
+
if (cardTags.length === 0) {
|
|
1931
|
+
return `No tags, neutral priority (${priority.toFixed(2)})`;
|
|
1932
|
+
}
|
|
1933
|
+
const tagList = cardTags.slice(0, 3).join(", ");
|
|
1934
|
+
const more = cardTags.length > 3 ? ` (+${cardTags.length - 3} more)` : "";
|
|
1935
|
+
if (boostFactor === 1) {
|
|
1936
|
+
return `Neutral priority (${priority.toFixed(2)}) for tags: ${tagList}${more}`;
|
|
1937
|
+
} else if (boostFactor > 1) {
|
|
1938
|
+
return `High-priority tags: ${tagList}${more} (priority ${priority.toFixed(2)} \u2192 boost ${boostFactor.toFixed(2)}x \u2192 ${finalScore.toFixed(2)})`;
|
|
1939
|
+
} else {
|
|
1940
|
+
return `Low-priority tags: ${tagList}${more} (priority ${priority.toFixed(2)} \u2192 reduce ${boostFactor.toFixed(2)}x \u2192 ${finalScore.toFixed(2)})`;
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1943
|
+
/**
|
|
1944
|
+
* CardFilter.transform implementation.
|
|
1945
|
+
*
|
|
1946
|
+
* Apply priority-adjusted scoring. Cards with high-priority tags get boosted,
|
|
1947
|
+
* cards with low-priority tags get reduced scores.
|
|
1948
|
+
*/
|
|
1949
|
+
async transform(cards, _context) {
|
|
1950
|
+
const adjusted = await Promise.all(
|
|
1951
|
+
cards.map(async (card) => {
|
|
1952
|
+
const cardTags = card.tags ?? [];
|
|
1953
|
+
const priority = this.computeCardPriority(cardTags);
|
|
1954
|
+
const boostFactor = this.computeBoostFactor(priority);
|
|
1955
|
+
const finalScore = Math.max(0, Math.min(1, card.score * boostFactor));
|
|
1956
|
+
const action = boostFactor > 1 ? "boosted" : boostFactor < 1 ? "penalized" : "passed";
|
|
1957
|
+
const reason = this.buildPriorityReason(cardTags, priority, boostFactor, finalScore);
|
|
1958
|
+
return {
|
|
1959
|
+
...card,
|
|
1960
|
+
score: finalScore,
|
|
1961
|
+
provenance: [
|
|
1962
|
+
...card.provenance,
|
|
1963
|
+
{
|
|
1964
|
+
strategy: "relativePriority",
|
|
1965
|
+
strategyName: this.strategyName || this.name,
|
|
1966
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-priority",
|
|
1967
|
+
action,
|
|
1968
|
+
score: finalScore,
|
|
1969
|
+
reason
|
|
1970
|
+
}
|
|
1971
|
+
]
|
|
1972
|
+
};
|
|
1973
|
+
})
|
|
1974
|
+
);
|
|
1975
|
+
return adjusted;
|
|
1976
|
+
}
|
|
1977
|
+
/**
|
|
1978
|
+
* Legacy getWeightedCards - now throws as filters should not be used as generators.
|
|
1979
|
+
*
|
|
1980
|
+
* Use transform() via Pipeline instead.
|
|
1981
|
+
*/
|
|
1982
|
+
async getWeightedCards(_limit) {
|
|
1983
|
+
throw new Error(
|
|
1984
|
+
"RelativePriorityNavigator is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
|
|
1985
|
+
);
|
|
1986
|
+
}
|
|
1987
|
+
// Legacy methods - stub implementations since filters don't generate cards
|
|
1988
|
+
async getNewCards(_n) {
|
|
1989
|
+
return [];
|
|
1990
|
+
}
|
|
1991
|
+
async getPendingReviews() {
|
|
1992
|
+
return [];
|
|
539
1993
|
}
|
|
540
1994
|
};
|
|
541
1995
|
}
|
|
542
1996
|
});
|
|
543
1997
|
|
|
544
|
-
// src/core/navigators/
|
|
545
|
-
var
|
|
546
|
-
__export(
|
|
547
|
-
default: () =>
|
|
1998
|
+
// src/core/navigators/srs.ts
|
|
1999
|
+
var srs_exports = {};
|
|
2000
|
+
__export(srs_exports, {
|
|
2001
|
+
default: () => SRSNavigator
|
|
548
2002
|
});
|
|
549
|
-
|
|
550
|
-
var
|
|
551
|
-
|
|
2003
|
+
import moment3 from "moment";
|
|
2004
|
+
var SRSNavigator;
|
|
2005
|
+
var init_srs = __esm({
|
|
2006
|
+
"src/core/navigators/srs.ts"() {
|
|
552
2007
|
"use strict";
|
|
553
2008
|
init_navigators();
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
user;
|
|
558
|
-
course;
|
|
2009
|
+
SRSNavigator = class extends ContentNavigator {
|
|
2010
|
+
/** Human-readable name for CardGenerator interface */
|
|
2011
|
+
name;
|
|
559
2012
|
constructor(user, course, strategyData) {
|
|
560
|
-
super();
|
|
561
|
-
this.
|
|
562
|
-
this.course = course;
|
|
563
|
-
if (strategyData.serializedData) {
|
|
564
|
-
try {
|
|
565
|
-
this.orderedCardIds = JSON.parse(strategyData.serializedData);
|
|
566
|
-
} catch (e) {
|
|
567
|
-
logger.error("Failed to parse serializedData for HardcodedOrderNavigator", e);
|
|
568
|
-
}
|
|
569
|
-
}
|
|
2013
|
+
super(user, course, strategyData);
|
|
2014
|
+
this.name = strategyData?.name || "SRS";
|
|
570
2015
|
}
|
|
571
|
-
|
|
2016
|
+
/**
|
|
2017
|
+
* Get review cards scored by urgency.
|
|
2018
|
+
*
|
|
2019
|
+
* Score formula combines:
|
|
2020
|
+
* - Relative overdueness: hoursOverdue / intervalHours
|
|
2021
|
+
* - Interval recency: exponential decay favoring shorter intervals
|
|
2022
|
+
*
|
|
2023
|
+
* Cards not yet due are excluded (not scored as 0).
|
|
2024
|
+
*
|
|
2025
|
+
* This method supports both the legacy signature (limit only) and the
|
|
2026
|
+
* CardGenerator interface signature (limit, context).
|
|
2027
|
+
*
|
|
2028
|
+
* @param limit - Maximum number of cards to return
|
|
2029
|
+
* @param _context - Optional GeneratorContext (currently unused, but required for interface)
|
|
2030
|
+
*/
|
|
2031
|
+
async getWeightedCards(limit, _context) {
|
|
2032
|
+
if (!this.user || !this.course) {
|
|
2033
|
+
throw new Error("SRSNavigator requires user and course to be set");
|
|
2034
|
+
}
|
|
572
2035
|
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
573
|
-
|
|
2036
|
+
const now = moment3.utc();
|
|
2037
|
+
const dueReviews = reviews.filter((r) => now.isAfter(moment3.utc(r.reviewTime)));
|
|
2038
|
+
const scored = dueReviews.map((review) => {
|
|
2039
|
+
const { score, reason } = this.computeUrgencyScore(review, now);
|
|
574
2040
|
return {
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
2041
|
+
cardId: review.cardId,
|
|
2042
|
+
courseId: review.courseId,
|
|
2043
|
+
score,
|
|
2044
|
+
provenance: [
|
|
2045
|
+
{
|
|
2046
|
+
strategy: "srs",
|
|
2047
|
+
strategyName: this.strategyName || this.name,
|
|
2048
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-SRS-default",
|
|
2049
|
+
action: "generated",
|
|
2050
|
+
score,
|
|
2051
|
+
reason
|
|
2052
|
+
}
|
|
2053
|
+
]
|
|
582
2054
|
};
|
|
583
2055
|
});
|
|
2056
|
+
return scored.sort((a, b) => b.score - a.score).slice(0, limit);
|
|
584
2057
|
}
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
2058
|
+
/**
|
|
2059
|
+
* Compute urgency score for a review card.
|
|
2060
|
+
*
|
|
2061
|
+
* Two factors:
|
|
2062
|
+
* 1. Relative overdueness = hoursOverdue / intervalHours
|
|
2063
|
+
* - 2 days overdue on 3-day interval = 0.67 (urgent)
|
|
2064
|
+
* - 2 days overdue on 180-day interval = 0.01 (not urgent)
|
|
2065
|
+
*
|
|
2066
|
+
* 2. Interval recency factor = 0.3 + 0.7 * exp(-intervalHours / 720)
|
|
2067
|
+
* - 24h interval → ~1.0 (very recent learning)
|
|
2068
|
+
* - 30 days (720h) → ~0.56
|
|
2069
|
+
* - 180 days → ~0.30
|
|
2070
|
+
*
|
|
2071
|
+
* Combined: base 0.5 + weighted average of factors * 0.45
|
|
2072
|
+
* Result range: approximately 0.5 to 0.95
|
|
2073
|
+
*/
|
|
2074
|
+
computeUrgencyScore(review, now) {
|
|
2075
|
+
const scheduledAt = moment3.utc(review.scheduledAt);
|
|
2076
|
+
const due = moment3.utc(review.reviewTime);
|
|
2077
|
+
const intervalHours = Math.max(1, due.diff(scheduledAt, "hours"));
|
|
2078
|
+
const hoursOverdue = now.diff(due, "hours");
|
|
2079
|
+
const relativeOverdue = hoursOverdue / intervalHours;
|
|
2080
|
+
const recencyFactor = 0.3 + 0.7 * Math.exp(-intervalHours / 720);
|
|
2081
|
+
const overdueContribution = Math.min(1, Math.max(0, relativeOverdue));
|
|
2082
|
+
const urgency = overdueContribution * 0.5 + recencyFactor * 0.5;
|
|
2083
|
+
const score = Math.min(0.95, 0.5 + urgency * 0.45);
|
|
2084
|
+
const reason = `${Math.round(hoursOverdue)}h overdue (interval: ${Math.round(intervalHours)}h, relative: ${relativeOverdue.toFixed(2)}), recency: ${recencyFactor.toFixed(2)}, review`;
|
|
2085
|
+
return { score, reason };
|
|
2086
|
+
}
|
|
2087
|
+
/**
|
|
2088
|
+
* Get pending reviews in legacy format.
|
|
2089
|
+
*
|
|
2090
|
+
* Returns all pending reviews for the course, enriched with session item fields.
|
|
2091
|
+
*/
|
|
2092
|
+
async getPendingReviews() {
|
|
2093
|
+
if (!this.user || !this.course) {
|
|
2094
|
+
throw new Error("SRSNavigator requires user and course to be set");
|
|
2095
|
+
}
|
|
2096
|
+
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
2097
|
+
return reviews.map((r) => ({
|
|
2098
|
+
...r,
|
|
2099
|
+
contentSourceType: "course",
|
|
2100
|
+
contentSourceID: this.course.getCourseID(),
|
|
2101
|
+
cardID: r.cardId,
|
|
2102
|
+
courseID: r.courseId,
|
|
2103
|
+
qualifiedID: `${r.courseId}-${r.cardId}`,
|
|
2104
|
+
reviewID: r._id,
|
|
2105
|
+
status: "review"
|
|
2106
|
+
}));
|
|
2107
|
+
}
|
|
2108
|
+
/**
|
|
2109
|
+
* SRS does not generate new cards.
|
|
2110
|
+
* Use ELONavigator or another generator for new cards.
|
|
2111
|
+
*/
|
|
2112
|
+
async getNewCards(_n) {
|
|
2113
|
+
return [];
|
|
600
2114
|
}
|
|
601
2115
|
};
|
|
602
2116
|
}
|
|
603
2117
|
});
|
|
604
2118
|
|
|
2119
|
+
// src/core/navigators/userGoal.ts
|
|
2120
|
+
var userGoal_exports = {};
|
|
2121
|
+
__export(userGoal_exports, {
|
|
2122
|
+
USER_GOAL_NAVIGATOR_STUB: () => USER_GOAL_NAVIGATOR_STUB
|
|
2123
|
+
});
|
|
2124
|
+
var USER_GOAL_NAVIGATOR_STUB;
|
|
2125
|
+
var init_userGoal = __esm({
|
|
2126
|
+
"src/core/navigators/userGoal.ts"() {
|
|
2127
|
+
"use strict";
|
|
2128
|
+
USER_GOAL_NAVIGATOR_STUB = true;
|
|
2129
|
+
}
|
|
2130
|
+
});
|
|
2131
|
+
|
|
605
2132
|
// import("./**/*") in src/core/navigators/index.ts
|
|
606
2133
|
var globImport;
|
|
607
2134
|
var init_ = __esm({
|
|
608
2135
|
'import("./**/*") in src/core/navigators/index.ts'() {
|
|
609
2136
|
globImport = __glob({
|
|
2137
|
+
"./CompositeGenerator.ts": () => Promise.resolve().then(() => (init_CompositeGenerator(), CompositeGenerator_exports)),
|
|
2138
|
+
"./Pipeline.ts": () => Promise.resolve().then(() => (init_Pipeline(), Pipeline_exports)),
|
|
2139
|
+
"./PipelineAssembler.ts": () => Promise.resolve().then(() => (init_PipelineAssembler(), PipelineAssembler_exports)),
|
|
610
2140
|
"./elo.ts": () => Promise.resolve().then(() => (init_elo(), elo_exports)),
|
|
2141
|
+
"./filters/eloDistance.ts": () => Promise.resolve().then(() => (init_eloDistance(), eloDistance_exports)),
|
|
2142
|
+
"./filters/index.ts": () => Promise.resolve().then(() => (init_filters(), filters_exports)),
|
|
2143
|
+
"./filters/types.ts": () => Promise.resolve().then(() => (init_types(), types_exports)),
|
|
2144
|
+
"./filters/userTagPreference.ts": () => Promise.resolve().then(() => (init_userTagPreference(), userTagPreference_exports)),
|
|
2145
|
+
"./generators/index.ts": () => Promise.resolve().then(() => (init_generators(), generators_exports)),
|
|
2146
|
+
"./generators/types.ts": () => Promise.resolve().then(() => (init_types2(), types_exports2)),
|
|
611
2147
|
"./hardcodedOrder.ts": () => Promise.resolve().then(() => (init_hardcodedOrder(), hardcodedOrder_exports)),
|
|
612
|
-
"./
|
|
2148
|
+
"./hierarchyDefinition.ts": () => Promise.resolve().then(() => (init_hierarchyDefinition(), hierarchyDefinition_exports)),
|
|
2149
|
+
"./index.ts": () => Promise.resolve().then(() => (init_navigators(), navigators_exports)),
|
|
2150
|
+
"./inferredPreference.ts": () => Promise.resolve().then(() => (init_inferredPreference(), inferredPreference_exports)),
|
|
2151
|
+
"./interferenceMitigator.ts": () => Promise.resolve().then(() => (init_interferenceMitigator(), interferenceMitigator_exports)),
|
|
2152
|
+
"./relativePriority.ts": () => Promise.resolve().then(() => (init_relativePriority(), relativePriority_exports)),
|
|
2153
|
+
"./srs.ts": () => Promise.resolve().then(() => (init_srs(), srs_exports)),
|
|
2154
|
+
"./userGoal.ts": () => Promise.resolve().then(() => (init_userGoal(), userGoal_exports))
|
|
613
2155
|
});
|
|
614
2156
|
}
|
|
615
2157
|
});
|
|
@@ -618,9 +2160,34 @@ var init_ = __esm({
|
|
|
618
2160
|
var navigators_exports = {};
|
|
619
2161
|
__export(navigators_exports, {
|
|
620
2162
|
ContentNavigator: () => ContentNavigator,
|
|
621
|
-
|
|
2163
|
+
NavigatorRole: () => NavigatorRole,
|
|
2164
|
+
NavigatorRoles: () => NavigatorRoles,
|
|
2165
|
+
Navigators: () => Navigators,
|
|
2166
|
+
getCardOrigin: () => getCardOrigin,
|
|
2167
|
+
isFilter: () => isFilter,
|
|
2168
|
+
isGenerator: () => isGenerator
|
|
622
2169
|
});
|
|
623
|
-
|
|
2170
|
+
function getCardOrigin(card) {
|
|
2171
|
+
if (card.provenance.length === 0) {
|
|
2172
|
+
throw new Error("Card has no provenance - cannot determine origin");
|
|
2173
|
+
}
|
|
2174
|
+
const firstEntry = card.provenance[0];
|
|
2175
|
+
const reason = firstEntry.reason.toLowerCase();
|
|
2176
|
+
if (reason.includes("failed")) {
|
|
2177
|
+
return "failed";
|
|
2178
|
+
}
|
|
2179
|
+
if (reason.includes("review")) {
|
|
2180
|
+
return "review";
|
|
2181
|
+
}
|
|
2182
|
+
return "new";
|
|
2183
|
+
}
|
|
2184
|
+
function isGenerator(impl) {
|
|
2185
|
+
return NavigatorRoles[impl] === "generator" /* GENERATOR */;
|
|
2186
|
+
}
|
|
2187
|
+
function isFilter(impl) {
|
|
2188
|
+
return NavigatorRoles[impl] === "filter" /* FILTER */;
|
|
2189
|
+
}
|
|
2190
|
+
var Navigators, NavigatorRole, NavigatorRoles, ContentNavigator;
|
|
624
2191
|
var init_navigators = __esm({
|
|
625
2192
|
"src/core/navigators/index.ts"() {
|
|
626
2193
|
"use strict";
|
|
@@ -628,14 +2195,103 @@ var init_navigators = __esm({
|
|
|
628
2195
|
init_();
|
|
629
2196
|
Navigators = /* @__PURE__ */ ((Navigators2) => {
|
|
630
2197
|
Navigators2["ELO"] = "elo";
|
|
2198
|
+
Navigators2["SRS"] = "srs";
|
|
631
2199
|
Navigators2["HARDCODED"] = "hardcodedOrder";
|
|
2200
|
+
Navigators2["HIERARCHY"] = "hierarchyDefinition";
|
|
2201
|
+
Navigators2["INTERFERENCE"] = "interferenceMitigator";
|
|
2202
|
+
Navigators2["RELATIVE_PRIORITY"] = "relativePriority";
|
|
2203
|
+
Navigators2["USER_TAG_PREFERENCE"] = "userTagPreference";
|
|
632
2204
|
return Navigators2;
|
|
633
2205
|
})(Navigators || {});
|
|
2206
|
+
NavigatorRole = /* @__PURE__ */ ((NavigatorRole2) => {
|
|
2207
|
+
NavigatorRole2["GENERATOR"] = "generator";
|
|
2208
|
+
NavigatorRole2["FILTER"] = "filter";
|
|
2209
|
+
return NavigatorRole2;
|
|
2210
|
+
})(NavigatorRole || {});
|
|
2211
|
+
NavigatorRoles = {
|
|
2212
|
+
["elo" /* ELO */]: "generator" /* GENERATOR */,
|
|
2213
|
+
["srs" /* SRS */]: "generator" /* GENERATOR */,
|
|
2214
|
+
["hardcodedOrder" /* HARDCODED */]: "generator" /* GENERATOR */,
|
|
2215
|
+
["hierarchyDefinition" /* HIERARCHY */]: "filter" /* FILTER */,
|
|
2216
|
+
["interferenceMitigator" /* INTERFERENCE */]: "filter" /* FILTER */,
|
|
2217
|
+
["relativePriority" /* RELATIVE_PRIORITY */]: "filter" /* FILTER */,
|
|
2218
|
+
["userTagPreference" /* USER_TAG_PREFERENCE */]: "filter" /* FILTER */
|
|
2219
|
+
};
|
|
634
2220
|
ContentNavigator = class {
|
|
2221
|
+
/** User interface for this navigation session */
|
|
2222
|
+
user;
|
|
2223
|
+
/** Course interface for this navigation session */
|
|
2224
|
+
course;
|
|
2225
|
+
/** Human-readable name for this strategy instance (from ContentNavigationStrategyData.name) */
|
|
2226
|
+
strategyName;
|
|
2227
|
+
/** Unique document ID for this strategy instance (from ContentNavigationStrategyData._id) */
|
|
2228
|
+
strategyId;
|
|
2229
|
+
/**
|
|
2230
|
+
* Constructor for standard navigators.
|
|
2231
|
+
* Call this from subclass constructors to initialize common fields.
|
|
2232
|
+
*
|
|
2233
|
+
* Note: CompositeGenerator doesn't use this pattern and should call super() without args.
|
|
2234
|
+
*/
|
|
2235
|
+
constructor(user, course, strategyData) {
|
|
2236
|
+
if (user && course && strategyData) {
|
|
2237
|
+
this.user = user;
|
|
2238
|
+
this.course = course;
|
|
2239
|
+
this.strategyName = strategyData.name;
|
|
2240
|
+
this.strategyId = strategyData._id;
|
|
2241
|
+
}
|
|
2242
|
+
}
|
|
2243
|
+
// ============================================================================
|
|
2244
|
+
// STRATEGY STATE HELPERS
|
|
2245
|
+
// ============================================================================
|
|
2246
|
+
//
|
|
2247
|
+
// These methods allow strategies to persist their own state (user preferences,
|
|
2248
|
+
// learned patterns, temporal tracking) in the user database.
|
|
2249
|
+
//
|
|
2250
|
+
// ============================================================================
|
|
2251
|
+
/**
|
|
2252
|
+
* Unique key identifying this strategy for state storage.
|
|
2253
|
+
*
|
|
2254
|
+
* Defaults to the constructor name (e.g., "UserTagPreferenceFilter").
|
|
2255
|
+
* Override in subclasses if multiple instances of the same strategy type
|
|
2256
|
+
* need separate state storage.
|
|
2257
|
+
*/
|
|
2258
|
+
get strategyKey() {
|
|
2259
|
+
return this.constructor.name;
|
|
2260
|
+
}
|
|
2261
|
+
/**
|
|
2262
|
+
* Get this strategy's persisted state for the current course.
|
|
2263
|
+
*
|
|
2264
|
+
* @returns The strategy's data payload, or null if no state exists
|
|
2265
|
+
* @throws Error if user or course is not initialized
|
|
2266
|
+
*/
|
|
2267
|
+
async getStrategyState() {
|
|
2268
|
+
if (!this.user || !this.course) {
|
|
2269
|
+
throw new Error(
|
|
2270
|
+
`Cannot get strategy state: navigator not properly initialized. Ensure user and course are provided to constructor.`
|
|
2271
|
+
);
|
|
2272
|
+
}
|
|
2273
|
+
return this.user.getStrategyState(this.course.getCourseID(), this.strategyKey);
|
|
2274
|
+
}
|
|
2275
|
+
/**
|
|
2276
|
+
* Persist this strategy's state for the current course.
|
|
2277
|
+
*
|
|
2278
|
+
* @param data - The strategy's data payload to store
|
|
2279
|
+
* @throws Error if user or course is not initialized
|
|
2280
|
+
*/
|
|
2281
|
+
async putStrategyState(data) {
|
|
2282
|
+
if (!this.user || !this.course) {
|
|
2283
|
+
throw new Error(
|
|
2284
|
+
`Cannot put strategy state: navigator not properly initialized. Ensure user and course are provided to constructor.`
|
|
2285
|
+
);
|
|
2286
|
+
}
|
|
2287
|
+
return this.user.putStrategyState(this.course.getCourseID(), this.strategyKey, data);
|
|
2288
|
+
}
|
|
635
2289
|
/**
|
|
2290
|
+
* Factory method to create navigator instances dynamically.
|
|
636
2291
|
*
|
|
637
|
-
* @param user
|
|
638
|
-
* @param
|
|
2292
|
+
* @param user - User interface
|
|
2293
|
+
* @param course - Course interface
|
|
2294
|
+
* @param strategyData - Strategy configuration document
|
|
639
2295
|
* @returns the runtime object used to steer a study session.
|
|
640
2296
|
*/
|
|
641
2297
|
static async create(user, course, strategyData) {
|
|
@@ -656,6 +2312,70 @@ var init_navigators = __esm({
|
|
|
656
2312
|
}
|
|
657
2313
|
return new NavigatorImpl(user, course, strategyData);
|
|
658
2314
|
}
|
|
2315
|
+
/**
|
|
2316
|
+
* Get cards with suitability scores and provenance trails.
|
|
2317
|
+
*
|
|
2318
|
+
* **This is the PRIMARY API for navigation strategies.**
|
|
2319
|
+
*
|
|
2320
|
+
* Returns cards ranked by suitability score (0-1). Higher scores indicate
|
|
2321
|
+
* better candidates for presentation. Each card includes a provenance trail
|
|
2322
|
+
* documenting how strategies contributed to the final score.
|
|
2323
|
+
*
|
|
2324
|
+
* ## For Generators
|
|
2325
|
+
* Override this method to generate candidates and compute scores based on
|
|
2326
|
+
* your strategy's logic (e.g., ELO proximity, review urgency). Create the
|
|
2327
|
+
* initial provenance entry with action='generated'.
|
|
2328
|
+
*
|
|
2329
|
+
* ## Default Implementation
|
|
2330
|
+
* The base class provides a backward-compatible default that:
|
|
2331
|
+
* 1. Calls legacy getNewCards() and getPendingReviews()
|
|
2332
|
+
* 2. Assigns score=1.0 to all cards
|
|
2333
|
+
* 3. Creates minimal provenance from legacy methods
|
|
2334
|
+
* 4. Returns combined results up to limit
|
|
2335
|
+
*
|
|
2336
|
+
* This allows existing strategies to work without modification while
|
|
2337
|
+
* new strategies can override with proper scoring and provenance.
|
|
2338
|
+
*
|
|
2339
|
+
* @param limit - Maximum cards to return
|
|
2340
|
+
* @returns Cards sorted by score descending, with provenance trails
|
|
2341
|
+
*/
|
|
2342
|
+
async getWeightedCards(limit) {
|
|
2343
|
+
const newCards = await this.getNewCards(limit);
|
|
2344
|
+
const reviews = await this.getPendingReviews();
|
|
2345
|
+
const weighted = [
|
|
2346
|
+
...newCards.map((c) => ({
|
|
2347
|
+
cardId: c.cardID,
|
|
2348
|
+
courseId: c.courseID,
|
|
2349
|
+
score: 1,
|
|
2350
|
+
provenance: [
|
|
2351
|
+
{
|
|
2352
|
+
strategy: "legacy",
|
|
2353
|
+
strategyName: this.strategyName || "Legacy API",
|
|
2354
|
+
strategyId: this.strategyId || "legacy-fallback",
|
|
2355
|
+
action: "generated",
|
|
2356
|
+
score: 1,
|
|
2357
|
+
reason: "Generated via legacy getNewCards(), new card"
|
|
2358
|
+
}
|
|
2359
|
+
]
|
|
2360
|
+
})),
|
|
2361
|
+
...reviews.map((r) => ({
|
|
2362
|
+
cardId: r.cardID,
|
|
2363
|
+
courseId: r.courseID,
|
|
2364
|
+
score: 1,
|
|
2365
|
+
provenance: [
|
|
2366
|
+
{
|
|
2367
|
+
strategy: "legacy",
|
|
2368
|
+
strategyName: this.strategyName || "Legacy API",
|
|
2369
|
+
strategyId: this.strategyId || "legacy-fallback",
|
|
2370
|
+
action: "generated",
|
|
2371
|
+
score: 1,
|
|
2372
|
+
reason: "Generated via legacy getPendingReviews(), review"
|
|
2373
|
+
}
|
|
2374
|
+
]
|
|
2375
|
+
}))
|
|
2376
|
+
];
|
|
2377
|
+
return weighted.slice(0, limit);
|
|
2378
|
+
}
|
|
659
2379
|
};
|
|
660
2380
|
}
|
|
661
2381
|
});
|
|
@@ -665,7 +2385,7 @@ import {
|
|
|
665
2385
|
EloToNumber,
|
|
666
2386
|
Status,
|
|
667
2387
|
blankCourseElo as blankCourseElo2,
|
|
668
|
-
toCourseElo as
|
|
2388
|
+
toCourseElo as toCourseElo6
|
|
669
2389
|
} from "@vue-skuilder/common";
|
|
670
2390
|
var init_courseDB = __esm({
|
|
671
2391
|
"src/impl/couch/courseDB.ts"() {
|
|
@@ -678,11 +2398,17 @@ var init_courseDB = __esm({
|
|
|
678
2398
|
init_courseAPI();
|
|
679
2399
|
init_courseLookupDB();
|
|
680
2400
|
init_navigators();
|
|
2401
|
+
init_Pipeline();
|
|
2402
|
+
init_PipelineAssembler();
|
|
2403
|
+
init_CompositeGenerator();
|
|
2404
|
+
init_elo();
|
|
2405
|
+
init_srs();
|
|
2406
|
+
init_eloDistance();
|
|
681
2407
|
}
|
|
682
2408
|
});
|
|
683
2409
|
|
|
684
2410
|
// src/impl/couch/classroomDB.ts
|
|
685
|
-
import
|
|
2411
|
+
import moment4 from "moment";
|
|
686
2412
|
var init_classroomDB2 = __esm({
|
|
687
2413
|
"src/impl/couch/classroomDB.ts"() {
|
|
688
2414
|
"use strict";
|
|
@@ -734,7 +2460,7 @@ var init_CouchDBSyncStrategy = __esm({
|
|
|
734
2460
|
|
|
735
2461
|
// src/impl/couch/index.ts
|
|
736
2462
|
import fetch3 from "cross-fetch";
|
|
737
|
-
import
|
|
2463
|
+
import moment5 from "moment";
|
|
738
2464
|
import process2 from "process";
|
|
739
2465
|
function createPouchDBConfig() {
|
|
740
2466
|
const hasExplicitCredentials = ENV.COUCHDB_USERNAME && ENV.COUCHDB_PASSWORD;
|
|
@@ -786,11 +2512,13 @@ var init_couch = __esm({
|
|
|
786
2512
|
|
|
787
2513
|
// src/impl/common/BaseUserDB.ts
|
|
788
2514
|
import { Status as Status3 } from "@vue-skuilder/common";
|
|
789
|
-
import
|
|
2515
|
+
import moment6 from "moment";
|
|
790
2516
|
function accomodateGuest() {
|
|
791
2517
|
logger.log("[funnel] accomodateGuest() called");
|
|
792
2518
|
if (typeof localStorage === "undefined") {
|
|
793
|
-
logger.log(
|
|
2519
|
+
logger.log(
|
|
2520
|
+
"[funnel] localStorage not available (Node.js environment), returning default guest"
|
|
2521
|
+
);
|
|
794
2522
|
return {
|
|
795
2523
|
username: GuestUsername + "nodejs-test",
|
|
796
2524
|
firstVisit: true
|
|
@@ -1224,7 +2952,7 @@ Currently logged-in as ${this._username}.`
|
|
|
1224
2952
|
);
|
|
1225
2953
|
return reviews.rows.filter((r) => {
|
|
1226
2954
|
if (r.id.startsWith(DocTypePrefixes["SCHEDULED_CARD" /* SCHEDULED_CARD */])) {
|
|
1227
|
-
const date =
|
|
2955
|
+
const date = moment6.utc(
|
|
1228
2956
|
r.id.substr(DocTypePrefixes["SCHEDULED_CARD" /* SCHEDULED_CARD */].length),
|
|
1229
2957
|
REVIEW_TIME_FORMAT
|
|
1230
2958
|
);
|
|
@@ -1237,11 +2965,11 @@ Currently logged-in as ${this._username}.`
|
|
|
1237
2965
|
}).map((r) => r.doc);
|
|
1238
2966
|
}
|
|
1239
2967
|
async getReviewsForcast(daysCount) {
|
|
1240
|
-
const time =
|
|
2968
|
+
const time = moment6.utc().add(daysCount, "days");
|
|
1241
2969
|
return this.getReviewstoDate(time);
|
|
1242
2970
|
}
|
|
1243
2971
|
async getPendingReviews(course_id) {
|
|
1244
|
-
const now =
|
|
2972
|
+
const now = moment6.utc();
|
|
1245
2973
|
return this.getReviewstoDate(now, course_id);
|
|
1246
2974
|
}
|
|
1247
2975
|
async getScheduledReviewCount(course_id) {
|
|
@@ -1528,7 +3256,7 @@ Currently logged-in as ${this._username}.`
|
|
|
1528
3256
|
*/
|
|
1529
3257
|
async putCardRecord(record) {
|
|
1530
3258
|
const cardHistoryID = getCardHistoryID(record.courseID, record.cardID);
|
|
1531
|
-
record.timeStamp =
|
|
3259
|
+
record.timeStamp = moment6.utc(record.timeStamp).toString();
|
|
1532
3260
|
try {
|
|
1533
3261
|
const cardHistory = await this.update(
|
|
1534
3262
|
cardHistoryID,
|
|
@@ -1544,7 +3272,7 @@ Currently logged-in as ${this._username}.`
|
|
|
1544
3272
|
const ret = {
|
|
1545
3273
|
...record2
|
|
1546
3274
|
};
|
|
1547
|
-
ret.timeStamp =
|
|
3275
|
+
ret.timeStamp = moment6.utc(record2.timeStamp);
|
|
1548
3276
|
return ret;
|
|
1549
3277
|
});
|
|
1550
3278
|
return cardHistory;
|
|
@@ -1768,6 +3496,55 @@ Currently logged-in as ${this._username}.`
|
|
|
1768
3496
|
async updateUserElo(courseId, elo) {
|
|
1769
3497
|
return updateUserElo(this._username, courseId, elo);
|
|
1770
3498
|
}
|
|
3499
|
+
async getStrategyState(courseId, strategyKey) {
|
|
3500
|
+
const docId = buildStrategyStateId(courseId, strategyKey);
|
|
3501
|
+
try {
|
|
3502
|
+
const doc = await this.localDB.get(docId);
|
|
3503
|
+
return doc.data;
|
|
3504
|
+
} catch (e) {
|
|
3505
|
+
const err = e;
|
|
3506
|
+
if (err.status === 404) {
|
|
3507
|
+
return null;
|
|
3508
|
+
}
|
|
3509
|
+
throw e;
|
|
3510
|
+
}
|
|
3511
|
+
}
|
|
3512
|
+
async putStrategyState(courseId, strategyKey, data) {
|
|
3513
|
+
const docId = buildStrategyStateId(courseId, strategyKey);
|
|
3514
|
+
let existingRev;
|
|
3515
|
+
try {
|
|
3516
|
+
const existing = await this.localDB.get(docId);
|
|
3517
|
+
existingRev = existing._rev;
|
|
3518
|
+
} catch (e) {
|
|
3519
|
+
const err = e;
|
|
3520
|
+
if (err.status !== 404) {
|
|
3521
|
+
throw e;
|
|
3522
|
+
}
|
|
3523
|
+
}
|
|
3524
|
+
const doc = {
|
|
3525
|
+
_id: docId,
|
|
3526
|
+
_rev: existingRev,
|
|
3527
|
+
docType: "STRATEGY_STATE" /* STRATEGY_STATE */,
|
|
3528
|
+
courseId,
|
|
3529
|
+
strategyKey,
|
|
3530
|
+
data,
|
|
3531
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
3532
|
+
};
|
|
3533
|
+
await this.localDB.put(doc);
|
|
3534
|
+
}
|
|
3535
|
+
async deleteStrategyState(courseId, strategyKey) {
|
|
3536
|
+
const docId = buildStrategyStateId(courseId, strategyKey);
|
|
3537
|
+
try {
|
|
3538
|
+
const doc = await this.localDB.get(docId);
|
|
3539
|
+
await this.localDB.remove(doc);
|
|
3540
|
+
} catch (e) {
|
|
3541
|
+
const err = e;
|
|
3542
|
+
if (err.status === 404) {
|
|
3543
|
+
return;
|
|
3544
|
+
}
|
|
3545
|
+
throw e;
|
|
3546
|
+
}
|
|
3547
|
+
}
|
|
1771
3548
|
};
|
|
1772
3549
|
userCoursesDoc = "CourseRegistrations";
|
|
1773
3550
|
userClassroomsDoc = "ClassroomRegistrations";
|
|
@@ -1800,12 +3577,24 @@ var init_factory = __esm({
|
|
|
1800
3577
|
}
|
|
1801
3578
|
});
|
|
1802
3579
|
|
|
3580
|
+
// src/study/TagFilteredContentSource.ts
|
|
3581
|
+
import { hasActiveFilter } from "@vue-skuilder/common";
|
|
3582
|
+
var init_TagFilteredContentSource = __esm({
|
|
3583
|
+
"src/study/TagFilteredContentSource.ts"() {
|
|
3584
|
+
"use strict";
|
|
3585
|
+
init_courseDB();
|
|
3586
|
+
init_logger();
|
|
3587
|
+
}
|
|
3588
|
+
});
|
|
3589
|
+
|
|
1803
3590
|
// src/core/interfaces/contentSource.ts
|
|
3591
|
+
import { hasActiveFilter as hasActiveFilter2 } from "@vue-skuilder/common";
|
|
1804
3592
|
var init_contentSource = __esm({
|
|
1805
3593
|
"src/core/interfaces/contentSource.ts"() {
|
|
1806
3594
|
"use strict";
|
|
1807
3595
|
init_factory();
|
|
1808
3596
|
init_classroomDB2();
|
|
3597
|
+
init_TagFilteredContentSource();
|
|
1809
3598
|
}
|
|
1810
3599
|
});
|
|
1811
3600
|
|
|
@@ -1850,6 +3639,16 @@ var init_user = __esm({
|
|
|
1850
3639
|
}
|
|
1851
3640
|
});
|
|
1852
3641
|
|
|
3642
|
+
// src/core/types/strategyState.ts
|
|
3643
|
+
function buildStrategyStateId(courseId, strategyKey) {
|
|
3644
|
+
return `STRATEGY_STATE::${courseId}::${strategyKey}`;
|
|
3645
|
+
}
|
|
3646
|
+
var init_strategyState = __esm({
|
|
3647
|
+
"src/core/types/strategyState.ts"() {
|
|
3648
|
+
"use strict";
|
|
3649
|
+
}
|
|
3650
|
+
});
|
|
3651
|
+
|
|
1853
3652
|
// src/core/bulkImport/cardProcessor.ts
|
|
1854
3653
|
import { Status as Status4 } from "@vue-skuilder/common";
|
|
1855
3654
|
var init_cardProcessor = __esm({
|
|
@@ -1860,7 +3659,7 @@ var init_cardProcessor = __esm({
|
|
|
1860
3659
|
});
|
|
1861
3660
|
|
|
1862
3661
|
// src/core/bulkImport/types.ts
|
|
1863
|
-
var
|
|
3662
|
+
var init_types3 = __esm({
|
|
1864
3663
|
"src/core/bulkImport/types.ts"() {
|
|
1865
3664
|
"use strict";
|
|
1866
3665
|
}
|
|
@@ -1871,7 +3670,7 @@ var init_bulkImport = __esm({
|
|
|
1871
3670
|
"src/core/bulkImport/index.ts"() {
|
|
1872
3671
|
"use strict";
|
|
1873
3672
|
init_cardProcessor();
|
|
1874
|
-
|
|
3673
|
+
init_types3();
|
|
1875
3674
|
}
|
|
1876
3675
|
});
|
|
1877
3676
|
|
|
@@ -1882,6 +3681,7 @@ var init_core = __esm({
|
|
|
1882
3681
|
init_interfaces();
|
|
1883
3682
|
init_types_legacy();
|
|
1884
3683
|
init_user();
|
|
3684
|
+
init_strategyState();
|
|
1885
3685
|
init_Loggable();
|
|
1886
3686
|
init_util();
|
|
1887
3687
|
init_navigators();
|
|
@@ -2454,6 +4254,14 @@ var init_courseDB3 = __esm({
|
|
|
2454
4254
|
};
|
|
2455
4255
|
}
|
|
2456
4256
|
}
|
|
4257
|
+
async getAppliedTagsBatch(cardIds) {
|
|
4258
|
+
const tagsIndex = await this.unpacker.getTagsIndex();
|
|
4259
|
+
const tagsByCard = /* @__PURE__ */ new Map();
|
|
4260
|
+
for (const cardId of cardIds) {
|
|
4261
|
+
tagsByCard.set(cardId, tagsIndex.byCard[cardId] || []);
|
|
4262
|
+
}
|
|
4263
|
+
return tagsByCard;
|
|
4264
|
+
}
|
|
2457
4265
|
async addTagToCard(_cardId, _tagId) {
|
|
2458
4266
|
throw new Error("Cannot modify tags in static mode");
|
|
2459
4267
|
}
|
|
@@ -2567,9 +4375,6 @@ var init_courseDB3 = __esm({
|
|
|
2567
4375
|
async updateNavigationStrategy(_id, _data) {
|
|
2568
4376
|
throw new Error("Cannot update navigation strategies in static mode");
|
|
2569
4377
|
}
|
|
2570
|
-
async surfaceNavigationStrategy() {
|
|
2571
|
-
return this.getNavigationStrategy("ELO");
|
|
2572
|
-
}
|
|
2573
4378
|
// Study Content Source implementation
|
|
2574
4379
|
async getPendingReviews() {
|
|
2575
4380
|
return [];
|