creditrating-wcq/IndexCalculation/基本信用评级指标/盈利能力/营业利润率_三年加权计算.py

31 lines
838 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:
ratio1 = p.当期营业利润 / p.当期营业收入 * 100
ratio2 = p.上期营业利润 / p.上期营业收入 * 100
ratio3 = p.上二期营业利润 / p.上二期营业收入 * 100
result = (ratio1 * 0.5 + ratio2 * 0.3 + ratio3 * 0.2) * 100
return round(result, 2)
except ZeroDivisionError:
return "算式无意义"
except Exception:
return "计算错误"