82 lines
3.0 KiB
Python
82 lines
3.0 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Egyszerű teszt a Gondos Gazda Index API végponthoz.
|
|
"""
|
|
|
|
import asyncio
|
|
import sys
|
|
import os
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'backend'))
|
|
|
|
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
|
|
from sqlalchemy.orm import sessionmaker
|
|
from app.database import AsyncSessionLocal
|
|
from app.services.trust_engine import TrustEngine
|
|
from app.models.identity import User
|
|
|
|
async def test_trust_engine():
|
|
"""Teszteli a TrustEngine működését."""
|
|
print("TrustEngine teszt indítása...")
|
|
|
|
# Adatbázis kapcsolat
|
|
engine = create_async_engine(
|
|
"postgresql+asyncpg://postgres:postgres@localhost:5432/service_finder",
|
|
echo=False
|
|
)
|
|
|
|
async_session = sessionmaker(
|
|
engine, class_=AsyncSession, expire_on_commit=False
|
|
)
|
|
|
|
async with async_session() as db:
|
|
# Keressünk egy teszt felhasználót
|
|
from sqlalchemy import select
|
|
stmt = select(User).limit(1)
|
|
result = await db.execute(stmt)
|
|
user = result.scalar_one_or_none()
|
|
|
|
if not user:
|
|
print("Nincs felhasználó az adatbázisban, teszt felhasználó létrehozása...")
|
|
# Egyszerűsítés: csak kiírjuk, hogy nincs felhasználó
|
|
print("Nincs felhasználó, a teszt kihagyva.")
|
|
return
|
|
|
|
print(f"Teszt felhasználó: {user.email} (ID: {user.id})")
|
|
|
|
# TrustEngine példányosítás
|
|
trust_engine = TrustEngine()
|
|
|
|
# Trust számítás
|
|
trust_data = await trust_engine.calculate_user_trust(db, user.id)
|
|
|
|
print("\n=== Trust Score Eredmény ===")
|
|
print(f"Trust Score: {trust_data['trust_score']}/100")
|
|
print(f"Maintenance Score: {trust_data['maintenance_score']:.2f}")
|
|
print(f"Quality Score: {trust_data['quality_score']:.2f}")
|
|
print(f"Preventive Score: {trust_data['preventive_score']:.2f}")
|
|
print(f"Last Calculated: {trust_data['last_calculated']}")
|
|
|
|
if trust_data['weights']:
|
|
print(f"\nSúlyozások:")
|
|
for key, value in trust_data['weights'].items():
|
|
print(f" {key}: {value:.2f}")
|
|
|
|
if trust_data['tolerance_km']:
|
|
print(f"Tolerancia KM: {trust_data['tolerance_km']}")
|
|
|
|
# Ellenőrizzük, hogy a UserTrustProfile létrejött-e
|
|
from sqlalchemy import select
|
|
from app.models.identity import UserTrustProfile
|
|
stmt = select(UserTrustProfile).where(UserTrustProfile.user_id == user.id)
|
|
result = await db.execute(stmt)
|
|
profile = result.scalar_one_or_none()
|
|
|
|
if profile:
|
|
print(f"\nUserTrustProfile létrehozva:")
|
|
print(f" Trust Score: {profile.trust_score}")
|
|
print(f" Last Calculated: {profile.last_calculated}")
|
|
else:
|
|
print("\nFIGYELEM: UserTrustProfile nem jött létre!")
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(test_trust_engine()) |