diff --git a/package-lock.json b/package-lock.json index 2100f05..e11a89c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10297,7 +10297,6 @@ }, "node_modules/npm/node_modules/lodash._baseindexof": { "version": "3.1.0", - "extraneous": true, "inBundle": true, "license": "MIT" }, @@ -10322,19 +10321,16 @@ }, "node_modules/npm/node_modules/lodash._bindcallback": { "version": "3.0.1", - "extraneous": true, "inBundle": true, "license": "MIT" }, "node_modules/npm/node_modules/lodash._cacheindexof": { "version": "3.0.2", - "extraneous": true, "inBundle": true, "license": "MIT" }, "node_modules/npm/node_modules/lodash._createcache": { "version": "3.1.2", - "extraneous": true, "inBundle": true, "license": "MIT", "dependencies": { @@ -10343,7 +10339,6 @@ }, "node_modules/npm/node_modules/lodash._getnative": { "version": "3.9.1", - "extraneous": true, "inBundle": true, "license": "MIT" }, @@ -10354,7 +10349,6 @@ }, "node_modules/npm/node_modules/lodash.restparam": { "version": "3.6.1", - "extraneous": true, "inBundle": true, "license": "MIT" }, @@ -24670,8 +24664,7 @@ }, "lodash._baseindexof": { "version": "3.1.0", - "bundled": true, - "extraneous": true + "bundled": true }, "lodash._baseuniq": { "version": "4.6.0", @@ -24693,26 +24686,22 @@ }, "lodash._bindcallback": { "version": "3.0.1", - "bundled": true, - "extraneous": true + "bundled": true }, "lodash._cacheindexof": { "version": "3.0.2", - "bundled": true, - "extraneous": true + "bundled": true }, "lodash._createcache": { "version": "3.1.2", "bundled": true, - "extraneous": true, "requires": { "lodash._getnative": "^3.0.0" } }, "lodash._getnative": { "version": "3.9.1", - "bundled": true, - "extraneous": true + "bundled": true }, "lodash.clonedeep": { "version": "4.5.0", @@ -24720,8 +24709,7 @@ }, "lodash.restparam": { "version": "3.6.1", - "bundled": true, - "extraneous": true + "bundled": true }, "lodash.union": { "version": "4.6.0", diff --git a/src/__tests__/index.test.ts b/src/__tests__/index.test.ts index e84c02e..1194090 100644 --- a/src/__tests__/index.test.ts +++ b/src/__tests__/index.test.ts @@ -3,7 +3,7 @@ import { Stimulus } from '../type'; import seedrandom from 'seedrandom'; describe('Cat', () => { - let cat1: Cat, cat2: Cat, cat3: Cat, cat4: Cat, cat5: Cat, cat6: Cat, cat7: Cat; + let cat1: Cat, cat2: Cat, cat3: Cat, cat4: Cat, cat5: Cat, cat6: Cat, cat7: Cat, cat8: Cat; let rng = seedrandom(); beforeEach(() => { cat1 = new Cat(); @@ -52,6 +52,8 @@ describe('Cat', () => { ], [0, 0], ); + + cat8 = new Cat({ nStartItems: 0, itemSelect: 'FIXED' }); }); const s1: Stimulus = { difficulty: 0.5, c: 0.5, word: 'looking' }; @@ -116,6 +118,13 @@ describe('Cat', () => { expect(received).toEqual(expected); }); + it('correctly suggests the next item (fixed method)', () => { + expect(cat8.itemSelect).toBe('fixed'); + const expected = { nextStimulus: s1, remainingStimuli: [s2, s3, s4, s5] }; + const received = cat8.findNextItem(stimuli); + expect(received).toEqual(expected); + }); + it('correctly suggests the next item (random method)', () => { let received; const stimuliSorted = stimuli.sort((a: Stimulus, b: Stimulus) => a.difficulty - b.difficulty); diff --git a/src/index.ts b/src/index.ts index 6291267..83424c1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -107,7 +107,7 @@ export class Cat { private static validateItemSelect(itemSelect: string) { const lowerItemSelect = itemSelect.toLowerCase(); - const validItemSelect: Array = ['mfi', 'random', 'closest']; + const validItemSelect: Array = ['mfi', 'random', 'closest', 'fixed']; if (!validItemSelect.includes(lowerItemSelect)) { throw new Error('The itemSelector you provided is not in the list of valid methods'); } @@ -116,7 +116,7 @@ export class Cat { private static validateStartSelect(startSelect: string) { const lowerStartSelect = startSelect.toLowerCase(); - const validStartSelect: Array = ['random', 'middle']; // TO DO: add staircase + const validStartSelect: Array = ['random', 'middle', 'fixed']; // TO DO: add staircase if (!validStartSelect.includes(lowerStartSelect)) { throw new Error('The startSelect you provided is not in the list of valid methods'); } @@ -213,9 +213,10 @@ export class Cat { if (this.nItems < this.nStartItems) { selector = this.startSelect; } - if (selector !== 'mfi') { + if (selector !== 'mfi' && selector !== 'fixed') { // for mfi, we sort the arr by fisher information in the private function to select the best item, // and then sort by difficulty to return the remainingStimuli + // for fixed, we want to keep the corpus order as input arr.sort((a: Stimulus, b: Stimulus) => a.difficulty - b.difficulty); } @@ -226,6 +227,8 @@ export class Cat { return this.selectorClosest(arr); } else if (selector === 'random') { return this.selectorRandom(arr); + } else if (selector === 'fixed') { + return this.selectorFixed(arr); } else { return this.selectorMFI(arr); } @@ -289,6 +292,23 @@ export class Cat { }; } + /** + * Picks the next item in line from the given list of stimuli. + * It grabs the first item from the list, removes it, and then returns it along with the rest of the list. + * + * @param arr - The list of stimuli to choose from. + * @returns {Object} - An object with the next item and the updated list. + * @returns {Stimulus} return.nextStimulus - The item that was picked from the list. + * @returns {Stimulus[]} return.remainingStimuli - The list of what's left after picking the item. + */ + private selectorFixed(arr: Stimulus[]) { + const nextItem = arr.shift() ?? null; + return { + nextStimulus: nextItem, + remainingStimuli: arr, + }; + } + /** * return a random integer between min and max * @param min - The minimum of the random number range (include) diff --git a/validation/simulation/simulation.js b/validation/simulation/simulation.js index b6ea10f..5070ebd 100644 --- a/validation/simulation/simulation.js +++ b/validation/simulation/simulation.js @@ -82,7 +82,7 @@ function convertListToCSV(list) { const rows = list.map(obj => keys.map(key => obj[key]).join(',')).join('\n'); return header + rows; } - +// eslint-disable-next-line @typescript-eslint/no-unused-vars const csvContent = await convertListToCSV(await shuffleAnswerRobot(answerRobot, 1)); // export const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8' });