Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions dashboardProgress.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
*/

(function () {
/**
* Progress Analytics Dashboard (extended)
* - Rolling average score + best score (from attempts history)
* - Mastery per category (subject)
* - Time spent per quiz (from attempts history)
* - Filters: date range + subject
*/
function pct(n) {
if (typeof n !== "number" || Number.isNaN(n)) return "—";
return `${Math.round(n * 100)}%`;
Expand Down
30 changes: 28 additions & 2 deletions progress.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,30 @@ const STATE_COLORS = {
};

const STORAGE_KEY = "learnsphere_progress";
// XP system constants
const XP_PER_LEVEL = 1000; // XP required per level
const REVIEW_SCHEDULE_KEY = "learnsphere_review_schedule_v1";

// ── Storage Helpers ───────────────────────────────────────────────────────────

function loadProgress() {
try {
return JSON.parse(localStorage.getItem(STORAGE_KEY)) || {};
const data = JSON.parse(localStorage.getItem(STORAGE_KEY)) || {};
// Ensure XP and level fields exist
if (typeof data.xp !== "number") data.xp = 0;
if (typeof data.level !== "number") data.level = 0;
return data;
} catch {
return {};
return { xp: 0, level: 0 };
}
}

// Helper to calculate level from XP
function calculateLevel(xp) {
if (typeof xp !== "number" || xp < 0) return 0;
return Math.floor(xp / XP_PER_LEVEL);
}

function loadReviewSchedule() {
try {
return JSON.parse(localStorage.getItem(REVIEW_SCHEDULE_KEY)) || {};
Expand All @@ -71,6 +83,9 @@ function saveReviewSchedule(scheduleMap) {

function saveProgress(progressMap) {
try {
// Ensure XP and level are persisted
if (typeof progressMap.xp !== "number") progressMap.xp = 0;
if (typeof progressMap.level !== "number") progressMap.level = 0;
localStorage.setItem(STORAGE_KEY, JSON.stringify(progressMap));
} catch (e) {
console.warn("LearnSphere: Could not save progress to localStorage.", e);
Expand Down Expand Up @@ -281,6 +296,17 @@ function updateProgressSummary() {

window.studyProgress = {
STREAK_KEY: "learnsphere_streak_state_v1",
// XP related helpers
addXP(amount) {
const progress = loadProgress();
const inc = Number(amount) || 0;
progress.xp = (progress.xp || 0) + inc;
progress.level = calculateLevel(progress.xp);
saveProgress(progress);
},
getXP() { return (loadProgress().xp) || 0; },
getLevel() { return (loadProgress().level) || 0; },
XP_PER_LEVEL,

loadStreakState() {
try {
Expand Down
37 changes: 37 additions & 0 deletions quiz/bank/physics-motion.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[
{
"category": "General",
"difficulty": "easy",
"question": "What is the SI unit of speed?",
"options": ["m/s", "km/h", "m/s²", "N"],
"answer": "m/s"
},
{
"category": "General",
"difficulty": "easy",
"question": "What causes an object to accelerate?",
"options": ["Mass", "Force", "Friction", "Temperature"],
"answer": "Force"
},
{
"category": "General",
"difficulty": "medium",
"question": "Which of these is a scalar quantity?",
"options": ["Velocity", "Acceleration", "Displacement", "Speed"],
"answer": "Speed"
},
{
"category": "General",
"difficulty": "medium",
"question": "What does Newton's First Law state?",
"options": ["F = ma", "Action = Reaction", "Objects stay in motion/rest unless acted on", "Momentum is conserved"],
"answer": "Objects stay in motion/rest unless acted on"
},
{
"category": "General",
"difficulty": "hard",
"question": "What is the formula for acceleration?",
"options": ["v/t", "d/t", "Δv/t", "F/m"],
"answer": "Δv/t"
}
]
8 changes: 8 additions & 0 deletions quizProgress.js
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,13 @@ function _updateUnifiedStreakAndGoal(type, value = 1) {
}
}

function getAttemptsHistory() {
const state = _loadState();
const attempts = Array.isArray(state?.attempts) ? state.attempts : [];
// Return a copy to avoid accidental mutation
return attempts.slice();
}

window.quizProgress = {
QUIZ_TOPICS,
SKILL_TAXONOMY,
Expand All @@ -674,6 +681,7 @@ window.quizProgress = {
getWeakestSkills,
getQuestionWeaknessWeight,
recordRetryAttempt,
getAttemptsHistory,
};


Expand Down
Loading
Loading