🎉 Improved session management system and logs organization 🎨
This commit is contained in:
@@ -1082,6 +1082,67 @@ def api_version():
|
||||
"environment": get_environment_type()
|
||||
})
|
||||
|
||||
@app.route("/api/stats", methods=['GET'])
|
||||
@login_required
|
||||
def api_stats():
|
||||
"""
|
||||
Allgemeine System-Statistiken API-Endpunkt.
|
||||
|
||||
Stellt grundlegende Statistiken über das System zur Verfügung.
|
||||
"""
|
||||
try:
|
||||
from models import get_db_session, User, Printer, Job
|
||||
|
||||
with get_cached_session() as db_session:
|
||||
# Grundlegende Counts
|
||||
total_users = db_session.query(User).count()
|
||||
total_printers = db_session.query(Printer).count()
|
||||
total_jobs = db_session.query(Job).count()
|
||||
|
||||
# Aktive Jobs
|
||||
active_jobs = db_session.query(Job).filter(
|
||||
Job.status.in_(['pending', 'printing', 'paused'])
|
||||
).count()
|
||||
|
||||
# Abgeschlossene Jobs heute
|
||||
from datetime import date
|
||||
today = date.today()
|
||||
completed_today = db_session.query(Job).filter(
|
||||
Job.status == 'completed',
|
||||
Job.updated_at >= today
|
||||
).count()
|
||||
|
||||
# Online-Drucker (aktive Drucker)
|
||||
online_printers = db_session.query(Printer).filter(
|
||||
Printer.active == True
|
||||
).count()
|
||||
|
||||
stats = {
|
||||
'total_users': total_users,
|
||||
'total_printers': total_printers,
|
||||
'total_jobs': total_jobs,
|
||||
'active_jobs': active_jobs,
|
||||
'completed_today': completed_today,
|
||||
'online_printers': online_printers,
|
||||
'timestamp': datetime.now().isoformat()
|
||||
}
|
||||
|
||||
app_logger.info(f"✅ API-Statistiken abgerufen von {current_user.username}")
|
||||
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'stats': stats,
|
||||
'message': 'Statistiken erfolgreich geladen'
|
||||
})
|
||||
|
||||
except Exception as e:
|
||||
app_logger.error(f"❌ Fehler beim Abrufen der API-Statistiken: {str(e)}")
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'error': 'Fehler beim Laden der Statistiken',
|
||||
'details': str(e)
|
||||
}), 500
|
||||
|
||||
# Statische Seiten
|
||||
@app.route("/privacy")
|
||||
def privacy():
|
||||
|
Reference in New Issue
Block a user