26 lines
561 B
Python
26 lines
561 B
Python
from fastapi import APIRouter
|
||
from pydantic import BaseModel
|
||
|
||
INDEX = "平均资本回报率(%))"
|
||
|
||
router = APIRouter()
|
||
|
||
|
||
class Params(BaseModel):
|
||
净利润: float
|
||
期初所有者权益: float
|
||
期末所有者权益: float
|
||
|
||
|
||
@router.post("/{}".format(INDEX))
|
||
def func(p: Params):
|
||
try:
|
||
d = (p.期初所有者权益 + p.期末所有者权益) / 2
|
||
result = p.净利润 / d * 100
|
||
return round(result, 2)
|
||
|
||
except ZeroDivisionError:
|
||
return "算式无意义"
|
||
except Exception:
|
||
return "计算错误"
|