Bump
This commit is contained in:
parent
60f8758a08
commit
9feccb5bd0
46
papi/main.py
46
papi/main.py
|
@ -5,6 +5,8 @@ from fastapi import FastAPI, Request, Body
|
|||
|
||||
from collections import defaultdict
|
||||
|
||||
from . import utils
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
|
@ -24,11 +26,6 @@ def read_root():
|
|||
return {"msg": "Hello World"}
|
||||
|
||||
|
||||
@app.get("/items/{item_id}")
|
||||
def read_item(item_id: int, q: Optional[str] = None):
|
||||
return {"item_id": item_id, "q": q}
|
||||
|
||||
|
||||
@app.post("/sonde/")
|
||||
def post_sonde(sonde: Sonde):
|
||||
print(sonde)
|
||||
|
@ -41,3 +38,42 @@ def list_sonde():
|
|||
return [x for x in sondes.values()]
|
||||
|
||||
|
||||
@app.post("/sonde/{idsonde}/")
|
||||
def post_sonde_data(idsonde: str, body: dict = Body(...)):
|
||||
if idsonde in sondes:
|
||||
mesures[idsonde].append(body)
|
||||
print(len(mesures[idsonde]))
|
||||
# print(dict(mesures))
|
||||
|
||||
|
||||
@app.get("/sonde/{idsonde}/rapport")
|
||||
def get_rapport(idsonde):
|
||||
try:
|
||||
last = mesures[idsonde][-1]
|
||||
except IndexError:
|
||||
pass
|
||||
else:
|
||||
last = utils.prepare(last)
|
||||
for name, data in sorted(last["channels"].items()):
|
||||
yield f'{name} {data["status"]}'
|
||||
|
||||
|
||||
@app.get("/sonde/{idsonde}/historique")
|
||||
def historique(idsonde):
|
||||
print(len(mesures[idsonde]))
|
||||
|
||||
for previous, present in zip(mesures[idsonde], mesures[idsonde][1:]):
|
||||
date = present["date"]
|
||||
previous = utils.prepare(previous)
|
||||
present = utils.prepare(present)
|
||||
all_channels = sorted(set((*previous["channels"], *present["channels"])))
|
||||
|
||||
diff = utils.compare(all_channels, previous, present)
|
||||
|
||||
if diff:
|
||||
for d in diff["changements"]:
|
||||
line = date, *d
|
||||
print(line)
|
||||
yield " ".join(line)
|
||||
else:
|
||||
print(f"no change for {date}")
|
||||
|
|
|
@ -32,3 +32,11 @@ def test_lister_sondes():
|
|||
response = client.get("/sonde/")
|
||||
assert response.status_code == 200
|
||||
assert sonde1 in response.json()
|
||||
|
||||
|
||||
def test_post_data():
|
||||
id_ = "masonde_001"
|
||||
data = {"example": "truc"}
|
||||
|
||||
response = client.post(f"/sonde/{id_}")
|
||||
assert response.ok
|
||||
|
|
Loading…
Reference in New Issue