|
59 | 59 | DataCollectionGroup, |
60 | 60 | FoilHole, |
61 | 61 | GridSquare, |
| 62 | + MagnificationLookup, |
62 | 63 | Movie, |
63 | 64 | PreprocessStash, |
64 | 65 | ProcessingJob, |
@@ -166,6 +167,27 @@ def machine_info_by_name(instrument_name: str) -> Optional[MachineConfig]: |
166 | 167 | return None |
167 | 168 |
|
168 | 169 |
|
| 170 | +@router.get("/mag_table/") |
| 171 | +def get_mag_table(db=murfey_db) -> List[MagnificationLookup]: |
| 172 | + return db.exec(select(MagnificationLookup)).all() |
| 173 | + |
| 174 | + |
| 175 | +@router.post("/mag_table/") |
| 176 | +def add_to_mag_table(rows: List[MagnificationLookup], db=murfey_db): |
| 177 | + for r in rows: |
| 178 | + db.add(r) |
| 179 | + db.commit() |
| 180 | + |
| 181 | + |
| 182 | +@router.delete("/mag_table/{mag}") |
| 183 | +def remove_mag_table_row(mag: int, db=murfey_db): |
| 184 | + row = db.exec( |
| 185 | + select(MagnificationLookup).where(MagnificationLookup.magnification == mag) |
| 186 | + ).one() |
| 187 | + db.delete(row) |
| 188 | + db.commit() |
| 189 | + |
| 190 | + |
169 | 191 | @router.get("/instruments/{instrument_name}/instrument_name") |
170 | 192 | def get_instrument_display_name(instrument_name: str) -> str: |
171 | 193 | machine_config = get_machine_config(instrument_name=instrument_name)[ |
@@ -396,6 +418,61 @@ def increment_rsync_transferred_files_prometheus( |
396 | 418 | ).inc(rsyncer_info.data_bytes) |
397 | 419 |
|
398 | 420 |
|
| 421 | +class ProcessingDetails(BaseModel): |
| 422 | + data_collection_group: DataCollectionGroup |
| 423 | + data_collections: List[DataCollection] |
| 424 | + processing_jobs: List[ProcessingJob] |
| 425 | + relion_params: SPARelionParameters |
| 426 | + feedback_params: SPAFeedbackParameters |
| 427 | + |
| 428 | + |
| 429 | +@router.get("/sessions/{session_id}/spa_processing_parameters") |
| 430 | +def get_spa_proc_param_details( |
| 431 | + session_id: MurfeySessionID, db=murfey_db |
| 432 | +) -> Optional[List[ProcessingDetails]]: |
| 433 | + params = db.exec( |
| 434 | + select( |
| 435 | + DataCollectionGroup, |
| 436 | + DataCollection, |
| 437 | + ProcessingJob, |
| 438 | + SPARelionParameters, |
| 439 | + SPAFeedbackParameters, |
| 440 | + ) |
| 441 | + .where(DataCollectionGroup.session_id == session_id) |
| 442 | + .where(DataCollectionGroup.id == DataCollection.dcg_id) |
| 443 | + .where(DataCollection.id == ProcessingJob.dc_id) |
| 444 | + .where(SPARelionParameters.pj_id == ProcessingJob.id) |
| 445 | + .where(SPAFeedbackParameters.pj_id == ProcessingJob.id) |
| 446 | + ).all() |
| 447 | + if not params: |
| 448 | + return None |
| 449 | + unique_dcg_indices = [] |
| 450 | + dcg_ids = [] |
| 451 | + for i, p in enumerate(params): |
| 452 | + if p[0].id not in dcg_ids: |
| 453 | + dcg_ids.append(p[0].id) |
| 454 | + unique_dcg_indices.append(i) |
| 455 | + |
| 456 | + def _parse(ps, i, dcg_id): |
| 457 | + res = [] |
| 458 | + for p in ps: |
| 459 | + if p[0].id == dcg_id: |
| 460 | + if p[i] not in res: |
| 461 | + res.append(p[i]) |
| 462 | + return res |
| 463 | + |
| 464 | + return [ |
| 465 | + ProcessingDetails( |
| 466 | + data_collection_group=params[i][0], |
| 467 | + data_collections=_parse(params, 1, d), |
| 468 | + processing_jobs=_parse(params, 2, d), |
| 469 | + relion_params=_parse(params, 3, d)[0], |
| 470 | + feedback_params=_parse(params, 4, d)[0], |
| 471 | + ) |
| 472 | + for i, d in zip(unique_dcg_indices, dcg_ids) |
| 473 | + ] |
| 474 | + |
| 475 | + |
399 | 476 | @router.post("/sessions/{session_id}/spa_processing_parameters") |
400 | 477 | def register_spa_proc_params( |
401 | 478 | session_id: MurfeySessionID, proc_params: ProcessingParametersSPA, db=murfey_db |
|
0 commit comments