DAQ: SSE work in progress
This commit is contained in:
1 parent
33b242eca6
commit
5f6e09102f
4 files changed
+234
-38
No files matched your search
@@ -67,37 +67,6 @@ class AareWrapper:
|
||||
)
|
||||
print(ret)
|
||||
|
||||
def get_sample_info(self) -> SampleShortInfoList:
|
||||
sample_list = (
|
||||
self.__tell_api.get_pucks_with_tell_position(tell=self.__bl.value.upper())
|
||||
)
|
||||
|
||||
ret = []
|
||||
for p in sample_list:
|
||||
for s in p.samples:
|
||||
dewar_address = None
|
||||
if p.tell_position is not None and len(p.tell_position) == 2:
|
||||
dewar_address = DewarAddress(
|
||||
segment=p.tell_position[0], pos=p.tell_position[1]
|
||||
)
|
||||
|
||||
ret.append(
|
||||
SampleShortInfo(
|
||||
db_id=s.id,
|
||||
puck_name=p.puck_name,
|
||||
dewar_name="Unknown" if p.dewar_name is None else p.dewar_name,
|
||||
sample_name=s.sample_name,
|
||||
user=p.pgroup,
|
||||
pin=s.position,
|
||||
location=dewar_address,
|
||||
priority=1.0 if s.priority is None else s.priority,
|
||||
comment=s.comments,
|
||||
mount_count=s.mount_count or 0,
|
||||
aaredb_params=s.data_collection_parameters
|
||||
)
|
||||
)
|
||||
return SampleShortInfoList(s=ret)
|
||||
|
||||
def sample_mounted(self, s: Optional[SampleShortInfo]):
|
||||
if s is not None:
|
||||
try:
|
||||
|
||||
@@ -607,7 +607,7 @@ class AareDAQ:
|
||||
|
||||
@property
|
||||
def sample_spreadsheet(self) -> SampleShortInfoList:
|
||||
return self.__aare.get_sample_info()
|
||||
return self.__cfg.spreadsheet
|
||||
|
||||
def sample_spreadsheet_user(self, pgroup: str) -> SampleShortInfoList:
|
||||
sample = self.sample_spreadsheet
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import asyncio
|
||||
import io
|
||||
from typing import Tuple
|
||||
from typing import Tuple, AsyncGenerator
|
||||
|
||||
import cv2
|
||||
import urllib3
|
||||
@@ -210,13 +211,40 @@ async def unmount(token: str = Depends(oauth2_scheme)):
|
||||
return "OK"
|
||||
|
||||
|
||||
@app.get("/tell/spreadsheet")
|
||||
async def spreadsheet(token: str = Depends(oauth2_scheme)):
|
||||
data = auth.parse_token(token)
|
||||
def get_spreadsheet(data: TokenData) -> SampleShortInfoList:
|
||||
if data.staff:
|
||||
return daq.sample_spreadsheet
|
||||
return cfg.spreadsheet
|
||||
else:
|
||||
return daq.sample_spreadsheet_user(data.group)
|
||||
return cfg.spreadsheet_pgroup(data.group)
|
||||
|
||||
|
||||
async def spreadsheet_event_stream(data: TokenData) -> AsyncGenerator[str, None]:
|
||||
try:
|
||||
while True:
|
||||
yield get_spreadsheet(data).model_dump_json()
|
||||
await asyncio.sleep(10)
|
||||
except asyncio.CancelledError:
|
||||
return
|
||||
|
||||
|
||||
@app.get("/sse/spreadsheet")
|
||||
async def spreadsheet_sse(token: str = Depends(oauth2_scheme)):
|
||||
data = auth.parse_token(token)
|
||||
return StreamingResponse(
|
||||
spreadsheet_event_stream(data),
|
||||
media_type="text/event-stream",
|
||||
headers={
|
||||
"Cache-Control": "no-cache",
|
||||
"Connection": "keep-alive",
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
"Access-Control-Allow-Headers": "Cache-Control"
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@app.get("/tell/spreadsheet")
|
||||
async def spreadsheet(token: str = Depends(oauth2_scheme)) -> SampleShortInfoList:
|
||||
return get_spreadsheet(auth.parse_token(token))
|
||||
|
||||
|
||||
# State transitions
|
||||
|
||||
Reference in new issue
Block a user