Skip to content

Commit

Permalink
[BUGFIX] Répare la finalisation de session quand une épreuve a été ex…
Browse files Browse the repository at this point in the history
…clue de la calibration (PIX-15226).

 #10529
  • Loading branch information
pix-service-auto-merge authored Nov 13, 2024
2 parents ad16a0e + 276b176 commit b753272
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@
* @typedef {import('../index.js').ChallengeRepository} ChallengeRepository
* @typedef {import('../index.js').ScoringDegradationService} ScoringDegradationService
*/
import Debug from 'debug';
import differenceBy from 'lodash/differenceBy.js';

import { config } from '../../../../../shared/config.js';
import { CompetenceMark } from '../../../../../shared/domain/models/index.js';
import { FlashAssessmentAlgorithm } from '../../../../flash-certification/domain/models/FlashAssessmentAlgorithm.js';
import { CertificationAssessmentHistory } from '../../../../scoring/domain/models/CertificationAssessmentHistory.js';
import { CertificationAssessmentScoreV3 } from '../../../../scoring/domain/models/CertificationAssessmentScoreV3.js';
import { AssessmentResultFactory } from '../../../../scoring/domain/models/factories/AssessmentResultFactory.js';

const debugScoringForV3Certification = Debug('pix:certif:v3:scoring');

/**
* @param {Object} params
* @param {AssessmentResultRepository} params.assessmentResultRepository
Expand Down Expand Up @@ -52,19 +57,42 @@ export const handleV3CertificationScoring = async ({
}) => {
const { certificationCourseId, id: assessmentId } = certificationAssessment;
const candidateAnswers = await answerRepository.findByAssessment(assessmentId);
const allChallenges = await challengeRepository.findFlashCompatibleWithoutLocale({
const flashCompatibleChallenges = await challengeRepository.findFlashCompatibleWithoutLocale({
useObsoleteChallenges: true,
});

debugScoringForV3Certification(`FlashCompatibleChallenges count: ${flashCompatibleChallenges.length}`);
debugScoringForV3Certification(`CandidateAnswers count: ${candidateAnswers.length}`);

const certificationChallengesForScoring = await certificationChallengeForScoringRepository.getByCertificationCourseId(
{ certificationCourseId },
);
const answeredChallenges = await challengeRepository.getMany(
const askedChallenges = await challengeRepository.getMany(
certificationChallengesForScoring.map((challengeForScoring) => challengeForScoring.id),
locale,
);

_restoreCalibrationValues(certificationChallengesForScoring, answeredChallenges);
_restoreCalibrationValues(certificationChallengesForScoring, askedChallenges);

const flashCompatibleChallengesNotAskedInCertification = differenceBy(
flashCompatibleChallenges,
askedChallenges,
'id',
);

const allChallenges = [...askedChallenges, ...flashCompatibleChallengesNotAskedInCertification];

debugScoringForV3Certification(
`Challenges after FlashCompatibleChallenges & CandidateAnswers merge count: ${allChallenges.length}`,
);

if (allChallenges.length > flashCompatibleChallenges.length) {
const addedChallenges = differenceBy(allChallenges, flashCompatibleChallenges, 'id');
const challengeIds = addedChallenges.map((challenge) => challenge.id);

debugScoringForV3Certification(`Added challenges after merge: ${challengeIds}`);
}

const certificationCourse = await certificationCourseRepository.get({ id: certificationCourseId });

const abortReason = certificationCourse.getAbortReason();
Expand All @@ -90,7 +118,7 @@ export const handleV3CertificationScoring = async ({
// so that in can be used during the assessment result creation
allAnswers: [...candidateAnswers],
allChallenges,
challenges: answeredChallenges,
challenges: askedChallenges,
maxReachableLevelOnCertificationDate: certificationCourse.getMaxReachableLevelOnCertificationDate(),
v3CertificationScoring,
scoringDegradationService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,7 @@ describe('Certification | Shared | Unit | Domain | Services | Scoring V3', funct
.resolves(baseFlashAlgorithmConfiguration);
flashAlgorithmService.getCapacityAndErrorRate
.withArgs({
challenges: answeredChallenges,
challenges: [challengeExcludedFromCalibration, ...challengesAfterCalibration],
allAnswers: answers,
capacity: sinon.match.number,
variationPercent: undefined,
Expand Down

0 comments on commit b753272

Please sign in to comment.