indexcalculation/基本信用评级指标/盈利能力/营业利润率_近三年加权平均.py

31 lines
815 B
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
@router.post("/{}".format(INDEX))
def func(p: Params):
try:
one = p.当年利润总额 / p.当年营业收入 * 100
two = p.去年利润总额 / p.去年营业收入 * 100
three = p.前年利润总额 / p.前年营业收入 * 100
result = (one * 0.5 + two * 0.3 + three * 0.2) * 100
return round(result, 2)
except ZeroDivisionError:
return "算式无意义"
except Exception:
return "计算错误"