Skip to content

Commit

Permalink
Merge pull request #196 from nmaytan/comm_proposals
Browse files Browse the repository at this point in the history
Make sync-experiment work for commissioning proposals
  • Loading branch information
padraic-shafer authored Sep 27, 2024
2 parents 6986ffa + ec840fc commit eaa7617
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions nslsii/sync_experiment/sync_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ def get_current_cycle() -> str:
return cycle_response.json()["cycle"]


def is_commissioning_proposal(proposal_number, beamline) -> bool:
"""True if proposal_number is registered as a commissioning proposal; else False."""
commissioning_proposals_response = nslsii_api_client.get(
f"/v1/proposals/commissioning?beamline={beamline}"
).raise_for_status()
commissioning_proposals = commissioning_proposals_response.json()[
"commissioning_proposals"
]
return proposal_number in commissioning_proposals


def validate_proposal(data_session_value, beamline) -> Dict[str, Any]:

proposal_data = {}
Expand All @@ -38,6 +49,7 @@ def validate_proposal(data_session_value, beamline) -> Dict[str, Any]:
try:
current_cycle = get_current_cycle()
proposal_number = data_session_match.group("proposal_number")
proposal_commissioning = is_commissioning_proposal(proposal_number, beamline)
proposal_response = nslsii_api_client.get(
f"/v1/proposal/{proposal_number}"
).raise_for_status()
Expand All @@ -49,7 +61,10 @@ def validate_proposal(data_session_value, beamline) -> Dict[str, Any]:
f"{proposal_data}"
)
else:
if current_cycle not in proposal_data["cycles"]:
if (
not proposal_commissioning
and current_cycle not in proposal_data["cycles"]
):
raise ValueError(
f"Proposal {data_session_value} is not valid in the current NSLS2 cycle ({current_cycle})."
)
Expand Down Expand Up @@ -154,7 +169,11 @@ def sync_experiment(proposal_number, beamline, verbose=False, prefix=""):
md["data_session"] = new_data_session
md["username"] = username
md["start_datetime"] = datetime.now().isoformat()
md["cycle"] = get_current_cycle()
md["cycle"] = (
"commissioning"
if is_commissioning_proposal(str(proposal_number), beamline)
else get_current_cycle()
)
md["proposal"] = {
"proposal_id": proposal_data.get("proposal_id"),
"title": proposal_data.get("title"),
Expand Down

0 comments on commit eaa7617

Please sign in to comment.