2022-12-30 09:28:54 +08:00
|
|
|
|
from fastapi import APIRouter
|
|
|
|
|
from pydantic import BaseModel
|
|
|
|
|
|
|
|
|
|
INDEX = "营业利润率-近三年加权平均(%)"
|
|
|
|
|
|
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Params(BaseModel):
|
|
|
|
|
当年利润总额: float
|
|
|
|
|
当年营业收入: float
|
|
|
|
|
去年利润总额: float
|
|
|
|
|
去年营业收入: float
|
|
|
|
|
前年利润总额: float
|
|
|
|
|
前年营业收入: float
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@router.post("/{}".format(INDEX))
|
|
|
|
|
def func(p: Params):
|
|
|
|
|
try:
|
|
|
|
|
one = p.当年利润总额 / p.当年营业收入 * 100
|
|
|
|
|
two = p.去年利润总额 / p.去年营业收入 * 100
|
|
|
|
|
three = p.前年利润总额 / p.前年营业收入 * 100
|
2023-01-04 14:52:23 +08:00
|
|
|
|
result = (one * 0.5 + two * 0.3 + three * 0.2) * 100
|
|
|
|
|
return round(result, 2)
|
2022-12-30 09:28:54 +08:00
|
|
|
|
|
|
|
|
|
except ZeroDivisionError:
|
|
|
|
|
return "算式无意义"
|
|
|
|
|
except Exception:
|
|
|
|
|
return "计算错误"
|