28 lines
601 B
Python
28 lines
601 B
Python
from fastapi import APIRouter
|
||
from pydantic import BaseModel
|
||
|
||
INDEX = "总资产报酬率(%)"
|
||
|
||
router = APIRouter()
|
||
|
||
|
||
class Params(BaseModel):
|
||
利润总额: float
|
||
利息费用: float
|
||
期末资产总计: float
|
||
期初资产总计: float
|
||
|
||
|
||
# 计算接口
|
||
@router.post("/{}".format(INDEX))
|
||
def func(p: Params):
|
||
try:
|
||
d = (p.期末资产总计 + p.期初资产总计) / 2
|
||
result = (p.利润总额 + p.利息费用) / d
|
||
return round(result, 6)
|
||
|
||
except ZeroDivisionError:
|
||
return "算式无意义"
|
||
except Exception:
|
||
return "计算错误"
|