| @@ -24,7 +24,7 @@ from collections import OrderedDict | |||||
| from pydantic import BaseModel, Field | from pydantic import BaseModel, Field | ||||
| from fastapi import Depends, FastAPI, HTTPException, File, UploadFile | |||||
| from fastapi import Depends, FastAPI, HTTPException, File, UploadFile, Query | |||||
| from fastapi.encoders import jsonable_encoder | from fastapi.encoders import jsonable_encoder | ||||
| from fastapi.openapi.docs import get_swagger_ui_html | from fastapi.openapi.docs import get_swagger_ui_html | ||||
| from fastapi.openapi.utils import get_openapi | from fastapi.openapi.utils import get_openapi | ||||
| @@ -193,19 +193,34 @@ async def get_documentation(): | |||||
| @app.get("/ble-ai/infer", tags=["BLE-AI"]) | @app.get("/ble-ai/infer", tags=["BLE-AI"]) | ||||
| async def get_ble_ai_infer(): | |||||
| async def get_ble_ai_infer(mac: Optional[List[str]] = Query(default=None)): | |||||
| path = config_env.BLE_AI_INFER_CSV | path = config_env.BLE_AI_INFER_CSV | ||||
| if not os.path.isfile(path): | if not os.path.isfile(path): | ||||
| raise HTTPException(status_code=404, detail="CSV not found") | raise HTTPException(status_code=404, detail="CSV not found") | ||||
| mac_filter = None | |||||
| if mac: | |||||
| mac_filter = set() | |||||
| for item in mac: | |||||
| if not item: | |||||
| continue | |||||
| for part in str(item).split(","): | |||||
| part = part.strip() | |||||
| if part: | |||||
| mac_filter.add(part.lower()) | |||||
| items = [] | items = [] | ||||
| with open(path, newline="") as f: | with open(path, newline="") as f: | ||||
| reader = csv.DictReader(f, delimiter=";") | reader = csv.DictReader(f, delimiter=";") | ||||
| for row in reader: | for row in reader: | ||||
| row_mac = row.get("mac") | |||||
| if mac_filter is not None: | |||||
| if not row_mac or row_mac.lower() not in mac_filter: | |||||
| continue | |||||
| try: | try: | ||||
| items.append( | items.append( | ||||
| { | { | ||||
| "mac": row.get("mac"), | |||||
| "mac": row_mac, | |||||
| "z": int(row["z"]) if row.get("z") not in (None, "") else None, | "z": int(row["z"]) if row.get("z") not in (None, "") else None, | ||||
| "x": int(row["x"]) if row.get("x") not in (None, "") else None, | "x": int(row["x"]) if row.get("x") not in (None, "") else None, | ||||
| "y": int(row["y"]) if row.get("y") not in (None, "") else None, | "y": int(row["y"]) if row.get("y") not in (None, "") else None, | ||||