Kaynağa Gözat

vypocteni vyledku

josef 2 hafta önce
ebeveyn
işleme
9e996a934f
2 değiştirilmiş dosya ile 48 ekleme ve 2 silme
  1. 1 0
      silly_qiz
  2. 47 2
      templates/home.html

+ 1 - 0
silly_qiz

@@ -0,0 +1 @@
+Subproject commit 32b44a2faf19634ded7ed6c3ff9c39de4d73851b

+ 47 - 2
templates/home.html

@@ -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>