-m Statistik über Lektionen wird gespeichert"
This commit is contained in:
parent
cbe8d4a670
commit
884867ad09
4 changed files with 90 additions and 18 deletions
32
app.py
32
app.py
|
|
@ -2,7 +2,7 @@ import os
|
|||
import json
|
||||
import re
|
||||
from flask import Flask, render_template, request, jsonify
|
||||
from models import db, Progress, Statistic
|
||||
from models import db, Progress, Statistic, LessonStatistic
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///typewriter.db'
|
||||
|
|
@ -464,6 +464,36 @@ def set_lesson():
|
|||
print(f"Fehler in set_lesson: {e}")
|
||||
return jsonify({'error': 'Interner Serverfehler'}), 500
|
||||
|
||||
@app.route('/save_lesson_statistics', methods=['POST'])
|
||||
def save_lesson_statistics():
|
||||
"""Speichert die Statistiken für eine abgeschlossene Lektion"""
|
||||
try:
|
||||
data = request.get_json()
|
||||
lesson_index = data.get('lesson_index')
|
||||
chars_per_second = data.get('chars_per_second')
|
||||
error_rate = data.get('error_rate')
|
||||
wpm = data.get('wpm')
|
||||
|
||||
if lesson_index is None:
|
||||
return jsonify({'error': 'Lektionsindex fehlt'}), 400
|
||||
|
||||
# Neue Statistik für die Lektion erstellen
|
||||
lesson_stat = LessonStatistic(
|
||||
lesson_index=lesson_index,
|
||||
chars_per_second=chars_per_second,
|
||||
error_rate=error_rate,
|
||||
wpm=wpm
|
||||
)
|
||||
|
||||
db.session.add(lesson_stat)
|
||||
db.session.commit()
|
||||
|
||||
return jsonify({'status': 'success', 'message': 'Lektionsstatistiken gespeichert'})
|
||||
|
||||
except Exception as e:
|
||||
print(f"Fehler in save_lesson_statistics: {e}")
|
||||
return jsonify({'error': 'Interner Serverfehler'}), 500
|
||||
|
||||
@app.route('/end_session', methods=['POST'])
|
||||
def end_session():
|
||||
"""Beendet eine Tipp-Session und speichert Statistiken"""
|
||||
|
|
|
|||
|
|
@ -18,3 +18,11 @@ class Statistic(db.Model):
|
|||
duration_per_char = db.Column(db.Float, default=0.0)
|
||||
accuracy = db.Column(db.Float, default=0.0)
|
||||
wpm = db.Column(db.Float, default=0.0)
|
||||
|
||||
class LessonStatistic(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
lesson_index = db.Column(db.Integer, nullable=False)
|
||||
chars_per_second = db.Column(db.Float, default=0.0)
|
||||
error_rate = db.Column(db.Float, default=0.0)
|
||||
wpm = db.Column(db.Float, default=0.0)
|
||||
created_at = db.Column(db.DateTime, default=db.func.now())
|
||||
|
|
|
|||
|
|
@ -88,11 +88,41 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||
currentLineIndex++;
|
||||
updateLineDisplay();
|
||||
} else {
|
||||
// Letzte Zeile abgeschlossen
|
||||
// Letzte Zeile abgeschlossen - Lektion beendet
|
||||
completedLines.push(currentLineInput);
|
||||
currentLineInput = '';
|
||||
this.value = '';
|
||||
alert('Lektion beendet!');
|
||||
|
||||
// Speichere die Statistiken für diese Lektion
|
||||
const lessonIndex = window.currentLessonIndex;
|
||||
const charsPerSecond = parseFloat(speedElement.textContent);
|
||||
const errorRate = parseFloat(errorRateElement.textContent);
|
||||
const wpm = parseFloat(wpmElement.textContent);
|
||||
|
||||
fetch('/save_lesson_statistics', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
lesson_index: lessonIndex,
|
||||
chars_per_second: charsPerSecond,
|
||||
error_rate: errorRate,
|
||||
wpm: wpm
|
||||
})
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.status === 'success') {
|
||||
alert('Lektion beendet! Statistiken wurden gespeichert.');
|
||||
} else {
|
||||
alert('Lektion beendet, aber Statistiken konnten nicht gespeichert werden.');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Fehler beim Speichern der Statistiken:', error);
|
||||
alert('Lektion beendet! (Fehler beim Speichern der Statistiken)');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -63,30 +63,8 @@
|
|||
></textarea>
|
||||
</div>
|
||||
|
||||
<!-- Statistik -->
|
||||
<!-- Fortschritt -->
|
||||
<div class="row mb-4">
|
||||
<div class="col-md-6">
|
||||
<div class="card bg-light">
|
||||
<div class="card-body">
|
||||
<h6 class="card-title">Statistik</h6>
|
||||
<ul class="list-group list-group-flush">
|
||||
<li class="list-group-item d-flex justify-content-between align-items-center">
|
||||
Zeichen pro Sekunde
|
||||
<span id="speed" class="badge bg-primary rounded-pill">0</span>
|
||||
</li>
|
||||
<li class="list-group-item d-flex justify-content-between align-items-center">
|
||||
Fehler in %
|
||||
<span id="error-rate" class="badge bg-danger rounded-pill">0</span>
|
||||
</li>
|
||||
<li class="list-group-item d-flex justify-content-between align-items-center">
|
||||
Wörter pro Minute (WPM)
|
||||
<span id="wpm" class="badge bg-info rounded-pill">0</span>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-6">
|
||||
<div class="card bg-light">
|
||||
<div class="card-body">
|
||||
|
|
@ -108,6 +86,28 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-6">
|
||||
<div class="card bg-light">
|
||||
<div class="card-body">
|
||||
<h6 class="card-title">Statistik</h6>
|
||||
<ul class="list-group list-group-flush">
|
||||
<li class="list-group-item d-flex justify-content-between align-items-center">
|
||||
Zeichen pro Sekunde
|
||||
<span id="speed" class="badge bg-primary rounded-pill">0</span>
|
||||
</li>
|
||||
<li class="list-group-item d-flex justify-content-between align-items-center">
|
||||
Fehler in %
|
||||
<span id="error-rate" class="badge bg-danger rounded-pill">0</span>
|
||||
</li>
|
||||
<li class="list-group-item d-flex justify-content-between align-items-center">
|
||||
Wörter pro Minute (WPM)
|
||||
<span id="wpm" class="badge bg-info rounded-pill">0</span>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Lektionen -->
|
||||
|
|
@ -144,6 +144,10 @@
|
|||
<!-- Bootstrap JS und Font Awesome -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="https://kit.fontawesome.com/a076d05399.js" crossorigin="anonymous"></script>
|
||||
<script>
|
||||
// Übergib die aktuelle Lektionsnummer an JavaScript
|
||||
window.currentLessonIndex = {{ current_lesson_index }};
|
||||
</script>
|
||||
<script src="{{ url_for('static', filename='js/script.js') }}"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue