Fix merge commit 3

pull/80/head
Zainab2604 2025-06-22 13:45:20 +02:00
parent 64426a5f83
commit 8b430f693d
9 changed files with 45 additions and 118 deletions

View File

@ -5,7 +5,6 @@ from dotenv import load_dotenv
from controller import register_routes
from model.database import init_db
from controller.socketIO import socketio
from controller.kennzahlen import kennzahlen_bp
app = Flask(__name__)
CORS(app)
@ -22,9 +21,6 @@ init_db(app)
register_routes(app)
# Register blueprints
app.register_blueprint(kennzahlen_bp)
@app.route("/health")
def health_check():
return "OK"

View File

@ -1,61 +0,0 @@
from flask import Blueprint, jsonify, request
from model.kennzahl import Kennzahl
from model.database import db
kennzahlen_bp = Blueprint('kennzahlen', __name__)
# Beispieldaten
EXAMPLE_DATA = [
{"pdf_id": "example", "label": "Fondsname", "value": "Fund Real Estate Prime Europe", "page": 1, "status": "ok"},
{"pdf_id": "example", "label": "Fondsmanager", "value": "", "page": 1, "status": "error"},
{"pdf_id": "example", "label": "Risikoprofil", "value": "Core/Core+", "page": 10, "status": "warning"},
{"pdf_id": "example", "label": "LTV", "value": "30-35 %", "page": 8, "status": "ok"},
{"pdf_id": "example", "label": "Ausschüttungsrendite", "value": "4%", "page": 34, "status": "ok"}
]
@kennzahlen_bp.route('/api/kennzahlen/init', methods=['POST'])
def init_kennzahlen():
try:
# Lösche existierende Beispieldaten
Kennzahl.query.filter_by(pdf_id='example').delete()
# Füge Beispieldaten ein
for data in EXAMPLE_DATA:
kennzahl = Kennzahl(
pdf_id=data['pdf_id'],
label=data['label'],
value=data['value'],
page=data['page'],
status=data['status']
)
db.session.add(kennzahl)
db.session.commit()
return jsonify({"message": "Kennzahlen erfolgreich initialisiert"})
except Exception as e:
db.session.rollback()
return jsonify({"error": str(e)}), 500
@kennzahlen_bp.route('/api/kennzahlen', methods=['GET'])
def get_kennzahlen():
pdf_id = request.args.get('pdf_id', 'example') # Default zu 'example' für Beispieldaten
kennzahlen = Kennzahl.query.filter_by(pdf_id=pdf_id).all()
return jsonify([k.to_dict() for k in kennzahlen])
@kennzahlen_bp.route('/api/kennzahlen/<label>', methods=['PUT'])
def update_kennzahl(label):
data = request.get_json()
pdf_id = request.args.get('pdf_id', 'example') # Default zu 'example' für Beispieldaten
kennzahl = Kennzahl.query.filter_by(pdf_id=pdf_id, label=label).first()
if not kennzahl:
return jsonify({'error': 'Kennzahl nicht gefunden'}), 404
kennzahl.value = data.get('value', kennzahl.value)
db.session.commit()
return jsonify(kennzahl.to_dict())

View File

@ -35,7 +35,7 @@ def create_kpi_setting():
"translation",
"example",
"position",
"active"
"active",
]
for field in required_fields:
if field not in data:
@ -61,7 +61,7 @@ def create_kpi_setting():
translation=data["translation"],
example=data["example"],
position=data["position"],
active=data["active"]
active=data["active"],
)
db.session.add(new_kpi_setting)
@ -136,7 +136,12 @@ def update_kpi_positions():
try:
for update_item in data:
if "id" not in update_item or "position" not in update_item:
return jsonify({"error": "Each item must have 'id' and 'position' fields"}), 400
return (
jsonify(
{"error": "Each item must have 'id' and 'position' fields"}
),
400,
)
kpi_setting = KPISettingModel.query.get_or_404(update_item["id"])
kpi_setting.position = update_item["position"]
@ -148,4 +153,4 @@ def update_kpi_positions():
except Exception as e:
db.session.rollback()
return jsonify({"error": f"Failed to update positions: {str(e)}"}), 500
return jsonify({"error": f"Failed to update positions: {str(e)}"}), 500

View File

@ -19,6 +19,6 @@ def progress():
):
return jsonify({"error": "Invalid progress value"}), 400
socketio.emit("progress", {"id": data["id"], "progress": data["progress"]})
socketio.emit("progress", {"id": int(data["id"]), "progress": data["progress"]})
# Process the data and return a response
return jsonify({"message": "Progress updated"})

View File

@ -14,4 +14,5 @@ def init_db(app):
with app.app_context():
db.create_all()
from model.seed_data import seed_default_kpi_settings
seed_default_kpi_settings()

View File

@ -1,26 +0,0 @@
from .database import db
class Kennzahl(db.Model):
__tablename__ = 'kennzahlen'
id = db.Column(db.Integer, primary_key=True)
pdf_id = db.Column(db.String(100), nullable=False) # ID des PDFs
label = db.Column(db.String(100), nullable=False)
value = db.Column(db.String(100))
page = db.Column(db.Integer)
status = db.Column(db.String(20))
# Zusammengesetzter Unique-Constraint für pdf_id und label
__table_args__ = (
db.UniqueConstraint('pdf_id', 'label', name='unique_pdf_kennzahl'),
)
def to_dict(self):
return {
'pdf_id': self.pdf_id,
'label': self.label,
'value': self.value,
'page': self.page,
'status': self.status
}

View File

@ -38,10 +38,12 @@ class KPISettingModel(db.Model):
"translation": self.translation,
"example": self.example,
"position": self.position,
"active": self.active
"active": self.active,
}
def __init__(self, name, description, mandatory, type, translation, example, position, active):
def __init__(
self, name, description, mandatory, type, translation, example, position, active
):
self.name = name
self.description = description
self.mandatory = mandatory

View File

@ -1,6 +1,7 @@
from model.database import db
from sqlalchemy.orm import Mapped, mapped_column
from sqlalchemy import LargeBinary
from datetime import datetime
class PitchBookModel(db.Model):
@ -8,9 +9,15 @@ class PitchBookModel(db.Model):
filename: Mapped[str] = mapped_column()
file: Mapped[bytes] = mapped_column(LargeBinary)
kpi: Mapped[str | None]
created_at: Mapped[datetime] = mapped_column(default=datetime.utcnow)
def to_dict(self):
return {"id": self.id, "filename": self.filename, "kpi": self.kpi}
return {
"id": self.id,
"filename": self.filename,
"kpi": self.kpi,
"created_at": self.created_at.isoformat() if self.created_at else None,
}
def __init__(self, filename, file):
self.filename = filename

View File

@ -1,6 +1,7 @@
from model.database import db
from model.kpi_setting_model import KPISettingModel, KPISettingType
def seed_default_kpi_settings():
if KPISettingModel.query.first() is not None:
print("KPI Settings bereits vorhanden, Seeding übersprungen")
@ -15,7 +16,7 @@ def seed_default_kpi_settings():
"translation": "Fund Name",
"example": "Alpha Real Estate Fund I",
"position": 1,
"active": True
"active": True,
},
{
"name": "Fondsmanager",
@ -25,7 +26,7 @@ def seed_default_kpi_settings():
"translation": "Fund Manager",
"example": "Max Mustermann",
"position": 2,
"active": True
"active": True,
},
{
"name": "AIFM",
@ -35,7 +36,7 @@ def seed_default_kpi_settings():
"translation": "AIFM",
"example": "Alpha Investment Management GmbH",
"position": 3,
"active": True
"active": True,
},
{
"name": "Datum",
@ -45,7 +46,7 @@ def seed_default_kpi_settings():
"translation": "Date",
"example": "05.05.2025",
"position": 4,
"active": True
"active": True,
},
{
"name": "Risikoprofil",
@ -55,7 +56,7 @@ def seed_default_kpi_settings():
"translation": "Risk Profile",
"example": "Core/Core++",
"position": 5,
"active": True
"active": True,
},
{
"name": "Artikel",
@ -65,7 +66,7 @@ def seed_default_kpi_settings():
"translation": "Article",
"example": "Artikel 8",
"position": 6,
"active": True
"active": True,
},
{
"name": "Zielrendite",
@ -75,7 +76,7 @@ def seed_default_kpi_settings():
"translation": "Target Return",
"example": "6.5",
"position": 7,
"active": True
"active": True,
},
{
"name": "Rendite",
@ -85,7 +86,7 @@ def seed_default_kpi_settings():
"translation": "Return",
"example": "5.8",
"position": 8,
"active": True
"active": True,
},
{
"name": "Zielausschüttung",
@ -95,7 +96,7 @@ def seed_default_kpi_settings():
"translation": "Target Distribution",
"example": "4.0",
"position": 9,
"active": True
"active": True,
},
{
"name": "Ausschüttung",
@ -105,7 +106,7 @@ def seed_default_kpi_settings():
"translation": "Distribution",
"example": "3.8",
"position": 10,
"active": True
"active": True,
},
{
"name": "Laufzeit",
@ -115,7 +116,7 @@ def seed_default_kpi_settings():
"translation": "Duration",
"example": "7 Jahre, 10, Evergreen",
"position": 11,
"active": True
"active": True,
},
{
"name": "LTV",
@ -125,7 +126,7 @@ def seed_default_kpi_settings():
"translation": "LTV",
"example": "65.0",
"position": 12,
"active": True
"active": True,
},
{
"name": "Managementgebühren",
@ -135,7 +136,7 @@ def seed_default_kpi_settings():
"translation": "Management Fees",
"example": "1.5",
"position": 13,
"active": True
"active": True,
},
{
"name": "Sektorenallokation",
@ -145,7 +146,7 @@ def seed_default_kpi_settings():
"translation": "Sector Allocation",
"example": "Büro, Wohnen, Logistik, Studentenwohnen",
"position": 14,
"active": True
"active": True,
},
{
"name": "Länderallokation",
@ -155,8 +156,8 @@ def seed_default_kpi_settings():
"translation": "Country Allocation",
"example": "Deutschland,Frankreich, Österreich, Schweiz",
"position": 15,
"active": True
}
"active": True,
},
]
print("Füge Standard KPI Settings hinzu...")
@ -170,15 +171,17 @@ def seed_default_kpi_settings():
translation=kpi_data["translation"],
example=kpi_data["example"],
position=kpi_data["position"],
active=kpi_data["active"]
active=kpi_data["active"],
)
db.session.add(kpi_setting)
try:
db.session.commit()
print(f"Erfolgreich {len(default_kpi_settings)} Standard KPI Settings hinzugefügt")
print(
f"Erfolgreich {len(default_kpi_settings)} Standard KPI Settings hinzugefügt"
)
except Exception as e:
db.session.rollback()
print(f"Fehler beim Hinzufügen der Standard KPI Settings: {e}")
raise
raise