@vue-skuilder/db 0.2.32 → 0.2.34

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/index.mjs CHANGED
@@ -5517,7 +5517,7 @@ var FRAMEWORK_VERSION, hostAppVersion, DEFAULT_STRATEGY_HASH;
5517
5517
  var init_versionStamps = __esm({
5518
5518
  "src/core/versionStamps.ts"() {
5519
5519
  "use strict";
5520
- FRAMEWORK_VERSION = true ? "0.2.32" : "dev";
5520
+ FRAMEWORK_VERSION = true ? "0.2.34" : "dev";
5521
5521
  DEFAULT_STRATEGY_HASH = "default";
5522
5522
  }
5523
5523
  });
@@ -8105,21 +8105,26 @@ function newQuestionInterval(user, cardHistory) {
8105
8105
  const interval = lastInterval * (0.75 + skill);
8106
8106
  cardHistory.lapses = getLapses(cardHistory.records);
8107
8107
  cardHistory.streak = getStreak(cardHistory.records);
8108
+ let ret = interval;
8108
8109
  if (cardHistory.lapses && cardHistory.streak && cardHistory.bestInterval && (cardHistory.lapses >= 0 || cardHistory.streak >= 0)) {
8109
- const ret = (cardHistory.lapses * interval + cardHistory.streak * cardHistory.bestInterval) / (cardHistory.lapses + cardHistory.streak);
8110
+ ret = (cardHistory.lapses * interval + cardHistory.streak * cardHistory.bestInterval) / (cardHistory.lapses + cardHistory.streak);
8110
8111
  logger.debug(`Weighted average interval calculation:
8111
8112
  (${cardHistory.lapses} * ${interval} + ${cardHistory.streak} * ${cardHistory.bestInterval}) / (${cardHistory.lapses} + ${cardHistory.streak}) = ${ret}`);
8112
- return ret;
8113
- } else {
8114
- return interval;
8115
8113
  }
8114
+ if (currentAttempt.fluent === false) {
8115
+ logger.debug(
8116
+ `Correct but not fluent: capping interval ${ret}s at ${SLOW_CORRECT_MAX_INTERVAL}s`
8117
+ );
8118
+ return Math.min(ret, SLOW_CORRECT_MAX_INTERVAL);
8119
+ }
8120
+ return ret;
8116
8121
  } else {
8117
8122
  return 0;
8118
8123
  }
8119
8124
  }
8120
8125
  function lastSuccessfulInterval(cardHistory) {
8121
8126
  for (let i = cardHistory.length - 1; i >= 1; i--) {
8122
- if (cardHistory[i].priorAttemps === 0 && cardHistory[i].isCorrect) {
8127
+ if (cardHistory[i].priorAttemps === 0 && cardHistory[i].isCorrect && cardHistory[i].fluent !== false) {
8123
8128
  const lastInterval = secondsBetween(cardHistory[i - 1].timeStamp, cardHistory[i].timeStamp);
8124
8129
  const ret = Math.max(lastInterval, 20 * 60 * 60);
8125
8130
  logger.debug(`Last interval w/ this card was: ${lastInterval}s, returning ${ret}s`);
@@ -8150,13 +8155,14 @@ function secondsBetween(start, end) {
8150
8155
  const ret = duration(end.diff(start)).asSeconds();
8151
8156
  return ret;
8152
8157
  }
8153
- var duration;
8158
+ var duration, SLOW_CORRECT_MAX_INTERVAL;
8154
8159
  var init_SpacedRepetition = __esm({
8155
8160
  "src/study/SpacedRepetition.ts"() {
8156
8161
  "use strict";
8157
8162
  init_util();
8158
8163
  init_logger();
8159
8164
  duration = moment4.duration;
8165
+ SLOW_CORRECT_MAX_INTERVAL = 20 * 60 * 60;
8160
8166
  }
8161
8167
  });
8162
8168
 
@@ -8274,10 +8280,30 @@ var init_EloService = __esm({
8274
8280
  EloService = class {
8275
8281
  dataLayer;
8276
8282
  user;
8283
+ /** Per course ID: its compiled `CourseConfig.qaUsernamePattern`, or null. */
8284
+ qaPatterns = /* @__PURE__ */ new Map();
8277
8285
  constructor(dataLayer, user) {
8278
8286
  this.dataLayer = dataLayer;
8279
8287
  this.user = user;
8280
8288
  }
8289
+ /**
8290
+ * Whether the current user is one of the course's QA accounts
8291
+ * (`CourseConfig.qaUsernamePattern`), whose responses must not move card
8292
+ * ELO. The pattern is read once per course. If the config is unreadable or
8293
+ * the pattern doesn't compile, nobody is a QA account.
8294
+ */
8295
+ async isQaUser(courseDB) {
8296
+ const courseId = courseDB.getCourseID();
8297
+ let pattern = this.qaPatterns.get(courseId);
8298
+ if (!pattern) {
8299
+ pattern = courseDB.getCourseConfig().then((cfg) => cfg.qaUsernamePattern ? new RegExp(cfg.qaUsernamePattern, "i") : null).catch((e) => {
8300
+ logger.warn(`[EloService] No QA username pattern for ${courseId}: ${e}`);
8301
+ return null;
8302
+ });
8303
+ this.qaPatterns.set(courseId, pattern);
8304
+ }
8305
+ return (await pattern)?.test(this.user.getUsername()) ?? false;
8306
+ }
8281
8307
  /**
8282
8308
  * Updates both user and card ELO ratings based on user performance.
8283
8309
  * @param userScore Score between 0-1 representing user performance
@@ -8304,6 +8330,7 @@ var init_EloService = __esm({
8304
8330
  const userElo = toCourseElo7(courseReg.elo);
8305
8331
  const cardElo = (await courseDB.getCardEloData([currentCard.card.card_id]))[0];
8306
8332
  if (cardElo && userElo) {
8333
+ const writeCard = !await this.isQaUser(courseDB);
8307
8334
  const beforeUserGlobal = userElo.global.score;
8308
8335
  const beforeCardGlobal = cardElo.global.score;
8309
8336
  const cardTagKeys = Object.keys(cardElo.tags);
@@ -8327,12 +8354,18 @@ var init_EloService = __esm({
8327
8354
  at: (/* @__PURE__ */ new Date()).toISOString(),
8328
8355
  userScore,
8329
8356
  global: { before: beforeUserGlobal, after: eloUpdate.userElo.global.score },
8330
- card: { before: beforeCardGlobal, after: eloUpdate.cardElo.global.score },
8357
+ card: {
8358
+ before: beforeCardGlobal,
8359
+ after: writeCard ? eloUpdate.cardElo.global.score : beforeCardGlobal
8360
+ },
8331
8361
  ...cardTagKeys.length ? { tags } : {}
8332
8362
  };
8363
+ if (!writeCard) {
8364
+ logger.info(`[EloService] QA account: card ELO for ${card_id} not written`);
8365
+ }
8333
8366
  const results = await Promise.allSettled([
8334
8367
  this.user.updateUserElo(course_id, eloUpdate.userElo),
8335
- courseDB.updateCardElo(card_id, eloUpdate.cardElo)
8368
+ writeCard ? courseDB.updateCardElo(card_id, eloUpdate.cardElo) : Promise.resolve(null)
8336
8369
  ]);
8337
8370
  const userEloStatus = results[0].status === "fulfilled";
8338
8371
  const cardEloStatus = results[1].status === "fulfilled";
@@ -8399,6 +8432,7 @@ var init_EloService = __esm({
8399
8432
  }
8400
8433
  }
8401
8434
  if (cardElo && userElo) {
8435
+ const writeCard = !await this.isQaUser(courseDB);
8402
8436
  const beforeUserGlobal = userElo.global.score;
8403
8437
  const beforeCardGlobal = cardElo.global.score;
8404
8438
  const touchedTags = Object.keys(enriched).filter((key) => key !== "_global");
@@ -8430,12 +8464,18 @@ var init_EloService = __esm({
8430
8464
  at,
8431
8465
  userScore: globalScore,
8432
8466
  global: { before: beforeUserGlobal, after: eloUpdate.userElo.global.score },
8433
- card: { before: beforeCardGlobal, after: eloUpdate.cardElo.global.score },
8467
+ card: {
8468
+ before: beforeCardGlobal,
8469
+ after: writeCard ? eloUpdate.cardElo.global.score : beforeCardGlobal
8470
+ },
8434
8471
  ...touchedTags.length ? { tags } : {}
8435
8472
  };
8473
+ if (!writeCard) {
8474
+ logger.info(`[EloService] QA account: card ELO for ${card_id} not written`);
8475
+ }
8436
8476
  const results = await Promise.allSettled([
8437
8477
  this.user.updateUserElo(course_id, eloUpdate.userElo),
8438
- courseDB.updateCardElo(card_id, eloUpdate.cardElo)
8478
+ writeCard ? courseDB.updateCardElo(card_id, eloUpdate.cardElo) : Promise.resolve(null)
8439
8479
  ]);
8440
8480
  const userEloStatus = results[0].status === "fulfilled";
8441
8481
  const cardEloStatus = results[1].status === "fulfilled";
@@ -16455,7 +16495,11 @@ init_courseLookupDB();
16455
16495
 
16456
16496
  // src/courseConfigRegistration.ts
16457
16497
  init_logger();
16458
- import { NameSpacer as NameSpacer2, toZodJSON } from "@vue-skuilder/common";
16498
+ import {
16499
+ NameSpacer as NameSpacer2,
16500
+ toCourseElo as toCourseElo9,
16501
+ toZodJSON
16502
+ } from "@vue-skuilder/common";
16459
16503
  function isDataShapeRegistered(dataShape, courseConfig) {
16460
16504
  const namespacedName = NameSpacer2.getDataShapeString({
16461
16505
  dataShape: dataShape.name,
@@ -16656,16 +16700,20 @@ async function registerSeedData(question, courseDB, username) {
16656
16700
  if (question.questionClass.seedData && Array.isArray(question.questionClass.seedData)) {
16657
16701
  logger.info(`Registering seed data for question: ${question.name}`);
16658
16702
  try {
16659
- const seedDataPromises = question.questionClass.seedData.filter(() => question.dataShapes.length > 0).map(
16660
- (seedDataItem) => courseDB.addNote(
16661
- question.course,
16662
- question.dataShapes[0],
16663
- seedDataItem,
16664
- username,
16665
- []
16666
- )
16667
- );
16668
- await Promise.all(seedDataPromises);
16703
+ if (question.dataShapes.length > 0) {
16704
+ for (const seedDataItem of question.questionClass.seedData) {
16705
+ const meta = question.questionClass.seedMeta?.(seedDataItem) ?? {};
16706
+ await courseDB.addNote(
16707
+ question.course,
16708
+ question.dataShapes[0],
16709
+ seedDataItem,
16710
+ username,
16711
+ meta.tags ?? [],
16712
+ void 0,
16713
+ meta.elo !== void 0 ? toCourseElo9(meta.elo) : void 0
16714
+ );
16715
+ }
16716
+ }
16669
16717
  logger.info(`Seed data registered for question: ${question.name}`);
16670
16718
  } catch (error) {
16671
16719
  logger.warn(