Add initial implementation of CalMiner with project structure, environment setup, and core features
- 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
This commit is contained in:
25
routes/simulations.py
Normal file
25
routes/simulations.py
Normal file
@@ -0,0 +1,25 @@
|
||||
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
|
||||
Reference in New Issue
Block a user