Parcourir la source

Infer Output bug fix

master
Lorenzo Pollutri il y a 9 heures
Parent
révision
c0feadec6a
1 fichiers modifiés avec 18 ajouts et 3 suppressions
  1. +18
    -3
      app.py

+ 18
- 3
app.py Voir le fichier

@@ -24,7 +24,7 @@ from collections import OrderedDict

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.openapi.docs import get_swagger_ui_html
from fastapi.openapi.utils import get_openapi
@@ -193,19 +193,34 @@ async def get_documentation():


@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
if not os.path.isfile(path):
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 = []
with open(path, newline="") as f:
reader = csv.DictReader(f, delimiter=";")
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:
items.append(
{
"mac": row.get("mac"),
"mac": row_mac,
"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,
"y": int(row["y"]) if row.get("y") not in (None, "") else None,


Chargement…
Annuler
Enregistrer