Skip to content

Commit

Permalink
refactor(api): remove linear success ranges parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrecoin committed Nov 15, 2024
1 parent 6e13136 commit 181cbaa
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 271 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,11 @@ import Joi from 'joi';
import { securityPreHandlers } from '../../../shared/application/security-pre-handlers.js';
import { scenarioSimulatorController } from './scenario-simulator-controller.js';

const _successRatesConfigurationValidator = Joi.alternatives(
Joi.object({
type: Joi.string().valid('fixed').required(),
startingChallengeIndex: Joi.number().integer().min(0).required(),
endingChallengeIndex: Joi.number().integer().min(Joi.ref('startingChallengeIndex')).required(),
value: Joi.number().min(0).max(1).required(),
}),
Joi.object({
type: Joi.string().valid('linear').required(),
startingChallengeIndex: Joi.number().integer().min(0).required(),
endingChallengeIndex: Joi.number().integer().min(Joi.ref('startingChallengeIndex')).required(),
startingValue: Joi.number().min(0).max(1).required(),
endingValue: Joi.number().min(0).max(1).required(),
}),
);
const _successRatesConfigurationValidator = Joi.object({
startingChallengeIndex: Joi.number().integer().min(0).required(),
endingChallengeIndex: Joi.number().integer().min(Joi.ref('startingChallengeIndex')).required(),
value: Joi.number().min(0).max(1).required(),
});

const _baseScenarioParametersValidator = Joi.object().keys({
initialCapacity: Joi.number().integer().min(-8).max(8),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { FlashAssessmentSuccessRateHandlerFixedStrategy } from './FlashAssessmentSuccessRateHandlerFixedStrategy.js';
import { FlashAssessmentSuccessRateHandlerLinearStrategy } from './FlashAssessmentSuccessRateHandlerLinearStrategy.js';

class FlashAssessmentSuccessRateHandler {
constructor({ startingChallengeIndex, endingChallengeIndex, strategy }) {
this.startingChallengeIndex = startingChallengeIndex;
this.endingChallengeIndex = endingChallengeIndex;

this._strategy = strategy;
}

Expand All @@ -18,15 +16,7 @@ class FlashAssessmentSuccessRateHandler {
}

static create(successRateRange) {
if (successRateRange.type === 'linear') {
return FlashAssessmentSuccessRateHandler.createLinear(successRateRange);
}
if (successRateRange.type === 'fixed') {
return FlashAssessmentSuccessRateHandler.createFixed(successRateRange);
}
}

static createFixed({ startingChallengeIndex, endingChallengeIndex, value }) {
const { startingChallengeIndex, endingChallengeIndex, value } = successRateRange;
return new FlashAssessmentSuccessRateHandler({
startingChallengeIndex,
endingChallengeIndex,
Expand All @@ -36,17 +26,6 @@ class FlashAssessmentSuccessRateHandler {
});
}

static createLinear({ startingChallengeIndex, endingChallengeIndex, startingValue, endingValue }) {
return new FlashAssessmentSuccessRateHandler({
startingChallengeIndex,
endingChallengeIndex,
strategy: new FlashAssessmentSuccessRateHandlerLinearStrategy({
startingValue,
endingValue,
}),
});
}

toDTO() {
return {
startingChallengeIndex: this.startingChallengeIndex,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,6 @@ describe('Integration | Application | scenario-simulator-controller', function (
endingChallengeIndex: 7,
value: 0.8,
},
{
type: 'linear',
startingChallengeIndex: 8,
endingChallengeIndex: 15,
startingValue: 0.8,
endingValue: 0.5,
},
];

const expectedSuccessRateRanges = [
Expand All @@ -321,12 +314,6 @@ describe('Integration | Application | scenario-simulator-controller', function (
endingChallengeIndex: 7,
value: 0.8,
}),
domainBuilder.buildFlashAssessmentAlgorithmSuccessRateHandlerLinear({
startingChallengeIndex: 8,
endingChallengeIndex: 15,
startingValue: 0.8,
endingValue: 0.5,
}),
];

const pickChallengeImplementation = sinon.stub();
Expand Down Expand Up @@ -395,54 +382,6 @@ describe('Integration | Application | scenario-simulator-controller', function (
endingChallengeIndex: 7,
value: 0.8,
},
{
type: 'linear',
startingChallengeIndex: 8,
endingChallengeIndex: 7,
startingValue: 0.8,
endingValue: 0.5,
},
];

securityPreHandlers.checkAdminMemberHasRoleSuperAdmin.returns(() => true);

// when
const response = await httpTestServer.request(
'POST',
'/api/scenario-simulator',
{
initialCapacity,
answerStatusArray,
minimumEstimatedSuccessRateRanges,
},
null,
{ 'accept-language': 'en' },
);

// then
expect(response.statusCode).to.equal(400);
});
});

context('When providing invalid linear config', function () {
it('should respond with a 400 error', async function () {
// given
const answerStatusArray = ['ok'];

const minimumEstimatedSuccessRateRanges = [
{
type: 'fixed',
startingChallengeIndex: 0,
endingChallengeIndex: 7,
value: 0.8,
},
{
type: 'linear',
startingChallengeIndex: 8,
endingChallengeIndex: 15,
startingValue: 1.3,
endingValue: 0.5,
},
];

securityPreHandlers.checkAdminMemberHasRoleSuperAdmin.returns(() => true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('Unit | Domain | Models | FlashAssessmentAlgorithmSuccessRateHandler',
value: 0.8,
};

flashAssessmentSuccessRateHandler = FlashAssessmentSuccessRateHandler.createFixed(fixedConfig);
flashAssessmentSuccessRateHandler = FlashAssessmentSuccessRateHandler.create(fixedConfig);
});

describe('when currentIndex is inside the application range', function () {
Expand Down Expand Up @@ -48,7 +48,7 @@ describe('Unit | Domain | Models | FlashAssessmentAlgorithmSuccessRateHandler',
value: configSuccessRate,
};

flashAssessmentSuccessRateHandler = FlashAssessmentSuccessRateHandler.createFixed(fixedConfig);
flashAssessmentSuccessRateHandler = FlashAssessmentSuccessRateHandler.create(fixedConfig);
});

it('should return the fixed value', function () {
Expand All @@ -58,28 +58,6 @@ describe('Unit | Domain | Models | FlashAssessmentAlgorithmSuccessRateHandler',
expect(successRate).to.equal(configSuccessRate);
});
});

describe('when strategy is linear', function () {
let flashAssessmentSuccessRateHandler;

beforeEach(function () {
const linearConfig = {
startingChallengeIndex: 0,
endingChallengeIndex: 4,
startingValue: 0.8,
endingValue: 0.6,
};

flashAssessmentSuccessRateHandler = FlashAssessmentSuccessRateHandler.createLinear(linearConfig);
});

it('should return the computed linear value', function () {
const questionIndex = 2;
const successRate = flashAssessmentSuccessRateHandler.getMinimalSuccessRate(questionIndex);

expect(successRate).to.equal(0.7);
});
});
});

describe('#create', function () {
Expand All @@ -101,24 +79,5 @@ describe('Unit | Domain | Models | FlashAssessmentAlgorithmSuccessRateHandler',
expect(successRate).to.equal(configSuccessRate);
});
});

describe('when type is linear', function () {
it('should return the linear value', function () {
const linearConfig = {
type: 'linear',
startingChallengeIndex: 0,
endingChallengeIndex: 2,
startingValue: 0.8,
endingValue: 0.6,
};

const flashAssessmentSuccessRateHandler = FlashAssessmentSuccessRateHandler.create(linearConfig);

const questionIndex = 1;
const successRate = flashAssessmentSuccessRateHandler.getMinimalSuccessRate(questionIndex);

expect(successRate).to.equal(0.7);
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ describe('Unit | Domain | Models | FlashAssessmentAlgorithm | FlashAssessmentAlg
configuration: _getAlgorithmConfig({
limitToOneQuestionPerTube: true,
minimumEstimatedSuccessRateRanges: [
FlashAssessmentSuccessRateHandler.createFixed({
FlashAssessmentSuccessRateHandler.create({
startingChallengeIndex: 0,
endingChallengeIndex: 1,
value: 0.8,
Expand Down Expand Up @@ -393,93 +393,6 @@ describe('Unit | Domain | Models | FlashAssessmentAlgorithm | FlashAssessmentAlg
expect(nextChallenges).to.deep.equal([easyChallenge, hardChallenge]);
});
});

context('when a linear minimal success rate has been set', function () {
it('should choose a challenge that has the required success rate first', function () {
// Given
const easyDifficulty = -3;
const hardDifficulty = 3;
const discriminant = 1;
const initialCapacity = 3;

const easyChallenge = domainBuilder.buildChallenge({
id: 'easyChallenge',
skill: domainBuilder.buildSkill({
id: 'skillEasy',
}),
competenceId: 'compEasy',
discriminant,
difficulty: easyDifficulty,
});

const hardChallenge2 = domainBuilder.buildChallenge({
id: 'hardChallenge2',
skill: domainBuilder.buildSkill({
id: 'hardSkill2',
}),
competenceId: 'compHard2',
discriminant,
difficulty: hardDifficulty,
});

const hardChallenge = domainBuilder.buildChallenge({
id: 'hardChallenge',
skill: domainBuilder.buildSkill({
id: 'skillHard',
}),
competenceId: 'compHard',
discriminant,
difficulty: hardDifficulty,
});

const challenges = [hardChallenge, easyChallenge, hardChallenge2];
const assessmentAnswers = [
domainBuilder.buildAnswer({
challengeId: hardChallenge.id,
}),
];

// when
const algorithm = new FlashAssessmentAlgorithm({
flashAlgorithmImplementation,
configuration: _getAlgorithmConfig({
limitToOneQuestionPerTube: false,
minimumEstimatedSuccessRateRanges: [
FlashAssessmentSuccessRateHandler.createLinear({
startingChallengeIndex: 0,
endingChallengeIndex: 2,
startingValue: 0.8,
endingValue: 0.4,
}),
],
}),
});

const expectedChallenges = [easyChallenge, hardChallenge2];
flashAlgorithmImplementation.getCapacityAndErrorRate.returns({
capacity: 0,
});
flashAlgorithmImplementation.getPossibleNextChallenges
.withArgs({
availableChallenges: expectedChallenges,
capacity: 0,
options: {
...baseGetNextChallengeOptions,
// Due to JS having troubles with float numbers, we must use a matcher.
minimalSuccessRate: sinon.match((value) => value.toPrecision(1) === '0.6'),
},
})
.returns(expectedChallenges);

const nextChallenges = algorithm.getPossibleNextChallenges({
assessmentAnswers,
challenges,
initialCapacity,
});

expect(nextChallenges).to.deep.equal(expectedChallenges);
});
});
});
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
import { FlashAssessmentSuccessRateHandler } from '../../../../src/certification/flash-certification/domain/models/FlashAssessmentSuccessRateHandler.js';

export const buildFlashAssessmentAlgorithmSuccessRateHandlerLinear = ({
startingChallengeIndex,
endingChallengeIndex,
startingValue,
endingValue,
}) => {
return FlashAssessmentSuccessRateHandler.createLinear({
startingChallengeIndex,
endingChallengeIndex,
startingValue,
endingValue,
});
};

export const buildFlashAssessmentAlgorithmSuccessRateHandlerFixed = ({
startingChallengeIndex,
endingChallengeIndex,
value,
}) => {
return FlashAssessmentSuccessRateHandler.createFixed({ startingChallengeIndex, endingChallengeIndex, value });
return FlashAssessmentSuccessRateHandler.create({ startingChallengeIndex, endingChallengeIndex, value });
};
6 changes: 1 addition & 5 deletions api/tests/tooling/domain-builder/factory/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,7 @@ import * as buildDataProtectionOfficer from './build-data-protection-officer.js'
import { buildFeedback } from './build-feedback.js';
import { buildFinalizedSession } from './build-finalized-session.js';
import { buildFlashAlgorithmConfiguration } from './build-flash-algorithm-configuration.js';
import {
buildFlashAssessmentAlgorithmSuccessRateHandlerFixed,
buildFlashAssessmentAlgorithmSuccessRateHandlerLinear,
} from './build-flash-assessment-algorithm-success-rate-handler.js';
import { buildFlashAssessmentAlgorithmSuccessRateHandlerFixed } from './build-flash-assessment-algorithm-success-rate-handler.js';
import { buildFramework } from './build-framework.js';
import { buildHabilitation } from './build-habilitation.js';
import { buildHint } from './build-hint.js';
Expand Down Expand Up @@ -363,7 +360,6 @@ export {
buildFlashAlgorithmConfiguration,
buildFlashAssessmentAlgorithm,
buildFlashAssessmentAlgorithmSuccessRateHandlerFixed,
buildFlashAssessmentAlgorithmSuccessRateHandlerLinear,
buildFramework,
buildHint,
buildJuryCertification,
Expand Down

0 comments on commit 181cbaa

Please sign in to comment.