34 lines
1.1 KiB
Python
34 lines
1.1 KiB
Python
from fastapi import APIRouter
|
||
from pydantic import BaseModel
|
||
|
||
INDEX = "经营性现金流净额/总债务-近三年加权平均(%)"
|
||
|
||
router = APIRouter()
|
||
|
||
|
||
class Params(BaseModel):
|
||
当年经营活动产生的现金流量净额: float
|
||
当年短期借款: float
|
||
当年长期借款: float
|
||
去年经营活动产生的现金流量净额: float
|
||
去年短期借款: float
|
||
去年长期借款: float
|
||
前年经营活动产生的现金流量净额: float
|
||
前年短期借款: float
|
||
前年长期借款: float
|
||
|
||
|
||
@router.post("/{}".format(INDEX))
|
||
def func(p: Params):
|
||
try:
|
||
one = p.当年经营活动产生的现金流量净额 / (p.当年长期借款 + p.当年短期借款) * 100
|
||
two = p.去年经营活动产生的现金流量净额 / (p.去年长期借款 + p.去年短期借款) * 100
|
||
three = p.前年经营活动产生的现金流量净额 / (p.前年短期借款 + p.前年长期借款) * 100
|
||
result = one * 0.5 + two * 0.3 + three * 0.2
|
||
return round(result, 6)
|
||
|
||
except ZeroDivisionError:
|
||
return "算式无意义"
|
||
except Exception:
|
||
return "计算错误"
|