Skip to content

Commit

Permalink
Merge pull request #474 from France-ioi/fix-reload-answer-silent
Browse files Browse the repository at this point in the history
Separate the behavior of saving the score VS showing the result popup…
  • Loading branch information
SebastienTainon authored Apr 24, 2024
2 parents a518be2 + 60c2ec5 commit 8ecf8d7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
4 changes: 2 additions & 2 deletions frontend/task/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -521,9 +521,9 @@ function* taskChangeLevelSaga({payload}: ReturnType<typeof taskChangeLevel>) {
const oldAnswer = selectAnswer(state);
yield* put(platformSaveAnswer({level: currentLevel, answer: oldAnswer}));

// Grade old answer
// Grade old answer with updateScore = true and showResult = false
const answer = stringify(yield* getTaskAnswerAggregated());
yield* call(taskGradeAnswerEventSaga, taskGradeAnswerEvent(answer, null, () => {}, () => {}, true));
yield* call(taskGradeAnswerEventSaga, taskGradeAnswerEvent(answer, null, () => {}, () => {}, true, false));
log.getLogger('task').debug('grading finished');

// Change level
Expand Down
5 changes: 3 additions & 2 deletions frontend/task/platform/actionTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,14 @@ export const taskReloadAnswerEvent = createAction('taskEventReloadAnswer', (answ
error,
},
}));
export const taskGradeAnswerEvent = createAction('taskEventGradeAnswer', (answer, answerToken, success, error, silent) => ({
export const taskGradeAnswerEvent = createAction('taskEventGradeAnswer', (answer, answerToken, success, error, updateScore: boolean, showResult: boolean) => ({
payload: {
answer,
answerToken,
success,
error,
silent,
updateScore,
showResult,
},
}));
export const taskGetResourcesPost = createAction('taskEventGetResourcesPost', (resources, callback) => ({
Expand Down
17 changes: 9 additions & 8 deletions frontend/task/platform/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,8 @@ function* taskReloadAnswerEventSaga ({payload: {answer, success, error}}: Return
yield* put(platformTaskRefresh());
}
}
yield* call(taskGradeAnswerEventSaga, taskGradeAnswerEvent(JSON.stringify(convertedAnswer), null, success, error, true));
// Grade with updateScore = true and showResult = false
yield* call(taskGradeAnswerEventSaga, taskGradeAnswerEvent(JSON.stringify(convertedAnswer), null, success, error, true, false));
yield* call(taskAnswerReloadedSaga);
} else if (answer) {
const answerObject = yield* call(backwardCompatibilityConvert, JSON.parse(answer));
Expand Down Expand Up @@ -481,7 +482,7 @@ function* taskLoadEventSaga ({payload: {views: _views, success, error}}: ReturnT
}
}

export function* taskGradeAnswerEventSaga ({payload: {answer, success, error, silent}}: ReturnType<typeof taskGradeAnswerEvent>) {
export function* taskGradeAnswerEventSaga ({payload: {answer, success, error, updateScore, showResult}}: ReturnType<typeof taskGradeAnswerEvent>) {
try {
const taskLevels = yield* appSelect(state => state.platform.levels);
log.getLogger('tests').debug('task levels', taskLevels);
Expand Down Expand Up @@ -513,7 +514,7 @@ export function* taskGradeAnswerEventSaga ({payload: {answer, success, error, si
currentScoreToken = scoreToken;
}

if (!silent) {
if (updateScore) {
yield* put(platformSaveScore({level, score, answer: answerObject[level]}));
}
}
Expand All @@ -525,7 +526,7 @@ export function* taskGradeAnswerEventSaga ({payload: {answer, success, error, si
const reconciledScore = computeReconciledScore(levelScores);
const scoreWithPlatformParameters = minScore + (maxScore - minScore) * reconciledScore;

if (!silent) {
if (showResult) {
yield* put(platformAnswerGraded({score: currentScore, message: currentMessage}));
}

Expand All @@ -543,7 +544,7 @@ export function* taskGradeAnswerEventSaga ({payload: {answer, success, error, si
const {score, message, scoreToken} = yield* call([taskGrader, taskGrader.gradeAnswer], {answer: answerObject});
const scoreWithPlatformParameters = minScore + (maxScore - minScore) * score;

if (!silent) {
if (showResult) {
yield* put(platformAnswerGraded({score, message}));
}
log.getLogger('tests').debug('[Tests] Evaluation result', {scoreWithPlatformParameters, message});
Expand All @@ -552,7 +553,7 @@ export function* taskGradeAnswerEventSaga ({payload: {answer, success, error, si
} catch (ex: any) {
const message = ex.message === 'Network request failed' ? getMessage('SUBMISSION_RESULTS_CRASHED_NETWORK')
: (ex.message ? ex.message : ex.toString());
if (!silent) {
if (showResult) {
yield* put(platformAnswerGraded({error: message}));
}
console.error(ex);
Expand Down Expand Up @@ -605,8 +606,8 @@ function* platformValidateEventSaga({payload: {mode}}: ReturnType<typeof platfor
} else {
const answer = stringify(yield* getTaskAnswerAggregated());

// Grade in mode silent = false
yield* call(taskGradeAnswerEventSaga, taskGradeAnswerEvent(answer, null, () => {}, () => {}, false));
// Grade with updateScore = true and showResult = true
yield* call(taskGradeAnswerEventSaga, taskGradeAnswerEvent(answer, null, () => {}, () => {}, true, true));
}
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/task/platform/task_channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function makeTask (emit, state: AppStore) {
} else {
silent = true;
}
emit(taskGradeAnswerEvent(answer, answerToken, success ?? (() => {}), error ?? (() => {}), silent));
emit(taskGradeAnswerEvent(answer, answerToken, success ?? (() => {}), error ?? (() => {}), !silent, !silent));
},
};
}

0 comments on commit 8ecf8d7

Please sign in to comment.