File size: 828 Bytes
78fefe8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from fastapi import APIRouter, HTTPException
from ..models.model_b import AllBInput
from ..logic.calc_b import calculate_all_b

router = APIRouter()

@router.post("/calculate/all")
def calculate_b(input: AllBInput):
    cathode_name = input.cathode_name
    # 1) V–Q / dQdV arrays
    if len(input.V) != len(input.t):
        raise HTTPException(400, "V and t must be same length")

    # 2) Rate‑capability arrays
    if len(input.C_rates) != len(input.t_discharge):
        raise HTTPException(400, "C_rates and t_discharge must be same length")

    # 3) GITT‑diffusion arrays
    if len(input.delta_E_tau) != len(input.delta_E_s):
        raise HTTPException(400, "delta_E_tau and delta_E_s must be same length")

    # All validations passed, compute everything
    return calculate_all_b(cathode_name, input.dict())