From 7316238f16655bd127b04476bbf7864b27f940f9 Mon Sep 17 00:00:00 2001 From: Sivaldo Date: Sat, 13 Jun 2026 19:20:23 -0300 Subject: Commit inicial --- static/dashboard.js | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 static/dashboard.js (limited to 'static/dashboard.js') diff --git a/static/dashboard.js b/static/dashboard.js new file mode 100644 index 0000000..c14369f --- /dev/null +++ b/static/dashboard.js @@ -0,0 +1,130 @@ +/** + * Dashboard de Progresso + * Lê dados do localStorage e mostra estatísticas de estudo + */ + +var PROGRESS_PREFIX = window.PROGRESS_PREFIX || 'quiz_progress_'; + +function initDashboard() { + const dashboard = document.getElementById('dashboard-stats'); + if (!dashboard) return; + + const stats = calculateStats(); + renderDashboard(stats); +} + +function calculateStats() { + const allKeys = Object.keys(localStorage); + const progressKeys = allKeys.filter((k) => k.startsWith(PROGRESS_PREFIX)); + + const stats = { + totalQuizzes: progressKeys.length, + totalAcertos: 0, + totalErros: 0, + disciplinas: {}, + }; + + progressKeys.forEach((key) => { + try { + const data = JSON.parse(localStorage.getItem(key)); + if (!data || !data.questions) return; + + const disciplina = key.replace(PROGRESS_PREFIX, '').split('_')[0]; + if (!stats.disciplinas[disciplina]) { + stats.disciplinas[disciplina] = { + acertos: 0, + erros: 0, + total: 0, + }; + } + + stats.disciplinas[disciplina].acertos += data.acertos || 0; + stats.disciplinas[disciplina].erros += data.erros || 0; + stats.disciplinas[disciplina].total += data.questions.length; + + stats.totalAcertos += data.acertos || 0; + stats.totalErros += data.erros || 0; + } catch (e) {} + }); + + return stats; +} + +function renderDashboard(stats) { + const dashboard = document.getElementById('dashboard-stats'); + if (!dashboard) return; + + const totalQuestoes = stats.totalAcertos + stats.totalErros; + const pctGeral = totalQuestoes > 0 ? Math.round((stats.totalAcertos / totalQuestoes) * 100) : 0; + + let html = ` +
+

📊 Seu Progresso de Estudo

+ +
+
+
Quizzes Iniciados
+
${stats.totalQuizzes}
+
+
+
Taxa de Acerto Geral
+
${pctGeral}%
+
+
+
Questões Respondidas
+
${totalQuestoes}
+
+
+ +
+

Por Disciplina

+ `; + + Object.entries(stats.disciplinas).forEach(([disc, data]) => { + const pct = data.total > 0 ? Math.round((data.acertos / data.total) * 100) : 0; + const nivel = pct >= 80 ? '🟢 Dominado' : pct >= 60 ? '🟡 Bom' : '🔴 Revisar'; + + html += ` +
+
${disc}
+
+
+
+
+ ${data.acertos}/${data.total} + ${pct}% + ${nivel} +
+
+ `; + }); + + html += ` +
+
+ +
+
+ `; + + dashboard.innerHTML = html; +} + +function clearAllProgress() { + if (confirm('Tem certeza que quer limpar todo o histórico de progresso?')) { + const allKeys = Object.keys(localStorage); + allKeys.forEach((key) => { + if (key.startsWith(PROGRESS_PREFIX)) { + localStorage.removeItem(key); + } + }); + initDashboard(); + } +} + +// Inicializar quando o DOM estiver pronto +if (document.readyState === 'loading') { + document.addEventListener('DOMContentLoaded', initDashboard); +} else { + initDashboard(); +} -- cgit v1.2.3