@vue-skuilder/db 0.1.16 → 0.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{userDB-DNa0XPtn.d.ts → classroomDB-BgfrVb8d.d.ts} +357 -103
- package/dist/{userDB-BqwxtJ_7.d.mts → classroomDB-CTOenngH.d.cts} +358 -104
- package/dist/core/index.d.cts +230 -0
- package/dist/core/index.d.ts +161 -23
- package/dist/core/index.js +1964 -154
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.mjs +1925 -121
- package/dist/core/index.mjs.map +1 -1
- package/dist/{dataLayerProvider-BV5iZqt_.d.ts → dataLayerProvider-CZxC9GtB.d.ts} +1 -1
- package/dist/{dataLayerProvider-VlngD19_.d.mts → dataLayerProvider-D6PoCwS6.d.cts} +1 -1
- package/dist/impl/couch/{index.d.mts → index.d.cts} +46 -5
- package/dist/impl/couch/index.d.ts +44 -3
- package/dist/impl/couch/index.js +1971 -171
- package/dist/impl/couch/index.js.map +1 -1
- package/dist/impl/couch/index.mjs +1933 -134
- package/dist/impl/couch/index.mjs.map +1 -1
- package/dist/impl/static/{index.d.mts → index.d.cts} +5 -6
- package/dist/impl/static/index.d.ts +2 -3
- package/dist/impl/static/index.js +1614 -119
- package/dist/impl/static/index.js.map +1 -1
- package/dist/impl/static/index.mjs +1585 -92
- package/dist/impl/static/index.mjs.map +1 -1
- package/dist/{index-Bmll7Xse.d.mts → index-D-Fa4Smt.d.cts} +1 -1
- package/dist/{index.d.mts → index.d.cts} +97 -13
- package/dist/index.d.ts +90 -6
- package/dist/index.js +2085 -153
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2031 -106
- package/dist/index.mjs.map +1 -1
- package/dist/pouch/index.js +3 -3
- package/dist/{types-Dbp5DaRR.d.mts → types-CzPDLAK6.d.cts} +1 -1
- package/dist/util/packer/{index.d.mts → index.d.cts} +3 -3
- package/dist/util/packer/index.js.map +1 -1
- package/dist/util/packer/index.mjs.map +1 -1
- package/docs/brainstorm-navigation-paradigm.md +369 -0
- package/docs/navigators-architecture.md +265 -0
- package/docs/todo-evolutionary-orchestration.md +310 -0
- package/docs/todo-nominal-tag-types.md +121 -0
- package/docs/todo-pipeline-optimization.md +117 -0
- package/docs/todo-strategy-authoring.md +401 -0
- package/docs/todo-strategy-state-storage.md +278 -0
- package/eslint.config.mjs +1 -1
- package/package.json +9 -4
- package/src/core/interfaces/contentSource.ts +88 -4
- package/src/core/interfaces/navigationStrategyManager.ts +0 -5
- package/src/core/navigators/CompositeGenerator.ts +268 -0
- package/src/core/navigators/Pipeline.ts +205 -0
- package/src/core/navigators/PipelineAssembler.ts +194 -0
- package/src/core/navigators/elo.ts +104 -15
- package/src/core/navigators/filters/eloDistance.ts +132 -0
- package/src/core/navigators/filters/index.ts +6 -0
- package/src/core/navigators/filters/types.ts +115 -0
- package/src/core/navigators/generators/index.ts +2 -0
- package/src/core/navigators/generators/types.ts +107 -0
- package/src/core/navigators/hardcodedOrder.ts +111 -12
- package/src/core/navigators/hierarchyDefinition.ts +266 -0
- package/src/core/navigators/index.ts +345 -3
- package/src/core/navigators/interferenceMitigator.ts +367 -0
- package/src/core/navigators/relativePriority.ts +267 -0
- package/src/core/navigators/srs.ts +195 -0
- package/src/impl/couch/classroomDB.ts +51 -0
- package/src/impl/couch/courseDB.ts +117 -39
- package/src/impl/static/courseDB.ts +0 -4
- package/src/study/SessionController.ts +149 -1
- package/src/study/TagFilteredContentSource.ts +255 -0
- package/src/study/index.ts +1 -0
- package/src/util/dataDirectory.test.ts +51 -22
- package/src/util/logger.ts +0 -1
- package/tests/core/navigators/CompositeGenerator.test.ts +455 -0
- package/tests/core/navigators/Pipeline.test.ts +405 -0
- package/tests/core/navigators/PipelineAssembler.test.ts +351 -0
- package/tests/core/navigators/SRSNavigator.test.ts +344 -0
- package/tests/core/navigators/eloDistanceFilter.test.ts +192 -0
- package/tests/core/navigators/navigators.test.ts +710 -0
- package/tsconfig.json +1 -1
- package/vitest.config.ts +29 -0
- package/dist/core/index.d.mts +0 -92
- /package/dist/{SyncStrategy-CyATpyLQ.d.mts → SyncStrategy-CyATpyLQ.d.cts} +0 -0
- /package/dist/pouch/{index.d.mts → index.d.cts} +0 -0
- /package/dist/{types-legacy-6ettoclI.d.mts → types-legacy-6ettoclI.d.cts} +0 -0
package/dist/impl/couch/index.js
CHANGED
|
@@ -106,9 +106,9 @@ var import_pouchdb, import_pouchdb_find, import_pouchdb_authentication, pouchdb_
|
|
|
106
106
|
var init_pouchdb_setup = __esm({
|
|
107
107
|
"src/impl/couch/pouchdb-setup.ts"() {
|
|
108
108
|
"use strict";
|
|
109
|
-
import_pouchdb = __toESM(require("pouchdb"));
|
|
110
|
-
import_pouchdb_find = __toESM(require("pouchdb-find"));
|
|
111
|
-
import_pouchdb_authentication = __toESM(require("@nilock2/pouchdb-authentication"));
|
|
109
|
+
import_pouchdb = __toESM(require("pouchdb"), 1);
|
|
110
|
+
import_pouchdb_find = __toESM(require("pouchdb-find"), 1);
|
|
111
|
+
import_pouchdb_authentication = __toESM(require("@nilock2/pouchdb-authentication"), 1);
|
|
112
112
|
import_pouchdb.default.plugin(import_pouchdb_find.default);
|
|
113
113
|
import_pouchdb.default.plugin(import_pouchdb_authentication.default);
|
|
114
114
|
import_pouchdb.default.defaults({
|
|
@@ -621,23 +621,460 @@ var init_courseLookupDB = __esm({
|
|
|
621
621
|
}
|
|
622
622
|
});
|
|
623
623
|
|
|
624
|
+
// src/core/navigators/CompositeGenerator.ts
|
|
625
|
+
var CompositeGenerator_exports = {};
|
|
626
|
+
__export(CompositeGenerator_exports, {
|
|
627
|
+
AggregationMode: () => AggregationMode,
|
|
628
|
+
default: () => CompositeGenerator
|
|
629
|
+
});
|
|
630
|
+
var AggregationMode, DEFAULT_AGGREGATION_MODE, FREQUENCY_BOOST_FACTOR, CompositeGenerator;
|
|
631
|
+
var init_CompositeGenerator = __esm({
|
|
632
|
+
"src/core/navigators/CompositeGenerator.ts"() {
|
|
633
|
+
"use strict";
|
|
634
|
+
init_navigators();
|
|
635
|
+
init_logger();
|
|
636
|
+
AggregationMode = /* @__PURE__ */ ((AggregationMode2) => {
|
|
637
|
+
AggregationMode2["MAX"] = "max";
|
|
638
|
+
AggregationMode2["AVERAGE"] = "average";
|
|
639
|
+
AggregationMode2["FREQUENCY_BOOST"] = "frequencyBoost";
|
|
640
|
+
return AggregationMode2;
|
|
641
|
+
})(AggregationMode || {});
|
|
642
|
+
DEFAULT_AGGREGATION_MODE = "frequencyBoost" /* FREQUENCY_BOOST */;
|
|
643
|
+
FREQUENCY_BOOST_FACTOR = 0.1;
|
|
644
|
+
CompositeGenerator = class _CompositeGenerator extends ContentNavigator {
|
|
645
|
+
/** Human-readable name for CardGenerator interface */
|
|
646
|
+
name = "Composite Generator";
|
|
647
|
+
generators;
|
|
648
|
+
aggregationMode;
|
|
649
|
+
constructor(generators, aggregationMode = DEFAULT_AGGREGATION_MODE) {
|
|
650
|
+
super();
|
|
651
|
+
this.generators = generators;
|
|
652
|
+
this.aggregationMode = aggregationMode;
|
|
653
|
+
if (generators.length === 0) {
|
|
654
|
+
throw new Error("CompositeGenerator requires at least one generator");
|
|
655
|
+
}
|
|
656
|
+
logger.debug(
|
|
657
|
+
`[CompositeGenerator] Created with ${generators.length} generators, mode: ${aggregationMode}`
|
|
658
|
+
);
|
|
659
|
+
}
|
|
660
|
+
/**
|
|
661
|
+
* Creates a CompositeGenerator from strategy data.
|
|
662
|
+
*
|
|
663
|
+
* This is a convenience factory for use by PipelineAssembler.
|
|
664
|
+
*/
|
|
665
|
+
static async fromStrategies(user, course, strategies, aggregationMode = DEFAULT_AGGREGATION_MODE) {
|
|
666
|
+
const generators = await Promise.all(
|
|
667
|
+
strategies.map((s) => ContentNavigator.create(user, course, s))
|
|
668
|
+
);
|
|
669
|
+
return new _CompositeGenerator(generators, aggregationMode);
|
|
670
|
+
}
|
|
671
|
+
/**
|
|
672
|
+
* Get weighted cards from all generators, merge and deduplicate.
|
|
673
|
+
*
|
|
674
|
+
* Cards appearing in multiple generators receive a score boost.
|
|
675
|
+
* Provenance tracks which generators produced each card and how scores were aggregated.
|
|
676
|
+
*
|
|
677
|
+
* This method supports both the legacy signature (limit only) and the
|
|
678
|
+
* CardGenerator interface signature (limit, context).
|
|
679
|
+
*
|
|
680
|
+
* @param limit - Maximum number of cards to return
|
|
681
|
+
* @param context - Optional GeneratorContext passed to child generators
|
|
682
|
+
*/
|
|
683
|
+
async getWeightedCards(limit, context) {
|
|
684
|
+
const results = await Promise.all(
|
|
685
|
+
this.generators.map((g) => g.getWeightedCards(limit, context))
|
|
686
|
+
);
|
|
687
|
+
const byCardId = /* @__PURE__ */ new Map();
|
|
688
|
+
for (const cards of results) {
|
|
689
|
+
for (const card of cards) {
|
|
690
|
+
const existing = byCardId.get(card.cardId) || [];
|
|
691
|
+
existing.push(card);
|
|
692
|
+
byCardId.set(card.cardId, existing);
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
const merged = [];
|
|
696
|
+
for (const [, cards] of byCardId) {
|
|
697
|
+
const aggregatedScore = this.aggregateScores(cards);
|
|
698
|
+
const finalScore = Math.min(1, aggregatedScore);
|
|
699
|
+
const mergedProvenance = cards.flatMap((c) => c.provenance);
|
|
700
|
+
const initialScore = cards[0].score;
|
|
701
|
+
const action = finalScore > initialScore ? "boosted" : finalScore < initialScore ? "penalized" : "passed";
|
|
702
|
+
const reason = this.buildAggregationReason(cards, finalScore);
|
|
703
|
+
merged.push({
|
|
704
|
+
...cards[0],
|
|
705
|
+
score: finalScore,
|
|
706
|
+
provenance: [
|
|
707
|
+
...mergedProvenance,
|
|
708
|
+
{
|
|
709
|
+
strategy: "composite",
|
|
710
|
+
strategyName: "Composite Generator",
|
|
711
|
+
strategyId: "COMPOSITE_GENERATOR",
|
|
712
|
+
action,
|
|
713
|
+
score: finalScore,
|
|
714
|
+
reason
|
|
715
|
+
}
|
|
716
|
+
]
|
|
717
|
+
});
|
|
718
|
+
}
|
|
719
|
+
return merged.sort((a, b) => b.score - a.score).slice(0, limit);
|
|
720
|
+
}
|
|
721
|
+
/**
|
|
722
|
+
* Build human-readable reason for score aggregation.
|
|
723
|
+
*/
|
|
724
|
+
buildAggregationReason(cards, finalScore) {
|
|
725
|
+
const count = cards.length;
|
|
726
|
+
const scores = cards.map((c) => c.score.toFixed(2)).join(", ");
|
|
727
|
+
if (count === 1) {
|
|
728
|
+
return `Single generator, score ${finalScore.toFixed(2)}`;
|
|
729
|
+
}
|
|
730
|
+
const strategies = cards.map((c) => c.provenance[0]?.strategy || "unknown").join(", ");
|
|
731
|
+
switch (this.aggregationMode) {
|
|
732
|
+
case "max" /* MAX */:
|
|
733
|
+
return `Max of ${count} generators (${strategies}): scores [${scores}] \u2192 ${finalScore.toFixed(2)}`;
|
|
734
|
+
case "average" /* AVERAGE */:
|
|
735
|
+
return `Average of ${count} generators (${strategies}): scores [${scores}] \u2192 ${finalScore.toFixed(2)}`;
|
|
736
|
+
case "frequencyBoost" /* FREQUENCY_BOOST */: {
|
|
737
|
+
const avg = cards.reduce((sum, c) => sum + c.score, 0) / count;
|
|
738
|
+
const boost = 1 + FREQUENCY_BOOST_FACTOR * (count - 1);
|
|
739
|
+
return `Frequency boost from ${count} generators (${strategies}): avg ${avg.toFixed(2)} \xD7 ${boost.toFixed(2)} \u2192 ${finalScore.toFixed(2)}`;
|
|
740
|
+
}
|
|
741
|
+
default:
|
|
742
|
+
return `Aggregated from ${count} generators: ${finalScore.toFixed(2)}`;
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
/**
|
|
746
|
+
* Aggregate scores from multiple generators for the same card.
|
|
747
|
+
*/
|
|
748
|
+
aggregateScores(cards) {
|
|
749
|
+
const scores = cards.map((c) => c.score);
|
|
750
|
+
switch (this.aggregationMode) {
|
|
751
|
+
case "max" /* MAX */:
|
|
752
|
+
return Math.max(...scores);
|
|
753
|
+
case "average" /* AVERAGE */:
|
|
754
|
+
return scores.reduce((sum, s) => sum + s, 0) / scores.length;
|
|
755
|
+
case "frequencyBoost" /* FREQUENCY_BOOST */: {
|
|
756
|
+
const avg = scores.reduce((sum, s) => sum + s, 0) / scores.length;
|
|
757
|
+
const frequencyBoost = 1 + FREQUENCY_BOOST_FACTOR * (cards.length - 1);
|
|
758
|
+
return avg * frequencyBoost;
|
|
759
|
+
}
|
|
760
|
+
default:
|
|
761
|
+
return scores[0];
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
/**
|
|
765
|
+
* Get new cards from all generators, merged and deduplicated.
|
|
766
|
+
*/
|
|
767
|
+
async getNewCards(n) {
|
|
768
|
+
const legacyGenerators = this.generators.filter(
|
|
769
|
+
(g) => g instanceof ContentNavigator
|
|
770
|
+
);
|
|
771
|
+
const results = await Promise.all(legacyGenerators.map((g) => g.getNewCards(n)));
|
|
772
|
+
const seen = /* @__PURE__ */ new Set();
|
|
773
|
+
const merged = [];
|
|
774
|
+
for (const cards of results) {
|
|
775
|
+
for (const card of cards) {
|
|
776
|
+
if (!seen.has(card.cardID)) {
|
|
777
|
+
seen.add(card.cardID);
|
|
778
|
+
merged.push(card);
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
return n ? merged.slice(0, n) : merged;
|
|
783
|
+
}
|
|
784
|
+
/**
|
|
785
|
+
* Get pending reviews from all generators, merged and deduplicated.
|
|
786
|
+
*/
|
|
787
|
+
async getPendingReviews() {
|
|
788
|
+
const legacyGenerators = this.generators.filter(
|
|
789
|
+
(g) => g instanceof ContentNavigator
|
|
790
|
+
);
|
|
791
|
+
const results = await Promise.all(legacyGenerators.map((g) => g.getPendingReviews()));
|
|
792
|
+
const seen = /* @__PURE__ */ new Set();
|
|
793
|
+
const merged = [];
|
|
794
|
+
for (const reviews of results) {
|
|
795
|
+
for (const review of reviews) {
|
|
796
|
+
if (!seen.has(review.cardID)) {
|
|
797
|
+
seen.add(review.cardID);
|
|
798
|
+
merged.push(review);
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
return merged;
|
|
803
|
+
}
|
|
804
|
+
};
|
|
805
|
+
}
|
|
806
|
+
});
|
|
807
|
+
|
|
808
|
+
// src/core/navigators/Pipeline.ts
|
|
809
|
+
var Pipeline_exports = {};
|
|
810
|
+
__export(Pipeline_exports, {
|
|
811
|
+
Pipeline: () => Pipeline
|
|
812
|
+
});
|
|
813
|
+
var import_common5, Pipeline;
|
|
814
|
+
var init_Pipeline = __esm({
|
|
815
|
+
"src/core/navigators/Pipeline.ts"() {
|
|
816
|
+
"use strict";
|
|
817
|
+
import_common5 = require("@vue-skuilder/common");
|
|
818
|
+
init_navigators();
|
|
819
|
+
init_logger();
|
|
820
|
+
Pipeline = class extends ContentNavigator {
|
|
821
|
+
generator;
|
|
822
|
+
filters;
|
|
823
|
+
/**
|
|
824
|
+
* Create a new pipeline.
|
|
825
|
+
*
|
|
826
|
+
* @param generator - The generator (or CompositeGenerator) that produces candidates
|
|
827
|
+
* @param filters - Filters to apply sequentially (order doesn't matter for multipliers)
|
|
828
|
+
* @param user - User database interface
|
|
829
|
+
* @param course - Course database interface
|
|
830
|
+
*/
|
|
831
|
+
constructor(generator, filters, user, course) {
|
|
832
|
+
super();
|
|
833
|
+
this.generator = generator;
|
|
834
|
+
this.filters = filters;
|
|
835
|
+
this.user = user;
|
|
836
|
+
this.course = course;
|
|
837
|
+
logger.debug(
|
|
838
|
+
`[Pipeline] Created with generator '${generator.name}' and ${filters.length} filters: ${filters.map((f) => f.name).join(", ")}`
|
|
839
|
+
);
|
|
840
|
+
}
|
|
841
|
+
/**
|
|
842
|
+
* Get weighted cards by running generator and applying filters.
|
|
843
|
+
*
|
|
844
|
+
* 1. Build shared context (user ELO, etc.)
|
|
845
|
+
* 2. Get candidates from generator (passing context)
|
|
846
|
+
* 3. Apply each filter sequentially
|
|
847
|
+
* 4. Remove zero-score cards
|
|
848
|
+
* 5. Sort by score descending
|
|
849
|
+
* 6. Return top N
|
|
850
|
+
*
|
|
851
|
+
* @param limit - Maximum number of cards to return
|
|
852
|
+
* @returns Cards sorted by score descending
|
|
853
|
+
*/
|
|
854
|
+
async getWeightedCards(limit) {
|
|
855
|
+
const context = await this.buildContext();
|
|
856
|
+
const overFetchMultiplier = 2 + this.filters.length * 0.5;
|
|
857
|
+
const fetchLimit = Math.ceil(limit * overFetchMultiplier);
|
|
858
|
+
logger.debug(
|
|
859
|
+
`[Pipeline] Fetching ${fetchLimit} candidates from generator '${this.generator.name}'`
|
|
860
|
+
);
|
|
861
|
+
let cards = await this.generator.getWeightedCards(fetchLimit, context);
|
|
862
|
+
logger.debug(`[Pipeline] Generator returned ${cards.length} candidates`);
|
|
863
|
+
for (const filter of this.filters) {
|
|
864
|
+
const beforeCount = cards.length;
|
|
865
|
+
cards = await filter.transform(cards, context);
|
|
866
|
+
logger.debug(`[Pipeline] Filter '${filter.name}': ${beforeCount} \u2192 ${cards.length} cards`);
|
|
867
|
+
}
|
|
868
|
+
cards = cards.filter((c) => c.score > 0);
|
|
869
|
+
cards.sort((a, b) => b.score - a.score);
|
|
870
|
+
const result = cards.slice(0, limit);
|
|
871
|
+
logger.debug(
|
|
872
|
+
`[Pipeline] Returning ${result.length} cards (top scores: ${result.slice(0, 3).map((c) => c.score.toFixed(2)).join(", ")}...)`
|
|
873
|
+
);
|
|
874
|
+
return result;
|
|
875
|
+
}
|
|
876
|
+
/**
|
|
877
|
+
* Build shared context for generator and filters.
|
|
878
|
+
*
|
|
879
|
+
* Called once per getWeightedCards() invocation.
|
|
880
|
+
* Contains data that the generator and multiple filters might need.
|
|
881
|
+
*
|
|
882
|
+
* The context satisfies both GeneratorContext and FilterContext interfaces.
|
|
883
|
+
*/
|
|
884
|
+
async buildContext() {
|
|
885
|
+
let userElo = 1e3;
|
|
886
|
+
try {
|
|
887
|
+
const courseReg = await this.user.getCourseRegDoc(this.course.getCourseID());
|
|
888
|
+
const courseElo = (0, import_common5.toCourseElo)(courseReg.elo);
|
|
889
|
+
userElo = courseElo.global.score;
|
|
890
|
+
} catch (e) {
|
|
891
|
+
logger.debug(`[Pipeline] Could not get user ELO, using default: ${e}`);
|
|
892
|
+
}
|
|
893
|
+
return {
|
|
894
|
+
user: this.user,
|
|
895
|
+
course: this.course,
|
|
896
|
+
userElo
|
|
897
|
+
};
|
|
898
|
+
}
|
|
899
|
+
// ===========================================================================
|
|
900
|
+
// Legacy StudyContentSource methods
|
|
901
|
+
// ===========================================================================
|
|
902
|
+
//
|
|
903
|
+
// These delegate to the generator for backward compatibility.
|
|
904
|
+
// Eventually SessionController will use getWeightedCards() exclusively.
|
|
905
|
+
//
|
|
906
|
+
/**
|
|
907
|
+
* Get new cards via legacy API.
|
|
908
|
+
* Delegates to the generator if it supports the legacy interface.
|
|
909
|
+
*/
|
|
910
|
+
async getNewCards(n) {
|
|
911
|
+
if ("getNewCards" in this.generator && typeof this.generator.getNewCards === "function") {
|
|
912
|
+
return this.generator.getNewCards(n);
|
|
913
|
+
}
|
|
914
|
+
return [];
|
|
915
|
+
}
|
|
916
|
+
/**
|
|
917
|
+
* Get pending reviews via legacy API.
|
|
918
|
+
* Delegates to the generator if it supports the legacy interface.
|
|
919
|
+
*/
|
|
920
|
+
async getPendingReviews() {
|
|
921
|
+
if ("getPendingReviews" in this.generator && typeof this.generator.getPendingReviews === "function") {
|
|
922
|
+
return this.generator.getPendingReviews();
|
|
923
|
+
}
|
|
924
|
+
return [];
|
|
925
|
+
}
|
|
926
|
+
/**
|
|
927
|
+
* Get the course ID for this pipeline.
|
|
928
|
+
*/
|
|
929
|
+
getCourseID() {
|
|
930
|
+
return this.course.getCourseID();
|
|
931
|
+
}
|
|
932
|
+
};
|
|
933
|
+
}
|
|
934
|
+
});
|
|
935
|
+
|
|
936
|
+
// src/core/navigators/PipelineAssembler.ts
|
|
937
|
+
var PipelineAssembler_exports = {};
|
|
938
|
+
__export(PipelineAssembler_exports, {
|
|
939
|
+
PipelineAssembler: () => PipelineAssembler
|
|
940
|
+
});
|
|
941
|
+
var PipelineAssembler;
|
|
942
|
+
var init_PipelineAssembler = __esm({
|
|
943
|
+
"src/core/navigators/PipelineAssembler.ts"() {
|
|
944
|
+
"use strict";
|
|
945
|
+
init_navigators();
|
|
946
|
+
init_Pipeline();
|
|
947
|
+
init_types_legacy();
|
|
948
|
+
init_logger();
|
|
949
|
+
init_CompositeGenerator();
|
|
950
|
+
PipelineAssembler = class {
|
|
951
|
+
/**
|
|
952
|
+
* Assembles a navigation pipeline from strategy documents.
|
|
953
|
+
*
|
|
954
|
+
* 1. Separates into generators and filters by role
|
|
955
|
+
* 2. Validates at least one generator exists (or creates default ELO)
|
|
956
|
+
* 3. Instantiates generators - wraps multiple in CompositeGenerator
|
|
957
|
+
* 4. Instantiates filters
|
|
958
|
+
* 5. Returns Pipeline(generator, filters)
|
|
959
|
+
*
|
|
960
|
+
* @param input - Strategy documents plus user/course interfaces
|
|
961
|
+
* @returns Assembled pipeline and any warnings
|
|
962
|
+
*/
|
|
963
|
+
async assemble(input) {
|
|
964
|
+
const { strategies, user, course } = input;
|
|
965
|
+
const warnings = [];
|
|
966
|
+
if (strategies.length === 0) {
|
|
967
|
+
return {
|
|
968
|
+
pipeline: null,
|
|
969
|
+
generatorStrategies: [],
|
|
970
|
+
filterStrategies: [],
|
|
971
|
+
warnings
|
|
972
|
+
};
|
|
973
|
+
}
|
|
974
|
+
const generatorStrategies = [];
|
|
975
|
+
const filterStrategies = [];
|
|
976
|
+
for (const s of strategies) {
|
|
977
|
+
if (isGenerator(s.implementingClass)) {
|
|
978
|
+
generatorStrategies.push(s);
|
|
979
|
+
} else if (isFilter(s.implementingClass)) {
|
|
980
|
+
filterStrategies.push(s);
|
|
981
|
+
} else {
|
|
982
|
+
warnings.push(`Unknown strategy type '${s.implementingClass}', skipping: ${s.name}`);
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
if (generatorStrategies.length === 0) {
|
|
986
|
+
if (filterStrategies.length > 0) {
|
|
987
|
+
logger.debug(
|
|
988
|
+
"[PipelineAssembler] No generator found, using default ELO with configured filters"
|
|
989
|
+
);
|
|
990
|
+
generatorStrategies.push(this.makeDefaultEloStrategy(course.getCourseID()));
|
|
991
|
+
} else {
|
|
992
|
+
warnings.push("No generator strategy found");
|
|
993
|
+
return {
|
|
994
|
+
pipeline: null,
|
|
995
|
+
generatorStrategies: [],
|
|
996
|
+
filterStrategies: [],
|
|
997
|
+
warnings
|
|
998
|
+
};
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
let generator;
|
|
1002
|
+
if (generatorStrategies.length === 1) {
|
|
1003
|
+
const nav = await ContentNavigator.create(user, course, generatorStrategies[0]);
|
|
1004
|
+
generator = nav;
|
|
1005
|
+
logger.debug(`[PipelineAssembler] Using single generator: ${generatorStrategies[0].name}`);
|
|
1006
|
+
} else {
|
|
1007
|
+
logger.debug(
|
|
1008
|
+
`[PipelineAssembler] Using CompositeGenerator for ${generatorStrategies.length} generators: ${generatorStrategies.map((g) => g.name).join(", ")}`
|
|
1009
|
+
);
|
|
1010
|
+
generator = await CompositeGenerator.fromStrategies(user, course, generatorStrategies);
|
|
1011
|
+
}
|
|
1012
|
+
const filters = [];
|
|
1013
|
+
const sortedFilterStrategies = [...filterStrategies].sort(
|
|
1014
|
+
(a, b) => a.name.localeCompare(b.name)
|
|
1015
|
+
);
|
|
1016
|
+
for (const filterStrategy of sortedFilterStrategies) {
|
|
1017
|
+
try {
|
|
1018
|
+
const nav = await ContentNavigator.create(user, course, filterStrategy);
|
|
1019
|
+
if ("transform" in nav && typeof nav.transform === "function") {
|
|
1020
|
+
filters.push(nav);
|
|
1021
|
+
logger.debug(`[PipelineAssembler] Added filter: ${filterStrategy.name}`);
|
|
1022
|
+
} else {
|
|
1023
|
+
warnings.push(
|
|
1024
|
+
`Filter '${filterStrategy.name}' does not implement CardFilter.transform(), skipping`
|
|
1025
|
+
);
|
|
1026
|
+
}
|
|
1027
|
+
} catch (e) {
|
|
1028
|
+
warnings.push(`Failed to instantiate filter '${filterStrategy.name}': ${e}`);
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
const pipeline = new Pipeline(generator, filters, user, course);
|
|
1032
|
+
logger.debug(
|
|
1033
|
+
`[PipelineAssembler] Assembled pipeline with ${generatorStrategies.length} generator(s) and ${filters.length} filter(s)`
|
|
1034
|
+
);
|
|
1035
|
+
return {
|
|
1036
|
+
pipeline,
|
|
1037
|
+
generatorStrategies,
|
|
1038
|
+
filterStrategies: sortedFilterStrategies,
|
|
1039
|
+
warnings
|
|
1040
|
+
};
|
|
1041
|
+
}
|
|
1042
|
+
/**
|
|
1043
|
+
* Creates a default ELO generator strategy.
|
|
1044
|
+
* Used when filters are configured but no generator is specified.
|
|
1045
|
+
*/
|
|
1046
|
+
makeDefaultEloStrategy(courseId) {
|
|
1047
|
+
return {
|
|
1048
|
+
_id: "NAVIGATION_STRATEGY-ELO-default",
|
|
1049
|
+
course: courseId,
|
|
1050
|
+
docType: "NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */,
|
|
1051
|
+
name: "ELO (default)",
|
|
1052
|
+
description: "Default ELO-based generator",
|
|
1053
|
+
implementingClass: "elo" /* ELO */,
|
|
1054
|
+
serializedData: ""
|
|
1055
|
+
};
|
|
1056
|
+
}
|
|
1057
|
+
};
|
|
1058
|
+
}
|
|
1059
|
+
});
|
|
1060
|
+
|
|
624
1061
|
// src/core/navigators/elo.ts
|
|
625
1062
|
var elo_exports = {};
|
|
626
1063
|
__export(elo_exports, {
|
|
627
1064
|
default: () => ELONavigator
|
|
628
1065
|
});
|
|
629
|
-
var ELONavigator;
|
|
1066
|
+
var import_common6, ELONavigator;
|
|
630
1067
|
var init_elo = __esm({
|
|
631
1068
|
"src/core/navigators/elo.ts"() {
|
|
632
1069
|
"use strict";
|
|
633
1070
|
init_navigators();
|
|
1071
|
+
import_common6 = require("@vue-skuilder/common");
|
|
634
1072
|
ELONavigator = class extends ContentNavigator {
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
constructor(user, course) {
|
|
638
|
-
super();
|
|
639
|
-
this.
|
|
640
|
-
this.course = course;
|
|
1073
|
+
/** Human-readable name for CardGenerator interface */
|
|
1074
|
+
name;
|
|
1075
|
+
constructor(user, course, strategyData) {
|
|
1076
|
+
super(user, course, strategyData);
|
|
1077
|
+
this.name = strategyData?.name || "ELO";
|
|
641
1078
|
}
|
|
642
1079
|
async getPendingReviews() {
|
|
643
1080
|
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
@@ -665,84 +1102,983 @@ var init_elo = __esm({
|
|
|
665
1102
|
};
|
|
666
1103
|
});
|
|
667
1104
|
}
|
|
668
|
-
async getNewCards(limit = 99) {
|
|
669
|
-
const activeCards = await this.user.getActiveCards();
|
|
670
|
-
return (await this.course.getCardsCenteredAtELO(
|
|
671
|
-
{ limit, elo: "user" },
|
|
672
|
-
(c) => {
|
|
673
|
-
if (activeCards.some((ac) => c.cardID === ac.cardID)) {
|
|
674
|
-
return false;
|
|
675
|
-
} else {
|
|
676
|
-
return true;
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
)).map((c) => {
|
|
680
|
-
return {
|
|
681
|
-
...c,
|
|
682
|
-
status: "new"
|
|
683
|
-
};
|
|
684
|
-
});
|
|
1105
|
+
async getNewCards(limit = 99) {
|
|
1106
|
+
const activeCards = await this.user.getActiveCards();
|
|
1107
|
+
return (await this.course.getCardsCenteredAtELO(
|
|
1108
|
+
{ limit, elo: "user" },
|
|
1109
|
+
(c) => {
|
|
1110
|
+
if (activeCards.some((ac) => c.cardID === ac.cardID)) {
|
|
1111
|
+
return false;
|
|
1112
|
+
} else {
|
|
1113
|
+
return true;
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
)).map((c) => {
|
|
1117
|
+
return {
|
|
1118
|
+
...c,
|
|
1119
|
+
status: "new"
|
|
1120
|
+
};
|
|
1121
|
+
});
|
|
1122
|
+
}
|
|
1123
|
+
/**
|
|
1124
|
+
* Get new cards with suitability scores based on ELO distance.
|
|
1125
|
+
*
|
|
1126
|
+
* Cards closer to user's ELO get higher scores.
|
|
1127
|
+
* Score formula: max(0, 1 - distance / 500)
|
|
1128
|
+
*
|
|
1129
|
+
* NOTE: This generator only handles NEW cards. Reviews are handled by
|
|
1130
|
+
* SRSNavigator. Use CompositeGenerator to combine both.
|
|
1131
|
+
*
|
|
1132
|
+
* This method supports both the legacy signature (limit only) and the
|
|
1133
|
+
* CardGenerator interface signature (limit, context).
|
|
1134
|
+
*
|
|
1135
|
+
* @param limit - Maximum number of cards to return
|
|
1136
|
+
* @param context - Optional GeneratorContext (used when called via Pipeline)
|
|
1137
|
+
*/
|
|
1138
|
+
async getWeightedCards(limit, context) {
|
|
1139
|
+
let userGlobalElo;
|
|
1140
|
+
if (context?.userElo !== void 0) {
|
|
1141
|
+
userGlobalElo = context.userElo;
|
|
1142
|
+
} else {
|
|
1143
|
+
const courseReg = await this.user.getCourseRegDoc(this.course.getCourseID());
|
|
1144
|
+
const userElo = (0, import_common6.toCourseElo)(courseReg.elo);
|
|
1145
|
+
userGlobalElo = userElo.global.score;
|
|
1146
|
+
}
|
|
1147
|
+
const newCards = await this.getNewCards(limit);
|
|
1148
|
+
const cardIds = newCards.map((c) => c.cardID);
|
|
1149
|
+
const cardEloData = await this.course.getCardEloData(cardIds);
|
|
1150
|
+
const scored = newCards.map((c, i) => {
|
|
1151
|
+
const cardElo = cardEloData[i]?.global?.score ?? 1e3;
|
|
1152
|
+
const distance = Math.abs(cardElo - userGlobalElo);
|
|
1153
|
+
const score = Math.max(0, 1 - distance / 500);
|
|
1154
|
+
return {
|
|
1155
|
+
cardId: c.cardID,
|
|
1156
|
+
courseId: c.courseID,
|
|
1157
|
+
score,
|
|
1158
|
+
provenance: [
|
|
1159
|
+
{
|
|
1160
|
+
strategy: "elo",
|
|
1161
|
+
strategyName: this.strategyName || this.name,
|
|
1162
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-ELO-default",
|
|
1163
|
+
action: "generated",
|
|
1164
|
+
score,
|
|
1165
|
+
reason: `ELO distance ${Math.round(distance)} (card: ${Math.round(cardElo)}, user: ${Math.round(userGlobalElo)}), new card`
|
|
1166
|
+
}
|
|
1167
|
+
]
|
|
1168
|
+
};
|
|
1169
|
+
});
|
|
1170
|
+
scored.sort((a, b) => b.score - a.score);
|
|
1171
|
+
return scored.slice(0, limit);
|
|
1172
|
+
}
|
|
1173
|
+
};
|
|
1174
|
+
}
|
|
1175
|
+
});
|
|
1176
|
+
|
|
1177
|
+
// src/core/navigators/filters/eloDistance.ts
|
|
1178
|
+
var eloDistance_exports = {};
|
|
1179
|
+
__export(eloDistance_exports, {
|
|
1180
|
+
DEFAULT_HALF_LIFE: () => DEFAULT_HALF_LIFE,
|
|
1181
|
+
DEFAULT_MAX_MULTIPLIER: () => DEFAULT_MAX_MULTIPLIER,
|
|
1182
|
+
DEFAULT_MIN_MULTIPLIER: () => DEFAULT_MIN_MULTIPLIER,
|
|
1183
|
+
createEloDistanceFilter: () => createEloDistanceFilter
|
|
1184
|
+
});
|
|
1185
|
+
function computeMultiplier(distance, halfLife, minMultiplier, maxMultiplier) {
|
|
1186
|
+
const normalizedDistance = distance / halfLife;
|
|
1187
|
+
const decay = Math.exp(-(normalizedDistance * normalizedDistance));
|
|
1188
|
+
return minMultiplier + (maxMultiplier - minMultiplier) * decay;
|
|
1189
|
+
}
|
|
1190
|
+
function createEloDistanceFilter(config) {
|
|
1191
|
+
const halfLife = config?.halfLife ?? DEFAULT_HALF_LIFE;
|
|
1192
|
+
const minMultiplier = config?.minMultiplier ?? DEFAULT_MIN_MULTIPLIER;
|
|
1193
|
+
const maxMultiplier = config?.maxMultiplier ?? DEFAULT_MAX_MULTIPLIER;
|
|
1194
|
+
return {
|
|
1195
|
+
name: "ELO Distance Filter",
|
|
1196
|
+
async transform(cards, context) {
|
|
1197
|
+
const { course, userElo } = context;
|
|
1198
|
+
const cardIds = cards.map((c) => c.cardId);
|
|
1199
|
+
const cardElos = await course.getCardEloData(cardIds);
|
|
1200
|
+
return cards.map((card, i) => {
|
|
1201
|
+
const cardElo = cardElos[i]?.global?.score ?? 1e3;
|
|
1202
|
+
const distance = Math.abs(cardElo - userElo);
|
|
1203
|
+
const multiplier = computeMultiplier(distance, halfLife, minMultiplier, maxMultiplier);
|
|
1204
|
+
const newScore = card.score * multiplier;
|
|
1205
|
+
const action = multiplier < maxMultiplier - 0.01 ? "penalized" : "passed";
|
|
1206
|
+
return {
|
|
1207
|
+
...card,
|
|
1208
|
+
score: newScore,
|
|
1209
|
+
provenance: [
|
|
1210
|
+
...card.provenance,
|
|
1211
|
+
{
|
|
1212
|
+
strategy: "eloDistance",
|
|
1213
|
+
strategyName: "ELO Distance Filter",
|
|
1214
|
+
strategyId: "ELO_DISTANCE_FILTER",
|
|
1215
|
+
action,
|
|
1216
|
+
score: newScore,
|
|
1217
|
+
reason: `ELO distance ${Math.round(distance)} (card: ${Math.round(cardElo)}, user: ${Math.round(userElo)}) \u2192 ${multiplier.toFixed(2)}x`
|
|
1218
|
+
}
|
|
1219
|
+
]
|
|
1220
|
+
};
|
|
1221
|
+
});
|
|
1222
|
+
}
|
|
1223
|
+
};
|
|
1224
|
+
}
|
|
1225
|
+
var DEFAULT_HALF_LIFE, DEFAULT_MIN_MULTIPLIER, DEFAULT_MAX_MULTIPLIER;
|
|
1226
|
+
var init_eloDistance = __esm({
|
|
1227
|
+
"src/core/navigators/filters/eloDistance.ts"() {
|
|
1228
|
+
"use strict";
|
|
1229
|
+
DEFAULT_HALF_LIFE = 200;
|
|
1230
|
+
DEFAULT_MIN_MULTIPLIER = 0.3;
|
|
1231
|
+
DEFAULT_MAX_MULTIPLIER = 1;
|
|
1232
|
+
}
|
|
1233
|
+
});
|
|
1234
|
+
|
|
1235
|
+
// src/core/navigators/filters/index.ts
|
|
1236
|
+
var filters_exports = {};
|
|
1237
|
+
__export(filters_exports, {
|
|
1238
|
+
createEloDistanceFilter: () => createEloDistanceFilter
|
|
1239
|
+
});
|
|
1240
|
+
var init_filters = __esm({
|
|
1241
|
+
"src/core/navigators/filters/index.ts"() {
|
|
1242
|
+
"use strict";
|
|
1243
|
+
init_eloDistance();
|
|
1244
|
+
}
|
|
1245
|
+
});
|
|
1246
|
+
|
|
1247
|
+
// src/core/navigators/filters/types.ts
|
|
1248
|
+
var types_exports = {};
|
|
1249
|
+
var init_types = __esm({
|
|
1250
|
+
"src/core/navigators/filters/types.ts"() {
|
|
1251
|
+
"use strict";
|
|
1252
|
+
}
|
|
1253
|
+
});
|
|
1254
|
+
|
|
1255
|
+
// src/core/navigators/generators/index.ts
|
|
1256
|
+
var generators_exports = {};
|
|
1257
|
+
var init_generators = __esm({
|
|
1258
|
+
"src/core/navigators/generators/index.ts"() {
|
|
1259
|
+
"use strict";
|
|
1260
|
+
}
|
|
1261
|
+
});
|
|
1262
|
+
|
|
1263
|
+
// src/core/navigators/generators/types.ts
|
|
1264
|
+
var types_exports2 = {};
|
|
1265
|
+
var init_types2 = __esm({
|
|
1266
|
+
"src/core/navigators/generators/types.ts"() {
|
|
1267
|
+
"use strict";
|
|
1268
|
+
}
|
|
1269
|
+
});
|
|
1270
|
+
|
|
1271
|
+
// src/core/navigators/hardcodedOrder.ts
|
|
1272
|
+
var hardcodedOrder_exports = {};
|
|
1273
|
+
__export(hardcodedOrder_exports, {
|
|
1274
|
+
default: () => HardcodedOrderNavigator
|
|
1275
|
+
});
|
|
1276
|
+
var HardcodedOrderNavigator;
|
|
1277
|
+
var init_hardcodedOrder = __esm({
|
|
1278
|
+
"src/core/navigators/hardcodedOrder.ts"() {
|
|
1279
|
+
"use strict";
|
|
1280
|
+
init_navigators();
|
|
1281
|
+
init_logger();
|
|
1282
|
+
HardcodedOrderNavigator = class extends ContentNavigator {
|
|
1283
|
+
/** Human-readable name for CardGenerator interface */
|
|
1284
|
+
name;
|
|
1285
|
+
orderedCardIds = [];
|
|
1286
|
+
constructor(user, course, strategyData) {
|
|
1287
|
+
super(user, course, strategyData);
|
|
1288
|
+
this.name = strategyData.name || "Hardcoded Order";
|
|
1289
|
+
if (strategyData.serializedData) {
|
|
1290
|
+
try {
|
|
1291
|
+
this.orderedCardIds = JSON.parse(strategyData.serializedData);
|
|
1292
|
+
} catch (e) {
|
|
1293
|
+
logger.error("Failed to parse serializedData for HardcodedOrderNavigator", e);
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
async getPendingReviews() {
|
|
1298
|
+
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
1299
|
+
return reviews.map((r) => {
|
|
1300
|
+
return {
|
|
1301
|
+
...r,
|
|
1302
|
+
contentSourceType: "course",
|
|
1303
|
+
contentSourceID: this.course.getCourseID(),
|
|
1304
|
+
cardID: r.cardId,
|
|
1305
|
+
courseID: r.courseId,
|
|
1306
|
+
reviewID: r._id,
|
|
1307
|
+
status: "review"
|
|
1308
|
+
};
|
|
1309
|
+
});
|
|
1310
|
+
}
|
|
1311
|
+
async getNewCards(limit = 99) {
|
|
1312
|
+
const activeCardIds = (await this.user.getActiveCards()).map((c) => c.cardID);
|
|
1313
|
+
const newCardIds = this.orderedCardIds.filter((cardId) => !activeCardIds.includes(cardId));
|
|
1314
|
+
const cardsToReturn = newCardIds.slice(0, limit);
|
|
1315
|
+
return cardsToReturn.map((cardId) => {
|
|
1316
|
+
return {
|
|
1317
|
+
cardID: cardId,
|
|
1318
|
+
courseID: this.course.getCourseID(),
|
|
1319
|
+
contentSourceType: "course",
|
|
1320
|
+
contentSourceID: this.course.getCourseID(),
|
|
1321
|
+
status: "new"
|
|
1322
|
+
};
|
|
1323
|
+
});
|
|
1324
|
+
}
|
|
1325
|
+
/**
|
|
1326
|
+
* Get cards in hardcoded order with scores based on position.
|
|
1327
|
+
*
|
|
1328
|
+
* Earlier cards in the sequence get higher scores.
|
|
1329
|
+
* Score formula: 1.0 - (position / totalCards) * 0.5
|
|
1330
|
+
* This ensures scores range from 1.0 (first card) to 0.5+ (last card).
|
|
1331
|
+
*
|
|
1332
|
+
* This method supports both the legacy signature (limit only) and the
|
|
1333
|
+
* CardGenerator interface signature (limit, context).
|
|
1334
|
+
*
|
|
1335
|
+
* @param limit - Maximum number of cards to return
|
|
1336
|
+
* @param _context - Optional GeneratorContext (currently unused, but required for interface)
|
|
1337
|
+
*/
|
|
1338
|
+
async getWeightedCards(limit, _context) {
|
|
1339
|
+
const activeCardIds = (await this.user.getActiveCards()).map((c) => c.cardID);
|
|
1340
|
+
const reviews = await this.getPendingReviews();
|
|
1341
|
+
const newCardIds = this.orderedCardIds.filter((cardId) => !activeCardIds.includes(cardId));
|
|
1342
|
+
const totalCards = newCardIds.length;
|
|
1343
|
+
const scoredNew = newCardIds.slice(0, limit).map((cardId, index) => {
|
|
1344
|
+
const position = index + 1;
|
|
1345
|
+
const score = Math.max(0.5, 1 - index / totalCards * 0.5);
|
|
1346
|
+
return {
|
|
1347
|
+
cardId,
|
|
1348
|
+
courseId: this.course.getCourseID(),
|
|
1349
|
+
score,
|
|
1350
|
+
provenance: [
|
|
1351
|
+
{
|
|
1352
|
+
strategy: "hardcodedOrder",
|
|
1353
|
+
strategyName: this.strategyName || this.name,
|
|
1354
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-hardcoded",
|
|
1355
|
+
action: "generated",
|
|
1356
|
+
score,
|
|
1357
|
+
reason: `Position ${position} of ${totalCards} in fixed sequence, new card`
|
|
1358
|
+
}
|
|
1359
|
+
]
|
|
1360
|
+
};
|
|
1361
|
+
});
|
|
1362
|
+
const scoredReviews = reviews.map((r) => ({
|
|
1363
|
+
cardId: r.cardID,
|
|
1364
|
+
courseId: r.courseID,
|
|
1365
|
+
score: 1,
|
|
1366
|
+
provenance: [
|
|
1367
|
+
{
|
|
1368
|
+
strategy: "hardcodedOrder",
|
|
1369
|
+
strategyName: this.strategyName || this.name,
|
|
1370
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-hardcoded",
|
|
1371
|
+
action: "generated",
|
|
1372
|
+
score: 1,
|
|
1373
|
+
reason: "Scheduled review, highest priority"
|
|
1374
|
+
}
|
|
1375
|
+
]
|
|
1376
|
+
}));
|
|
1377
|
+
const all = [...scoredReviews, ...scoredNew];
|
|
1378
|
+
all.sort((a, b) => b.score - a.score);
|
|
1379
|
+
return all.slice(0, limit);
|
|
1380
|
+
}
|
|
1381
|
+
};
|
|
1382
|
+
}
|
|
1383
|
+
});
|
|
1384
|
+
|
|
1385
|
+
// src/core/navigators/hierarchyDefinition.ts
|
|
1386
|
+
var hierarchyDefinition_exports = {};
|
|
1387
|
+
__export(hierarchyDefinition_exports, {
|
|
1388
|
+
default: () => HierarchyDefinitionNavigator
|
|
1389
|
+
});
|
|
1390
|
+
var import_common7, DEFAULT_MIN_COUNT, HierarchyDefinitionNavigator;
|
|
1391
|
+
var init_hierarchyDefinition = __esm({
|
|
1392
|
+
"src/core/navigators/hierarchyDefinition.ts"() {
|
|
1393
|
+
"use strict";
|
|
1394
|
+
init_navigators();
|
|
1395
|
+
import_common7 = require("@vue-skuilder/common");
|
|
1396
|
+
DEFAULT_MIN_COUNT = 3;
|
|
1397
|
+
HierarchyDefinitionNavigator = class extends ContentNavigator {
|
|
1398
|
+
config;
|
|
1399
|
+
_strategyData;
|
|
1400
|
+
/** Human-readable name for CardFilter interface */
|
|
1401
|
+
name;
|
|
1402
|
+
constructor(user, course, _strategyData) {
|
|
1403
|
+
super(user, course, _strategyData);
|
|
1404
|
+
this._strategyData = _strategyData;
|
|
1405
|
+
this.config = this.parseConfig(_strategyData.serializedData);
|
|
1406
|
+
this.name = _strategyData.name || "Hierarchy Definition";
|
|
1407
|
+
}
|
|
1408
|
+
parseConfig(serializedData) {
|
|
1409
|
+
try {
|
|
1410
|
+
const parsed = JSON.parse(serializedData);
|
|
1411
|
+
return {
|
|
1412
|
+
prerequisites: parsed.prerequisites || {}
|
|
1413
|
+
};
|
|
1414
|
+
} catch {
|
|
1415
|
+
return {
|
|
1416
|
+
prerequisites: {}
|
|
1417
|
+
};
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
/**
|
|
1421
|
+
* Check if a specific prerequisite is satisfied
|
|
1422
|
+
*/
|
|
1423
|
+
isPrerequisiteMet(prereq, userTagElo, userGlobalElo) {
|
|
1424
|
+
if (!userTagElo) return false;
|
|
1425
|
+
const minCount = prereq.masteryThreshold?.minCount ?? DEFAULT_MIN_COUNT;
|
|
1426
|
+
if (userTagElo.count < minCount) return false;
|
|
1427
|
+
if (prereq.masteryThreshold?.minElo !== void 0) {
|
|
1428
|
+
return userTagElo.score >= prereq.masteryThreshold.minElo;
|
|
1429
|
+
} else {
|
|
1430
|
+
return userTagElo.score >= userGlobalElo;
|
|
1431
|
+
}
|
|
1432
|
+
}
|
|
1433
|
+
/**
|
|
1434
|
+
* Get the set of tags the user has mastered.
|
|
1435
|
+
* A tag is "mastered" if it appears as a prerequisite somewhere and meets its threshold.
|
|
1436
|
+
*/
|
|
1437
|
+
async getMasteredTags(context) {
|
|
1438
|
+
const mastered = /* @__PURE__ */ new Set();
|
|
1439
|
+
try {
|
|
1440
|
+
const courseReg = await context.user.getCourseRegDoc(context.course.getCourseID());
|
|
1441
|
+
const userElo = (0, import_common7.toCourseElo)(courseReg.elo);
|
|
1442
|
+
for (const prereqs of Object.values(this.config.prerequisites)) {
|
|
1443
|
+
for (const prereq of prereqs) {
|
|
1444
|
+
const tagElo = userElo.tags[prereq.tag];
|
|
1445
|
+
if (this.isPrerequisiteMet(prereq, tagElo, userElo.global.score)) {
|
|
1446
|
+
mastered.add(prereq.tag);
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1450
|
+
} catch {
|
|
1451
|
+
}
|
|
1452
|
+
return mastered;
|
|
1453
|
+
}
|
|
1454
|
+
/**
|
|
1455
|
+
* Get the set of tags that are unlocked (prerequisites met)
|
|
1456
|
+
*/
|
|
1457
|
+
getUnlockedTags(masteredTags) {
|
|
1458
|
+
const unlocked = /* @__PURE__ */ new Set();
|
|
1459
|
+
for (const [tagId, prereqs] of Object.entries(this.config.prerequisites)) {
|
|
1460
|
+
const allPrereqsMet = prereqs.every((prereq) => masteredTags.has(prereq.tag));
|
|
1461
|
+
if (allPrereqsMet) {
|
|
1462
|
+
unlocked.add(tagId);
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1465
|
+
return unlocked;
|
|
1466
|
+
}
|
|
1467
|
+
/**
|
|
1468
|
+
* Check if a tag has prerequisites defined in config
|
|
1469
|
+
*/
|
|
1470
|
+
hasPrerequisites(tagId) {
|
|
1471
|
+
return tagId in this.config.prerequisites;
|
|
1472
|
+
}
|
|
1473
|
+
/**
|
|
1474
|
+
* Check if a card is unlocked and generate reason.
|
|
1475
|
+
*/
|
|
1476
|
+
async checkCardUnlock(cardId, course, unlockedTags, masteredTags) {
|
|
1477
|
+
try {
|
|
1478
|
+
const tagResponse = await course.getAppliedTags(cardId);
|
|
1479
|
+
const cardTags = tagResponse.rows.map((row) => row.value?.name || row.key);
|
|
1480
|
+
const lockedTags = cardTags.filter(
|
|
1481
|
+
(tag) => this.hasPrerequisites(tag) && !unlockedTags.has(tag)
|
|
1482
|
+
);
|
|
1483
|
+
if (lockedTags.length === 0) {
|
|
1484
|
+
const tagList = cardTags.length > 0 ? cardTags.join(", ") : "none";
|
|
1485
|
+
return {
|
|
1486
|
+
isUnlocked: true,
|
|
1487
|
+
reason: `Prerequisites met, tags: ${tagList}`
|
|
1488
|
+
};
|
|
1489
|
+
}
|
|
1490
|
+
const missingPrereqs = lockedTags.flatMap((tag) => {
|
|
1491
|
+
const prereqs = this.config.prerequisites[tag] || [];
|
|
1492
|
+
return prereqs.filter((p) => !masteredTags.has(p.tag)).map((p) => p.tag);
|
|
1493
|
+
});
|
|
1494
|
+
return {
|
|
1495
|
+
isUnlocked: false,
|
|
1496
|
+
reason: `Blocked: missing prerequisites ${missingPrereqs.join(", ")} for tags ${lockedTags.join(", ")}`
|
|
1497
|
+
};
|
|
1498
|
+
} catch {
|
|
1499
|
+
return {
|
|
1500
|
+
isUnlocked: true,
|
|
1501
|
+
reason: "Prerequisites check skipped (tag lookup failed)"
|
|
1502
|
+
};
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1505
|
+
/**
|
|
1506
|
+
* CardFilter.transform implementation.
|
|
1507
|
+
*
|
|
1508
|
+
* Apply prerequisite gating to cards. Cards with locked tags receive score: 0.
|
|
1509
|
+
*/
|
|
1510
|
+
async transform(cards, context) {
|
|
1511
|
+
const masteredTags = await this.getMasteredTags(context);
|
|
1512
|
+
const unlockedTags = this.getUnlockedTags(masteredTags);
|
|
1513
|
+
const gated = [];
|
|
1514
|
+
for (const card of cards) {
|
|
1515
|
+
const { isUnlocked, reason } = await this.checkCardUnlock(
|
|
1516
|
+
card.cardId,
|
|
1517
|
+
context.course,
|
|
1518
|
+
unlockedTags,
|
|
1519
|
+
masteredTags
|
|
1520
|
+
);
|
|
1521
|
+
const finalScore = isUnlocked ? card.score : 0;
|
|
1522
|
+
const action = isUnlocked ? "passed" : "penalized";
|
|
1523
|
+
gated.push({
|
|
1524
|
+
...card,
|
|
1525
|
+
score: finalScore,
|
|
1526
|
+
provenance: [
|
|
1527
|
+
...card.provenance,
|
|
1528
|
+
{
|
|
1529
|
+
strategy: "hierarchyDefinition",
|
|
1530
|
+
strategyName: this.strategyName || this.name,
|
|
1531
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-hierarchy",
|
|
1532
|
+
action,
|
|
1533
|
+
score: finalScore,
|
|
1534
|
+
reason
|
|
1535
|
+
}
|
|
1536
|
+
]
|
|
1537
|
+
});
|
|
1538
|
+
}
|
|
1539
|
+
return gated;
|
|
1540
|
+
}
|
|
1541
|
+
/**
|
|
1542
|
+
* Legacy getWeightedCards - now throws as filters should not be used as generators.
|
|
1543
|
+
*
|
|
1544
|
+
* Use transform() via Pipeline instead.
|
|
1545
|
+
*/
|
|
1546
|
+
async getWeightedCards(_limit) {
|
|
1547
|
+
throw new Error(
|
|
1548
|
+
"HierarchyDefinitionNavigator is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
|
|
1549
|
+
);
|
|
1550
|
+
}
|
|
1551
|
+
// Legacy methods - stub implementations since filters don't generate cards
|
|
1552
|
+
async getNewCards(_n) {
|
|
1553
|
+
return [];
|
|
1554
|
+
}
|
|
1555
|
+
async getPendingReviews() {
|
|
1556
|
+
return [];
|
|
1557
|
+
}
|
|
1558
|
+
};
|
|
1559
|
+
}
|
|
1560
|
+
});
|
|
1561
|
+
|
|
1562
|
+
// src/core/navigators/interferenceMitigator.ts
|
|
1563
|
+
var interferenceMitigator_exports = {};
|
|
1564
|
+
__export(interferenceMitigator_exports, {
|
|
1565
|
+
default: () => InterferenceMitigatorNavigator
|
|
1566
|
+
});
|
|
1567
|
+
var import_common8, DEFAULT_MIN_COUNT2, DEFAULT_MIN_ELAPSED_DAYS, DEFAULT_INTERFERENCE_DECAY, InterferenceMitigatorNavigator;
|
|
1568
|
+
var init_interferenceMitigator = __esm({
|
|
1569
|
+
"src/core/navigators/interferenceMitigator.ts"() {
|
|
1570
|
+
"use strict";
|
|
1571
|
+
init_navigators();
|
|
1572
|
+
import_common8 = require("@vue-skuilder/common");
|
|
1573
|
+
DEFAULT_MIN_COUNT2 = 10;
|
|
1574
|
+
DEFAULT_MIN_ELAPSED_DAYS = 3;
|
|
1575
|
+
DEFAULT_INTERFERENCE_DECAY = 0.8;
|
|
1576
|
+
InterferenceMitigatorNavigator = class extends ContentNavigator {
|
|
1577
|
+
config;
|
|
1578
|
+
_strategyData;
|
|
1579
|
+
/** Human-readable name for CardFilter interface */
|
|
1580
|
+
name;
|
|
1581
|
+
/** Precomputed map: tag -> set of { partner, decay } it interferes with */
|
|
1582
|
+
interferenceMap;
|
|
1583
|
+
constructor(user, course, _strategyData) {
|
|
1584
|
+
super(user, course, _strategyData);
|
|
1585
|
+
this._strategyData = _strategyData;
|
|
1586
|
+
this.config = this.parseConfig(_strategyData.serializedData);
|
|
1587
|
+
this.interferenceMap = this.buildInterferenceMap();
|
|
1588
|
+
this.name = _strategyData.name || "Interference Mitigator";
|
|
1589
|
+
}
|
|
1590
|
+
parseConfig(serializedData) {
|
|
1591
|
+
try {
|
|
1592
|
+
const parsed = JSON.parse(serializedData);
|
|
1593
|
+
let sets = parsed.interferenceSets || [];
|
|
1594
|
+
if (sets.length > 0 && Array.isArray(sets[0])) {
|
|
1595
|
+
sets = sets.map((tags) => ({ tags }));
|
|
1596
|
+
}
|
|
1597
|
+
return {
|
|
1598
|
+
interferenceSets: sets,
|
|
1599
|
+
maturityThreshold: {
|
|
1600
|
+
minCount: parsed.maturityThreshold?.minCount ?? DEFAULT_MIN_COUNT2,
|
|
1601
|
+
minElo: parsed.maturityThreshold?.minElo,
|
|
1602
|
+
minElapsedDays: parsed.maturityThreshold?.minElapsedDays ?? DEFAULT_MIN_ELAPSED_DAYS
|
|
1603
|
+
},
|
|
1604
|
+
defaultDecay: parsed.defaultDecay ?? DEFAULT_INTERFERENCE_DECAY
|
|
1605
|
+
};
|
|
1606
|
+
} catch {
|
|
1607
|
+
return {
|
|
1608
|
+
interferenceSets: [],
|
|
1609
|
+
maturityThreshold: {
|
|
1610
|
+
minCount: DEFAULT_MIN_COUNT2,
|
|
1611
|
+
minElapsedDays: DEFAULT_MIN_ELAPSED_DAYS
|
|
1612
|
+
},
|
|
1613
|
+
defaultDecay: DEFAULT_INTERFERENCE_DECAY
|
|
1614
|
+
};
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
/**
|
|
1618
|
+
* Build a map from each tag to its interference partners with decay coefficients.
|
|
1619
|
+
* If tags A, B, C are in an interference group with decay 0.8, then:
|
|
1620
|
+
* - A interferes with B (decay 0.8) and C (decay 0.8)
|
|
1621
|
+
* - B interferes with A (decay 0.8) and C (decay 0.8)
|
|
1622
|
+
* - etc.
|
|
1623
|
+
*/
|
|
1624
|
+
buildInterferenceMap() {
|
|
1625
|
+
const map = /* @__PURE__ */ new Map();
|
|
1626
|
+
for (const group of this.config.interferenceSets) {
|
|
1627
|
+
const decay = group.decay ?? this.config.defaultDecay ?? DEFAULT_INTERFERENCE_DECAY;
|
|
1628
|
+
for (const tag of group.tags) {
|
|
1629
|
+
if (!map.has(tag)) {
|
|
1630
|
+
map.set(tag, []);
|
|
1631
|
+
}
|
|
1632
|
+
const partners = map.get(tag);
|
|
1633
|
+
for (const other of group.tags) {
|
|
1634
|
+
if (other !== tag) {
|
|
1635
|
+
const existing = partners.find((p) => p.partner === other);
|
|
1636
|
+
if (existing) {
|
|
1637
|
+
existing.decay = Math.max(existing.decay, decay);
|
|
1638
|
+
} else {
|
|
1639
|
+
partners.push({ partner: other, decay });
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
}
|
|
1645
|
+
return map;
|
|
1646
|
+
}
|
|
1647
|
+
/**
|
|
1648
|
+
* Get the set of tags that are currently immature for this user.
|
|
1649
|
+
* A tag is immature if the user has interacted with it but hasn't
|
|
1650
|
+
* reached the maturity threshold.
|
|
1651
|
+
*/
|
|
1652
|
+
async getImmatureTags(context) {
|
|
1653
|
+
const immature = /* @__PURE__ */ new Set();
|
|
1654
|
+
try {
|
|
1655
|
+
const courseReg = await context.user.getCourseRegDoc(context.course.getCourseID());
|
|
1656
|
+
const userElo = (0, import_common8.toCourseElo)(courseReg.elo);
|
|
1657
|
+
const minCount = this.config.maturityThreshold?.minCount ?? DEFAULT_MIN_COUNT2;
|
|
1658
|
+
const minElo = this.config.maturityThreshold?.minElo;
|
|
1659
|
+
const minElapsedDays = this.config.maturityThreshold?.minElapsedDays ?? DEFAULT_MIN_ELAPSED_DAYS;
|
|
1660
|
+
const minCountForElapsed = minElapsedDays * 2;
|
|
1661
|
+
for (const [tagId, tagElo] of Object.entries(userElo.tags)) {
|
|
1662
|
+
if (tagElo.count === 0) continue;
|
|
1663
|
+
const belowCount = tagElo.count < minCount;
|
|
1664
|
+
const belowElo = minElo !== void 0 && tagElo.score < minElo;
|
|
1665
|
+
const belowElapsed = tagElo.count < minCountForElapsed;
|
|
1666
|
+
if (belowCount || belowElo || belowElapsed) {
|
|
1667
|
+
immature.add(tagId);
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
} catch {
|
|
1671
|
+
}
|
|
1672
|
+
return immature;
|
|
1673
|
+
}
|
|
1674
|
+
/**
|
|
1675
|
+
* Get all tags that interfere with any immature tag, along with their decay coefficients.
|
|
1676
|
+
* These are the tags we want to avoid introducing.
|
|
1677
|
+
*/
|
|
1678
|
+
getTagsToAvoid(immatureTags) {
|
|
1679
|
+
const avoid = /* @__PURE__ */ new Map();
|
|
1680
|
+
for (const immatureTag of immatureTags) {
|
|
1681
|
+
const partners = this.interferenceMap.get(immatureTag);
|
|
1682
|
+
if (partners) {
|
|
1683
|
+
for (const { partner, decay } of partners) {
|
|
1684
|
+
if (!immatureTags.has(partner)) {
|
|
1685
|
+
const existing = avoid.get(partner) ?? 0;
|
|
1686
|
+
avoid.set(partner, Math.max(existing, decay));
|
|
1687
|
+
}
|
|
1688
|
+
}
|
|
1689
|
+
}
|
|
1690
|
+
}
|
|
1691
|
+
return avoid;
|
|
1692
|
+
}
|
|
1693
|
+
/**
|
|
1694
|
+
* Get tags for a single card
|
|
1695
|
+
*/
|
|
1696
|
+
async getCardTags(cardId, course) {
|
|
1697
|
+
try {
|
|
1698
|
+
const tagResponse = await course.getAppliedTags(cardId);
|
|
1699
|
+
return tagResponse.rows.map((row) => row.value?.name || row.key).filter(Boolean);
|
|
1700
|
+
} catch {
|
|
1701
|
+
return [];
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1704
|
+
/**
|
|
1705
|
+
* Compute interference score reduction for a card.
|
|
1706
|
+
* Returns: { multiplier, interfering tags, reason }
|
|
1707
|
+
*/
|
|
1708
|
+
computeInterferenceEffect(cardTags, tagsToAvoid, immatureTags) {
|
|
1709
|
+
if (tagsToAvoid.size === 0) {
|
|
1710
|
+
return {
|
|
1711
|
+
multiplier: 1,
|
|
1712
|
+
interferingTags: [],
|
|
1713
|
+
reason: "No interference detected"
|
|
1714
|
+
};
|
|
1715
|
+
}
|
|
1716
|
+
let multiplier = 1;
|
|
1717
|
+
const interferingTags = [];
|
|
1718
|
+
for (const tag of cardTags) {
|
|
1719
|
+
const decay = tagsToAvoid.get(tag);
|
|
1720
|
+
if (decay !== void 0) {
|
|
1721
|
+
interferingTags.push(tag);
|
|
1722
|
+
multiplier *= 1 - decay;
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
if (interferingTags.length === 0) {
|
|
1726
|
+
return {
|
|
1727
|
+
multiplier: 1,
|
|
1728
|
+
interferingTags: [],
|
|
1729
|
+
reason: "No interference detected"
|
|
1730
|
+
};
|
|
1731
|
+
}
|
|
1732
|
+
const causingTags = /* @__PURE__ */ new Set();
|
|
1733
|
+
for (const tag of interferingTags) {
|
|
1734
|
+
for (const immatureTag of immatureTags) {
|
|
1735
|
+
const partners = this.interferenceMap.get(immatureTag);
|
|
1736
|
+
if (partners?.some((p) => p.partner === tag)) {
|
|
1737
|
+
causingTags.add(immatureTag);
|
|
1738
|
+
}
|
|
1739
|
+
}
|
|
1740
|
+
}
|
|
1741
|
+
const reason = `Interferes with immature tags ${Array.from(causingTags).join(", ")} (tags: ${interferingTags.join(", ")}, multiplier: ${multiplier.toFixed(2)})`;
|
|
1742
|
+
return { multiplier, interferingTags, reason };
|
|
1743
|
+
}
|
|
1744
|
+
/**
|
|
1745
|
+
* CardFilter.transform implementation.
|
|
1746
|
+
*
|
|
1747
|
+
* Apply interference-aware scoring. Cards with tags that interfere with
|
|
1748
|
+
* immature learnings get reduced scores.
|
|
1749
|
+
*/
|
|
1750
|
+
async transform(cards, context) {
|
|
1751
|
+
const immatureTags = await this.getImmatureTags(context);
|
|
1752
|
+
const tagsToAvoid = this.getTagsToAvoid(immatureTags);
|
|
1753
|
+
const adjusted = [];
|
|
1754
|
+
for (const card of cards) {
|
|
1755
|
+
const cardTags = await this.getCardTags(card.cardId, context.course);
|
|
1756
|
+
const { multiplier, reason } = this.computeInterferenceEffect(
|
|
1757
|
+
cardTags,
|
|
1758
|
+
tagsToAvoid,
|
|
1759
|
+
immatureTags
|
|
1760
|
+
);
|
|
1761
|
+
const finalScore = card.score * multiplier;
|
|
1762
|
+
const action = multiplier < 1 ? "penalized" : multiplier > 1 ? "boosted" : "passed";
|
|
1763
|
+
adjusted.push({
|
|
1764
|
+
...card,
|
|
1765
|
+
score: finalScore,
|
|
1766
|
+
provenance: [
|
|
1767
|
+
...card.provenance,
|
|
1768
|
+
{
|
|
1769
|
+
strategy: "interferenceMitigator",
|
|
1770
|
+
strategyName: this.strategyName || this.name,
|
|
1771
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-interference",
|
|
1772
|
+
action,
|
|
1773
|
+
score: finalScore,
|
|
1774
|
+
reason
|
|
1775
|
+
}
|
|
1776
|
+
]
|
|
1777
|
+
});
|
|
1778
|
+
}
|
|
1779
|
+
return adjusted;
|
|
1780
|
+
}
|
|
1781
|
+
/**
|
|
1782
|
+
* Legacy getWeightedCards - now throws as filters should not be used as generators.
|
|
1783
|
+
*
|
|
1784
|
+
* Use transform() via Pipeline instead.
|
|
1785
|
+
*/
|
|
1786
|
+
async getWeightedCards(_limit) {
|
|
1787
|
+
throw new Error(
|
|
1788
|
+
"InterferenceMitigatorNavigator is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
|
|
1789
|
+
);
|
|
1790
|
+
}
|
|
1791
|
+
// Legacy methods - stub implementations since filters don't generate cards
|
|
1792
|
+
async getNewCards(_n) {
|
|
1793
|
+
return [];
|
|
1794
|
+
}
|
|
1795
|
+
async getPendingReviews() {
|
|
1796
|
+
return [];
|
|
1797
|
+
}
|
|
1798
|
+
};
|
|
1799
|
+
}
|
|
1800
|
+
});
|
|
1801
|
+
|
|
1802
|
+
// src/core/navigators/relativePriority.ts
|
|
1803
|
+
var relativePriority_exports = {};
|
|
1804
|
+
__export(relativePriority_exports, {
|
|
1805
|
+
default: () => RelativePriorityNavigator
|
|
1806
|
+
});
|
|
1807
|
+
var DEFAULT_PRIORITY, DEFAULT_PRIORITY_INFLUENCE, DEFAULT_COMBINE_MODE, RelativePriorityNavigator;
|
|
1808
|
+
var init_relativePriority = __esm({
|
|
1809
|
+
"src/core/navigators/relativePriority.ts"() {
|
|
1810
|
+
"use strict";
|
|
1811
|
+
init_navigators();
|
|
1812
|
+
DEFAULT_PRIORITY = 0.5;
|
|
1813
|
+
DEFAULT_PRIORITY_INFLUENCE = 0.5;
|
|
1814
|
+
DEFAULT_COMBINE_MODE = "max";
|
|
1815
|
+
RelativePriorityNavigator = class extends ContentNavigator {
|
|
1816
|
+
config;
|
|
1817
|
+
_strategyData;
|
|
1818
|
+
/** Human-readable name for CardFilter interface */
|
|
1819
|
+
name;
|
|
1820
|
+
constructor(user, course, _strategyData) {
|
|
1821
|
+
super(user, course, _strategyData);
|
|
1822
|
+
this._strategyData = _strategyData;
|
|
1823
|
+
this.config = this.parseConfig(_strategyData.serializedData);
|
|
1824
|
+
this.name = _strategyData.name || "Relative Priority";
|
|
1825
|
+
}
|
|
1826
|
+
parseConfig(serializedData) {
|
|
1827
|
+
try {
|
|
1828
|
+
const parsed = JSON.parse(serializedData);
|
|
1829
|
+
return {
|
|
1830
|
+
tagPriorities: parsed.tagPriorities || {},
|
|
1831
|
+
defaultPriority: parsed.defaultPriority ?? DEFAULT_PRIORITY,
|
|
1832
|
+
combineMode: parsed.combineMode ?? DEFAULT_COMBINE_MODE,
|
|
1833
|
+
priorityInfluence: parsed.priorityInfluence ?? DEFAULT_PRIORITY_INFLUENCE
|
|
1834
|
+
};
|
|
1835
|
+
} catch {
|
|
1836
|
+
return {
|
|
1837
|
+
tagPriorities: {},
|
|
1838
|
+
defaultPriority: DEFAULT_PRIORITY,
|
|
1839
|
+
combineMode: DEFAULT_COMBINE_MODE,
|
|
1840
|
+
priorityInfluence: DEFAULT_PRIORITY_INFLUENCE
|
|
1841
|
+
};
|
|
1842
|
+
}
|
|
1843
|
+
}
|
|
1844
|
+
/**
|
|
1845
|
+
* Look up the priority for a tag.
|
|
1846
|
+
*/
|
|
1847
|
+
getTagPriority(tagId) {
|
|
1848
|
+
return this.config.tagPriorities[tagId] ?? this.config.defaultPriority ?? DEFAULT_PRIORITY;
|
|
1849
|
+
}
|
|
1850
|
+
/**
|
|
1851
|
+
* Compute combined priority for a card based on its tags.
|
|
1852
|
+
*/
|
|
1853
|
+
computeCardPriority(cardTags) {
|
|
1854
|
+
if (cardTags.length === 0) {
|
|
1855
|
+
return this.config.defaultPriority ?? DEFAULT_PRIORITY;
|
|
1856
|
+
}
|
|
1857
|
+
const priorities = cardTags.map((tag) => this.getTagPriority(tag));
|
|
1858
|
+
switch (this.config.combineMode) {
|
|
1859
|
+
case "max":
|
|
1860
|
+
return Math.max(...priorities);
|
|
1861
|
+
case "min":
|
|
1862
|
+
return Math.min(...priorities);
|
|
1863
|
+
case "average":
|
|
1864
|
+
return priorities.reduce((sum, p) => sum + p, 0) / priorities.length;
|
|
1865
|
+
default:
|
|
1866
|
+
return Math.max(...priorities);
|
|
1867
|
+
}
|
|
1868
|
+
}
|
|
1869
|
+
/**
|
|
1870
|
+
* Compute boost factor based on priority.
|
|
1871
|
+
*
|
|
1872
|
+
* The formula: 1 + (priority - 0.5) * priorityInfluence
|
|
1873
|
+
*
|
|
1874
|
+
* This creates a multiplier centered around 1.0:
|
|
1875
|
+
* - Priority 1.0 with influence 0.5 → 1.25 (25% boost)
|
|
1876
|
+
* - Priority 0.5 with any influence → 1.00 (neutral)
|
|
1877
|
+
* - Priority 0.0 with influence 0.5 → 0.75 (25% reduction)
|
|
1878
|
+
*/
|
|
1879
|
+
computeBoostFactor(priority) {
|
|
1880
|
+
const influence = this.config.priorityInfluence ?? DEFAULT_PRIORITY_INFLUENCE;
|
|
1881
|
+
return 1 + (priority - 0.5) * influence;
|
|
1882
|
+
}
|
|
1883
|
+
/**
|
|
1884
|
+
* Build human-readable reason for priority adjustment.
|
|
1885
|
+
*/
|
|
1886
|
+
buildPriorityReason(cardTags, priority, boostFactor, finalScore) {
|
|
1887
|
+
if (cardTags.length === 0) {
|
|
1888
|
+
return `No tags, neutral priority (${priority.toFixed(2)})`;
|
|
1889
|
+
}
|
|
1890
|
+
const tagList = cardTags.slice(0, 3).join(", ");
|
|
1891
|
+
const more = cardTags.length > 3 ? ` (+${cardTags.length - 3} more)` : "";
|
|
1892
|
+
if (boostFactor === 1) {
|
|
1893
|
+
return `Neutral priority (${priority.toFixed(2)}) for tags: ${tagList}${more}`;
|
|
1894
|
+
} else if (boostFactor > 1) {
|
|
1895
|
+
return `High-priority tags: ${tagList}${more} (priority ${priority.toFixed(2)} \u2192 boost ${boostFactor.toFixed(2)}x \u2192 ${finalScore.toFixed(2)})`;
|
|
1896
|
+
} else {
|
|
1897
|
+
return `Low-priority tags: ${tagList}${more} (priority ${priority.toFixed(2)} \u2192 reduce ${boostFactor.toFixed(2)}x \u2192 ${finalScore.toFixed(2)})`;
|
|
1898
|
+
}
|
|
1899
|
+
}
|
|
1900
|
+
/**
|
|
1901
|
+
* Get tags for a single card.
|
|
1902
|
+
*/
|
|
1903
|
+
async getCardTags(cardId, course) {
|
|
1904
|
+
try {
|
|
1905
|
+
const tagResponse = await course.getAppliedTags(cardId);
|
|
1906
|
+
return tagResponse.rows.map((r) => r.doc?.name).filter((x) => !!x);
|
|
1907
|
+
} catch {
|
|
1908
|
+
return [];
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
/**
|
|
1912
|
+
* CardFilter.transform implementation.
|
|
1913
|
+
*
|
|
1914
|
+
* Apply priority-adjusted scoring. Cards with high-priority tags get boosted,
|
|
1915
|
+
* cards with low-priority tags get reduced scores.
|
|
1916
|
+
*/
|
|
1917
|
+
async transform(cards, context) {
|
|
1918
|
+
const adjusted = await Promise.all(
|
|
1919
|
+
cards.map(async (card) => {
|
|
1920
|
+
const cardTags = await this.getCardTags(card.cardId, context.course);
|
|
1921
|
+
const priority = this.computeCardPriority(cardTags);
|
|
1922
|
+
const boostFactor = this.computeBoostFactor(priority);
|
|
1923
|
+
const finalScore = Math.max(0, Math.min(1, card.score * boostFactor));
|
|
1924
|
+
const action = boostFactor > 1 ? "boosted" : boostFactor < 1 ? "penalized" : "passed";
|
|
1925
|
+
const reason = this.buildPriorityReason(cardTags, priority, boostFactor, finalScore);
|
|
1926
|
+
return {
|
|
1927
|
+
...card,
|
|
1928
|
+
score: finalScore,
|
|
1929
|
+
provenance: [
|
|
1930
|
+
...card.provenance,
|
|
1931
|
+
{
|
|
1932
|
+
strategy: "relativePriority",
|
|
1933
|
+
strategyName: this.strategyName || this.name,
|
|
1934
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-priority",
|
|
1935
|
+
action,
|
|
1936
|
+
score: finalScore,
|
|
1937
|
+
reason
|
|
1938
|
+
}
|
|
1939
|
+
]
|
|
1940
|
+
};
|
|
1941
|
+
})
|
|
1942
|
+
);
|
|
1943
|
+
return adjusted;
|
|
1944
|
+
}
|
|
1945
|
+
/**
|
|
1946
|
+
* Legacy getWeightedCards - now throws as filters should not be used as generators.
|
|
1947
|
+
*
|
|
1948
|
+
* Use transform() via Pipeline instead.
|
|
1949
|
+
*/
|
|
1950
|
+
async getWeightedCards(_limit) {
|
|
1951
|
+
throw new Error(
|
|
1952
|
+
"RelativePriorityNavigator is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
|
|
1953
|
+
);
|
|
1954
|
+
}
|
|
1955
|
+
// Legacy methods - stub implementations since filters don't generate cards
|
|
1956
|
+
async getNewCards(_n) {
|
|
1957
|
+
return [];
|
|
1958
|
+
}
|
|
1959
|
+
async getPendingReviews() {
|
|
1960
|
+
return [];
|
|
685
1961
|
}
|
|
686
1962
|
};
|
|
687
1963
|
}
|
|
688
1964
|
});
|
|
689
1965
|
|
|
690
|
-
// src/core/navigators/
|
|
691
|
-
var
|
|
692
|
-
__export(
|
|
693
|
-
default: () =>
|
|
1966
|
+
// src/core/navigators/srs.ts
|
|
1967
|
+
var srs_exports = {};
|
|
1968
|
+
__export(srs_exports, {
|
|
1969
|
+
default: () => SRSNavigator
|
|
694
1970
|
});
|
|
695
|
-
var
|
|
696
|
-
var
|
|
697
|
-
"src/core/navigators/
|
|
1971
|
+
var import_moment, SRSNavigator;
|
|
1972
|
+
var init_srs = __esm({
|
|
1973
|
+
"src/core/navigators/srs.ts"() {
|
|
698
1974
|
"use strict";
|
|
1975
|
+
import_moment = __toESM(require("moment"), 1);
|
|
699
1976
|
init_navigators();
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
user;
|
|
704
|
-
course;
|
|
1977
|
+
SRSNavigator = class extends ContentNavigator {
|
|
1978
|
+
/** Human-readable name for CardGenerator interface */
|
|
1979
|
+
name;
|
|
705
1980
|
constructor(user, course, strategyData) {
|
|
706
|
-
super();
|
|
707
|
-
this.
|
|
708
|
-
this.course = course;
|
|
709
|
-
if (strategyData.serializedData) {
|
|
710
|
-
try {
|
|
711
|
-
this.orderedCardIds = JSON.parse(strategyData.serializedData);
|
|
712
|
-
} catch (e) {
|
|
713
|
-
logger.error("Failed to parse serializedData for HardcodedOrderNavigator", e);
|
|
714
|
-
}
|
|
715
|
-
}
|
|
1981
|
+
super(user, course, strategyData);
|
|
1982
|
+
this.name = strategyData?.name || "SRS";
|
|
716
1983
|
}
|
|
717
|
-
|
|
1984
|
+
/**
|
|
1985
|
+
* Get review cards scored by urgency.
|
|
1986
|
+
*
|
|
1987
|
+
* Score formula combines:
|
|
1988
|
+
* - Relative overdueness: hoursOverdue / intervalHours
|
|
1989
|
+
* - Interval recency: exponential decay favoring shorter intervals
|
|
1990
|
+
*
|
|
1991
|
+
* Cards not yet due are excluded (not scored as 0).
|
|
1992
|
+
*
|
|
1993
|
+
* This method supports both the legacy signature (limit only) and the
|
|
1994
|
+
* CardGenerator interface signature (limit, context).
|
|
1995
|
+
*
|
|
1996
|
+
* @param limit - Maximum number of cards to return
|
|
1997
|
+
* @param _context - Optional GeneratorContext (currently unused, but required for interface)
|
|
1998
|
+
*/
|
|
1999
|
+
async getWeightedCards(limit, _context) {
|
|
2000
|
+
if (!this.user || !this.course) {
|
|
2001
|
+
throw new Error("SRSNavigator requires user and course to be set");
|
|
2002
|
+
}
|
|
718
2003
|
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
719
|
-
|
|
2004
|
+
const now = import_moment.default.utc();
|
|
2005
|
+
const dueReviews = reviews.filter((r) => now.isAfter(import_moment.default.utc(r.reviewTime)));
|
|
2006
|
+
const scored = dueReviews.map((review) => {
|
|
2007
|
+
const { score, reason } = this.computeUrgencyScore(review, now);
|
|
720
2008
|
return {
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
2009
|
+
cardId: review.cardId,
|
|
2010
|
+
courseId: review.courseId,
|
|
2011
|
+
score,
|
|
2012
|
+
provenance: [
|
|
2013
|
+
{
|
|
2014
|
+
strategy: "srs",
|
|
2015
|
+
strategyName: this.strategyName || this.name,
|
|
2016
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-SRS-default",
|
|
2017
|
+
action: "generated",
|
|
2018
|
+
score,
|
|
2019
|
+
reason
|
|
2020
|
+
}
|
|
2021
|
+
]
|
|
728
2022
|
};
|
|
729
2023
|
});
|
|
2024
|
+
return scored.sort((a, b) => b.score - a.score).slice(0, limit);
|
|
730
2025
|
}
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
2026
|
+
/**
|
|
2027
|
+
* Compute urgency score for a review card.
|
|
2028
|
+
*
|
|
2029
|
+
* Two factors:
|
|
2030
|
+
* 1. Relative overdueness = hoursOverdue / intervalHours
|
|
2031
|
+
* - 2 days overdue on 3-day interval = 0.67 (urgent)
|
|
2032
|
+
* - 2 days overdue on 180-day interval = 0.01 (not urgent)
|
|
2033
|
+
*
|
|
2034
|
+
* 2. Interval recency factor = 0.3 + 0.7 * exp(-intervalHours / 720)
|
|
2035
|
+
* - 24h interval → ~1.0 (very recent learning)
|
|
2036
|
+
* - 30 days (720h) → ~0.56
|
|
2037
|
+
* - 180 days → ~0.30
|
|
2038
|
+
*
|
|
2039
|
+
* Combined: base 0.5 + weighted average of factors * 0.45
|
|
2040
|
+
* Result range: approximately 0.5 to 0.95
|
|
2041
|
+
*/
|
|
2042
|
+
computeUrgencyScore(review, now) {
|
|
2043
|
+
const scheduledAt = import_moment.default.utc(review.scheduledAt);
|
|
2044
|
+
const due = import_moment.default.utc(review.reviewTime);
|
|
2045
|
+
const intervalHours = Math.max(1, due.diff(scheduledAt, "hours"));
|
|
2046
|
+
const hoursOverdue = now.diff(due, "hours");
|
|
2047
|
+
const relativeOverdue = hoursOverdue / intervalHours;
|
|
2048
|
+
const recencyFactor = 0.3 + 0.7 * Math.exp(-intervalHours / 720);
|
|
2049
|
+
const overdueContribution = Math.min(1, Math.max(0, relativeOverdue));
|
|
2050
|
+
const urgency = overdueContribution * 0.5 + recencyFactor * 0.5;
|
|
2051
|
+
const score = Math.min(0.95, 0.5 + urgency * 0.45);
|
|
2052
|
+
const reason = `${Math.round(hoursOverdue)}h overdue (interval: ${Math.round(intervalHours)}h, relative: ${relativeOverdue.toFixed(2)}), recency: ${recencyFactor.toFixed(2)}, review`;
|
|
2053
|
+
return { score, reason };
|
|
2054
|
+
}
|
|
2055
|
+
/**
|
|
2056
|
+
* Get pending reviews in legacy format.
|
|
2057
|
+
*
|
|
2058
|
+
* Returns all pending reviews for the course, enriched with session item fields.
|
|
2059
|
+
*/
|
|
2060
|
+
async getPendingReviews() {
|
|
2061
|
+
if (!this.user || !this.course) {
|
|
2062
|
+
throw new Error("SRSNavigator requires user and course to be set");
|
|
2063
|
+
}
|
|
2064
|
+
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
2065
|
+
return reviews.map((r) => ({
|
|
2066
|
+
...r,
|
|
2067
|
+
contentSourceType: "course",
|
|
2068
|
+
contentSourceID: this.course.getCourseID(),
|
|
2069
|
+
cardID: r.cardId,
|
|
2070
|
+
courseID: r.courseId,
|
|
2071
|
+
qualifiedID: `${r.courseId}-${r.cardId}`,
|
|
2072
|
+
reviewID: r._id,
|
|
2073
|
+
status: "review"
|
|
2074
|
+
}));
|
|
2075
|
+
}
|
|
2076
|
+
/**
|
|
2077
|
+
* SRS does not generate new cards.
|
|
2078
|
+
* Use ELONavigator or another generator for new cards.
|
|
2079
|
+
*/
|
|
2080
|
+
async getNewCards(_n) {
|
|
2081
|
+
return [];
|
|
746
2082
|
}
|
|
747
2083
|
};
|
|
748
2084
|
}
|
|
@@ -753,9 +2089,21 @@ var globImport;
|
|
|
753
2089
|
var init_ = __esm({
|
|
754
2090
|
'import("./**/*") in src/core/navigators/index.ts'() {
|
|
755
2091
|
globImport = __glob({
|
|
2092
|
+
"./CompositeGenerator.ts": () => Promise.resolve().then(() => (init_CompositeGenerator(), CompositeGenerator_exports)),
|
|
2093
|
+
"./Pipeline.ts": () => Promise.resolve().then(() => (init_Pipeline(), Pipeline_exports)),
|
|
2094
|
+
"./PipelineAssembler.ts": () => Promise.resolve().then(() => (init_PipelineAssembler(), PipelineAssembler_exports)),
|
|
756
2095
|
"./elo.ts": () => Promise.resolve().then(() => (init_elo(), elo_exports)),
|
|
2096
|
+
"./filters/eloDistance.ts": () => Promise.resolve().then(() => (init_eloDistance(), eloDistance_exports)),
|
|
2097
|
+
"./filters/index.ts": () => Promise.resolve().then(() => (init_filters(), filters_exports)),
|
|
2098
|
+
"./filters/types.ts": () => Promise.resolve().then(() => (init_types(), types_exports)),
|
|
2099
|
+
"./generators/index.ts": () => Promise.resolve().then(() => (init_generators(), generators_exports)),
|
|
2100
|
+
"./generators/types.ts": () => Promise.resolve().then(() => (init_types2(), types_exports2)),
|
|
757
2101
|
"./hardcodedOrder.ts": () => Promise.resolve().then(() => (init_hardcodedOrder(), hardcodedOrder_exports)),
|
|
758
|
-
"./
|
|
2102
|
+
"./hierarchyDefinition.ts": () => Promise.resolve().then(() => (init_hierarchyDefinition(), hierarchyDefinition_exports)),
|
|
2103
|
+
"./index.ts": () => Promise.resolve().then(() => (init_navigators(), navigators_exports)),
|
|
2104
|
+
"./interferenceMitigator.ts": () => Promise.resolve().then(() => (init_interferenceMitigator(), interferenceMitigator_exports)),
|
|
2105
|
+
"./relativePriority.ts": () => Promise.resolve().then(() => (init_relativePriority(), relativePriority_exports)),
|
|
2106
|
+
"./srs.ts": () => Promise.resolve().then(() => (init_srs(), srs_exports))
|
|
759
2107
|
});
|
|
760
2108
|
}
|
|
761
2109
|
});
|
|
@@ -764,9 +2112,34 @@ var init_ = __esm({
|
|
|
764
2112
|
var navigators_exports = {};
|
|
765
2113
|
__export(navigators_exports, {
|
|
766
2114
|
ContentNavigator: () => ContentNavigator,
|
|
767
|
-
|
|
2115
|
+
NavigatorRole: () => NavigatorRole,
|
|
2116
|
+
NavigatorRoles: () => NavigatorRoles,
|
|
2117
|
+
Navigators: () => Navigators,
|
|
2118
|
+
getCardOrigin: () => getCardOrigin,
|
|
2119
|
+
isFilter: () => isFilter,
|
|
2120
|
+
isGenerator: () => isGenerator
|
|
768
2121
|
});
|
|
769
|
-
|
|
2122
|
+
function getCardOrigin(card) {
|
|
2123
|
+
if (card.provenance.length === 0) {
|
|
2124
|
+
throw new Error("Card has no provenance - cannot determine origin");
|
|
2125
|
+
}
|
|
2126
|
+
const firstEntry = card.provenance[0];
|
|
2127
|
+
const reason = firstEntry.reason.toLowerCase();
|
|
2128
|
+
if (reason.includes("failed")) {
|
|
2129
|
+
return "failed";
|
|
2130
|
+
}
|
|
2131
|
+
if (reason.includes("review")) {
|
|
2132
|
+
return "review";
|
|
2133
|
+
}
|
|
2134
|
+
return "new";
|
|
2135
|
+
}
|
|
2136
|
+
function isGenerator(impl) {
|
|
2137
|
+
return NavigatorRoles[impl] === "generator" /* GENERATOR */;
|
|
2138
|
+
}
|
|
2139
|
+
function isFilter(impl) {
|
|
2140
|
+
return NavigatorRoles[impl] === "filter" /* FILTER */;
|
|
2141
|
+
}
|
|
2142
|
+
var Navigators, NavigatorRole, NavigatorRoles, ContentNavigator;
|
|
770
2143
|
var init_navigators = __esm({
|
|
771
2144
|
"src/core/navigators/index.ts"() {
|
|
772
2145
|
"use strict";
|
|
@@ -774,14 +2147,55 @@ var init_navigators = __esm({
|
|
|
774
2147
|
init_();
|
|
775
2148
|
Navigators = /* @__PURE__ */ ((Navigators2) => {
|
|
776
2149
|
Navigators2["ELO"] = "elo";
|
|
2150
|
+
Navigators2["SRS"] = "srs";
|
|
777
2151
|
Navigators2["HARDCODED"] = "hardcodedOrder";
|
|
2152
|
+
Navigators2["HIERARCHY"] = "hierarchyDefinition";
|
|
2153
|
+
Navigators2["INTERFERENCE"] = "interferenceMitigator";
|
|
2154
|
+
Navigators2["RELATIVE_PRIORITY"] = "relativePriority";
|
|
778
2155
|
return Navigators2;
|
|
779
2156
|
})(Navigators || {});
|
|
2157
|
+
NavigatorRole = /* @__PURE__ */ ((NavigatorRole2) => {
|
|
2158
|
+
NavigatorRole2["GENERATOR"] = "generator";
|
|
2159
|
+
NavigatorRole2["FILTER"] = "filter";
|
|
2160
|
+
return NavigatorRole2;
|
|
2161
|
+
})(NavigatorRole || {});
|
|
2162
|
+
NavigatorRoles = {
|
|
2163
|
+
["elo" /* ELO */]: "generator" /* GENERATOR */,
|
|
2164
|
+
["srs" /* SRS */]: "generator" /* GENERATOR */,
|
|
2165
|
+
["hardcodedOrder" /* HARDCODED */]: "generator" /* GENERATOR */,
|
|
2166
|
+
["hierarchyDefinition" /* HIERARCHY */]: "filter" /* FILTER */,
|
|
2167
|
+
["interferenceMitigator" /* INTERFERENCE */]: "filter" /* FILTER */,
|
|
2168
|
+
["relativePriority" /* RELATIVE_PRIORITY */]: "filter" /* FILTER */
|
|
2169
|
+
};
|
|
780
2170
|
ContentNavigator = class {
|
|
2171
|
+
/** User interface for this navigation session */
|
|
2172
|
+
user;
|
|
2173
|
+
/** Course interface for this navigation session */
|
|
2174
|
+
course;
|
|
2175
|
+
/** Human-readable name for this strategy instance (from ContentNavigationStrategyData.name) */
|
|
2176
|
+
strategyName;
|
|
2177
|
+
/** Unique document ID for this strategy instance (from ContentNavigationStrategyData._id) */
|
|
2178
|
+
strategyId;
|
|
2179
|
+
/**
|
|
2180
|
+
* Constructor for standard navigators.
|
|
2181
|
+
* Call this from subclass constructors to initialize common fields.
|
|
2182
|
+
*
|
|
2183
|
+
* Note: CompositeGenerator doesn't use this pattern and should call super() without args.
|
|
2184
|
+
*/
|
|
2185
|
+
constructor(user, course, strategyData) {
|
|
2186
|
+
if (user && course && strategyData) {
|
|
2187
|
+
this.user = user;
|
|
2188
|
+
this.course = course;
|
|
2189
|
+
this.strategyName = strategyData.name;
|
|
2190
|
+
this.strategyId = strategyData._id;
|
|
2191
|
+
}
|
|
2192
|
+
}
|
|
781
2193
|
/**
|
|
2194
|
+
* Factory method to create navigator instances dynamically.
|
|
782
2195
|
*
|
|
783
|
-
* @param user
|
|
784
|
-
* @param
|
|
2196
|
+
* @param user - User interface
|
|
2197
|
+
* @param course - Course interface
|
|
2198
|
+
* @param strategyData - Strategy configuration document
|
|
785
2199
|
* @returns the runtime object used to steer a study session.
|
|
786
2200
|
*/
|
|
787
2201
|
static async create(user, course, strategyData) {
|
|
@@ -802,6 +2216,70 @@ var init_navigators = __esm({
|
|
|
802
2216
|
}
|
|
803
2217
|
return new NavigatorImpl(user, course, strategyData);
|
|
804
2218
|
}
|
|
2219
|
+
/**
|
|
2220
|
+
* Get cards with suitability scores and provenance trails.
|
|
2221
|
+
*
|
|
2222
|
+
* **This is the PRIMARY API for navigation strategies.**
|
|
2223
|
+
*
|
|
2224
|
+
* Returns cards ranked by suitability score (0-1). Higher scores indicate
|
|
2225
|
+
* better candidates for presentation. Each card includes a provenance trail
|
|
2226
|
+
* documenting how strategies contributed to the final score.
|
|
2227
|
+
*
|
|
2228
|
+
* ## For Generators
|
|
2229
|
+
* Override this method to generate candidates and compute scores based on
|
|
2230
|
+
* your strategy's logic (e.g., ELO proximity, review urgency). Create the
|
|
2231
|
+
* initial provenance entry with action='generated'.
|
|
2232
|
+
*
|
|
2233
|
+
* ## Default Implementation
|
|
2234
|
+
* The base class provides a backward-compatible default that:
|
|
2235
|
+
* 1. Calls legacy getNewCards() and getPendingReviews()
|
|
2236
|
+
* 2. Assigns score=1.0 to all cards
|
|
2237
|
+
* 3. Creates minimal provenance from legacy methods
|
|
2238
|
+
* 4. Returns combined results up to limit
|
|
2239
|
+
*
|
|
2240
|
+
* This allows existing strategies to work without modification while
|
|
2241
|
+
* new strategies can override with proper scoring and provenance.
|
|
2242
|
+
*
|
|
2243
|
+
* @param limit - Maximum cards to return
|
|
2244
|
+
* @returns Cards sorted by score descending, with provenance trails
|
|
2245
|
+
*/
|
|
2246
|
+
async getWeightedCards(limit) {
|
|
2247
|
+
const newCards = await this.getNewCards(limit);
|
|
2248
|
+
const reviews = await this.getPendingReviews();
|
|
2249
|
+
const weighted = [
|
|
2250
|
+
...newCards.map((c) => ({
|
|
2251
|
+
cardId: c.cardID,
|
|
2252
|
+
courseId: c.courseID,
|
|
2253
|
+
score: 1,
|
|
2254
|
+
provenance: [
|
|
2255
|
+
{
|
|
2256
|
+
strategy: "legacy",
|
|
2257
|
+
strategyName: this.strategyName || "Legacy API",
|
|
2258
|
+
strategyId: this.strategyId || "legacy-fallback",
|
|
2259
|
+
action: "generated",
|
|
2260
|
+
score: 1,
|
|
2261
|
+
reason: "Generated via legacy getNewCards(), new card"
|
|
2262
|
+
}
|
|
2263
|
+
]
|
|
2264
|
+
})),
|
|
2265
|
+
...reviews.map((r) => ({
|
|
2266
|
+
cardId: r.cardID,
|
|
2267
|
+
courseId: r.courseID,
|
|
2268
|
+
score: 1,
|
|
2269
|
+
provenance: [
|
|
2270
|
+
{
|
|
2271
|
+
strategy: "legacy",
|
|
2272
|
+
strategyName: this.strategyName || "Legacy API",
|
|
2273
|
+
strategyId: this.strategyId || "legacy-fallback",
|
|
2274
|
+
action: "generated",
|
|
2275
|
+
score: 1,
|
|
2276
|
+
reason: "Generated via legacy getPendingReviews(), review"
|
|
2277
|
+
}
|
|
2278
|
+
]
|
|
2279
|
+
}))
|
|
2280
|
+
];
|
|
2281
|
+
return weighted.slice(0, limit);
|
|
2282
|
+
}
|
|
805
2283
|
};
|
|
806
2284
|
}
|
|
807
2285
|
});
|
|
@@ -924,11 +2402,11 @@ ${JSON.stringify(config)}
|
|
|
924
2402
|
function isSuccessRow(row) {
|
|
925
2403
|
return "doc" in row && row.doc !== null && row.doc !== void 0;
|
|
926
2404
|
}
|
|
927
|
-
var
|
|
2405
|
+
var import_common9, CoursesDB, CourseDB;
|
|
928
2406
|
var init_courseDB = __esm({
|
|
929
2407
|
"src/impl/couch/courseDB.ts"() {
|
|
930
2408
|
"use strict";
|
|
931
|
-
|
|
2409
|
+
import_common9 = require("@vue-skuilder/common");
|
|
932
2410
|
init_couch();
|
|
933
2411
|
init_updateQueue();
|
|
934
2412
|
init_types_legacy();
|
|
@@ -937,6 +2415,12 @@ var init_courseDB = __esm({
|
|
|
937
2415
|
init_courseAPI();
|
|
938
2416
|
init_courseLookupDB();
|
|
939
2417
|
init_navigators();
|
|
2418
|
+
init_Pipeline();
|
|
2419
|
+
init_PipelineAssembler();
|
|
2420
|
+
init_CompositeGenerator();
|
|
2421
|
+
init_elo();
|
|
2422
|
+
init_srs();
|
|
2423
|
+
init_eloDistance();
|
|
940
2424
|
CoursesDB = class {
|
|
941
2425
|
_courseIDs;
|
|
942
2426
|
constructor(courseIDs) {
|
|
@@ -1048,14 +2532,14 @@ var init_courseDB = __esm({
|
|
|
1048
2532
|
docs.rows.forEach((r) => {
|
|
1049
2533
|
if (isSuccessRow(r)) {
|
|
1050
2534
|
if (r.doc && r.doc.elo) {
|
|
1051
|
-
ret.push((0,
|
|
2535
|
+
ret.push((0, import_common9.toCourseElo)(r.doc.elo));
|
|
1052
2536
|
} else {
|
|
1053
2537
|
logger.warn("no elo data for card: " + r.id);
|
|
1054
|
-
ret.push((0,
|
|
2538
|
+
ret.push((0, import_common9.blankCourseElo)());
|
|
1055
2539
|
}
|
|
1056
2540
|
} else {
|
|
1057
2541
|
logger.warn("no elo data for card: " + JSON.stringify(r));
|
|
1058
|
-
ret.push((0,
|
|
2542
|
+
ret.push((0, import_common9.blankCourseElo)());
|
|
1059
2543
|
}
|
|
1060
2544
|
});
|
|
1061
2545
|
return ret;
|
|
@@ -1237,7 +2721,7 @@ ${above.rows.map((r) => ` ${r.id}-${r.key}
|
|
|
1237
2721
|
async getCourseTagStubs() {
|
|
1238
2722
|
return getCourseTagStubs(this.id);
|
|
1239
2723
|
}
|
|
1240
|
-
async addNote(codeCourse, shape, data, author, tags, uploads, elo = (0,
|
|
2724
|
+
async addNote(codeCourse, shape, data, author, tags, uploads, elo = (0, import_common9.blankCourseElo)()) {
|
|
1241
2725
|
try {
|
|
1242
2726
|
const resp = await addNote55(this.id, codeCourse, shape, data, author, tags, uploads, elo);
|
|
1243
2727
|
if (resp.ok) {
|
|
@@ -1246,19 +2730,19 @@ ${above.rows.map((r) => ` ${r.id}-${r.key}
|
|
|
1246
2730
|
`[courseDB.addNote] Note added but card creation failed: ${resp.cardCreationError}`
|
|
1247
2731
|
);
|
|
1248
2732
|
return {
|
|
1249
|
-
status:
|
|
2733
|
+
status: import_common9.Status.error,
|
|
1250
2734
|
message: `Note was added but no cards were created: ${resp.cardCreationError}`,
|
|
1251
2735
|
id: resp.id
|
|
1252
2736
|
};
|
|
1253
2737
|
}
|
|
1254
2738
|
return {
|
|
1255
|
-
status:
|
|
2739
|
+
status: import_common9.Status.ok,
|
|
1256
2740
|
message: "",
|
|
1257
2741
|
id: resp.id
|
|
1258
2742
|
};
|
|
1259
2743
|
} else {
|
|
1260
2744
|
return {
|
|
1261
|
-
status:
|
|
2745
|
+
status: import_common9.Status.error,
|
|
1262
2746
|
message: "Unexpected error adding note"
|
|
1263
2747
|
};
|
|
1264
2748
|
}
|
|
@@ -1270,7 +2754,7 @@ ${above.rows.map((r) => ` ${r.id}-${r.key}
|
|
|
1270
2754
|
message: ${err.message}`
|
|
1271
2755
|
);
|
|
1272
2756
|
return {
|
|
1273
|
-
status:
|
|
2757
|
+
status: import_common9.Status.error,
|
|
1274
2758
|
message: `Error adding note to course. ${e.reason || err.message}`
|
|
1275
2759
|
};
|
|
1276
2760
|
}
|
|
@@ -1321,42 +2805,82 @@ ${above.rows.map((r) => ` ${r.id}-${r.key}
|
|
|
1321
2805
|
logger.debug(JSON.stringify(data));
|
|
1322
2806
|
return Promise.resolve();
|
|
1323
2807
|
}
|
|
1324
|
-
|
|
2808
|
+
/**
|
|
2809
|
+
* Creates an instantiated navigator for this course.
|
|
2810
|
+
*
|
|
2811
|
+
* Handles multiple generators by wrapping them in CompositeGenerator.
|
|
2812
|
+
* This is the preferred method for getting a ready-to-use navigator.
|
|
2813
|
+
*
|
|
2814
|
+
* @param user - User database interface
|
|
2815
|
+
* @returns Instantiated ContentNavigator ready for use
|
|
2816
|
+
*/
|
|
2817
|
+
async createNavigator(user) {
|
|
1325
2818
|
try {
|
|
1326
|
-
const
|
|
1327
|
-
if (
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
return strategy;
|
|
1333
|
-
}
|
|
1334
|
-
} catch (e) {
|
|
1335
|
-
logger.warn(
|
|
1336
|
-
// @ts-expect-error tmp: defaultNavigationStrategyId property does not yet exist
|
|
1337
|
-
`Failed to load strategy '${config.defaultNavigationStrategyId}' specified in course config. Falling back to ELO.`,
|
|
1338
|
-
e
|
|
1339
|
-
);
|
|
1340
|
-
}
|
|
2819
|
+
const allStrategies = await this.getAllNavigationStrategies();
|
|
2820
|
+
if (allStrategies.length === 0) {
|
|
2821
|
+
logger.debug(
|
|
2822
|
+
"[courseDB] No strategy documents found, using default Pipeline(Composite(ELO, SRS), [eloDistanceFilter])"
|
|
2823
|
+
);
|
|
2824
|
+
return this.createDefaultPipeline(user);
|
|
1341
2825
|
}
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
2826
|
+
const assembler = new PipelineAssembler();
|
|
2827
|
+
const { pipeline, generatorStrategies, filterStrategies, warnings } = await assembler.assemble({
|
|
2828
|
+
strategies: allStrategies,
|
|
2829
|
+
user,
|
|
2830
|
+
course: this
|
|
2831
|
+
});
|
|
2832
|
+
for (const warning of warnings) {
|
|
2833
|
+
logger.warn(`[PipelineAssembler] ${warning}`);
|
|
2834
|
+
}
|
|
2835
|
+
if (!pipeline) {
|
|
2836
|
+
logger.debug("[courseDB] Pipeline assembly failed, using default pipeline");
|
|
2837
|
+
return this.createDefaultPipeline(user);
|
|
2838
|
+
}
|
|
2839
|
+
logger.debug(
|
|
2840
|
+
`[courseDB] Using assembled pipeline with ${generatorStrategies.length} generator(s) and ${filterStrategies.length} filter(s)`
|
|
1346
2841
|
);
|
|
2842
|
+
return pipeline;
|
|
2843
|
+
} catch (e) {
|
|
2844
|
+
logger.error(`[courseDB] Error creating navigator: ${e}`);
|
|
2845
|
+
throw e;
|
|
1347
2846
|
}
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
2847
|
+
}
|
|
2848
|
+
makeDefaultEloStrategy() {
|
|
2849
|
+
return {
|
|
2850
|
+
_id: "NAVIGATION_STRATEGY-ELO-default",
|
|
1351
2851
|
docType: "NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */,
|
|
1352
|
-
name: "ELO",
|
|
1353
|
-
description: "ELO-based navigation strategy",
|
|
2852
|
+
name: "ELO (default)",
|
|
2853
|
+
description: "Default ELO-based navigation strategy for new cards",
|
|
1354
2854
|
implementingClass: "elo" /* ELO */,
|
|
1355
2855
|
course: this.id,
|
|
1356
2856
|
serializedData: ""
|
|
1357
|
-
// serde is a noop for ELO navigator.
|
|
1358
2857
|
};
|
|
1359
|
-
|
|
2858
|
+
}
|
|
2859
|
+
makeDefaultSrsStrategy() {
|
|
2860
|
+
return {
|
|
2861
|
+
_id: "NAVIGATION_STRATEGY-SRS-default",
|
|
2862
|
+
docType: "NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */,
|
|
2863
|
+
name: "SRS (default)",
|
|
2864
|
+
description: "Default SRS-based navigation strategy for reviews",
|
|
2865
|
+
implementingClass: "srs" /* SRS */,
|
|
2866
|
+
course: this.id,
|
|
2867
|
+
serializedData: ""
|
|
2868
|
+
};
|
|
2869
|
+
}
|
|
2870
|
+
/**
|
|
2871
|
+
* Creates the default navigation pipeline for courses with no configured strategies.
|
|
2872
|
+
*
|
|
2873
|
+
* Default: Pipeline(Composite(ELO, SRS), [eloDistanceFilter])
|
|
2874
|
+
* - ELO generator: scores new cards by skill proximity
|
|
2875
|
+
* - SRS generator: scores reviews by overdueness and interval recency
|
|
2876
|
+
* - ELO distance filter: penalizes cards far from user's current level
|
|
2877
|
+
*/
|
|
2878
|
+
createDefaultPipeline(user) {
|
|
2879
|
+
const eloNavigator = new ELONavigator(user, this, this.makeDefaultEloStrategy());
|
|
2880
|
+
const srsNavigator = new SRSNavigator(user, this, this.makeDefaultSrsStrategy());
|
|
2881
|
+
const compositeGenerator = new CompositeGenerator([eloNavigator, srsNavigator]);
|
|
2882
|
+
const eloDistanceFilter = createEloDistanceFilter();
|
|
2883
|
+
return new Pipeline(compositeGenerator, [eloDistanceFilter], user, this);
|
|
1360
2884
|
}
|
|
1361
2885
|
////////////////////////////////////
|
|
1362
2886
|
// END NavigationStrategyManager implementation
|
|
@@ -1367,22 +2891,39 @@ ${above.rows.map((r) => ` ${r.id}-${r.key}
|
|
|
1367
2891
|
async getNewCards(limit = 99) {
|
|
1368
2892
|
const u = await this._getCurrentUser();
|
|
1369
2893
|
try {
|
|
1370
|
-
const
|
|
1371
|
-
const navigator = await ContentNavigator.create(u, this, strategy);
|
|
2894
|
+
const navigator = await this.createNavigator(u);
|
|
1372
2895
|
return navigator.getNewCards(limit);
|
|
1373
2896
|
} catch (e) {
|
|
1374
|
-
logger.error(`[courseDB] Error
|
|
2897
|
+
logger.error(`[courseDB] Error in getNewCards: ${e}`);
|
|
1375
2898
|
throw e;
|
|
1376
2899
|
}
|
|
1377
2900
|
}
|
|
1378
2901
|
async getPendingReviews() {
|
|
1379
2902
|
const u = await this._getCurrentUser();
|
|
1380
2903
|
try {
|
|
1381
|
-
const
|
|
1382
|
-
const navigator = await ContentNavigator.create(u, this, strategy);
|
|
2904
|
+
const navigator = await this.createNavigator(u);
|
|
1383
2905
|
return navigator.getPendingReviews();
|
|
1384
2906
|
} catch (e) {
|
|
1385
|
-
logger.error(`[courseDB] Error
|
|
2907
|
+
logger.error(`[courseDB] Error in getPendingReviews: ${e}`);
|
|
2908
|
+
throw e;
|
|
2909
|
+
}
|
|
2910
|
+
}
|
|
2911
|
+
/**
|
|
2912
|
+
* Get cards with suitability scores for presentation.
|
|
2913
|
+
*
|
|
2914
|
+
* This is the PRIMARY API for content sources going forward. Delegates to the
|
|
2915
|
+
* course's configured NavigationStrategy to get scored candidates.
|
|
2916
|
+
*
|
|
2917
|
+
* @param limit - Maximum number of cards to return
|
|
2918
|
+
* @returns Cards sorted by score descending
|
|
2919
|
+
*/
|
|
2920
|
+
async getWeightedCards(limit) {
|
|
2921
|
+
const u = await this._getCurrentUser();
|
|
2922
|
+
try {
|
|
2923
|
+
const navigator = await this.createNavigator(u);
|
|
2924
|
+
return navigator.getWeightedCards(limit);
|
|
2925
|
+
} catch (e) {
|
|
2926
|
+
logger.error(`[courseDB] Error getting weighted cards: ${e}`);
|
|
1386
2927
|
throw e;
|
|
1387
2928
|
}
|
|
1388
2929
|
}
|
|
@@ -1398,7 +2939,7 @@ ${above.rows.map((r) => ` ${r.id}-${r.key}
|
|
|
1398
2939
|
const courseDoc = (await u.getCourseRegistrationsDoc()).courses.find((c) => {
|
|
1399
2940
|
return c.courseID === this.id;
|
|
1400
2941
|
});
|
|
1401
|
-
targetElo = (0,
|
|
2942
|
+
targetElo = (0, import_common9.EloToNumber)(courseDoc.elo);
|
|
1402
2943
|
} catch {
|
|
1403
2944
|
targetElo = 1e3;
|
|
1404
2945
|
}
|
|
@@ -1533,13 +3074,13 @@ function getClassroomDB(classID, version) {
|
|
|
1533
3074
|
async function getClassroomConfig(classID) {
|
|
1534
3075
|
return await getClassroomDB(classID, "student").get(CLASSROOM_CONFIG);
|
|
1535
3076
|
}
|
|
1536
|
-
var
|
|
3077
|
+
var import_moment2, classroomLookupDBTitle, CLASSROOM_CONFIG, ClassroomDBBase, StudentClassroomDB, TeacherClassroomDB, ClassroomLookupDB;
|
|
1537
3078
|
var init_classroomDB2 = __esm({
|
|
1538
3079
|
"src/impl/couch/classroomDB.ts"() {
|
|
1539
3080
|
"use strict";
|
|
1540
3081
|
init_factory();
|
|
1541
3082
|
init_logger();
|
|
1542
|
-
|
|
3083
|
+
import_moment2 = __toESM(require("moment"), 1);
|
|
1543
3084
|
init_pouchdb_setup();
|
|
1544
3085
|
init_couch();
|
|
1545
3086
|
init_courseDB();
|
|
@@ -1634,9 +3175,9 @@ var init_classroomDB2 = __esm({
|
|
|
1634
3175
|
}
|
|
1635
3176
|
async getNewCards() {
|
|
1636
3177
|
const activeCards = await this._user.getActiveCards();
|
|
1637
|
-
const now =
|
|
3178
|
+
const now = import_moment2.default.utc();
|
|
1638
3179
|
const assigned = await this.getAssignedContent();
|
|
1639
|
-
const due = assigned.filter((c) => now.isAfter(
|
|
3180
|
+
const due = assigned.filter((c) => now.isAfter(import_moment2.default.utc(c.activeOn, REVIEW_TIME_FORMAT)));
|
|
1640
3181
|
logger.info(`Due content: ${JSON.stringify(due)}`);
|
|
1641
3182
|
let ret = [];
|
|
1642
3183
|
for (let i = 0; i < due.length; i++) {
|
|
@@ -1673,6 +3214,52 @@ var init_classroomDB2 = __esm({
|
|
|
1673
3214
|
}
|
|
1674
3215
|
});
|
|
1675
3216
|
}
|
|
3217
|
+
/**
|
|
3218
|
+
* Get cards with suitability scores for presentation.
|
|
3219
|
+
*
|
|
3220
|
+
* This implementation wraps the legacy getNewCards/getPendingReviews methods,
|
|
3221
|
+
* assigning score=1.0 to all cards. StudentClassroomDB does not currently
|
|
3222
|
+
* support pluggable navigation strategies.
|
|
3223
|
+
*
|
|
3224
|
+
* @param limit - Maximum number of cards to return
|
|
3225
|
+
* @returns Cards sorted by score descending (all scores = 1.0)
|
|
3226
|
+
*/
|
|
3227
|
+
async getWeightedCards(limit) {
|
|
3228
|
+
const [newCards, reviews] = await Promise.all([this.getNewCards(), this.getPendingReviews()]);
|
|
3229
|
+
const weighted = [
|
|
3230
|
+
...newCards.map((c) => ({
|
|
3231
|
+
cardId: c.cardID,
|
|
3232
|
+
courseId: c.courseID,
|
|
3233
|
+
score: 1,
|
|
3234
|
+
provenance: [
|
|
3235
|
+
{
|
|
3236
|
+
strategy: "classroom",
|
|
3237
|
+
strategyName: "Classroom",
|
|
3238
|
+
strategyId: "CLASSROOM",
|
|
3239
|
+
action: "generated",
|
|
3240
|
+
score: 1,
|
|
3241
|
+
reason: "Classroom legacy getNewCards(), new card"
|
|
3242
|
+
}
|
|
3243
|
+
]
|
|
3244
|
+
})),
|
|
3245
|
+
...reviews.map((r) => ({
|
|
3246
|
+
cardId: r.cardID,
|
|
3247
|
+
courseId: r.courseID,
|
|
3248
|
+
score: 1,
|
|
3249
|
+
provenance: [
|
|
3250
|
+
{
|
|
3251
|
+
strategy: "classroom",
|
|
3252
|
+
strategyName: "Classroom",
|
|
3253
|
+
strategyId: "CLASSROOM",
|
|
3254
|
+
action: "generated",
|
|
3255
|
+
score: 1,
|
|
3256
|
+
reason: "Classroom legacy getPendingReviews(), review"
|
|
3257
|
+
}
|
|
3258
|
+
]
|
|
3259
|
+
}))
|
|
3260
|
+
];
|
|
3261
|
+
return weighted.slice(0, limit);
|
|
3262
|
+
}
|
|
1676
3263
|
};
|
|
1677
3264
|
TeacherClassroomDB = class _TeacherClassroomDB extends ClassroomDBBase {
|
|
1678
3265
|
_stuDb;
|
|
@@ -1729,8 +3316,8 @@ var init_classroomDB2 = __esm({
|
|
|
1729
3316
|
type: "tag",
|
|
1730
3317
|
_id: id,
|
|
1731
3318
|
assignedBy: content.assignedBy,
|
|
1732
|
-
assignedOn:
|
|
1733
|
-
activeOn: content.activeOn ||
|
|
3319
|
+
assignedOn: import_moment2.default.utc(),
|
|
3320
|
+
activeOn: content.activeOn || import_moment2.default.utc()
|
|
1734
3321
|
});
|
|
1735
3322
|
} else {
|
|
1736
3323
|
put = await this._db.put({
|
|
@@ -1738,8 +3325,8 @@ var init_classroomDB2 = __esm({
|
|
|
1738
3325
|
type: "course",
|
|
1739
3326
|
_id: id,
|
|
1740
3327
|
assignedBy: content.assignedBy,
|
|
1741
|
-
assignedOn:
|
|
1742
|
-
activeOn: content.activeOn ||
|
|
3328
|
+
assignedOn: import_moment2.default.utc(),
|
|
3329
|
+
activeOn: content.activeOn || import_moment2.default.utc()
|
|
1743
3330
|
});
|
|
1744
3331
|
}
|
|
1745
3332
|
if (put.ok) {
|
|
@@ -1758,6 +3345,213 @@ var init_classroomDB2 = __esm({
|
|
|
1758
3345
|
}
|
|
1759
3346
|
});
|
|
1760
3347
|
|
|
3348
|
+
// src/study/TagFilteredContentSource.ts
|
|
3349
|
+
var import_common10, TagFilteredContentSource;
|
|
3350
|
+
var init_TagFilteredContentSource = __esm({
|
|
3351
|
+
"src/study/TagFilteredContentSource.ts"() {
|
|
3352
|
+
"use strict";
|
|
3353
|
+
import_common10 = require("@vue-skuilder/common");
|
|
3354
|
+
init_courseDB();
|
|
3355
|
+
init_logger();
|
|
3356
|
+
TagFilteredContentSource = class {
|
|
3357
|
+
courseId;
|
|
3358
|
+
filter;
|
|
3359
|
+
user;
|
|
3360
|
+
// Cache resolved card IDs to avoid repeated lookups within a session
|
|
3361
|
+
resolvedCardIds = null;
|
|
3362
|
+
constructor(courseId, filter, user) {
|
|
3363
|
+
this.courseId = courseId;
|
|
3364
|
+
this.filter = filter;
|
|
3365
|
+
this.user = user;
|
|
3366
|
+
logger.info(
|
|
3367
|
+
`[TagFilteredContentSource] Created for course "${courseId}" with filter:`,
|
|
3368
|
+
JSON.stringify(filter)
|
|
3369
|
+
);
|
|
3370
|
+
}
|
|
3371
|
+
/**
|
|
3372
|
+
* Resolves the TagFilter to a set of eligible card IDs.
|
|
3373
|
+
*
|
|
3374
|
+
* - Cards in `include` tags are OR'd together (card needs at least one)
|
|
3375
|
+
* - Cards in `exclude` tags are removed from the result
|
|
3376
|
+
*/
|
|
3377
|
+
async resolveFilteredCardIds() {
|
|
3378
|
+
if (this.resolvedCardIds !== null) {
|
|
3379
|
+
return this.resolvedCardIds;
|
|
3380
|
+
}
|
|
3381
|
+
const includedCardIds = /* @__PURE__ */ new Set();
|
|
3382
|
+
if (this.filter.include.length > 0) {
|
|
3383
|
+
for (const tagName of this.filter.include) {
|
|
3384
|
+
try {
|
|
3385
|
+
const tagDoc = await getTag(this.courseId, tagName);
|
|
3386
|
+
tagDoc.taggedCards.forEach((cardId) => includedCardIds.add(cardId));
|
|
3387
|
+
} catch (error) {
|
|
3388
|
+
logger.warn(
|
|
3389
|
+
`[TagFilteredContentSource] Could not resolve tag "${tagName}" for inclusion:`,
|
|
3390
|
+
error
|
|
3391
|
+
);
|
|
3392
|
+
}
|
|
3393
|
+
}
|
|
3394
|
+
}
|
|
3395
|
+
if (includedCardIds.size === 0 && this.filter.include.length > 0) {
|
|
3396
|
+
logger.warn(
|
|
3397
|
+
`[TagFilteredContentSource] No cards found for include tags: ${this.filter.include.join(", ")}`
|
|
3398
|
+
);
|
|
3399
|
+
this.resolvedCardIds = /* @__PURE__ */ new Set();
|
|
3400
|
+
return this.resolvedCardIds;
|
|
3401
|
+
}
|
|
3402
|
+
const excludedCardIds = /* @__PURE__ */ new Set();
|
|
3403
|
+
if (this.filter.exclude.length > 0) {
|
|
3404
|
+
for (const tagName of this.filter.exclude) {
|
|
3405
|
+
try {
|
|
3406
|
+
const tagDoc = await getTag(this.courseId, tagName);
|
|
3407
|
+
tagDoc.taggedCards.forEach((cardId) => excludedCardIds.add(cardId));
|
|
3408
|
+
} catch (error) {
|
|
3409
|
+
logger.warn(
|
|
3410
|
+
`[TagFilteredContentSource] Could not resolve tag "${tagName}" for exclusion:`,
|
|
3411
|
+
error
|
|
3412
|
+
);
|
|
3413
|
+
}
|
|
3414
|
+
}
|
|
3415
|
+
}
|
|
3416
|
+
const finalCardIds = /* @__PURE__ */ new Set();
|
|
3417
|
+
for (const cardId of includedCardIds) {
|
|
3418
|
+
if (!excludedCardIds.has(cardId)) {
|
|
3419
|
+
finalCardIds.add(cardId);
|
|
3420
|
+
}
|
|
3421
|
+
}
|
|
3422
|
+
logger.info(
|
|
3423
|
+
`[TagFilteredContentSource] Resolved ${finalCardIds.size} cards (included: ${includedCardIds.size}, excluded: ${excludedCardIds.size})`
|
|
3424
|
+
);
|
|
3425
|
+
this.resolvedCardIds = finalCardIds;
|
|
3426
|
+
return finalCardIds;
|
|
3427
|
+
}
|
|
3428
|
+
/**
|
|
3429
|
+
* Gets new cards that match the tag filter and are not already active for the user.
|
|
3430
|
+
*/
|
|
3431
|
+
async getNewCards(limit) {
|
|
3432
|
+
if (!(0, import_common10.hasActiveFilter)(this.filter)) {
|
|
3433
|
+
logger.warn("[TagFilteredContentSource] getNewCards called with no active filter");
|
|
3434
|
+
return [];
|
|
3435
|
+
}
|
|
3436
|
+
const eligibleCardIds = await this.resolveFilteredCardIds();
|
|
3437
|
+
const activeCards = await this.user.getActiveCards();
|
|
3438
|
+
const activeCardIds = new Set(activeCards.map((c) => c.cardID));
|
|
3439
|
+
const newItems = [];
|
|
3440
|
+
for (const cardId of eligibleCardIds) {
|
|
3441
|
+
if (!activeCardIds.has(cardId)) {
|
|
3442
|
+
newItems.push({
|
|
3443
|
+
courseID: this.courseId,
|
|
3444
|
+
cardID: cardId,
|
|
3445
|
+
contentSourceType: "course",
|
|
3446
|
+
contentSourceID: this.courseId,
|
|
3447
|
+
status: "new"
|
|
3448
|
+
});
|
|
3449
|
+
}
|
|
3450
|
+
if (limit !== void 0 && newItems.length >= limit) {
|
|
3451
|
+
break;
|
|
3452
|
+
}
|
|
3453
|
+
}
|
|
3454
|
+
logger.info(`[TagFilteredContentSource] Found ${newItems.length} new cards matching filter`);
|
|
3455
|
+
return newItems;
|
|
3456
|
+
}
|
|
3457
|
+
/**
|
|
3458
|
+
* Gets pending reviews, filtered to only include cards that match the tag filter.
|
|
3459
|
+
*/
|
|
3460
|
+
async getPendingReviews() {
|
|
3461
|
+
if (!(0, import_common10.hasActiveFilter)(this.filter)) {
|
|
3462
|
+
logger.warn("[TagFilteredContentSource] getPendingReviews called with no active filter");
|
|
3463
|
+
return [];
|
|
3464
|
+
}
|
|
3465
|
+
const eligibleCardIds = await this.resolveFilteredCardIds();
|
|
3466
|
+
const allReviews = await this.user.getPendingReviews(this.courseId);
|
|
3467
|
+
const filteredReviews = allReviews.filter((review) => {
|
|
3468
|
+
return eligibleCardIds.has(review.cardId);
|
|
3469
|
+
});
|
|
3470
|
+
logger.info(
|
|
3471
|
+
`[TagFilteredContentSource] Found ${filteredReviews.length} pending reviews matching filter (of ${allReviews.length} total)`
|
|
3472
|
+
);
|
|
3473
|
+
return filteredReviews.map((r) => ({
|
|
3474
|
+
...r,
|
|
3475
|
+
courseID: r.courseId,
|
|
3476
|
+
cardID: r.cardId,
|
|
3477
|
+
contentSourceType: "course",
|
|
3478
|
+
contentSourceID: this.courseId,
|
|
3479
|
+
reviewID: r._id,
|
|
3480
|
+
status: "review"
|
|
3481
|
+
}));
|
|
3482
|
+
}
|
|
3483
|
+
/**
|
|
3484
|
+
* Get cards with suitability scores for presentation.
|
|
3485
|
+
*
|
|
3486
|
+
* This implementation wraps the legacy getNewCards/getPendingReviews methods,
|
|
3487
|
+
* assigning score=1.0 to all cards. TagFilteredContentSource does not currently
|
|
3488
|
+
* support pluggable navigation strategies - it returns flat-scored candidates.
|
|
3489
|
+
*
|
|
3490
|
+
* @param limit - Maximum number of cards to return
|
|
3491
|
+
* @returns Cards sorted by score descending (all scores = 1.0)
|
|
3492
|
+
*/
|
|
3493
|
+
async getWeightedCards(limit) {
|
|
3494
|
+
const [newCards, reviews] = await Promise.all([
|
|
3495
|
+
this.getNewCards(limit),
|
|
3496
|
+
this.getPendingReviews()
|
|
3497
|
+
]);
|
|
3498
|
+
const weighted = [
|
|
3499
|
+
...reviews.map((r) => ({
|
|
3500
|
+
cardId: r.cardID,
|
|
3501
|
+
courseId: r.courseID,
|
|
3502
|
+
score: 1,
|
|
3503
|
+
provenance: [
|
|
3504
|
+
{
|
|
3505
|
+
strategy: "tagFilter",
|
|
3506
|
+
strategyName: "Tag Filter",
|
|
3507
|
+
strategyId: "TAG_FILTER",
|
|
3508
|
+
action: "generated",
|
|
3509
|
+
score: 1,
|
|
3510
|
+
reason: `Tag-filtered review (tags: ${this.filter.include.join(", ")})`
|
|
3511
|
+
}
|
|
3512
|
+
]
|
|
3513
|
+
})),
|
|
3514
|
+
...newCards.map((c) => ({
|
|
3515
|
+
cardId: c.cardID,
|
|
3516
|
+
courseId: c.courseID,
|
|
3517
|
+
score: 1,
|
|
3518
|
+
provenance: [
|
|
3519
|
+
{
|
|
3520
|
+
strategy: "tagFilter",
|
|
3521
|
+
strategyName: "Tag Filter",
|
|
3522
|
+
strategyId: "TAG_FILTER",
|
|
3523
|
+
action: "generated",
|
|
3524
|
+
score: 1,
|
|
3525
|
+
reason: `Tag-filtered new card (tags: ${this.filter.include.join(", ")})`
|
|
3526
|
+
}
|
|
3527
|
+
]
|
|
3528
|
+
}))
|
|
3529
|
+
];
|
|
3530
|
+
return weighted.slice(0, limit);
|
|
3531
|
+
}
|
|
3532
|
+
/**
|
|
3533
|
+
* Clears the cached resolved card IDs.
|
|
3534
|
+
* Call this if the underlying tag data may have changed during a session.
|
|
3535
|
+
*/
|
|
3536
|
+
clearCache() {
|
|
3537
|
+
this.resolvedCardIds = null;
|
|
3538
|
+
}
|
|
3539
|
+
/**
|
|
3540
|
+
* Returns the course ID this source is filtering.
|
|
3541
|
+
*/
|
|
3542
|
+
getCourseId() {
|
|
3543
|
+
return this.courseId;
|
|
3544
|
+
}
|
|
3545
|
+
/**
|
|
3546
|
+
* Returns the active tag filter.
|
|
3547
|
+
*/
|
|
3548
|
+
getFilter() {
|
|
3549
|
+
return this.filter;
|
|
3550
|
+
}
|
|
3551
|
+
};
|
|
3552
|
+
}
|
|
3553
|
+
});
|
|
3554
|
+
|
|
1761
3555
|
// src/core/interfaces/contentSource.ts
|
|
1762
3556
|
function isReview(item) {
|
|
1763
3557
|
const ret = item.status === "review" || item.status === "failed-review" || "reviewID" in item;
|
|
@@ -1767,14 +3561,20 @@ async function getStudySource(source, user) {
|
|
|
1767
3561
|
if (source.type === "classroom") {
|
|
1768
3562
|
return await StudentClassroomDB.factory(source.id, user);
|
|
1769
3563
|
} else {
|
|
3564
|
+
if ((0, import_common11.hasActiveFilter)(source.tagFilter)) {
|
|
3565
|
+
return new TagFilteredContentSource(source.id, source.tagFilter, user);
|
|
3566
|
+
}
|
|
1770
3567
|
return getDataLayer().getCourseDB(source.id);
|
|
1771
3568
|
}
|
|
1772
3569
|
}
|
|
3570
|
+
var import_common11;
|
|
1773
3571
|
var init_contentSource = __esm({
|
|
1774
3572
|
"src/core/interfaces/contentSource.ts"() {
|
|
1775
3573
|
"use strict";
|
|
1776
3574
|
init_factory();
|
|
1777
3575
|
init_classroomDB2();
|
|
3576
|
+
import_common11 = require("@vue-skuilder/common");
|
|
3577
|
+
init_TagFilteredContentSource();
|
|
1778
3578
|
}
|
|
1779
3579
|
});
|
|
1780
3580
|
|
|
@@ -1831,17 +3631,17 @@ var init_util = __esm({
|
|
|
1831
3631
|
});
|
|
1832
3632
|
|
|
1833
3633
|
// src/core/bulkImport/cardProcessor.ts
|
|
1834
|
-
var
|
|
3634
|
+
var import_common12;
|
|
1835
3635
|
var init_cardProcessor = __esm({
|
|
1836
3636
|
"src/core/bulkImport/cardProcessor.ts"() {
|
|
1837
3637
|
"use strict";
|
|
1838
|
-
|
|
3638
|
+
import_common12 = require("@vue-skuilder/common");
|
|
1839
3639
|
init_logger();
|
|
1840
3640
|
}
|
|
1841
3641
|
});
|
|
1842
3642
|
|
|
1843
3643
|
// src/core/bulkImport/types.ts
|
|
1844
|
-
var
|
|
3644
|
+
var init_types3 = __esm({
|
|
1845
3645
|
"src/core/bulkImport/types.ts"() {
|
|
1846
3646
|
"use strict";
|
|
1847
3647
|
}
|
|
@@ -1852,7 +3652,7 @@ var init_bulkImport = __esm({
|
|
|
1852
3652
|
"src/core/bulkImport/index.ts"() {
|
|
1853
3653
|
"use strict";
|
|
1854
3654
|
init_cardProcessor();
|
|
1855
|
-
|
|
3655
|
+
init_types3();
|
|
1856
3656
|
}
|
|
1857
3657
|
});
|
|
1858
3658
|
|
|
@@ -1893,8 +3693,8 @@ var path, os;
|
|
|
1893
3693
|
var init_dataDirectory = __esm({
|
|
1894
3694
|
"src/util/dataDirectory.ts"() {
|
|
1895
3695
|
"use strict";
|
|
1896
|
-
path = __toESM(require("path"));
|
|
1897
|
-
os = __toESM(require("os"));
|
|
3696
|
+
path = __toESM(require("path"), 1);
|
|
3697
|
+
os = __toESM(require("os"), 1);
|
|
1898
3698
|
init_tuiLogger();
|
|
1899
3699
|
init_factory();
|
|
1900
3700
|
}
|
|
@@ -1928,7 +3728,7 @@ function getStartAndEndKeys2(key) {
|
|
|
1928
3728
|
};
|
|
1929
3729
|
}
|
|
1930
3730
|
function updateGuestAccountExpirationDate(guestDB) {
|
|
1931
|
-
const currentTime =
|
|
3731
|
+
const currentTime = import_moment3.default.utc();
|
|
1932
3732
|
const expirationDate = currentTime.add(2, "months").toISOString();
|
|
1933
3733
|
const expiryDocID2 = "GuestAccountExpirationDate";
|
|
1934
3734
|
void guestDB.get(expiryDocID2).then((doc) => {
|
|
@@ -1953,7 +3753,7 @@ function getLocalUserDB(username) {
|
|
|
1953
3753
|
}
|
|
1954
3754
|
}
|
|
1955
3755
|
function scheduleCardReviewLocal(userDB, review) {
|
|
1956
|
-
const now =
|
|
3756
|
+
const now = import_moment3.default.utc();
|
|
1957
3757
|
logger.info(`Scheduling for review in: ${review.time.diff(now, "h") / 24} days`);
|
|
1958
3758
|
void userDB.put({
|
|
1959
3759
|
_id: DocTypePrefixes["SCHEDULED_CARD" /* SCHEDULED_CARD */] + review.time.format(REVIEW_TIME_FORMAT2),
|
|
@@ -1976,11 +3776,11 @@ async function removeScheduledCardReviewLocal(userDB, reviewDocID) {
|
|
|
1976
3776
|
${JSON.stringify(err)}`);
|
|
1977
3777
|
});
|
|
1978
3778
|
}
|
|
1979
|
-
var
|
|
3779
|
+
var import_moment3, REVIEW_TIME_FORMAT2, log2;
|
|
1980
3780
|
var init_userDBHelpers = __esm({
|
|
1981
3781
|
"src/impl/common/userDBHelpers.ts"() {
|
|
1982
3782
|
"use strict";
|
|
1983
|
-
|
|
3783
|
+
import_moment3 = __toESM(require("moment"), 1);
|
|
1984
3784
|
init_core();
|
|
1985
3785
|
init_logger();
|
|
1986
3786
|
init_pouchdb_setup();
|
|
@@ -1993,11 +3793,11 @@ var init_userDBHelpers = __esm({
|
|
|
1993
3793
|
});
|
|
1994
3794
|
|
|
1995
3795
|
// src/impl/couch/user-course-relDB.ts
|
|
1996
|
-
var
|
|
3796
|
+
var import_moment4, UsrCrsData;
|
|
1997
3797
|
var init_user_course_relDB = __esm({
|
|
1998
3798
|
"src/impl/couch/user-course-relDB.ts"() {
|
|
1999
3799
|
"use strict";
|
|
2000
|
-
|
|
3800
|
+
import_moment4 = __toESM(require("moment"), 1);
|
|
2001
3801
|
init_logger();
|
|
2002
3802
|
UsrCrsData = class {
|
|
2003
3803
|
user;
|
|
@@ -2007,11 +3807,11 @@ var init_user_course_relDB = __esm({
|
|
|
2007
3807
|
this._courseId = courseId;
|
|
2008
3808
|
}
|
|
2009
3809
|
async getReviewsForcast(daysCount) {
|
|
2010
|
-
const time =
|
|
3810
|
+
const time = import_moment4.default.utc().add(daysCount, "days");
|
|
2011
3811
|
return this.getReviewstoDate(time);
|
|
2012
3812
|
}
|
|
2013
3813
|
async getPendingReviews() {
|
|
2014
|
-
const now =
|
|
3814
|
+
const now = import_moment4.default.utc();
|
|
2015
3815
|
return this.getReviewstoDate(now);
|
|
2016
3816
|
}
|
|
2017
3817
|
async getScheduledReviewCount() {
|
|
@@ -2038,7 +3838,7 @@ var init_user_course_relDB = __esm({
|
|
|
2038
3838
|
`Fetching ${this.user.getUsername()}'s scheduled reviews for course ${this._courseId}.`
|
|
2039
3839
|
);
|
|
2040
3840
|
return allReviews.filter((review) => {
|
|
2041
|
-
const reviewTime =
|
|
3841
|
+
const reviewTime = import_moment4.default.utc(review.reviewTime);
|
|
2042
3842
|
return targetDate.isAfter(reviewTime);
|
|
2043
3843
|
});
|
|
2044
3844
|
}
|
|
@@ -2218,14 +4018,14 @@ async function dropUserFromClassroom(user, classID) {
|
|
|
2218
4018
|
async function getUserClassrooms(user) {
|
|
2219
4019
|
return getOrCreateClassroomRegistrationsDoc(user);
|
|
2220
4020
|
}
|
|
2221
|
-
var
|
|
4021
|
+
var import_common13, import_moment5, log3, BaseUser, userCoursesDoc, userClassroomsDoc;
|
|
2222
4022
|
var init_BaseUserDB = __esm({
|
|
2223
4023
|
"src/impl/common/BaseUserDB.ts"() {
|
|
2224
4024
|
"use strict";
|
|
2225
4025
|
init_core();
|
|
2226
4026
|
init_util();
|
|
2227
|
-
|
|
2228
|
-
|
|
4027
|
+
import_common13 = require("@vue-skuilder/common");
|
|
4028
|
+
import_moment5 = __toESM(require("moment"), 1);
|
|
2229
4029
|
init_types_legacy();
|
|
2230
4030
|
init_logger();
|
|
2231
4031
|
init_userDBHelpers();
|
|
@@ -2274,7 +4074,7 @@ Currently logged-in as ${this._username}.`
|
|
|
2274
4074
|
);
|
|
2275
4075
|
}
|
|
2276
4076
|
const result = await this.syncStrategy.createAccount(username, password);
|
|
2277
|
-
if (result.status ===
|
|
4077
|
+
if (result.status === import_common13.Status.ok) {
|
|
2278
4078
|
log3(`Account created successfully, updating username to ${username}`);
|
|
2279
4079
|
this._username = username;
|
|
2280
4080
|
try {
|
|
@@ -2316,7 +4116,7 @@ Currently logged-in as ${this._username}.`
|
|
|
2316
4116
|
async resetUserData() {
|
|
2317
4117
|
if (this.syncStrategy.canAuthenticate()) {
|
|
2318
4118
|
return {
|
|
2319
|
-
status:
|
|
4119
|
+
status: import_common13.Status.error,
|
|
2320
4120
|
error: "Reset user data is only available for local-only mode. Use logout instead for remote sync."
|
|
2321
4121
|
};
|
|
2322
4122
|
}
|
|
@@ -2335,11 +4135,11 @@ Currently logged-in as ${this._username}.`
|
|
|
2335
4135
|
await localDB.bulkDocs(docsToDelete);
|
|
2336
4136
|
}
|
|
2337
4137
|
await this.init();
|
|
2338
|
-
return { status:
|
|
4138
|
+
return { status: import_common13.Status.ok };
|
|
2339
4139
|
} catch (error) {
|
|
2340
4140
|
logger.error("Failed to reset user data:", error);
|
|
2341
4141
|
return {
|
|
2342
|
-
status:
|
|
4142
|
+
status: import_common13.Status.error,
|
|
2343
4143
|
error: error instanceof Error ? error.message : "Unknown error during reset"
|
|
2344
4144
|
};
|
|
2345
4145
|
}
|
|
@@ -2486,7 +4286,7 @@ Currently logged-in as ${this._username}.`
|
|
|
2486
4286
|
);
|
|
2487
4287
|
return reviews.rows.filter((r) => {
|
|
2488
4288
|
if (r.id.startsWith(DocTypePrefixes["SCHEDULED_CARD" /* SCHEDULED_CARD */])) {
|
|
2489
|
-
const date =
|
|
4289
|
+
const date = import_moment5.default.utc(
|
|
2490
4290
|
r.id.substr(DocTypePrefixes["SCHEDULED_CARD" /* SCHEDULED_CARD */].length),
|
|
2491
4291
|
REVIEW_TIME_FORMAT2
|
|
2492
4292
|
);
|
|
@@ -2499,11 +4299,11 @@ Currently logged-in as ${this._username}.`
|
|
|
2499
4299
|
}).map((r) => r.doc);
|
|
2500
4300
|
}
|
|
2501
4301
|
async getReviewsForcast(daysCount) {
|
|
2502
|
-
const time =
|
|
4302
|
+
const time = import_moment5.default.utc().add(daysCount, "days");
|
|
2503
4303
|
return this.getReviewstoDate(time);
|
|
2504
4304
|
}
|
|
2505
4305
|
async getPendingReviews(course_id) {
|
|
2506
|
-
const now =
|
|
4306
|
+
const now = import_moment5.default.utc();
|
|
2507
4307
|
return this.getReviewstoDate(now, course_id);
|
|
2508
4308
|
}
|
|
2509
4309
|
async getScheduledReviewCount(course_id) {
|
|
@@ -2790,7 +4590,7 @@ Currently logged-in as ${this._username}.`
|
|
|
2790
4590
|
*/
|
|
2791
4591
|
async putCardRecord(record) {
|
|
2792
4592
|
const cardHistoryID = getCardHistoryID(record.courseID, record.cardID);
|
|
2793
|
-
record.timeStamp =
|
|
4593
|
+
record.timeStamp = import_moment5.default.utc(record.timeStamp).toString();
|
|
2794
4594
|
try {
|
|
2795
4595
|
const cardHistory = await this.update(
|
|
2796
4596
|
cardHistoryID,
|
|
@@ -2806,7 +4606,7 @@ Currently logged-in as ${this._username}.`
|
|
|
2806
4606
|
const ret = {
|
|
2807
4607
|
...record2
|
|
2808
4608
|
};
|
|
2809
|
-
ret.timeStamp =
|
|
4609
|
+
ret.timeStamp = import_moment5.default.utc(record2.timeStamp);
|
|
2810
4610
|
return ret;
|
|
2811
4611
|
});
|
|
2812
4612
|
return cardHistory;
|
|
@@ -3180,19 +4980,19 @@ var init_auth = __esm({
|
|
|
3180
4980
|
"use strict";
|
|
3181
4981
|
init_factory();
|
|
3182
4982
|
init_logger();
|
|
3183
|
-
import_cross_fetch = __toESM(require("cross-fetch"));
|
|
4983
|
+
import_cross_fetch = __toESM(require("cross-fetch"), 1);
|
|
3184
4984
|
}
|
|
3185
4985
|
});
|
|
3186
4986
|
|
|
3187
4987
|
// src/impl/couch/CouchDBSyncStrategy.ts
|
|
3188
|
-
var
|
|
4988
|
+
var import_common15, log4, CouchDBSyncStrategy;
|
|
3189
4989
|
var init_CouchDBSyncStrategy = __esm({
|
|
3190
4990
|
"src/impl/couch/CouchDBSyncStrategy.ts"() {
|
|
3191
4991
|
"use strict";
|
|
3192
4992
|
init_factory();
|
|
3193
4993
|
init_types_legacy();
|
|
3194
4994
|
init_logger();
|
|
3195
|
-
|
|
4995
|
+
import_common15 = require("@vue-skuilder/common");
|
|
3196
4996
|
init_common();
|
|
3197
4997
|
init_pouchdb_setup();
|
|
3198
4998
|
init_couch();
|
|
@@ -3263,32 +5063,32 @@ var init_CouchDBSyncStrategy = __esm({
|
|
|
3263
5063
|
}
|
|
3264
5064
|
}
|
|
3265
5065
|
return {
|
|
3266
|
-
status:
|
|
5066
|
+
status: import_common15.Status.ok,
|
|
3267
5067
|
error: void 0
|
|
3268
5068
|
};
|
|
3269
5069
|
} else {
|
|
3270
5070
|
return {
|
|
3271
|
-
status:
|
|
5071
|
+
status: import_common15.Status.error,
|
|
3272
5072
|
error: "Failed to log in after account creation"
|
|
3273
5073
|
};
|
|
3274
5074
|
}
|
|
3275
5075
|
} else {
|
|
3276
5076
|
logger.warn(`Signup not OK: ${JSON.stringify(signupRequest)}`);
|
|
3277
5077
|
return {
|
|
3278
|
-
status:
|
|
5078
|
+
status: import_common15.Status.error,
|
|
3279
5079
|
error: "Account creation failed"
|
|
3280
5080
|
};
|
|
3281
5081
|
}
|
|
3282
5082
|
} catch (e) {
|
|
3283
5083
|
if (e.reason === "Document update conflict.") {
|
|
3284
5084
|
return {
|
|
3285
|
-
status:
|
|
5085
|
+
status: import_common15.Status.error,
|
|
3286
5086
|
error: "This username is taken!"
|
|
3287
5087
|
};
|
|
3288
5088
|
}
|
|
3289
5089
|
logger.error(`Error on signup: ${JSON.stringify(e)}`);
|
|
3290
5090
|
return {
|
|
3291
|
-
status:
|
|
5091
|
+
status: import_common15.Status.error,
|
|
3292
5092
|
error: e.message || "Unknown error during account creation"
|
|
3293
5093
|
};
|
|
3294
5094
|
}
|
|
@@ -3527,7 +5327,7 @@ async function usernameIsAvailable(username) {
|
|
|
3527
5327
|
}
|
|
3528
5328
|
}
|
|
3529
5329
|
function updateGuestAccountExpirationDate2(guestDB) {
|
|
3530
|
-
const currentTime =
|
|
5330
|
+
const currentTime = import_moment6.default.utc();
|
|
3531
5331
|
const expirationDate = currentTime.add(2, "months").toISOString();
|
|
3532
5332
|
void guestDB.get(expiryDocID).then((doc) => {
|
|
3533
5333
|
return guestDB.put({
|
|
@@ -3590,7 +5390,7 @@ function getCouchUserDB(username) {
|
|
|
3590
5390
|
return ret;
|
|
3591
5391
|
}
|
|
3592
5392
|
function scheduleCardReview(review) {
|
|
3593
|
-
const now =
|
|
5393
|
+
const now = import_moment6.default.utc();
|
|
3594
5394
|
logger.info(`Scheduling for review in: ${review.time.diff(now, "h") / 24} days`);
|
|
3595
5395
|
void getCouchUserDB(review.user).put({
|
|
3596
5396
|
_id: DocTypePrefixes["SCHEDULED_CARD" /* SCHEDULED_CARD */] + review.time.format(REVIEW_TIME_FORMAT),
|
|
@@ -3619,16 +5419,16 @@ function getStartAndEndKeys(key) {
|
|
|
3619
5419
|
endkey: key + "\uFFF0"
|
|
3620
5420
|
};
|
|
3621
5421
|
}
|
|
3622
|
-
var import_cross_fetch2,
|
|
5422
|
+
var import_cross_fetch2, import_moment6, import_process, isBrowser, expiryDocID, GUEST_LOCAL_DB, localUserDB, pouchDBincludeCredentialsConfig, REVIEW_TIME_FORMAT;
|
|
3623
5423
|
var init_couch = __esm({
|
|
3624
5424
|
"src/impl/couch/index.ts"() {
|
|
3625
5425
|
init_factory();
|
|
3626
5426
|
init_types_legacy();
|
|
3627
|
-
import_cross_fetch2 = __toESM(require("cross-fetch"));
|
|
3628
|
-
|
|
5427
|
+
import_cross_fetch2 = __toESM(require("cross-fetch"), 1);
|
|
5428
|
+
import_moment6 = __toESM(require("moment"), 1);
|
|
3629
5429
|
init_logger();
|
|
3630
5430
|
init_pouchdb_setup();
|
|
3631
|
-
import_process = __toESM(require("process"));
|
|
5431
|
+
import_process = __toESM(require("process"), 1);
|
|
3632
5432
|
init_contentSource();
|
|
3633
5433
|
init_adminDB2();
|
|
3634
5434
|
init_classroomDB2();
|