diff --git a/nslsii/sync_experiment/sync_experiment.py b/nslsii/sync_experiment/sync_experiment.py index 844f127..f9c88b6 100644 --- a/nslsii/sync_experiment/sync_experiment.py +++ b/nslsii/sync_experiment/sync_experiment.py @@ -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 = {} @@ -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() @@ -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})." ) @@ -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"),