Remove zpm_test.py from repository
This commit is contained in:
parent
563f47813b
commit
26a726db39
1 changed files with 0 additions and 170 deletions
170
zpm_test.py
170
zpm_test.py
|
|
@ -1,170 +0,0 @@
|
|||
import sqlite3
|
||||
import time
|
||||
import os
|
||||
import sys
|
||||
|
||||
def test_zpm_measurement_and_storage():
|
||||
"""Testet die Messung und Speicherung von Zeichen pro Minute"""
|
||||
|
||||
# Datenbankverbindung herstellen - erstelle Datenbank falls nicht vorhanden
|
||||
db_path = 'typewriter.db'
|
||||
conn = sqlite3.connect(db_path)
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Erstelle die Tabelle falls sie nicht existiert
|
||||
cursor.execute('''
|
||||
CREATE TABLE IF NOT EXISTS lesson_statistic (
|
||||
id INTEGER PRIMARY KEY,
|
||||
lesson_index INTEGER NOT NULL,
|
||||
chars_per_minute FLOAT DEFAULT 0.0,
|
||||
error_rate FLOAT DEFAULT 0.0,
|
||||
wpm FLOAT DEFAULT 0.0,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
)
|
||||
''')
|
||||
conn.commit()
|
||||
|
||||
try:
|
||||
# Prüfe, ob die Tabelle lesson_statistic existiert
|
||||
cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='lesson_statistic'")
|
||||
if not cursor.fetchone():
|
||||
print("Fehler: Tabelle 'lesson_statistic' existiert nicht!")
|
||||
return False
|
||||
|
||||
# Prüfe die Spalten der Tabelle
|
||||
cursor.execute("PRAGMA table_info(lesson_statistic)")
|
||||
columns = [column[1] for column in cursor.fetchall()]
|
||||
expected_columns = ['id', 'lesson_index', 'chars_per_minute', 'error_rate', 'wpm', 'created_at']
|
||||
|
||||
if not all(col in columns for col in expected_columns):
|
||||
print(f"Fehler: Tabelle hat nicht die erwarteten Spalten. Gefunden: {columns}")
|
||||
return False
|
||||
|
||||
print("✓ Datenbankstruktur ist korrekt")
|
||||
|
||||
# Testdaten einfügen
|
||||
test_lesson_index = 0
|
||||
test_chars_per_minute = 150
|
||||
test_error_rate = 5.5
|
||||
test_wpm = 30
|
||||
|
||||
cursor.execute('''
|
||||
INSERT INTO lesson_statistic (lesson_index, chars_per_minute, error_rate, wpm)
|
||||
VALUES (?, ?, ?, ?)
|
||||
''', (test_lesson_index, test_chars_per_minute, test_error_rate, test_wpm))
|
||||
|
||||
conn.commit()
|
||||
print("✓ Testdaten erfolgreich eingefügt")
|
||||
|
||||
# Testdaten auslesen und überprüfen
|
||||
cursor.execute('''
|
||||
SELECT lesson_index, chars_per_minute, error_rate, wpm
|
||||
FROM lesson_statistic
|
||||
WHERE lesson_index = ?
|
||||
ORDER BY created_at DESC
|
||||
LIMIT 1
|
||||
''', (test_lesson_index,))
|
||||
|
||||
result = cursor.fetchone()
|
||||
|
||||
if not result:
|
||||
print("Fehler: Testdaten konnten nicht ausgelesen werden!")
|
||||
return False
|
||||
|
||||
stored_lesson_index, stored_chars_per_minute, stored_error_rate, stored_wpm = result
|
||||
|
||||
# Überprüfe die gespeicherten Werte
|
||||
if (stored_lesson_index == test_lesson_index and
|
||||
stored_chars_per_minute == test_chars_per_minute and
|
||||
stored_error_rate == test_error_rate and
|
||||
stored_wpm == test_wpm):
|
||||
print("✓ Alle Testwerte wurden korrekt gespeichert:")
|
||||
print(f" Lektion: {stored_lesson_index}")
|
||||
print(f" ZPM: {stored_chars_per_minute}")
|
||||
print(f" Fehlerrate: {stored_error_rate}%")
|
||||
print(f" WPM: {stored_wpm}")
|
||||
else:
|
||||
print("Fehler: Gespeicherte Werte stimmen nicht mit Testdaten überein!")
|
||||
print(f" Erwartet: Lektion={test_lesson_index}, ZPM={test_chars_per_minute}, "
|
||||
f"Fehlerrate={test_error_rate}, WPM={test_wpm}")
|
||||
print(f" Gespeichert: Lektion={stored_lesson_index}, ZPM={stored_chars_per_minute}, "
|
||||
f"Fehlerrate={stored_error_rate}, WPM={stored_wpm}")
|
||||
return False
|
||||
|
||||
# Teste die Berechnung von ZPM
|
||||
print("\nTeste ZPM-Berechnung...")
|
||||
|
||||
# Simuliere Tippen: 300 Zeichen in 60 Sekunden = 300 ZPM
|
||||
test_chars = 300
|
||||
test_time_seconds = 60
|
||||
calculated_zpm = (test_chars / test_time_seconds) * 60
|
||||
|
||||
if calculated_zpm == 300:
|
||||
print(f"✓ ZPM-Berechnung korrekt: {calculated_zpm} ZPM")
|
||||
else:
|
||||
print(f"Fehler: ZPM-Berechnung falsch. Erwartet: 300, Berechnet: {calculated_zpm}")
|
||||
return False
|
||||
|
||||
# Teste mehrere Datensätze für Zeitreihen
|
||||
print("\nTeste Zeitreihen-Funktionalität...")
|
||||
|
||||
# Füge mehrere Datensätze für dieselbe Lektion ein
|
||||
test_data_points = [
|
||||
(test_lesson_index, 100, 10.0, 20),
|
||||
(test_lesson_index, 150, 8.0, 25),
|
||||
(test_lesson_index, 200, 5.5, 30)
|
||||
]
|
||||
|
||||
for data_point in test_data_points:
|
||||
cursor.execute('''
|
||||
INSERT INTO lesson_statistic (lesson_index, chars_per_minute, error_rate, wpm)
|
||||
VALUES (?, ?, ?, ?)
|
||||
''', data_point)
|
||||
|
||||
conn.commit()
|
||||
|
||||
# Zähle die Datensätze für diese Lektion
|
||||
cursor.execute('''
|
||||
SELECT COUNT(*) FROM lesson_statistic WHERE lesson_index = ?
|
||||
''', (test_lesson_index,))
|
||||
|
||||
count = cursor.fetchone()[0]
|
||||
print(f"✓ Anzahl der Datensätze für Lektion {test_lesson_index}: {count}")
|
||||
|
||||
# Hole die Zeitreihe
|
||||
cursor.execute('''
|
||||
SELECT chars_per_minute, error_rate, wpm, created_at
|
||||
FROM lesson_statistic
|
||||
WHERE lesson_index = ?
|
||||
ORDER BY created_at ASC
|
||||
''', (test_lesson_index,))
|
||||
|
||||
time_series = cursor.fetchall()
|
||||
print(f"✓ Zeitreihe mit {len(time_series)} Datensätzen abgerufen")
|
||||
|
||||
# Zeige die Entwicklung
|
||||
print(" Entwicklung der ZPM-Werte:")
|
||||
for i, (zpm, error_rate, wpm, created_at) in enumerate(time_series[-5:]): # Letzte 5 Einträge
|
||||
print(f" Punkt {i+1}: ZPM={zpm}, Fehlerrate={error_rate}%, WPM={wpm}")
|
||||
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
print(f"Fehler während des Tests: {e}")
|
||||
return False
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
print("Starte ZPM-Test...")
|
||||
print("=" * 50)
|
||||
|
||||
success = test_zpm_measurement_and_storage()
|
||||
|
||||
print("=" * 50)
|
||||
if success:
|
||||
print("🎉 Alle Tests erfolgreich! ZPM-Messung und -Speicherung funktionieren korrekt.")
|
||||
sys.exit(0)
|
||||
else:
|
||||
print("❌ Tests fehlgeschlagen!")
|
||||
sys.exit(1)
|
||||
Loading…
Add table
Add a link
Reference in a new issue