- Create .env.example for environment variables - Update README with project structure and development setup instructions - Implement FastAPI application with API routes for scenarios and parameters - Add database models for scenarios, parameters, and simulation results - Introduce validation middleware for JSON requests - Create services for running simulations and generating reports - Add testing strategy and directory structure in documentation
26 lines
750 B
Python
26 lines
750 B
Python
from fastapi import APIRouter, HTTPException, Depends
|
|
from typing import List
|
|
|
|
from services.simulation import run_simulation
|
|
from sqlalchemy.orm import Session
|
|
from config.database import SessionLocal
|
|
|
|
router = APIRouter(prefix="/api/simulations", tags=["Simulations"])
|
|
|
|
|
|
def get_db():
|
|
db = SessionLocal()
|
|
try:
|
|
yield db
|
|
finally:
|
|
db.close()
|
|
|
|
|
|
@router.post("/run", response_model=List[dict])
|
|
async def simulate(params: List[dict], iterations: int = 1000, db: Session = Depends(get_db)):
|
|
if not params:
|
|
raise HTTPException(status_code=400, detail="No parameters provided")
|
|
# TODO: you might use db to fetch scenario info or persist results
|
|
results = run_simulation(params, iterations)
|
|
return results
|