Merge pull request #6 from yardstick/feature/QUANT-989-add-solver-endpoint
QUANT-989: add solver endpoint
This commit is contained in:
commit
98f316da1e
19
app/main.py
19
app/main.py
@ -1,4 +1,11 @@
|
|||||||
from fastapi import FastAPI, __version__
|
from fastapi import FastAPI, __version__
|
||||||
|
from pydantic import BaseModel
|
||||||
|
from typing import Set, List, Optional, Dict
|
||||||
|
from random import randint
|
||||||
|
|
||||||
|
from models.solver_run import SolverRun
|
||||||
|
from models.solution import Solution
|
||||||
|
from models.form import Form
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
@ -13,10 +20,20 @@ async def health():
|
|||||||
"git_repo": "https://github.com/yardstick/measure-solver",
|
"git_repo": "https://github.com/yardstick/measure-solver",
|
||||||
"server": "OK",
|
"server": "OK",
|
||||||
"fastapi version": __version__,
|
"fastapi version": __version__,
|
||||||
"app version": "0.1.0"
|
"app version": "0.1.1"
|
||||||
}
|
}
|
||||||
return content
|
return content
|
||||||
|
|
||||||
@app.get('/readycheck')
|
@app.get('/readycheck')
|
||||||
async def ready():
|
async def ready():
|
||||||
return 'OK' # just means we're on air
|
return 'OK' # just means we're on air
|
||||||
|
|
||||||
|
@app.post('/solve/')
|
||||||
|
async def solve(solver_run: SolverRun):
|
||||||
|
response = Solution(
|
||||||
|
response_id=randint(100,5000),
|
||||||
|
forms=[Form(
|
||||||
|
items=[item.id for item in solver_run.items]
|
||||||
|
)]
|
||||||
|
)
|
||||||
|
return response
|
||||||
|
11
app/models/advanced_options.py
Normal file
11
app/models/advanced_options.py
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
from pydantic import BaseModel
|
||||||
|
from typing import List, Optional, Dict
|
||||||
|
|
||||||
|
class AdvancedOptions(BaseModel):
|
||||||
|
linearity_check: bool
|
||||||
|
show_progress: bool
|
||||||
|
max_solution_time: Optional[int]
|
||||||
|
brand_bound_tolerance: Optional[float]
|
||||||
|
max_forms: Optional[int]
|
||||||
|
precision: Optional[float]
|
||||||
|
extra_param_range: Optional[List[Dict]]
|
7
app/models/attribute.py
Normal file
7
app/models/attribute.py
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
from pydantic import BaseModel
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
class Attribute(BaseModel):
|
||||||
|
value: str
|
||||||
|
type: Optional[str]
|
||||||
|
id: str
|
9
app/models/constraint.py
Normal file
9
app/models/constraint.py
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
from pydantic import BaseModel
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
from models.attribute import Attribute
|
||||||
|
|
||||||
|
class Constraint(BaseModel):
|
||||||
|
reference_attribute: Attribute
|
||||||
|
minimum: int
|
||||||
|
maximum: int
|
7
app/models/form.py
Normal file
7
app/models/form.py
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
from pydantic import BaseModel
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
from models.item import Item
|
||||||
|
|
||||||
|
class Form(BaseModel):
|
||||||
|
items: List[int]
|
7
app/models/irt_model.py
Normal file
7
app/models/irt_model.py
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
class IRTModel(BaseModel):
|
||||||
|
a_param: float
|
||||||
|
b_param: float
|
||||||
|
c_param: float
|
||||||
|
model: str
|
8
app/models/item.py
Normal file
8
app/models/item.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
from pydantic import BaseModel
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
from models.attribute import Attribute
|
||||||
|
|
||||||
|
class Item(BaseModel):
|
||||||
|
id: int
|
||||||
|
attributes: List[Attribute]
|
13
app/models/objective_function.py
Normal file
13
app/models/objective_function.py
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
from pydantic import BaseModel
|
||||||
|
from typing import Dict, List
|
||||||
|
|
||||||
|
from models.target import Target
|
||||||
|
|
||||||
|
class ObjectiveFunction(BaseModel):
|
||||||
|
# minimizing tif/tcc target value is only option currently
|
||||||
|
# as we add more we can build this out to be more dynamic
|
||||||
|
# likely with models representing each objective function type
|
||||||
|
tif_targets: List[Target]
|
||||||
|
tcc_targets: List[Target]
|
||||||
|
objective: "minimize"
|
||||||
|
weight: Dict = {'tif': 1, 'tcc': 1}
|
8
app/models/solution.py
Normal file
8
app/models/solution.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
from pydantic import BaseModel
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
from models.form import Form
|
||||||
|
|
||||||
|
class Solution(BaseModel):
|
||||||
|
response_id: int
|
||||||
|
forms: List[Form]
|
17
app/models/solver_run.py
Normal file
17
app/models/solver_run.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
from pydantic import BaseModel
|
||||||
|
from typing import List, Optional
|
||||||
|
|
||||||
|
from models.item import Item
|
||||||
|
from models.constraint import Constraint
|
||||||
|
from models.irt_model import IRTModel
|
||||||
|
from models.objective_function import ObjectiveFunction
|
||||||
|
from models.advanced_options import AdvancedOptions
|
||||||
|
|
||||||
|
class SolverRun(BaseModel):
|
||||||
|
items: List[Item]
|
||||||
|
constraints: List[Constraint]
|
||||||
|
irt_model: IRTModel
|
||||||
|
objective_fuction: ObjectiveFunction
|
||||||
|
total_form_items: int
|
||||||
|
advanced_options: Optional[AdvancedOptions]
|
||||||
|
engine: str
|
5
app/models/target.py
Normal file
5
app/models/target.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
class Target(BaseModel):
|
||||||
|
theta: float
|
||||||
|
value: float
|
Loading…
x
Reference in New Issue
Block a user