BACKEND-CheckScan / routes /analyze.py
SamilG2's picture
deploy: backend CheckScan inicial
37d841f
Raw History Blame Contribute Delete
1.05 kB
"""Endpoint de análisis: recibe un PGN y devuelve evaluación jugada a jugada."""
from flask import Blueprint, request, jsonify
from modules.analysis.stockfish_wrapper import analyze_pgn
analyze_bp = Blueprint('analyze', __name__)
@analyze_bp.route('/analyze', methods=['POST'])
def analyze():
"""
Body JSON:
{ "pgn_en": "1. e4 e5 2. Nf3 ...", "depth": 18 (opcional) }
Respuesta:
{ "depth": int, "total_moves": int, "moves": [...] }
"""
data = request.get_json(silent=True) or {}
pgn = (data.get('pgn_en') or '').strip()
if not pgn:
return jsonify({'error': "Se esperaba {'pgn_en': '...'}"}), 400
depth = data.get('depth')
if depth is not None:
try:
depth = int(depth)
if not (1 <= depth <= 30):
return jsonify({'error': 'depth debe estar entre 1 y 30'}), 400
except (TypeError, ValueError):
return jsonify({'error': 'depth debe ser entero'}), 400
result = analyze_pgn(pgn, depth=depth)
return jsonify(result)