-
Notifications
You must be signed in to change notification settings - Fork 20
[#342] [FEATURE] Affichage de la zone de correction pour les challenges QROCM-ind (US-385) #342
Changes from 87 commits
c0342dd
612c342
ea29e7e
ebc6e03
8bf8be5
6216a7b
a797d6e
7f8ad88
0a42aea
999dc20
dfb2377
c3ca82f
bd0b947
5ca838a
7791deb
6773a54
26f8d3b
4cda34c
8141f56
51a85c2
fd0c048
92bf347
7ac9ff2
c9075f4
66dd96b
b4db391
91157b6
2de0240
e8312e3
44f4b9b
a4696f1
2731782
3a6fcbb
b2147b2
b8c62b1
b9d812d
b908c40
ee5a90b
a45e008
3c7887c
5114f4e
06c421d
0fa0f86
cfbe72b
76177b9
a530689
3679ce7
467c2fe
9087b70
da73ffd
d575d55
8fbb709
7864fc7
f389810
4d7fc92
2d73406
d32dca7
5836978
ae3cd28
0af95dd
44d83aa
d3fc56a
1ea846e
b1c4b55
a031e02
838acee
a6ebc9b
d25e2d6
c036cd5
15a711b
e1f4f57
158a88b
14fc4dd
5c5919b
a0e5228
81d2fa2
3cf4838
5765b0e
5e36208
20582b6
ed99da6
b3fd0db
4cb25aa
8ab9f23
42654c7
dd5e94c
8f45602
34b5e98
6afd649
2d2dbb5
3c6e74b
759b68d
30c3f28
1ab8cba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const TABLE_NAME = 'answers'; | ||
|
||
exports.up = function(knex, Promise) { | ||
return Promise.all([ | ||
knex.schema.table(TABLE_NAME, function(table){ | ||
table.text('resultDetails'); | ||
}) | ||
]); | ||
}; | ||
|
||
exports.down = function(knex, Promise) { | ||
return Promise.all([ | ||
knex.schema.table(TABLE_NAME, function(table){ | ||
table.dropColumn('resultDetails'); | ||
}) | ||
]); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,21 +4,25 @@ const answerSerializer = require('../../infrastructure/serializers/jsonapi/answe | |
const solutionRepository = require('../../infrastructure/repositories/solution-repository'); | ||
const answerRepository = require('../../infrastructure/repositories/answer-repository'); | ||
const solutionService = require('../../domain/services/solution-service'); | ||
const jsYaml = require('js-yaml'); | ||
|
||
function _updateExistingAnswer(existingAnswer, newAnswer, reply) { | ||
solutionRepository | ||
.get(existingAnswer.get('challengeId')) | ||
.then((solution) => { | ||
const answerCorrectness = solutionService.match(newAnswer, solution); | ||
const answerCorrectness = solutionService.validate(newAnswer, solution); | ||
new Answer({ id: existingAnswer.id }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Je trouve que la méthode est longue, elle est dense. |
||
.save({ | ||
result: answerCorrectness, | ||
result: answerCorrectness.result, | ||
resultDetails: jsYaml.safeDump(answerCorrectness.resultDetails), | ||
value: newAnswer.get('value'), | ||
timeout: newAnswer.get('timeout'), | ||
challengeId: existingAnswer.get('challengeId'), | ||
assessmentId: existingAnswer.get('assessmentId') | ||
}, { method: 'update' }) | ||
.then((updatedAnswer) => reply(answerSerializer.serialize(updatedAnswer)).code(200)) | ||
.then((updatedAnswer) => { | ||
return reply(answerSerializer.serialize(updatedAnswer)).code(200); | ||
}) | ||
.catch((err) => reply(Boom.badImplementation(err))); | ||
}); | ||
} | ||
|
@@ -27,8 +31,9 @@ function _saveNewAnswer(newAnswer, reply) { | |
solutionRepository | ||
.get(newAnswer.get('challengeId')) | ||
.then((solution) => { | ||
const answerCorrectness = solutionService.match(newAnswer, solution); | ||
newAnswer.set('result', answerCorrectness); | ||
const answerValidation = solutionService.validate(newAnswer, solution); | ||
newAnswer.set('result', answerValidation.result); | ||
newAnswer.set('resultDetails', jsYaml.safeDump(answerValidation.resultDetails)); | ||
newAnswer.set('timeout', newAnswer.get('timeout')); | ||
newAnswer.set('elapsedTime', newAnswer.get('elapsedTime')); | ||
newAnswer.save() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
const _ = require('../../infrastructure/utils/lodash-utils'); | ||
|
||
|
||
module.exports = { | ||
|
||
match (answer, solution) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,47 @@ | ||
const utils = require('./solution-service-utils'); | ||
const deactivationsService = require('./deactivations-service'); | ||
const _ = require('../../infrastructure/utils/lodash-utils'); | ||
const { t1, t2, applyPreTreatments } = require('./validation-treatments'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. t1, t2 what ??? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. on n'a pas le choix c'est le vocabulaire métier, malheureusement. et pourtant je me suis battu contre... |
||
|
||
function _applyPreTreatmentsToSolutions(solution) { | ||
return _.chain(solution) | ||
.split('\n') | ||
.reject(_.isEmpty) | ||
.value(); | ||
return _.chain(solution) | ||
.split('\n') | ||
.reject(_.isEmpty) | ||
.value(); | ||
} | ||
|
||
function _applyTreatmentsToSolutions(solution, deactivations) { | ||
const pretreatedSolutions = _applyPreTreatmentsToSolutions(solution); | ||
return _.map(pretreatedSolutions, (pretreatedSolution) => { | ||
return _.map(pretreatedSolutions, (pretreatedSolution) => { | ||
|
||
if (deactivationsService.isDefault(deactivations)) { | ||
return utils._treatmentT2(utils._treatmentT1(pretreatedSolution)); | ||
return t2(t1(pretreatedSolution)); | ||
} | ||
else if (deactivationsService.hasOnlyT1(deactivations)) { | ||
return utils._treatmentT2(pretreatedSolution); | ||
return t2(pretreatedSolution); | ||
} | ||
else if (deactivationsService.hasOnlyT2(deactivations)) { | ||
return utils._treatmentT1(pretreatedSolution); | ||
return t1(pretreatedSolution); | ||
} | ||
else if (deactivationsService.hasOnlyT3(deactivations)) { | ||
return utils._treatmentT2(utils._treatmentT1(pretreatedSolution)); | ||
return t2(t1(pretreatedSolution)); | ||
} | ||
else if (deactivationsService.hasOnlyT1T2(deactivations)) { | ||
return pretreatedSolution; | ||
} | ||
else if (deactivationsService.hasOnlyT1T3(deactivations)) { | ||
return utils._treatmentT2(pretreatedSolution); | ||
return t2(pretreatedSolution); | ||
} | ||
else if (deactivationsService.hasOnlyT2T3(deactivations)) { | ||
return utils._treatmentT1(pretreatedSolution); | ||
return t1(pretreatedSolution); | ||
} | ||
else if (deactivationsService.hasT1T2T3(deactivations)) { | ||
return pretreatedSolution; | ||
} | ||
|
||
}); | ||
} | ||
|
||
// remove unbreakable space | ||
function _applyAnswerTreatment(strArg) { | ||
return strArg.replace(/\u00A0/g, ' '); | ||
} | ||
|
||
|
||
function _calculateResult(validations, deactivations) { | ||
function _formatResult(validations, deactivations) { | ||
|
||
if (deactivationsService.isDefault(deactivations)) { | ||
if (validations.t1t2t3Ratio <= 0.25) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. t1t2t3Ratio ??? une issue peut-être? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ça fait partie des bouts de code qu'on a préféré ne pas toucher car sinon c'était encore 2 semaines dans la vue. |
||
|
@@ -97,24 +91,24 @@ function _calculateResult(validations, deactivations) { | |
} | ||
return 'ko'; | ||
} | ||
|
||
} | ||
|
||
|
||
module.exports = { | ||
|
||
match (answer, solution, deactivations) { | ||
|
||
if (_.isNotString(answer) || _.isNotString(solution) || _.isEmpty(solution)) { | ||
// Input checking | ||
if (!_.isString(answer) | ||
|| !_.isString(solution) | ||
|| _.isEmpty(solution)) { | ||
return 'ko'; | ||
} | ||
|
||
const treatedAnswer = _applyAnswerTreatment(answer); | ||
const treatedAnswer = applyPreTreatments(answer); | ||
const treatedSolutions = _applyTreatmentsToSolutions(solution, deactivations); | ||
|
||
const validations = utils.treatmentT1T2T3(treatedAnswer, treatedSolutions); | ||
|
||
return _calculateResult(validations, deactivations); | ||
|
||
return _formatResult(validations, deactivations); | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,31 @@ | ||
/*eslint no-console: ["error", { allow: ["warn", "error"] }] */ | ||
const jsYaml = require('js-yaml'); | ||
const _ = require('../../infrastructure/utils/lodash-utils'); | ||
const utils = require('./solution-service-utils'); | ||
const deactivationsService = require('./deactivations-service'); | ||
|
||
const { t1, t2, applyPreTreatments } = require('./validation-treatments'); | ||
|
||
function _applyTreatmentsToSolutions(solutions, deactivations) { | ||
return _.mapValues(solutions, (validSolutions) => { | ||
return _.map(validSolutions, (validSolution) => { | ||
const pretreatedSolution = validSolution.toString(); | ||
|
||
if (deactivationsService.isDefault(deactivations)) { | ||
return utils._treatmentT2(utils._treatmentT1(pretreatedSolution)); | ||
return t2(t1(pretreatedSolution)); | ||
} | ||
else if (deactivationsService.hasOnlyT1(deactivations)) { | ||
return utils._treatmentT2(pretreatedSolution); | ||
return t2(pretreatedSolution); | ||
} | ||
else if (deactivationsService.hasOnlyT2(deactivations)) { | ||
return utils._treatmentT1(pretreatedSolution); | ||
return t1(pretreatedSolution); | ||
} | ||
else if (deactivationsService.hasOnlyT3(deactivations)) { | ||
return utils._treatmentT2(utils._treatmentT1(pretreatedSolution)); | ||
return t2(t1(pretreatedSolution)); | ||
} | ||
else if (deactivationsService.hasOnlyT1T2(deactivations)) { | ||
return pretreatedSolution; | ||
} | ||
else if (deactivationsService.hasOnlyT1T3(deactivations)) { | ||
return utils._treatmentT2(pretreatedSolution); | ||
return t2(pretreatedSolution); | ||
} | ||
else if (deactivationsService.hasT1T2T3(deactivations)) { | ||
return pretreatedSolution; | ||
|
@@ -35,13 +34,11 @@ function _applyTreatmentsToSolutions(solutions, deactivations) { | |
}); | ||
} | ||
|
||
|
||
function _applyTreatmentsToAnswers(answers) { | ||
return _.mapValues(answers, _.toString); | ||
} | ||
|
||
|
||
function _calculateValidation(answers, solutions) { | ||
function _compareAnswersAndSolutions(answers, solutions) { | ||
|
||
const validations = {}; | ||
|
||
|
@@ -104,7 +101,7 @@ function _goodAnswer(allValidations, deactivations) { | |
} | ||
} | ||
|
||
function _calculateResult(scoring, validations, deactivations) { | ||
function _formatResult(scoring, validations, deactivations) { | ||
let result = 'ok'; | ||
|
||
const numberOfGoodAnswers = _numberOfGoodAnswers(validations, deactivations); | ||
|
@@ -129,39 +126,33 @@ function _calculateResult(scoring, validations, deactivations) { | |
return result; | ||
} | ||
|
||
function _applyPreTreatmentsToAnswer(yamlAnswer) { | ||
return yamlAnswer.replace(/\u00A0/g, ' '); | ||
} | ||
|
||
module.exports = { | ||
|
||
match(yamlAnswer, yamlSolution, yamlScoring, deactivations) { | ||
|
||
// Validate inputs | ||
if (_.isNotString(yamlAnswer) | ||
|| _.isNotString(yamlSolution) | ||
// Input checking | ||
if (!_.isString(yamlAnswer) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pourquoi avez-vous enlevé la vérification sur la solution ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. car c'est pris en compte dans la condition d'après (cdf. le code de la méthode dans Lodash, et le fait que si tu retires la ligne ça ne plante pas les tests) |
||
|| _.isEmpty(yamlAnswer) | ||
|| !_.includes(yamlSolution, '\n')) { | ||
return 'ko'; | ||
} | ||
|
||
// Pre-Treatments | ||
const preTreatedAnswers = _applyPreTreatmentsToAnswer(yamlAnswer); | ||
const preTreatedAnswers = applyPreTreatments(yamlAnswer); | ||
|
||
// remove unbreakable spaces | ||
// Convert Yaml to JS objects | ||
const answers = jsYaml.safeLoad(preTreatedAnswers); | ||
const solutions = jsYaml.safeLoad(yamlSolution); | ||
const scoring = jsYaml.safeLoad(_.ensureString(yamlScoring)); | ||
|
||
|
||
// Treatments | ||
const treatedSolutions = _applyTreatmentsToSolutions(solutions, deactivations); | ||
const treatedAnswers = _applyTreatmentsToAnswers(answers); | ||
|
||
// Comparisons | ||
const fullValidations = _calculateValidation(treatedAnswers, treatedSolutions); | ||
const fullValidations = _compareAnswersAndSolutions(treatedAnswers, treatedSolutions); | ||
|
||
return _calculateResult(scoring, fullValidations, deactivations); | ||
return _formatResult(scoring, fullValidations, deactivations); | ||
} | ||
|
||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Je pense qu'une méthode plus explicite en Newspaper dans le style : findSolutionByChallengeId.
Parce qu'on ne sait pas trop ce qu'il fait sans avoir lu la suite