Spaces:
Running
Running
Download progress-store.js from matt-ritchey/math4: direct link, hf CLI and curl.
- Browser
- Download file 1.84 kB
-
https://huggingface.co/spaces/matt-ritchey/math4/resolve/main/progress-store.js
- Command line
-
hf download hf://spaces/matt-ritchey/math4/progress-store.js
-
curl -L -o progress-store.js https://huggingface.co/spaces/matt-ritchey/math4/resolve/main/progress-store.js
1.84 kB
| const ProgressStore = { | |
| _key: 'math4-progress', | |
| _defaults() { | |
| return { | |
| points: 0, | |
| streak: 0, | |
| bestStreak: 0, | |
| totalCorrect: 0, | |
| totalAttempted: 0, | |
| topicStats: {}, | |
| quizHistory: [] | |
| }; | |
| }, | |
| load() { | |
| try { | |
| const raw = localStorage.getItem(this._key); | |
| if (raw) { | |
| const data = JSON.parse(raw); | |
| return { ...this._defaults(), ...data }; | |
| } | |
| } catch (e) {} | |
| return this._defaults(); | |
| }, | |
| save(data) { | |
| try { | |
| localStorage.setItem(this._key, JSON.stringify(data)); | |
| } catch (e) {} | |
| }, | |
| getTopicStats(topic) { | |
| const data = this.load(); | |
| if (!data.topicStats[topic]) { | |
| data.topicStats[topic] = { correct: 0, attempted: 0 }; | |
| } | |
| return data.topicStats[topic]; | |
| }, | |
| recordAnswer(topic, correct) { | |
| const data = this.load(); | |
| if (!data.topicStats[topic]) { | |
| data.topicStats[topic] = { correct: 0, attempted: 0 }; | |
| } | |
| data.topicStats[topic].attempted++; | |
| data.totalAttempted++; | |
| if (correct) { | |
| data.topicStats[topic].correct++; | |
| data.totalCorrect++; | |
| data.streak++; | |
| if (data.streak > data.bestStreak) data.bestStreak = data.streak; | |
| data.points += 10; | |
| } else { | |
| data.streak = 0; | |
| } | |
| this.save(data); | |
| return data; | |
| }, | |
| recordQuiz(topic, score, total, difficulty) { | |
| const data = this.load(); | |
| data.quizHistory.push({ | |
| topic, | |
| score, | |
| total, | |
| difficulty, | |
| date: new Date().toISOString() | |
| }); | |
| if (data.quizHistory.length > 50) data.quizHistory.shift(); | |
| const pct = score / total; | |
| if (pct >= 1) data.points += 50; | |
| else if (pct >= 0.8) data.points += 30; | |
| else if (pct >= 0.6) data.points += 15; | |
| this.save(data); | |
| return data; | |
| }, | |
| reset() { | |
| localStorage.removeItem(this._key); | |
| } | |
| }; | |