Frontend: Added option to select detector

This commit is contained in:
2023-04-13 18:12:19 +02:00
parent ae44b2eedf
commit 96a1b6e50c
7 changed files with 228 additions and 35 deletions
+44 -1
View File
@@ -29,7 +29,6 @@ channel = grpc.insecure_channel(
("grpc.max_receive_message_length", MAX_MESSAGE_LENGTH),
],
)
stub = jfjoch_pb2_grpc.gRPC_JFJochBrokerStub(channel)
@app.get("/", response_class=RedirectResponse)
@@ -45,6 +44,7 @@ async def get_frontend():
@app.post("/detector/pedestal")
async def pedestal():
try:
stub = jfjoch_pb2_grpc.gRPC_JFJochBrokerStub(channel)
stub.Pedestal(jfjoch_pb2.Empty())
except grpc.RpcError as e:
raise HTTPException(status_code=400, detail=e.details())
@@ -54,6 +54,7 @@ async def pedestal():
@app.post("/detector/initialize")
async def initialize():
try:
stub = jfjoch_pb2_grpc.gRPC_JFJochBrokerStub(channel)
stub.Initialize(jfjoch_pb2.Empty())
except grpc.RpcError as e:
raise HTTPException(status_code=400, detail=e.details())
@@ -63,6 +64,7 @@ async def initialize():
@app.post("/detector/deactivate")
async def deactivate():
try:
stub = jfjoch_pb2_grpc.gRPC_JFJochBrokerStub(channel)
stub.Deactivate(jfjoch_pb2.Empty())
except grpc.RpcError as e:
raise HTTPException(status_code=400, detail=e.details())
@@ -72,6 +74,7 @@ async def deactivate():
@app.post("/detector/start")
async def start(data: str = Body(...)):
try:
stub = jfjoch_pb2_grpc.gRPC_JFJochBrokerStub(channel)
stub.Start(Parse(data, jfjoch_pb2.DatasetSettings()))
return {}
except ParseError as e:
@@ -83,6 +86,7 @@ async def start(data: str = Body(...)):
@app.post("/detector/stop")
async def stop():
try:
stub = jfjoch_pb2_grpc.gRPC_JFJochBrokerStub(channel)
stub.Stop(jfjoch_pb2.Empty())
except grpc.RpcError as e:
raise HTTPException(status_code=400, detail=e.details())
@@ -92,6 +96,7 @@ async def stop():
@app.post("/detector/trigger")
async def stop():
try:
stub = jfjoch_pb2_grpc.gRPC_JFJochBrokerStub(channel)
stub.Trigger(jfjoch_pb2.Empty())
except grpc.RpcError as e:
raise HTTPException(status_code=400, detail=e.details())
@@ -101,6 +106,7 @@ async def stop():
@app.get("/detector/status")
async def get_status():
try:
stub = jfjoch_pb2_grpc.gRPC_JFJochBrokerStub(channel)
return MessageToDict(
stub.GetStatus(jfjoch_pb2.Empty()), including_default_value_fields=True
)
@@ -111,6 +117,7 @@ async def get_status():
@app.get("/detector/settings")
async def get_settings():
try:
stub = jfjoch_pb2_grpc.gRPC_JFJochBrokerStub(channel)
return MessageToDict(
stub.GetDetectorSettings(jfjoch_pb2.Empty()),
including_default_value_fields=True,
@@ -122,6 +129,7 @@ async def get_settings():
@app.put("/detector/settings")
async def put_settings(data: str = Body(...)):
try:
stub = jfjoch_pb2_grpc.gRPC_JFJochBrokerStub(channel)
stub.PutDetectorSettings(Parse(data, jfjoch_pb2.DetectorSettings()))
return {}
except ParseError as e:
@@ -133,6 +141,7 @@ async def put_settings(data: str = Body(...)):
@app.get("/detector/calibration")
async def get_calibration():
try:
stub = jfjoch_pb2_grpc.gRPC_JFJochBrokerStub(channel)
return MessageToDict(
stub.GetCalibrationStatistics(jfjoch_pb2.Empty()),
including_default_value_fields=True,
@@ -144,6 +153,7 @@ async def get_calibration():
@app.get("/data_processing/settings")
async def get_settings():
try:
stub = jfjoch_pb2_grpc.gRPC_JFJochBrokerStub(channel)
return MessageToDict(
stub.GetDataProcessingSettings(jfjoch_pb2.Empty()),
including_default_value_fields=True,
@@ -155,6 +165,7 @@ async def get_settings():
@app.put("/data_processing/settings")
async def put_data_processing_settings(data: str = Body(...)):
try:
stub = jfjoch_pb2_grpc.gRPC_JFJochBrokerStub(channel)
stub.PutDataProcessingSettings(Parse(data, jfjoch_pb2.DataProcessingSettings()))
return {}
except ParseError as e:
@@ -166,6 +177,7 @@ async def put_data_processing_settings(data: str = Body(...)):
@app.get("/data_processing/plots")
async def get_settings():
try:
stub = jfjoch_pb2_grpc.gRPC_JFJochBrokerStub(channel)
return MessageToDict(
stub.GetPlots(jfjoch_pb2.Empty()), including_default_value_fields=True
)
@@ -176,6 +188,7 @@ async def get_settings():
@app.put("/detector/measurement_statistics")
async def get_meas_stats():
try:
stub = jfjoch_pb2_grpc.gRPC_JFJochBrokerStub(channel)
return MessageToDict(
stub.GetMeasurementStatistics(jfjoch_pb2.Empty()), including_default_value_fields=True
)
@@ -183,6 +196,29 @@ async def get_meas_stats():
raise HTTPException(status_code=400, detail=e.details())
@app.get("/detector/list")
async def get_detector_list():
try:
stub = jfjoch_pb2_grpc.gRPC_JFJochBrokerStub(channel)
return MessageToDict(
stub.GetDetectorList(jfjoch_pb2.Empty()), including_default_value_fields=True
)
except grpc.RpcError as e:
raise HTTPException(status_code=400, detail=e.details())
@app.put("/detector/select")
async def put_detector_selection(data: str = Body(...)):
try:
stub = jfjoch_pb2_grpc.gRPC_JFJochBrokerStub(channel)
stub.SelectDetector(Parse(data, jfjoch_pb2.DetectorSelection()))
return {}
except ParseError as e:
return HTTPException(status_code=400, detail="Parser error: " + str(e))
except grpc.RpcError as e:
raise HTTPException(status_code=400, detail=e.details())
# https://stackoverflow.com/questions/55873174/how-do-i-return-an-image-in-fastapi
@app.get(
"/image/preview.tiff",
@@ -191,6 +227,7 @@ async def get_meas_stats():
)
async def get_preview():
try:
stub = jfjoch_pb2_grpc.gRPC_JFJochBrokerStub(channel)
pbuf = stub.GetPreview(jfjoch_pb2.Empty())
image_array = numpy.frombuffer(pbuf.data, numpy.int16)
image_array = numpy.where(image_array < 0, -1, image_array)
@@ -220,6 +257,7 @@ def calib_to_tiff(im: jfjoch_pb2.Image) -> bytes:
)
async def get_preview_dioptas():
try:
stub = jfjoch_pb2_grpc.gRPC_JFJochBrokerStub(channel)
pbuf = stub.GetPreview(jfjoch_pb2.Empty())
if pbuf.pixel_depth == 2:
image_array = numpy.frombuffer(pbuf.data, numpy.int16)
@@ -242,6 +280,7 @@ async def get_preview_dioptas():
)
async def get_pedestalg0():
try:
stub = jfjoch_pb2_grpc.gRPC_JFJochBrokerStub(channel)
pbuf = stub.GetPedestalG0(jfjoch_pb2.Empty())
return Response(content=calib_to_tiff(pbuf), media_type="image/tiff")
except grpc.RpcError as e:
@@ -255,6 +294,7 @@ async def get_pedestalg0():
)
async def get_pedestalg1():
try:
stub = jfjoch_pb2_grpc.gRPC_JFJochBrokerStub(channel)
pbuf = stub.GetPedestalG1(jfjoch_pb2.Empty())
return Response(content=calib_to_tiff(pbuf), media_type="image/tiff")
except grpc.RpcError as e:
@@ -268,6 +308,7 @@ async def get_pedestalg1():
)
async def get_pedestalg2():
try:
stub = jfjoch_pb2_grpc.gRPC_JFJochBrokerStub(channel)
pbuf = stub.GetPedestalG2(jfjoch_pb2.Empty())
return Response(content=calib_to_tiff(pbuf), media_type="image/tiff")
except grpc.RpcError as e:
@@ -281,7 +322,9 @@ async def get_pedestalg2():
)
async def get_mask():
try:
stub = jfjoch_pb2_grpc.gRPC_JFJochBrokerStub(channel)
pbuf = stub.GetMask(jfjoch_pb2.Empty())
return Response(content=calib_to_tiff(pbuf), media_type="image/tiff")
except grpc.RpcError as e:
raise HTTPException(status_code=400, detail=e.details())
+24 -24
View File
File diff suppressed because one or more lines are too long