25 lines
646 B
Python
25 lines
646 B
Python
from fastapi import APIRouter
|
||
from pydantic import BaseModel
|
||
|
||
INDEX = "EBIT利润率_含投资收益(%)"
|
||
|
||
router = APIRouter()
|
||
|
||
|
||
class Params(BaseModel):
|
||
利润总额: float
|
||
计入财务费用的利息支出: float
|
||
营业收入_含投资收益: float
|
||
|
||
|
||
@router.post("/{}".format(INDEX))
|
||
def func(p: Params):
|
||
try:
|
||
result = (p.利润总额 + p.计入财务费用的利息支出) / p. 营业收入_含投资收益 * 100
|
||
return round(result, 2)
|
||
|
||
except ZeroDivisionError:
|
||
return "+inf" # 此处本应为算式无意义,特殊处理为正无穷大
|
||
except Exception:
|
||
return "计算错误"
|