2022-10-13 17:07:52 +08:00
|
|
|
"""
|
|
|
|
营业利润率
|
|
|
|
"""
|
|
|
|
from fastapi import APIRouter, HTTPException
|
|
|
|
from pydantic import BaseModel
|
|
|
|
|
|
|
|
from Common.schemas import IndicatorDescription
|
|
|
|
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
|
|
# 指标描述
|
2022-10-13 17:24:46 +08:00
|
|
|
ENAME = "operating_profit_ratio"
|
2022-10-13 17:07:52 +08:00
|
|
|
CNAME = "营业利润率"
|
|
|
|
NATURE = "定量"
|
|
|
|
CATEGORY = "盈利能力"
|
|
|
|
DESCRIPTION = "营业利润率 = 利润总额 / 营业收入"
|
|
|
|
|
|
|
|
# 参数描述
|
|
|
|
PARAM1_ENAME = "the_total_profit"
|
|
|
|
PARAM1_CNAME = "利润总额"
|
|
|
|
PARAM1_DESCR = "利润表科目,指息税前利润。"
|
|
|
|
|
|
|
|
PARAM2_ENAME = "operating_income"
|
|
|
|
PARAM2_CNAME = "营业收入"
|
|
|
|
PARAM2_DESCR = "利润表科目,指主营业务或其他业务所取得的收入"
|
|
|
|
|
|
|
|
|
|
|
|
# 输入参数
|
|
|
|
class Parameter(BaseModel):
|
|
|
|
the_total_profit: float = "利润总额"
|
|
|
|
operating_income: float = "营业收入"
|
|
|
|
|
|
|
|
|
|
|
|
# 计算接口
|
|
|
|
@router.post("/{}/".format(ENAME), tags=[CATEGORY], summary=CNAME, description=DESCRIPTION)
|
|
|
|
def profit_ratio(parameter: Parameter):
|
|
|
|
try:
|
|
|
|
result = parameter.the_total_profit / parameter.operating_income
|
|
|
|
return round(result, 6)
|
|
|
|
|
|
|
|
except Exception:
|
|
|
|
raise HTTPException(status_code=400, detail="Calculate Failed")
|
|
|
|
|
|
|
|
|
|
|
|
# 描述接口
|
|
|
|
@router.get("/{}/description".format(ENAME),
|
|
|
|
response_model=IndicatorDescription,
|
|
|
|
tags=[CATEGORY], summary=CNAME, description=DESCRIPTION)
|
|
|
|
def profit_ratio_register():
|
|
|
|
|
|
|
|
body = {
|
|
|
|
"ename": ENAME,
|
|
|
|
"cname": CNAME,
|
|
|
|
"nature": NATURE,
|
|
|
|
"category": CATEGORY,
|
|
|
|
"description": DESCRIPTION,
|
|
|
|
"parameters": [
|
|
|
|
{"ename": PARAM1_ENAME, "cname": PARAM1_CNAME, "description": PARAM1_DESCR},
|
|
|
|
{"ename": PARAM2_ENAME, "cname": PARAM2_CNAME, "description": PARAM2_DESCR}
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
return body
|