Commit 4c2b1b33 authored by Christopher Fullarton's avatar Christopher Fullarton

Fixes correct / wrong calculation of ranged question answers

parent ad33f6f9
export interface IQuizResponse {
value: Array<number> | number | string;
value: Array<number> | string;
responseTime: number;
confidence: number;
readingConfirmation: boolean;
......
......@@ -72,21 +72,25 @@ export class ProgressBarComponent {
if (typeof value.responses[this.questionIndex] === 'undefined' || value.responses[this.questionIndex].responseTime === -1) {
return false;
}
const responseValue: any = value.responses[this.questionIndex].value;
if (!responseValue || !String(responseValue).length || (Array.isArray(responseValue) && !responseValue.length)) {
const responseValue: Array<number> | string = value.responses[this.questionIndex].value;
if (!Array.isArray(responseValue) || !['number', 'string'].includes(typeof responseValue)) {
return false;
}
if (question.TYPE === QuestionType.FreeTextQuestion) {
const answer = question.answerOptionList[0] = new FreeTextAnswerEntity(question.answerOptionList[0]);
if (answer.isCorrectInput(responseValue)) {
if (answer.isCorrectInput(responseValue as unknown as string)) {
correct++;
} else {
wrong++;
}
} else if (question.TYPE === QuestionType.RangedQuestion) {
if (responseValue === question.correctValue || responseValue !== question.correctValue && responseValue >= question.rangeMin && responseValue
<= question.rangeMax) {
const parsedResponseValue = parseInt(responseValue as unknown as string, 10);
if (parsedResponseValue === question.correctValue || //
(
parsedResponseValue >= question.rangeMin && //
parsedResponseValue <= question.rangeMax
)) {
correct++;
} else {
wrong++;
......@@ -98,12 +102,16 @@ export class ProgressBarComponent {
base--;
question.answerOptionList.forEach((answer, answerIndex) => {
if (answer.isCorrect) {
if ((<any>responseValue.indexOf(answerIndex)) > -1) {
if ((
responseValue.indexOf(answerIndex)
) > -1) {
correct++;
base++;
}
} else {
if ((<any>responseValue.indexOf(answerIndex)) > -1) {
if ((
responseValue.indexOf(answerIndex)
) > -1) {
wrong++;
base++;
}
......@@ -145,9 +153,13 @@ export class ProgressBarComponent {
if (Array.isArray(responseValue)) {
if (isNaN(responseValue[0])) {
return (<any>responseValue.indexOf(question.answerOptionList[answerIndex].answerText)) > -1;
return (
<any>responseValue.indexOf(question.answerOptionList[answerIndex].answerText)
) > -1;
} else {
return (<any>responseValue.indexOf(answerIndex)) > -1;
return (
<any>responseValue.indexOf(answerIndex)
) > -1;
}
} else {
return responseValue === answerIndex;
......@@ -169,7 +181,7 @@ export class ProgressBarComponent {
if (typeof value.responses[this.questionIndex] === 'undefined') {
return false;
}
const responseValue = value.responses[this.questionIndex].value;
const responseValue = parseInt(value.responses[this.questionIndex].value as unknown as string, 10);
if (Array.isArray(responseValue)) {
return false;
}
......
......@@ -62,7 +62,7 @@ export class AnsweroptionsRangedComponent implements OnInit, OnDestroy {
.subscribe(questionIndex => {
this._questionIndex = questionIndex;
this._question = <RangedQuestionEntity>this.quizService.quiz.questionList[this._questionIndex];
this._question = this.quizService.quiz.questionList[this._questionIndex] as RangedQuestionEntity;
this._minRange = String(this._question.rangeMin);
this._maxRange = String(this._question.rangeMax);
this._correctValue = String(this._question.correctValue);
......@@ -75,7 +75,7 @@ export class AnsweroptionsRangedComponent implements OnInit, OnDestroy {
this._question.rangeMax = parseInt(this._maxRange, 10);
this._question.correctValue = parseInt(this._correctValue, 10);
this.quizService.quiz.questionList[this._questionIndex] = <RangedQuestionEntity>this._question;
this.quizService.quiz.questionList[this._questionIndex] = this._question;
this.quizService.persist();
this._destroy.next();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment