This repository was archived by the owner on Mar 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidator.py
More file actions
55 lines (41 loc) · 2.07 KB
/
Copy pathvalidator.py
File metadata and controls
55 lines (41 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from fastapi import Request, HTTPException
from config import ParamsList
paramsList = ParamsList()
# Define the dependency
async def validateRunAlgoRequest(request: Request):
# Get the request body
body = await request.json()
if body["algorithm"] in paramsList.algorithm:
# if body["algorithm"] == "eaSimple":
# if body["mu"] is not None or body["lambda_"] is not None:
# raise HTTPException(status_code=400, detail="Invalid parameters for eaSimple")
if body["algorithm"] == "eaMuPlusLambda":
if body["mu"] is None or body["lambda_"] is None:
raise HTTPException(status_code=400, detail="Invalid parameters for eaMuPlusLambda")
elif body["algorithm"] == "eaMuCommaLambda":
if body["mu"] is None or body["lambda_"] is None:
raise HTTPException(status_code=400, detail="Invalid parameters for eaMuCommaLambda")
if body["mu"] >= body["lambda_"]:
raise HTTPException(status_code=400, detail="mu should be less than lambda for eaMuCommaLambda")
# elif body["algorithm"] == "eaGenerateUpdate":
# if body["mu"] is not None or body["lambda_"] is not None:
# raise HTTPException(status_code=400, detail="Invalid parameters for eaGenerateUpdate")
pass
else:
raise HTTPException(status_code=400, detail="Invalid algorithm")
if body["individual"] in paramsList.individual:
pass
else:
raise HTTPException(status_code=400, detail="Invalid individual")
if body["populationFunction"] in paramsList.populationFunction:
pass
else:
raise HTTPException(status_code=400, detail="Invalid population function")
if body["evaluationFunction"] in paramsList.evaluationFunction:
pass
else:
raise HTTPException(status_code=400, detail="Invalid evaluation function")
if body["crossoverFunction"] in paramsList.crossoverFunction:
pass
else:
raise HTTPException(status_code=400, detail="Invalid crossover function")