DAQ: added logging to server.py
This commit is contained in:
1 parent
70ccb4256f
commit
2d5f0160c6
1 file changed
+32
-1
@@ -6,9 +6,10 @@ import cv2
|
||||
import urllib3
|
||||
import uvicorn
|
||||
from aaredaqlib.coordinate import SmargonCoordinate, Coordinate
|
||||
from aaredaqlib.logger_config import setup_logger
|
||||
from aaredaqlib.models import SampleShortInfo, DAQStatusModel, BeamlineStateEnum, BeamlineSettingsModel, \
|
||||
SampleShortInfoList, SessionStatus, SampleCameraSettings, AutofocusSettings, TokenData, \
|
||||
CryojetSettingsModel, SimpleScanParameters
|
||||
CryojetSettingsModel, SimpleScanParameters, CrystalSize
|
||||
from aaredaqlib.raster_grid import RasterGridRequest, CompletedRasterGrid
|
||||
from aaredaqlib.rotation_scan import RotationScanRequest, CompletedRotationScan
|
||||
from aaredaqlib.sample_geometry import SampleGeometryModel
|
||||
@@ -35,6 +36,7 @@ bl = mx_beamline()
|
||||
cfg = BeamlineConfig(bl)
|
||||
daq = AareDAQ(cfg, bl)
|
||||
|
||||
logger = setup_logger("aareDAQ")
|
||||
|
||||
@app.post("/token")
|
||||
async def login(form_data: OAuth2PasswordRequestForm = Depends()):
|
||||
@@ -69,6 +71,7 @@ async def sample_geometry(
|
||||
|
||||
@app.put("/beamline/omega")
|
||||
async def omega(val: float, token: str = Depends(oauth2_scheme)):
|
||||
logger.debug(f"Setting omega to {val}")
|
||||
auth.check_jwt_rw(cfg, auth.parse_token(token))
|
||||
daq.omega = val
|
||||
return "OK"
|
||||
@@ -76,6 +79,7 @@ async def omega(val: float, token: str = Depends(oauth2_scheme)):
|
||||
|
||||
@app.put("/beamline/light")
|
||||
async def light(val: float, token: str = Depends(oauth2_scheme)):
|
||||
logger.debug(f"Setting light to {val}")
|
||||
auth.check_jwt_rw(cfg, auth.parse_token(token))
|
||||
daq.light = val
|
||||
return "OK"
|
||||
@@ -83,6 +87,7 @@ async def light(val: float, token: str = Depends(oauth2_scheme)):
|
||||
|
||||
@app.put("/beamline/zoom")
|
||||
async def zoom(val: float, token: str = Depends(oauth2_scheme)):
|
||||
logger.debug(f"Setting zoom to {val}")
|
||||
auth.check_jwt_rw(cfg, auth.parse_token(token))
|
||||
daq.zoom = val
|
||||
return "OK"
|
||||
@@ -90,6 +95,7 @@ async def zoom(val: float, token: str = Depends(oauth2_scheme)):
|
||||
|
||||
@app.put("/beamline/smargon")
|
||||
async def smargon(val: SmargonCoordinate, token: str = Depends(oauth2_scheme)):
|
||||
logger.debug(f"Setting smargon to {val}")
|
||||
auth.check_jwt_rw(cfg, auth.parse_token(token))
|
||||
daq.smargon = val
|
||||
return "OK"
|
||||
@@ -97,6 +103,7 @@ async def smargon(val: SmargonCoordinate, token: str = Depends(oauth2_scheme)):
|
||||
|
||||
@app.post("/beamline/tweak_abr_meas_pos")
|
||||
async def tweak_abr_meas_pos(val: Coordinate, token: str = Depends(oauth2_scheme)):
|
||||
logger.debug(f"Setting abr to {val}")
|
||||
auth.check_jwt_staff(cfg, auth.parse_token(token))
|
||||
daq.tweak_abr_meas_pos(val)
|
||||
return "OK"
|
||||
@@ -104,24 +111,28 @@ async def tweak_abr_meas_pos(val: Coordinate, token: str = Depends(oauth2_scheme
|
||||
|
||||
@app.post("/beamline/save_abr_meas_pos")
|
||||
async def save_abr_meas_pos(token: str = Depends(oauth2_scheme)):
|
||||
logger.debug(f"Save abr")
|
||||
auth.check_jwt_staff(cfg, auth.parse_token(token))
|
||||
daq.save_abr_meas_pos()
|
||||
return "OK"
|
||||
|
||||
@app.post("/beamline/anneal")
|
||||
async def anneal(time_s: float, token: str = Depends(oauth2_scheme)):
|
||||
logger.debug(f"Anneal {time_s}")
|
||||
auth.check_jwt_rw(cfg, auth.parse_token(token))
|
||||
daq.anneal(time_s)
|
||||
return "OK"
|
||||
|
||||
@app.post("/beamline/goto_abr_meas_pos")
|
||||
async def goto_abr_meas_pos(token: str = Depends(oauth2_scheme)):
|
||||
logger.debug(f"Go to ABR meas pos")
|
||||
auth.check_jwt_rw(cfg, auth.parse_token(token))
|
||||
daq.goto_abr_meas_pos()
|
||||
return "OK"
|
||||
|
||||
@app.post("/beam_mark/add")
|
||||
async def mark_beam(x: float, y: float, token: str = Depends(oauth2_scheme)):
|
||||
logger.debug(f"Marking beam to {x}, {y}")
|
||||
auth.check_jwt_staff(cfg, auth.parse_token(token))
|
||||
daq.mark_beam(x, y)
|
||||
return "OK"
|
||||
@@ -129,36 +140,42 @@ async def mark_beam(x: float, y: float, token: str = Depends(oauth2_scheme)):
|
||||
|
||||
@app.post("/beam_mark/clear")
|
||||
async def clear_beam_mark(token: str = Depends(oauth2_scheme)):
|
||||
logger.debug(f"Clear beam mark")
|
||||
auth.check_jwt_staff(cfg, auth.parse_token(token))
|
||||
daq.clear_mark_beam()
|
||||
return "OK"
|
||||
|
||||
@app.post("/beamline/beam_center")
|
||||
async def beam_center(x: float, y: float, token: str = Depends(oauth2_scheme)):
|
||||
logger.debug(f"Beam Center {x}, {y}")
|
||||
auth.check_jwt_staff(cfg, auth.parse_token(token))
|
||||
daq.beam_center = (x, y)
|
||||
return "OK"
|
||||
|
||||
@app.post("/beamline/beam_size_mm")
|
||||
async def beam_size_mm(x: float, y: float, token: str = Depends(oauth2_scheme)):
|
||||
logger.debug(f"Beam Size {x}, {y}")
|
||||
auth.check_jwt_staff(cfg, auth.parse_token(token))
|
||||
daq.beam_size_mm = Coordinate(x=x, y=y)
|
||||
return "OK"
|
||||
|
||||
@app.put("/beamline/samcam")
|
||||
async def samcam_settings(s: SampleCameraSettings, token: str = Depends(oauth2_scheme)):
|
||||
logger.debug(f"SamCam settings: {s}")
|
||||
auth.check_jwt_rw(cfg, auth.parse_token(token))
|
||||
daq.samcam_settings = s
|
||||
return "OK"
|
||||
|
||||
@app.post("/samcam/autofocus")
|
||||
async def samcam_autofocus(s: AutofocusSettings, token: str = Depends(oauth2_scheme)):
|
||||
logger.debug(f"SamCam AutoFocus")
|
||||
auth.check_jwt_rw(cfg, auth.parse_token(token))
|
||||
daq.autofocus(s)
|
||||
return "OK"
|
||||
|
||||
@app.post("/beamline/shutter")
|
||||
async def shutter(val: bool, token: str = Depends(oauth2_scheme)):
|
||||
logger.debug(f"Shutter {val}")
|
||||
auth.check_jwt_rw(cfg, auth.parse_token(token))
|
||||
daq.shutter = val
|
||||
return "OK"
|
||||
@@ -199,6 +216,7 @@ async def sample(token: str = Depends(oauth2_scheme)) -> SampleShortInfo:
|
||||
@app.post("/sample/mount")
|
||||
async def mount(dbid: int, token: str = Depends(oauth2_scheme), reference: bool = False):
|
||||
token_data = auth.parse_token(token)
|
||||
logger.debug(f"Mount {dbid}")
|
||||
auth.check_jwt_rw(cfg, auth.parse_token(token))
|
||||
|
||||
if reference:
|
||||
@@ -226,6 +244,7 @@ async def mount(dbid: int, token: str = Depends(oauth2_scheme), reference: bool
|
||||
|
||||
@app.post("/sample/unmount")
|
||||
async def unmount(token: str = Depends(oauth2_scheme)):
|
||||
logger.debug(f"Unmount")
|
||||
auth.check_jwt_rw(cfg, auth.parse_token(token))
|
||||
daq.sample = None
|
||||
return "OK"
|
||||
@@ -233,6 +252,7 @@ async def unmount(token: str = Depends(oauth2_scheme)):
|
||||
|
||||
@app.post("/sample/manual")
|
||||
async def manual(s: SampleShortInfo, token: str = Depends(oauth2_scheme)):
|
||||
logger.debug(f"Manual Sample {s.sample_name}")
|
||||
auth.check_jwt_rw(cfg, auth.parse_token(token))
|
||||
print(f"DB ID prior creating {s.db_id}")
|
||||
daq.create_sample(s)
|
||||
@@ -347,12 +367,15 @@ async def auto(s: SampleShortInfo, token: str = Depends(oauth2_scheme)):
|
||||
|
||||
@app.post("/scan/smart_params")
|
||||
async def set_smart_params(p: SimpleScanParameters, token: str = Depends(oauth2_scheme)) -> str:
|
||||
token_data = auth.parse_token(token)
|
||||
logger.debug(f"{token_data.session} Try to set smart params: {p}")
|
||||
auth.check_jwt_rw(cfg, auth.parse_token(token))
|
||||
daq.smart_params = p
|
||||
return "OK"
|
||||
|
||||
@app.post("/scan/cancel")
|
||||
async def cancel(token: str = Depends(oauth2_scheme)):
|
||||
logger.debug(f"Scan Cancel")
|
||||
auth.check_jwt_rw(cfg, auth.parse_token(token))
|
||||
daq.cancel()
|
||||
|
||||
@@ -366,6 +389,7 @@ async def alc_background(token: str = Depends(oauth2_scheme)) -> str:
|
||||
|
||||
@app.post("/alc/center_loop")
|
||||
async def alc_center_loop(token: str = Depends(oauth2_scheme)) -> str:
|
||||
logger.debug(f"ALC")
|
||||
auth.check_jwt_rw(cfg, auth.parse_token(token))
|
||||
daq.auto_loop_center()
|
||||
return "OK"
|
||||
@@ -379,6 +403,7 @@ async def alc_ml_bounding_box(token: str = Depends(oauth2_scheme)) -> RasterGrid
|
||||
|
||||
@app.post("/face_detection/run")
|
||||
async def face_detection_run(steps: int, step_size: int, token: str = Depends(oauth2_scheme)) -> dict:
|
||||
logger.debug(f"Face detection run: {steps} steps, {step_size} step size")
|
||||
auth.check_jwt_rw(cfg, auth.parse_token(token))
|
||||
result = daq.face_detection(steps=steps, step_size=step_size)
|
||||
return result
|
||||
@@ -411,6 +436,7 @@ async def set_commissioning_mode(val: bool, token: str = Depends(oauth2_scheme))
|
||||
|
||||
@app.post("/access/end_session")
|
||||
async def end_session(token: str = Depends(oauth2_scheme)) -> str:
|
||||
logger.debug(f"Try to end Session")
|
||||
# End active session will only delete session, if it is equal to token value
|
||||
# so no need to check R/W permissions
|
||||
token_data = auth.parse_token(token)
|
||||
@@ -420,6 +446,7 @@ async def end_session(token: str = Depends(oauth2_scheme)) -> str:
|
||||
|
||||
@app.post("/access/force_current_session")
|
||||
async def force_current_session(token: str = Depends(oauth2_scheme)) -> str:
|
||||
logger.debug(f"Try to grab session")
|
||||
data = auth.parse_token(token)
|
||||
# Counterintuitive, this operation requires only R/O permission
|
||||
# as this is actually acquiring R/W permissions
|
||||
@@ -430,22 +457,26 @@ async def force_current_session(token: str = Depends(oauth2_scheme)) -> str:
|
||||
|
||||
@app.get("/beamline/settings")
|
||||
async def get_settings(token: str = Depends(oauth2_scheme)) -> BeamlineSettingsModel:
|
||||
logger.debug(f"Get settings")
|
||||
auth.check_jwt_staff(cfg, auth.parse_token(token))
|
||||
return cfg.settings
|
||||
|
||||
|
||||
@app.put("/beamline/settings")
|
||||
async def put_settings(s: BeamlineSettingsModel, token: str = Depends(oauth2_scheme)):
|
||||
logger.debug(f"Putting settings: {s}")
|
||||
auth.check_jwt_staff(cfg, auth.parse_token(token))
|
||||
cfg.settings = s
|
||||
|
||||
@app.get("/beamline/cryo_settings")
|
||||
async def get_cryo_settings(token: str = Depends(oauth2_scheme)) -> CryojetSettingsModel:
|
||||
logger.debug(f"Get Cryo Settings")
|
||||
auth.check_jwt_staff(cfg, auth.parse_token(token))
|
||||
return cfg.cryojet_settings
|
||||
|
||||
@app.put("/beamline/cryo_settings")
|
||||
async def put_cryo_settings(s: CryojetSettingsModel, token: str = Depends(oauth2_scheme)):
|
||||
logger.debug(f"Put Cryo Settings: {s}")
|
||||
auth.check_jwt_staff(cfg, auth.parse_token(token))
|
||||
cfg.cryojet_settings = s
|
||||
|
||||
|
||||
Reference in new issue
Block a user