Big update to the admin-screen and smaller bug-fixes

This commit is contained in:
Mawoka
2022-06-24 17:34:03 +02:00
parent c19e362aaf
commit ffee61fde3
14 changed files with 375 additions and 257 deletions
+56
View File
@@ -0,0 +1,56 @@
import type { QuizData } from '$lib/quiz_types';
export const get_question_title = (q_number: number, quiz_data: QuizData): string => {
if (q_number - 1 === quiz_data.questions.length) {
return;
}
try {
return quiz_data.questions[q_number].question;
} catch (e) {
return '';
}
};
export const getWinnersSorted = (
quiz_data: QuizData,
final_results: Array<null> | Array<Array<PlayerAnswer>>
) => {
const winners = {};
const q_count = quiz_data.questions.length;
for (let i = 0; i < q_count; i++) {
const q_res = final_results[i];
if (q_res === null) {
continue;
}
for (let j = 0; j < q_res.length; j++) {
const res = q_res[j];
if (res['right']) {
if (winners[res['username']] === undefined) {
winners[res['username']] = 0;
}
winners[res['username']] += 1;
}
}
}
function sortObjectbyValue(obj) {
const asc = false;
const ret = {};
Object.keys(obj)
.sort((a, b) => obj[asc ? a : b] - obj[asc ? b : a])
.forEach((s) => (ret[s] = obj[s]));
return ret;
}
return sortObjectbyValue(winners);
};
export interface Player {
username: string;
}
export interface PlayerAnswer {
username: string;
answer: string;
right: string;
}