36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
from fastapi import APIRouter
|
||
from pydantic import BaseModel
|
||
|
||
INDEX = "EBIT利润率_三年加权计算(%)"
|
||
|
||
router = APIRouter()
|
||
|
||
|
||
class Params(BaseModel):
|
||
当期利润总额: float
|
||
当期计入财务费用的利息支出: float
|
||
当期营业收入: float
|
||
|
||
上期利润总额: float
|
||
上期计入财务费用的利息支出: float
|
||
上期营业收入: float
|
||
|
||
上二期利润总额: float
|
||
上二期计入财务费用的利息支出: float
|
||
上二期营业收入: float
|
||
|
||
|
||
@router.post("/{}".format(INDEX))
|
||
def func(p: Params):
|
||
try:
|
||
ebit1 = (p.当期利润总额 + p.当期计入财务费用的利息支出) / p.当期营业收入 * 100
|
||
ebit2 = (p.上期利润总额 + p.上期计入财务费用的利息支出) / p.上期营业收入 * 100
|
||
ebit3 = (p.上二期利润总额 + p.上二期计入财务费用的利息支出) / p.上二期营业收入 * 100
|
||
result = ebit1 * 0.5 + ebit2 * 0.3 + ebit3 * 0.2
|
||
return round(result, 2)
|
||
|
||
except ZeroDivisionError:
|
||
return "+inf" # 此处本应为算式无意义,特殊处理为正无穷大
|
||
except Exception:
|
||
return "计算错误"
|