From a93d2c969f35f1279c0d9f6af3e8a89536fa7eb6 Mon Sep 17 00:00:00 2001 From: nmaytan Date: Thu, 26 Sep 2024 22:28:58 -0400 Subject: [PATCH 1/3] Make sync-experiment work for commissioning proposals --- nslsii/sync_experiment/sync_experiment.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/nslsii/sync_experiment/sync_experiment.py b/nslsii/sync_experiment/sync_experiment.py index 844f127..ad16f30 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 get_commissioning_status(proposal_number, beamline) -> bool: + commissioning_proposals_response = nslsii_api_client.get( + f"/v1/proposals/commissioning?beamline={beamline}" + ).raise_for_status() + commissioning_proposals = commissioning_proposals_response.json()[ + "commissioning_proposals" + ] + commissioning_status = proposal_number in commissioning_proposals + return commissioning_status + + 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") + is_commissioning_proposal = get_commissioning_status(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 is_commissioning_proposal + 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 get_commissioning_status(str(proposal_number), beamline) + else get_current_cycle() + ) md["proposal"] = { "proposal_id": proposal_data.get("proposal_id"), "title": proposal_data.get("title"), From 44346b00e578e9383e9ea647867b32d1c163406a Mon Sep 17 00:00:00 2001 From: nmaytan Date: Fri, 27 Sep 2024 11:05:50 -0400 Subject: [PATCH 2/3] Rename commissioning check --- nslsii/sync_experiment/sync_experiment.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/nslsii/sync_experiment/sync_experiment.py b/nslsii/sync_experiment/sync_experiment.py index ad16f30..2e82658 100644 --- a/nslsii/sync_experiment/sync_experiment.py +++ b/nslsii/sync_experiment/sync_experiment.py @@ -24,15 +24,14 @@ def get_current_cycle() -> str: return cycle_response.json()["cycle"] -def get_commissioning_status(proposal_number, beamline) -> bool: +def is_commissioning_proposal(proposal_number, beamline) -> bool: commissioning_proposals_response = nslsii_api_client.get( f"/v1/proposals/commissioning?beamline={beamline}" ).raise_for_status() commissioning_proposals = commissioning_proposals_response.json()[ "commissioning_proposals" ] - commissioning_status = proposal_number in commissioning_proposals - return commissioning_status + return proposal_number in commissioning_proposals def validate_proposal(data_session_value, beamline) -> Dict[str, Any]: @@ -49,7 +48,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") - is_commissioning_proposal = get_commissioning_status(proposal_number, beamline) + proposal_commissioning = is_commissioning_proposal(proposal_number, beamline) proposal_response = nslsii_api_client.get( f"/v1/proposal/{proposal_number}" ).raise_for_status() @@ -62,7 +61,7 @@ def validate_proposal(data_session_value, beamline) -> Dict[str, Any]: ) else: if ( - not is_commissioning_proposal + not proposal_commissioning and current_cycle not in proposal_data["cycles"] ): raise ValueError( @@ -171,7 +170,7 @@ def sync_experiment(proposal_number, beamline, verbose=False, prefix=""): md["start_datetime"] = datetime.now().isoformat() md["cycle"] = ( "commissioning" - if get_commissioning_status(str(proposal_number), beamline) + if is_commissioning_proposal(str(proposal_number), beamline) else get_current_cycle() ) md["proposal"] = { From ec840fc92d70fb0c0ef0a779b901fa9357bdfc15 Mon Sep 17 00:00:00 2001 From: nmaytan Date: Fri, 27 Sep 2024 11:08:28 -0400 Subject: [PATCH 3/3] Docstring on commissioning check --- nslsii/sync_experiment/sync_experiment.py | 1 + 1 file changed, 1 insertion(+) diff --git a/nslsii/sync_experiment/sync_experiment.py b/nslsii/sync_experiment/sync_experiment.py index 2e82658..f9c88b6 100644 --- a/nslsii/sync_experiment/sync_experiment.py +++ b/nslsii/sync_experiment/sync_experiment.py @@ -25,6 +25,7 @@ def get_current_cycle() -> str: 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()