from fastapi import APIRouter, Depends, HTTPException from sqlalchemy.orm import Session from typing import Optional from ...core.database import get_db from ...services.analysis_service import LotteryAnalysisService router = APIRouter() @router.get("/hot-cold/{lottery_type}") def get_hot_cold_numbers( lottery_type: str, periods: Optional[int] = 50, db: Session = Depends(get_db) ): """获取热号和冷号分析""" if lottery_type not in ['ssq', 'dlt']: raise HTTPException(status_code=400, detail="Invalid lottery type") analysis_service = LotteryAnalysisService(db) return analysis_service.get_hot_cold_numbers(lottery_type, periods) @router.get("/distribution/{lottery_type}") def get_number_distribution( lottery_type: str, periods: Optional[int] = 100, db: Session = Depends(get_db) ): """获取号码分布分析""" if lottery_type not in ['ssq', 'dlt']: raise HTTPException(status_code=400, detail="Invalid lottery type") analysis_service = LotteryAnalysisService(db) return analysis_service.analyze_number_distribution(lottery_type, periods) @router.get("/consecutive/{lottery_type}") def get_consecutive_analysis( lottery_type: str, periods: Optional[int] = 100, db: Session = Depends(get_db) ): """获取连号和重复号分析""" if lottery_type not in ['ssq', 'dlt']: raise HTTPException(status_code=400, detail="Invalid lottery type") analysis_service = LotteryAnalysisService(db) return analysis_service.analyze_consecutive_numbers(lottery_type, periods) @router.get("/math-stats/{lottery_type}") def get_mathematical_stats( lottery_type: str, periods: Optional[int] = 100, db: Session = Depends(get_db) ): """获取数学统计特征""" if lottery_type not in ['ssq', 'dlt']: raise HTTPException(status_code=400, detail="Invalid lottery type") analysis_service = LotteryAnalysisService(db) return analysis_service.analyze_mathematical_stats(lottery_type, periods) @router.get("/missing/{lottery_type}") def get_missing_periods( lottery_type: str, db: Session = Depends(get_db) ): """获取号码遗漏值分析""" if lottery_type not in ['ssq', 'dlt']: raise HTTPException(status_code=400, detail="Invalid lottery type") analysis_service = LotteryAnalysisService(db) return analysis_service.get_missing_periods(lottery_type) @router.get("/smart-numbers/{lottery_type}") def generate_smart_numbers( lottery_type: str, strategy: Optional[str] = 'balanced', count: Optional[int] = 1, periods: Optional[int] = 100, db: Session = Depends(get_db) ): """智能选号 Args: lottery_type: 彩票类型 ('ssq' 或 'dlt') strategy: 选号策略 ('balanced', 'hot', 'cold', 'missing') count: 生成注数,默认1注 periods: 分析期数,默认100期 """ if lottery_type not in ['ssq', 'dlt']: raise HTTPException(status_code=400, detail="Invalid lottery type") if strategy not in ['balanced', 'hot', 'cold', 'missing']: raise HTTPException(status_code=400, detail="Invalid strategy") if count < 1 or count > 10: raise HTTPException( status_code=400, detail="Count must be between 1 and 10") if periods < 50 or periods > 200: raise HTTPException( status_code=400, detail="Periods must be between 50 and 200") analysis_service = LotteryAnalysisService(db) return analysis_service.generate_smart_numbers(lottery_type, strategy, count, periods)