Skip to content

Commit

Permalink
[BUGFIX] Corrige le problème de finalisation de session pour les sess…
Browse files Browse the repository at this point in the history
…ions à cheval sur 2 calibrations (PIX-15005).

 #10471
  • Loading branch information
pix-service-auto-merge authored Nov 6, 2024
2 parents 4ba3c2e + 293d7aa commit c6a957e
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export const handleV3CertificationScoring = async ({
locale,
);

_restoreCalibrationValues(certificationChallengesForScoring, answeredChallenges);
const certificationCourse = await certificationCourseRepository.get({ id: certificationCourseId });

const abortReason = certificationCourse.getAbortReason();
Expand Down Expand Up @@ -127,6 +128,14 @@ export const handleV3CertificationScoring = async ({
return certificationCourse;
};

function _restoreCalibrationValues(certificationChallengesForScoring, answeredChallenges) {
certificationChallengesForScoring.forEach((certificationChallengeForScoring) => {
const answeredChallenge = answeredChallenges.find(({ id }) => id === certificationChallengeForScoring.id);
answeredChallenge.discriminant = certificationChallengeForScoring.discriminant;
answeredChallenge.difficulty = certificationChallengeForScoring.difficulty;
});
}

function _createV3AssessmentResult({
allAnswers,
emitter,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
/**
* @typedef {import('../../../flash-certification/domain/models/FlashAssessmentAlgorithm.js').FlashAssessmentAlgorithm} FlashAssessmentAlgorithm
* @typedef {import('./CertificationChallengeForScoring.js').CertificationChallengeForScoring} CertificationChallengeForScoring
* @typedef {import('../../../../evaluation/domain/models/Answer.js').Answer} Answer
*/
import { CertificationChallengeCapacity } from './CertificationChallengeCapacity.js';

export class CertificationAssessmentHistory {
constructor({ capacityHistory }) {
this.capacityHistory = capacityHistory;
}
// WARN: challenges are not Array<Challenge> but Array<CertificationChallengeForScoring>
/**
* @param {Object} params
* @param {FlashAssessmentAlgorithm } params.algorithm
* @param {Array<CertificationChallengeForScoring>} params.challenges
* @param {Array<Answer>} params.allAnswers
**/
static fromChallengesAndAnswers({ algorithm, challenges, allAnswers }) {
const capacityAndErrorRateHistory = algorithm.getCapacityAndErrorRateHistory({
allAnswers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ class CertificationAssessmentScoreV3 {
allAnswers,
});

if (_shouldDowngradeCapacity({ flashAssessmentAlgorithmConfiguration, answers: allAnswers, abortReason })) {
if (
_shouldDowngradeCapacity({
maximumAssessmentLength: flashAssessmentAlgorithmConfiguration.maximumAssessmentLength,
answers: allAnswers,
abortReason,
})
) {
capacity = scoringDegradationService.downgradeCapacity({
algorithm,
capacity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,12 @@ describe('Certification | Shared | Unit | Domain | Services | Scoring V3', funct
competenceMarkRepository = { save: sinon.stub().rejects(new Error('Args mismatch')) };
flashAlgorithmConfigurationRepository = { getMostRecentBeforeDate: sinon.stub() };
flashAlgorithmService = {
getCapacityAndErrorRate: sinon.stub().rejects(new Error('Args mismatch')),
getCapacityAndErrorRateHistory: sinon.stub().rejects(new Error('Args mismatch')),
getCapacityAndErrorRate: sinon.stub().callsFake((a) => {
throw new Error(`Args mismatch, was called with ${JSON.stringify(a.challenges)}`);
}),
getCapacityAndErrorRateHistory: sinon.stub().callsFake(() => {
throw new Error('Args mismatch');
}),
};
scoringDegradationService = { downgradeCapacity: sinon.stub().rejects(new Error('Args mismatch')) };
scoringConfigurationRepository = {
Expand Down Expand Up @@ -1032,6 +1036,18 @@ describe('Certification | Shared | Unit | Domain | Services | Scoring V3', funct
capacityHistory,
});

const challengeExcludedFromCalibration = domainBuilder.buildChallenge({
...answeredChallenges[0],
discriminant: null,
difficulty: null,
});

const challengesAfterCalibration = answeredChallenges.slice(1);

challengeRepository.getMany
.withArgs(answeredChallenges.map((e) => e.id))
.returns([challengeExcludedFromCalibration, ...challengesAfterCalibration]);

certificationChallengeForScoringRepository.getByCertificationCourseId
.withArgs({ certificationCourseId })
.resolves(certificationChallengesForScoring);
Expand All @@ -1044,7 +1060,7 @@ describe('Certification | Shared | Unit | Domain | Services | Scoring V3', funct
.resolves(baseFlashAlgorithmConfiguration);
flashAlgorithmService.getCapacityAndErrorRate
.withArgs({
challenges: allChallenges,
challenges: answeredChallenges,
allAnswers: answers,
capacity: sinon.match.number,
variationPercent: undefined,
Expand All @@ -1069,6 +1085,12 @@ describe('Certification | Shared | Unit | Domain | Services | Scoring V3', funct
},
]);

challengeRepository.findFlashCompatibleWithoutLocale
.withArgs({
useObsoleteChallenges: true,
})
.returns(challengesAfterCalibration);

scoringConfigurationRepository.getLatestByDateAndLocale
.withArgs({ locale: 'fr', date: abortedCertificationCourse.getStartDate() })
.resolves(scoringConfiguration);
Expand Down

0 comments on commit c6a957e

Please sign in to comment.