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B,SAAS,QAAQ,SAAW,GAAS,IAAI,SAAQ,CAAC,EAAS,KACzD,IAAK,EAAM,OAAQ,OAAO,EAAQ,GASlC,MAAM,EAAQ,SAAS,QAAQ,SAAW,OAE1C,IAAI,EAAO,CAAC,EAAK,KACf,IAAI,GAAY,IAAI,KAAS,EAAI,MAAQ,IACrC,EAAW,KAAK,IAAI,KAAK,GAAK,EAAQ,GAG1C,OADA,EAAW,KAAK,IAAI,EAAU,SAAS,QAAQ,SACxC,EAAM,CAAQ,EAGvB,IAAI,EAAO,EAAM,QAAO,GAAgB,SAAX,EAAE,OAAiB,OAAO,EAAM,GACzD,EAAM,EAAM,QAAO,GAAgB,QAAX,EAAE,OAAgB,OAAO,EAAM,GACvD,EAAQ,GAAM,IAAO,EAAO,IAAQ,EAAO,GAC3C,SAAS,QAAQ,OACnB,QAAQ,IAAI,WAAY,EAAO,EAAM,GAEvC,EAAQ,MAAM,GAAO,IAWvB,SAAS,QAAQ,OAAS,IAAM,IAAI,SAAQ,CAAC,EAAS,KACpD,IAAI,EAAS,SAAS,QAAQ,UAE9B,EAAQ,GAAM,EAAS,EAAI,EAAS,KAAK,SAAS,IAK9B,oBAAX,SACT,OAAO,QAAU","file":"/npm/recordar@1.3.0/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/recordar@1.3.0/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","// Recordar - Gives a 0.0-1.0 range, the higher the more you remember it\nconst bound = num => Math.min(Math.max(0, num), 1);\n\nconst defaults = {\n\n  debug: false,\n\n  // The half-life of each answer. Set higher for easier sets or fast learners\n  halflife: 7 * 24 * 3600,\n\n  // The minimum that each try will bias the solution (min, 1)\n  minimum: 0.3,\n\n  // The amount to ranzomize: 0.5 +- randomize\n  randomize: 0.1,\n\n  factor_forget: true,\n  factor_accuracy: true,\n  factor_random: true\n};\n\n// The main function. Accepts options and then a list of the actual tries\n// recordar({})([{}, {}, {}]).then(score => { ... });\nconst recordar = (tries = [], options = {}) => new Promise((resolve, reject) => {\n  if (!(tries instanceof Array)) {\n    throw new Error('The parameter should be an array of tries');\n  }\n  if(tries.length === 0) {\n    return resolve(0.5);\n  }\n\n  recordar.options = Object.assign({}, recordar.options, options);\n\n  Object.keys(recordar.factors).reduce((all, key) => {\n    if (!recordar.options['factor_' + key]) return all;\n    return all.then(glo => recordar.factors[key](tries).then(local => {\n      if (recordar.options.debug) {\n        console.log(\"Word:\", options.word, \"For:\", key, local);\n      }\n      return glo * local * 2;\n    }));\n  }, Promise.resolve(0.5)).then(sol => resolve(bound(sol)));\n});\n\n\nrecordar.options = defaults;\n\n\n// Every one of the factors range from 0 to 1, averagin around 0.5\n// Since they have to be multiplied together, each is duplicated before\nrecordar.factors = {};\n\n// Time factor; the longer the time, the more you don't know\nrecordar.factors.forget = tries => new Promise((resolve, reject) => {\n  if (!tries.length) return resolve(0.5);\n\n  let sorted = tries.map(w => w.time).map(time => new Date(time)).sort();\n  let last = sorted.pop();\n  if (!last) return resolve(0.5);\n  // Wolfram Alpha: 1 - ln(x) / (2 * ln(3600)) from 0 to 10000\n  // 0.5 ~= 1 - ln(x) / 2 * ln(const)\n  let selffactor = 2 * Math.log(recordar.options.halflife);\n  let solution = 1 - Math.log((new Date() - last) / 1000) / selffactor;\n  if (recordar.options.debug) {\n    console.log('Forget:', solution, sorted, last);\n  }\n  resolve(bound(solution));\n});\n\n// Accuracy factor; the more errors you make, the less that you know\n// Old errors/rights account less than newer ones\nrecordar.factors.accuracy = tries => new Promise((resolve, reject) => {\n  if (!tries.length) return resolve(1);\n\n  // Forget 50% in e ^ (-A * t)\n  //   f(t = halflife) = 0.5\n  //   A == coeff == ?\n  //   0.5 = e ^ (-coeff * halflife)\n  //   ln(0.5) = -coeff * halflife\n  //   0.69315 = coeff * halflife\n  //   coeff = 0.69315 / halflife\n  const coeff = recordar.options.halflife / 0.69315;\n\n  let size = (all, one) => {\n    let timediff = (new Date() - one.time) / 1000;\n    let remember = Math.pow(Math.E, (-coeff * timediff));\n    // Force each try to always influence even if it's just a bit\n    remember = Math.max(remember, recordar.options.minimum);\n    return all + remember;\n  };\n\n  var good = tries.filter(n => n.type === 'good').reduce(size, 1);\n  var bad = tries.filter(n => n.type === 'bad').reduce(size, 1);\n  var total = 0.5 + 0.5 * (good - bad) / (good + bad);\n  if (recordar.options.debug) {\n    console.log(\"Accuracy\", total, good, bad);\n  }\n  resolve(bound(total));\n});\n\n// Position of the index vs total size\n// TODO: dynamic range depending on the dataset size\n// TODO: push this up\n// recordar.factors.index = function(word, i, all) {\n//   return 1.2 - 0.4 * (word.index / all.length);\n// };\n\n// Make it slightly random\nrecordar.factors.random = () => new Promise((resolve, reject) => {\n  let factor = recordar.options.randomize;\n  // From (0.5 - factor) +- factor\n  resolve(0.5 - factor + 2 * factor * Math.random());\n});\n\n\n\nif (typeof module !== 'undefined') {\n  module.exports = recordar;\n}\n"]}