Corrections of SQL Alchemy error

This commit is contained in:
2026-01-23 23:13:03 +01:00
parent db6d11cf60
commit 744a84663e

View File

@@ -7,6 +7,7 @@ import os, json
from datetime import datetime, timedelta from datetime import datetime, timedelta
from io import BytesIO from io import BytesIO
from xhtml2pdf import pisa from xhtml2pdf import pisa
from sqlalchemy import text
app = Flask(__name__) app = Flask(__name__)
@@ -61,17 +62,17 @@ def load_user(user_id):
# --- Hilfsfunktionen --- # --- Hilfsfunktionen ---
def get_calculated_schedule(car_num): def get_calculated_schedule(car_num):
config = RaceConfig.query.first() config = RaceConfig.query.first()
stints = Stint.query.filter_by(car_number=car_num).order_by(Stint.order).all() if not config: return []
stints = Stint.query.filter_by(car_number=car_num).order_by(Stint.order).all()
schedule = [] schedule = []
current_time = config.start_time current_time = config.start_time
fuel_capacity = 120.0 # Liter (Beispielhaft fixiert) fuel_capacity = 120.0
for i, stint in enumerate(stints): for i, stint in enumerate(stints):
driver = stint.driver driver = stint.driver
if not driver: continue if not driver: continue
# Vereinfachte Berechnung: Ein Stint ist voll, wenn der Tank leer ist
laps_possible = int(fuel_capacity / driver.cons_per_lap) laps_possible = int(fuel_capacity / driver.cons_per_lap)
duration_sec = laps_possible * driver.avg_lap_time duration_sec = laps_possible * driver.avg_lap_time
@@ -172,11 +173,21 @@ def logout():
if __name__ == '__main__': if __name__ == '__main__':
with app.app_context(): with app.app_context():
db.create_all() db.create_all()
# Initialer User falls nicht vorhanden
# Manueller Fix: Spalte 'theme' hinzufügen, falls sie fehlt (SQLite-spezifisch)
try:
db.session.execute(text("ALTER TABLE user ADD COLUMN theme VARCHAR(20) DEFAULT 'light'"))
db.session.commit()
except Exception:
# Fehler tritt auf, wenn Spalte bereits existiert das ist ok
db.session.rollback()
if not User.query.filter_by(username='mscaltenbach').first(): if not User.query.filter_by(username='mscaltenbach').first():
pw = generate_password_hash('admin123') pw = generate_password_hash('admin123')
db.session.add(User(username='mscaltenbach', password=pw, theme='light')) db.session.add(User(username='mscaltenbach', password=pw, theme='light'))
if not RaceConfig.query.first(): if not RaceConfig.query.first():
db.session.add(RaceConfig()) db.session.add(RaceConfig())
db.session.commit() db.session.commit()
app.run(host='0.0.0.0', port=5000, debug=True) app.run(host='0.0.0.0', port=5000, debug=True)