changes
This commit is contained in:
parent
ac11363ae6
commit
df8a550ce7
|
@ -6,4 +6,5 @@ class OperatingProfitRatio(BaseModel):
|
|||
operating_income: float
|
||||
|
||||
def exec(self):
|
||||
return self.the_total_profit/self.operating_income
|
||||
result = self.the_total_profit / self.operating_income
|
||||
return round(result, 6)
|
||||
|
|
|
@ -7,4 +7,5 @@ class ReturnOnNetAssets(BaseModel):
|
|||
previous_period_total_owner_equity: float
|
||||
|
||||
def exec(self):
|
||||
return self.net_profit / ((self.current_period_total_owner_equity + self.previous_period_total_owner_equity) / 2)
|
||||
result = self.net_profit / ((self.current_period_total_owner_equity + self.previous_period_total_owner_equity) / 2)
|
||||
return result
|
||||
|
|
|
@ -8,4 +8,5 @@ class ReturnOnTotalAssets(BaseModel):
|
|||
last_total_assets: float
|
||||
|
||||
def exec(self):
|
||||
return (self.the_total_profit + self.interest_expense) / ((self.current_total_assets + self.last_total_assets) / 2)
|
||||
result = (self.the_total_profit + self.interest_expense) / ((self.current_total_assets + self.last_total_assets) / 2)
|
||||
return result
|
||||
|
|
39
main.py
39
main.py
|
@ -1,17 +1,20 @@
|
|||
import json
|
||||
|
||||
from fastapi import FastAPI
|
||||
from fastapi import FastAPI, HTTPException
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
|
||||
from pydantic import BaseModel
|
||||
from pydantic.error_wrappers import ValidationError
|
||||
|
||||
|
||||
class Item(BaseModel):
|
||||
class Args(BaseModel):
|
||||
func_name: str = "ReturnOnNetAssets" # 指标函数名称
|
||||
func_args: str = "{'net_profit': 1, 'current_period_total_owner_equity': 2, 'previous_period_total_owner_equity': 3}" # 指标函数参数
|
||||
func_args: dict = {'net_profit': 1, 'current_period_total_owner_equity': 2, 'previous_period_total_owner_equity': 3} # 指标函数参数
|
||||
|
||||
|
||||
app = FastAPI()
|
||||
app = FastAPI(
|
||||
title="指标函数计算接口",
|
||||
description="发送指标计算请求,返回计算后的指标数值",
|
||||
version="v1.0.0"
|
||||
)
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
|
@ -23,14 +26,22 @@ app.add_middleware(
|
|||
|
||||
|
||||
@app.post("/api/003/indicator_calculator/execute/", summary='输入参数,计算指标数值', description='接口描述', tags=['计算指标数值'])
|
||||
async def root(item: Item):
|
||||
func_name = item.func_name
|
||||
func_args = json.loads(json.dumps(eval(item.func_args)))
|
||||
async def root(args: Args):
|
||||
|
||||
str1 = "from MyFunc.{} import {}".format(func_name, func_name)
|
||||
str2 = "{}(**func_args).exec()".format(func_name)
|
||||
try:
|
||||
func_name = dict(args)["func_name"]
|
||||
func_args = dict(args)["func_args"]
|
||||
|
||||
exec(str1)
|
||||
result = eval(str2)
|
||||
str1 = "from MyFunc.{} import {}".format(func_name, func_name)
|
||||
str2 = "{}(**func_args).exec()".format(func_name)
|
||||
|
||||
return result
|
||||
exec(str1)
|
||||
result = eval(str2)
|
||||
|
||||
return result
|
||||
|
||||
except ModuleNotFoundError:
|
||||
raise HTTPException(status_code=400, detail="Function Not Found")
|
||||
|
||||
except ValidationError as e:
|
||||
raise HTTPException(status_code=400, detail="FuncArgs Incorrect")
|
||||
|
|
Loading…
Reference in New Issue