diff --git a/public/index.html b/public/index.html
index 744bf0c..150523e 100644
--- a/public/index.html
+++ b/public/index.html
@@ -49,6 +49,7 @@
+
@@ -104,6 +105,21 @@
+
+
+
Smart Analytics Overview
+
+ - Average Score: –
+ - Total Completed Sessions: –
+ - Most Missed Word: –
+
+
+
Per-Student Breakdown
+
+
+
+
+
🎨 Select Theme
diff --git a/public/js/admin.js b/public/js/admin.js
index beb2204..73818f2 100644
--- a/public/js/admin.js
+++ b/public/js/admin.js
@@ -225,4 +225,56 @@ async function loadUserDropdowns() {
} catch (err) {
console.error("⚠️ Failed to load user list:", err);
}
+}
+async function refreshAnalytics() {
+ const summary = document.getElementById("analyticsSummary");
+ const breakdown = document.getElementById("studentBreakdown");
+ summary.innerHTML = "Loading...";
+ breakdown.innerHTML = "";
+
+ try {
+ const res = await fetch('/getResults');
+ const data = await res.json();
+
+ let totalScore = 0, sessionCount = 0;
+ const missMap = {};
+
+ for (const username in data) {
+ const { score, completed, answers } = data[username];
+ if (!completed || !Array.isArray(answers)) continue;
+
+ totalScore += score;
+ sessionCount++;
+
+ // Count missed words
+ answers.forEach(({ word, correct }) => {
+ if (!correct) {
+ missMap[word] = (missMap[word] || 0) + 1;
+ }
+ });
+
+ // Per-student breakdown
+ const li = document.createElement("li");
+ li.innerHTML = `${username}: ${score}/${answers.length} correct`;
+ breakdown.appendChild(li);
+ }
+
+ const avgScore = sessionCount ? (totalScore / sessionCount).toFixed(2) : "0";
+ let mostMissed = "-", highestMisses = 0;
+ for (const word in missMap) {
+ if (missMap[word] > highestMisses) {
+ highestMisses = missMap[word];
+ mostMissed = word;
+ }
+ }
+
+ summary.innerHTML = `
+ Average Score: ${avgScore}
+ Total Completed Sessions: ${sessionCount}
+ Most Missed Word: ${mostMissed} (${highestMisses} misses)
+ `;
+ } catch (err) {
+ console.error("📉 Failed to refresh analytics:", err);
+ summary.innerHTML = 'Error loading analytics.';
+ }
}
\ No newline at end of file