Overhaul website to modernize design, integrate SVG visualizations, and enhance KI functionality; update documentation for MindMapProjekt.
This commit is contained in:
258
init_db.py
Executable file
258
init_db.py
Executable file
@@ -0,0 +1,258 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from app import app, initialize_database, db_path
|
||||
from models import db, User, Thought, Comment, MindMapNode, ThoughtRelation, ThoughtRating, RelationType
|
||||
from models import Category, UserMindmap, UserMindmapNode, MindmapNote
|
||||
import os
|
||||
|
||||
def init_database():
|
||||
"""Initialisiert die Datenbank mit Beispieldaten."""
|
||||
with app.app_context():
|
||||
# Datenbank löschen und neu erstellen
|
||||
if os.path.exists(db_path):
|
||||
os.remove(db_path)
|
||||
|
||||
# Stellen Sie sicher, dass das Verzeichnis existiert
|
||||
os.makedirs(os.path.dirname(db_path), exist_ok=True)
|
||||
|
||||
db.create_all()
|
||||
|
||||
# Admin-Benutzer erstellen
|
||||
admin = User(username='admin', email='admin@example.com', is_admin=True)
|
||||
admin.set_password('admin')
|
||||
db.session.add(admin)
|
||||
|
||||
# Beispiel-Benutzer erstellen
|
||||
user = User(username='user', email='user@example.com')
|
||||
user.set_password('user')
|
||||
db.session.add(user)
|
||||
|
||||
# Commit, um IDs zu generieren
|
||||
db.session.commit()
|
||||
|
||||
# Wissenschaftliche Kategorien erstellen
|
||||
science = Category(name='Wissenschaft', description='Wissenschaftliche Erkenntnisse',
|
||||
color_code='#4CAF50', icon='flask')
|
||||
db.session.add(science)
|
||||
|
||||
philosophy = Category(name='Philosophie', description='Philosophische Theorien und Gedanken',
|
||||
color_code='#9C27B0', icon='lightbulb')
|
||||
db.session.add(philosophy)
|
||||
|
||||
technology = Category(name='Technologie', description='Technologische Entwicklungen',
|
||||
color_code='#FF9800', icon='microchip')
|
||||
db.session.add(technology)
|
||||
|
||||
db.session.commit()
|
||||
|
||||
# Wissenschaftliche Unterkategorien
|
||||
physics = Category(name='Physik', description='Studium der Materie und Energie',
|
||||
color_code='#81C784', icon='atom', parent_id=science.id)
|
||||
biology = Category(name='Biologie', description='Studium lebender Organismen',
|
||||
color_code='#66BB6A', icon='leaf', parent_id=science.id)
|
||||
chemistry = Category(name='Chemie', description='Studium der Stoffe und ihrer Reaktionen',
|
||||
color_code='#A5D6A7', icon='vial', parent_id=science.id)
|
||||
|
||||
db.session.add_all([physics, biology, chemistry])
|
||||
|
||||
# Technologie-Unterkategorien
|
||||
informatics = Category(name='Informatik', description='Studium der Informationsverarbeitung',
|
||||
color_code='#FFB74D', icon='laptop-code', parent_id=technology.id)
|
||||
ai = Category(name='Künstliche Intelligenz', description='Entwicklung intelligenter Systeme',
|
||||
color_code='#FFA726', icon='robot', parent_id=technology.id)
|
||||
|
||||
db.session.add_all([informatics, ai])
|
||||
|
||||
# Philosophie-Unterkategorien
|
||||
ethics = Category(name='Ethik', description='Moralphilosophie und Wertesysteme',
|
||||
color_code='#BA68C8', icon='balance-scale', parent_id=philosophy.id)
|
||||
logic = Category(name='Logik', description='Studie der gültigen Schlussfolgerungen',
|
||||
color_code='#AB47BC', icon='project-diagram', parent_id=philosophy.id)
|
||||
|
||||
db.session.add_all([ethics, logic])
|
||||
|
||||
db.session.commit()
|
||||
|
||||
# Knoten für die öffentliche Mindmap erstellen
|
||||
nodes = {
|
||||
'quantenmechanik': MindMapNode(
|
||||
name='Quantenmechanik',
|
||||
description='Physikalische Theorie zur Beschreibung der Materie auf atomarer Ebene',
|
||||
color_code='#81C784',
|
||||
category_id=physics.id,
|
||||
created_by_id=admin.id
|
||||
),
|
||||
'relativitaetstheorie': MindMapNode(
|
||||
name='Relativitätstheorie',
|
||||
description='Einsteins Theorien zur Raumzeit und Gravitation',
|
||||
color_code='#81C784',
|
||||
category_id=physics.id,
|
||||
created_by_id=admin.id
|
||||
),
|
||||
'genetik': MindMapNode(
|
||||
name='Genetik',
|
||||
description='Wissenschaft der Gene und Vererbung',
|
||||
color_code='#66BB6A',
|
||||
category_id=biology.id,
|
||||
created_by_id=admin.id
|
||||
),
|
||||
'machine_learning': MindMapNode(
|
||||
name='Machine Learning',
|
||||
description='Algorithmen, die aus Daten lernen können',
|
||||
color_code='#FFA726',
|
||||
category_id=ai.id,
|
||||
created_by_id=admin.id
|
||||
),
|
||||
'ki_ethik': MindMapNode(
|
||||
name='KI-Ethik',
|
||||
description='Moralische Implikationen künstlicher Intelligenz',
|
||||
color_code='#BA68C8',
|
||||
category_id=ethics.id,
|
||||
created_by_id=user.id
|
||||
)
|
||||
}
|
||||
|
||||
for node in nodes.values():
|
||||
db.session.add(node)
|
||||
|
||||
db.session.commit()
|
||||
|
||||
# Verknüpfungen zwischen Knoten herstellen (Hierarchie)
|
||||
nodes['machine_learning'].parents.append(nodes['ki_ethik'])
|
||||
db.session.commit()
|
||||
|
||||
# Gedanken erstellen
|
||||
thoughts = [
|
||||
{
|
||||
'title': 'Künstliche Intelligenz und Bewusstsein',
|
||||
'content': 'Die Frage nach maschinellem Bewusstsein ist fundamental für die KI-Ethik. Aktuelle KI-Systeme haben kein Bewusstsein, aber fortschrittliche KI könnte in Zukunft Eigenschaften entwickeln, die diesem nahekommen.',
|
||||
'abstract': 'Eine Untersuchung der philosophischen Implikationen von KI-Bewusstsein.',
|
||||
'keywords': 'KI, Bewusstsein, Ethik, Philosophie',
|
||||
'branch': 'Philosophie',
|
||||
'color_code': '#BA68C8',
|
||||
'source_type': 'Markdown',
|
||||
'user_id': user.id,
|
||||
'node': nodes['ki_ethik']
|
||||
},
|
||||
{
|
||||
'title': 'Quantenmechanik und Realität',
|
||||
'content': 'Die Kopenhagener Deutung und ihre Auswirkungen auf unser Verständnis der Realität. Quantenmechanik stellt grundlegende Annahmen über Determinismus und Lokalität in Frage.',
|
||||
'abstract': 'Eine Analyse verschiedener Interpretationen der Quantenmechanik.',
|
||||
'keywords': 'Quantenmechanik, Physik, Realität',
|
||||
'branch': 'Physik',
|
||||
'color_code': '#81C784',
|
||||
'source_type': 'PDF',
|
||||
'user_id': admin.id,
|
||||
'node': nodes['quantenmechanik']
|
||||
},
|
||||
{
|
||||
'title': 'Deep Learning Fortschritte',
|
||||
'content': 'Die neuesten Fortschritte im Deep Learning haben zu beeindruckenden Ergebnissen in Bereichen wie Computer Vision, Natural Language Processing und Reinforcement Learning geführt.',
|
||||
'abstract': 'Überblick über aktuelle Deep Learning-Techniken und ihre Anwendungen.',
|
||||
'keywords': 'Deep Learning, Neural Networks, AI',
|
||||
'branch': 'Technologie',
|
||||
'color_code': '#FFA726',
|
||||
'source_type': 'Webpage',
|
||||
'user_id': admin.id,
|
||||
'node': nodes['machine_learning']
|
||||
}
|
||||
]
|
||||
|
||||
thought_objects = []
|
||||
for t_data in thoughts:
|
||||
node = t_data.pop('node')
|
||||
thought = Thought(**t_data)
|
||||
node.thoughts.append(thought)
|
||||
thought_objects.append(thought)
|
||||
db.session.add(thought)
|
||||
|
||||
db.session.commit()
|
||||
|
||||
# Beziehungen zwischen Gedanken
|
||||
relation = ThoughtRelation(
|
||||
source_id=thought_objects[0].id,
|
||||
target_id=thought_objects[2].id,
|
||||
relation_type=RelationType.INSPIRES,
|
||||
created_by_id=user.id
|
||||
)
|
||||
db.session.add(relation)
|
||||
|
||||
# Bewertungen erstellen
|
||||
rating1 = ThoughtRating(
|
||||
thought_id=thought_objects[0].id,
|
||||
user_id=admin.id,
|
||||
relevance_score=5
|
||||
)
|
||||
rating2 = ThoughtRating(
|
||||
thought_id=thought_objects[2].id,
|
||||
user_id=user.id,
|
||||
relevance_score=4
|
||||
)
|
||||
db.session.add_all([rating1, rating2])
|
||||
|
||||
# Kommentare erstellen
|
||||
for thought in thought_objects:
|
||||
comment = Comment(
|
||||
content=f'Interessante Perspektive zu {thought.title}!',
|
||||
thought_id=thought.id,
|
||||
user_id=admin.id if thought.user_id != admin.id else user.id
|
||||
)
|
||||
db.session.add(comment)
|
||||
|
||||
# Benutzer-Mindmaps erstellen
|
||||
user_mindmap = UserMindmap(
|
||||
name='Meine KI-Forschung',
|
||||
description='Meine persönliche Sammlung zu KI und Ethik',
|
||||
user_id=user.id
|
||||
)
|
||||
db.session.add(user_mindmap)
|
||||
db.session.commit()
|
||||
|
||||
# Knoten zur Benutzer-Mindmap hinzufügen
|
||||
user_mindmap_nodes = [
|
||||
UserMindmapNode(
|
||||
user_mindmap_id=user_mindmap.id,
|
||||
node_id=nodes['machine_learning'].id,
|
||||
x_position=200,
|
||||
y_position=300
|
||||
),
|
||||
UserMindmapNode(
|
||||
user_mindmap_id=user_mindmap.id,
|
||||
node_id=nodes['ki_ethik'].id,
|
||||
x_position=500,
|
||||
y_position=200
|
||||
)
|
||||
]
|
||||
db.session.add_all(user_mindmap_nodes)
|
||||
|
||||
# Private Notizen
|
||||
note = MindmapNote(
|
||||
user_id=user.id,
|
||||
mindmap_id=user_mindmap.id,
|
||||
node_id=nodes['ki_ethik'].id,
|
||||
content="Recherchiere mehr über aktuelle ethische Richtlinien für KI-Entwicklung!",
|
||||
color_code="#FFF59D"
|
||||
)
|
||||
db.session.add(note)
|
||||
|
||||
# Gedanken zu Bookmarks hinzufügen
|
||||
user.bookmarked_thoughts.append(thought_objects[0])
|
||||
admin.bookmarked_thoughts.append(thought_objects[1])
|
||||
|
||||
# Finaler Commit
|
||||
db.session.commit()
|
||||
|
||||
print("Datenbank wurde erfolgreich initialisiert!")
|
||||
|
||||
def init_db():
|
||||
"""Alias für Kompatibilität mit älteren Scripts."""
|
||||
init_database()
|
||||
|
||||
if __name__ == '__main__':
|
||||
init_database()
|
||||
print("Datenbank wurde erfolgreich initialisiert!")
|
||||
print("Sie können die Anwendung jetzt mit 'python app.py' starten")
|
||||
print("Anmelden mit:")
|
||||
print(" Admin: username=admin, password=admin")
|
||||
print(" User: username=user, password=user")
|
||||
Reference in New Issue
Block a user