173 lines
6.3 KiB
Python
173 lines
6.3 KiB
Python
"""
|
|
Gamification Action Keys Seed Script
|
|
=====================================
|
|
Cél: Hiányzó action_key-ek felvétele a gamification.point_rules táblába.
|
|
|
|
Az audit során az alábbi akciókhoz NEM létezik action_key a point_rules táblában:
|
|
- KYC_VERIFICATION (auth_service KYC completion)
|
|
- P2P_REFERRAL_SUCCESS (auth_service P2P referral)
|
|
- EXPENSE_LOG (cost_service expense recording)
|
|
- FLEET_EVENT (fleet_service vehicle event)
|
|
- PROVIDER_VALIDATED (social_service provider validation)
|
|
- PROVIDER_REJECTED (social_service provider rejection)
|
|
- SERVICE_HUNT (services.py service hunt)
|
|
- SERVICE_VALIDATION (services.py service validation)
|
|
|
|
Használat:
|
|
docker compose exec sf_api python3 /app/backend/app/scripts/seed_gamification_action_keys.py
|
|
"""
|
|
|
|
import asyncio
|
|
import logging
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
# Projekt gyökér hozzáadása a Python path-hoz
|
|
sys.path.insert(0, str(Path(__file__).resolve().parent.parent.parent))
|
|
|
|
from sqlalchemy import select
|
|
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine, async_sessionmaker
|
|
from app.core.config import settings
|
|
from app.models.gamification.gamification import PointRule
|
|
|
|
logging.basicConfig(level=logging.INFO, format="%(asctime)s [%(levelname)s] %(message)s")
|
|
logger = logging.getLogger("Seed-Gamification-Action-Keys")
|
|
|
|
# Hiányzó action_key-ek a point_rules táblába
|
|
# Pontértékek a meglévő ConfigService default értékek alapján:
|
|
# KYC_VERIFICATION = 100 (auth_service: kyc_reward)
|
|
# P2P_REFERRAL_SUCCESS = 50 (auth_service: gamification_p2p_invite_xp default)
|
|
# EXPENSE_LOG = 50 (cost_service: xp_per_cost_log default)
|
|
# FLEET_EVENT = 20 (fleet_service: event_rewards["default"]["xp"])
|
|
# PROVIDER_VALIDATED = 100 (social_service: hardcoded 100XP)
|
|
# PROVIDER_REJECTED = 50 (social_service: hardcoded 50XP)
|
|
# SERVICE_HUNT = 50 (services.py: GAMIFICATION_HUNT_REWARD default)
|
|
# SERVICE_VALIDATION = 10 (services.py: GAMIFICATION_VALIDATE_REWARD default)
|
|
# APP_USAGE_EXPENSE = 10 (P0 Smart Expense Workflow: basic app usage XP)
|
|
# PROVIDER_VALIDATION_HELP = 100 (P0 Smart Expense Workflow: provider validation XP)
|
|
SEED_RULES = [
|
|
{
|
|
"action_key": "KYC_VERIFICATION",
|
|
"points": 100,
|
|
"description": "Sikeres KYC (Know Your Customer) folyamat teljesítése",
|
|
"is_active": True,
|
|
},
|
|
{
|
|
"action_key": "P2P_REFERRAL_SUCCESS",
|
|
"points": 50,
|
|
"description": "Sikeres P2P meghívó (referred_by_id alapján)",
|
|
"is_active": True,
|
|
},
|
|
{
|
|
"action_key": "EXPENSE_LOG",
|
|
"points": 50,
|
|
"description": "Költség rögzítése (base_xp, OCR bónusz nélkül)",
|
|
"is_active": True,
|
|
},
|
|
{
|
|
"action_key": "FLEET_EVENT",
|
|
"points": 20,
|
|
"description": "Flotta esemény rögzítése (alapértelmezett pont)",
|
|
"is_active": True,
|
|
},
|
|
{
|
|
"action_key": "PROVIDER_VALIDATED",
|
|
"points": 100,
|
|
"description": "Provider adatainak közösségi validálása (jóváhagyás)",
|
|
"is_active": True,
|
|
},
|
|
{
|
|
"action_key": "PROVIDER_REJECTED",
|
|
"points": 50,
|
|
"description": "Provider adatainak közösségi elutasítása (büntetés)",
|
|
"is_active": True,
|
|
},
|
|
{
|
|
"action_key": "SERVICE_HUNT",
|
|
"points": 50,
|
|
"description": "Új szerviz felfedezése (service hunt)",
|
|
"is_active": True,
|
|
},
|
|
{
|
|
"action_key": "SERVICE_VALIDATION",
|
|
"points": 10,
|
|
"description": "Szerviz validálása (más user által beküldött staging rekord)",
|
|
"is_active": True,
|
|
},
|
|
# === P0 Smart Expense Workflow: New action keys ===
|
|
{
|
|
"action_key": "APP_USAGE_EXPENSE",
|
|
"points": 10,
|
|
"description": "Költség rögzítése (alap app használati XP)",
|
|
"is_active": True,
|
|
},
|
|
{
|
|
"action_key": "PROVIDER_VALIDATION_HELP",
|
|
"points": 100,
|
|
"description": "Szolgáltató validációs pontjának növelése költség rögzítéskor",
|
|
"is_active": True,
|
|
},
|
|
]
|
|
|
|
|
|
async def seed_gamification_action_keys():
|
|
"""
|
|
Feltölti a gamification.point_rules táblát a hiányzó action_key-ekkel.
|
|
Csak azokat a rekordokat szúrja be, amelyek még nem léteznek (action_key alapján).
|
|
"""
|
|
engine = create_async_engine(settings.DATABASE_URL, echo=False)
|
|
async_session = async_sessionmaker(engine, class_=AsyncSession, expire_on_commit=False)
|
|
|
|
async with async_session() as db:
|
|
try:
|
|
inserted_count = 0
|
|
skipped_count = 0
|
|
|
|
for rule_data in SEED_RULES:
|
|
# Ellenőrizzük, hogy létezik-e már ez a szabály
|
|
stmt = select(PointRule).where(
|
|
PointRule.action_key == rule_data["action_key"]
|
|
)
|
|
result = await db.execute(stmt)
|
|
existing = result.scalar_one_or_none()
|
|
|
|
if existing:
|
|
logger.info(
|
|
f"⏭️ Szabály már létezik: {rule_data['action_key']} "
|
|
f"(pont: {existing.points}, ID: {existing.id})"
|
|
)
|
|
skipped_count += 1
|
|
continue
|
|
|
|
# Új szabály beszúrása
|
|
new_rule = PointRule(
|
|
action_key=rule_data["action_key"],
|
|
points=rule_data["points"],
|
|
description=rule_data["description"],
|
|
is_active=rule_data["is_active"],
|
|
)
|
|
db.add(new_rule)
|
|
await db.flush()
|
|
logger.info(
|
|
f"✅ Szabály létrehozva: {rule_data['action_key']} "
|
|
f"(pont: {rule_data['points']}, ID: {new_rule.id})"
|
|
)
|
|
inserted_count += 1
|
|
|
|
await db.commit()
|
|
logger.info(
|
|
f"\n📊 Összegzés: {inserted_count} új szabály beszúrva, "
|
|
f"{skipped_count} már létezett."
|
|
)
|
|
|
|
except Exception as e:
|
|
await db.rollback()
|
|
logger.error(f"❌ Hiba a seedelés során: {e}", exc_info=True)
|
|
raise
|
|
finally:
|
|
await engine.dispose()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(seed_gamification_action_keys())
|