indexcalculation/基本信用评级指标/偿债能力/经营性现金流净额_总债务_三年加权平均.py

34 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 "计算错误"