diff --git a/app/main.py b/app/main.py index 18fcd45..8ec950c 100644 --- a/app/main.py +++ b/app/main.py @@ -1,4 +1,11 @@ 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() @@ -13,10 +20,20 @@ async def health(): "git_repo": "https://github.com/yardstick/measure-solver", "server": "OK", "fastapi version": __version__, - "app version": "0.1.0" + "app version": "0.1.1" } return content @app.get('/readycheck') async def ready(): 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 diff --git a/app/models/advanced_options.py b/app/models/advanced_options.py new file mode 100644 index 0000000..1a9fb34 --- /dev/null +++ b/app/models/advanced_options.py @@ -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]] diff --git a/app/models/attribute.py b/app/models/attribute.py new file mode 100644 index 0000000..0219ea6 --- /dev/null +++ b/app/models/attribute.py @@ -0,0 +1,7 @@ +from pydantic import BaseModel +from typing import Optional + +class Attribute(BaseModel): + value: str + type: Optional[str] + id: str diff --git a/app/models/constraint.py b/app/models/constraint.py new file mode 100644 index 0000000..84eb1b2 --- /dev/null +++ b/app/models/constraint.py @@ -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 diff --git a/app/models/form.py b/app/models/form.py new file mode 100644 index 0000000..5ff5414 --- /dev/null +++ b/app/models/form.py @@ -0,0 +1,7 @@ +from pydantic import BaseModel +from typing import List + +from models.item import Item + +class Form(BaseModel): + items: List[int] diff --git a/app/models/irt_model.py b/app/models/irt_model.py new file mode 100644 index 0000000..4751ba9 --- /dev/null +++ b/app/models/irt_model.py @@ -0,0 +1,7 @@ +from pydantic import BaseModel + +class IRTModel(BaseModel): + a_param: float + b_param: float + c_param: float + model: str diff --git a/app/models/item.py b/app/models/item.py new file mode 100644 index 0000000..975593e --- /dev/null +++ b/app/models/item.py @@ -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] diff --git a/app/models/objective_function.py b/app/models/objective_function.py new file mode 100644 index 0000000..0c7835d --- /dev/null +++ b/app/models/objective_function.py @@ -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} diff --git a/app/models/solution.py b/app/models/solution.py new file mode 100644 index 0000000..d895574 --- /dev/null +++ b/app/models/solution.py @@ -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] diff --git a/app/models/solver_run.py b/app/models/solver_run.py new file mode 100644 index 0000000..5dea7f0 --- /dev/null +++ b/app/models/solver_run.py @@ -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 diff --git a/app/models/target.py b/app/models/target.py new file mode 100644 index 0000000..1383208 --- /dev/null +++ b/app/models/target.py @@ -0,0 +1,5 @@ +from pydantic import BaseModel + +class Target(BaseModel): + theta: float + value: float