322 lines
12 KiB
Python
322 lines
12 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import os
|
|
import sqlite3
|
|
from flask import Flask
|
|
from flask_sqlalchemy import SQLAlchemy
|
|
from datetime import datetime
|
|
|
|
# Pfad zur Datenbank
|
|
basedir = os.path.abspath(os.path.dirname(__file__))
|
|
db_path = os.path.join(basedir, 'database', 'systades.db')
|
|
|
|
# Stelle sicher, dass das Verzeichnis existiert
|
|
db_dir = os.path.dirname(db_path)
|
|
os.makedirs(db_dir, exist_ok=True)
|
|
|
|
# Erstelle eine temporäre Flask-App, um die Datenbank zu initialisieren
|
|
app = Flask(__name__)
|
|
app.config['SQLALCHEMY_DATABASE_URI'] = f'sqlite:///{db_path}'
|
|
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
|
|
|
# Importiere die Modelle nach der App-Initialisierung
|
|
from models import db, User, Thought, Comment, MindMapNode, ThoughtRelation, ThoughtRating, RelationType
|
|
from models import Category, UserMindmap, UserMindmapNode, MindmapNote
|
|
|
|
db.init_app(app)
|
|
|
|
def init_db():
|
|
with app.app_context():
|
|
print("Initialisiere Datenbank...")
|
|
|
|
# Tabellen erstellen
|
|
db.create_all()
|
|
print("Tabellen wurden erstellt.")
|
|
|
|
# Standardbenutzer erstellen, falls keine vorhanden sind
|
|
if User.query.count() == 0:
|
|
print("Erstelle Standardbenutzer...")
|
|
create_default_users()
|
|
|
|
# Standardkategorien erstellen, falls keine vorhanden sind
|
|
if Category.query.count() == 0:
|
|
print("Erstelle Standardkategorien...")
|
|
create_default_categories()
|
|
|
|
# Beispiel-Mindmap erstellen, falls keine Knoten vorhanden sind
|
|
if MindMapNode.query.count() == 0:
|
|
print("Erstelle Beispiel-Mindmap...")
|
|
create_sample_mindmap()
|
|
|
|
print("Datenbankinitialisierung abgeschlossen.")
|
|
|
|
def create_default_users():
|
|
"""Erstellt Standardbenutzer für die Anwendung"""
|
|
users = [
|
|
{
|
|
'username': 'admin',
|
|
'email': 'admin@example.com',
|
|
'password': 'admin',
|
|
'role': 'admin'
|
|
},
|
|
{
|
|
'username': 'user',
|
|
'email': 'user@example.com',
|
|
'password': 'user',
|
|
'role': 'user'
|
|
}
|
|
]
|
|
|
|
for user_data in users:
|
|
password = user_data.pop('password')
|
|
user = User(**user_data)
|
|
user.set_password(password)
|
|
db.session.add(user)
|
|
|
|
db.session.commit()
|
|
print(f"{len(users)} Benutzer wurden erstellt.")
|
|
|
|
def create_default_categories():
|
|
"""Erstellt die Standardkategorien für die Mindmap"""
|
|
# Hauptkategorien
|
|
main_categories = [
|
|
{
|
|
"name": "Philosophie",
|
|
"description": "Philosophisches Denken und Konzepte",
|
|
"color_code": "#9F7AEA",
|
|
"icon": "fa-brain"
|
|
},
|
|
{
|
|
"name": "Wissenschaft",
|
|
"description": "Wissenschaftliche Disziplinen und Erkenntnisse",
|
|
"color_code": "#60A5FA",
|
|
"icon": "fa-flask"
|
|
},
|
|
{
|
|
"name": "Technologie",
|
|
"description": "Technologische Entwicklungen und Anwendungen",
|
|
"color_code": "#10B981",
|
|
"icon": "fa-microchip"
|
|
},
|
|
{
|
|
"name": "Künste",
|
|
"description": "Künstlerische Ausdrucksformen und Werke",
|
|
"color_code": "#F59E0B",
|
|
"icon": "fa-palette"
|
|
},
|
|
{
|
|
"name": "Psychologie",
|
|
"description": "Mentale Prozesse und Verhaltensweisen",
|
|
"color_code": "#EF4444",
|
|
"icon": "fa-brain"
|
|
}
|
|
]
|
|
|
|
# Hauptkategorien erstellen
|
|
category_map = {}
|
|
for cat_data in main_categories:
|
|
category = Category(**cat_data)
|
|
db.session.add(category)
|
|
db.session.flush() # ID generieren
|
|
category_map[cat_data["name"]] = category
|
|
|
|
# Unterkategorien für Philosophie
|
|
philosophy_subcategories = [
|
|
{"name": "Ethik", "description": "Moralische Grundsätze", "icon": "fa-balance-scale", "color_code": "#8B5CF6"},
|
|
{"name": "Logik", "description": "Gesetze des Denkens", "icon": "fa-project-diagram", "color_code": "#8B5CF6"},
|
|
{"name": "Erkenntnistheorie", "description": "Natur des Wissens", "icon": "fa-lightbulb", "color_code": "#8B5CF6"}
|
|
]
|
|
|
|
# Unterkategorien für Wissenschaft
|
|
science_subcategories = [
|
|
{"name": "Physik", "description": "Studie der Materie und Energie", "icon": "fa-atom", "color_code": "#3B82F6"},
|
|
{"name": "Biologie", "description": "Studie des Lebens", "icon": "fa-dna", "color_code": "#3B82F6"},
|
|
{"name": "Mathematik", "description": "Studie der Zahlen und Strukturen", "icon": "fa-square-root-alt", "color_code": "#3B82F6"}
|
|
]
|
|
|
|
# Unterkategorien für Technologie
|
|
tech_subcategories = [
|
|
{"name": "Software", "description": "Computerprogramme und Anwendungen", "icon": "fa-code", "color_code": "#059669"},
|
|
{"name": "Hardware", "description": "Physische Komponenten der Technik", "icon": "fa-microchip", "color_code": "#059669"},
|
|
{"name": "Internet", "description": "Globales Netzwerk und Web", "icon": "fa-globe", "color_code": "#059669"}
|
|
]
|
|
|
|
# Unterkategorien für Künste
|
|
arts_subcategories = [
|
|
{"name": "Musik", "description": "Klangkunst", "icon": "fa-music", "color_code": "#D97706"},
|
|
{"name": "Literatur", "description": "Geschriebene Kunst", "icon": "fa-book", "color_code": "#D97706"},
|
|
{"name": "Bildende Kunst", "description": "Visuelle Kunst", "icon": "fa-paint-brush", "color_code": "#D97706"}
|
|
]
|
|
|
|
# Unterkategorien für Psychologie
|
|
psychology_subcategories = [
|
|
{"name": "Kognition", "description": "Gedächtnisprozesse und Denken", "icon": "fa-brain", "color_code": "#DC2626"},
|
|
{"name": "Emotionen", "description": "Gefühle und emotionale Prozesse", "icon": "fa-heart", "color_code": "#DC2626"},
|
|
{"name": "Verhalten", "description": "Beobachtbares Verhalten und Reaktionen", "icon": "fa-user", "color_code": "#DC2626"}
|
|
]
|
|
|
|
# Alle Unterkategorien zu ihren Hauptkategorien hinzufügen
|
|
for subcat_data in philosophy_subcategories:
|
|
subcat = Category(**subcat_data)
|
|
subcat.parent_id = category_map["Philosophie"].id
|
|
db.session.add(subcat)
|
|
|
|
for subcat_data in science_subcategories:
|
|
subcat = Category(**subcat_data)
|
|
subcat.parent_id = category_map["Wissenschaft"].id
|
|
db.session.add(subcat)
|
|
|
|
for subcat_data in tech_subcategories:
|
|
subcat = Category(**subcat_data)
|
|
subcat.parent_id = category_map["Technologie"].id
|
|
db.session.add(subcat)
|
|
|
|
for subcat_data in arts_subcategories:
|
|
subcat = Category(**subcat_data)
|
|
subcat.parent_id = category_map["Künste"].id
|
|
db.session.add(subcat)
|
|
|
|
for subcat_data in psychology_subcategories:
|
|
subcat = Category(**subcat_data)
|
|
subcat.parent_id = category_map["Psychologie"].id
|
|
db.session.add(subcat)
|
|
|
|
db.session.commit()
|
|
print(f"{len(main_categories)} Hauptkategorien und {len(philosophy_subcategories + science_subcategories + tech_subcategories + arts_subcategories + psychology_subcategories)} Unterkategorien wurden erstellt.")
|
|
|
|
def create_sample_mindmap():
|
|
"""Erstellt eine Beispiel-Mindmap mit Knoten und Beziehungen"""
|
|
|
|
# Kategorien für die Zuordnung
|
|
categories = Category.query.all()
|
|
category_map = {cat.name: cat for cat in categories}
|
|
|
|
# Beispielknoten erstellen
|
|
nodes = [
|
|
{
|
|
'name': 'Wissensmanagement',
|
|
'description': 'Systematische Erfassung, Speicherung und Nutzung von Wissen in Organisationen.',
|
|
'color_code': '#6366f1',
|
|
'icon': 'database',
|
|
'category': category_map.get('Konzept'),
|
|
'x': 0,
|
|
'y': 0
|
|
},
|
|
{
|
|
'name': 'Mind-Mapping',
|
|
'description': 'Technik zur visuellen Darstellung von Informationen und Zusammenhängen.',
|
|
'color_code': '#10b981',
|
|
'icon': 'git-branch',
|
|
'category': category_map.get('Prozess'),
|
|
'x': 200,
|
|
'y': -150
|
|
},
|
|
{
|
|
'name': 'Cytoscape.js',
|
|
'description': 'JavaScript-Bibliothek für die Visualisierung und Manipulation von Graphen.',
|
|
'color_code': '#3b82f6',
|
|
'icon': 'code',
|
|
'category': category_map.get('Technologie'),
|
|
'x': 350,
|
|
'y': -50
|
|
},
|
|
{
|
|
'name': 'Socket.IO',
|
|
'description': 'Bibliothek für Echtzeit-Kommunikation zwischen Client und Server.',
|
|
'color_code': '#3b82f6',
|
|
'icon': 'zap',
|
|
'category': category_map.get('Technologie'),
|
|
'x': 350,
|
|
'y': 100
|
|
},
|
|
{
|
|
'name': 'Kollaboration',
|
|
'description': 'Zusammenarbeit mehrerer Benutzer an gemeinsamen Inhalten.',
|
|
'color_code': '#f59e0b',
|
|
'icon': 'users',
|
|
'category': category_map.get('Prozess'),
|
|
'x': 200,
|
|
'y': 150
|
|
},
|
|
{
|
|
'name': 'SQLite',
|
|
'description': 'Leichtgewichtige relationale Datenbank, die ohne Server-Prozess auskommt.',
|
|
'color_code': '#3b82f6',
|
|
'icon': 'database',
|
|
'category': category_map.get('Technologie'),
|
|
'x': 0,
|
|
'y': 200
|
|
},
|
|
{
|
|
'name': 'Flask',
|
|
'description': 'Leichtgewichtiges Python-Webframework für die Entwicklung von Webanwendungen.',
|
|
'color_code': '#3b82f6',
|
|
'icon': 'server',
|
|
'category': category_map.get('Technologie'),
|
|
'x': -200,
|
|
'y': 150
|
|
},
|
|
{
|
|
'name': 'REST API',
|
|
'description': 'Architekturstil für verteilte Systeme, insbesondere Webanwendungen.',
|
|
'color_code': '#10b981',
|
|
'icon': 'link',
|
|
'category': category_map.get('Konzept'),
|
|
'x': -200,
|
|
'y': -150
|
|
},
|
|
{
|
|
'name': 'Dokumentation',
|
|
'description': 'Strukturierte Erfassung und Beschreibung von Informationen und Prozessen.',
|
|
'color_code': '#ec4899',
|
|
'icon': 'file-text',
|
|
'category': category_map.get('Dokument'),
|
|
'x': -350,
|
|
'y': 0
|
|
}
|
|
]
|
|
|
|
# Knoten in die Datenbank einfügen
|
|
node_objects = {}
|
|
for node_data in nodes:
|
|
category = node_data.pop('category', None)
|
|
x = node_data.pop('x', 0)
|
|
y = node_data.pop('y', 0)
|
|
node = MindMapNode(**node_data)
|
|
if category:
|
|
node.category_id = category.id
|
|
db.session.add(node)
|
|
db.session.flush() # Generiert IDs für neue Objekte
|
|
node_objects[node.name] = node
|
|
|
|
# Beziehungen erstellen
|
|
relationships = [
|
|
('Wissensmanagement', 'Mind-Mapping'),
|
|
('Wissensmanagement', 'Kollaboration'),
|
|
('Wissensmanagement', 'Dokumentation'),
|
|
('Mind-Mapping', 'Cytoscape.js'),
|
|
('Kollaboration', 'Socket.IO'),
|
|
('Wissensmanagement', 'SQLite'),
|
|
('SQLite', 'Flask'),
|
|
('Flask', 'REST API'),
|
|
('REST API', 'Socket.IO'),
|
|
('REST API', 'Dokumentation')
|
|
]
|
|
|
|
for parent_name, child_name in relationships:
|
|
parent = node_objects.get(parent_name)
|
|
child = node_objects.get(child_name)
|
|
if parent and child:
|
|
parent.children.append(child)
|
|
|
|
db.session.commit()
|
|
print(f"{len(nodes)} Knoten und {len(relationships)} Beziehungen wurden erstellt.")
|
|
|
|
if __name__ == '__main__':
|
|
init_db()
|
|
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") |