This commit is contained in:
王思川 2022-10-09 13:43:06 +08:00
parent 3a6cdf8fd6
commit 0f0ffe7d47
4 changed files with 34 additions and 14 deletions

View File

@ -0,0 +1,10 @@
from pydantic import BaseModel
class ReturnOnNetAssets(BaseModel):
net_profit: float
current_period_total_owner_equity: float
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)

View File

@ -0,0 +1,11 @@
from pydantic import BaseModel
class ReturnOnTotalAssets(BaseModel):
the_total_profit: float
interest_expense: float
current_total_assets: float
last_total_assets: float
def exec(self):
return (self.the_total_profit + self.interest_expense) / ((self.current_total_assets + self.last_total_assets) / 2)

16
main.py
View File

@ -1,18 +1,28 @@
import json import json
from fastapi import FastAPI from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel from pydantic import BaseModel
class Item(BaseModel): class Item(BaseModel):
func_name: str func_name: str # 指标函数名称
func_args: str func_args: str # 指标函数参数
app = FastAPI() app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.post("/api/functions/")
@app.post("/indicator_calculator/execute/", summary='输入参数,计算指标数值', description='接口描述', tags=['计算指标数值'])
async def root(item: Item): async def root(item: Item):
func_name = item.func_name func_name = item.func_name
func_args = json.loads(json.dumps(eval(item.func_args))) func_args = json.loads(json.dumps(eval(item.func_args)))

View File

@ -1,11 +0,0 @@
# Test your FastAPI endpoints
GET http://127.0.0.1:8000/
Accept: application/json
###
GET http://127.0.0.1:8000/hello/User
Accept: application/json
###