Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions src/murfey/server/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
DataCollectionGroup,
FoilHole,
GridSquare,
MagnificationLookup,
Movie,
PreprocessStash,
ProcessingJob,
Expand Down Expand Up @@ -166,6 +167,27 @@
return None


@router.get("/mag_table/")
def get_mag_table(db=murfey_db) -> List[MagnificationLookup]:
return db.exec(select(MagnificationLookup)).all()

Check warning on line 172 in src/murfey/server/api/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/__init__.py#L172

Added line #L172 was not covered by tests


@router.post("/mag_table/")
def add_to_mag_table(rows: List[MagnificationLookup], db=murfey_db):
for r in rows:
db.add(r)
db.commit()

Check warning on line 179 in src/murfey/server/api/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/__init__.py#L178-L179

Added lines #L178 - L179 were not covered by tests


@router.delete("/mag_table/{mag}")
def remove_mag_table_row(mag: int, db=murfey_db):
row = db.exec(

Check warning on line 184 in src/murfey/server/api/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/__init__.py#L184

Added line #L184 was not covered by tests
select(MagnificationLookup).where(MagnificationLookup.magnification == mag)
).one()
db.delete(row)
db.commit()

Check warning on line 188 in src/murfey/server/api/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/__init__.py#L187-L188

Added lines #L187 - L188 were not covered by tests


@router.get("/instruments/{instrument_name}/instrument_name")
def get_instrument_display_name(instrument_name: str) -> str:
machine_config = get_machine_config(instrument_name=instrument_name)[
Expand Down Expand Up @@ -396,6 +418,61 @@
).inc(rsyncer_info.data_bytes)


class ProcessingDetails(BaseModel):
data_collection_group: DataCollectionGroup
data_collections: List[DataCollection]
processing_jobs: List[ProcessingJob]
relion_params: SPARelionParameters
feedback_params: SPAFeedbackParameters


@router.get("/sessions/{session_id}/spa_processing_parameters")
def get_spa_proc_param_details(
session_id: MurfeySessionID, db=murfey_db
) -> Optional[List[ProcessingDetails]]:
params = db.exec(

Check warning on line 433 in src/murfey/server/api/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/__init__.py#L433

Added line #L433 was not covered by tests
select(
DataCollectionGroup,
DataCollection,
ProcessingJob,
SPARelionParameters,
SPAFeedbackParameters,
)
.where(DataCollectionGroup.session_id == session_id)
.where(DataCollectionGroup.id == DataCollection.dcg_id)
.where(DataCollection.id == ProcessingJob.dc_id)
.where(SPARelionParameters.pj_id == ProcessingJob.id)
.where(SPAFeedbackParameters.pj_id == ProcessingJob.id)
).all()
if not params:
return None
unique_dcg_indices = []
dcg_ids = []

Check warning on line 450 in src/murfey/server/api/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/__init__.py#L448-L450

Added lines #L448 - L450 were not covered by tests
for i, p in enumerate(params):
if p[0].id not in dcg_ids:
dcg_ids.append(p[0].id)
unique_dcg_indices.append(i)

Check warning on line 454 in src/murfey/server/api/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/__init__.py#L453-L454

Added lines #L453 - L454 were not covered by tests

def _parse(ps, i, dcg_id):
res = []

Check warning on line 457 in src/murfey/server/api/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/__init__.py#L456-L457

Added lines #L456 - L457 were not covered by tests
for p in ps:
if p[0].id == dcg_id:
if p[i] not in res:
res.append(p[i])
return res

Check warning on line 462 in src/murfey/server/api/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/__init__.py#L461-L462

Added lines #L461 - L462 were not covered by tests

return [

Check warning on line 464 in src/murfey/server/api/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/__init__.py#L464

Added line #L464 was not covered by tests
ProcessingDetails(
data_collection_group=params[i][0],
data_collections=_parse(params, 1, d),
processing_jobs=_parse(params, 2, d),
relion_params=_parse(params, 3, d)[0],
feedback_params=_parse(params, 4, d)[0],
)
for i, d in zip(unique_dcg_indices, dcg_ids)
]


@router.post("/sessions/{session_id}/spa_processing_parameters")
def register_spa_proc_params(
session_id: MurfeySessionID, proc_params: ProcessingParametersSPA, db=murfey_db
Expand Down