Fixes tests

parent 9c758f28
...@@ -32,7 +32,8 @@ npm_test: ...@@ -32,7 +32,8 @@ npm_test:
- nodejs - nodejs
script: script:
- npm install - npm install
- node_modules/mocha/bin/mocha --opts src/tests/mocha.opts - export NODE_ENV='test'
- node_modules/nyc/bin/nyc.js --reporter=text node_modules/mocha/bin/mocha --opts src/tests/mocha.opts
build: build:
stage: build stage: build
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
"description": "Version 2 of arsnova.click (Backend)", "description": "Version 2 of arsnova.click (Backend)",
"scripts": { "scripts": {
"clean": "rm -rf ./dist/*", "clean": "rm -rf ./dist/*",
"test": "mocha --opts src/tests/mocha.opts", "test": "node_modules/nyc/bin/nyc.js --reporter=text mocha --opts src/tests/mocha.opts",
"prebuild:DEV": "npm run clean", "prebuild:DEV": "npm run clean",
"prebuild:PROD": "npm run clean", "prebuild:PROD": "npm run clean",
"build:DEV": "tsc && cp -r assets dist/", "build:DEV": "tsc && cp -r assets dist/",
...@@ -76,12 +76,30 @@ ...@@ -76,12 +76,30 @@
"chai": "^4.2.0", "chai": "^4.2.0",
"chai-http": "^4.3.0", "chai-http": "^4.3.0",
"mocha": "^6.2.2", "mocha": "^6.2.2",
"mocha-prepare": "^0.1.0",
"mocha-typescript": "^1.1.17", "mocha-typescript": "^1.1.17",
"mongo-unit": "^1.4.5",
"nyc": "^14.1.1", "nyc": "^14.1.1",
"sinon": "latest", "sinon": "latest",
"ts-loader": "^6.2.1", "ts-loader": "^6.2.1",
"ts-node": "^8.4.1", "ts-node": "^8.4.1",
"tslint": "^5.20.1", "tslint": "^5.20.1",
"typescript": "^3.7.2" "typescript": "^3.7.2"
},
"nyc": {
"extension": [
".ts",
".tsx"
],
"exclude": [
"**/*.d.ts",
"jobs/**",
"src/tests/**",
"src/interfaces/**"
],
"reporter": [
"text"
],
"all": true
} }
} }
...@@ -170,7 +170,7 @@ class QuizDAO extends AbstractDAO { ...@@ -170,7 +170,7 @@ class QuizDAO extends AbstractDAO {
public isActiveQuiz(quizName: string): Promise<boolean> { public isActiveQuiz(quizName: string): Promise<boolean> {
return QuizModel.exists({ return QuizModel.exists({
name: this.buildQuiznameQuery(name), name: this.buildQuiznameQuery(quizName),
state: { $in: [QuizState.Active, QuizState.Running, QuizState.Finished] }, state: { $in: [QuizState.Active, QuizState.Running, QuizState.Finished] },
}); });
} }
......
import { EventEmitter } from 'events';
import * as xlsx from 'excel4node'; import * as xlsx from 'excel4node';
import * as MessageFormat from 'messageformat'; import * as MessageFormat from 'messageformat';
import { Document } from 'mongoose'; import { Document } from 'mongoose';
...@@ -7,7 +8,6 @@ import { IQuizBase } from '../interfaces/quizzes/IQuizEntity'; ...@@ -7,7 +8,6 @@ import { IQuizBase } from '../interfaces/quizzes/IQuizEntity';
import { Leaderboard } from '../lib/leaderboard/leaderboard'; import { Leaderboard } from '../lib/leaderboard/leaderboard';
import { MemberModelItem } from '../models/member/MemberModel'; import { MemberModelItem } from '../models/member/MemberModel';
import { excelDefaultWorksheetOptions } from './lib/excel_default_options'; import { excelDefaultWorksheetOptions } from './lib/excel_default_options';
import { ExcelTheme } from './lib/excel_default_styles'; import { ExcelTheme } from './lib/excel_default_styles';
export abstract class ExcelWorksheet { export abstract class ExcelWorksheet {
...@@ -27,12 +27,6 @@ export abstract class ExcelWorksheet { ...@@ -27,12 +27,6 @@ export abstract class ExcelWorksheet {
return this._mf; return this._mf;
} }
protected _leaderBoardData: Array<ILeaderBoardItemBase>;
get leaderBoardData(): Array<ILeaderBoardItemBase> {
return this._leaderBoardData;
}
protected _ws: xlsx.Worksheet; protected _ws: xlsx.Worksheet;
get ws(): xlsx.Worksheet { get ws(): xlsx.Worksheet {
...@@ -52,6 +46,7 @@ export abstract class ExcelWorksheet { ...@@ -52,6 +46,7 @@ export abstract class ExcelWorksheet {
private readonly _createdAt: string; private readonly _createdAt: string;
private readonly _quiz: IQuizBase; private readonly _quiz: IQuizBase;
private _columnsToFormat: number; private _columnsToFormat: number;
protected readonly loaded = new EventEmitter();
protected constructor({ theme, translation, quiz, mf, questionIndex }) { protected constructor({ theme, translation, quiz, mf, questionIndex }) {
this._theme = theme; this._theme = theme;
...@@ -88,13 +83,13 @@ export abstract class ExcelWorksheet { ...@@ -88,13 +83,13 @@ export abstract class ExcelWorksheet {
if (this._responsesWithConfidenceValue.length > 0) { if (this._responsesWithConfidenceValue.length > 0) {
this._columnsToFormat++; this._columnsToFormat++;
} }
this.loaded.emit('load');
}); });
if (this._quiz.sessionConfig.nicks.restrictToCasLogin) { if (this._quiz.sessionConfig.nicks.restrictToCasLogin) {
this._columnsToFormat += 2; this._columnsToFormat += 2;
} }
this.getLeaderboardData(questionIndex).then(data => this._leaderBoardData = data);
} }
protected generateCreatedAtString(): string { protected generateCreatedAtString(): string {
...@@ -104,7 +99,7 @@ export abstract class ExcelWorksheet { ...@@ -104,7 +99,7 @@ export abstract class ExcelWorksheet {
return `${dateYMD} ${this._mf('export.exported_at')} ${dateHM} ${this._mf('export.exported_at_time')}`; return `${dateYMD} ${this._mf('export.exported_at')} ${dateHM} ${this._mf('export.exported_at_time')}`;
} }
protected async getLeaderboardData(questionIndex: number): Promise<Array<ILeaderBoardItemBase>> { protected async getLeaderboardData(): Promise<Array<ILeaderBoardItemBase>> {
const leaderBoard = new Leaderboard(); const leaderBoard = new Leaderboard();
const { correctResponses } = await leaderBoard.buildLeaderboard(this.quiz); const { correctResponses } = await leaderBoard.buildLeaderboard(this.quiz);
return leaderBoard.sortBy(correctResponses, 'score'); return leaderBoard.sortBy(correctResponses, 'score');
......
import MemberDAO from '../db/MemberDAO'; import MemberDAO from '../db/MemberDAO';
import { IExcelWorksheet } from '../interfaces/iExcel'; import { IExcelWorksheet } from '../interfaces/iExcel';
import { IQuestionFreetext } from '../interfaces/questions/IQuestionFreetext'; import { IQuestionFreetext } from '../interfaces/questions/IQuestionFreetext';
import { asyncForEach } from '../lib/async-for-each';
import { MemberModelItem } from '../models/member/MemberModel'; import { MemberModelItem } from '../models/member/MemberModel';
import { ExcelWorksheet } from './ExcelWorksheet'; import { ExcelWorksheet } from './ExcelWorksheet';
...@@ -28,8 +29,10 @@ export class FreeTextExcelWorksheet extends ExcelWorksheet implements IExcelWork ...@@ -28,8 +29,10 @@ export class FreeTextExcelWorksheet extends ExcelWorksheet implements IExcelWork
}); });
})); }));
this.formatSheet(); this.loaded.on('load', () => {
this.addSheetData(); this.formatSheet();
this.addSheetData();
});
} }
public async formatSheet(): Promise<void> { public async formatSheet(): Promise<void> {
...@@ -104,8 +107,8 @@ export class FreeTextExcelWorksheet extends ExcelWorksheet implements IExcelWork ...@@ -104,8 +107,8 @@ export class FreeTextExcelWorksheet extends ExcelWorksheet implements IExcelWork
}); });
this.ws.cell(11, 1, attendeeEntryRows + 10, columnsToFormat, !hasEntries).style(attendeeEntryRowStyle); this.ws.cell(11, 1, attendeeEntryRows + 10, columnsToFormat, !hasEntries).style(attendeeEntryRowStyle);
this.allResponses.forEach((responseItem, indexInList) => { await asyncForEach(this.allResponses, async (responseItem, indexInList) => {
const leaderboardItem = this.leaderBoardData.filter(lbItem => lbItem.name === responseItem.name)[0]; const leaderboardItem = (await this.getLeaderboardData()).filter(lbItem => lbItem.name === responseItem.name)[0];
let nextColumnIndex = 2; let nextColumnIndex = 2;
const targetRow = indexInList + 11; const targetRow = indexInList + 11;
if (this._isCasRequired) { if (this._isCasRequired) {
...@@ -158,7 +161,7 @@ export class FreeTextExcelWorksheet extends ExcelWorksheet implements IExcelWork ...@@ -158,7 +161,7 @@ export class FreeTextExcelWorksheet extends ExcelWorksheet implements IExcelWork
${this.mf(answerOption.configTrimWhitespaces ? 'global.yes' : 'global.no')}`); ${this.mf(answerOption.configTrimWhitespaces ? 'global.yes' : 'global.no')}`);
this.ws.cell(7, 1).string(this.mf('export.percent_correct') + ':'); this.ws.cell(7, 1).string(this.mf('export.percent_correct') + ':');
const correctResponsesPercentage: number = this.leaderBoardData.map(leaderboard => leaderboard.correctQuestions) const correctResponsesPercentage: number = (await this.getLeaderboardData()).map(leaderboard => leaderboard.correctQuestions)
.filter(correctQuestions => correctQuestions.includes(this._questionIndex)).length .filter(correctQuestions => correctQuestions.includes(this._questionIndex)).length
/ (await MemberDAO.getMembersOfQuiz(this.quiz.name)).length * 100; / (await MemberDAO.getMembersOfQuiz(this.quiz.name)).length * 100;
this.ws.cell(7, 2).number((isNaN(correctResponsesPercentage) ? 0 : Math.round(correctResponsesPercentage))); this.ws.cell(7, 2).number((isNaN(correctResponsesPercentage) ? 0 : Math.round(correctResponsesPercentage)));
......
...@@ -24,8 +24,11 @@ export class MultipleChoiceExcelWorksheet extends ExcelWorksheet implements IExc ...@@ -24,8 +24,11 @@ export class MultipleChoiceExcelWorksheet extends ExcelWorksheet implements IExc
this._ws = wb.addWorksheet(`${mf('export.question')} ${questionIndex + 1}`, this._options); this._ws = wb.addWorksheet(`${mf('export.question')} ${questionIndex + 1}`, this._options);
this._questionIndex = questionIndex; this._questionIndex = questionIndex;
this._question = this.quiz.questionList[questionIndex] as IQuestionChoice; this._question = this.quiz.questionList[questionIndex] as IQuestionChoice;
this.formatSheet();
this.addSheetData(); this.loaded.on('load', () => {
this.formatSheet();
this.addSheetData();
});
} }
public async formatSheet(): Promise<void> { public async formatSheet(): Promise<void> {
...@@ -152,7 +155,7 @@ export class MultipleChoiceExcelWorksheet extends ExcelWorksheet implements IExc ...@@ -152,7 +155,7 @@ export class MultipleChoiceExcelWorksheet extends ExcelWorksheet implements IExc
this.ws.cell(6, 1).string(this.mf('export.number_of_answers') + ':'); this.ws.cell(6, 1).string(this.mf('export.number_of_answers') + ':');
this.ws.cell(7, 1).string(this.mf('export.percent_correct') + ':'); this.ws.cell(7, 1).string(this.mf('export.percent_correct') + ':');
const correctResponsesPercentage: number = this.leaderBoardData.map(leaderboard => leaderboard.correctQuestions) const correctResponsesPercentage: number = (await this.getLeaderboardData()).map(leaderboard => leaderboard.correctQuestions)
.filter(correctQuestions => correctQuestions.includes(this._questionIndex)).length .filter(correctQuestions => correctQuestions.includes(this._questionIndex)).length
/ (await MemberDAO.getMembersOfQuiz(this.quiz.name)).length * 100; / (await MemberDAO.getMembersOfQuiz(this.quiz.name)).length * 100;
this.ws.cell(7, 2).number((isNaN(correctResponsesPercentage) ? 0 : Math.round(correctResponsesPercentage))); this.ws.cell(7, 2).number((isNaN(correctResponsesPercentage) ? 0 : Math.round(correctResponsesPercentage)));
...@@ -171,7 +174,7 @@ export class MultipleChoiceExcelWorksheet extends ExcelWorksheet implements IExc ...@@ -171,7 +174,7 @@ export class MultipleChoiceExcelWorksheet extends ExcelWorksheet implements IExc
for (let j = 0; j < answerList.length; j++) { for (let j = 0; j < answerList.length; j++) {
this.ws.cell(2, (j + 2)).string(this.mf('export.answer') + ' ' + (j + 1)); this.ws.cell(2, (j + 2)).string(this.mf('export.answer') + ' ' + (j + 1));
this.ws.cell(4, (j + 2)).string(answerList[j].answerText); this.ws.cell(4, (j + 2)).string(answerList[j].answerText);
this.ws.cell(6, (j + 2)).number(calculateNumberOfAnswers(this.quiz, this._questionIndex, j)); this.ws.cell(6, (j + 2)).number(await calculateNumberOfAnswers(this.quiz, this._questionIndex, j));
} }
let nextColumnIndex = 1; let nextColumnIndex = 1;
......
...@@ -22,8 +22,11 @@ export class RangedExcelWorksheet extends ExcelWorksheet implements IExcelWorksh ...@@ -22,8 +22,11 @@ export class RangedExcelWorksheet extends ExcelWorksheet implements IExcelWorksh
this._ws = wb.addWorksheet(`${mf('export.question')} ${questionIndex + 1}`, this._options); this._ws = wb.addWorksheet(`${mf('export.question')} ${questionIndex + 1}`, this._options);
this._questionIndex = questionIndex; this._questionIndex = questionIndex;
this._question = this.quiz.questionList[questionIndex] as IQuestionRanged; this._question = this.quiz.questionList[questionIndex] as IQuestionRanged;
this.formatSheet();
this.addSheetData(); this.loaded.on('load', () => {
this.formatSheet();
this.addSheetData();
});
} }
public async formatSheet(): Promise<void> { public async formatSheet(): Promise<void> {
...@@ -138,8 +141,10 @@ export class RangedExcelWorksheet extends ExcelWorksheet implements IExcelWorksh ...@@ -138,8 +141,10 @@ export class RangedExcelWorksheet extends ExcelWorksheet implements IExcelWorksh
lastColumn: minColums, lastColumn: minColums,
}); });
const hasEntries = this.leaderBoardData.length > 0; const leaderBoardData = await this.getLeaderboardData();
const attendeeEntryRows = hasEntries ? (this.leaderBoardData.length) : 1;
const hasEntries = leaderBoardData.length > 0;
const attendeeEntryRows = hasEntries ? (leaderBoardData.length) : 1;
const attendeeEntryRowStyle = hasEntries ? defaultStyles.attendeeEntryRowStyle : Object.assign({}, defaultStyles.attendeeEntryRowStyle, { const attendeeEntryRowStyle = hasEntries ? defaultStyles.attendeeEntryRowStyle : Object.assign({}, defaultStyles.attendeeEntryRowStyle, {
alignment: { alignment: {
horizontal: 'center', horizontal: 'center',
...@@ -147,7 +152,7 @@ export class RangedExcelWorksheet extends ExcelWorksheet implements IExcelWorksh ...@@ -147,7 +152,7 @@ export class RangedExcelWorksheet extends ExcelWorksheet implements IExcelWorksh
}); });
this.ws.cell(11, 1, attendeeEntryRows + 10, columnsToFormat, !hasEntries).style(attendeeEntryRowStyle); this.ws.cell(11, 1, attendeeEntryRows + 10, columnsToFormat, !hasEntries).style(attendeeEntryRowStyle);
await asyncForEach(this.leaderBoardData, async (leaderboardItem, indexInList) => { await asyncForEach(leaderBoardData, async (leaderboardItem, indexInList) => {
let nextColumnIndex = 2; let nextColumnIndex = 2;
const targetRow = indexInList + 11; const targetRow = indexInList + 11;
if (this._isCasRequired) { if (this._isCasRequired) {
...@@ -190,6 +195,7 @@ export class RangedExcelWorksheet extends ExcelWorksheet implements IExcelWorksh ...@@ -190,6 +195,7 @@ export class RangedExcelWorksheet extends ExcelWorksheet implements IExcelWorksh
} }
public async addSheetData(): Promise<void> { public async addSheetData(): Promise<void> {
const leaderBoardData = await this.getLeaderboardData();
const castedQuestion = this._question as IQuestionRanged; const castedQuestion = this._question as IQuestionRanged;
const numberOfInputValuesPerGroup = await calculateNumberOfRangedAnswers(this.quiz, this._questionIndex, castedQuestion.rangeMin, const numberOfInputValuesPerGroup = await calculateNumberOfRangedAnswers(this.quiz, this._questionIndex, castedQuestion.rangeMin,
castedQuestion.correctValue, castedQuestion.rangeMax); castedQuestion.correctValue, castedQuestion.rangeMax);
...@@ -212,7 +218,7 @@ export class RangedExcelWorksheet extends ExcelWorksheet implements IExcelWorksh ...@@ -212,7 +218,7 @@ export class RangedExcelWorksheet extends ExcelWorksheet implements IExcelWorksh
this.ws.cell(6, 4).number(numberOfInputValuesPerGroup.maxRange); this.ws.cell(6, 4).number(numberOfInputValuesPerGroup.maxRange);
this.ws.cell(7, 1).string(this.mf('export.percent_correct') + ':'); this.ws.cell(7, 1).string(this.mf('export.percent_correct') + ':');
const correctResponsesPercentage: number = this.leaderBoardData.map(leaderboard => leaderboard.correctQuestions) const correctResponsesPercentage: number = leaderBoardData.map(leaderboard => leaderboard.correctQuestions)
.filter(correctQuestions => correctQuestions.includes(this._questionIndex)).length .filter(correctQuestions => correctQuestions.includes(this._questionIndex)).length
/ (await MemberDAO.getMembersOfQuiz(this.quiz.name)).length * 100; / (await MemberDAO.getMembersOfQuiz(this.quiz.name)).length * 100;
this.ws.cell(7, 2).number((isNaN(correctResponsesPercentage) ? 0 : Math.round(correctResponsesPercentage))); this.ws.cell(7, 2).number((isNaN(correctResponsesPercentage) ? 0 : Math.round(correctResponsesPercentage)));
...@@ -239,7 +245,7 @@ export class RangedExcelWorksheet extends ExcelWorksheet implements IExcelWorksh ...@@ -239,7 +245,7 @@ export class RangedExcelWorksheet extends ExcelWorksheet implements IExcelWorksh
this.ws.cell(10, nextColumnIndex++).string(this.mf('export.time')); this.ws.cell(10, nextColumnIndex++).string(this.mf('export.time'));
let nextStartRow = 10; let nextStartRow = 10;
await asyncForEach(this.leaderBoardData, async leaderboardItem => { await asyncForEach(leaderBoardData, async leaderboardItem => {
const responseItem = (await MemberDAO.getMembersOfQuiz(this.quiz.name)).filter(nickitem => { const responseItem = (await MemberDAO.getMembersOfQuiz(this.quiz.name)).filter(nickitem => {
return nickitem.name === leaderboardItem.name; return nickitem.name === leaderboardItem.name;
})[0].responses[this._questionIndex]; })[0].responses[this._questionIndex];
......
...@@ -24,8 +24,11 @@ export class SingleChoiceExcelWorksheet extends ExcelWorksheet implements IExcel ...@@ -24,8 +24,11 @@ export class SingleChoiceExcelWorksheet extends ExcelWorksheet implements IExcel
this._ws = wb.addWorksheet(`${mf('export.question')} ${questionIndex + 1}`, this._options); this._ws = wb.addWorksheet(`${mf('export.question')} ${questionIndex + 1}`, this._options);
this._questionIndex = questionIndex; this._questionIndex = questionIndex;
this._question = this.quiz.questionList[questionIndex] as IQuestionChoice; this._question = this.quiz.questionList[questionIndex] as IQuestionChoice;
this.formatSheet();
this.addSheetData(); this.loaded.on('load', () => {
this.formatSheet();
this.addSheetData();
});
} }
public async formatSheet(): Promise<void> { public async formatSheet(): Promise<void> {
...@@ -164,12 +167,12 @@ export class SingleChoiceExcelWorksheet extends ExcelWorksheet implements IExcel ...@@ -164,12 +167,12 @@ export class SingleChoiceExcelWorksheet extends ExcelWorksheet implements IExcel
for (let j = 0; j < answerList.length; j++) { for (let j = 0; j < answerList.length; j++) {
this.ws.cell(2, (j + 2)).string(this.mf('export.answer') + ' ' + (j + 1)); this.ws.cell(2, (j + 2)).string(this.mf('export.answer') + ' ' + (j + 1));
this.ws.cell(4, (j + 2)).string(answerList[j].answerText); this.ws.cell(4, (j + 2)).string(answerList[j].answerText);
this.ws.cell(6, (j + 2)).number(calculateNumberOfAnswers(this.quiz, this._questionIndex, j)); this.ws.cell(6, (j + 2)).number(await calculateNumberOfAnswers(this.quiz, this._questionIndex, j));
} }
this.ws.cell(6, 1).string(this.mf('export.number_of_answers') + ':'); this.ws.cell(6, 1).string(this.mf('export.number_of_answers') + ':');
this.ws.cell(7, 1).string(this.mf('export.percent_correct') + ':'); this.ws.cell(7, 1).string(this.mf('export.percent_correct') + ':');
const correctResponsesPercentage: number = this.leaderBoardData.map(leaderboard => leaderboard.correctQuestions) const correctResponsesPercentage: number = (await this.getLeaderboardData()).map(leaderboard => leaderboard.correctQuestions)
.filter(correctQuestions => correctQuestions.includes(this._questionIndex)).length .filter(correctQuestions => correctQuestions.includes(this._questionIndex)).length
/ (await MemberDAO.getMembersOfQuiz(this.quiz.name)).length * 100; / (await MemberDAO.getMembersOfQuiz(this.quiz.name)).length * 100;
this.ws.cell(7, 2).number((isNaN(correctResponsesPercentage) ? 0 : Math.round(correctResponsesPercentage))); this.ws.cell(7, 2).number((isNaN(correctResponsesPercentage) ? 0 : Math.round(correctResponsesPercentage)));
......
...@@ -16,17 +16,6 @@ declare global { ...@@ -16,17 +16,6 @@ declare global {
setWidth(width: number): void; setWidth(width: number): void;
} }
interface IWorksheet {
cell: Function;
addImage: Function;
row(index: number): IRow;
}
interface IWorkbook {
addWorksheet: Function;
}
} }
} }
...@@ -42,12 +31,14 @@ export class SummaryExcelWorksheet extends ExcelWorksheet implements IExcelWorks ...@@ -42,12 +31,14 @@ export class SummaryExcelWorksheet extends ExcelWorksheet implements IExcelWorks
questionIndex: null, questionIndex: null,
}); });
this._ws = wb.addWorksheet(mf('export.summary'), this._options); this._ws = wb.addWorksheet(mf('export.summary'), this._options);
this.formatSheet(); Promise.all([
this.addSheetData(); this.formatSheet(), this.addSheetData(),
]);
} }
public formatSheet(): void { public async formatSheet(): Promise<void> {
const defaultStyles = this._theme.getStyles(); const defaultStyles = this._theme.getStyles();
const leaderBoardData = await this.getLeaderboardData();
this.ws.row(1).setHeight(20); this.ws.row(1).setHeight(20);
this.ws.column(1).setWidth(30); this.ws.column(1).setWidth(30);
...@@ -112,7 +103,7 @@ export class SummaryExcelWorksheet extends ExcelWorksheet implements IExcelWorks ...@@ -112,7 +103,7 @@ export class SummaryExcelWorksheet extends ExcelWorksheet implements IExcelWorks
}); });
let dataWithoutCompleteCorrectQuestions = 0; let dataWithoutCompleteCorrectQuestions = 0;
this.leaderBoardData.forEach((leaderboardItem, indexInList) => { await asyncForEach(leaderBoardData, (leaderboardItem, indexInList) => {
let hasNotAllQuestionsCorrect = false; let hasNotAllQuestionsCorrect = false;
this.quiz.questionList.forEach((item, index) => { this.quiz.questionList.forEach((item, index) => {
if (![ if (![
...@@ -148,15 +139,14 @@ export class SummaryExcelWorksheet extends ExcelWorksheet implements IExcelWorks ...@@ -148,15 +139,14 @@ export class SummaryExcelWorksheet extends ExcelWorksheet implements IExcelWorks
}); });
}); });
if (dataWithoutCompleteCorrectQuestions === this.leaderBoardData.length) { if (dataWithoutCompleteCorrectQuestions === leaderBoardData.length) {
this.ws.cell(++currentRowIndex, 1, currentRowIndex, this.columnsToFormat, true).style(Object.assign({}, defaultStyles.attendeeEntryRowStyle, { this.ws.cell(++currentRowIndex, 1, currentRowIndex, this.columnsToFormat, true).style(Object.assign({}, defaultStyles.attendeeEntryRowStyle, {
alignment: { alignment: {
horizontal: 'center', horizontal: 'center',
}, },
})); }));
} else { } else {
this.ws.cell(currentRowIndex, 1, (this.leaderBoardData.length + currentRowIndex - 1 - dataWithoutCompleteCorrectQuestions), this.ws.cell(currentRowIndex, 1, (leaderBoardData.length + currentRowIndex - 1 - dataWithoutCompleteCorrectQuestions), this.columnsToFormat)
this.columnsToFormat)
.style(defaultStyles.attendeeEntryRowStyle); .style(defaultStyles.attendeeEntryRowStyle);
} }
currentRowIndex += 6; currentRowIndex += 6;
...@@ -172,10 +162,10 @@ export class SummaryExcelWorksheet extends ExcelWorksheet implements IExcelWorks ...@@ -172,10 +162,10 @@ export class SummaryExcelWorksheet extends ExcelWorksheet implements IExcelWorks
}); });
currentRowIndex++; currentRowIndex++;
this.ws.cell(currentRowIndex, 1, (this.leaderBoardData.length + (currentRowIndex - 1)), this.columnsToFormat) this.ws.cell(currentRowIndex, 1, (leaderBoardData.length + (currentRowIndex - 1)), this.columnsToFormat)
.style(defaultStyles.attendeeEntryRowStyle); .style(defaultStyles.attendeeEntryRowStyle);
this.leaderBoardData.forEach((leaderboardItem, indexInList) => { leaderBoardData.forEach((leaderboardItem, indexInList) => {
let nextColumnIndex = 3; let nextColumnIndex = 3;
const targetRow = indexInList + currentRowIndex; const targetRow = indexInList + currentRowIndex;
if (this.quiz.sessionConfig.confidenceSliderEnabled) { if (this.quiz.sessionConfig.confidenceSliderEnabled) {
...@@ -201,6 +191,7 @@ export class SummaryExcelWorksheet extends ExcelWorksheet implements IExcelWorks ...@@ -201,6 +191,7 @@ export class SummaryExcelWorksheet extends ExcelWorksheet implements IExcelWorks
} }
public async addSheetData(): Promise<void> { public async addSheetData(): Promise<void> {
const leaderBoardData = await this.getLeaderboardData();
let currentRowIndex = 1; let currentRowIndex = 1;
const numberOfResponses = (await MemberDAO.getMembersOfQuiz(this.quiz.name)).filter(nickname => { const numberOfResponses = (await MemberDAO.getMembersOfQuiz(this.quiz.name)).filter(nickname => {
return nickname.responses.filter(response => { return nickname.responses.filter(response => {
...@@ -232,7 +223,7 @@ export class SummaryExcelWorksheet extends ExcelWorksheet implements IExcelWorks ...@@ -232,7 +223,7 @@ export class SummaryExcelWorksheet extends ExcelWorksheet implements IExcelWorks
currentRowIndex++; currentRowIndex++;
this.ws.cell(currentRowIndex, 1).string(`${this.mf('export.average_correct_answered_questions')}:`); this.ws.cell(currentRowIndex, 1).string(`${this.mf('export.average_correct_answered_questions')}:`);
this.ws.cell(currentRowIndex, 3).number((this.leaderBoardData.map((x) => { this.ws.cell(currentRowIndex, 3).number((leaderBoardData.map((x) => {
return x.correctQuestions.length; return x.correctQuestions.length;
}).reduce((a, b) => { }).reduce((a, b) => {
return a + b; return a + b;
...@@ -241,7 +232,7 @@ export class SummaryExcelWorksheet extends ExcelWorksheet implements IExcelWorks ...@@ -241,7 +232,7 @@ export class SummaryExcelWorksheet extends ExcelWorksheet implements IExcelWorks
if (this.quiz.sessionConfig.confidenceSliderEnabled) { if (this.quiz.sessionConfig.confidenceSliderEnabled) {
this.ws.cell(currentRowIndex, 1).string(`${this.mf('export.average_confidence')}:`); this.ws.cell(currentRowIndex, 1).string(`${this.mf('export.average_confidence')}:`);
const averageConfidencePercentage = (this.leaderBoardData.filter((x) => { const averageConfidencePercentage = (leaderBoardData.filter((x) => {
return x.confidenceValue > -1; return x.confidenceValue > -1;
}).map((x) => { }).map((x) => {
return x.confidenceValue; return x.confidenceValue;
...@@ -253,7 +244,7 @@ export class SummaryExcelWorksheet extends ExcelWorksheet implements IExcelWorks ...@@ -253,7 +244,7 @@ export class SummaryExcelWorksheet extends ExcelWorksheet implements IExcelWorks
} }
this.ws.cell(currentRowIndex, 1).string(`${this.mf('export.average_response_time')}:`); this.ws.cell(currentRowIndex, 1).string(`${this.mf('export.average_response_time')}:`);
this.ws.cell(currentRowIndex, 3).number((Math.round((this.leaderBoardData.map((x) => { this.ws.cell(currentRowIndex, 3).number((Math.round((leaderBoardData.map((x) => {
return x.responseTime; return x.responseTime;
}).reduce((a, b) => { }).reduce((a, b) => {
return a + b; return a + b;
...@@ -280,7 +271,7 @@ export class SummaryExcelWorksheet extends ExcelWorksheet implements IExcelWorks ...@@ -280,7 +271,7 @@ export class SummaryExcelWorksheet extends ExcelWorksheet implements IExcelWorks
currentRowIndex++; currentRowIndex++;
let nextStartRow = currentRowIndex + 5; let nextStartRow = currentRowIndex + 5;
await asyncForEach(this.leaderBoardData, async (leaderboardItem, indexInList) => { await asyncForEach(leaderBoardData, async (leaderboardItem, indexInList) => {
if (this.quiz.questionList.some((item, index) => ![QuestionType.SurveyQuestion, QuestionType.ABCDSingleChoiceQuestion].includes(item.TYPE) if (this.quiz.questionList.some((item, index) => ![QuestionType.SurveyQuestion, QuestionType.ABCDSingleChoiceQuestion].includes(item.TYPE)
&& leaderboardItem.correctQuestions.indexOf((index)) === -1)) { && leaderboardItem.correctQuestions.indexOf((index)) === -1)) {
return; return;
...@@ -302,7 +293,7 @@ export class SummaryExcelWorksheet extends ExcelWorksheet implements IExcelWorks ...@@ -302,7 +293,7 @@ export class SummaryExcelWorksheet extends ExcelWorksheet implements IExcelWorks
} }
this.ws.cell(targetRow, nextColumnIndex++).number(Math.round(leaderboardItem.responseTime)); this.ws.cell(targetRow, nextColumnIndex++).number(Math.round(leaderboardItem.responseTime));
this.ws.cell(targetRow, nextColumnIndex++).number(Math.round((leaderboardItem.responseTime / this.leaderBoardData.length))); this.ws.cell(targetRow, nextColumnIndex++).number(Math.round((leaderboardItem.responseTime / leaderBoardData.length)));
}); });