|
|
@@ -17,16 +17,61 @@ function quizApp() {
|
|
|
return {
|
|
|
zacalqiz: false,
|
|
|
otazky: [],
|
|
|
-
|
|
|
+
|
|
|
async startQuiz() {
|
|
|
- this.zacalqiz = ! this.zacalqiz
|
|
|
+ this.zacalqiz = !this.zacalqiz;
|
|
|
if (this.zacalqiz && !this.otazky.length) {
|
|
|
const res = await fetch('/api/questions?count=5');
|
|
|
this.otazky = await res.json();
|
|
|
}
|
|
|
}
|
|
|
+ };
|
|
|
+}
|
|
|
+
|
|
|
+function getSummary() {
|
|
|
+ const quizScope = document.querySelector('[x-data*="SvobodaBody"]');
|
|
|
+
|
|
|
+ if (!quizScope || typeof Alpine === 'undefined' || typeof Alpine.$data !== 'function') {
|
|
|
+ return {
|
|
|
+ teacher: null,
|
|
|
+ similarityPercent: 0,
|
|
|
+ message: 'Kvízové proměnné zatím nejsou dostupné. Spusťte kvíz a zavolejte getSummary() znovu.'
|
|
|
+ };
|
|
|
}
|
|
|
+
|
|
|
+ const data = Alpine.$data(quizScope);
|
|
|
+ const scores = Object.entries(data)
|
|
|
+ .filter(([key, value]) => /Body$/.test(key) && typeof value === 'number' && Number(value) > 0)
|
|
|
+ .map(([key, value]) => ({
|
|
|
+ teacher: key.replace(/Body$/, ''),
|
|
|
+ score: Number(value) || 0
|
|
|
+ }));
|
|
|
+
|
|
|
+ if (!scores.length) {
|
|
|
+ return {
|
|
|
+ teacher: null,
|
|
|
+ similarityPercent: 0,
|
|
|
+ totalScore: 0,
|
|
|
+ message: 'Zatím není zaznamenán žádný výsledek.'
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ const totalScore = scores.reduce((sum, entry) => sum + entry.score, 0);
|
|
|
+ const bestMatch = scores.reduce((currentBest, entry) => {
|
|
|
+ return entry.score > currentBest.score ? entry : currentBest;
|
|
|
+ }, scores[0]);
|
|
|
+
|
|
|
+ return {
|
|
|
+ teacher: bestMatch.teacher,
|
|
|
+ similarityPercent: totalScore > 0
|
|
|
+ ? Math.round((bestMatch.score / totalScore) * 100)
|
|
|
+ : 0,
|
|
|
+ topScore: bestMatch.score,
|
|
|
+ totalScore
|
|
|
+ };
|
|
|
}
|
|
|
+
|
|
|
+window.getSummary = getSummary;
|
|
|
</script>
|
|
|
</head>
|
|
|
|