chore: Änderungen commited
This commit is contained in:
520
app.py
520
app.py
@@ -2476,211 +2476,343 @@ def get_mindmap_data(node_id):
|
||||
"""
|
||||
Stellt Mindmap-Daten für das Frontend bereit.
|
||||
Liefert für 'root' die Hauptebene und für andere Node-IDs die entsprechenden Unterknoten.
|
||||
Daten werden aus der Datenbank abgerufen.
|
||||
"""
|
||||
app.logger.info(f"Mindmap-Daten werden für Node '{node_id}' angefordert.")
|
||||
|
||||
try:
|
||||
# Fallback-Daten falls Datenbankzugriff fehlschlägt
|
||||
fallback_data = get_fallback_mindmap_data(node_id)
|
||||
|
||||
if node_id == 'root':
|
||||
# Hauptebene der Mindmap
|
||||
nodes = [
|
||||
{
|
||||
"id": "center",
|
||||
"name": "Wissenskarte",
|
||||
"description": "Zentrale Wissenskarte mit allen Hauptthemen",
|
||||
"is_center": True,
|
||||
"color_code": "#f5f5f5",
|
||||
"has_children": True
|
||||
},
|
||||
{
|
||||
"id": "philosophy",
|
||||
"name": "Philosophie",
|
||||
"description": "Die Lehre vom Denken und der Erkenntnis",
|
||||
"category": "Philosophie",
|
||||
"has_children": True,
|
||||
"color_code": "#9F7AEA"
|
||||
},
|
||||
{
|
||||
"id": "science",
|
||||
"name": "Wissenschaft",
|
||||
"description": "Systematische Erforschung der Natur und Gesellschaft",
|
||||
"category": "Wissenschaft",
|
||||
"has_children": True,
|
||||
"color_code": "#f4b400"
|
||||
},
|
||||
{
|
||||
"id": "technology",
|
||||
"name": "Technologie",
|
||||
"description": "Anwendung wissenschaftlicher Erkenntnisse",
|
||||
"category": "Technologie",
|
||||
"has_children": True,
|
||||
"color_code": "#0d47a1"
|
||||
},
|
||||
{
|
||||
"id": "arts",
|
||||
"name": "Künste",
|
||||
"description": "Kreativer Ausdruck und künstlerische Gestaltung",
|
||||
"category": "Künste",
|
||||
"has_children": True,
|
||||
"color_code": "#c2185b"
|
||||
}
|
||||
]
|
||||
# Hauptebene der Mindmap - finde den "Wissen"-Knoten und seine Verbindungen
|
||||
wissen_node = MindMapNode.query.filter_by(name="Wissen").first()
|
||||
|
||||
edges = [
|
||||
{"source_id": "center", "target_id": "philosophy", "strength": 0.9},
|
||||
{"source_id": "center", "target_id": "science", "strength": 0.9},
|
||||
{"source_id": "center", "target_id": "technology", "strength": 0.9},
|
||||
{"source_id": "center", "target_id": "arts", "strength": 0.9}
|
||||
]
|
||||
if not wissen_node:
|
||||
app.logger.warning("'Wissen'-Knoten nicht in der Datenbank gefunden, Fallback zu Hardcoded-Daten.")
|
||||
return jsonify(fallback_data)
|
||||
|
||||
elif node_id == 'philosophy':
|
||||
nodes = [
|
||||
{
|
||||
"id": "epistemology",
|
||||
"name": "Erkenntnistheorie",
|
||||
"description": "Untersuchung der Natur und Grenzen menschlicher Erkenntnis",
|
||||
"category": "Philosophie",
|
||||
"has_children": True,
|
||||
"color_code": "#9F7AEA"
|
||||
},
|
||||
{
|
||||
"id": "ethics",
|
||||
"name": "Ethik",
|
||||
"description": "Lehre vom moralisch richtigen Handeln",
|
||||
"category": "Philosophie",
|
||||
"has_children": True,
|
||||
"color_code": "#9F7AEA"
|
||||
},
|
||||
{
|
||||
"id": "metaphysics",
|
||||
"name": "Metaphysik",
|
||||
"description": "Grundfragen des Seins und der Wirklichkeit",
|
||||
"category": "Philosophie",
|
||||
"has_children": True,
|
||||
"color_code": "#9F7AEA"
|
||||
}
|
||||
]
|
||||
# Zentrum der Mindmap ist der "Wissen"-Knoten
|
||||
nodes = [{
|
||||
"id": str(wissen_node.id),
|
||||
"name": "Wissenskarte", # Frontend-Name für Root-Knoten
|
||||
"description": wissen_node.description or "Zentrale Wissenskarte mit allen Hauptthemen",
|
||||
"is_center": True,
|
||||
"color_code": "#f5f5f5",
|
||||
"has_children": True
|
||||
}]
|
||||
|
||||
edges = [
|
||||
{"source_id": "philosophy", "target_id": "epistemology", "strength": 0.8},
|
||||
{"source_id": "philosophy", "target_id": "ethics", "strength": 0.8},
|
||||
{"source_id": "philosophy", "target_id": "metaphysics", "strength": 0.8}
|
||||
]
|
||||
|
||||
elif node_id == 'science':
|
||||
nodes = [
|
||||
{
|
||||
"id": "physics",
|
||||
"name": "Physik",
|
||||
"description": "Lehre von der Materie und ihren Wechselwirkungen",
|
||||
"category": "Wissenschaft",
|
||||
"has_children": True,
|
||||
"color_code": "#f4b400"
|
||||
},
|
||||
{
|
||||
"id": "biology",
|
||||
"name": "Biologie",
|
||||
"description": "Lehre von den Lebewesen und ihren Lebensprozessen",
|
||||
"category": "Wissenschaft",
|
||||
"has_children": True,
|
||||
"color_code": "#f4b400"
|
||||
},
|
||||
{
|
||||
"id": "chemistry",
|
||||
"name": "Chemie",
|
||||
"description": "Wissenschaft von den Stoffen und ihren Reaktionen",
|
||||
"category": "Wissenschaft",
|
||||
"has_children": True,
|
||||
"color_code": "#f4b400"
|
||||
}
|
||||
]
|
||||
|
||||
edges = [
|
||||
{"source_id": "science", "target_id": "physics", "strength": 0.8},
|
||||
{"source_id": "science", "target_id": "biology", "strength": 0.8},
|
||||
{"source_id": "science", "target_id": "chemistry", "strength": 0.8}
|
||||
]
|
||||
|
||||
elif node_id == 'technology':
|
||||
nodes = [
|
||||
{
|
||||
"id": "ai",
|
||||
"name": "Künstliche Intelligenz",
|
||||
"description": "Maschinelles Lernen und intelligente Systeme",
|
||||
"category": "Technologie",
|
||||
"has_children": True,
|
||||
"color_code": "#0d47a1"
|
||||
},
|
||||
{
|
||||
"id": "robotics",
|
||||
"name": "Robotik",
|
||||
"description": "Entwicklung und Steuerung von Robotern",
|
||||
"category": "Technologie",
|
||||
"has_children": True,
|
||||
"color_code": "#0d47a1"
|
||||
},
|
||||
{
|
||||
"id": "quantum_computing",
|
||||
"name": "Quantencomputing",
|
||||
"description": "Computer basierend auf Quantenmechanik",
|
||||
"category": "Technologie",
|
||||
"has_children": True,
|
||||
"color_code": "#0d47a1"
|
||||
}
|
||||
]
|
||||
|
||||
edges = [
|
||||
{"source_id": "technology", "target_id": "ai", "strength": 0.8},
|
||||
{"source_id": "technology", "target_id": "robotics", "strength": 0.8},
|
||||
{"source_id": "technology", "target_id": "quantum_computing", "strength": 0.8}
|
||||
]
|
||||
|
||||
elif node_id == 'arts':
|
||||
nodes = [
|
||||
{
|
||||
"id": "visual_arts",
|
||||
"name": "Bildende Kunst",
|
||||
"description": "Malerei, Bildhauerei und andere visuelle Kunstformen",
|
||||
"category": "Künste",
|
||||
"has_children": True,
|
||||
"color_code": "#c2185b"
|
||||
},
|
||||
{
|
||||
"id": "music",
|
||||
"name": "Musik",
|
||||
"description": "Tonkunst und musikalische Komposition",
|
||||
"category": "Künste",
|
||||
"has_children": True,
|
||||
"color_code": "#c2185b"
|
||||
},
|
||||
{
|
||||
"id": "literature",
|
||||
"name": "Literatur",
|
||||
"description": "Schriftliche Kunstwerke und Poesie",
|
||||
"category": "Künste",
|
||||
"has_children": True,
|
||||
"color_code": "#c2185b"
|
||||
}
|
||||
]
|
||||
|
||||
edges = [
|
||||
{"source_id": "arts", "target_id": "visual_arts", "strength": 0.8},
|
||||
{"source_id": "arts", "target_id": "music", "strength": 0.8},
|
||||
{"source_id": "arts", "target_id": "literature", "strength": 0.8}
|
||||
]
|
||||
|
||||
else:
|
||||
# Für jede andere Node-ID geben wir eine leere Struktur zurück
|
||||
nodes = []
|
||||
# Hauptkategorien als Knoten
|
||||
main_categories = Category.query.filter_by(parent_id=None).all()
|
||||
category_nodes = []
|
||||
edges = []
|
||||
|
||||
for category in main_categories:
|
||||
category_node = {
|
||||
"id": f"cat_{category.id}",
|
||||
"name": category.name,
|
||||
"description": category.description or f"Kategorie: {category.name}",
|
||||
"category": category.name,
|
||||
"has_children": True,
|
||||
"color_code": category.color_code or "#9F7AEA"
|
||||
}
|
||||
category_nodes.append(category_node)
|
||||
|
||||
# Verbindung vom Wissen-Knoten zur Kategorie
|
||||
edges.append({
|
||||
"source_id": str(wissen_node.id),
|
||||
"target_id": f"cat_{category.id}",
|
||||
"strength": 0.9
|
||||
})
|
||||
|
||||
nodes.extend(category_nodes)
|
||||
|
||||
response = {
|
||||
"nodes": nodes,
|
||||
"edges": edges
|
||||
}
|
||||
|
||||
app.logger.info(f"Mindmap-Daten für 'root' erfolgreich aus Datenbank geladen. {len(nodes)} Knoten gefunden.")
|
||||
return jsonify(response)
|
||||
|
||||
elif node_id.startswith('cat_'):
|
||||
# Unterkategorien einer Hauptkategorie anzeigen
|
||||
category_id = node_id.replace('cat_', '')
|
||||
try:
|
||||
category_id = int(category_id)
|
||||
category = Category.query.get(category_id)
|
||||
|
||||
if not category:
|
||||
app.logger.warning(f"Kategorie mit ID {category_id} nicht gefunden.")
|
||||
return jsonify(fallback_data)
|
||||
|
||||
nodes = []
|
||||
edges = []
|
||||
|
||||
# Unterkategorien dieser Kategorie
|
||||
subcategories = Category.query.filter_by(parent_id=category_id).all()
|
||||
|
||||
for subcat in subcategories:
|
||||
subcat_node = {
|
||||
"id": f"subcat_{subcat.id}",
|
||||
"name": subcat.name,
|
||||
"description": subcat.description or f"Unterkategorie: {subcat.name}",
|
||||
"category": category.name,
|
||||
"has_children": True,
|
||||
"color_code": subcat.color_code or category.color_code
|
||||
}
|
||||
nodes.append(subcat_node)
|
||||
|
||||
# Verbindung von der Hauptkategorie zur Unterkategorie
|
||||
edges.append({
|
||||
"source_id": node_id,
|
||||
"target_id": f"subcat_{subcat.id}",
|
||||
"strength": 0.8
|
||||
})
|
||||
|
||||
# Wenn es keine Unterkategorien gibt, zeige verwandte Knoten
|
||||
if not subcategories:
|
||||
# Im Fallback-Modus zurückfallen
|
||||
app.logger.info(f"Keine Unterkategorien für Kategorie {category.name} gefunden, verwende Fallback-Daten.")
|
||||
return jsonify(fallback_data)
|
||||
|
||||
response = {
|
||||
"nodes": nodes,
|
||||
"edges": edges
|
||||
}
|
||||
|
||||
return jsonify(response)
|
||||
|
||||
except (ValueError, TypeError):
|
||||
app.logger.error(f"Ungültige Kategorie-ID: {category_id}")
|
||||
return jsonify(fallback_data)
|
||||
|
||||
# Antwort zusammenstellen
|
||||
response = {
|
||||
"nodes": nodes,
|
||||
"edges": edges
|
||||
}
|
||||
else:
|
||||
# Versuche, einen MindMapNode mit der gegebenen ID zu finden
|
||||
try:
|
||||
node_id_int = int(node_id)
|
||||
node = MindMapNode.query.get(node_id_int)
|
||||
|
||||
if node:
|
||||
# Zeige Gedanken oder verwandte Knoten
|
||||
# Hier würden wir verwandte Knoten aus der Datenbank laden
|
||||
# Für den Moment verwenden wir Fallback-Daten
|
||||
app.logger.info(f"Knoten {node.name} gefunden, aber keine spezifische Verarbeitung implementiert.")
|
||||
return jsonify(fallback_data)
|
||||
|
||||
except (ValueError, TypeError):
|
||||
# Wenn die ID kein Integer ist, verwende das bisherige Verhalten
|
||||
app.logger.info(f"Falle auf bisheriges Verhalten für Node ID '{node_id}' zurück.")
|
||||
return jsonify(fallback_data)
|
||||
|
||||
return jsonify(response)
|
||||
# Wenn wir hier ankommen, gibt es keine spezifische Verarbeitung für diese node_id
|
||||
return jsonify(fallback_data)
|
||||
|
||||
except Exception as e:
|
||||
app.logger.error(f"Fehler beim Abrufen der Mindmap-Daten: {str(e)}")
|
||||
return jsonify({"error": "Fehler beim Abrufen der Mindmap-Daten"}), 500
|
||||
app.logger.error(f"Stack Trace: {traceback.format_exc()}")
|
||||
return jsonify({"error": "Fehler beim Abrufen der Mindmap-Daten"}), 500
|
||||
|
||||
|
||||
def get_fallback_mindmap_data(node_id):
|
||||
"""
|
||||
Liefert Fallback-Daten für die Mindmap, wenn die Datenbank nicht verfügbar ist.
|
||||
"""
|
||||
if node_id == 'root':
|
||||
# Hauptebene der Mindmap
|
||||
nodes = [
|
||||
{
|
||||
"id": "center",
|
||||
"name": "Wissenskarte",
|
||||
"description": "Zentrale Wissenskarte mit allen Hauptthemen",
|
||||
"is_center": True,
|
||||
"color_code": "#f5f5f5",
|
||||
"has_children": True
|
||||
},
|
||||
{
|
||||
"id": "philosophy",
|
||||
"name": "Philosophie",
|
||||
"description": "Die Lehre vom Denken und der Erkenntnis",
|
||||
"category": "Philosophie",
|
||||
"has_children": True,
|
||||
"color_code": "#9F7AEA"
|
||||
},
|
||||
{
|
||||
"id": "science",
|
||||
"name": "Wissenschaft",
|
||||
"description": "Systematische Erforschung der Natur und Gesellschaft",
|
||||
"category": "Wissenschaft",
|
||||
"has_children": True,
|
||||
"color_code": "#f4b400"
|
||||
},
|
||||
{
|
||||
"id": "technology",
|
||||
"name": "Technologie",
|
||||
"description": "Anwendung wissenschaftlicher Erkenntnisse",
|
||||
"category": "Technologie",
|
||||
"has_children": True,
|
||||
"color_code": "#0d47a1"
|
||||
},
|
||||
{
|
||||
"id": "arts",
|
||||
"name": "Künste",
|
||||
"description": "Kreativer Ausdruck und künstlerische Gestaltung",
|
||||
"category": "Künste",
|
||||
"has_children": True,
|
||||
"color_code": "#c2185b"
|
||||
}
|
||||
]
|
||||
|
||||
edges = [
|
||||
{"source_id": "center", "target_id": "philosophy", "strength": 0.9},
|
||||
{"source_id": "center", "target_id": "science", "strength": 0.9},
|
||||
{"source_id": "center", "target_id": "technology", "strength": 0.9},
|
||||
{"source_id": "center", "target_id": "arts", "strength": 0.9}
|
||||
]
|
||||
|
||||
elif node_id == 'philosophy':
|
||||
nodes = [
|
||||
{
|
||||
"id": "epistemology",
|
||||
"name": "Erkenntnistheorie",
|
||||
"description": "Untersuchung der Natur und Grenzen menschlicher Erkenntnis",
|
||||
"category": "Philosophie",
|
||||
"has_children": True,
|
||||
"color_code": "#9F7AEA"
|
||||
},
|
||||
{
|
||||
"id": "ethics",
|
||||
"name": "Ethik",
|
||||
"description": "Lehre vom moralisch richtigen Handeln",
|
||||
"category": "Philosophie",
|
||||
"has_children": True,
|
||||
"color_code": "#9F7AEA"
|
||||
},
|
||||
{
|
||||
"id": "metaphysics",
|
||||
"name": "Metaphysik",
|
||||
"description": "Grundfragen des Seins und der Wirklichkeit",
|
||||
"category": "Philosophie",
|
||||
"has_children": True,
|
||||
"color_code": "#9F7AEA"
|
||||
}
|
||||
]
|
||||
|
||||
edges = [
|
||||
{"source_id": "philosophy", "target_id": "epistemology", "strength": 0.8},
|
||||
{"source_id": "philosophy", "target_id": "ethics", "strength": 0.8},
|
||||
{"source_id": "philosophy", "target_id": "metaphysics", "strength": 0.8}
|
||||
]
|
||||
|
||||
elif node_id == 'science':
|
||||
nodes = [
|
||||
{
|
||||
"id": "physics",
|
||||
"name": "Physik",
|
||||
"description": "Lehre von der Materie und ihren Wechselwirkungen",
|
||||
"category": "Wissenschaft",
|
||||
"has_children": True,
|
||||
"color_code": "#f4b400"
|
||||
},
|
||||
{
|
||||
"id": "biology",
|
||||
"name": "Biologie",
|
||||
"description": "Lehre von den Lebewesen und ihren Lebensprozessen",
|
||||
"category": "Wissenschaft",
|
||||
"has_children": True,
|
||||
"color_code": "#f4b400"
|
||||
},
|
||||
{
|
||||
"id": "chemistry",
|
||||
"name": "Chemie",
|
||||
"description": "Wissenschaft von den Stoffen und ihren Reaktionen",
|
||||
"category": "Wissenschaft",
|
||||
"has_children": True,
|
||||
"color_code": "#f4b400"
|
||||
}
|
||||
]
|
||||
|
||||
edges = [
|
||||
{"source_id": "science", "target_id": "physics", "strength": 0.8},
|
||||
{"source_id": "science", "target_id": "biology", "strength": 0.8},
|
||||
{"source_id": "science", "target_id": "chemistry", "strength": 0.8}
|
||||
]
|
||||
|
||||
elif node_id == 'technology':
|
||||
nodes = [
|
||||
{
|
||||
"id": "ai",
|
||||
"name": "Künstliche Intelligenz",
|
||||
"description": "Maschinelles Lernen und intelligente Systeme",
|
||||
"category": "Technologie",
|
||||
"has_children": True,
|
||||
"color_code": "#0d47a1"
|
||||
},
|
||||
{
|
||||
"id": "robotics",
|
||||
"name": "Robotik",
|
||||
"description": "Entwicklung und Steuerung von Robotern",
|
||||
"category": "Technologie",
|
||||
"has_children": True,
|
||||
"color_code": "#0d47a1"
|
||||
},
|
||||
{
|
||||
"id": "quantum_computing",
|
||||
"name": "Quantencomputing",
|
||||
"description": "Computer basierend auf Quantenmechanik",
|
||||
"category": "Technologie",
|
||||
"has_children": True,
|
||||
"color_code": "#0d47a1"
|
||||
}
|
||||
]
|
||||
|
||||
edges = [
|
||||
{"source_id": "technology", "target_id": "ai", "strength": 0.8},
|
||||
{"source_id": "technology", "target_id": "robotics", "strength": 0.8},
|
||||
{"source_id": "technology", "target_id": "quantum_computing", "strength": 0.8}
|
||||
]
|
||||
|
||||
elif node_id == 'arts':
|
||||
nodes = [
|
||||
{
|
||||
"id": "visual_arts",
|
||||
"name": "Bildende Kunst",
|
||||
"description": "Malerei, Bildhauerei und andere visuelle Kunstformen",
|
||||
"category": "Künste",
|
||||
"has_children": True,
|
||||
"color_code": "#c2185b"
|
||||
},
|
||||
{
|
||||
"id": "music",
|
||||
"name": "Musik",
|
||||
"description": "Tonkunst und musikalische Komposition",
|
||||
"category": "Künste",
|
||||
"has_children": True,
|
||||
"color_code": "#c2185b"
|
||||
},
|
||||
{
|
||||
"id": "literature",
|
||||
"name": "Literatur",
|
||||
"description": "Schriftliche Kunstwerke und Poesie",
|
||||
"category": "Künste",
|
||||
"has_children": True,
|
||||
"color_code": "#c2185b"
|
||||
}
|
||||
]
|
||||
|
||||
edges = [
|
||||
{"source_id": "arts", "target_id": "visual_arts", "strength": 0.8},
|
||||
{"source_id": "arts", "target_id": "music", "strength": 0.8},
|
||||
{"source_id": "arts", "target_id": "literature", "strength": 0.8}
|
||||
]
|
||||
|
||||
else:
|
||||
# Für jede andere Node-ID geben wir eine leere Struktur zurück
|
||||
nodes = []
|
||||
edges = []
|
||||
|
||||
# Antwort zusammenstellen
|
||||
return {
|
||||
"nodes": nodes,
|
||||
"edges": edges
|
||||
}
|
||||
Reference in New Issue
Block a user